Java 类com.amazonaws.services.rds.model.DBInstance 实例源码

项目:scouter-pulse-aws-monitor    文件:GetMonitoringInstances.java   
private void getRDSInstances() {
    DescribeDBInstancesResult response = rdsClient.describeDBInstances(new DescribeDBInstancesRequest());

    List<PulseInstance> rds = new ArrayList<PulseInstance>();

    PulseInstance pulse = null;
    for (DBInstance instance : response.getDBInstances()) {
        ListTagsForResourceResult result = rdsClient.listTagsForResource(new ListTagsForResourceRequest().withResourceName(instance.getDBInstanceArn()));

        for (com.amazonaws.services.rds.model.Tag tag : result.getTagList()) {
            if (tag.getKey().equals(properties.getTag()) && (tag.getValue().equals("TRUE") || tag.getValue().equals("True") || tag.getValue().equals("true"))) {
                pulse = new PulseInstance();
                pulse.setId(instance.getDBInstanceIdentifier());
                pulse.setName(instance.getDBInstanceIdentifier());
                pulse.setAddress(instance.getEndpoint().getAddress());
                pulse.setType(instance.getDBInstanceClass());

                rds.add(pulse);
            }
        }
    }

    GetMonitoringInstances.rds = rds;
}
项目:bluegreen-manager    文件:RdsClientTest.java   
/**
 * Test helper - makes describe result with a named instance.
 */
private DescribeDBInstancesResult makeDescribeDBInstancesResult(String... instanceNames)
{
  DescribeDBInstancesResult result = new DescribeDBInstancesResult();
  List<DBInstance> dbInstances = new ArrayList<DBInstance>();
  if (ArrayUtils.isNotEmpty(instanceNames))
  {
    for (String instanceName : instanceNames)
    {
      DBInstance dbInstance = new DBInstance();
      dbInstance.setDBInstanceIdentifier(instanceName);
      dbInstances.add(dbInstance);
    }
  }
  result.setDBInstances(dbInstances);
  return result;
}
项目:obevo    文件:CreateDbInstance.java   
public void createOracle(String dbInstanceIdentifier) throws Exception {
    // http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html
    CreateDBInstanceRequest request = new CreateDBInstanceRequest()
            .withEngine("oracle-se2")
            //.withEngineVersion("12.1.0.2.v8")
            .withLicenseModel("license-included")
            .withAllocatedStorage(10)
            .withStorageType("gp2")  // SSD
            .withBackupRetentionPeriod(0)
            .withDBInstanceClass("db.t2.micro")
            .withDBInstanceIdentifier(dbInstanceIdentifier)
            .withDBName("DBDEPLOY")
            .withMasterUsername("deploybuilddbo")
            .withMasterUserPassword("deploybuilddb0")
            ;
    DBInstance response = client.createDBInstance(request);
    System.out.println(response);

    describe(dbInstanceIdentifier);
}
项目:obevo    文件:CreateDbInstance.java   
public void createPostgresql(String dbInstanceIdentifier) throws Exception {
    // http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html
    CreateDBInstanceRequest request = new CreateDBInstanceRequest()
            .withEngine("postgres")
            .withEngineVersion("9.6.2")
            .withLicenseModel("postgresql-license")
            .withAllocatedStorage(5)
            .withStorageType("gp2")  // SSD
            .withBackupRetentionPeriod(0)
            .withDBInstanceClass("db.t2.micro")
            .withDBInstanceIdentifier(dbInstanceIdentifier)
            .withDBName("DBDEPLOY")
            .withMasterUsername("deploybuilddbo")
            .withMasterUserPassword("deploybuilddb0")
            ;
    DBInstance response = client.createDBInstance(request);
    System.out.println(response);

    describe(dbInstanceIdentifier);
}
项目:obevo    文件:CreateDbInstance.java   
public void createSqlServer(String dbInstanceIdentifier) throws Exception {
    // http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html
    CreateDBInstanceRequest request = new CreateDBInstanceRequest()
            .withEngine("sqlserver-ex")
            .withEngineVersion("13.00.2164.0.v1")
            .withLicenseModel("license-included")
            .withAllocatedStorage(20)
            .withStorageType("gp2")  // SSD
            .withBackupRetentionPeriod(0)
            .withDBInstanceClass("db.t2.micro")
            .withDBInstanceIdentifier(dbInstanceIdentifier)
            //.withDBName("DBDEPLOY")
            .withMasterUsername("deploybuilddbo")
            .withMasterUserPassword("deploybuilddb0")
            ;
    DBInstance response = client.createDBInstance(request);
    System.out.println(response);

    describe(dbInstanceIdentifier);
}
项目:obevo    文件:CreateDbInstance.java   
public 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;
        }

        System.out.println("Not done - will wait 10s: " + response);
        Thread.sleep(10000L);
    }
}
项目:bluegreen-manager    文件:RdsInstanceDeleteTask.java   
/**
 * Deletes the parameter group, if it appears to have been created solely for the deleted db instance.
 * <p/>
 * (The parameter group cannot be deleted until the dependent rdsInstance is fully deleted.)
 */
