Search in sources :

Example 6 with EmrMasterSecurityGroupAddRequest

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

the class EmrServiceTest method testEmrServiceMethodsNewTx.

/**
 * This method is to get the coverage for the emr service method that starts the new transaction.
 */
@Test
public void testEmrServiceMethodsNewTx() throws Exception {
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
    try {
        emrServiceImpl.createCluster(request);
        fail("Should throw a ObjectNotFoundException.");
    } catch (ObjectNotFoundException e) {
        assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
    }
    try {
        EmrShellStepAddRequest stepRequest = getNewEmrShellStepAddRequest(request.getEmrClusterName());
        emrServiceImpl.addStepToCluster(stepRequest);
        fail("Should throw a ObjectNotFoundException.");
    } catch (ObjectNotFoundException e) {
        assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
    }
    try {
        EmrMasterSecurityGroupAddRequest emrMasterSecurityGroupAddRequest = getNewEmrAddSecurityGroupMasterRequest(request.getEmrClusterName());
        emrServiceImpl.addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest);
        fail("Should throw a ObjectNotFoundException.");
    } catch (ObjectNotFoundException e) {
        assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
    }
    try {
        EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName("test_cluster").build();
        emrServiceImpl.getCluster(emrClusterAlternateKeyDto, null, null, false, null, false);
        fail("Should throw a ObjectNotFoundException.");
    } catch (ObjectNotFoundException e) {
        assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
    }
    try {
        EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName("test_cluster").build();
        emrServiceImpl.terminateCluster(emrClusterAlternateKeyDto, false, null, null);
        fail("Should throw a ObjectNotFoundException.");
    } catch (ObjectNotFoundException e) {
        assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
    }
}
Also used : EmrMasterSecurityGroupAddRequest(org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) EmrShellStepAddRequest(org.finra.herd.model.api.xml.EmrShellStepAddRequest) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) Test(org.junit.Test)

Example 7 with EmrMasterSecurityGroupAddRequest

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

the class EmrServiceWithAccountIdTest method getNewEmrAddSecurityGroupMasterRequestWithAccountId.

/**
 * This method fills-up the parameters required for the EMR add steps request. This is called from all the other test methods.
 */
private EmrMasterSecurityGroupAddRequest getNewEmrAddSecurityGroupMasterRequestWithAccountId(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);
    // add account id
    request.setAccountId(AWS_ACCOUNT_ID);
    return request;
}
Also used : EmrMasterSecurityGroupAddRequest(org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest) ArrayList(java.util.ArrayList)

Example 8 with EmrMasterSecurityGroupAddRequest

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

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

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

the class EmrServiceTest method testAddSecurityGroupNoneSpecified.

/**
 * This method tests the scenario when at least one security group must be specified
 */
@Test(expected = IllegalArgumentException.class)
public void testAddSecurityGroupNoneSpecified() 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.setSecurityGroupIds(null);
    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)

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