Search in sources :

Example 6 with EmrStepHelper

use of org.finra.herd.service.helper.EmrStepHelper in project herd by FINRAOS.

the class EmrServiceImpl method addStepToClusterImpl.

/**
 * Adds step to an existing EMR Cluster.
 *
 * @param request the EMR steps add request
 *
 * @return the EMR step add object with added steps
 * @throws Exception if there were any errors while adding a step to the cluster.
 */
protected Object addStepToClusterImpl(Object request) throws Exception {
    EmrStepHelper stepHelper = emrStepHelperFactory.getStepHelper(request.getClass().getName());
    // Perform the request validation.
    validateAddStepToClusterRequest(request, stepHelper);
    // Perform the step specific validation
    stepHelper.validateAddStepRequest(request);
    // get accountId and awsParamDto
    String accountId = stepHelper.getRequestAccountId(request);
    AwsParamsDto awsParamsDto = emrHelper.getAwsParamsDtoByAcccountId(accountId);
    // Get the namespace and ensure it exists.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(stepHelper.getRequestNamespace(request));
    // Get the EMR cluster definition and ensure it exists.
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(stepHelper.getRequestNamespace(request), stepHelper.getRequestEmrClusterDefinitionName(request));
    // Update the namespace and cluster definition name in request from database.
    stepHelper.setRequestNamespace(request, namespaceEntity.getCode());
    stepHelper.setRequestEmrClusterDefinitionName(request, emrClusterDefinitionEntity.getName());
    String clusterName = emrHelper.buildEmrClusterName(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), stepHelper.getRequestEmrClusterName(request));
    Object emrStep = stepHelper.buildResponseFromRequest(request);
    try {
        String clusterId = emrHelper.getActiveEmrClusterId(stepHelper.getRequestEmrClusterId(request), clusterName, stepHelper.getRequestAccountId(request));
        stepHelper.setRequestEmrClusterId(request, clusterId);
        String stepId = emrDao.addEmrStep(clusterId, stepHelper.getEmrStepConfig(emrStep), awsParamsDto);
        stepHelper.setStepId(emrStep, stepId);
    } catch (AmazonServiceException ex) {
        handleAmazonException(ex, "An Amazon exception occurred while adding EMR step \"" + stepHelper.getRequestStepName(request) + "\" to cluster with name \"" + clusterName + "\".");
    }
    return emrStep;
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AmazonServiceException(com.amazonaws.AmazonServiceException) EmrStepHelper(org.finra.herd.service.helper.EmrStepHelper) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity)

Aggregations

EmrStepHelper (org.finra.herd.service.helper.EmrStepHelper)6 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)3 Test (org.junit.Test)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)2 EmrHadoopJarStepAddRequest (org.finra.herd.model.api.xml.EmrHadoopJarStepAddRequest)2 EmrHiveStepAddRequest (org.finra.herd.model.api.xml.EmrHiveStepAddRequest)2 EmrPigStepAddRequest (org.finra.herd.model.api.xml.EmrPigStepAddRequest)2 EmrShellStepAddRequest (org.finra.herd.model.api.xml.EmrShellStepAddRequest)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)1 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)1 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)1 Matchers.anyBoolean (org.mockito.Matchers.anyBoolean)1