Search in sources :

Example 6 with ClusterSummary

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

the class EmrHelperTest method testGetActiveEmrClusterIdNoIdSpecifiedAssertReturnActualClusterId.

@Test
public void testGetActiveEmrClusterIdNoIdSpecifiedAssertReturnActualClusterId() {
    EmrDao originalEmrDao = emrHelper.getEmrDao();
    EmrDao mockEmrDao = mock(EmrDao.class);
    emrHelper.setEmrDao(mockEmrDao);
    try {
        String emrClusterId = null;
        String emrClusterName = "emrClusterName";
        String expectedEmrClusterId = "expectedEmrClusterId";
        when(mockEmrDao.getActiveEmrClusterByName(any(), any())).thenReturn(new ClusterSummary().withId(expectedEmrClusterId).withName(emrClusterName));
        assertEquals(expectedEmrClusterId, emrHelper.getActiveEmrClusterId(emrClusterId, emrClusterName, null));
        verify(mockEmrDao).getActiveEmrClusterByName(eq(emrClusterName), any());
        verifyNoMoreInteractions(mockEmrDao);
    } finally {
        emrHelper.setEmrDao(originalEmrDao);
    }
}
Also used : ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) EmrDao(org.finra.herd.dao.EmrDao) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 7 with ClusterSummary

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

the class EmrDaoImplTest method testGetActiveEmrClusterByNameWhenClusterNameIsBlank.

@Test
public void testGetActiveEmrClusterByNameWhenClusterNameIsBlank() {
    // 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);
    // Call the method under test.
    ClusterSummary result = emrDaoImpl.getActiveEmrClusterByName(BLANK_TEXT, awsParamsDto);
    // Verify the external calls.
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertNull(result);
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 8 with ClusterSummary

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

the class MockEmrOperationsImpl method listEmrClusters.

@Override
public ListClustersResult listEmrClusters(AmazonElasticMapReduceClient emrClient, ListClustersRequest listClustersRequest) {
    List<ClusterSummary> clusterSummaryList = new ArrayList<>();
    for (MockEmrJobFlow cluster : emrClusters.values()) {
        if (!listClustersRequest.getClusterStates().isEmpty() && listClustersRequest.getClusterStates().contains(cluster.getStatus())) {
            ClusterSummary clusterSummary = new ClusterSummary();
            clusterSummary.withId(cluster.getJobFlowId()).withName(cluster.getJobFlowName()).withStatus(new ClusterStatus().withState(cluster.getStatus()).withStateChangeReason(new ClusterStateChangeReason().withCode(cluster.getStatusChangeReason().getCode()).withMessage(cluster.getStatusChangeReason().getMessage())).withTimeline(new ClusterTimeline().withCreationDateTime(cluster.getStatusTimeline().getCreationTime() != null ? cluster.getStatusTimeline().getCreationTime().toGregorianCalendar().getTime() : null).withEndDateTime(cluster.getStatusTimeline().getEndTime() != null ? cluster.getStatusTimeline().getEndTime().toGregorianCalendar().getTime() : null).withReadyDateTime(cluster.getStatusTimeline().getReadyTime() != null ? cluster.getStatusTimeline().getReadyTime().toGregorianCalendar().getTime() : null)));
            clusterSummaryList.add(clusterSummary);
        }
    }
    if (StringUtils.isBlank(listClustersRequest.getMarker())) {
        return new ListClustersResult().withClusters(clusterSummaryList).withMarker(MOCK_EMR_MAKER);
    } else {
        return new ListClustersResult().withClusters(clusterSummaryList);
    }
}
Also used : ClusterStateChangeReason(com.amazonaws.services.elasticmapreduce.model.ClusterStateChangeReason) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) ArrayList(java.util.ArrayList) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) ClusterStatus(com.amazonaws.services.elasticmapreduce.model.ClusterStatus) ClusterTimeline(com.amazonaws.services.elasticmapreduce.model.ClusterTimeline)

Example 9 with ClusterSummary

use of com.amazonaws.services.elasticmapreduce.model.ClusterSummary 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 10 with ClusterSummary

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

the class EmrDaoTest method getActiveEmrClusterByNameAssertOnlyReturnClusterWithMatchingName.

@Test
public void getActiveEmrClusterByNameAssertOnlyReturnClusterWithMatchingName() throws Exception {
    String clusterName = "clusterName";
    String expectedClusterId = "clusterId3";
    ListClustersResult listClustersResult = new ListClustersResult();
    listClustersResult.setClusters(new ArrayList<>());
    {
        ClusterSummary clusterSummary = new ClusterSummary();
        clusterSummary.setId("clusterId1");
        clusterSummary.setName("not_matching");
        listClustersResult.getClusters().add(clusterSummary);
    }
    {
        ClusterSummary clusterSummary = new ClusterSummary();
        clusterSummary.setId("clusterId2");
        clusterSummary.setName("");
        listClustersResult.getClusters().add(clusterSummary);
    }
    {
        ClusterSummary clusterSummary = new ClusterSummary();
        clusterSummary.setId(expectedClusterId);
        clusterSummary.setName(clusterName);
        listClustersResult.getClusters().add(clusterSummary);
    }
    when(mockEmrOperations.listEmrClusters(any(), any())).thenReturn(listClustersResult);
    ClusterSummary result = emrDao.getActiveEmrClusterByName(clusterName, new AwsParamsDto());
    assertNotNull(result);
    assertEquals(expectedClusterId, result.getId());
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) Test(org.junit.Test)

Aggregations

ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)15 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)11 Test (org.junit.Test)10 ListClustersResult (com.amazonaws.services.elasticmapreduce.model.ListClustersResult)9 ListClustersRequest (com.amazonaws.services.elasticmapreduce.model.ListClustersRequest)3 ArrayList (java.util.ArrayList)3 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2 Cluster (com.amazonaws.services.elasticmapreduce.model.Cluster)2 ListInstancesResult (com.amazonaws.services.elasticmapreduce.model.ListInstancesResult)2 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)2 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)2 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 AmazonElasticMapReduceClient (com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient)1 AddJobFlowStepsRequest (com.amazonaws.services.elasticmapreduce.model.AddJobFlowStepsRequest)1 ClusterStateChangeReason (com.amazonaws.services.elasticmapreduce.model.ClusterStateChangeReason)1 ClusterStatus (com.amazonaws.services.elasticmapreduce.model.ClusterStatus)1 ClusterTimeline (com.amazonaws.services.elasticmapreduce.model.ClusterTimeline)1 Instance (com.amazonaws.services.elasticmapreduce.model.Instance)1