Search in sources :

Example 6 with ClusterStatus

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

the class EmrHelperTest method testGetActiveEmrClusterIdAssertErrorWhenClusterIdSpecifiedAndClusterStateNotActive.

@Test
public void testGetActiveEmrClusterIdAssertErrorWhenClusterIdSpecifiedAndClusterStateNotActive() {
    EmrDao originalEmrDao = emrHelper.getEmrDao();
    EmrDao mockEmrDao = mock(EmrDao.class);
    emrHelper.setEmrDao(mockEmrDao);
    try {
        String emrClusterId = "emrClusterId";
        String emrClusterName = "emrClusterName";
        String expectedEmrClusterId = "expectedEmrClusterId";
        ClusterState actualClusterState = ClusterState.TERMINATED;
        when(mockEmrDao.getEmrClusterById(any(), any())).thenReturn(new Cluster().withId(expectedEmrClusterId).withName(emrClusterName).withStatus(new ClusterStatus().withState(actualClusterState)));
        try {
            emrHelper.getActiveEmrClusterId(emrClusterId, emrClusterName, null);
            fail();
        } catch (IllegalArgumentException e) {
            assertEquals(String.format("The cluster with ID \"%s\" is not active. The cluster state must be in one of [STARTING, BOOTSTRAPPING, RUNNING, " + "WAITING]. Current state is \"%s\"", emrClusterId, actualClusterState), e.getMessage());
        }
        verify(mockEmrDao).getEmrClusterById(eq(emrClusterId), any());
        verifyNoMoreInteractions(mockEmrDao);
    } finally {
        emrHelper.setEmrDao(originalEmrDao);
    }
}
Also used : ClusterState(com.amazonaws.services.elasticmapreduce.model.ClusterState) Cluster(com.amazonaws.services.elasticmapreduce.model.Cluster) EmrDao(org.finra.herd.dao.EmrDao) ClusterStatus(com.amazonaws.services.elasticmapreduce.model.ClusterStatus) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 7 with ClusterStatus

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

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

the class EmrDaoTest method getEmrClusterStatusByIdAssertReturnClusterState.

@Test
public void getEmrClusterStatusByIdAssertReturnClusterState() throws Exception {
    String clusterId = "clusterId";
    ClusterState expectedState = ClusterState.BOOTSTRAPPING;
    when(mockEmrOperations.describeClusterRequest(any(), any())).then(new Answer<DescribeClusterResult>() {

        @Override
        public DescribeClusterResult answer(InvocationOnMock invocation) throws Throwable {
            DescribeClusterRequest describeClusterRequest = invocation.getArgument(1);
            assertEquals(clusterId, describeClusterRequest.getClusterId());
            DescribeClusterResult describeClusterResult = new DescribeClusterResult();
            Cluster cluster = new Cluster();
            ClusterStatus status = new ClusterStatus();
            status.setState(expectedState);
            cluster.setStatus(status);
            describeClusterResult.setCluster(cluster);
            return describeClusterResult;
        }
    });
    assertEquals(expectedState.toString(), emrDao.getEmrClusterStatusById(clusterId, new AwsParamsDto()));
}
Also used : ClusterState(com.amazonaws.services.elasticmapreduce.model.ClusterState) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) DescribeClusterRequest(com.amazonaws.services.elasticmapreduce.model.DescribeClusterRequest) DescribeClusterResult(com.amazonaws.services.elasticmapreduce.model.DescribeClusterResult) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Cluster(com.amazonaws.services.elasticmapreduce.model.Cluster) ClusterStatus(com.amazonaws.services.elasticmapreduce.model.ClusterStatus) Test(org.junit.Test)

Aggregations

ClusterStatus (com.amazonaws.services.elasticmapreduce.model.ClusterStatus)8 Cluster (com.amazonaws.services.elasticmapreduce.model.Cluster)7 Test (org.junit.Test)7 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)6 EmrDao (org.finra.herd.dao.EmrDao)6 ClusterState (com.amazonaws.services.elasticmapreduce.model.ClusterState)2 ClusterStateChangeReason (com.amazonaws.services.elasticmapreduce.model.ClusterStateChangeReason)1 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)1 ClusterTimeline (com.amazonaws.services.elasticmapreduce.model.ClusterTimeline)1 DescribeClusterRequest (com.amazonaws.services.elasticmapreduce.model.DescribeClusterRequest)1 DescribeClusterResult (com.amazonaws.services.elasticmapreduce.model.DescribeClusterResult)1 ListClustersResult (com.amazonaws.services.elasticmapreduce.model.ListClustersResult)1 ArrayList (java.util.ArrayList)1 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1