void deleteParameterGroup(DBInstance rdsInstance, boolean noop)
{
  if (noop)
  {
    //rdsInstance is null, don't try to analyze it
    LOGGER.info(context() + "Deleting parameter group" + noopRemark(noop));
  }
  else
  {
    String paramGroupName = rdsAnalyzer.findSelfNamedParamGroupName(rdsInstance);
    if (StringUtils.isBlank(paramGroupName))
    {
      LOGGER.info(context() + "Deleted database did not have its own special parameter group");
    }
    else
    {
      LOGGER.info(context() + "Deleting parameter group '" + paramGroupName + "', which was used only by the deleted database");
      rdsClient.deleteParameterGroup(paramGroupName);
    }
  }
}
项目:bluegreen-manager    文件:RdsInstanceProgressChecker.java   
/**
 * Communicates with RDS for updated instance progress and checks the status.
 * Concludes if error or if naturally done.
 */
@Override
public void followupCheck(int waitNum)
{
  try
  {
    DBInstance dbInstance = rdsClient.describeInstance(instanceId);
    checkInstanceId(dbInstance);
    logFollowupStatus(waitNum, dbInstance);
    checkInstanceStatus(dbInstance);
  }
  catch (DBInstanceNotFoundException e)
  {
    handleInstanceNotFound(waitNum, e);
  }
}
项目:bluegreen-manager    文件:RdsInstanceProgressChecker.java   
/**
 * Checks if the instance is in an acceptable intermediate status, and flags done if at final state.
 */
protected void checkInstanceStatus(DBInstance dbInstance)
{
  final String status = dbInstance.getDBInstanceStatus();
  if (expectedFinalState.equalsString(status))
  {
    LOGGER.info("RDS " + getDescription() + " is done");
    done = true;
    result = dbInstance;
  }
  else if (isOneOfTheseStates(expectedIntermediateStates, status))
  {
    //Keep waiting.
  }
  else
  {
    LOGGER.error(logContext + getDescription() + ": Unexpected response status '" + status + "'");
    done = true;
  }
}
项目:bluegreen-manager    文件:RdsInstanceProgressChecker.java   
/**
 * Amazon can't find the instance.  This is an allowed final state for a delete operation, otherwise is a bad error.
 */
private void handleInstanceNotFound(int waitNum, DBInstanceNotFoundException e)
{
  LOGGER.debug("RDS " + getDescription() + " status after wait#" + waitNum + ": " + e.getClass().getSimpleName()
      + ": " + e.getMessage());
  if (expectedFinalState.equals(DELETE_FINAL_STATE))
  {
    LOGGER.info("RDS " + getDescription() + " is done");
    result = new DBInstance(); //Just a stub, since result==null would be considered a progress error.
  }
  else
  {
    LOGGER.error(logContext + getDescription() + ": not found", e);
  }
  done = true;
}
项目:bluegreen-manager    文件:RdsSnapshotRestoreTask.java   
/**
 * Makes a copy of the live instance's parameter group.
 */
