Search in sources :

Example 56 with AwsParamsDto

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);
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest) Test(org.junit.Test)

Example 57 with AwsParamsDto

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))));
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) MessageHeader(org.finra.herd.model.dto.MessageHeader) SendMessageResult(com.amazonaws.services.sqs.model.SendMessageResult) Test(org.junit.Test)

Example 58 with AwsParamsDto

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();
    }
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) Cluster(com.amazonaws.services.elasticmapreduce.model.Cluster)

Example 59 with AwsParamsDto

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;
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto)

Example 60 with 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);
}
Also used : EmrClusterDefinitionDaoHelper(org.finra.herd.service.helper.EmrClusterDefinitionDaoHelper) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrServiceImpl(org.finra.herd.service.impl.EmrServiceImpl) EmrHelper(org.finra.herd.dao.helper.EmrHelper) NamespaceDaoHelper(org.finra.herd.service.helper.NamespaceDaoHelper) EmrDao(org.finra.herd.dao.EmrDao) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity) AlternateKeyHelper(org.finra.herd.service.helper.AlternateKeyHelper) Test(org.junit.Test)

Aggregations

AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)67 Test (org.junit.Test)52 InvocationOnMock (org.mockito.invocation.InvocationOnMock)13 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)11 ClientConfiguration (com.amazonaws.ClientConfiguration)9 ArrayList (java.util.ArrayList)9 ListClustersResult (com.amazonaws.services.elasticmapreduce.model.ListClustersResult)8 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)8 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)7 AmazonElasticMapReduceClient (com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 RunJobFlowRequest (com.amazonaws.services.elasticmapreduce.model.RunJobFlowRequest)5 NodeTag (org.finra.herd.model.api.xml.NodeTag)5 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)5 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)5 Cluster (com.amazonaws.services.elasticmapreduce.model.Cluster)4 DescribeClusterResult (com.amazonaws.services.elasticmapreduce.model.DescribeClusterResult)4 ListInstancesResult (com.amazonaws.services.elasticmapreduce.model.ListInstancesResult)4 List (java.util.List)4 InstanceDefinitions (org.finra.herd.model.api.xml.InstanceDefinitions)4