Search in sources :

Example 1 with AmazonElasticMapReduceClient

use of com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient in project herd by FINRAOS.

the class EmrDaoImplTest method testGetListInstanceFleetsResult.

@Test
public void testGetListInstanceFleetsResult() {
    // Create an AWS parameters DTO.
    AwsParamsDto awsParamsDto = new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
    // Create a mock AmazonElasticMapReduceClient.
    AmazonElasticMapReduceClient amazonElasticMapReduceClient = mock(AmazonElasticMapReduceClient.class);
    // Create a list instance fleets request.
    ListInstanceFleetsRequest listInstanceFleetsRequest = new ListInstanceFleetsRequest().withClusterId(EMR_CLUSTER_ID);
    // Create a list instance fleets result.
    ListInstanceFleetsResult listInstanceFleetsResult = new ListInstanceFleetsResult().withMarker(MARKER);
    // Mock the external calls.
    when(awsClientFactory.getEmrClient(awsParamsDto)).thenReturn(amazonElasticMapReduceClient);
    when(emrOperations.listInstanceFleets(amazonElasticMapReduceClient, listInstanceFleetsRequest)).thenReturn(listInstanceFleetsResult);
    // Call the method under test.
    ListInstanceFleetsResult result = emrDaoImpl.getListInstanceFleetsResult(EMR_CLUSTER_ID, awsParamsDto);
    // Verify the external calls.
    verify(awsClientFactory).getEmrClient(awsParamsDto);
    verify(emrOperations).listInstanceFleets(amazonElasticMapReduceClient, listInstanceFleetsRequest);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(listInstanceFleetsResult, result);
}
Also used : ListInstanceFleetsRequest(com.amazonaws.services.elasticmapreduce.model.ListInstanceFleetsRequest) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ListInstanceFleetsResult(com.amazonaws.services.elasticmapreduce.model.ListInstanceFleetsResult) AmazonElasticMapReduceClient(com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 2 with AmazonElasticMapReduceClient

use of com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient in project herd by FINRAOS.

the class EmrDaoImplTest method testGetActiveEmrClusterByName.

@Test
public void testGetActiveEmrClusterByName() {
    // Create an AWS parameters DTO.
    AwsParamsDto awsParamsDto = new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
    // Create a mock AmazonElasticMapReduceClient.
    AmazonElasticMapReduceClient amazonElasticMapReduceClient = mock(AmazonElasticMapReduceClient.class);
    // Create a list cluster request.
    ListClustersRequest listClustersRequest = new ListClustersRequest().withClusterStates(EMR_VALID_STATE);
    // Create a list cluster result with a non-matching cluster and a marker.
    ListClustersResult listClusterResultWithMarker = new ListClustersResult().withClusters(new ClusterSummary().withName(INVALID_VALUE)).withMarker(MARKER);
    // Create a list cluster request with marker.
    ListClustersRequest listClustersRequestWithMarker = new ListClustersRequest().withClusterStates(EMR_VALID_STATE).withMarker(MARKER);
    // Create a cluster summary.
    ClusterSummary clusterSummary = new ClusterSummary().withName(EMR_CLUSTER_NAME);
    // Create a list cluster result with the matching cluster.
    ListClustersResult listClusterResult = new ListClustersResult().withClusters(clusterSummary);
    // Mock the external calls.
    when(configurationHelper.getProperty(ConfigurationValue.EMR_VALID_STATES)).thenReturn(EMR_VALID_STATE);
    when(configurationHelper.getProperty(ConfigurationValue.FIELD_DATA_DELIMITER)).thenReturn((String) ConfigurationValue.FIELD_DATA_DELIMITER.getDefaultValue());
    when(awsClientFactory.getEmrClient(awsParamsDto)).thenReturn(amazonElasticMapReduceClient);
    when(emrOperations.listEmrClusters(amazonElasticMapReduceClient, listClustersRequest)).thenReturn(listClusterResultWithMarker);
    when(emrOperations.listEmrClusters(amazonElasticMapReduceClient, listClustersRequestWithMarker)).thenReturn(listClusterResult);
    // Call the method under test.
    ClusterSummary result = emrDaoImpl.getActiveEmrClusterByName(EMR_CLUSTER_NAME, awsParamsDto);
    // Verify the external calls.
    verify(configurationHelper).getProperty(ConfigurationValue.EMR_VALID_STATES);
    verify(configurationHelper).getProperty(ConfigurationValue.FIELD_DATA_DELIMITER);
    verify(awsClientFactory, times(2)).getEmrClient(awsParamsDto);
    verify(emrOperations, times(2)).listEmrClusters(eq(amazonElasticMapReduceClient), any(ListClustersRequest.class));
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(clusterSummary, result);
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) AmazonElasticMapReduceClient(com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient) ListClustersRequest(com.amazonaws.services.elasticmapreduce.model.ListClustersRequest) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 3 with AmazonElasticMapReduceClient

use of com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient in project herd by FINRAOS.

the class EmrDaoTest method getEmrClientAssertClientConfigurationNotSetWhenProxyPortIsNull.

@Test
public void getEmrClientAssertClientConfigurationNotSetWhenProxyPortIsNull() throws Exception {
    String httpProxyHost = "httpProxyHost";
    Integer httpProxyPort = null;
    AwsParamsDto awsParamsDto = new AwsParamsDto();
    awsParamsDto.setHttpProxyHost(httpProxyHost);
    awsParamsDto.setHttpProxyPort(httpProxyPort);
    AmazonElasticMapReduceClient amazonElasticMapReduceClient = emrDao.getEmrClient(awsParamsDto);
    ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonElasticMapReduceClient, "clientConfiguration");
    assertNotNull(clientConfiguration);
    assertNull(clientConfiguration.getProxyHost());
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) AmazonElasticMapReduceClient(com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient) ClientConfiguration(com.amazonaws.ClientConfiguration) Test(org.junit.Test)

