use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity in project herd by FINRAOS.
the class EmrClusterDefinitionServiceTest method testUpdateEmrClusterDefinitionLowerCaseParameters.
@Test
public void testUpdateEmrClusterDefinitionLowerCaseParameters() throws Exception {
// Create and persist the namespace entity with an uppercase name.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE.toUpperCase());
// Create and persist the EMR cluster definition entity with an uppercase name using minimal test XML configuration.
EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME.toUpperCase(), getTestEmrClusterDefinitionConfigurationXml(EMR_CLUSTER_DEFINITION_XML_FILE_MINIMAL_CLASSPATH));
executeWithoutLogging(EmrClusterDefinitionServiceImpl.class, () -> {
// Update an EMR cluster definition with the normal test XML configuration by passing the EMR cluster definition name key parameters in lower case.
EmrClusterDefinitionInformation updatedEmrClusterDefinition = emrClusterDefinitionService.updateEmrClusterDefinition(new EmrClusterDefinitionKey(NAMESPACE.toLowerCase(), EMR_CLUSTER_DEFINITION_NAME.toLowerCase()), createEmrClusterDefinitionUpdateRequest(getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH)));
// Validate the returned object.
validateEmrClusterDefinition(emrClusterDefinitionEntity.getId(), NAMESPACE.toUpperCase(), EMR_CLUSTER_DEFINITION_NAME.toUpperCase(), getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH), updatedEmrClusterDefinition);
});
}
use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity in project herd by FINRAOS.
the class EmrClusterDefinitionServiceTest method testDeleteEmrClusterDefinitionTrimParameters.
@Test
public void testDeleteEmrClusterDefinitionTrimParameters() throws Exception {
// Create and persist the namespace entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
// Create and persist the EMR cluster definition entity.
EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, getTestEmrClusterDefinitionConfigurationXml(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH));
// Validate that this EMR cluster definition exists.
assertNotNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME));
executeWithoutLogging(EmrClusterDefinitionServiceImpl.class, () -> {
// Delete this EMR cluster definition by passing namespace and EMR cluster definition name with leading and trailing whitespace characters.
EmrClusterDefinitionInformation deletedEmrClusterDefinition = emrClusterDefinitionService.deleteEmrClusterDefinition(new EmrClusterDefinitionKey(addWhitespace(NAMESPACE), addWhitespace(EMR_CLUSTER_DEFINITION_NAME)));
// Validate the returned object.
validateEmrClusterDefinition(emrClusterDefinitionEntity.getId(), NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH), deletedEmrClusterDefinition);
// Ensure that this EMR cluster definition is no longer there.
assertNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME));
});
}
use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity in project herd by FINRAOS.
the class EmrClusterDefinitionServiceTest method testDeleteEmrClusterDefinitionUpperCaseParameters.
@Test
public void testDeleteEmrClusterDefinitionUpperCaseParameters() throws Exception {
// Create and persist the namespace entity with a lowercase name.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE.toLowerCase());
// Create and persist the EMR cluster definition entity with a lowercase name.
EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME.toLowerCase(), getTestEmrClusterDefinitionConfigurationXml(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH));
// Validate that this EMR cluster definition exists.
assertNotNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE.toLowerCase(), EMR_CLUSTER_DEFINITION_NAME.toLowerCase()));
executeWithoutLogging(EmrClusterDefinitionServiceImpl.class, () -> {
// Delete this EMR cluster definition by passing the EMR cluster definition name key parameters in upper case.
EmrClusterDefinitionInformation deletedEmrClusterDefinition = emrClusterDefinitionService.deleteEmrClusterDefinition(new EmrClusterDefinitionKey(NAMESPACE.toUpperCase(), EMR_CLUSTER_DEFINITION_NAME.toUpperCase()));
// Validate the returned object.
validateEmrClusterDefinition(emrClusterDefinitionEntity.getId(), NAMESPACE.toLowerCase(), EMR_CLUSTER_DEFINITION_NAME.toLowerCase(), getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH), deletedEmrClusterDefinition);
// Ensure that this EMR cluster definition is no longer there.
assertNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE.toLowerCase(), EMR_CLUSTER_DEFINITION_NAME.toLowerCase()));
});
}
use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity 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);
}
use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity in project herd by FINRAOS.
the class EmrClusterDefinitionServiceImpl method getEmrClusterDefinition.
@NamespacePermission(fields = "#emrClusterDefinitionKey?.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public EmrClusterDefinitionInformation getEmrClusterDefinition(EmrClusterDefinitionKey emrClusterDefinitionKey) throws Exception {
// Perform validate and trim of the EMR cluster definition key.
emrClusterDefinitionHelper.validateEmrClusterDefinitionKey(emrClusterDefinitionKey);
// Retrieve and ensure that a EMR cluster definition exists with the specified key.
EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterDefinitionKey);
// Create and return the EMR cluster definition object from the persisted entity.
return createEmrClusterDefinitionFromEntity(emrClusterDefinitionEntity);
}
Aggregations