com.amazonaws.services.redshift.model.Cluster Java Examples

The following examples show how to use com.amazonaws.services.redshift.model.Cluster. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedshiftClusterPublicAccessAutoFix.java    From pacbot with Apache License 2.0 6 votes vote down vote up
@Override
public boolean backupExistingConfigForResource(final String resourceId, final String resourceType, Map<String, Object> clientMap, Map<String, String> ruleParams, Map<String, String> issue) throws AutoFixException {
	LOGGER.debug("backing up the config for {}" , resourceId);
       StringBuilder oldConfig = new StringBuilder();
	try {
		List<Cluster> clusters = PublicAccessAutoFix
				.getClusterForRedhiftResource(clientMap, resourceId);
		List<VpcSecurityGroupMembership> originalSgMembers = clusters
				.get(0).getVpcSecurityGroups();
		for (VpcSecurityGroupMembership sgm : originalSgMembers) {
			if ("active".equals(sgm.getStatus())) {
				if (oldConfig.length() > 0) {
					oldConfig.append(",").append(sgm.getVpcSecurityGroupId());
				} else {
					oldConfig.append(sgm.getVpcSecurityGroupId());
				}
			}
		}
	} catch (Exception e) {
		LOGGER.error(e.getMessage());
	}
	DETACHED_SG = oldConfig.toString();
       backupOldConfig(resourceId, EXISTING_GROUPS, oldConfig.toString());
       LOGGER.debug("backup complete for {}" , resourceId);
       return true;
}
 
Example #2
Source File: RedshiftInstanceUtil.java    From obevo with Apache License 2.0 6 votes vote down vote up
private void create(String dbInstanceIdentifier) throws Exception {
    // http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html
    CreateClusterRequest request = new CreateClusterRequest()
            .withClusterIdentifier(INSTANCE_ID)
            .withNodeType("dc2.large")
            .withDBName("dbdeploy")
            .withPubliclyAccessible(true)
            .withAvailabilityZone("us-east-1")
            .withClusterType("single-node")
            .withMasterUsername("deploybuilddbo")
            .withMasterUserPassword("Deploybuilddb0");
    Cluster response = client.createCluster(request);
    System.out.println(response);

    describe(dbInstanceIdentifier);
}
 
Example #3
Source File: RedshiftInstanceUtil.java    From obevo with Apache License 2.0 6 votes vote down vote up
private void describe(String dbInstanceIdentifier) throws Exception {
    while (true) {
        DescribeDBInstancesRequest request = new DescribeDBInstancesRequest()
                .withDBInstanceIdentifier(dbInstanceIdentifier);

        DescribeClustersResult response = client.describeClusters(new DescribeClustersRequest()
                .withClusterIdentifier(INSTANCE_ID)
        );
        Cluster dbInstance = response.getClusters().get(0);
        if (!dbInstance.getClusterStatus().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);
    }
}
 
Example #4
Source File: PublicAccessAutoFix.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
   * Gets the cluster for redhift resource.
   *
   * @param clientMap the client map
   * @param resourceId the resource id
   * @return the cluster for redhift resource
   * @throws Exception the exception
   */
  public static List<Cluster> getClusterForRedhiftResource(Map<String,Object> clientMap,String resourceId) throws Exception {
  	AmazonRedshift amazonRedshift = (AmazonRedshift) clientMap.get("client");
DescribeClustersRequest describeClustersRequest = new DescribeClustersRequest();
describeClustersRequest.setClusterIdentifier(resourceId);
DescribeClustersResult clustersResult = amazonRedshift.describeClusters(describeClustersRequest);

return clustersResult.getClusters();
  }
 
Example #5
Source File: RedshiftInstanceUtil.java    From obevo with Apache License 2.0 5 votes vote down vote up
private void restore(String dbInstanceIdentifier) throws Exception {
    Cluster response = client.restoreFromClusterSnapshot(new RestoreFromClusterSnapshotRequest()
            .withSnapshotIdentifier(SNAPSHOT_IDENTIFIER)
            .withClusterIdentifier(INSTANCE_ID)
    );
    System.out.println(response);

    describe(dbInstanceIdentifier);
}
 
Example #6
Source File: RedshiftInstanceUtil.java    From obevo with Apache License 2.0 5 votes vote down vote up
private void delete(String dbInstanceIdentifier) {
        Cluster dbInstance = client.deleteCluster(new DeleteClusterRequest()
                .withClusterIdentifier(INSTANCE_ID)
//                .withFinalClusterSnapshotIdentifier(SNAPSHOT_IDENTIFIER)
                .withSkipFinalClusterSnapshot(true)
        );
        System.out.println(dbInstance);
    }
 
Example #7
Source File: RedshiftUtils.java    From amazon-kinesis-connectors with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the JDBC URL associated with an active Amazon Redshift cluster.
 * 
 * @param client
 *        The {@link AmazonRedshiftClient} with read permissions
 * @param clusterIdentifier
 *        The unique Amazon Redshift cluster identifier
 * @return JDBC URL for the Amazon Redshift cluster
 */
public static String getClusterURL(AmazonRedshiftClient client, String clusterIdentifier) {
    DescribeClustersRequest describeClustersRequest = new DescribeClustersRequest();
    describeClustersRequest.setClusterIdentifier(clusterIdentifier);
    DescribeClustersResult describeClustersResult = client.describeClusters(describeClustersRequest);
    List<Cluster> clusters = describeClustersResult.getClusters();
    if (!clusters.isEmpty()) {
        return toJDBC(clusters.get(0).getEndpoint(), clusters.get(0).getDBName());
    }
    return null;
}
 
Example #8
Source File: RedshiftUtils.java    From amazon-kinesis-connectors with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to determine the Amazon Redshift cluster state
 * 
 * @param client
 *        The {@link AmazonRedshiftClient} with read permissions
 * @param clusterIdentifier
 *        The Amazon Redshift cluster to get the state of
 * @return The String representation of the Amazon Redshift cluster state
 */
public static String clusterState(AmazonRedshiftClient client, String clusterIdentifier) {
    DescribeClustersRequest describeClustersRequest = new DescribeClustersRequest();
    describeClustersRequest.setClusterIdentifier(clusterIdentifier);
    List<Cluster> clusters = client.describeClusters(describeClustersRequest).getClusters();
    if (clusters.size() == 1) {
        return clusters.get(0).getClusterStatus();
    }
    throw new ClusterNotFoundException(clusterIdentifier);

}
 
Example #9
Source File: RedshiftVH.java    From pacbot with Apache License 2.0 4 votes vote down vote up
public RedshiftVH(Cluster cluster){
    this.cluster = cluster;
}
 
Example #10
Source File: RedshiftVH.java    From pacbot with Apache License 2.0 4 votes vote down vote up
public Cluster getCluster() {
    return cluster;
}
 
Example #11
Source File: RedshiftVH.java    From pacbot with Apache License 2.0 4 votes vote down vote up
public void setCluster(Cluster cluster) {
    this.cluster = cluster;
}