Search in sources :

Example 1 with Minutes

use of org.joda.time.Minutes in project beam by apache.

the class SimplifiedKinesisClient method getBacklogBytes.

/**
 * 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;
    });
}
Also used : Datapoint(com.amazonaws.services.cloudwatch.model.Datapoint) GetMetricStatisticsRequest(com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest) GetMetricStatisticsResult(com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult) Minutes(org.joda.time.Minutes)

Example 2 with Minutes

use of org.joda.time.Minutes in project beam by apache.

the class SimplifiedKinesisClientTest method shouldCountBytesWhenMultipleDataPointsReturned.

@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));
    when(cloudWatch.getMetricStatistics(metricStatisticsRequest)).thenReturn(result);
    long backlogBytes = underTest.getBacklogBytes(STREAM, countSince, countTo);
    assertThat(backlogBytes).isEqualTo(6L);
}
Also used : Datapoint(com.amazonaws.services.cloudwatch.model.Datapoint) GetMetricStatisticsRequest(com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest) Instant(org.joda.time.Instant) GetMetricStatisticsResult(com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult) Minutes(org.joda.time.Minutes) Test(org.junit.Test)

Example 3 with Minutes

use of org.joda.time.Minutes in project beam by apache.

the class SimplifiedKinesisClientTest method shouldCountBytesWhenSingleDataPointReturned.

@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);
    GetMetricStatisticsResponse result = GetMetricStatisticsResponse.builder().datapoints(Datapoint.builder().sum(1.0).build()).build();
    when(cloudWatch.getMetricStatistics(metricStatisticsRequest)).thenReturn(result);
    long backlogBytes = underTest.getBacklogBytes(STREAM, countSince, countTo);
    assertThat(backlogBytes).isEqualTo(1L);
}
Also used : GetMetricStatisticsRequest(software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsRequest) GetMetricStatisticsResponse(software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsResponse) Instant(org.joda.time.Instant) Minutes(org.joda.time.Minutes) Test(org.junit.Test)

Example 4 with Minutes

use of org.joda.time.Minutes in project beam by apache.

the class SimplifiedKinesisClientTest method shouldHandleGetBacklogBytesError.

private void shouldHandleGetBacklogBytesError(Exception thrownException, Class<? extends Exception> expectedExceptionClass) {
    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);
    when(cloudWatch.getMetricStatistics(metricStatisticsRequest)).thenThrow(thrownException);
    try {
        underTest.getBacklogBytes(STREAM, countSince, countTo);
        failBecauseExceptionWasNotThrown(expectedExceptionClass);
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(expectedExceptionClass);
    } finally {
        reset(kinesis);
    }
}
Also used : GetMetricStatisticsRequest(software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsRequest) Instant(org.joda.time.Instant) Minutes(org.joda.time.Minutes) LimitExceededException(software.amazon.awssdk.services.kinesis.model.LimitExceededException) ProvisionedThroughputExceededException(software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) ExpiredIteratorException(software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException) SdkServiceException(software.amazon.awssdk.core.exception.SdkServiceException)

Example 5 with Minutes

use of org.joda.time.Minutes in project kylo by Teradata.

the class TimerToCronExpression method getMinutesCron.

private static String getMinutesCron(Period p) {
    Integer min = p.getMinutes();
    Minutes m = p.toStandardMinutes();
    Integer minutes = m.getMinutes();
    String str = "0" + (min > 0 ? "/" + min : "");
    if (minutes > 60) {
        str = min + "";
    }
    return str;
}
Also used : Minutes(org.joda.time.Minutes)

Aggregations

Minutes (org.joda.time.Minutes)9 Instant (org.joda.time.Instant)6 GetMetricStatisticsRequest (com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest)4 Test (org.junit.Test)4 GetMetricStatisticsRequest (software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsRequest)4 Datapoint (com.amazonaws.services.cloudwatch.model.Datapoint)3 GetMetricStatisticsResult (com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult)3 GetMetricStatisticsResponse (software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsResponse)3 AmazonServiceException (com.amazonaws.AmazonServiceException)1 ExpiredIteratorException (com.amazonaws.services.kinesis.model.ExpiredIteratorException)1 LimitExceededException (com.amazonaws.services.kinesis.model.LimitExceededException)1 ProvisionedThroughputExceededException (com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException)1 SdkClientException (software.amazon.awssdk.core.exception.SdkClientException)1 SdkServiceException (software.amazon.awssdk.core.exception.SdkServiceException)1 Datapoint (software.amazon.awssdk.services.cloudwatch.model.Datapoint)1 ExpiredIteratorException (software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException)1 LimitExceededException (software.amazon.awssdk.services.kinesis.model.LimitExceededException)1 ProvisionedThroughputExceededException (software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException)1