amazon-web-services – 亚马逊EMR – 等待步骤

我正在编写一个运行aws emr命令的bash脚本(aws emr版本1.5.2).

如何让我的脚本等到emr作业完成后再继续? –wait-for-steps选项现在已折旧.

通过jq我得到了这个,但它似乎是错误的方法:

STEP_STATUS_STATE=$(aws emr list-steps --cluster-id ${CLUSTER_ID} | jq '.Steps[0].Status.State' | tr -d '"')
while [[ ${STEP_STATUS_STATE} == PENDING ]] || [[ ${STEP_STATUS_STATE} == RUNNING ]]; do
    STEP_STATUS_STATE=$(aws emr list-steps --cluster-id ${CLUSTER_ID} | jq '.Steps[0].Status.State' | tr -d '"')
    echo $(date) ${STEP_STATUS_STATE}
    sleep 10
done

最佳答案 我使用AWS java api等到工作完成如下.希望这可以帮助

 public static final List<JobFlowExecutionState> DONE_STATES = Arrays
        .asList(new JobFlowExecutionState[] {
                JobFlowExecutionState.COMPLETED,
                JobFlowExecutionState.FAILED,
                JobFlowExecutionState.TERMINATED });

  public static boolean isDone(String value) {
    JobFlowExecutionState state = JobFlowExecutionState.fromValue(value);
    return Constants.DONE_STATES.contains(state);
}

   .
   .
  STATUS_LOOP: while (true) {
        DescribeJobFlowsRequest desc = new DescribeJobFlowsRequest(
                Arrays.asList(new String[] { result.getJobFlowId() }));
        DescribeJobFlowsResult descResult = emr.describeJobFlows(desc);
        for (JobFlowDetail detail : descResult.getJobFlows()) {
            String state = detail.getExecutionStatusDetail().getState();
            if (isDone(state)) {
                logger.info("Job " + state + ": " + detail.toString());

                if(loadToDailyDB && state.equalsIgnoreCase("COMPLETED"))
                {

                    //Do something
                }
                if(!state.equalsIgnoreCase("COMPLETED"))
                {

                }

                break STATUS_LOOP;
            } else if (!lastState.equals(state)) {
                lastState = state;
                logger.info("Job " + state + " at "
                        + new Date().toString());
            }
        }
        Thread.sleep(75000);
点赞