private DBParameterGroup copyParameterGroup(DBInstance liveInstance, boolean noop)
{
  String stagePhysicalInstanceName = dbMap.get(liveLogicalDatabase.getLogicalName());
  String liveParamGroupName = rdsAnalyzer.findSelfNamedOrDefaultParamGroupName(liveInstance);
  String stageParamGroupName = makeStageParamGroupName(liveParamGroupName,
      liveInstance.getDBInstanceIdentifier(), stagePhysicalInstanceName);
  LOGGER.info(liveContext() + "Copying live parameter group '" + liveParamGroupName
      + "' to stage parameter group '" + stageParamGroupName + "'" + noopRemark(noop));
  if (!noop)
  {
    return rdsClient.copyParameterGroup(liveParamGroupName, stageParamGroupName);
  }
  else
  {
    return null;
  }
}
项目:bluegreen-manager    文件:RdsSnapshotRestoreTask.java   
/**
 * Restores the live snapshot into the new staging environment.
 * Then makes a few small modifications that restore would not do automatically (paramgroup and security group).
 * Reboots the db so the paramgroup modification will take effect.
 * Returns the rebooted instance.
 */
DBInstance restoreStage(DBSnapshot dbSnapshot,
                        DBParameterGroup stageParamGroup,
                        DBInstance liveInstance,
                        boolean noop)
{
  LOGGER.info(liveContext() + "Restoring snapshot to new stage RDS instance" + noopRemark(noop));
  if (!noop)
  {
    String stagePhysicalInstanceName = dbMap.get(liveLogicalDatabase.getLogicalName());
    initModel(stagePhysicalInstanceName);
    String subnetGroupName = getSubnetGroupName(liveInstance);
    DBInstance stageInstance = rdsClient.restoreInstanceFromSnapshot(stagePhysicalInstanceName,
        dbSnapshot.getDBSnapshotIdentifier(), subnetGroupName);
    stageInstance = waitTilInstanceIsAvailable(stagePhysicalInstanceName, stageInstance, RdsInstanceStatus.CREATING);
    DBInstance modifiedInstance = modifyInstance(stageInstance, stageParamGroup, liveInstance);
    modifiedInstance = waitTilParamGroupIsPendingReboot(stagePhysicalInstanceName, modifiedInstance, stageParamGroup,
        RdsInstanceStatus.MODIFYING);
    DBInstance rebootedInstance = rebootInstance(modifiedInstance);
    rebootedInstance = waitTilInstanceIsAvailable(stagePhysicalInstanceName, rebootedInstance, RdsInstanceStatus.REBOOTING);
    return rebootedInstance;
  }
  return null;
}
项目:bluegreen-manager    文件:RdsSnapshotRestoreTask.java   
/**
 * Creates a Waiter using an instance paramgroup progress checker, and returns the final DBInstance when waiting is done.
 * In case of error - never returns null, throws instead.
 */
private DBInstance waitTilParamGroupIsPendingReboot(String instanceId, DBInstance initialInstance,
                                                    DBParameterGroup stageParamGroup,
                                                    RdsInstanceStatus expectedInitialState)
{
  LOGGER.info(liveContext() + "Waiting for instance to become available and instance paramgroup modification to be fully applied");
  RdsInstanceParamGroupProgressChecker progressChecker = new RdsInstanceParamGroupProgressChecker(instanceId,
      stageParamGroup.getDBParameterGroupName(), liveContext(), rdsClient, rdsAnalyzer, initialInstance, expectedInitialState);
  Waiter<DBInstance> waiter = new Waiter(waiterParameters, threadSleeper, progressChecker);
  DBInstance dbInstance = waiter.waitTilDone();
  if (dbInstance == null)
  {
    throw new RuntimeException(liveContext() + progressChecker.getDescription() + " did not become available, "
        + "or paramgroup failed to reach pending-reboot state");
  }
  return dbInstance;
}
项目:bluegreen-manager    文件:RdsClient.java   
/**
 * Restores a snapshot to a brand new instance.
 * <p/>
 * New instance gets the default security group, otherwise should be same as snapshot.
 * <p/>
 * Caller must wait for status=available afterwards.
 */
public DBInstance restoreInstanceFromSnapshot(String instanceName, String snapshotId, String subnetGroupName)
{
  LOGGER.debug("restoreDBInstanceFromDBSnapshot(instanceName: " + instanceName + ", snapshotId: " + snapshotId
      + ", subnetGroupName: " + subnetGroupName + ")");
  StopWatch stopWatch = new StopWatch();
  try
  {
    stopWatch.start();
    RestoreDBInstanceFromDBSnapshotRequest request = new RestoreDBInstanceFromDBSnapshotRequest(
        instanceName, snapshotId);
    request.setDBSubnetGroupName(subnetGroupName);
    return awsRdsClient.restoreDBInstanceFromDBSnapshot(request);
  }
  finally
  {
    stopWatch.stop();
    LOGGER.debug("restoreDBInstanceFromDBSnapshot time elapsed: " + stopWatch);
  }
}
项目:bluegreen-manager    文件:RdsClient.java   
/**
 * Modifies the instance by applying new security groups and new parameter group.
 * <p/>
 * Caller must wait for status=available afterwards.
 */
