use of org.finra.herd.model.api.xml.EmrHiveStep in project herd by FINRAOS.
the class EmrHiveStepHelper method buildResponseFromRequest.
@Override
public Object buildResponseFromRequest(Object stepRequest) {
EmrHiveStepAddRequest emrHiveStepAddRequest = (EmrHiveStepAddRequest) stepRequest;
EmrHiveStep step = new EmrHiveStep();
step.setNamespace(emrHiveStepAddRequest.getNamespace());
step.setEmrClusterDefinitionName(emrHiveStepAddRequest.getEmrClusterDefinitionName());
step.setEmrClusterName(emrHiveStepAddRequest.getEmrClusterName());
step.setStepName(emrHiveStepAddRequest.getStepName().trim());
step.setScriptLocation(emrHiveStepAddRequest.getScriptLocation().trim().replaceAll(getS3ManagedReplaceString(), emrHelper.getS3StagingLocation()));
// Add the script arguments
if (!CollectionUtils.isEmpty(emrHiveStepAddRequest.getScriptArguments())) {
List<String> scriptArguments = new ArrayList<>();
step.setScriptArguments(scriptArguments);
for (String argument : emrHiveStepAddRequest.getScriptArguments()) {
scriptArguments.add(argument.trim());
}
}
step.setContinueOnError(emrHiveStepAddRequest.isContinueOnError());
return step;
}
use of org.finra.herd.model.api.xml.EmrHiveStep in project herd by FINRAOS.
the class EmrRestControllerTest method testAddHiveStepToEmrCluster.
@Test
public void testAddHiveStepToEmrCluster() throws Exception {
// Create an add step request.
EmrHiveStepAddRequest emrHiveStepAddRequest = new EmrHiveStepAddRequest(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, EMR_STEP_NAME, EMR_STEP_SCRIPT_LOCATION, Arrays.asList(ATTRIBUTE_NAME_1_MIXED_CASE), CONTINUE_ON_ERROR, EMR_CLUSTER_ID, AWS_ACCOUNT_ID);
// Create an add step response.
EmrHiveStep emrHiveStep = new EmrHiveStep(EMR_STEP_ID, NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, EMR_STEP_NAME, EMR_STEP_SCRIPT_LOCATION, Arrays.asList(ATTRIBUTE_NAME_1_MIXED_CASE), CONTINUE_ON_ERROR, EMR_CLUSTER_ID);
// Mock the external calls.
when(emrService.addStepToCluster(emrHiveStepAddRequest)).thenReturn(emrHiveStep);
// Call the method under test.
EmrHiveStep result = emrRestController.addHiveStepToEmrCluster(emrHiveStepAddRequest);
// Verify the external calls.
verify(emrService).addStepToCluster(emrHiveStepAddRequest);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(emrHiveStep, result);
}
use of org.finra.herd.model.api.xml.EmrHiveStep in project herd by FINRAOS.
the class EmrHiveStepHelper method getEmrStepConfig.
@Override
public StepConfig getEmrStepConfig(Object step) {
EmrHiveStep emrHiveStep = (EmrHiveStep) step;
// Default ActionOnFailure is to cancel the execution and wait
ActionOnFailure actionOnFailure = ActionOnFailure.CANCEL_AND_WAIT;
if (emrHiveStep.isContinueOnError() != null && emrHiveStep.isContinueOnError()) {
// Override based on user input
actionOnFailure = ActionOnFailure.CONTINUE;
}
// If there are no arguments to hive script
if (CollectionUtils.isEmpty(emrHiveStep.getScriptArguments())) {
// Just build the StepConfig object and return
return new StepConfig().withName(emrHiveStep.getStepName().trim()).withActionOnFailure(actionOnFailure).withHadoopJarStep(new StepFactory().newRunHiveScriptStep(emrHiveStep.getScriptLocation().trim()));
} else // If there are arguments specified
{
// For each argument, add "-d" option
List<String> hiveArgs = new ArrayList<>();
for (String hiveArg : emrHiveStep.getScriptArguments()) {
hiveArgs.add("-d");
hiveArgs.add(hiveArg);
}
// Return the StepConfig object
return new StepConfig().withName(emrHiveStep.getStepName().trim()).withActionOnFailure(actionOnFailure).withHadoopJarStep(new StepFactory().newRunHiveScriptStep(emrHiveStep.getScriptLocation().trim(), hiveArgs.toArray(new String[hiveArgs.size()])));
}
}
use of org.finra.herd.model.api.xml.EmrHiveStep in project herd by FINRAOS.
the class EmrHelperTest method testEmrAddStepsAllTypesNegativeTestCase.
/**
* This method tests the negative test cases scenario by testing all the step types
*/
@Test
public void testEmrAddStepsAllTypesNegativeTestCase() throws Exception {
// Create a namespace entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
// Create an EMR cluster definition entity.
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
// Create EC2 on-demand pricing entities.
ec2OnDemandPricingDaoTestHelper.createEc2OnDemandPricingEntities();
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
EmrCluster emrCluster = emrService.createCluster(request);
EmrStepHelper stepHelper;
// Shell script arguments
List<String> shellScriptArgs = new ArrayList<>();
shellScriptArgs.add("Hello");
shellScriptArgs.add("herd");
shellScriptArgs.add("How Are You");
List<Object> steps = new ArrayList<>();
// Shell step parameters
EmrShellStep shellStep = new EmrShellStep(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, request.getEmrClusterName(), null, null, null, null, null, null);
shellStep.setScriptLocation("s3://test-bucket-managed/app-a/test/test_script.sh");
shellStep.setStepName("Test Shell Script");
shellStep.setScriptArguments(shellScriptArgs);
shellStep.setContinueOnError(true);
steps.add(shellStep);
// Hive step parameters
EmrHiveStep hiveStep = new EmrHiveStep(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, request.getEmrClusterName(), null, null, null, null, null, null);
hiveStep.setStepName("Test Hive");
hiveStep.setScriptLocation("s3://test-bucket-managed/app-a/test/test_hive.hql");
hiveStep.setContinueOnError(true);
steps.add(hiveStep);
// Pig step parameter
EmrPigStep pigStep = new EmrPigStep(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, request.getEmrClusterName(), null, null, null, null, null, null);
pigStep.setStepName("Test Pig");
pigStep.setContinueOnError(true);
pigStep.setScriptLocation("s3://test-bucket-managed/app-a/test/test_pig.pig");
steps.add(pigStep);
// Oozie step that includes a shell script to install oozie
shellStep = new EmrShellStep(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, request.getEmrClusterName(), null, null, null, null, null, null);
shellStep.setScriptLocation("s3://test-bucket-managed/app-a/bootstrap/install_oozie.sh");
shellStep.setStepName("Install Oozie");
List<String> shellScriptArgsOozie = new ArrayList<>();
shellScriptArgsOozie.add("s3://test-bucket-managed/app-a/bootstrap/oozie-4.0.1-distro.tar");
shellStep.setScriptArguments(shellScriptArgsOozie);
steps.add(shellStep);
// Hadoop jar step configuration
EmrHadoopJarStep hadoopJarStep = new EmrHadoopJarStep(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, request.getEmrClusterName(), null, null, null, null, null, null, null);
hadoopJarStep.setContinueOnError(true);
hadoopJarStep.setStepName("Hadoop Jar");
hadoopJarStep.setJarLocation("s3://test-bucket-managed/app-a/test/hadoop-mapreduce-examples-2.4.0.jar");
hadoopJarStep.setMainClass("wordcount");
steps.add(hadoopJarStep);
for (Object emrStep : steps) {
stepHelper = emrStepHelperFactory.getStepHelper(emrStep.getClass().getName());
emrDao.addEmrStep(emrCluster.getId(), stepHelper.getEmrStepConfig(emrStep), emrHelper.getAwsParamsDto());
}
}
Aggregations