Example usage for com.amazonaws.services.rds AmazonRDSClient setRegion

List of usage examples for com.amazonaws.services.rds AmazonRDSClient setRegion

Introduction

In this page you can find the example usage for com.amazonaws.services.rds AmazonRDSClient setRegion.

Prototype

@Deprecated
public void setRegion(Region region) throws IllegalArgumentException 

Source Link

Document

An alternative to AmazonWebServiceClient#setEndpoint(String) , sets the regional endpoint for this client's service calls.

Usage

From source file:com.hangum.tadpole.aws.rds.commons.core.utils.AmazonRDSUtsils.java

License:Open Source License

/**
 * Get RDS to Tadpole UserDB data./* ww  w. java2s. co m*/
 * 
 * @param accessKey
 * @param secretKey
 * @param regionName
 * @return 
 * @throws Exception
 */
public static List<AWSRDSUserDBDAO> getDBList(String accessKey, String secretKey, String regionName)
        throws Exception {
    List<AWSRDSUserDBDAO> returnDBList = new ArrayList<AWSRDSUserDBDAO>();

    try {
        BasicAWSCredentials awsCredential = new BasicAWSCredentials(accessKey, secretKey);
        AmazonRDSClient rdsClient = new AmazonRDSClient(awsCredential);
        rdsClient.setRegion(RegionUtils.getRegion(regionName));

        DescribeDBInstancesResult describeDBInstance = rdsClient.describeDBInstances();
        List<DBInstance> listDBInstance = describeDBInstance.getDBInstances();
        for (DBInstance rdsDbInstance : listDBInstance) {
            AWSRDSUserDBDAO rdsUserDB = new AWSRDSUserDBDAO();

            // rds information
            rdsUserDB.setAccessKey(accessKey);
            rdsUserDB.setSecretKey(secretKey);
            rdsUserDB.setEndPoint(regionName);

            // ext information
            rdsUserDB.setExt1(rdsDbInstance.getDBInstanceClass());
            rdsUserDB.setExt2(rdsDbInstance.getAvailabilityZone());

            // db information
            String strDBMStype = rdsDbInstance.getEngine();
            if (strDBMStype.startsWith("sqlserver")) {
                String strEngVer = rdsDbInstance.getEngineVersion();
                //               if(strEngVer.startsWith("11")) 
                //               else strDBMStype = "MSSQL_8_LE";

                strDBMStype = DBDefine.MSSQL_DEFAULT.getDBToString();
            } else if (strDBMStype.startsWith("oracle")) {
                strDBMStype = DBDefine.ORACLE_DEFAULT.getDBToString();
            }

            rdsUserDB.setDbms_types(DBDefine.getDBDefine(strDBMStype).getDBToString());
            rdsUserDB.setDisplay_name(
                    rdsDbInstance.getDBInstanceIdentifier() + "." + rdsDbInstance.getAvailabilityZone());
            rdsUserDB.setOperation_type(DBOperationType.DEVELOP.toString());
            rdsUserDB.setDb(rdsDbInstance.getDBInstanceIdentifier());//getDBName());
            rdsUserDB.setHost(rdsDbInstance.getEndpoint().getAddress());
            rdsUserDB.setPort("" + rdsDbInstance.getEndpoint().getPort());
            rdsUserDB.setLocale(
                    rdsDbInstance.getCharacterSetName() == null ? "" : rdsDbInstance.getCharacterSetName());
            rdsUserDB.setUsers(rdsDbInstance.getMasterUsername());
            rdsUserDB.setPasswd("");

            returnDBList.add(rdsUserDB);
        }
    } catch (Exception e) {
        throw e;
    }

    return returnDBList;
}

From source file:com.optimalbi.AmazonAccount.java

License:Apache License

private void populateRDS() throws AmazonClientException {
    for (Region region : getRegions()) {
        try {/*from  w ww .  ja  v a2 s . co  m*/
            if (region.isServiceSupported(ServiceAbbreviations.RDS)) {
                AmazonRDSClient rds = new AmazonRDSClient(getCredentials().getCredentials());
                rds.setRegion(region);

                DescribeDBInstancesResult result = rds.describeDBInstances();
                List<DBInstance> instances = result.getDBInstances();

                getLogger().info("RDS, Adding " + instances.size() + " instances from " + region.getName());

                for (DBInstance i : instances) {
                    LocalRDSService temp;
                    if (i.getDBName() != null) {
                        temp = new LocalRDSService(i.getDBName(), getCredentials(), region, i, getLogger());
                    } else {
                        temp = new LocalRDSService(i.getDBInstanceIdentifier(), getCredentials(), region, i,
                                getLogger());
                    }
                    if (servicePricings != null && servicePricings.size() > 0) {
                        if (servicePricings.get(region).getRDSPricing() != null) {
                            temp.attachPricing(servicePricings.get(region).getRDSPricing());
                        }
                    }
                    services.add(temp);
                }
            } else {
                getLogger().info("RDS, NOPE from " + region.getName());
            }
        } catch (AmazonClientException e) {
            throw new AmazonClientException(region.getName() + " " + e.getMessage());
        }
        completed.set(completed.get() + 1);
    }
}

From source file:com.optimalbi.Controller.AmazonAccount.java

License:Apache License

private void populateRDS() throws AmazonClientException {
    for (Region region : getRegions()) {
        try {//from ww  w  .jav  a 2s  . co  m
            if (region.isServiceSupported(ServiceAbbreviations.RDS)) {
                //                services.addAll(RDSService.populateServices(region, getCredentials(), getLogger()));
                AmazonRDSClient rds = new AmazonRDSClient(getCredentials().getCredentials());
                rds.setRegion(region);

                DescribeDBInstancesResult result = rds.describeDBInstances();
                List<DBInstance> instances = result.getDBInstances();

                getLogger().info("RDS, Adding " + instances.size() + " instances from " + region.getName());
                services.addAll(
                        instances
                                .stream().map(i -> new LocalRDSService(i.getDBInstanceIdentifier(),
                                        getCredentials(), region, i, getLogger()))
                                .collect(Collectors.toList()));
            } else {
                getLogger().info("RDS, NOPE from " + region.getName());
            }
        } catch (AmazonClientException e) {
            throw new AmazonClientException(region.getName() + " " + e.getMessage());
        }
        completed.set(completed.get() + 1);

    }
}

From source file:com.optimalbi.Services.LocalRDSService.java

License:Apache License

public void refreshInstance() {
    AmazonRDSClient rds = new AmazonRDSClient(getCredentials().getCredentials());
    rds.setRegion(region);

    DescribeDBInstancesResult result = rds.describeDBInstances();
    List<DBInstance> instances = result.getDBInstances();
    DBInstance tempInstance = null;//w  w  w .  j  a  v a2s  .c  o  m
    for (DBInstance d : instances) {
        if (d.getDBInstanceIdentifier().equalsIgnoreCase(thisService.getDBInstanceIdentifier())) {
            tempInstance = d;
        }
    }
    if (tempInstance != null) {
        thisService = tempInstance;
    } else {
        getLogger().error("Failed to refresh " + this.serviceName());
    }
}

From source file:org.xmlsh.aws.gradle.rds.AmazonRDSPluginExtension.java

License:BSD License

private AmazonRDS initClient() {
    AwsPluginExtension aws = project.getExtensions().getByType(AwsPluginExtension.class);
    AmazonRDSClient client = aws.createClient(AmazonRDSClient.class, profileName);
    client.setRegion(aws.getActiveRegion(region));
    return client;
}