Search in sources :

Example 31 with EmrClusterDefinitionEntity

use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity 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

EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)31 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)24 Test (org.junit.Test)16 EmrClusterDefinitionKey (org.finra.herd.model.api.xml.EmrClusterDefinitionKey)14 EmrClusterDefinitionInformation (org.finra.herd.model.api.xml.EmrClusterDefinitionInformation)12 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)4 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)2 Parameter (org.finra.herd.model.api.xml.Parameter)2 EmrClusterAlternateKeyDto (org.finra.herd.model.dto.EmrClusterAlternateKeyDto)2 Cluster (com.amazonaws.services.elasticmapreduce.model.Cluster)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 ArrayList (java.util.ArrayList)1 Tuple (javax.persistence.Tuple)1