Search in sources :

Example 66 with NamespaceEntity

use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.

the class EmrServiceTest method testCreateEmrClusterInstanceNotDefined.

/**
 * This method tests the error cases for Illegal Arguments for Instances not defined properly
 */
@Test
public void testCreateEmrClusterInstanceNotDefined() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    // Create the test EMR cluster definition entity with missing instance definitions.
    String configXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_MINIMAL_CLASSPATH).getInputStream());
    EmrClusterDefinition emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, configXml);
    emrClusterDefinition.setInstanceDefinitions(null);
    configXml = xmlHelper.objectToXml(emrClusterDefinition);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, configXml);
    // Try to create a new EMR cluster using EMR cluster definition with missing both instance definitions and instance fleets.
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
    try {
        emrService.createCluster(request);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("Instance group definitions or instance fleets must be specified.", e.getMessage());
    }
}
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)

Example 67 with NamespaceEntity

use of org.finra.herd.model.jpa.NamespaceEntity 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 68 with NamespaceEntity

use of org.finra.herd.model.jpa.NamespaceEntity 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 69 with NamespaceEntity

use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.

the class EmrServiceTest method testCreateEmrClusterOverrideList.

@Test
public void testCreateEmrClusterOverrideList() 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();
    EmrClusterDefinition emrClusterDefinitionOverride = new EmrClusterDefinition();
    emrClusterDefinitionOverride.setApplications(Collections.<EmrClusterDefinitionApplication>emptyList());
    expectedEmrClusterDefinition.setApplications(emrClusterDefinitionOverride.getApplications());
    emrClusterDefinitionOverride.setConfigurations(Collections.<EmrClusterDefinitionConfiguration>emptyList());
    expectedEmrClusterDefinition.setConfigurations(emrClusterDefinitionOverride.getConfigurations());
    emrClusterDefinitionOverride.setCustomBootstrapActionAll(Collections.<ScriptDefinition>emptyList());
    expectedEmrClusterDefinition.setCustomBootstrapActionAll(emrClusterDefinitionOverride.getCustomBootstrapActionAll());
    emrClusterDefinitionOverride.setCustomBootstrapActionMaster(Collections.<ScriptDefinition>emptyList());
    expectedEmrClusterDefinition.setCustomBootstrapActionMaster(emrClusterDefinitionOverride.getCustomBootstrapActionMaster());
    emrClusterDefinitionOverride.setDaemonConfigurations(Collections.<Parameter>emptyList());
    expectedEmrClusterDefinition.setDaemonConfigurations(emrClusterDefinitionOverride.getDaemonConfigurations());
    emrClusterDefinitionOverride.setHadoopConfigurations(Collections.<Serializable>emptyList());
    expectedEmrClusterDefinition.setHadoopConfigurations(emrClusterDefinitionOverride.getHadoopConfigurations());
    emrClusterDefinitionOverride.setHadoopJarSteps(Collections.<HadoopJarStep>emptyList());
    expectedEmrClusterDefinition.setHadoopJarSteps(emrClusterDefinitionOverride.getHadoopJarSteps());
    emrClusterDefinitionOverride.setAdditionalMasterSecurityGroups(Collections.emptyList());
    expectedEmrClusterDefinition.setAdditionalMasterSecurityGroups(emrClusterDefinitionOverride.getAdditionalMasterSecurityGroups());
    emrClusterDefinitionOverride.setAdditionalSlaveSecurityGroups(Collections.emptyList());
    expectedEmrClusterDefinition.setAdditionalSlaveSecurityGroups(emrClusterDefinitionOverride.getAdditionalSlaveSecurityGroups());
    List<NodeTag> nodeTags = expectedEmrClusterDefinition.getNodeTags();
    nodeTags.add(new NodeTag("testTag", "test"));
    emrClusterDefinitionOverride.setNodeTags(nodeTags);
    expectedEmrClusterDefinition.setNodeTags(nodeTags);
    request.setEmrClusterDefinitionOverride(emrClusterDefinitionOverride);
    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());
    assertTrue(emrCluster.isEmrClusterCreated());
    assertNotNull(emrCluster.getEmrClusterDefinition());
    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) NodeTag(org.finra.herd.model.api.xml.NodeTag) EmrCluster(org.finra.herd.model.api.xml.EmrCluster) Test(org.junit.Test)

Example 70 with NamespaceEntity

use of org.finra.herd.model.jpa.NamespaceEntity 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)

Aggregations

NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)225 Test (org.junit.Test)139 ArrayList (java.util.ArrayList)63 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)59 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)43 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)40 Predicate (javax.persistence.criteria.Predicate)39 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)38 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)32 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)25 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)24 NamespaceIamRoleAuthorizationEntity (org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)24 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)18 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)16 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)14 EmrClusterDefinitionKey (org.finra.herd.model.api.xml.EmrClusterDefinitionKey)13 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)13 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)13 StorageEntity (org.finra.herd.model.jpa.StorageEntity)13 EmrClusterDefinitionInformation (org.finra.herd.model.api.xml.EmrClusterDefinitionInformation)12