Search in sources :

Example 6 with EmrClusterAlternateKeyDto

use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto 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 EmrClusterAlternateKeyDto

use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.

the class EmrServiceTest method testGetEmrClusterByIdWithFleetInstance.

/**
 * This method tests the happy path scenario by providing all the parameters
 */
@Test
public void testGetEmrClusterByIdWithFleetInstance() 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_CLUSTER_STATUS_WAITING);
    configXml = xmlHelper.objectToXml(emrClusterDefinition);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, configXml);
    // 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 emrClusterGet = emrService.getCluster(emrClusterAlternateKeyDto, emrCluster.getId(), null, true, null, true);
    // 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()));
    assertNotNull(emrClusterGet.getInstanceFleets());
    assertTrue(emrClusterGet.getInstanceFleets().size() == 1);
}
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 8 with EmrClusterAlternateKeyDto

use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.

the class EmrPricingHelperTest method updateEmrClusterDefinitionWithBestPrice.

/**
 * Creates a new EMR cluster definition using the specified parameters, updates it with best price algorithm, and returns the definition.
 *
 * @param subnetId Subnet ID. Optional.
 * @param masterInstanceDefinition The master instance definition
 * @param coreInstanceDefinition The core instance definition
 * @param taskInstanceDefinition The task instance definition. Optional.
 *
 * @return Updated EMR cluster definition.
 */
private EmrClusterDefinition updateEmrClusterDefinitionWithBestPrice(String subnetId, MasterInstanceDefinition masterInstanceDefinition, InstanceDefinition coreInstanceDefinition, InstanceDefinition taskInstanceDefinition) {
    EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition();
    emrClusterDefinition.setSubnetId(subnetId);
    InstanceDefinitions instanceDefinitions = new InstanceDefinitions();
    instanceDefinitions.setMasterInstances(masterInstanceDefinition);
    instanceDefinitions.setCoreInstances(coreInstanceDefinition);
    instanceDefinitions.setTaskInstances(taskInstanceDefinition);
    emrClusterDefinition.setInstanceDefinitions(instanceDefinitions);
    emrPricingHelper.updateEmrClusterDefinitionWithBestPrice(new EmrClusterAlternateKeyDto(), emrClusterDefinition, new AwsParamsDto());
    return emrClusterDefinition;
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) InstanceDefinitions(org.finra.herd.model.api.xml.InstanceDefinitions)

Example 9 with EmrClusterAlternateKeyDto

use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.

the class EmrRestControllerTest method testTerminateEmrCluster.

@Test
public void testTerminateEmrCluster() throws Exception {
    // Create an EMR cluster key.
    EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = new EmrClusterAlternateKeyDto(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME);
    // Create an EMR cluster.
    EmrCluster emrCluster = new EmrCluster();
    emrCluster.setId(EMR_CLUSTER_ID);
    // Mock the external calls.
    when(emrService.terminateCluster(emrClusterAlternateKeyDto, OVERRIDE_TERMINATION_PROTECTION, EMR_CLUSTER_ID, AWS_ACCOUNT_ID)).thenReturn(emrCluster);
    // Call the method under test.
    EmrCluster result = emrRestController.terminateEmrCluster(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, OVERRIDE_TERMINATION_PROTECTION, EMR_CLUSTER_ID, AWS_ACCOUNT_ID);
    // Verify the external calls.
    verify(emrService).terminateCluster(emrClusterAlternateKeyDto, OVERRIDE_TERMINATION_PROTECTION, EMR_CLUSTER_ID, AWS_ACCOUNT_ID);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(emrCluster, result);
}
Also used : EmrCluster(org.finra.herd.model.api.xml.EmrCluster) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) Test(org.junit.Test)

Example 10 with EmrClusterAlternateKeyDto

use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.

the class EmrServiceTest method testGetEmrClusterByName.

/**
 * This method tests the happy path scenario by providing all the parameters
 */
@Test
public void testGetEmrClusterByName() 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 emrClusterGet = emrService.getCluster(emrClusterAlternateKeyDto, null, null, true, null, false);
    // Validate the returned object against the input.
    assertNotNull(emrCluster);
    assertNotNull(emrClusterGet);
    assertTrue(emrCluster.getNamespace().equals(emrClusterGet.getNamespace()));
    assertTrue(emrCluster.getEmrClusterDefinitionName().equals(emrClusterGet.getEmrClusterDefinitionName()));
    assertTrue(emrCluster.getEmrClusterName().equals(emrClusterGet.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

EmrClusterAlternateKeyDto (org.finra.herd.model.dto.EmrClusterAlternateKeyDto)21 Test (org.junit.Test)16 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)14 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)12 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)10 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)5 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)3 EmrShellStepAddRequest (org.finra.herd.model.api.xml.EmrShellStepAddRequest)2 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)1 EmrDao (org.finra.herd.dao.EmrDao)1 EmrHelper (org.finra.herd.dao.helper.EmrHelper)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1 EmrMasterSecurityGroupAddRequest (org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest)1 EmrShellStep (org.finra.herd.model.api.xml.EmrShellStep)1 InstanceDefinitions (org.finra.herd.model.api.xml.InstanceDefinitions)1 EmrClusterCreationLogEntity (org.finra.herd.model.jpa.EmrClusterCreationLogEntity)1 AlternateKeyHelper (org.finra.herd.service.helper.AlternateKeyHelper)1 EmrClusterDefinitionDaoHelper (org.finra.herd.service.helper.EmrClusterDefinitionDaoHelper)1