Search in sources :

Example 1 with DescribeAlarmsResult

use of com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult in project Synapse-Stack-Builder by Sage-Bionetworks.

the class ElbAlarmSetup method describeAlarms.

public DescribeAlarmsResult describeAlarms(EnvironmentDescription ed) throws InterruptedException {
    String topicArn = resources.getStackInstanceNotificationTopicArn();
    LoadBalancer loadBalancer = getLoadBalancerFromEnvironmentName(ed.getEnvironmentName());
    DescribeAlarmsRequest req = createDescribeAlarmsRequest(ed.getEnvironmentName(), loadBalancer.getName(), topicArn);
    DescribeAlarmsResult res = this.cloudWatchClient.describeAlarms(req);
    return res;
}
Also used : DescribeAlarmsResult(com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult) LoadBalancer(com.amazonaws.services.elasticbeanstalk.model.LoadBalancer) DescribeAlarmsRequest(com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest)

Example 2 with DescribeAlarmsResult

use of com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult in project Synapse-Stack-Builder by Sage-Bionetworks.

the class RdsAlarmSetup method setupAllAlarms.

/**
 * Setup all alarms.
 */
public void setupAllAlarms() {
    List<PutMetricAlarmRequest> l;
    DescribeAlarmsResult r;
    // This is the topic where all alarm notification are sent
    String topicArn = resources.getStackInstanceNotificationTopicArn();
    // setup the alarms for the id generator
    DBInstance instance = resources.getIdGeneratorDatabase();
    l = createAllAlarmsForDatabase(instance, topicArn);
    r = describeAllAlarmsForDatabase(instance);
    resources.setIdGeneratorDatabaseAlarms(r);
    // setup the alarms for the stack instances database.
    instance = resources.getStackInstancesDatabase();
    l = createAllAlarmsForDatabase(instance, topicArn);
    r = describeAllAlarmsForDatabase(instance);
    resources.setStackInstancesDatabaseAlarms(r);
    // setup the alarms for the stack table databases.
    List<DescribeAlarmsResult> lr = new ArrayList<DescribeAlarmsResult>();
    List<DBInstance> tblInstances = resources.getStackInstanceTablesDatabases();
    for (DBInstance i : tblInstances) {
        l = createAllAlarmsForDatabase(i, topicArn);
        r = describeAllAlarmsForDatabase(i);
        lr.add(r);
    }
    resources.setStackInstanceTablesDatabaseAlarms(lr);
}
Also used : PutMetricAlarmRequest(com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest) DescribeAlarmsResult(com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult) DBInstance(com.amazonaws.services.rds.model.DBInstance) ArrayList(java.util.ArrayList)

Example 3 with DescribeAlarmsResult

use of com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult in project Synapse-Stack-Builder by Sage-Bionetworks.

the class RdsAlarmSetup method describeAllAlarmsForDatabase.

public DescribeAlarmsResult describeAllAlarmsForDatabase(DBInstance instance) {
    if (instance == null)
        throw new IllegalArgumentException("DBInstance cannpt be null");
    List<String> alarmsToDescribe = this.getAlarms(instance);
    DescribeAlarmsRequest req = new DescribeAlarmsRequest().withAlarmNames(alarmsToDescribe);
    DescribeAlarmsResult res = client.describeAlarms(req);
    return res;
}
Also used : DescribeAlarmsResult(com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult) DescribeAlarmsRequest(com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest)

Example 4 with DescribeAlarmsResult

use of com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult in project photon-model by vmware.

the class AWSClientManager method getOrCreateCloudWatchClient.

