我通过GUI屏幕启动了一个EMR集群。群集启动后,我可以看到ID。如何获得类Cluster的对象,该对象表示具有该ID的集群?我正在使用Java与EMR进行交互。
答案 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);
}
请注意以下步骤:
正如它提到的具体问题,我担心无法获得群集的实际对象。相反,API允许获取具体集群的信息摘要(在上面提供的代码中使用)。但是,您仍然可以发出诸如终止群集之类的命令,例如:
clusterId //Defined in the code above
TerminateJobFlowsRequest terminate;
terminate = new TerminateJobFlowsRequest().withJobFlowIds(Arrays.asList(new String[] {clusterId});
emrClient.terminateJobFlows(terminate);