hashCode = prime * hashCode + ((getDBInstanceIdentifier() == null) ? 0 : getDBInstanceIdentifier().hashCode()); hashCode = prime * hashCode + ((getDBInstanceClass() == null) ? 0 : getDBInstanceClass().hashCode()); hashCode = prime * hashCode + ((getEngine() == null) ? 0 : getEngine().hashCode()); hashCode = prime * hashCode + ((getDBInstanceStatus() == null) ? 0 : getDBInstanceStatus().hashCode()); hashCode = prime * hashCode + ((getMasterUsername() == null) ? 0 : getMasterUsername().hashCode()); hashCode = prime * hashCode + ((getDBName() == null) ? 0 : getDBName().hashCode()); hashCode = prime * hashCode + ((getEndpoint() == null) ? 0 : getEndpoint().hashCode()); hashCode = prime * hashCode + ((getAllocatedStorage() == null) ? 0 : getAllocatedStorage().hashCode()); hashCode = prime * hashCode + ((getInstanceCreateTime() == null) ? 0 : getInstanceCreateTime().hashCode()); hashCode = prime * hashCode + ((getPreferredBackupWindow() == null) ? 0 : getPreferredBackupWindow().hashCode()); hashCode = prime * hashCode + ((getBackupRetentionPeriod() == null) ? 0 : getBackupRetentionPeriod().hashCode()); hashCode = prime * hashCode + ((getDBSecurityGroups() == null) ? 0 : getDBSecurityGroups().hashCode()); hashCode = prime * hashCode + ((getVpcSecurityGroups() == null) ? 0 : getVpcSecurityGroups().hashCode()); hashCode = prime * hashCode + ((getDBParameterGroups() == null) ? 0 : getDBParameterGroups().hashCode()); hashCode = prime * hashCode + ((getAvailabilityZone() == null) ? 0 : getAvailabilityZone().hashCode()); hashCode = prime * hashCode + ((getDBSubnetGroup() == null) ? 0 : getDBSubnetGroup().hashCode()); hashCode = prime * hashCode + ((getPreferredMaintenanceWindow() == null) ? 0 : getPreferredMaintenanceWindow().hashCode()); hashCode = prime * hashCode + ((getPendingModifiedValues() == null) ? 0 : getPendingModifiedValues().hashCode()); hashCode = prime * hashCode + ((getLatestRestorableTime() == null) ? 0 : getLatestRestorableTime().hashCode()); hashCode = prime * hashCode + ((getMultiAZ() == null) ? 0 : getMultiAZ().hashCode()); hashCode = prime * hashCode + ((getEngineVersion() == null) ? 0 : getEngineVersion().hashCode()); hashCode = prime * hashCode + ((getAutoMinorVersionUpgrade() == null) ? 0 : getAutoMinorVersionUpgrade().hashCode()); hashCode = prime * hashCode + ((getReadReplicaSourceDBInstanceIdentifier() == null) ? 0 : getReadReplicaSourceDBInstanceIdentifier().hashCode()); hashCode = prime * hashCode + ((getReadReplicaDBInstanceIdentifiers() == null) ? 0 : getReadReplicaDBInstanceIdentifiers().hashCode()); hashCode = prime * hashCode + ((getReadReplicaDBClusterIdentifiers() == null) ? 0 : getReadReplicaDBClusterIdentifiers().hashCode()); hashCode = prime * hashCode + ((getLicenseModel() == null) ? 0 : getLicenseModel().hashCode()); hashCode = prime * hashCode + ((getIops() == null) ? 0 : getIops().hashCode()); hashCode = prime * hashCode + ((getOptionGroupMemberships() == null) ? 0 : getOptionGroupMemberships().hashCode()); hashCode = prime * hashCode + ((getCharacterSetName() == null) ? 0 : getCharacterSetName().hashCode());
public RDSInstance(DBInstance instance, DBCluster cluster, List<Tag> tagList, List<String> snapshots) { 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.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();
private DataSourceInformation fromRdsInstance(DBInstance dbInstance) { Assert.notNull(dbInstance, "DbInstance must not be null"); Assert.notNull(dbInstance.getEndpoint(), "The database instance has no endpoint available!"); return new DataSourceInformation(DatabaseType.fromEngine(dbInstance.getEngine()), dbInstance.getEndpoint().getAddress(), dbInstance.getEndpoint().getPort(), StringUtils.hasText(this.databaseName) ? this.databaseName : dbInstance.getDBName(), StringUtils.hasText(this.username) ? this.username : dbInstance.getMasterUsername(), this.password); } }
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; } System.out.println("Not done - will wait 10s: " + response); Thread.sleep(10000L); } }
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"); } }
public static boolean checkIfMaster(DBInstance instance, DBCluster cluster) { if (instance.getDBClusterIdentifier() == null || cluster == null) { // It's NOT a member of a DB cluster return instance.getReadReplicaSourceDBInstanceIdentifier() == null; } else { // It's a member of a DB cluster for (DBClusterMember member : cluster.getDBClusterMembers()) { if (member.getDBInstanceIdentifier().equals(instance.getDBInstanceIdentifier()) && member.isClusterWriter()) { return true; } } return false; } }
if (RDSInstance.checkIfMaster(instance, instanceIdToCluster.get(instance.getDBInstanceIdentifier()))) { if ("aurora".equals(instance.getEngine()) || "aurora-mysql".equals(instance.getEngine())) { DescribeDBClusterSnapshotsRequest snapshotsRequest = new DescribeDBClusterSnapshotsRequest() .withDBClusterIdentifier(instance.getDBClusterIdentifier()); DescribeDBClusterSnapshotsResult snapshotsResult = client.describeDBClusterSnapshots(snapshotsRequest); for (DBClusterSnapshot s : snapshotsResult.getDBClusterSnapshots()) { .withDBInstanceIdentifier(instance.getDBInstanceIdentifier()); DescribeDBSnapshotsResult snapshotsResult = client.describeDBSnapshots(snapshotsRequest); for (DBSnapshot s : snapshotsResult.getDBSnapshots()) { instanceIdToCluster.get(instance.getDBInstanceIdentifier()), tagsResult.getTagList(), snapshots));
public String getDBEndPoint(String dbInstanceId, int timeout){ DescribeDBInstancesRequest ddbir = new DescribeDBInstancesRequest() .withDBInstanceIdentifier(dbInstanceId); System.out.println("Waiting for DB endpoints"); while(timeout -- > 0){ System.out.print("-"); DescribeDBInstancesResult ddbi = rdsClient.describeDBInstances(ddbir); Endpoint endpoint = ddbi.getDBInstances().get(0).getEndpoint(); if(endpoint != null && endpoint.toString().length()!=0) return endpoint.getAddress()+":"+endpoint.getPort(); try { Thread.sleep(1000); } catch (InterruptedException ex) { Logger.getLogger(BeanstalkConnector.class.getName()).log(Level.SEVERE, null, ex); } } return ""; }
private String rdsARN(String regionName, String accountNumber, DBInstance instance) { return String.format( "arn:aws:rds:%s:%s:db:%s", regionName, accountNumber, instance.getDBInstanceIdentifier() ); } }
journal.log(Level.INFO, String.format(">> RDS instance created: %s, at %s", instance.toString(),instance.getEndpoint()));
if (dbInstance.getReadReplicaDBInstanceIdentifiers().isEmpty()) { return super.createInstance(); dbInstance.getReadReplicaDBInstanceIdentifiers().size()); for (String replicaName : dbInstance.getReadReplicaDBInstanceIdentifiers()) { replicaMap.put(replicaName, createDataSourceInstance(replicaName));
public String getDBStatus(String dbInstanceId){ DescribeDBInstancesRequest ddbir = new DescribeDBInstancesRequest() .withDBInstanceIdentifier(dbInstanceId); DescribeDBInstancesResult ddbi = rdsClient.describeDBInstances(ddbir); try{ return ddbi.getDBInstances().get(0).getStatusInfos().toString(); }catch(Exception e){ throw new RuntimeException("DBInstance not found"); } }
private DataSourceInformation fromRdsInstance(DBInstance dbInstance) { Assert.notNull(dbInstance, "DbInstance must not be null"); Assert.notNull(dbInstance.getEndpoint(), "The database instance has no endpoint available!"); return new DataSourceInformation(DatabaseType.fromEngine(dbInstance.getEngine()), dbInstance.getEndpoint().getAddress(), dbInstance.getEndpoint().getPort(), StringUtils.hasText(this.databaseName) ? this.databaseName : dbInstance.getDBName(), StringUtils.hasText(this.username) ? this.username : dbInstance.getMasterUsername(), this.password); } }
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"); } }
.filter(dbInstance -> dbInstance.getEndpoint() != null) .forEach(dbInstance -> { final Map<String, Object> metadata = newHashMap(); metadata.put("unsecuredDatabase", dbInstance.getEndpoint().getAddress()); metadata.put("errorMessages", "Unsecured Database! Your DB can be reached from outside"); writeViolation(accountId, region, metadata, dbInstance.getEndpoint().getAddress());
@TaskAction public void rebootDBInstance() { // to enable conventionMappings feature String dbInstanceIdentifier = getDbInstanceIdentifier(); if (dbInstanceIdentifier == null) { throw new GradleException("dbInstanceIdentifier is required"); } AmazonRDSPluginExtension ext = getProject().getExtensions().getByType(AmazonRDSPluginExtension.class); AmazonRDS rds = ext.getClient(); RebootDBInstanceRequest request = new RebootDBInstanceRequest() .withDBInstanceIdentifier(dbInstanceIdentifier) .withForceFailover(getForceFailover()); dbInstance = rds.rebootDBInstance(request); getLogger().info("Reboot RDS instance requested: {}", dbInstance.getDBInstanceIdentifier()); } }
if (dbInstance.getReadReplicaDBInstanceIdentifiers().isEmpty()) { return super.createInstance(); dbInstance.getReadReplicaDBInstanceIdentifiers().size()); for (String replicaName : dbInstance.getReadReplicaDBInstanceIdentifiers()) { replicaMap.put(replicaName, createDataSourceInstance(replicaName));
return false; DBInstance other = (DBInstance) obj; if (other.getDBInstanceIdentifier() == null ^ this.getDBInstanceIdentifier() == null) return false; if (other.getDBInstanceIdentifier() != null && other.getDBInstanceIdentifier().equals(this.getDBInstanceIdentifier()) == false) return false; if (other.getDBInstanceClass() == null ^ this.getDBInstanceClass() == null) return false; if (other.getDBInstanceClass() != null && other.getDBInstanceClass().equals(this.getDBInstanceClass()) == false) return false; if (other.getEngine() == null ^ this.getEngine() == null) return false; if (other.getEngine() != null && other.getEngine().equals(this.getEngine()) == false) return false; if (other.getDBInstanceStatus() == null ^ this.getDBInstanceStatus() == null) return false; if (other.getDBInstanceStatus() != null && other.getDBInstanceStatus().equals(this.getDBInstanceStatus()) == false) return false; if (other.getMasterUsername() == null ^ this.getMasterUsername() == null) return false; if (other.getMasterUsername() != null && other.getMasterUsername().equals(this.getMasterUsername()) == false) return false; if (other.getDBName() == null ^ this.getDBName() == null) return false; if (other.getDBName() != null && other.getDBName().equals(this.getDBName()) == false) return false; if (other.getEndpoint() == null ^ this.getEndpoint() == null) return false; if (other.getEndpoint() != null && other.getEndpoint().equals(this.getEndpoint()) == false)
@TaskAction public void createOrUpdateDBInstance() throws InterruptedException { AmazonRDSPluginExtension ext = getProject().getExtensions().getByType(AmazonRDSPluginExtension.class); AmazonRDS rds = ext.getClient(); try { DescribeDBInstancesResult describeDBInstancesResult = rds.describeDBInstances(new DescribeDBInstancesRequest() .withDBInstanceIdentifier(dbInstanceIdentifier)); DBInstance dbInstance = describeDBInstancesResult.getDBInstances().get(0); if (stableStatuses.contains(dbInstance.getDBInstanceStatus())) { modifyDBInstance(rds); } else { throw new GradleException("Invalid status for update: " + dbInstance.getDBInstanceStatus()); } } catch (DBInstanceNotFoundException e) { getLogger().info(e.getMessage()); createDBInstance(rds); } }
@TaskAction public void deleteDBInstance() { // to enable conventionMappings feature String dbInstanceIdentifier = getDbInstanceIdentifier(); if (dbInstanceIdentifier == null) { throw new GradleException("dbInstanceIdentifier is required"); } AmazonRDSPluginExtension ext = getProject().getExtensions().getByType(AmazonRDSPluginExtension.class); AmazonRDS rds = ext.getClient(); try { DeleteDBInstanceRequest request = new DeleteDBInstanceRequest() .withDBInstanceIdentifier(dbInstanceIdentifier) .withSkipFinalSnapshot(isSkipFinalSnapshot()) .withFinalDBSnapshotIdentifier(getFinalDBSnapshotIdentifier()); dbInstance = rds.deleteDBInstance(request); getLogger().info("Delete RDS instance requested: {}", dbInstance.getDBInstanceIdentifier()); } catch (DBInstanceNotFoundException e) { getLogger().warn(e.getMessage()); } } }