Search in sources :

Example 86 with EmrClusterDefinition

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

the class EmrServiceWithAccountIdTest method testGetEmrClusterById.

@Test
public void testGetEmrClusterById() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    // Create a trusting AWS account.
    trustingAccountDaoTestHelper.createTrustingAccountEntity(AWS_ACCOUNT_ID, AWS_ROLE_ARN);
    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_CLUSTER_STATUS_WAITING);
    configXml = xmlHelper.objectToXml(emrClusterDefinition);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, configXml);
    // Create a new EMR cluster create request
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequestWithAccountId();
    EmrCluster emrCluster = emrService.createCluster(request);
    EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName(request.getEmrClusterName()).build();
    EmrCluster emrClusterGet = emrService.getCluster(emrClusterAlternateKeyDto, emrCluster.getId(), null, true, AWS_ACCOUNT_ID, false);
    // Validate the returned object against the input.
    assertNotNull(emrCluster);
    assertNotNull(emrClusterGet);
    assertTrue(emrCluster.getId().equals(emrClusterGet.getId()));
    assertTrue(emrCluster.getNamespace().equals(emrClusterGet.getNamespace()));
    assertTrue(emrCluster.getEmrClusterDefinitionName().equals(emrClusterGet.getEmrClusterDefinitionName()));
    assertTrue(emrCluster.getEmrClusterName().equals(emrClusterGet.getEmrClusterName()));
    assertEquals(emrCluster.getEmrClusterDefinition().getAccountId(), AWS_ACCOUNT_ID);
    assertEquals(AWS_ACCOUNT_ID, emrCluster.getAccountId());
    // Terminate the cluster and validate.
    emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, AWS_ACCOUNT_ID);
    emrClusterGet = emrService.getCluster(emrClusterAlternateKeyDto, emrCluster.getId(), null, true, AWS_ACCOUNT_ID, false);
    // Validate the returned object against the input.
    assertNotNull(emrCluster);
    assertNotNull(emrClusterGet);
    assertTrue(emrCluster.getId().equals(emrClusterGet.getId()));
    assertTrue(emrCluster.getNamespace().equals(emrClusterGet.getNamespace()));
    assertTrue(emrCluster.getEmrClusterDefinitionName().equals(emrClusterGet.getEmrClusterDefinitionName()));
    assertTrue(emrCluster.getEmrClusterName().equals(emrClusterGet.getEmrClusterName()));
    assertEquals(emrCluster.getEmrClusterDefinition().getAccountId(), AWS_ACCOUNT_ID);
}
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) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) Test(org.junit.Test)

Example 87 with EmrClusterDefinition

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

the class EmrServiceWithAccountIdTest method testCreateEmrClusterWithAccountId.

@Test
public void testCreateEmrClusterWithAccountId() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    // Create a trusting AWS account.
    trustingAccountDaoTestHelper.createTrustingAccountEntity(AWS_ACCOUNT_ID, AWS_ROLE_ARN);
    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 and add an account id to the EMR cluster definition override.
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequestWithAccountId();
    EmrClusterDefinition emrClusterDefinitionOverride = new EmrClusterDefinition();
    request.setEmrClusterDefinitionOverride(emrClusterDefinitionOverride);
    emrClusterDefinitionOverride.setAccountId(AWS_ACCOUNT_ID);
    // Create an EMR cluster.
    EmrCluster emrCluster = emrService.createCluster(request);
    // Update the expected EMR cluster definition with the account id.
    expectedEmrClusterDefinition.setAccountId(AWS_ACCOUNT_ID);
    // 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()));
    assertEquals(AWS_ACCOUNT_ID, emrCluster.getAccountId());
    assertNotNull(emrCluster.getId());
    assertNull(emrCluster.isDryRun());
    assertNotNull(emrCluster.getEmrClusterDefinition());
    assertTrue(emrCluster.isEmrClusterCreated());
    assertEquals(expectedEmrClusterDefinition, emrCluster.getEmrClusterDefinition());
    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 88 with EmrClusterDefinition

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

