Search in sources :

Example 11 with Cluster

use of com.amazonaws.services.elasticmapreduce.model.Cluster in project herd by FINRAOS.

the class EmrServiceImpl method getClusterImpl.

/**
 * 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.
 * @throws Exception if an error occurred while getting the cluster
 */
protected EmrCluster getClusterImpl(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, String emrClusterId, String emrStepId, boolean verbose, String accountId, Boolean retrieveInstanceFleets) throws Exception {
    AwsParamsDto awsParamsDto = emrHelper.getAwsParamsDtoByAcccountId(accountId);
    // Perform the request validation.
    validateEmrClusterKey(emrClusterAlternateKeyDto);
    // Get the namespace and ensure it exists.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(emrClusterAlternateKeyDto.getNamespace());
    // Get the EMR cluster definition and ensure it exists.
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName());
    EmrCluster emrCluster = createEmrClusterFromRequest(null, namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName(), accountId, null, null, null, null);
    String clusterName = emrHelper.buildEmrClusterName(namespaceEntity.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) {
        handleAmazonException(ex, "An Amazon exception occurred while getting EMR cluster details with name \"" + clusterName + "\".");
    }
    return emrCluster;
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) StepSummary(com.amazonaws.services.elasticmapreduce.model.StepSummary) ListInstanceFleetsResult(com.amazonaws.services.elasticmapreduce.model.ListInstanceFleetsResult) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) EmrCluster(org.finra.herd.model.api.xml.EmrCluster) AmazonServiceException(com.amazonaws.AmazonServiceException) EmrCluster(org.finra.herd.model.api.xml.EmrCluster) Cluster(com.amazonaws.services.elasticmapreduce.model.Cluster) EmrStep(org.finra.herd.model.api.xml.EmrStep) Step(com.amazonaws.services.elasticmapreduce.model.Step) EmrStep(org.finra.herd.model.api.xml.EmrStep) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity)

Aggregations

Cluster (com.amazonaws.services.elasticmapreduce.model.Cluster)11 Test (org.junit.Test)9 ClusterStatus (com.amazonaws.services.elasticmapreduce.model.ClusterStatus)7 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)6 EmrDao (org.finra.herd.dao.EmrDao)6 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)4 ClusterState (com.amazonaws.services.elasticmapreduce.model.ClusterState)2 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)2 DescribeClusterRequest (com.amazonaws.services.elasticmapreduce.model.DescribeClusterRequest)2 DescribeClusterResult (com.amazonaws.services.elasticmapreduce.model.DescribeClusterResult)2 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 ListInstanceFleetsResult (com.amazonaws.services.elasticmapreduce.model.ListInstanceFleetsResult)1 Step (com.amazonaws.services.elasticmapreduce.model.Step)1 StepSummary (com.amazonaws.services.elasticmapreduce.model.StepSummary)1 EmrStep (org.finra.herd.model.api.xml.EmrStep)1 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)1 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)1 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)1