Example usage for com.amazonaws.services.elasticmapreduce.model ClusterState WAITING

List of usage examples for com.amazonaws.services.elasticmapreduce.model ClusterState WAITING

Introduction

In this page you can find the example usage for com.amazonaws.services.elasticmapreduce.model ClusterState WAITING.

Prototype

ClusterState WAITING

To view the source code for com.amazonaws.services.elasticmapreduce.model ClusterState WAITING.

Click Source Link

Usage

From source file:com.aegeus.aws.ElasticMapReduceService.java

License:Apache License

/**
 * Wait cluster until cluster is ready//from   w  ww  . ja va  2s. c  o  m
 */
public void waitCluster() {
    String lastReason = null;
    DescribeClusterRequest request = new DescribeClusterRequest().withClusterId(clusterId);
    DescribeClusterResult result;

    while (true) {
        try {
            result = emr.describeCluster(request);
            String reason = result.getCluster().getStatus().getStateChangeReason().getMessage();

            if (!reason.equals(lastReason)) {
                LOGGER.info("Cluster status changed. New status is " + reason);
                lastReason = reason;
            }

            ClusterState status = ClusterState.fromValue(result.getCluster().getStatus().getState());
            if (status.equals(ClusterState.WAITING)) {
                return;
            }

            Thread.sleep(SLEEP);
        } catch (InterruptedException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
}

From source file:org.finra.dm.dao.impl.MockEmrOperationsImpl.java

License:Apache License

@Override
public String runEmrJobFlow(AmazonElasticMapReduceClient emrClient, RunJobFlowRequest jobFlowRequest) {
    String clusterStatus = ClusterState.BOOTSTRAPPING.toString();

    if (StringUtils.isNotBlank(jobFlowRequest.getAmiVersion())) {
        if (jobFlowRequest.getAmiVersion().equals(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION)) {
            AmazonServiceException throttlingException = new AmazonServiceException(
                    "test throttling exception");
            throttlingException.setErrorCode("ThrottlingException");

            throw throttlingException;
        } else if (jobFlowRequest.getAmiVersion().equals(MockAwsOperationsHelper.AMAZON_BAD_REQUEST)) {
            AmazonServiceException badRequestException = new AmazonServiceException(
                    MockAwsOperationsHelper.AMAZON_BAD_REQUEST);
            badRequestException.setStatusCode(HttpStatus.SC_BAD_REQUEST);
            throw badRequestException;
        } else if (jobFlowRequest.getAmiVersion().equals(MockAwsOperationsHelper.AMAZON_NOT_FOUND)) {
            AmazonServiceException notFoundException = new AmazonServiceException(
                    MockAwsOperationsHelper.AMAZON_NOT_FOUND);
            notFoundException.setStatusCode(HttpStatus.SC_NOT_FOUND);
            throw notFoundException;
        } else if (jobFlowRequest.getAmiVersion().equals(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION)) {
            throw new AmazonServiceException(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION);
        } else if (jobFlowRequest.getAmiVersion()
                .equals(MockAwsOperationsHelper.AMAZON_CLUSTER_STATUS_WAITING)) {
            clusterStatus = ClusterState.WAITING.toString();
        } else if (jobFlowRequest.getAmiVersion()
                .equals(MockAwsOperationsHelper.AMAZON_CLUSTER_STATUS_RUNNING)) {
            clusterStatus = ClusterState.RUNNING.toString();
        }/*from   w w  w . j  a va2  s .  c  o  m*/
    }

    return createNewCluster(jobFlowRequest, clusterStatus).getJobFlowId();
}

From source file:org.finra.herd.dao.impl.MockEmrOperationsImpl.java

License:Apache License

@Override
public String runEmrJobFlow(AmazonElasticMapReduceClient emrClient, RunJobFlowRequest jobFlowRequest) {
    String clusterStatus = ClusterState.BOOTSTRAPPING.toString();

    StatusChangeReason reason = new StatusChangeReason(ClusterStateChangeReasonCode.USER_REQUEST.toString(),
            "Started " + clusterStatus);
    StatusTimeline timeline = new StatusTimeline();
    timeline.setCreationTime(HerdDateUtils.getXMLGregorianCalendarValue(new Date()));

    if (StringUtils.isNotBlank(jobFlowRequest.getAmiVersion())) {
        if (jobFlowRequest.getAmiVersion().equals(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION)) {
            AmazonServiceException throttlingException = new AmazonServiceException(
                    "test throttling exception");
            throttlingException.setErrorCode("ThrottlingException");

            throw throttlingException;
        } else if (jobFlowRequest.getAmiVersion().equals(MockAwsOperationsHelper.AMAZON_BAD_REQUEST)) {
            AmazonServiceException badRequestException = new AmazonServiceException(
                    MockAwsOperationsHelper.AMAZON_BAD_REQUEST);
            badRequestException.setStatusCode(HttpStatus.SC_BAD_REQUEST);
            throw badRequestException;
        } else if (jobFlowRequest.getAmiVersion().equals(MockAwsOperationsHelper.AMAZON_NOT_FOUND)) {
            AmazonServiceException notFoundException = new AmazonServiceException(
                    MockAwsOperationsHelper.AMAZON_NOT_FOUND);
            notFoundException.setStatusCode(HttpStatus.SC_NOT_FOUND);
            throw notFoundException;
        } else if (jobFlowRequest.getAmiVersion().equals(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION)) {
            throw new AmazonServiceException(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION);
        } else if (jobFlowRequest.getAmiVersion()
                .equals(MockAwsOperationsHelper.AMAZON_CLUSTER_STATUS_WAITING)) {
            clusterStatus = ClusterState.WAITING.toString();
        } else if (jobFlowRequest.getAmiVersion()
                .equals(MockAwsOperationsHelper.AMAZON_CLUSTER_STATUS_RUNNING)) {
            clusterStatus = ClusterState.RUNNING.toString();
        }/*w  ww.j  a v  a  2 s  . com*/
    }

    return createNewCluster(jobFlowRequest, clusterStatus, reason, timeline).getJobFlowId();
}

From source file:org.pentaho.amazon.client.impl.EmrClientImpl.java

License:Apache License

/**
 * Determine if the step flow is in a running state.
 *
 * @return true if it is not in COMPLETED or CANCELLED or FAILED or INTERRUPTED, and false otherwise.
 *//*from w  w  w. j av  a  2  s  . co m*/
@Override
public boolean isClusterRunning() {
    if (ClusterState.WAITING.name().equalsIgnoreCase(currentClusterState)) {
        return false;
    }
    if (ClusterState.TERMINATED.name().equalsIgnoreCase(currentClusterState)) {
        return false;
    }
    if (ClusterState.TERMINATED_WITH_ERRORS.name().equalsIgnoreCase(currentClusterState)) {
        return false;
    }
    return true;
}

From source file:org.pentaho.amazon.client.impl.EmrClientImpl.java

License:Apache License

@Override
public boolean isRunning() {
    currentStepState = getActualStepState();
    currentClusterState = getActualClusterState();
    boolean isClusterRunning = isClusterRunning();
    boolean isStepRunning = isStepRunning();

    if (!alive && !requestClusterShutdown
            && ClusterState.WAITING.name().equalsIgnoreCase(currentClusterState)) {
        if (!isStepRunning) {
            terminateJobFlows();//from  w w w  .  j  a va  2 s. c  om
            return isClusterRunning();
        }
    }
    return (isClusterRunning || isStepRunning);
}