Java 类com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest 实例源码

项目:aws-doc-sdk-examples    文件:DescribeAlarms.java   
public static void main(String[] args) {

        final AmazonCloudWatch cw =
            AmazonCloudWatchClientBuilder.defaultClient();

        boolean done = false;
        DescribeAlarmsRequest request = new DescribeAlarmsRequest();

        while(!done) {

            DescribeAlarmsResult response = cw.describeAlarms(request);

            for(MetricAlarm alarm : response.getMetricAlarms()) {
                System.out.printf("Retrieved alarm %s", alarm.getAlarmName());
            }

            request.setNextToken(response.getNextToken());

            if(response.getNextToken() == null) {
                done = true;
            }
        }
    }
项目:aws-mock    文件:CloudWatchBaseTest.java   
/**
 * describerAlarmsTest to get the data points
 *
 * @return MetricAlarm
 */
protected final MetricAlarm describerAlarmsTest() {
    MetricAlarm metricAlarm = null;
    DescribeAlarmsRequest describeAlarmsRequest = new DescribeAlarmsRequest();
    DescribeAlarmsResult result = amazonCloudWatchClient.describeAlarms(describeAlarmsRequest);

    if (result != null && !result.getMetricAlarms().isEmpty()) {
        metricAlarm = result.getMetricAlarms().get(0);
    }

    return metricAlarm;
}
项目:photon-model    文件:AWSClientManager.java   
/**
 * Get or create a CloudWatch Client instance that will be used to get stats from AWS.
 * @param credentials
 *         The auth credentials to be used for the client creation
 * @param regionId
 *         The region of the AWS client
 * @param service
 *         The stateless service for which the operation is being performed.
 * @param isMock
 *         Indicates if this a mock request
 * @return
 */
public AmazonCloudWatchAsyncClient getOrCreateCloudWatchClient(
        AuthCredentialsServiceState credentials,
        String regionId, StatelessService service, boolean isMock,
        Consumer<Throwable> failConsumer) {
    if (this.awsClientType != AwsClientType.CLOUD_WATCH) {
        throw new UnsupportedOperationException(
                "This client manager supports only AWS " + this.awsClientType + " clients.");
    }
    String cacheKey = createCredentialRegionCacheKey(credentials, regionId);
    if (isCloudWatchClientInvalid(cacheKey)) {
        failConsumer.accept(
                new IllegalStateException("Invalid cloud watch client for key: " + cacheKey));
        return null;
    }
    AmazonCloudWatchAsyncClient amazonCloudWatchClient = null;
    try {
        amazonCloudWatchClient = this.cloudWatchClientCache.computeIfAbsent(cacheKey, key -> {
            AmazonCloudWatchAsyncClient client = AWSUtils.getStatsAsyncClient
                    (credentials, regionId, getExecutor(), isMock);
            client.describeAlarmsAsync(
                    new AsyncHandler<DescribeAlarmsRequest, DescribeAlarmsResult>() {
                        @Override
                        public void onError(Exception exception) {
                            markCloudWatchClientInvalid(service, cacheKey);
                        }

                        @Override
                        public void onSuccess(DescribeAlarmsRequest request,
                                DescribeAlarmsResult result) {
                            //noop
                        }
                    });
            return client;
        });
    } catch (Throwable e) {
        service.logSevere(e);
        failConsumer.accept(e);
    }
    return amazonCloudWatchClient;
}