public DBInstance modifyInstanceWithSecgrpParamgrp(String instanceName,
                                                   Collection<String> vpcSecurityGroupIds,
                                                   String paramGroupName)
{
  LOGGER.debug("modifyDBInstance(instanceName: " + instanceName + ", vpcSecurityGroupIds: ("
      + StringUtils.join(vpcSecurityGroupIds, ", ") + "), paramGroupName: " + paramGroupName + ")");
  StopWatch stopWatch = new StopWatch();
  try
  {
    stopWatch.start();
    ModifyDBInstanceRequest request = new ModifyDBInstanceRequest(instanceName);
    request.setVpcSecurityGroupIds(vpcSecurityGroupIds);
    request.setDBParameterGroupName(paramGroupName);
    return awsRdsClient.modifyDBInstance(request);
  }
  finally
  {
    stopWatch.stop();
    LOGGER.debug("modifyDBInstance time elapsed: " + stopWatch);
  }
}
项目:bluegreen-manager    文件:RdsClient.java   
/**
 * Requests deletion of the instance, without creating a final snapshot or deleting any other related
 * snapshots.
 * <p/>
 * Caller must wait for status=deleted or DBInstanceNotFoundException afterwards.
 */
public DBInstance deleteInstance(String instanceName)
{
  LOGGER.debug("deleteDBInstance(instanceName: " + instanceName + ")");
  StopWatch stopWatch = new StopWatch();
  try
  {
    stopWatch.start();
    DeleteDBInstanceRequest request = new DeleteDBInstanceRequest(instanceName);
    request.setSkipFinalSnapshot(true);
    return awsRdsClient.deleteDBInstance(request);
  }
  finally
  {
    stopWatch.stop();
    LOGGER.debug("deleteDBInstance time elapsed: " + stopWatch);
  }
}
项目:bluegreen-manager    文件:RdsClient.java   
/**
 * Requests a reboot of the instance.
 * <p/>
 * Caller must wait for status=available afterwards.
 */
public DBInstance rebootInstance(String instanceId)
{
  LOGGER.debug("rebootDBInstance(instanceName: " + instanceId + ")");
  StopWatch stopWatch = new StopWatch();
  try
  {
    stopWatch.start();
    RebootDBInstanceRequest request = new RebootDBInstanceRequest(instanceId);
    return awsRdsClient.rebootDBInstance(request);
  }
  finally
  {
    stopWatch.stop();
    LOGGER.debug("rebootDBInstance time elapsed: " + stopWatch);
  }
}
项目:bluegreen-manager    文件:RdsAnalyzer.java   
/**
 * Finds the name of the instance's paramgroup whose name embeds the instname.  If not found, then simply returns
 * the first paramgroup name.
 */
public String findSelfNamedOrDefaultParamGroupName(DBInstance dbInstance)
{
  String selfNamedGroupName = findSelfNamedParamGroupName(dbInstance);
  if (selfNamedGroupName != null)
  {
    return selfNamedGroupName;
  }
  if (dbInstance != null && CollectionUtils.isNotEmpty(dbInstance.getDBParameterGroups()))
  {
    String defaultName = dbInstance.getDBParameterGroups().get(0).getDBParameterGroupName();
    LOGGER.warn("Could not find paramgroup containing the string '" + dbInstance.getDBInstanceIdentifier()
        + "', falling back to '" + defaultName + "'");
    return defaultName;
  }
  return null;
}
项目:bluegreen-manager    文件:RdsAnalyzer.java   
/**
 * Finds the name of the instance's paramgroup whose name embeds the instname, or null if not found.
 * We are assuming there is at most one such paramgroup!
 */
