Skip to content

Instantly share code, notes, and snippets.

@sujee
Created August 25, 2011 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sujee/1169743 to your computer and use it in GitHub Desktop.
Save sujee/1169743 to your computer and use it in GitHub Desktop.
hadoop utilities : Cluster Status
package sujee;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.mapred.ClusterStatus;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
/*
compile into a jar and execute:
hadoop jar a.jar sujee.TestCluster
output:
number of task trackers: 1
maximum map tasks : 3
currently running map tasks : 0
*/
public class TestCluster extends Configured implements Tool
{
public static void main(String[] args) throws Exception
{
int result = ToolRunner.run(new Configuration(), new TestCluster(), args);
System.exit(result);
}
@Override
public int run(String[] arg0) throws Exception
{
JobConf dummyJob = new JobConf(new Configuration(), TestCluster.class);
JobClient jobClient = new JobClient(dummyJob);
ClusterStatus clusterStatus = jobClient.getClusterStatus();
System.out.println("number of task trackers: " + clusterStatus.getTaskTrackers());
System.out.println("maximum map tasks : " + clusterStatus.getMaxMapTasks());
System.out.println("currently running map tasks : " + clusterStatus.getMapTasks());
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment