Search in sources :

Example 1 with EmrMasterSecurityGroupAddRequest

use of org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest in project herd by FINRAOS.

the class AddEmrMasterSecurityGroup method executeImpl.

@Override
public void executeImpl(DelegateExecution execution) throws Exception {
    // Create the request.
    EmrMasterSecurityGroupAddRequest request = new EmrMasterSecurityGroupAddRequest();
    request.setNamespace(activitiHelper.getExpressionVariableAsString(namespace, execution));
    request.setEmrClusterDefinitionName(activitiHelper.getExpressionVariableAsString(emrClusterDefinitionName, execution));
    request.setEmrClusterName(activitiHelper.getExpressionVariableAsString(emrClusterName, execution));
    request.setAccountId(activitiHelper.getExpressionVariableAsString(accountId, execution));
    String groupIdStr = activitiHelper.getExpressionVariableAsString(securityGroupIds, execution);
    if (StringUtils.isBlank(groupIdStr)) {
        throw new IllegalArgumentException("At least one security group must be specified.");
    }
    request.setSecurityGroupIds(daoHelper.splitStringWithDefaultDelimiter(groupIdStr.trim()));
    // Create the cluster in a new transaction.
    EmrMasterSecurityGroup emrMasterSecurityGroup = emrService.addSecurityGroupsToClusterMaster(request);
    // Set workflow variables based on the security groups.
    setTaskWorkflowVariable(execution, VARIABLE_EMR_MASTER_SECURITY_GROUPS, herdStringHelper.buildStringWithDefaultDelimiter(emrMasterSecurityGroup.getSecurityGroupIds()));
}
Also used : EmrMasterSecurityGroup(org.finra.herd.model.api.xml.EmrMasterSecurityGroup) EmrMasterSecurityGroupAddRequest(org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest)

Example 2 with EmrMasterSecurityGroupAddRequest

use of org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest in project herd by FINRAOS.

the class EmrServiceTest method testAddSecurityGroup.

/**
 * This method tests the happy path scenario for adding security groups
 */
@Test
public void testAddSecurityGroup() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
    emrService.createCluster(request);
    // Create the Add security group.
    EmrMasterSecurityGroupAddRequest emrMasterSecurityGroupAddRequest = getNewEmrAddSecurityGroupMasterRequest(request.getEmrClusterName());
    EmrMasterSecurityGroup emrMasterSecurityGroup = emrService.addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest);
    // Validate the returned object against the input.
    assertNotNull(emrMasterSecurityGroup);
    assertTrue(emrMasterSecurityGroup.getNamespace().equals(request.getNamespace()));
    assertTrue(emrMasterSecurityGroup.getEmrClusterDefinitionName().equals(request.getEmrClusterDefinitionName()));
    assertTrue(emrMasterSecurityGroup.getEmrClusterName().equals(request.getEmrClusterName()));
}
Also used : EmrMasterSecurityGroup(org.finra.herd.model.api.xml.EmrMasterSecurityGroup) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrMasterSecurityGroupAddRequest(org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) Test(org.junit.Test)

Example 3 with EmrMasterSecurityGroupAddRequest

use of org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest in project herd by FINRAOS.

the class EmrServiceTest method testAddSecurityGroupClusterDoesNotExist.

/**
 * This method tests the scenario where cluster does not exist
 */
@Test(expected = IllegalArgumentException.class)
public void testAddSecurityGroupClusterDoesNotExist() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
    // Create the Add security group.
    EmrMasterSecurityGroupAddRequest emrMasterSecurityGroupAddRequest = getNewEmrAddSecurityGroupMasterRequest("DOES_NOT_EXIST");
    emrService.addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrMasterSecurityGroupAddRequest(org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest) Test(org.junit.Test)

Example 4 with EmrMasterSecurityGroupAddRequest

use of org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest in project herd by FINRAOS.

the class EmrServiceTest method testAddSecurityGroupAmazonException.

/**
 * This method tests the scenario where AmazonServiceException is thrown
 */
@Test(expected = AmazonServiceException.class)
public void testAddSecurityGroupAmazonException() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
    emrService.createCluster(request);
    // Create the Add security group.
    EmrMasterSecurityGroupAddRequest emrMasterSecurityGroupAddRequest = getNewEmrAddSecurityGroupMasterRequest(request.getEmrClusterName());
    emrMasterSecurityGroupAddRequest.getSecurityGroupIds().clear();
    emrMasterSecurityGroupAddRequest.getSecurityGroupIds().add(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION);
    emrService.addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrMasterSecurityGroupAddRequest(org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) Test(org.junit.Test)

Example 5 with EmrMasterSecurityGroupAddRequest

use of org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest in project herd by FINRAOS.

the class EmrServiceTest method getNewEmrAddSecurityGroupMasterRequest.

/**
 * This method fills-up the parameters required for the EMR add steps request. This is called from all the other test methods.
 */
private EmrMasterSecurityGroupAddRequest getNewEmrAddSecurityGroupMasterRequest(String clusterName) throws Exception {
    // Create the EmrMasterSecurityGroupAddRequest object
    EmrMasterSecurityGroupAddRequest request = new EmrMasterSecurityGroupAddRequest();
    // Fill in the parameters.
    request.setNamespace(NAMESPACE);
    request.setEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME);
    request.setEmrClusterName(clusterName);
    List<String> groupIds = new ArrayList<>();
    groupIds.add("A_TEST_SECURITY_GROUP");
    request.setSecurityGroupIds(groupIds);
    return request;
}
Also used : EmrMasterSecurityGroupAddRequest(org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest) ArrayList(java.util.ArrayList)

Aggregations

EmrMasterSecurityGroupAddRequest (org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest)11 Test (org.junit.Test)8 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)6 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)6 EmrMasterSecurityGroup (org.finra.herd.model.api.xml.EmrMasterSecurityGroup)4 ArrayList (java.util.ArrayList)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1 EmrShellStepAddRequest (org.finra.herd.model.api.xml.EmrShellStepAddRequest)1 EmrClusterAlternateKeyDto (org.finra.herd.model.dto.EmrClusterAlternateKeyDto)1