public String findSelfNamedParamGroupName(DBInstance dbInstance)
{
  if (dbInstance != null && CollectionUtils.isNotEmpty(dbInstance.getDBParameterGroups()))
  {
    String instanceName = dbInstance.getDBInstanceIdentifier();
    for (DBParameterGroupStatus paramGroup : dbInstance.getDBParameterGroups())
    {
      String paramGroupName = paramGroup.getDBParameterGroupName();
      if (StringUtils.contains(paramGroupName, instanceName))
      {
        return paramGroup.getDBParameterGroupName();
      }
    }
  }
  return null;
}
项目:bluegreen-manager    文件:RdsSnapshotRestoreTaskTest.java   
/**
 * Test setup and execution for restoreStage.
 *
 * @param stageRestoreInstanceStatus Instance status of stage physicaldb after restore-from-snapshot operation.
 * @param stageModifyInstanceStatus  Instance status of stage physicaldb after modify operation.
 */
private RestoreStageResults testRestoreStage(String stageParamGroupName,
                                             RdsInstanceStatus stageRestoreInstanceStatus,
                                             RdsInstanceStatus stageModifyInstanceStatus,
                                             RdsParameterApplyStatus stageModifyParamStatus)
{
  normalSetup();
  RestoreStageFakeData data = restoreSetup(FAKE_SNAPSHOT_ID, stageParamGroupName,
      stageRestoreInstanceStatus, stageModifyInstanceStatus, stageModifyParamStatus);
  DBInstance resultInstance = null;
  Throwable exception = null;
  try
  {
    resultInstance = rdsSnapshotRestoreTask.restoreStage(data.getDbSnapshot(), data.getStageParamGroup(),
        data.getLiveInstance(), false/*noop*/);
  }
  catch (Throwable e)
  {
    exception = e;
  }
  return new RestoreStageResults(data, resultInstance, exception);
}
项目:bluegreen-manager    文件:RdsInstanceParamGroupProgressCheckerTest.java   
/**
 * Test helper - makes a DBInstance
 */
private DBInstance fakeInstance(String instanceId, RdsInstanceStatus currentInstanceStatus,
                                String paramGroupName, RdsParameterApplyStatus currentParameterApplyStatus)
{
  DBInstance dbInstance = new DBInstance();
  dbInstance.setDBInstanceIdentifier(instanceId);
  dbInstance.setDBInstanceStatus(currentInstanceStatus == null ? STATUS_UNKNOWN : currentInstanceStatus.toString());
  if (paramGroupName != null)
  {
    List<DBParameterGroupStatus> list = new ArrayList<DBParameterGroupStatus>();
    DBParameterGroupStatus paramGroup = new DBParameterGroupStatus();
    paramGroup.setDBParameterGroupName(paramGroupName);
    paramGroup.setParameterApplyStatus(currentParameterApplyStatus == null ? STATUS_UNKNOWN : currentParameterApplyStatus.toString());
    list.add(paramGroup);
    dbInstance.setDBParameterGroups(list);
  }
  return dbInstance;
}
项目:bluegreen-manager    文件:RdsAnalyzerTest.java   
/**
 * Test helper - makes a DBInstance having the specified paramgroup names.
 */
private DBInstance makeDBInstanceWithParamGroups(RdsParameterApplyStatus parameterApplyStatus,
                                                 String... paramGroupNames)
{
  DBInstance dbInstance = new DBInstance();
  dbInstance.setDBInstanceIdentifier(INSTANCE_NAME);
  if (ArrayUtils.isNotEmpty(paramGroupNames))
  {
    Collection<DBParameterGroupStatus> paramGroups = new ArrayList<DBParameterGroupStatus>();
    for (String paramGroupName : paramGroupNames)
    {
      paramGroups.add(makeDBParameterGroupStatus(paramGroupName, parameterApplyStatus));
    }
    dbInstance.setDBParameterGroups(paramGroups);
  }
  return dbInstance;
}
项目:bluegreen-manager    文件:RdsAnalyzerTest.java   
/**
 * Test helper - makes a DBInstance having the specified security group names.
 */
