Example usage for com.amazonaws.services.elasticmapreduce.model Cluster getStatus

List of usage examples for com.amazonaws.services.elasticmapreduce.model Cluster getStatus

Introduction

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

Prototype


public ClusterStatus getStatus() 

Source Link

Document

The current status details about the cluster.

Usage

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

License:Apache License

/**
 * Get EMR cluster status by cluster Id.
 *
 * @param clusterId the job Id returned by EMR for the cluster.
 * @param awsParams AWS related parameters for access/secret keys and proxy details.
 *
 * @return the cluster status./*from  ww  w  .  j  a  va2  s .c  o m*/
 */
@Override
public String getEmrClusterStatusById(String clusterId, AwsParamsDto awsParams) {
    Cluster cluster = getEmrClusterById(clusterId, awsParams);

    return ((cluster == null) ? null : cluster.getStatus().getState());
}

From source file:org.finra.dm.service.impl.EmrServiceImpl.java

License:Apache License

/**
 * Gets details of an existing EMR Cluster.
 *
 * @param emrClusterAlternateKeyDto the EMR cluster alternate key
 * @param emrClusterId the cluster id of the cluster to get details
 * @param emrStepId the step id of the step to get details
 * @param verbose parameter for whether to return detailed information
 * @param retrieveOozieJobs parameter for whether to retrieve oozie job information
 *
 * @return the EMR Cluster object with details.
 * @throws Exception if an error occurred while getting the cluster.
 */// ww  w.  j a v  a  2s. c o  m
protected EmrCluster getClusterImpl(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, String emrClusterId,
        String emrStepId, boolean verbose, boolean retrieveOozieJobs) throws Exception {
    // Perform the request validation.
    emrHelper.validateEmrClusterKey(emrClusterAlternateKeyDto);

    // Get the namespace and ensure it exists.
    NamespaceEntity namespaceEntity = dmDaoHelper.getNamespaceEntity(emrClusterAlternateKeyDto.getNamespace());

    // Get the EMR cluster definition and ensure it exists.
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = dmDaoHelper.getEmrClusterDefinitionEntity(
            emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName());

    EmrCluster emrCluster = createEmrClusterFromRequest(null, namespaceEntity.getCode(),
            emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName(), null, null,
            null, null);
    String clusterName = emrHelper.buildEmrClusterName(namespaceEntity.getCode(),
            emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName());
    try {
        // Get Cluster status if clusterId is specified
        if (StringUtils.hasText(emrClusterId)) {
            Cluster cluster = emrDao.getEmrClusterById(emrClusterId.trim(), emrHelper.getAwsParamsDto());

            // Validate that, Cluster exists
            Assert.notNull(cluster, "An EMR cluster must exists with the cluster ID \"" + emrClusterId + "\".");

            // Validate that, Cluster name match as specified
            Assert.isTrue(clusterName.equalsIgnoreCase(cluster.getName()),
                    "Cluster name of specified cluster id \"" + emrClusterId
                            + "\" must match the name specified.");
            emrCluster.setId(cluster.getId());
            emrCluster.setStatus(cluster.getStatus().getState());
        } else {
            ClusterSummary clusterSummary = emrDao.getActiveEmrClusterByName(clusterName,
                    emrHelper.getAwsParamsDto());

            // Validate that, Cluster exists with the name
            Assert.notNull(clusterSummary, "An EMR cluster must exists with the name \"" + clusterName + "\".");

            emrCluster.setId(clusterSummary.getId());
            emrCluster.setStatus(clusterSummary.getStatus().getState());
        }

        // Get active step details
        if (emrHelper.isActiveEmrState(emrCluster.getStatus())) {
            StepSummary stepSummary = emrDao.getClusterActiveStep(emrCluster.getId(),
                    emrHelper.getAwsParamsDto());
            if (stepSummary != null) {
                EmrStep activeStep;

                // If verbose get active step details
                if (verbose) {
                    activeStep = buildEmrStepFromAwsStep(emrDao.getClusterStep(emrCluster.getId(),
                            stepSummary.getId(), emrHelper.getAwsParamsDto()), true);
                } else {
                    activeStep = buildEmrStepFromAwsStepSummary(stepSummary);
                }
                emrCluster.setActiveStep(activeStep);
            }
        }

        // Get requested step details
        if (StringUtils.hasText(emrStepId)) {
            Step step = emrDao.getClusterStep(emrCluster.getId(), emrStepId.trim(),
                    emrHelper.getAwsParamsDto());

            emrCluster.setStep(buildEmrStepFromAwsStep(step, verbose));
        }

        // Get oozie job details if requested.
        if (retrieveOozieJobs && (emrCluster.getStatus().equalsIgnoreCase("RUNNING")
                || emrCluster.getStatus().equalsIgnoreCase("WAITING"))) {
            emrCluster.setOozieWorkflowJobs(retrieveOozieJobs(emrCluster.getId()));
        }
    } catch (AmazonServiceException ex) {
        handleAmazonException(ex, "An Amazon exception occurred while getting EMR cluster details with name \""
                + clusterName + "\".");
    }

    return emrCluster;
}

