@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DescribeClusterResult == false) return false; DescribeClusterResult other = (DescribeClusterResult) obj; if (other.getCluster() == null ^ this.getCluster() == null) return false; if (other.getCluster() != null && other.getCluster().equals(this.getCluster()) == false) return false; return true; }
public DescribeClusterResult unmarshall(JsonUnmarshallerContext context) throws Exception { DescribeClusterResult describeClusterResult = new DescribeClusterResult(); int originalDepth = context.getCurrentDepth(); String currentParentElement = context.getCurrentParentElement(); int targetDepth = originalDepth + 1; JsonToken token = context.getCurrentToken(); if (token == null) token = context.nextToken(); if (token == VALUE_NULL) { return describeClusterResult; } while (true) { if (token == null) break; if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression("Cluster", targetDepth)) { context.nextToken(); describeClusterResult.setCluster(ClusterJsonUnmarshaller.getInstance().unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) { if (context.getCurrentDepth() <= originalDepth) break; } } token = context.nextToken(); } return describeClusterResult; }
@Override public DescribeClusterResult answer(InvocationOnMock invocation) throws Throwable { DescribeClusterRequest describeClusterRequest = invocation.getArgument(1); assertEquals(clusterId, describeClusterRequest.getClusterId()); return new DescribeClusterResult(); } });
@Override public DescribeClusterResult describeClusterRequest(AmazonElasticMapReduceClient emrClient, DescribeClusterRequest describeClusterRequest) { if (describeClusterRequest.getClusterId().equalsIgnoreCase(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION)) { throw new AmazonServiceException(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION); } MockEmrJobFlow cluster = getClusterById(describeClusterRequest.getClusterId()); if (cluster != null) { return new DescribeClusterResult().withCluster(new Cluster().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)))); } else { return null; } }
/** * <p> * This output contains the details for the requested cluster. * </p> * * @param cluster * This output contains the details for the requested cluster. * @return Returns a reference to this object so that method calls can be chained together. */ public DescribeClusterResult withCluster(Cluster cluster) { setCluster(cluster); return this; }
@Test public void getEmrClusterByIdAssertReturnNullWhenDescribeClusterResponseClusterIsNull() throws Exception { String clusterId = "clusterId"; when(mockEmrOperations.describeClusterRequest(any(), any())).thenReturn(new DescribeClusterResult()); assertNull(emrDao.getEmrClusterById(clusterId, getAwsParamsDto())); }
/** * <p> * This output contains the details for the requested cluster. * </p> * * @param cluster * This output contains the details for the requested cluster. * @return Returns a reference to this object so that method calls can be chained together. */ public DescribeClusterResult withCluster(Cluster cluster) { setCluster(cluster); return this; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getCluster() == null) ? 0 : getCluster().hashCode()); return hashCode; }
@Override public DescribeClusterResult answer(InvocationOnMock invocation) throws Throwable { DescribeClusterRequest describeClusterRequest = invocation.getArgument(1); assertEquals(clusterId, describeClusterRequest.getClusterId()); DescribeClusterResult describeClusterResult = new DescribeClusterResult(); describeClusterResult.setCluster(expectedCluster); return describeClusterResult; } });
@Test public void getEmrClusterStatusByIdAssertReturnNullWhenClusterIsNull() throws Exception { String clusterId = "clusterId"; 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()); return new DescribeClusterResult(); } }); assertNull(emrDao.getEmrClusterStatusById(clusterId, getAwsParamsDto())); }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getCluster() != null) sb.append("Cluster: ").append(getCluster()); sb.append("}"); return sb.toString(); }
@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; } });
@Test public void getEmrClusterByIdAssertCallDescribeCluster() throws Exception { String clusterId = "clusterId"; Cluster expectedCluster = new Cluster(); when(mockEmrOperations.describeClusterRequest(any(), any())).thenAnswer(new Answer<DescribeClusterResult>() { @Override public DescribeClusterResult answer(InvocationOnMock invocation) throws Throwable { DescribeClusterRequest describeClusterRequest = invocation.getArgument(1); assertEquals(clusterId, describeClusterRequest.getClusterId()); DescribeClusterResult describeClusterResult = new DescribeClusterResult(); describeClusterResult.setCluster(expectedCluster); return describeClusterResult; } }); assertEquals(expectedCluster, emrDao.getEmrClusterById(clusterId, getAwsParamsDto())); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DescribeClusterResult == false) return false; DescribeClusterResult other = (DescribeClusterResult) obj; if (other.getCluster() == null ^ this.getCluster() == null) return false; if (other.getCluster() != null && other.getCluster().equals(this.getCluster()) == false) return false; return true; }
public DescribeClusterResult unmarshall(JsonUnmarshallerContext context) throws Exception { DescribeClusterResult describeClusterResult = new DescribeClusterResult(); int originalDepth = context.getCurrentDepth(); String currentParentElement = context.getCurrentParentElement(); int targetDepth = originalDepth + 1; JsonToken token = context.getCurrentToken(); if (token == null) token = context.nextToken(); if (token == VALUE_NULL) { return describeClusterResult; } while (true) { if (token == null) break; if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression("Cluster", targetDepth)) { context.nextToken(); describeClusterResult.setCluster(ClusterJsonUnmarshaller.getInstance().unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) { if (context.getCurrentDepth() <= originalDepth) break; } } token = context.nextToken(); } return describeClusterResult; }
@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, getAwsParamsDto())); }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getCluster() == null) ? 0 : getCluster().hashCode()); return hashCode; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getCluster() != null) sb.append("Cluster: ").append(getCluster()); sb.append("}"); return sb.toString(); }
RunJobFlowResult runJobResult = emr.runJobFlow(runJobFlowRequest); System.out.printf("Run JobFlowId is: %s\n", runJobResult.getJobFlowId()); while(true) { DescribeClusterRequest desc = new DescribeClusterRequest() .withClusterId(runJobResult.getJobFlowId()); DescribeClusterResult clusterResult = emr.describeCluster(desc); Cluster cluster = clusterResult.getCluster(); String status = cluster.getStatus().getState(); System.out.printf("Status: %s\n", status); if(status.equals(ClusterState.TERMINATED.toString()) || status.equals(ClusterState.TERMINATED_WITH_ERRORS.toString())) { break; } try { TimeUnit.SECONDS.sleep(30); } catch (InterruptedException e) { e.printStackTrace(); } // maybe other handle }
@Override public Cluster getEmrClusterById(String clusterId, AwsParamsDto awsParams) { Cluster cluster = null; if (StringUtils.isNotBlank(clusterId)) { DescribeClusterResult describeClusterResult = emrOperations.describeClusterRequest(getEmrClient(awsParams), new DescribeClusterRequest().withClusterId(clusterId)); if (describeClusterResult != null && describeClusterResult.getCluster() != null) { cluster = describeClusterResult.getCluster(); } } return cluster; }