Search in sources :

Example 1 with Step

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

the class EmrDaoTest method getClusterStepAssertCallsDescribeStepAndReturnsStep.

@Test
public void getClusterStepAssertCallsDescribeStepAndReturnsStep() throws Exception {
    String clusterId = "clusterId";
    String stepId = "stepId";
    Step expectedStep = new Step();
    when(mockEmrOperations.describeStepRequest(any(), any())).then(new Answer<DescribeStepResult>() {

        @Override
        public DescribeStepResult answer(InvocationOnMock invocation) throws Throwable {
            DescribeStepRequest describeStepRequest = invocation.getArgument(1);
            assertEquals(clusterId, describeStepRequest.getClusterId());
            assertEquals(stepId, describeStepRequest.getStepId());
            DescribeStepResult describeStepResult = new DescribeStepResult();
            describeStepResult.setStep(expectedStep);
            return describeStepResult;
        }
    });
    assertEquals(expectedStep, emrDao.getClusterStep(clusterId, stepId, new AwsParamsDto()));
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) DescribeStepResult(com.amazonaws.services.elasticmapreduce.model.DescribeStepResult) DescribeStepRequest(com.amazonaws.services.elasticmapreduce.model.DescribeStepRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Step(com.amazonaws.services.elasticmapreduce.model.Step) HadoopJarStep(org.finra.herd.model.api.xml.HadoopJarStep) Test(org.junit.Test)

Example 2 with Step

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

the class MockEmrOperationsImpl method describeStepRequest.

@Override
public DescribeStepResult describeStepRequest(AmazonElasticMapReduceClient emrClient, DescribeStepRequest describeStepRequest) {
    MockEmrJobFlow cluster = getClusterById(describeStepRequest.getClusterId());
    if (cluster == null) {
        throw new AmazonServiceException("No cluster found with jobFlowId: " + describeStepRequest.getClusterId());
    }
    Step stepResult = null;
    // Add steps that are in these states
    for (MockEmrJobFlow step : cluster.getSteps()) {
        if (describeStepRequest.getStepId().equalsIgnoreCase(step.getJobFlowId())) {
            HadoopStepConfig hadoopStepConfig = new HadoopStepConfig().withJar(step.getJarLocation());
            stepResult = new Step().withId(step.getJobFlowId()).withName(step.getJobFlowName()).withStatus(new StepStatus().withState(step.getStatus())).withConfig(hadoopStepConfig);
            if (stepResult.getName().equalsIgnoreCase(MOCK_STEP_WITHOUT_ID_NAME)) {
                stepResult.setId(null);
            }
            break;
        }
    }
    return new DescribeStepResult().withStep(stepResult);
}
Also used : DescribeStepResult(com.amazonaws.services.elasticmapreduce.model.DescribeStepResult) AmazonServiceException(com.amazonaws.AmazonServiceException) Step(com.amazonaws.services.elasticmapreduce.model.Step) HadoopStepConfig(com.amazonaws.services.elasticmapreduce.model.HadoopStepConfig) StepStatus(com.amazonaws.services.elasticmapreduce.model.StepStatus)

Example 3 with Step

use of com.amazonaws.services.elasticmapreduce.model.Step 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

Step (com.amazonaws.services.elasticmapreduce.model.Step)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2 DescribeStepResult (com.amazonaws.services.elasticmapreduce.model.DescribeStepResult)2 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)2 Cluster (com.amazonaws.services.elasticmapreduce.model.Cluster)1 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)1 DescribeStepRequest (com.amazonaws.services.elasticmapreduce.model.DescribeStepRequest)1 HadoopStepConfig (com.amazonaws.services.elasticmapreduce.model.HadoopStepConfig)1 ListInstanceFleetsResult (com.amazonaws.services.elasticmapreduce.model.ListInstanceFleetsResult)1 StepStatus (com.amazonaws.services.elasticmapreduce.model.StepStatus)1 StepSummary (com.amazonaws.services.elasticmapreduce.model.StepSummary)1 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)1 EmrStep (org.finra.herd.model.api.xml.EmrStep)1 HadoopJarStep (org.finra.herd.model.api.xml.HadoopJarStep)1 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)1 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1