From source file:org.finra.herd.dao.helper.EmrHelper.java

License:Apache License

/**
 * Gets the ID of an active EMR cluster which matches the given criteria. If both cluster ID and cluster name is specified, the name of the actual cluster
 * with the given ID must match the specified name. For cases where the cluster is not found (does not exists or not active), the method fails. All
 * parameters are case-insensitive and whitespace trimmed. Blank parameters are equal to null.
 *
 * @param emrClusterId EMR cluster ID//from w  ww. j  a v a  2  s .  com
 * @param emrClusterName EMR cluster name
 * @param accountId the account Id that EMR cluster is running under
 *
 * @return The cluster ID
 */
public String getActiveEmrClusterId(String emrClusterId, String emrClusterName, String accountId) {
    boolean emrClusterIdSpecified = StringUtils.isNotBlank(emrClusterId);
    boolean emrClusterNameSpecified = StringUtils.isNotBlank(emrClusterName);

    Assert.isTrue(emrClusterIdSpecified || emrClusterNameSpecified,
            "One of EMR cluster ID or EMR cluster name must be specified.");
    AwsParamsDto awsParamsDto = getAwsParamsDtoByAccountId(accountId);

    // Get cluster by ID first
    if (emrClusterIdSpecified) {
        String emrClusterIdTrimmed = emrClusterId.trim();

        // Assert cluster exists
        Cluster cluster = emrDao.getEmrClusterById(emrClusterIdTrimmed, awsParamsDto);
        Assert.notNull(cluster,
                String.format("The cluster with ID \"%s\" does not exist.", emrClusterIdTrimmed));

        // Assert the cluster's state is active
        String emrClusterState = cluster.getStatus().getState();
        Assert.isTrue(isActiveEmrState(emrClusterState), String.format(
                "The cluster with ID \"%s\" is not active. The cluster state must be in one of %s. Current state is \"%s\"",
                emrClusterIdTrimmed, Arrays.toString(getActiveEmrClusterStates()), emrClusterState));

        // Assert cluster name equals if cluster name was specified
        if (emrClusterNameSpecified) {
            String emrClusterNameTrimmed = emrClusterName.trim();
            Assert.isTrue(cluster.getName().equalsIgnoreCase(emrClusterNameTrimmed), String.format(
                    "The cluster with ID \"%s\" does not match the expected name \"%s\". The actual name is \"%s\".",
                    cluster.getId(), emrClusterNameTrimmed, cluster.getName()));
        }

        return cluster.getId();
    } else {
        String emrClusterNameTrimmed = emrClusterName.trim();
        ClusterSummary clusterSummary = emrDao.getActiveEmrClusterByName(emrClusterNameTrimmed, awsParamsDto);
        Assert.notNull(clusterSummary,
                String.format("The cluster with name \"%s\" does not exist.", emrClusterNameTrimmed));
        return clusterSummary.getId();
    }
}

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

License:Apache License

@Override
public String getEmrClusterStatusById(String clusterId, AwsParamsDto awsParams) {
    Cluster cluster = getEmrClusterById(clusterId, awsParams);

    return ((cluster == null) ? null : cluster.getStatus().getState());
}

From source file:org.finra.herd.service.impl.EmrServiceImpl.java

License:Apache License

