List of usage examples for com.amazonaws.services.rds.model DBInstance getEndpoint
public Endpoint getEndpoint()
Specifies the connection endpoint.
From source file:RDSManager.java
public String createRDS() { String endPointAddr = null;/* www .j av a 2s.co m*/ try { System.out.println("Creating RDS"); CreateDBParameterGroupRequest cdpgr = new CreateDBParameterGroupRequest(); cdpgr.setDBParameterGroupName(DB_PARAM_GROUP_NAME); cdpgr.setDescription(DB_PARAM_GROU_DESC); cdpgr.setDBParameterGroupFamily(DB_PARAM_GROUP_FAMILY); rds.createDBParameterGroup(cdpgr); Collection<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter().withParameterName("max_connections").withParameterValue("200") .withApplyMethod("immediate")); parameters.add(new Parameter().withParameterName("max_allowed_packet").withParameterValue("999999") .withApplyMethod("immediate")); rds.modifyDBParameterGroup(new ModifyDBParameterGroupRequest() .withDBParameterGroupName(DB_PARAM_GROUP_NAME).withParameters(parameters)); /// create configuration of instance CreateDBInstanceRequest cdbir = new CreateDBInstanceRequest(); cdbir.setEngine(RDS_ENGINE); cdbir.setEngineVersion(ENGINE_VERSION); cdbir.setLicenseModel(LICENSE_MODEL); cdbir.setAutoMinorVersionUpgrade(AUTO_MINOR_VERSION_UPGRADE); cdbir.setDBInstanceClass(DB_INSTANCE_TYPE); cdbir.setMultiAZ(MULTI_AZ); cdbir.setAllocatedStorage(ALLOCATED_STORAGE); cdbir.setDBInstanceIdentifier(DBInstanceIdentifier); cdbir.setMasterUsername(MASTER_USER_NAME); cdbir.setMasterUserPassword(MasterUserPassword); cdbir.setDBName(DB_NAME); cdbir.setPort(DB_PORT); cdbir.setBackupRetentionPeriod(BackupRetentionPeriod); cdbir.setPubliclyAccessible(PubliclyAccessible); cdbir.setDBParameterGroupName(DB_PARAM_GROUP_NAME); ArrayList<String> arrDbSecur = new ArrayList<String>(); arrDbSecur.add(SECURITY_GROUP_NAME); cdbir.setDBSecurityGroups(arrDbSecur); System.out.println("Creating RDS DB Instance"); // creating instance DBInstance dbi = rds.createDBInstance(cdbir); // wait till instance created boolean isWaiting = true; while (isWaiting) { Thread.sleep(30000); DescribeDBInstancesRequest request = new DescribeDBInstancesRequest(); request.setDBInstanceIdentifier(dbi.getDBInstanceIdentifier()); DescribeDBInstancesResult result = rds.describeDBInstances(request); List<DBInstance> d = result.getDBInstances(); Iterator<DBInstance> i = d.iterator(); while (i.hasNext()) { DBInstance d1 = i.next(); System.out.println("RDS Status : " + d1.getDBInstanceStatus()); if (d1.getDBInstanceStatus().equals("available")) { isWaiting = false; System.out.println("RDS Endpoint Address : " + d1.getEndpoint().getAddress()); endPointAddr = d1.getEndpoint().getAddress(); } } } } catch (Exception e) { e.printStackTrace(); } return endPointAddr; }
From source file:beanstalk.BeansDatabase.java
License:Apache License
public String getDBEndpoint(String AWSKeyId, String AWSSecretKey, String dbname) {//throws Exception { String endpoint_str = ""; BasicAWSCredentials basic_credentials = new BasicAWSCredentials(AWSKeyId, AWSSecretKey); AmazonRDSClient rDSClient = new AmazonRDSClient(basic_credentials); ModifyDBInstanceRequest mod_db = new ModifyDBInstanceRequest(dbname + "cloud4soaid"); DBInstance dbInstance = new DBInstance(); ////CHECK THIS. in order to make correct ModifyDBInstanceRequest an attribute must be sent for modification. ///5 (GB) is the minimum mod_db.setAllocatedStorage(6);/*from ww w . jav a 2s .c o m*/ dbInstance = rDSClient.modifyDBInstance(mod_db); Endpoint endpoint = new Endpoint(); endpoint = dbInstance.getEndpoint(); if (endpoint != null) { endpoint_str = endpoint.getAddress(); System.out.println("endpoint to string:" + endpoint_str);/////{Address: cloud4soadbid.coaodqyxxykq.us-east-1.rds.amazonaws.com, Port: 3306, } System.out.println("endpoint get address:" + endpoint.getAddress());/////cloud4soadbid.coaodqyxxykq.us-east-1.rds.amazonaws.com } return endpoint_str; }
From source file:beanstalk.BeansDatabase.java
License:Apache License
public boolean deleteDatabase(String AWSKeyId, String AWSSecretKey, String dbIdentifier) {//throws Exception { boolean ret = false; // credentials = new PropertiesCredentials(BeanstalkDeployNoGUI.class.getResourceAsStream("AwsCredentials.properties")) BasicAWSCredentials basic_credentials = new BasicAWSCredentials(AWSKeyId, AWSSecretKey); // SimpleDBUtils simpledb= new SimpleDBUtils(); AmazonRDSClient rDSClient = new AmazonRDSClient(basic_credentials); // RestoreDBInstanceFromDBSnapshotRequest req= new RestoreDBInstanceFromDBSnapshotRequest(); // req.setDBName("dbname"); // req.setPort(3306); DescribeDBInstancesRequest ddbi = new DescribeDBInstancesRequest(); DBInstance dbins = new DBInstance(); dbins.getEndpoint(); DeleteDBInstanceRequest delRequest = new DeleteDBInstanceRequest(dbIdentifier); // rDSClient.restoreDBInstanceFromDBSnapshot(req); delRequest.setSkipFinalSnapshot(true); rDSClient.deleteDBInstance(delRequest); return ret;/*from w w w . j a v a2s.co m*/ }
From source file:com.airbnb.billow.RDSInstance.java
public RDSInstance(DBInstance instance, DBCluster cluster, List<Tag> tagList) { this.allocatedStorage = instance.getAllocatedStorage(); this.autoMinorVersionUpgrade = instance.getAutoMinorVersionUpgrade(); this.availabilityZone = instance.getAvailabilityZone(); this.backupRetentionPeriod = instance.getBackupRetentionPeriod(); this.characterSetName = instance.getCharacterSetName(); this.dBInstanceClass = instance.getDBInstanceClass(); this.dBInstanceIdentifier = instance.getDBInstanceIdentifier(); this.dBInstanceStatus = instance.getDBInstanceStatus(); this.dBClusterIdentifier = instance.getDBClusterIdentifier(); this.dBName = instance.getDBName(); this.dBParameterGroups = instance.getDBParameterGroups(); this.dBSecurityGroups = instance.getDBSecurityGroups(); this.dBSubnetGroup = instance.getDBSubnetGroup(); this.endpoint = instance.getEndpoint(); if (this.endpoint != null) { this.hostname = endpoint.getAddress(); this.privateIP = getPrivateIp(hostname); } else {//from w w w .ja v a 2 s .c o m this.hostname = null; this.privateIP = null; } this.engine = instance.getEngine(); this.engineVersion = instance.getEngineVersion(); this.instanceCreateTime = instance.getInstanceCreateTime(); this.iops = instance.getIops(); this.latestRestorableTime = instance.getLatestRestorableTime(); this.licenseModel = instance.getLicenseModel(); this.masterUsername = instance.getMasterUsername(); this.multiAZ = instance.getMultiAZ(); this.optionGroupMemberships = instance.getOptionGroupMemberships(); this.pendingModifiedValues = instance.getPendingModifiedValues(); this.preferredBackupWindow = instance.getPreferredBackupWindow(); this.preferredMaintenanceWindow = instance.getPreferredMaintenanceWindow(); this.publiclyAccessible = instance.getPubliclyAccessible(); this.readReplicaDBInstanceIdentifiers = instance.getReadReplicaDBInstanceIdentifiers(); this.readReplicaSourceDBInstanceIdentifier = instance.getReadReplicaSourceDBInstanceIdentifier(); this.secondaryAvailabilityZone = instance.getSecondaryAvailabilityZone(); this.statusInfos = instance.getStatusInfos(); this.vpcSecurityGroups = instance.getVpcSecurityGroups(); this.isMaster = checkIfMaster(instance, cluster); this.tags = new HashMap<>(tagList.size()); for (Tag tag : tagList) { this.tags.put(tag.getKey(), tag.getValue()); } }
From source file:com.amediamanager.dao.RdsDbEndpointRetriever.java
License:Apache License
@Override public List<Endpoint> getReadReplicaEndpoints(String dbInstanceId) { List<Endpoint> endpoints = null; DescribeDBInstancesResult result = rds .describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbInstanceId)); // If the master exist and has any read replicas if (result.getDBInstances().size() == 1 && result.getDBInstances().get(0).getReadReplicaDBInstanceIdentifiers().size() > 0) { endpoints = new ArrayList<Endpoint>(); for (String readReplicaId : result.getDBInstances().get(0).getReadReplicaDBInstanceIdentifiers()) { DBInstance rrInstance = rds .describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier(readReplicaId)) .getDBInstances().get(0); if (rrInstance.getDBInstanceStatus().equals("available")) { endpoints.add(rrInstance.getEndpoint()); }//from ww w . j a v a2s .c o m } if (endpoints.size() == 0) { endpoints = null; } } return endpoints; }
From source file:com.cloudera.director.aws.rds.RDSInstance.java
License:Apache License
/** * Returns the private IP address of the specified RDS instance. * * @param dbInstance the RDS instance/*from www. j a va 2 s . c om*/ * @return the private IP address of the specified RDS instance */ private static InetAddress getPrivateIpAddress(DBInstance dbInstance) { Preconditions.checkNotNull(dbInstance, "dbInstance is null"); InetAddress privateIpAddress = null; try { Endpoint endpoint = dbInstance.getEndpoint(); if (endpoint != null) { String endpointAddress = endpoint.getAddress(); if (endpointAddress != null) { privateIpAddress = InetAddress.getByName(endpointAddress); } } } catch (UnknownHostException e) { throw new IllegalArgumentException("Invalid private IP address", e); } return privateIpAddress; }
From source file:com.cloudera.director.aws.rds.RDSInstance.java
License:Apache License
/** * Returns the port used for administrative database connections on the specified RDS instance. * * @param dbInstance the RDS instance// w ww .j av a 2 s.c o m * @return the port used for administrative database connections on the specified RDS instance */ private static Integer getPort(DBInstance dbInstance) { Preconditions.checkNotNull(dbInstance, "dbInstance is null"); Endpoint endpoint = dbInstance.getEndpoint(); return (endpoint == null) ? null : endpoint.getPort(); }
From source file:com.github.blacklocus.rdsecho.EchoPromote.java
License:Open Source License
@Override boolean traverseStage(DBInstance instance) { LOG.info("Reading current DNS records"); String tld = EchoUtil.getTLD(cfg.promoteCname()) + '.'; HostedZone hostedZone = route53Find.hostedZone(nameEquals(tld)).get(); LOG.info(" Found corresponding HostedZone. name: {} id: {}", hostedZone.getName(), hostedZone.getId()); ResourceRecordSet resourceRecordSet = route53Find .resourceRecordSet(hostedZone.getId(), cnameEquals(cfg.promoteCname())).get(); ResourceRecord resourceRecord = getOnlyElement(resourceRecordSet.getResourceRecords()); LOG.info(" Found CNAME {} with current value {}", resourceRecordSet.getName(), resourceRecord.getValue()); Endpoint endpoint = instance.getEndpoint(); String tagEchoManaged = echo.getTagEchoManaged(); String dbInstanceId = instance.getDBInstanceIdentifier(); if (null == endpoint) { LOG.info("Echo DB instance {} (id: {}) has no address. Is it still initializing?", tagEchoManaged, dbInstanceId);/*from w w w .j av a 2s . c o m*/ return false; } String instanceAddr = endpoint.getAddress(); if (resourceRecord.getValue().equals(instanceAddr)) { LOG.info(" Echo DB instance {} ({}) lines up with CNAME {}. Nothing to do.", tagEchoManaged, instanceAddr, resourceRecordSet.getName()); return false; } else { LOG.info(" Echo DB instance {} ({}) differs from CNAME {}.", tagEchoManaged, instanceAddr, resourceRecordSet.getName()); } if (cfg.interactive()) { String format = "Are you sure you want to promote %s to be the new target of %s? Input %s to confirm."; if (!EchoUtil.prompt(dbInstanceId, format, dbInstanceId, cfg.promoteCname(), dbInstanceId)) { LOG.info("User declined to proceed. Exiting."); return false; } } LOG.info("Updating CNAME {} from {} to {}", cfg.name(), resourceRecord.getValue(), instanceAddr); ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest() .withHostedZoneId(hostedZone.getId()) .withChangeBatch(new ChangeBatch().withChanges( new Change(ChangeAction.UPSERT, new ResourceRecordSet(cfg.promoteCname(), RRType.CNAME) .withResourceRecords(new ResourceRecord(instanceAddr)).withTTL(cfg.promoteTtl())))); route53.changeResourceRecordSets(request); Optional<String[]> promoteTags = cfg.promoteTags(); if (promoteTags.isPresent()) { List<Tag> tags = EchoUtil.parseTags(promoteTags.get()); if (tags.size() > 0) { LOG.info("Applying tags on promote: {}", Arrays.asList(tags)); AddTagsToResourceRequest tagsRequest = new AddTagsToResourceRequest().withResourceName( RdsFind.instanceArn(cfg.region(), cfg.accountNumber(), instance.getDBInstanceIdentifier())); tagsRequest.setTags(tags); rds.addTagsToResource(tagsRequest); } } LOG.info("Searching for any existing promoted instance to demote."); return true; }
From source file:com.gs.obevo.amazon.CreateDbInstance.java
License:Apache License
private void describe(String dbInstanceIdentifier) throws Exception { while (true) { DescribeDBInstancesRequest request = new DescribeDBInstancesRequest() .withDBInstanceIdentifier(dbInstanceIdentifier); DescribeDBInstancesResult response = client.describeDBInstances(request); DBInstance dbInstance = response.getDBInstances().get(0); if (!dbInstance.getDBInstanceStatus().equalsIgnoreCase("creating")) { System.out.println("Done! " + response); System.out.println(dbInstance.getEndpoint().getAddress()); System.out.println(dbInstance.getEndpoint().getPort()); break; }/* ww w .j av a 2 s . co m*/ System.out.println("Not done - will wait 10s: " + response); Thread.sleep(10000L); } }
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 . jav a 2 s .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; }