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());
}
}
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);
}
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;
}
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);
}
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()));
}
Aggregations