@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getLabel() == null) ? 0 : getLabel().hashCode()); hashCode = prime * hashCode + ((getDatapoints() == null) ? 0 : getDatapoints().hashCode()); return hashCode; }
/** * <p> * The data points for the specified metric. * </p> * * @param datapoints * The data points for the specified metric. * @return Returns a reference to this object so that method calls can be chained together. */ public GetMetricStatisticsResult withDatapoints(java.util.Collection<Datapoint> datapoints) { setDatapoints(datapoints); return this; }
/** * <p> * A label for the specified metric. * </p> * * @param label * A label for the specified metric. * @return Returns a reference to this object so that method calls can be chained together. */ public GetMetricStatisticsResult withLabel(String label) { setLabel(label); return this; }
/** * <p> * The datapoints for the specified metric. * </p> * <p> * Returns a reference to this object so that method calls can be chained * together. * * @param datapoints <p> * The datapoints for the specified metric. * </p> * @return A reference to this updated object so that method calls can be * chained together. */ public GetMetricStatisticsResult withDatapoints(Datapoint... datapoints) { if (getDatapoints() == null) { this.datapoints = new java.util.ArrayList<Datapoint>(datapoints.length); } for (Datapoint value : datapoints) { this.datapoints.add(value); } return this; }
public GetMetricStatisticsResult unmarshall(StaxUnmarshallerContext context) throws Exception { GetMetricStatisticsResult getMetricStatisticsResult = new GetMetricStatisticsResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return getMetricStatisticsResult; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("Label", targetDepth)) { getMetricStatisticsResult.setLabel(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("Datapoints", targetDepth)) { getMetricStatisticsResult.withDatapoints(new ArrayList<Datapoint>()); continue; } if (context.testExpression("Datapoints/member", targetDepth)) { getMetricStatisticsResult.withDatapoints(DatapointStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return getMetricStatisticsResult; } } } }
@Test public void shouldCountBytesWhenSingleDataPointReturned() throws Exception { Instant countSince = new Instant("2017-04-06T10:00:00.000Z"); Instant countTo = new Instant("2017-04-06T11:00:00.000Z"); Minutes periodTime = Minutes.minutesBetween(countSince, countTo); GetMetricStatisticsRequest metricStatisticsRequest = underTest.createMetricStatisticsRequest(STREAM, countSince, countTo, periodTime); GetMetricStatisticsResult result = new GetMetricStatisticsResult().withDatapoints(new Datapoint().withSum(1.0)); given(cloudWatch.getMetricStatistics(metricStatisticsRequest)).willReturn(result); long backlogBytes = underTest.getBacklogBytes(STREAM, countSince, countTo); assertThat(backlogBytes).isEqualTo(1L); }
for (Datapoint d : cloudWatchMetrics.getDatapoints()) { StreamMetric metric = StreamMetric.fromUnit(d.getUnit());
public GetMetricStatisticsResult unmarshall(StaxUnmarshallerContext context) throws Exception { GetMetricStatisticsResult getMetricStatisticsResult = new GetMetricStatisticsResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { int xmlEvent = context.nextEvent(); if (xmlEvent == XmlPullParser.END_DOCUMENT) break; if (xmlEvent == XmlPullParser.START_TAG) { if (context.testExpression("Label", targetDepth)) { getMetricStatisticsResult.setLabel(StringStaxUnmarshaller.getInstance() .unmarshall(context)); continue; } if (context.testExpression("Datapoints/member", targetDepth)) { getMetricStatisticsResult.withDatapoints(DatapointStaxUnmarshaller .getInstance().unmarshall(context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { break; } } } return getMetricStatisticsResult; }
@Test public void shouldCountBytesWhenMultipleDataPointsReturned() throws Exception { Instant countSince = new Instant("2017-04-06T10:00:00.000Z"); Instant countTo = new Instant("2017-04-06T11:00:00.000Z"); Minutes periodTime = Minutes.minutesBetween(countSince, countTo); GetMetricStatisticsRequest metricStatisticsRequest = underTest.createMetricStatisticsRequest(STREAM, countSince, countTo, periodTime); GetMetricStatisticsResult result = new GetMetricStatisticsResult() .withDatapoints( new Datapoint().withSum(1.0), new Datapoint().withSum(3.0), new Datapoint().withSum(2.0)); given(cloudWatch.getMetricStatistics(metricStatisticsRequest)).willReturn(result); long backlogBytes = underTest.getBacklogBytes(STREAM, countSince, countTo); assertThat(backlogBytes).isEqualTo(6L); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof GetMetricStatisticsResult == false) return false; GetMetricStatisticsResult other = (GetMetricStatisticsResult) obj; if (other.getLabel() == null ^ this.getLabel() == null) return false; if (other.getLabel() != null && other.getLabel().equals(this.getLabel()) == false) return false; if (other.getDatapoints() == null ^ this.getDatapoints() == null) return false; if (other.getDatapoints() != null && other.getDatapoints().equals(this.getDatapoints()) == false) return false; return true; }
.getMetricStatistics(request); for (final Datapoint dataPoint : result.getDatapoints()) {
/** * <p> * The data points for the specified metric. * </p> * <p> * <b>NOTE:</b> This method appends the values to the existing list (if any). Use * {@link #setDatapoints(java.util.Collection)} or {@link #withDatapoints(java.util.Collection)} if you want to * override the existing values. * </p> * * @param datapoints * The data points for the specified metric. * @return Returns a reference to this object so that method calls can be chained together. */ public GetMetricStatisticsResult withDatapoints(Datapoint... datapoints) { if (this.datapoints == null) { setDatapoints(new com.amazonaws.internal.SdkInternalList<Datapoint>(datapoints.length)); } for (Datapoint ele : datapoints) { this.datapoints.add(ele); } return this; }
/** * 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 (getLabel() != null) sb.append("Label: ").append(getLabel()).append(","); if (getDatapoints() != null) sb.append("Datapoints: ").append(getDatapoints()); sb.append("}"); return sb.toString(); }
.getMetricStatistics(request); for (final Datapoint dataPoint : result.getDatapoints()) {
/** * <p> * The datapoints for the specified metric. * </p> * <p> * Returns a reference to this object so that method calls can be chained * together. * * @param datapoints <p> * The datapoints for the specified metric. * </p> * @return A reference to this updated object so that method calls can be * chained together. */ public GetMetricStatisticsResult withDatapoints(java.util.Collection<Datapoint> datapoints) { setDatapoints(datapoints); return this; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getLabel() == null) ? 0 : getLabel().hashCode()); hashCode = prime * hashCode + ((getDatapoints() == null) ? 0 : getDatapoints().hashCode()); return hashCode; }
getMetricRequest.setMetricName(metricName); GetMetricStatisticsResult getMetricStatisticsResult = cwClient.getMetricStatistics(getMetricRequest); List<Datapoint> datapoints = getMetricStatisticsResult.getDatapoints(); for (Datapoint datapoint : datapoints) {
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof GetMetricStatisticsResult == false) return false; GetMetricStatisticsResult other = (GetMetricStatisticsResult) obj; if (other.getLabel() == null ^ this.getLabel() == null) return false; if (other.getLabel() != null && other.getLabel().equals(this.getLabel()) == false) return false; if (other.getDatapoints() == null ^ this.getDatapoints() == null) return false; if (other.getDatapoints() != null && other.getDatapoints().equals(this.getDatapoints()) == false) return false; return true; } }
/** * Gets total size in bytes of all events that remain in Kinesis stream between specified * instants. * * @return total size in bytes of all Kinesis events after specified instant */ public long getBacklogBytes( final String streamName, final Instant countSince, final Instant countTo) throws TransientKinesisException { return wrapExceptions( () -> { Minutes period = Minutes.minutesBetween(countSince, countTo); if (period.isLessThan(Minutes.ONE)) { return 0L; } GetMetricStatisticsRequest request = createMetricStatisticsRequest(streamName, countSince, countTo, period); long totalSizeInBytes = 0; GetMetricStatisticsResult result = cloudWatch.getMetricStatistics(request); for (Datapoint point : result.getDatapoints()) { totalSizeInBytes += point.getSum().longValue(); } return totalSizeInBytes; }); }
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getLabel() != null) sb.append("Label: " + getLabel() + ","); if (getDatapoints() != null) sb.append("Datapoints: " + getDatapoints()); sb.append("}"); return sb.toString(); }