Search in sources :

Example 6 with StepConfig

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

the class EmrDaoImpl method getStepConfig.

/**
 * Create the step config list of objects for hive/pig installation.
 *
 * @param emrClusterDefinition the EMR definition name value.
 *
 * @return list of step configuration that contains all the steps for the given configuration.
 */
private List<StepConfig> getStepConfig(EmrClusterDefinition emrClusterDefinition) {
    StepFactory stepFactory = new StepFactory();
    List<StepConfig> appSteps = new ArrayList<>();
    // Create install hive step and add to the StepConfig list
    if (StringUtils.isNotBlank(emrClusterDefinition.getHiveVersion())) {
        StepConfig installHive = new StepConfig().withName("Hive " + emrClusterDefinition.getHiveVersion()).withActionOnFailure(ActionOnFailure.TERMINATE_JOB_FLOW).withHadoopJarStep(stepFactory.newInstallHiveStep(emrClusterDefinition.getHiveVersion()));
        appSteps.add(installHive);
    }
    // Create install Pig step and add to the StepConfig List
    if (StringUtils.isNotBlank(emrClusterDefinition.getPigVersion())) {
        StepConfig installPig = new StepConfig().withName("Pig " + emrClusterDefinition.getPigVersion()).withActionOnFailure(ActionOnFailure.TERMINATE_JOB_FLOW).withHadoopJarStep(stepFactory.newInstallPigStep(emrClusterDefinition.getPigVersion()));
        appSteps.add(installPig);
    }
    // Add the hadoop jar steps that need to be added.
    if (!CollectionUtils.isEmpty(emrClusterDefinition.getHadoopJarSteps())) {
        for (HadoopJarStep hadoopJarStep : emrClusterDefinition.getHadoopJarSteps()) {
            StepConfig stepConfig = emrHelper.getEmrHadoopJarStepConfig(hadoopJarStep.getStepName(), hadoopJarStep.getJarLocation(), hadoopJarStep.getMainClass(), hadoopJarStep.getScriptArguments(), hadoopJarStep.isContinueOnError());
            appSteps.add(stepConfig);
        }
    }
    return appSteps;
}
Also used : ArrayList(java.util.ArrayList) StepConfig(com.amazonaws.services.elasticmapreduce.model.StepConfig) StepFactory(com.amazonaws.services.elasticmapreduce.util.StepFactory) HadoopJarStep(org.finra.herd.model.api.xml.HadoopJarStep)

Example 7 with StepConfig

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

the class EmrHelperTest method testEmrHadoopJarStepConfigWithArguments.

@Test
public void testEmrHadoopJarStepConfigWithArguments() throws Exception {
    List<String> arguments = new ArrayList<>();
    arguments.add("arg1");
    StepConfig stepConfig = emrHelper.getEmrHadoopJarStepConfig("step_name", "jar_location", null, arguments, false);
    assertNotNull("step not retuned", stepConfig);
    assertEquals("name not found", "step_name", stepConfig.getName());
    assertEquals("jar not found", "jar_location", stepConfig.getHadoopJarStep().getJar());
    assertNotNull("arguments not found", stepConfig.getHadoopJarStep().getArgs());
}
Also used : ArrayList(java.util.ArrayList) StepConfig(com.amazonaws.services.elasticmapreduce.model.StepConfig) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 8 with StepConfig

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

the class EmrHelperTest method testEmrHadoopJarStepConfig.

@Test
public void testEmrHadoopJarStepConfig() throws Exception {
    StepConfig stepConfig = emrHelper.getEmrHadoopJarStepConfig("step_name", "jar_location", null, null, false);
    assertNotNull("step not retuned", stepConfig);
    assertEquals("name not found", "step_name", stepConfig.getName());
    assertEquals("jar not found", "jar_location", stepConfig.getHadoopJarStep().getJar());
}
Also used : StepConfig(com.amazonaws.services.elasticmapreduce.model.StepConfig) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 9 with StepConfig

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

the class MockEmrOperationsImpl method addJobFlowStepsRequest.

/**
 * Add Job Flow Step to AmazonElasticMapReduceClient
 */
