use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.
the class EmrServiceTest method testGetEmrClusterById.
/**
* This method tests the happy path scenario by providing all the parameters
*/
@Test
public void testGetEmrClusterById() 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, 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()));
// Terminate the cluster and validate.
emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, null);
emrClusterGet = emrService.getCluster(emrClusterAlternateKeyDto, emrCluster.getId(), null, true, null, 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()));
}
use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.
the class EmrServiceTest method testGetEmrClusterByIdWithStepId.
/**
* This method tests the scenario with providing step Id.
*/
@Test
public void testGetEmrClusterByIdWithStepId() 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);
// Add a running step
// Create the Add step request.
EmrShellStepAddRequest stepRequest = getNewEmrShellStepAddRequest(request.getEmrClusterName());
stepRequest.setStepName(MockEmrOperationsImpl.MOCK_STEP_RUNNING_NAME);
EmrShellStep emrShellStep = (EmrShellStep) emrService.addStepToCluster(stepRequest);
String stepId = emrShellStep.getId();
EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName(request.getEmrClusterName()).build();
EmrCluster emrClusterGet = emrService.getCluster(emrClusterAlternateKeyDto, emrCluster.getId(), stepId, true, null, 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()));
assertTrue(stepId.equals(emrClusterGet.getActiveStep().getId()));
assertTrue(stepId.equals(emrClusterGet.getStep().getId()));
// Test the non verbose flow
emrClusterGet = emrService.getCluster(emrClusterAlternateKeyDto, emrCluster.getId(), stepId, false, null, 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()));
assertTrue(stepId.equals(emrClusterGet.getActiveStep().getId()));
assertTrue(stepId.equals(emrClusterGet.getStep().getId()));
}
use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.
the class EmrServiceTest method testTerminateEmrClusterAmazonException.
/**
* This method tests the scenario where AmazonServiceException is thrown
*/
@Test(expected = AmazonServiceException.class)
public void testTerminateEmrClusterAmazonException() 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();
request.setEmrClusterName(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION);
emrService.createCluster(request);
EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName(request.getEmrClusterName()).build();
emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, null);
}
use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.
the class EmrServiceTest method testGetEmrClusterByIdAmazonException.
/**
* This method tests the scenario with AmazonServiceException.
*/
@Test(expected = AmazonServiceException.class)
public void testGetEmrClusterByIdAmazonException() 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()));
EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName("test").build();
emrService.getCluster(emrClusterAlternateKeyDto, MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION, null, true, null, false);
fail("Should throw an AmazonServiceException.");
}
use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.
the class EmrServiceTest method testTerminateEmrClusterWithClusterId.
@Test
public void testTerminateEmrClusterWithClusterId() throws Exception {
EmrService emrService = new EmrServiceImpl();
AlternateKeyHelper mockAlternateKeyHelper = mock(AlternateKeyHelper.class);
ReflectionTestUtils.setField(emrService, "alternateKeyHelper", mockAlternateKeyHelper);
EmrHelper mockEmrHelper = mock(EmrHelper.class);
ReflectionTestUtils.setField(emrService, "emrHelper", mockEmrHelper);
EmrDao mockEmrDao = mock(EmrDao.class);
ReflectionTestUtils.setField(emrService, "emrDao", mockEmrDao);
NamespaceDaoHelper mockNamespaceDaoHelper = mock(NamespaceDaoHelper.class);
ReflectionTestUtils.setField(emrService, "namespaceDaoHelper", mockNamespaceDaoHelper);
EmrClusterDefinitionDaoHelper mockEmrClusterDefinitionDaoHelper = mock(EmrClusterDefinitionDaoHelper.class);
ReflectionTestUtils.setField(emrService, "emrClusterDefinitionDaoHelper", mockEmrClusterDefinitionDaoHelper);
String namespace = "namespace";
String emrClusterDefinitionName = "emrClusterDefinitionName";
String emrClusterName = "emrClusterName";
boolean overrideTerminationProtection = false;
String emrClusterId = "emrClusterId";
EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = new EmrClusterAlternateKeyDto();
emrClusterAlternateKeyDto.setNamespace(namespace);
emrClusterAlternateKeyDto.setEmrClusterDefinitionName(emrClusterDefinitionName);
emrClusterAlternateKeyDto.setEmrClusterName(emrClusterName);
AwsParamsDto awsParamsDto = new AwsParamsDto();
when(mockEmrHelper.getAwsParamsDtoByAcccountId(any())).thenReturn(awsParamsDto);
NamespaceEntity namespaceEntity = new NamespaceEntity();
when(mockNamespaceDaoHelper.getNamespaceEntity(any())).thenReturn(namespaceEntity);
EmrClusterDefinitionEntity emrClusterDefinitionEntity = new EmrClusterDefinitionEntity();
when(mockEmrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(any(), any())).thenReturn(emrClusterDefinitionEntity);
String buildEmrClusterNameResult = "buildEmrClusterNameResult";
when(mockEmrHelper.buildEmrClusterName(any(), any(), any())).thenReturn(buildEmrClusterNameResult);
when(mockEmrHelper.getActiveEmrClusterId(any(), any(), any())).thenReturn(buildEmrClusterNameResult);
when(mockEmrDao.getEmrClusterStatusById(any(), any())).thenReturn(buildEmrClusterNameResult);
emrService.terminateCluster(emrClusterAlternateKeyDto, overrideTerminationProtection, emrClusterId, null);
verify(mockAlternateKeyHelper).validateStringParameter("namespace", namespace);
verify(mockAlternateKeyHelper).validateStringParameter("An", "EMR cluster definition name", emrClusterDefinitionName);
verify(mockAlternateKeyHelper).validateStringParameter("An", "EMR cluster name", emrClusterName);
verify(mockNamespaceDaoHelper).getNamespaceEntity(emrClusterAlternateKeyDto.getNamespace());
verify(mockEmrClusterDefinitionDaoHelper).getEmrClusterDefinitionEntity(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName());
verify(mockEmrHelper).buildEmrClusterName(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName());
verify(mockEmrHelper).getActiveEmrClusterId(emrClusterId, buildEmrClusterNameResult, null);
verify(mockEmrDao).terminateEmrCluster(buildEmrClusterNameResult, overrideTerminationProtection, awsParamsDto);
verify(mockEmrDao).getEmrClusterStatusById(buildEmrClusterNameResult, awsParamsDto);
// verifyNoMoreInteractions(mockEmrHelper, mockNamespaceDaoHelper, mockEmrClusterDefinitionDaoHelper, mockEmrDao);
}
Aggregations