use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.
the class AwsHelperTest method testGetAwsParamsDto.
@Test
public void testGetAwsParamsDto() throws Exception {
// Get AWS parameters DTO.
AwsParamsDto resultAwsParamsDto = awsHelper.getAwsParamsDto();
// Validate the results.
// Since local users could set environment variables with a real HTTP proxy to test the real application, we can't update the environment to test
// specific values. Instead, we can only test that the returned DTO contains the values in the environment.
assertEquals(configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_HOST), resultAwsParamsDto.getHttpProxyHost());
assertEquals(configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_PORT, Integer.class), resultAwsParamsDto.getHttpProxyPort());
assertNotNull(resultAwsParamsDto);
}
use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.
the class SqsDaoTest method testSendMessage.
@Test
public void testSendMessage() {
// Send an SQS message.
assertEquals(new SendMessageResult().withMessageId(MESSAGE_ID), sqsDao.sendMessage(new AwsParamsDto(), AWS_SQS_QUEUE_NAME, MESSAGE_TEXT, NO_MESSAGE_HEADERS));
// Send an SQS message using proxy settings.
assertEquals(new SendMessageResult().withMessageId(MESSAGE_ID), sqsDao.sendMessage(new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT), AWS_SQS_QUEUE_NAME, MESSAGE_TEXT, NO_MESSAGE_HEADERS));
// Publish an SQS message with message headers.
assertEquals(new SendMessageResult().withMessageId(MESSAGE_ID), sqsDao.sendMessage(new AwsParamsDto(), AWS_SNS_TOPIC_ARN, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE))));
}
use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.
the class EmrHelper method getActiveEmrClusterId.
/**
* Gets the ID of an active EMR cluster which matches the given criteria. If both cluster ID and cluster name is specified, the name of the actual cluster
* with the given ID must match the specified name. For cases where the cluster is not found (does not exists or not active), the method fails. All
* parameters are case-insensitive and whitespace trimmed. Blank parameters are equal to null.
*
* @param emrClusterId EMR cluster ID
* @param emrClusterName EMR cluster name
* @param accountId the account Id that EMR cluster is running under
*
* @return The cluster ID
*/
public String getActiveEmrClusterId(String emrClusterId, String emrClusterName, String accountId) {
boolean emrClusterIdSpecified = StringUtils.isNotBlank(emrClusterId);
boolean emrClusterNameSpecified = StringUtils.isNotBlank(emrClusterName);
Assert.isTrue(emrClusterIdSpecified || emrClusterNameSpecified, "One of EMR cluster ID or EMR cluster name must be specified.");
AwsParamsDto awsParamsDto = getAwsParamsDtoByAcccountId(accountId);
// Get cluster by ID first
if (emrClusterIdSpecified) {
String emrClusterIdTrimmed = emrClusterId.trim();
// Assert cluster exists
Cluster cluster = emrDao.getEmrClusterById(emrClusterIdTrimmed, awsParamsDto);
Assert.notNull(cluster, String.format("The cluster with ID \"%s\" does not exist.", emrClusterIdTrimmed));
// Assert the cluster's state is active
String emrClusterState = cluster.getStatus().getState();
Assert.isTrue(isActiveEmrState(emrClusterState), String.format("The cluster with ID \"%s\" is not active. The cluster state must be in one of %s. Current state is \"%s\"", emrClusterIdTrimmed, Arrays.toString(getActiveEmrClusterStates()), emrClusterState));
// Assert cluster name equals if cluster name was specified
if (emrClusterNameSpecified) {
String emrClusterNameTrimmed = emrClusterName.trim();
Assert.isTrue(cluster.getName().equalsIgnoreCase(emrClusterNameTrimmed), String.format("The cluster with ID \"%s\" does not match the expected name \"%s\". The actual name is \"%s\".", cluster.getId(), emrClusterNameTrimmed, cluster.getName()));
}
return cluster.getId();
} else {
String emrClusterNameTrimmed = emrClusterName.trim();
ClusterSummary clusterSummary = emrDao.getActiveEmrClusterByName(emrClusterNameTrimmed, awsParamsDto);
Assert.notNull(clusterSummary, String.format("The cluster with name \"%s\" does not exist.", emrClusterNameTrimmed));
return clusterSummary.getId();
}
}
use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.
the class AwsHelper method getAwsParamsDto.
/**
* Constructs awsParamsDto with AWS parameters.
*
* @return the AWS params DTO object.
*/
public AwsParamsDto getAwsParamsDto() {
// Get HTTP proxy configuration settings.
String httpProxyHost = configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_HOST);
Integer httpProxyPort = configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_PORT, Integer.class);
// Create an AWS parameters DTO.
AwsParamsDto awsParamsDto = new AwsParamsDto();
awsParamsDto.setHttpProxyHost(httpProxyHost);
awsParamsDto.setHttpProxyPort(httpProxyPort);
return awsParamsDto;
}
use of org.finra.herd.model.dto.AwsParamsDto 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