从ID Amazon EMR获取集群对象

时间:2014-07-21 22:02:01

标签: java hadoop emr

我通过GUI屏幕启动了一个EMR集群。群集启动后,我可以看到ID。如何获得类Cluster的对象,该对象表示具有该ID的集群?我正在使用Java与EMR进行交互。

1 个答案:

答案 0 :(得分:1)

您无法运行单个命令以获取群集的身份。以下是读取所有故障集群的ID的算法的工作示例。

AWSCredentials credentials;
credentials = new BasicAWSCredentials("myAccessKey", "mySecretKey");

AmazonElasticMapReduceClient emrClient;
emrClient = new AmazonElasticMapReduceClient(credentials);
emrClient.setEndpoint("elasticmapreduce.eu-west-1.amazonaws.com");

ListClustersRequest req;
req = new ListClustersRequest().withClusterStates(ClusterState.TERMINATED_WITH_ERRORS);

ListClustersResult res;
res = emrClient.listClusters(req);

int size  = res.getClusters().size();

System.out.println("***************** CLUSTER LIST ***************");
System.out.println("*** Size: " + size);

for(int i = 0 ; i < size; i++){           
    String clusterID = res.getClusters().get(i).getId();
    System.out.println(">>> Cluster: " + clusterID);    
}

请注意以下步骤:

  • 使用您自己的凭据生成EMR客户端以访问Amazon的服务
  • 创建指示状态过滤器的群集请求(存在其他几个过滤器)
  • 获取所选群集的实际列表
  • 获取for循环中每个群集的ID

正如它提到的具体问题,我担心无法获得群集的实际对象。相反,API允许获取具体集群的信息摘要(在上面提供的代码中使用)。但是,您仍然可以发出诸如终止群集之类的命令,例如:

clusterId  //Defined in the code above

TerminateJobFlowsRequest terminate;
terminate = new TerminateJobFlowsRequest().withJobFlowIds(Arrays.asList(new String[] {clusterId});

emrClient.terminateJobFlows(terminate);
相关问题