private DBInstance makeDBInstanceWithSecurityGroups(String... securityGroupIds)
{
  DBInstance dbInstance = new DBInstance();
  dbInstance.setDBInstanceIdentifier(INSTANCE_NAME);
  if (ArrayUtils.isNotEmpty(securityGroupIds))
  {
    List<VpcSecurityGroupMembership> securityGroups = new ArrayList<VpcSecurityGroupMembership>();
    for (String securityGroupId : securityGroupIds)
    {
      securityGroups.add(makeVpcSecurityGroupMembership(securityGroupId));
    }
    dbInstance.setVpcSecurityGroups(securityGroups);
  }
  return dbInstance;
}
项目:candlestack    文件:RDSMetricsFetcher.java   
private void fetchInstanceMetrics() throws CandlestackAWSException, CandlestackException {
    Set<String> replicaInstances = RDSUtil.getReplicaInstances( rdsClient );

    DescribeDBInstancesResult dbInstanceResults = rdsClient.describeDBInstances();
    for ( DBInstance dbInstance : dbInstanceResults.getDBInstances() ) {

        String dbInstanceId = dbInstance.getDBInstanceIdentifier();
        RDSType rdsType = RDSType.getTypeFromEngine( dbInstance.getEngine() );
        if ( !RDSUtil.isDBInstanceEligible( dbInstanceId, dbInstancePrefix, dbInstanceRegex, rdsType ) ) {
            continue;
        }

        for ( RDSCloudWatchMetric cloudWatchMetric : cloudWatchMetrics ) {
            if ( cloudWatchMetric.isRDSTypeSupported( rdsType ) && !cloudWatchMetric.isClusterOnlyMetric() && ( !cloudWatchMetric.isReplicaOnlyMetric() || replicaInstances.contains( dbInstanceId ) ) ) {
                cloudWatchAccessor.lookupAndSaveMetricData( cloudWatchMetric, dbInstanceId, RDSUtil.TYPE_NAME );
            }
        }

    }
}
项目:director-aws-plugin    文件:RDSProvider.java   
@Override
public Collection<RDSInstance> find(final RDSInstanceTemplate template,
    Collection<String> virtualInstanceIds) throws InterruptedException {

  final Collection<RDSInstance> rdsInstances =
      Lists.newArrayListWithExpectedSize(virtualInstanceIds.size());

  forEachInstance(virtualInstanceIds, new InstanceHandler() {
    @Override
    public void handle(DBInstance dbInstance) {
      String virtualInstanceId = checkInstanceIsManagedByDirector(dbInstance, template);
      rdsInstances.add(new RDSInstance(template, virtualInstanceId, dbInstance));
    }
  });

  return rdsInstances;
}
项目:director-aws-plugin    文件:RDSInstance.java   
/**
 * Returns the private IP address of the specified RDS instance.
 *
 * @param dbInstance the RDS instance
 * @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;
}
项目:amediamanager    文件:RdsDbEndpointRetriever.java   
@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());
            }
        }
        if(endpoints.size() == 0) {
            endpoints = null;
        }

    }

    return endpoints;
}
项目:spring-cloud-aws    文件:DatabaseInstanceStatusRetryPolicy.java   
private boolean isDatabaseAvailable(RetryContext context) {
    DescribeDBInstancesResult describeDBInstancesResult;
    try {
        describeDBInstancesResult = this.amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier((String) context.getAttribute(DB_INSTANCE_ATTRIBUTE_NAME)));
    } catch (DBInstanceNotFoundException e) {
        LOGGER.warn("Database Instance with name {} has been removed or is not configured correctly, no retry possible", getDbInstanceIdentifier());
        //Database has been deleted while operating, hence we can not retry
        return false;
    }

    if (describeDBInstancesResult.getDBInstances().size() == 1) {
        DBInstance dbInstance = describeDBInstancesResult.getDBInstances().get(0);
        InstanceStatus instanceStatus = InstanceStatus.fromDatabaseStatus(dbInstance.getDBInstanceStatus());
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Status of database to be retried is {}", instanceStatus);
        }
        return instanceStatus.isRetryable();
    } else {
        throw new IllegalStateException("Multiple databases found for same identifier, this is likely an incompatibility with the Amazon SDK");
    }
}
项目:spring-cloud-aws    文件:AmazonRdsInstanceConfigurationTest.java   
@Bean
public AmazonRDS amazonRDS() {
    AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class);
    when(client.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).thenReturn(
            new DescribeDBInstancesResult().
                    withDBInstances(new DBInstance().
                            withDBInstanceStatus("available").
                            withDBName("test").
                            withDBInstanceIdentifier("test").
                            withEngine("mysql").
                            withMasterUsername("admin").
                            withEndpoint(new Endpoint().
                                    withAddress("localhost").
                                    withPort(3306)
                            ).withReadReplicaDBInstanceIdentifiers("read1")
                    )
    );
    return client;
}
项目:spring-cloud-aws    文件:AmazonRdsInstanceConfigurationTest.java   
@Bean
public AmazonRDS amazonRDS() {
    AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class);
    when(client.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).thenReturn(
            new DescribeDBInstancesResult().
                    withDBInstances(new DBInstance().
                            withDBInstanceStatus("available").
                            withDBName("test").
                            withDBInstanceIdentifier("test").
                            withEngine("mysql").
                            withMasterUsername("admin").
                            withEndpoint(new Endpoint().
                                    withAddress("localhost").
                                    withPort(3306)
                            ).withReadReplicaDBInstanceIdentifiers("read1")
                    )
    );
    return client;
}
项目:spring-cloud-aws    文件:AmazonRdsInstanceConfigurationTest.java   
@Bean
public AmazonRDS amazonRDS() {
    AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class);
    when(client.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).thenReturn(
            new DescribeDBInstancesResult().
                    withDBInstances(new DBInstance().
                            withDBInstanceStatus("available").
                            withDBName("test").
                            withDBInstanceIdentifier("test").
                            withEngine("mysql").
                            withMasterUsername("admin").
                            withEndpoint(new Endpoint().
                                    withAddress("localhost").
                                    withPort(3306)
                            ).withReadReplicaDBInstanceIdentifiers("read1")
                    )
    );
    return client;
}
项目:spring-cloud-aws    文件:AmazonRdsInstanceConfigurationTest.java   
@Bean
public AmazonRDS amazonRDS() {
    AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class);
    when(client.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).thenReturn(
            new DescribeDBInstancesResult().
                    withDBInstances(new DBInstance().
                            withDBInstanceStatus("available").
                            withDBName("test").
                            withDBInstanceIdentifier("test").
                            withEngine("mysql").
                            withMasterUsername("admin").
                            withEndpoint(new Endpoint().
                                    withAddress("localhost").
                                    withPort(3306)
                            ).withReadReplicaDBInstanceIdentifiers("read1")
                    )
    );
    return client;
}
项目:spring-cloud-aws    文件:DatabaseInstanceStatusRetryPolicyTest.java   
@Test
public void canRetry_retryPossibleDueToAvailableDatabase_returnsTrue() throws Exception {
    //Arrange
    AmazonRDS amazonRDS = mock(AmazonRDS.class);

    DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy(amazonRDS, "test");
    when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).
            thenReturn(new DescribeDBInstancesResult().withDBInstances(new DBInstance().withDBInstanceStatus("available")));

    RetryContext retryContext = policy.open(new RetryContextSupport(null));

    //Act
    policy.registerThrowable(retryContext, new TransientDataAccessResourceException("not available"));

    //Assert
    assertTrue(policy.canRetry(retryContext));
    policy.close(retryContext);
}
项目:spring-cloud-aws    文件:DatabaseInstanceStatusRetryPolicyTest.java   
@Test
public void canRetry_withResourceIdResolver_returnsTrue() throws Exception {
    //Arrange
    AmazonRDS amazonRDS = mock(AmazonRDS.class);
    ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);

    DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy(amazonRDS, "foo");
    when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).
            thenReturn(new DescribeDBInstancesResult().withDBInstances(new DBInstance().withDBInstanceStatus("available")));

    when(resourceIdResolver.resolveToPhysicalResourceId("foo")).thenReturn("test");

    policy.setResourceIdResolver(resourceIdResolver);


    RetryContext retryContext = policy.open(new RetryContextSupport(null));

    //Act
    policy.registerThrowable(retryContext, new TransientDataAccessResourceException("not available"));

    //Assert
    assertTrue(policy.canRetry(retryContext));
    policy.close(retryContext);
}
项目:spring-cloud-aws    文件:DatabaseInstanceStatusRetryPolicyTest.java   
@Test
public void canRetry_multipleDatabasesFoundForInstanceIdentifier_reportsException() throws Exception {
    //Arrange
    this.expectedException.expect(IllegalStateException.class);
    this.expectedException.expectMessage("Multiple databases found for same identifier");

    AmazonRDS amazonRDS = mock(AmazonRDS.class);

    DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy(amazonRDS, "test");

    DescribeDBInstancesResult describeDBInstancesResult = new DescribeDBInstancesResult().withDBInstances(new DBInstance(), new DBInstance());
    when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).
            thenReturn(describeDBInstancesResult);

    RetryContext retryContext = policy.open(new RetryContextSupport(null));

    //Act
    policy.registerThrowable(retryContext, new TransientDataAccessResourceException("not available"));

    //Assert
    policy.canRetry(retryContext);
}
项目:spring-cloud-aws    文件:AmazonRdsDatabaseAutoConfigurationTest.java   
@Bean
public AmazonRDSClient amazonRDS() {
    AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class);
    when(client.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).thenReturn(
            new DescribeDBInstancesResult().
                    withDBInstances(new DBInstance().
                            withDBInstanceStatus("available").
                            withDBName("test").
                            withDBInstanceIdentifier("test").
                            withEngine("mysql").
                            withMasterUsername("admin").
                            withEndpoint(new Endpoint().
                                    withAddress("localhost").
                                    withPort(3306)
                            ).withReadReplicaDBInstanceIdentifiers("read1")
                    )
    );
    return client;
}
项目:cfnassist    文件:RDSClient.java   
public List<DBInstance> getDBInstancesForVpc(String vpcId) {    
    DescribeDBInstancesResult result = rdsClient.describeDBInstances();
    List<DBInstance> dbInstances = result.getDBInstances();

    List<DBInstance> filtered = new LinkedList<DBInstance>(); 
    for(DBInstance dbInstance : dbInstances) {
        DBSubnetGroup dbSubnetGroup = dbInstance.getDBSubnetGroup();
        if (dbSubnetGroup!=null) {
            String groupVpcId = dbSubnetGroup.getVpcId();
            if (groupVpcId.equals(vpcId)) {
                filtered.add(dbInstance);
            }
        }
    }
    return filtered;
}
项目:datamung    文件:RdsActivitiesImpl.java   
private static DatabaseInstance toDatabaseInstance( DBInstance dbInstance )
{
    DatabaseInstance i = new DatabaseInstance();
    i.setAllocatedStorage( dbInstance.getAllocatedStorage() );
    i.setAvailabilityZone( dbInstance.getAvailabilityZone() );
    i.setInstanceId( dbInstance.getDBInstanceIdentifier() );
    i.setInstanceStatus( dbInstance.getDBInstanceStatus() );
    i.setInstanceType( dbInstance.getDBInstanceClass() );
    i.setMasterUser( dbInstance.getMasterUsername() );
    if ( dbInstance.getEndpoint() != null )
    {
        i.setPort( dbInstance.getEndpoint().getPort() );
        i.setPublicHostName( dbInstance.getEndpoint().getAddress() );
    }
    if ( dbInstance.getDBSubnetGroup() != null )
    {
        i.setSubnetGroupName( dbInstance.getDBSubnetGroup().getDBSubnetGroupName() );
    }
    return i;
}
项目:datamung    文件:RdsActivitiesImpl.java   
/**
 * @inheritDoc
 */
@Override
public DatabaseInstance describeInstance( String instanceName,
                                          Identity identity )
{
    AmazonRDS rds =
        ActivityUtils.createClient( AmazonRDSClient.class, identity );
    DescribeDBInstancesResult results =
        rds.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier( instanceName ) );
    if ( results.getDBInstances().isEmpty() )
    {
        return null;
    }
    DBInstance result = results.getDBInstances().get( 0 );
    return toDatabaseInstance( result );
}
项目:bluegreen-manager    文件:RdsInstanceDeleteTask.java   
/**
 * Deletes the rds instance, its parameter group (if non-default), and its original bluegreen snapshot.
 * <p/>
 * Leaves behind any snapshots that Amazon automatically made of the rds instance.
 */
@Override
public TaskStatus process(boolean noop)
{
  loadDataModel();
  checkDeleteDatabaseIsNotLive();
  rdsClient = rdsClientFactory.create();
  DBInstance rdsInstance = deleteInstance(noop);
  deleteParameterGroup(rdsInstance, noop);
  persistModel(noop);
  return noop ? TaskStatus.NOOP : TaskStatus.DONE;
}