Search in sources :

Example 6 with EmrClusterCreateRequest

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

the class EmrServiceTest method testTerminateEmrCluster.

/**
 * This method tests the happy path scenario by providing all the parameters
 */
@Test
public void testTerminateEmrCluster() 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 a new EMR cluster create request
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
    EmrCluster emrCluster = emrService.createCluster(request);
    EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName(request.getEmrClusterName()).build();
    EmrCluster emrClusterTerminated = emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, null);
    // Validate the returned object against the input.
    assertNotNull(emrCluster);
    assertNotNull(emrClusterTerminated);
    assertTrue(emrCluster.getNamespace().equals(emrClusterTerminated.getNamespace()));
    assertTrue(emrCluster.getEmrClusterDefinitionName().equals(emrClusterTerminated.getEmrClusterDefinitionName()));
    assertTrue(emrCluster.getEmrClusterName().equals(emrClusterTerminated.getEmrClusterName()));
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) EmrCluster(org.finra.herd.model.api.xml.EmrCluster) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) Test(org.junit.Test)

Example 7 with EmrClusterCreateRequest

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

the class EmrServiceTest method testCreateEmrClusterDuplicate.

@Test
public void testCreateEmrClusterDuplicate() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    String definitionXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream());
    EmrClusterDefinition expectedEmrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, definitionXml);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, definitionXml);
    // Create a new EMR cluster create request
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
    emrService.createCluster(request);
    EmrCluster emrCluster = emrService.createCluster(request);
    // Validate the returned object against the input.
    assertNotNull(emrCluster);
    assertTrue(emrCluster.getNamespace().equals(request.getNamespace()));
    assertTrue(emrCluster.getEmrClusterDefinitionName().equals(request.getEmrClusterDefinitionName()));
    assertTrue(emrCluster.getEmrClusterName().equals(request.getEmrClusterName()));
    assertNotNull(emrCluster.getId());
    assertNull(emrCluster.isDryRun());
    assertFalse(emrCluster.isEmrClusterCreated());
    assertNull(emrCluster.getEmrClusterDefinition());
    // should throw if not unique
    validateEmrClusterCreationLogUnique(emrCluster, expectedEmrClusterDefinition);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) EmrCluster(org.finra.herd.model.api.xml.EmrCluster) Test(org.junit.Test)

Example 8 with EmrClusterCreateRequest

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

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

the class EmrServiceTest method testCreateEmrClusterInvalidParameters.

@Test
public void testCreateEmrClusterInvalidParameters() throws Exception {
    // Try to perform a create when namespace contains a forward slash character.
    try {
        EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
        request.setNamespace(addSlash(request.getNamespace()));
        emrService.createCluster(request);
        fail("Should throw an IllegalArgumentException when namespace contains a forward slash character.");
    } catch (IllegalArgumentException e) {
        assertEquals("Namespace can not contain a forward slash character.", e.getMessage());
    }
    // Try to perform a create when EMR cluster definition name contains a forward slash character.
    try {
        EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
        request.setEmrClusterDefinitionName(addSlash(request.getEmrClusterDefinitionName()));
        emrService.createCluster(request);
        fail("Should throw an IllegalArgumentException when EMR cluster definition name contains a forward slash character.");
    } catch (IllegalArgumentException e) {
        assertEquals("EMR cluster definition name can not contain a forward slash character.", e.getMessage());
    }
    // Try to perform a create when EMR cluster name contains a forward slash character.
    try {
        EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
        request.setEmrClusterName(addSlash(request.getEmrClusterName()));
        emrService.createCluster(request);
        fail("Should throw an IllegalArgumentException when EMR cluster name contains a forward slash character.");
    } catch (IllegalArgumentException e) {
        assertEquals("EMR cluster name can not contain a forward slash character.", e.getMessage());
    }
}
Also used : EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) Test(org.junit.Test)

Example 10 with EmrClusterCreateRequest

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

the class EmrServiceTest method testCreateEmrClusterAmazonOtherException.

/**
 * This method tests the error cases for AmazonExceptions for AmazonServiceException
 */
@Test(expected = AmazonServiceException.class)
public void testCreateEmrClusterAmazonOtherException() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    String configXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_MINIMAL_CLASSPATH).getInputStream());
    EmrClusterDefinition emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, configXml);
    emrClusterDefinition.setAmiVersion(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION);
    configXml = xmlHelper.objectToXml(emrClusterDefinition);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, configXml);
    // Create a new EMR cluster create request.
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
    emrService.createCluster(request);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) Test(org.junit.Test)

Aggregations

EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)68 Test (org.junit.Test)64 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)59 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)39 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)33 EmrClusterAlternateKeyDto (org.finra.herd.model.dto.EmrClusterAlternateKeyDto)10 EmrShellStepAddRequest (org.finra.herd.model.api.xml.EmrShellStepAddRequest)9 ArrayList (java.util.ArrayList)6 EmrMasterSecurityGroupAddRequest (org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest)6 EmrClusterDefinitionInstanceFleet (org.finra.herd.model.api.xml.EmrClusterDefinitionInstanceFleet)3 EmrHadoopJarStep (org.finra.herd.model.api.xml.EmrHadoopJarStep)3 EmrHadoopJarStepAddRequest (org.finra.herd.model.api.xml.EmrHadoopJarStepAddRequest)3 EmrShellStep (org.finra.herd.model.api.xml.EmrShellStep)3 Serializable (java.io.Serializable)2 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 EmrHiveStepAddRequest (org.finra.herd.model.api.xml.EmrHiveStepAddRequest)2 EmrMasterSecurityGroup (org.finra.herd.model.api.xml.EmrMasterSecurityGroup)2 EmrPigStepAddRequest (org.finra.herd.model.api.xml.EmrPigStepAddRequest)2