Created
August 25, 2011 01:23
-
-
Save sujee/1169743 to your computer and use it in GitHub Desktop.
hadoop utilities : Cluster Status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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