Example usage for com.amazonaws.services.rds.model DescribeDBClustersResult getDBClusters

List of usage examples for com.amazonaws.services.rds.model DescribeDBClustersResult getDBClusters

Introduction

In this page you can find the example usage for com.amazonaws.services.rds.model DescribeDBClustersResult getDBClusters.

Prototype


public java.util.List<DBCluster> getDBClusters() 

Source Link

Document

Contains a list of DB clusters for the user.

Usage

From source file:jp.classmethod.aws.gradle.rds.AmazonRDSWaitClusterStatusTask.java

License:Apache License

@TaskAction
public void waitClusterForStatus() { // NOPMD
    // to enable conventionMappings feature
    String dbClusterIdentifier = getDbClusterIdentifier();
    List<String> successStatuses = getSuccessStatuses();
    List<String> waitStatuses = getWaitStatuses();
    int loopTimeout = getLoopTimeout();
    int loopWait = getLoopWait();

    if (dbClusterIdentifier == null) {
        throw new GradleException("dbClusterIdentifier is not specified");
    }//from  w w  w .  j a v  a2 s  . co m

    AmazonRDSPluginExtension ext = getProject().getExtensions().getByType(AmazonRDSPluginExtension.class);
    AmazonRDS rds = ext.getClient();

    long start = System.currentTimeMillis();
    while (true) {
        if (System.currentTimeMillis() > start + (loopTimeout * 1000)) {
            throw new GradleException("Timeout");
        }
        try {
            DescribeDBClustersResult dir = rds.describeDBClusters(
                    new DescribeDBClustersRequest().withDBClusterIdentifier(dbClusterIdentifier));
            DBCluster dbCluster = dir.getDBClusters().get(0);

            found = true;
            lastStatus = dbCluster.getStatus();
            if (successStatuses.contains(lastStatus)) {
                getLogger().info("Status of DB cluster {} is now {}.", dbClusterIdentifier, lastStatus);
                break;
            } else if (waitStatuses.contains(lastStatus)) {
                getLogger().info("Status of DB cluster {} is {}...", dbClusterIdentifier, lastStatus);
                try {
                    Thread.sleep(loopWait * 1000);
                } catch (InterruptedException e) {
                    throw new GradleException("Sleep interrupted", e);
                }
            } else {
                // fail when current status is not waitStatuses or successStatuses
                throw new GradleException(
                        "Status of " + dbClusterIdentifier + " is " + lastStatus + ".  It seems to be failed.");
            }
        } catch (DBClusterNotFoundException e) {
            throw new GradleException(dbClusterIdentifier + " does not exist", e);
        } catch (AmazonServiceException e) {
            if (found) {
                break;
            } else {
                throw new GradleException("Fail to describe instance: " + dbClusterIdentifier, e);
            }
        }
    }
}