/**
 * Get or create a CloudWatch Client instance that will be used to get stats from AWS.
 *
 * Note: ARN-based credentials will not be accepted unless they have already been exchanged to
 * AWS for session credentials. If unset, this method will throw a
 * {@link UnsupportedOperationException} exception in this circumstance. To enable ARN-based
 * credentials, migrate to {@link #getOrCreateCloudWatchClientAsync(AuthCredentialsServiceState,
 * String, StatelessService, boolean)}.
 *
 * @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.");
    }
    if (isArnCredentials(credentials) && !isSetCredentials(credentials)) {
        throw new UnsupportedOperationException("For ARN-based credentials, exchange for session-based access key/secret key first before retrieving the client.");
    }
    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;
}
Also used : S3_TM_CLIENT_CACHE_INITIAL_SIZE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.S3_TM_CLIENT_CACHE_INITIAL_SIZE) TransferManager(com.amazonaws.services.s3.transfer.TransferManager) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) LRUCache(com.vmware.photon.controller.model.adapters.util.LRUCache) OperationContext(com.vmware.xenon.common.OperationContext) INVALID_CLIENT_CACHE_INITIAL_SIZE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.INVALID_CLIENT_CACHE_INITIAL_SIZE) AmazonCloudWatchAsyncClient(com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClient) HashMap(java.util.HashMap) S3_CLIENT_CACHE_INITIAL_SIZE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.S3_CLIENT_CACHE_INITIAL_SIZE) AWSUtils.isArnCredentials(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.isArnCredentials) Utils(com.vmware.xenon.common.Utils) UriPaths(com.vmware.photon.controller.model.UriPaths) CW_CLIENT_CACHE_INITIAL_SIZE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.CW_CLIENT_CACHE_INITIAL_SIZE) Map(java.util.Map) INVALID_CLIENT_CACHE_MAX_SIZE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.INVALID_CLIENT_CACHE_MAX_SIZE) EXTERNAL_ID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.EXTERNAL_ID_KEY) AwsClientType(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AwsClientType) EC2_CLIENT_CACHE_MAX_SIZE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.EC2_CLIENT_CACHE_MAX_SIZE) LB_CLIENT_CACHE_INITIAL_SIZE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.LB_CLIENT_CACHE_INITIAL_SIZE) ExecutorService(java.util.concurrent.ExecutorService) AWSUtils.awsSessionCredentialsToAuthCredentialsState(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.awsSessionCredentialsToAuthCredentialsState) EC2_CLIENT_CACHE_INITIAL_SIZE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.EC2_CLIENT_CACHE_INITIAL_SIZE) AWSUtils.getArnSessionCredentialsAsync(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getArnSessionCredentialsAsync) DescribeAlarmsRequest(com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest) StatelessService(com.vmware.xenon.common.StatelessService) TILDA(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.TILDA) CompletionException(java.util.concurrent.CompletionException) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) S3_CLIENT_CACHE_MAX_SIZE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.S3_CLIENT_CACHE_MAX_SIZE) AWSUtils(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CW_CLIENT_CACHE_MAX_SIZE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.CW_CLIENT_CACHE_MAX_SIZE) AmazonElasticLoadBalancingAsyncClient(com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingAsyncClient) ARN_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.ARN_KEY) DescribeAlarmsResult(com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult) S3_TM_CLIENT_CACHE_MAX_SIZE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.S3_TM_CLIENT_CACHE_MAX_SIZE) AsyncHandler(com.amazonaws.handlers.AsyncHandler) DeferredResult(com.vmware.xenon.common.DeferredResult) LB_CLIENT_CACHE_MAX_SIZE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.LB_CLIENT_CACHE_MAX_SIZE) Collections(java.util.Collections) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) AsyncHandler(com.amazonaws.handlers.AsyncHandler) DescribeAlarmsResult(com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult) AmazonCloudWatchAsyncClient(com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClient) DescribeAlarmsRequest(com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest) CompletionException(java.util.concurrent.CompletionException)

Example 5 with DescribeAlarmsResult

use of com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult in project aws-doc-sdk-examples by awsdocs.

the class DescribeAlarms method main.

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;
        }
    }
}
Also used : MetricAlarm(com.amazonaws.services.cloudwatch.model.MetricAlarm) DescribeAlarmsResult(com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult) AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) DescribeAlarmsRequest(com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest)

Aggregations

DescribeAlarmsResult (com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult)5 DescribeAlarmsRequest (com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest)4 AsyncHandler (com.amazonaws.handlers.AsyncHandler)1 AmazonCloudWatch (com.amazonaws.services.cloudwatch.AmazonCloudWatch)1 AmazonCloudWatchAsyncClient (com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClient)1 MetricAlarm (com.amazonaws.services.cloudwatch.model.MetricAlarm)1 PutMetricAlarmRequest (com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest)1 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)1 LoadBalancer (com.amazonaws.services.elasticbeanstalk.model.LoadBalancer)1 AmazonElasticLoadBalancingAsyncClient (com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingAsyncClient)1 DBInstance (com.amazonaws.services.rds.model.DBInstance)1 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)1 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)1 UriPaths (com.vmware.photon.controller.model.UriPaths)1 ARN_KEY (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.ARN_KEY)1 EXTERNAL_ID_KEY (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.EXTERNAL_ID_KEY)1 AwsClientType (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AwsClientType)1 CW_CLIENT_CACHE_INITIAL_SIZE (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.CW_CLIENT_CACHE_INITIAL_SIZE)1 CW_CLIENT_CACHE_MAX_SIZE (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.CW_CLIENT_CACHE_MAX_SIZE)1 EC2_CLIENT_CACHE_INITIAL_SIZE (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.EC2_CLIENT_CACHE_INITIAL_SIZE)1