/**
 * Gets details of an existing EMR Cluster.
 *
 * @param emrClusterAlternateKeyDto the EMR cluster alternate key
 * @param emrClusterId the cluster id of the cluster to get details
 * @param emrStepId the step id of the step to get details
 * @param verbose parameter for whether to return detailed information
 * @param accountId the optional AWS account that EMR cluster is running in
 * @param retrieveInstanceFleets parameter for whether to retrieve instance fleets
 *
 * @return the EMR Cluster object with details.
 *///from w ww  .  j  a v a 2 s  . c o  m
protected EmrCluster getClusterImpl(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, String emrClusterId,
        String emrStepId, boolean verbose, String accountId, Boolean retrieveInstanceFleets) {
    AwsParamsDto awsParamsDto = emrHelper.getAwsParamsDtoByAccountId(accountId);

    // Perform the request validation.
    validateEmrClusterKey(emrClusterAlternateKeyDto);

    // Get the EMR cluster definition and ensure it exists.
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper
            .getEmrClusterDefinitionEntity(new EmrClusterDefinitionKey(emrClusterAlternateKeyDto.getNamespace(),
                    emrClusterAlternateKeyDto.getEmrClusterDefinitionName()));

    EmrCluster emrCluster = createEmrClusterFromRequest(null,
            emrClusterDefinitionEntity.getNamespace().getCode(), emrClusterDefinitionEntity.getName(),
            emrClusterAlternateKeyDto.getEmrClusterName(), accountId, null, null, null, null);
    String clusterName = emrHelper.buildEmrClusterName(emrClusterDefinitionEntity.getNamespace().getCode(),
            emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName());
    try {
        // Get Cluster status if clusterId is specified
        if (StringUtils.isNotBlank(emrClusterId)) {
            Cluster cluster = emrDao.getEmrClusterById(emrClusterId.trim(), awsParamsDto);

            // Validate that, Cluster exists
            Assert.notNull(cluster, "An EMR cluster must exists with the cluster ID \"" + emrClusterId + "\".");

            // Validate that, Cluster name match as specified
            Assert.isTrue(clusterName.equalsIgnoreCase(cluster.getName()),
                    "Cluster name of specified cluster id \"" + emrClusterId
                            + "\" must match the name specified.");
            emrCluster.setId(cluster.getId());
            setEmrClusterStatus(emrCluster, cluster.getStatus());
        } else {
            ClusterSummary clusterSummary = emrDao.getActiveEmrClusterByName(clusterName, awsParamsDto);

            // Validate that, Cluster exists with the name
            Assert.notNull(clusterSummary, "An EMR cluster must exists with the name \"" + clusterName + "\".");

            emrCluster.setId(clusterSummary.getId());
            setEmrClusterStatus(emrCluster, clusterSummary.getStatus());
        }

        // Get active step details
        if (emrHelper.isActiveEmrState(emrCluster.getStatus())) {
            StepSummary stepSummary = emrDao.getClusterActiveStep(emrCluster.getId(), awsParamsDto);
            if (stepSummary != null) {
                EmrStep activeStep;

                // If verbose get active step details
                if (verbose) {
                    activeStep = buildEmrStepFromAwsStep(stepSummary, true);
                } else {
                    activeStep = buildEmrStepFromAwsStepSummary(stepSummary);
                }
                emrCluster.setActiveStep(activeStep);
            }
        }

        // Get requested step details
        if (StringUtils.isNotBlank(emrStepId)) {
            Step step = emrDao.getClusterStep(emrCluster.getId(), emrStepId.trim(), awsParamsDto);

            emrCluster.setStep(buildEmrStepFromAwsStep(step, verbose));
        }

        // Get instance fleet if true
        if (BooleanUtils.isTrue(retrieveInstanceFleets)) {
            ListInstanceFleetsResult listInstanceFleetsResult = emrDao
                    .getListInstanceFleetsResult(emrCluster.getId(), awsParamsDto);
            emrCluster.setInstanceFleets(
                    emrHelper.buildEmrClusterInstanceFleetFromAwsResult(listInstanceFleetsResult));
        }
    } catch (AmazonServiceException ex) {
        awsServiceHelper.handleAmazonException(ex,
                "An Amazon exception occurred while getting EMR cluster details with name \"" + clusterName
                        + "\".");
    }

    return emrCluster;
}