Example 4 with AmazonElasticMapReduceClient

use of com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient in project herd by FINRAOS.

the class EmrDaoTest method getEmrClientAssertClientConfigurationSet.

@Test
public void getEmrClientAssertClientConfigurationSet() throws Exception {
    String httpProxyHost = "httpProxyHost";
    Integer httpProxyPort = 1234;
    AwsParamsDto awsParamsDto = new AwsParamsDto();
    awsParamsDto.setHttpProxyHost(httpProxyHost);
    awsParamsDto.setHttpProxyPort(httpProxyPort);
    AmazonElasticMapReduceClient amazonElasticMapReduceClient = emrDao.getEmrClient(awsParamsDto);
    ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonElasticMapReduceClient, "clientConfiguration");
    assertNotNull(clientConfiguration);
    assertEquals(httpProxyHost, clientConfiguration.getProxyHost());
    assertEquals(httpProxyPort.intValue(), clientConfiguration.getProxyPort());
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) AmazonElasticMapReduceClient(com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient) ClientConfiguration(com.amazonaws.ClientConfiguration) Test(org.junit.Test)

Example 5 with AmazonElasticMapReduceClient

use of com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient in project herd by FINRAOS.

the class AwsClientFactoryTest method testGetEmrClientCacheHitMiss.

@Test
public void testGetEmrClientCacheHitMiss() {
    // Create an AWS parameters DTO that contains both AWS credentials and proxy information.
    AwsParamsDto awsParamsDto = new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
    // Get an Amazon EMR client.
    AmazonElasticMapReduceClient amazonElasticMapReduceClient = awsClientFactory.getEmrClient(awsParamsDto);
    // Confirm a cache hit.
    assertEquals(amazonElasticMapReduceClient, awsClientFactory.getEmrClient(new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT)));
    // Confirm a cache miss due to AWS credentials.
    assertNotEquals(amazonElasticMapReduceClient, awsClientFactory.getEmrClient(new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY_2, AWS_ASSUMED_ROLE_SECRET_KEY_2, AWS_ASSUMED_ROLE_SESSION_TOKEN_2, HTTP_PROXY_HOST, HTTP_PROXY_PORT)));
    // Confirm a cache miss due to http proxy information.
    assertNotEquals(amazonElasticMapReduceClient, awsClientFactory.getEmrClient(new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST_2, HTTP_PROXY_PORT_2)));
    // Clear the cache.
    cacheManager.getCache(DaoSpringModuleConfig.HERD_CACHE_NAME).clear();
    // Confirm a cache miss due to cleared cache.
    assertNotEquals(amazonElasticMapReduceClient, awsClientFactory.getEmrClient(awsParamsDto));
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) AmazonElasticMapReduceClient(com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient) Test(org.junit.Test)

Aggregations

AmazonElasticMapReduceClient (com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient)6 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)6 Test (org.junit.Test)6 ClientConfiguration (com.amazonaws.ClientConfiguration)3 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)2 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)1 ListClustersRequest (com.amazonaws.services.elasticmapreduce.model.ListClustersRequest)1 ListClustersResult (com.amazonaws.services.elasticmapreduce.model.ListClustersResult)1 ListInstanceFleetsRequest (com.amazonaws.services.elasticmapreduce.model.ListInstanceFleetsRequest)1 ListInstanceFleetsResult (com.amazonaws.services.elasticmapreduce.model.ListInstanceFleetsResult)1