the class EmrHelperTest method testGetActiveEmrClusterByName.

@Test
public void testGetActiveEmrClusterByName() throws Exception {
    // Get the EMR cluster definition object
    String configXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream());
    EmrClusterDefinition emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, configXml);
    // check cluster summary before creation
    ClusterSummary clusterSummary = emrDao.getActiveEmrClusterByName(MockEmrOperationsImpl.MOCK_CLUSTER_NAME, emrHelper.getAwsParamsDto());
    assertNull(clusterSummary);
    // Create the cluster
    String clusterId = emrDao.createEmrCluster(MockEmrOperationsImpl.MOCK_CLUSTER_NAME, emrClusterDefinition, emrHelper.getAwsParamsDto());
    // check cluster summary after creation
    clusterSummary = emrDao.getActiveEmrClusterByName(MockEmrOperationsImpl.MOCK_CLUSTER_NAME, emrHelper.getAwsParamsDto());
    assertNotNull(clusterSummary);
    assertEquals(clusterId, clusterSummary.getId());
}
Also used : EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 89 with EmrClusterDefinition

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

the class EmrClusterDefinitionHelperTest method testValidateEmrClusterDefinitionConfigurationMasterMaxSearchPriceNegative.

/**
 * Tests case where validation is run against the definition generated by createValidEmrClusterDefinition() The master instance max search price is
 * negative. The definition is not valid. All prices must be positive.
 */
@Test
public void testValidateEmrClusterDefinitionConfigurationMasterMaxSearchPriceNegative() {
    EmrClusterDefinition emrClusterDefinition = createValidEmrClusterDefinition();
    emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceMaxSearchPrice(BigDecimal.ONE.negate());
    try {
        emrClusterDefinitionHelper.validateEmrClusterDefinitionConfiguration(emrClusterDefinition);
        fail("expected IllegalArgumentException, but no exception was thrown");
    } catch (Exception e) {
        assertEquals("thrown exception", IllegalArgumentException.class, e.getClass());
    }
}
Also used : EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 90 with EmrClusterDefinition

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

the class EmrClusterDefinitionHelperTest method testValidateEmrClusterDefinitionConfigurationCoreInstanceSpecifiedInstanceCountNegative.

@Test
public void testValidateEmrClusterDefinitionConfigurationCoreInstanceSpecifiedInstanceCountNegative() {
    EmrClusterDefinition emrClusterDefinition = createValidEmrClusterDefinition();
    emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceCount(-1);
    try {
        emrClusterDefinitionHelper.validateEmrClusterDefinitionConfiguration(emrClusterDefinition);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("At least 0 core instance must be specified.", e.getMessage());
    }
}
Also used : EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Aggregations

EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)101 Test (org.junit.Test)94 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)40 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)39 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)25 InstanceDefinition (org.finra.herd.model.api.xml.InstanceDefinition)24 MasterInstanceDefinition (org.finra.herd.model.api.xml.MasterInstanceDefinition)23 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)20 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)18 NodeTag (org.finra.herd.model.api.xml.NodeTag)12 EmrClusterDefinitionKey (org.finra.herd.model.api.xml.EmrClusterDefinitionKey)9 InstanceDefinitions (org.finra.herd.model.api.xml.InstanceDefinitions)8 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)7 ArrayList (java.util.ArrayList)6 RunJobFlowRequest (com.amazonaws.services.elasticmapreduce.model.RunJobFlowRequest)5 HashMap (java.util.HashMap)5 EmrClusterDefinitionInformation (org.finra.herd.model.api.xml.EmrClusterDefinitionInformation)5 EmrClusterAlternateKeyDto (org.finra.herd.model.dto.EmrClusterAlternateKeyDto)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 EmrClusterDefinitionInstanceFleet (org.finra.herd.model.api.xml.EmrClusterDefinitionInstanceFleet)4