@Override
public List<String> addJobFlowStepsRequest(AmazonElasticMapReduceClient emrClient, AddJobFlowStepsRequest addJobFlowStepsRequest) {
    if (addJobFlowStepsRequest.getSteps() != null && addJobFlowStepsRequest.getSteps().get(0) != null) {
        StepConfig firstStep = addJobFlowStepsRequest.getSteps().get(0);
        if (firstStep.getName().equals(MockAwsOperationsHelper.AMAZON_BAD_REQUEST)) {
            AmazonServiceException badRequestException = new AmazonServiceException(MockAwsOperationsHelper.AMAZON_BAD_REQUEST);
            badRequestException.setStatusCode(HttpStatus.SC_BAD_REQUEST);
            throw badRequestException;
        } else if (firstStep.getName().equals(MockAwsOperationsHelper.AMAZON_NOT_FOUND)) {
            AmazonServiceException notFoundException = new AmazonServiceException(MockAwsOperationsHelper.AMAZON_NOT_FOUND);
            notFoundException.setStatusCode(HttpStatus.SC_NOT_FOUND);
            throw notFoundException;
        } else if (firstStep.getName().equals(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION)) {
            throw new AmazonServiceException(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION);
        }
    }
    MockEmrJobFlow cluster = getClusterById(addJobFlowStepsRequest.getJobFlowId());
    if (cluster == null) {
        throw new AmazonServiceException("No Cluster exists with jobFlowId: " + addJobFlowStepsRequest.getJobFlowId());
    }
    List<String> jobIds = new ArrayList<>();
    for (StepConfig step : addJobFlowStepsRequest.getSteps()) {
        jobIds.add(addClusterStep(cluster.getJobFlowId(), step).getJobFlowId());
    }
    return jobIds;
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) ArrayList(java.util.ArrayList) StepConfig(com.amazonaws.services.elasticmapreduce.model.StepConfig) HadoopStepConfig(com.amazonaws.services.elasticmapreduce.model.HadoopStepConfig)

Example 10 with StepConfig

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

the class EmrDaoImpl method addEmrStep.

@Override
public String addEmrStep(String clusterId, StepConfig emrStepConfig, AwsParamsDto awsParamsDto) throws Exception {
    List<StepConfig> steps = new ArrayList<>();
    steps.add(emrStepConfig);
    // Add the job flow request
    AddJobFlowStepsRequest jobFlowStepRequest = new AddJobFlowStepsRequest(clusterId, steps);
    List<String> emrStepIds = emrOperations.addJobFlowStepsRequest(getEmrClient(awsParamsDto), jobFlowStepRequest);
    return emrStepIds.get(0);
}
Also used : ArrayList(java.util.ArrayList) StepConfig(com.amazonaws.services.elasticmapreduce.model.StepConfig) AddJobFlowStepsRequest(com.amazonaws.services.elasticmapreduce.model.AddJobFlowStepsRequest)

Aggregations

StepConfig (com.amazonaws.services.elasticmapreduce.model.StepConfig)12 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)5 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)4 ActionOnFailure (com.amazonaws.services.elasticmapreduce.model.ActionOnFailure)3 StepFactory (com.amazonaws.services.elasticmapreduce.util.StepFactory)3 AddJobFlowStepsRequest (com.amazonaws.services.elasticmapreduce.model.AddJobFlowStepsRequest)2 HadoopStepConfig (com.amazonaws.services.elasticmapreduce.model.HadoopStepConfig)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)1 HadoopJarStepConfig (com.amazonaws.services.elasticmapreduce.model.HadoopJarStepConfig)1 ListClustersResult (com.amazonaws.services.elasticmapreduce.model.ListClustersResult)1 List (java.util.List)1 EmrHiveStep (org.finra.herd.model.api.xml.EmrHiveStep)1 EmrPigStep (org.finra.herd.model.api.xml.EmrPigStep)1 EmrShellStep (org.finra.herd.model.api.xml.EmrShellStep)1 HadoopJarStep (org.finra.herd.model.api.xml.HadoopJarStep)1 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1