Search in sources :

Example 41 with AwsParamsDto

use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.

the class EmrDaoTest method getEmrMasterInstanceReturnsInstance.

@Test
public void getEmrMasterInstanceReturnsInstance() throws Exception {
    String clusterId = "clusterId";
    Instance expectedInstance = new Instance();
    /*
         * Stub EmrOperations.listClusterInstancesRequest() and assert correct parameters are being passed into the method when the call is made.
         */
    when(mockEmrOperations.listClusterInstancesRequest(any(), any())).thenAnswer(new Answer<ListInstancesResult>() {

        @Override
        public ListInstancesResult answer(InvocationOnMock invocation) throws Throwable {
            /*
                 * Assert correct parameters are used when calling this method.
                 */
            ListInstancesRequest listInstancesRequest = invocation.getArgument(1);
            assertEquals(clusterId, listInstancesRequest.getClusterId());
            List<String> instanceGroupTypes = listInstancesRequest.getInstanceGroupTypes();
            assertEquals(1, instanceGroupTypes.size());
            assertEquals("MASTER", instanceGroupTypes.get(0));
            ListInstancesResult listInstancesResult = new ListInstancesResult();
            listInstancesResult.setInstances(Arrays.asList(expectedInstance));
            return listInstancesResult;
        }
    });
    Instance actualInstance = emrDao.getEmrMasterInstance(clusterId, new AwsParamsDto());
    assertEquals(expectedInstance, actualInstance);
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ListInstancesResult(com.amazonaws.services.elasticmapreduce.model.ListInstancesResult) Instance(com.amazonaws.services.elasticmapreduce.model.Instance) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ListInstancesRequest(com.amazonaws.services.elasticmapreduce.model.ListInstancesRequest) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 42 with AwsParamsDto

use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.

the class EmrDaoTest method getEmrClientAssertClientConfigurationNotSetWhenProxyHostIsBlank.

@Test
public void getEmrClientAssertClientConfigurationNotSetWhenProxyHostIsBlank() throws Exception {
    String 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);
    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 43 with AwsParamsDto

use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.

the class EmrDaoTest method addEmrMasterSecurityGroupsCallsEc2AddSecurityGroup.

@Test
public void addEmrMasterSecurityGroupsCallsEc2AddSecurityGroup() throws Exception {
    String clusterName = "clusterName";
    List<String> securityGroups = Arrays.asList("securityGroup");
    AwsParamsDto awsParams = new AwsParamsDto();
    String ec2InstanceId = "ec2InstanceId";
    ListClustersResult listClustersResult = new ListClustersResult();
    listClustersResult.setClusters(new ArrayList<>());
    ClusterSummary clusterSummary = new ClusterSummary();
    clusterSummary.setId("clusterId");
    clusterSummary.setName(clusterName);
    listClustersResult.getClusters().add(clusterSummary);
    when(mockEmrOperations.listEmrClusters(any(), any())).thenReturn(listClustersResult);
    ListInstancesResult listInstancesResult = new ListInstancesResult();
    listInstancesResult.setInstances(new ArrayList<>());
    Instance instance = new Instance();
    instance.setEc2InstanceId(ec2InstanceId);
    listInstancesResult.getInstances().add(instance);
    when(mockEmrOperations.listClusterInstancesRequest(any(), any())).thenReturn(listInstancesResult);
    emrDao.addEmrMasterSecurityGroups(clusterName, securityGroups, awsParams);
    verify(mockEc2Dao).addSecurityGroupsToEc2Instance(eq(ec2InstanceId), eq(securityGroups), any());
    verifyNoMoreInteractions(mockEc2Dao);
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ListInstancesResult(com.amazonaws.services.elasticmapreduce.model.ListInstancesResult) Instance(com.amazonaws.services.elasticmapreduce.model.Instance) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) Test(org.junit.Test)

Example 44 with AwsParamsDto

use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.

the class EmrDaoTest method getActiveEmrClusterByNameAssertReturnNullWhenClusterNameIsBlank.

@Test
public void getActiveEmrClusterByNameAssertReturnNullWhenClusterNameIsBlank() throws Exception {
    String clusterName = "";
    when(mockEmrOperations.listEmrClusters(any(), any())).thenReturn(new ListClustersResult());
    assertNull(emrDao.getActiveEmrClusterByName(clusterName, new AwsParamsDto()));
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) Test(org.junit.Test)

Example 45 with AwsParamsDto

use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.

the class EmrDaoTest method getClusterActiveStepAssertCallListStepsAndReturnStepSummary.

@Test
public void getClusterActiveStepAssertCallListStepsAndReturnStepSummary() throws Exception {
    String clusterId = "clusterId";
    StepSummary expectedStepSummary = new StepSummary();
    when(mockEmrOperations.listStepsRequest(any(), any())).then(new Answer<ListStepsResult>() {

        @Override
        public ListStepsResult answer(InvocationOnMock invocation) throws Throwable {
            ListStepsRequest listStepsRequest = invocation.getArgument(1);
            assertEquals(clusterId, listStepsRequest.getClusterId());
            assertEquals(1, listStepsRequest.getStepStates().size());
            assertEquals(StepState.RUNNING.toString(), listStepsRequest.getStepStates().get(0));
            ListStepsResult listStepsResult = new ListStepsResult();
            listStepsResult.setSteps(new ArrayList<>());
            listStepsResult.getSteps().add(expectedStepSummary);
            return listStepsResult;
        }
    });
    assertEquals(expectedStepSummary, emrDao.getClusterActiveStep(clusterId, new AwsParamsDto()));
}
Also used : ListStepsResult(com.amazonaws.services.elasticmapreduce.model.ListStepsResult) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) StepSummary(com.amazonaws.services.elasticmapreduce.model.StepSummary) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) ListStepsRequest(com.amazonaws.services.elasticmapreduce.model.ListStepsRequest) 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