Search in sources :

Example 1 with EmrMasterSecurityGroup

use of org.finra.herd.model.api.xml.EmrMasterSecurityGroup 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 EmrMasterSecurityGroup

use of org.finra.herd.model.api.xml.EmrMasterSecurityGroup 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 EmrMasterSecurityGroup

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

the class EmrServiceWithAccountIdTest 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);
    // Create a trusting AWS account.
    trustingAccountDaoTestHelper.createTrustingAccountEntity(AWS_ACCOUNT_ID, AWS_ROLE_ARN);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequestWithAccountId();
    emrService.createCluster(request);
    // Create the Add security group.
    EmrMasterSecurityGroupAddRequest emrMasterSecurityGroupAddRequest = getNewEmrAddSecurityGroupMasterRequestWithAccountId(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 4 with EmrMasterSecurityGroup

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

the class EmrRestControllerTest method testAddGroupsToEmrClusterMaster.

@Test
public void testAddGroupsToEmrClusterMaster() throws Exception {
    // Create an add EMR master security group request.
    EmrMasterSecurityGroupAddRequest emrMasterSecurityGroupAddRequest = new EmrMasterSecurityGroupAddRequest(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, Arrays.asList(AWS_SECURITY_GROUP_ID), EMR_CLUSTER_ID, AWS_ACCOUNT_ID);
    // Create an EMR master security group.
    EmrMasterSecurityGroup emrMasterSecurityGroup = new EmrMasterSecurityGroup(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, Arrays.asList(AWS_SECURITY_GROUP_ID), EMR_CLUSTER_ID);
    // Mock the external calls.
    when(emrService.addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest)).thenReturn(emrMasterSecurityGroup);
    // Call the method under test.
    EmrMasterSecurityGroup result = emrRestController.addGroupsToEmrClusterMaster(emrMasterSecurityGroupAddRequest);
    // Verify the external calls.
    verify(emrService).addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(emrMasterSecurityGroup, result);
}
Also used : EmrMasterSecurityGroup(org.finra.herd.model.api.xml.EmrMasterSecurityGroup) EmrMasterSecurityGroupAddRequest(org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest) Test(org.junit.Test)

Example 5 with EmrMasterSecurityGroup

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

the class EmrServiceImpl method createEmrClusterMasterGroupFromRequest.

/**
 * Creates a new EMR master group object from request.
 *
 * @param namespaceCd, the namespace Code
 * @param clusterDefinitionName, the cluster definition name
 * @param clusterName, the cluster name
 * @param groupIds, the List of groupId
 *
 * @return the created EMR master group object
 */
private EmrMasterSecurityGroup createEmrClusterMasterGroupFromRequest(String namespaceCd, String clusterDefinitionName, String clusterName, List<String> groupIds) {
    // Create the EMR cluster.
    EmrMasterSecurityGroup emrMasterSecurityGroup = new EmrMasterSecurityGroup();
    emrMasterSecurityGroup.setNamespace(namespaceCd);
    emrMasterSecurityGroup.setEmrClusterDefinitionName(clusterDefinitionName);
    emrMasterSecurityGroup.setEmrClusterName(clusterName);
    emrMasterSecurityGroup.setSecurityGroupIds(groupIds);
    return emrMasterSecurityGroup;
}
Also used : EmrMasterSecurityGroup(org.finra.herd.model.api.xml.EmrMasterSecurityGroup)

Aggregations

EmrMasterSecurityGroup (org.finra.herd.model.api.xml.EmrMasterSecurityGroup)5 EmrMasterSecurityGroupAddRequest (org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest)4 Test (org.junit.Test)3 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)2 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)2