2015-12-14 81 views
1
public void setup(Context context) throws IOException, InterruptedException{ 
      Configuration conf = context.getConfiguration(); 
      org.apache.hadoop.mapreduce.Cluster cluster = new org.apache.hadoop.mapreduce.Cluster(conf); 
      Job currentJob = cluster.getJob(context.getJobID()); 
      mapperCounter = currentJob.getCounters().findCounter(TEST).getValue(); 
     } 

我編寫了下面的代碼來獲取計數器的值,該計數器的值在我的mapper函數中增加。問題是由cluster.getJob返回的currentJob變爲null。有誰知道我該如何解決這個問題?cluster.getJob在hadoop中返回null

我的問題是不同的原因我試圖訪問減速器中的我的計數器不是所有的地圖減少任務完成後。我粘貼在這裏的代碼屬於我的reducer類。

+0

我沒有用'org.apache.hadoop.mapreduce.Cluster'太多的經驗,但是你確定工作實際上在運行? –

+0

我不知道我是否明白你的意思,但是我在集羣作業任務內的Reducer任務中運行這段代碼,所以作業必須正確運行? – Aditya

+0

我假設你從http://diveintodata.org/2011/03/15/an-example-of-hadoop-mapreduce-counter/獲得了這段代碼,但它確實表示代碼僅用於完成作業。我從來沒有以這種方式檢索到計數器。由於新的API和缺乏透明度,計數器總會有一定的試驗和錯誤,但是我可能會建議查看http://lintool.github.io/Cloud9/docs/content/counters.html? –

回答