diff --git a/java/example_code/redshift/ConnectToCluster.java b/java/example_code/redshift/ConnectToCluster.java index 466a20b2de9..a7fc103f75b 100644 --- a/java/example_code/redshift/ConnectToCluster.java +++ b/java/example_code/redshift/ConnectToCluster.java @@ -4,74 +4,14 @@ // snippet-start:[redshift.java.ConnectToCluster.complete] package connection; - -import java.sql.*; -import java.util.Properties; - public class ConnectToCluster { - // Redshift driver: - // "jdbc:redshift://x.y.us-west-2.redshift.amazonaws.com:5439/dev"; - static final String dbURL = "***jdbc cluster connection string ****"; - static final String MasterUsername = "***master user name***"; - static final String MasterUserPassword = "***master user password***"; - - public static void main(String[] args) { - Connection conn = null; - Statement stmt = null; - try { - // Dynamically load driver at runtime. - // Redshift JDBC 4.1 driver: com.amazon.redshift.jdbc41.Driver - // Redshift JDBC 4 driver: com.amazon.redshift.jdbc4.Driver - Class.forName("com.amazon.redshift.jdbc.Driver"); - - // Open a connection and define properties. - System.out.println("Connecting to database..."); - Properties props = new Properties(); - - // Uncomment the following line if using a keystore. - // props.setProperty("ssl", "true"); - props.setProperty("user", MasterUsername); - props.setProperty("password", MasterUserPassword); - conn = DriverManager.getConnection(dbURL, props); - - // Try a simple query. - System.out.println("Listing system tables..."); - stmt = conn.createStatement(); - String sql; - sql = "select * from information_schema.tables;"; - ResultSet rs = stmt.executeQuery(sql); + /* + The AWS SDK for Java v1 is approaching end-of-support. For more information, see: + https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/ - // Get the data from the result set. - while (rs.next()) { - // Retrieve two columns. - String catalog = rs.getString("table_catalog"); - String name = rs.getString("table_name"); + See the V2 version here: + https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/redshift + */ - // Display values. - System.out.print("Catalog: " + catalog); - System.out.println(", Name: " + name); - } - rs.close(); - stmt.close(); - conn.close(); - } catch (Exception ex) { - // For convenience, handle all errors here. - ex.printStackTrace(); - } finally { - // Finally block to close resources. - try { - if (stmt != null) - stmt.close(); - } catch (Exception ex) { - } // nothing we can do - try { - if (conn != null) - conn.close(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - System.out.println("Finished connectivity test."); - } } // snippet-end:[redshift.java.ConnectToCluster.complete] \ No newline at end of file diff --git a/java/example_code/redshift/ConnectToClusterExample.java b/java/example_code/redshift/ConnectToClusterExample.java deleted file mode 100644 index 1d321549c10..00000000000 --- a/java/example_code/redshift/ConnectToClusterExample.java +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -package connection; - -import java.sql.*; -import java.util.Properties; - -public class Docs { - // Redshift driver: - // "jdbc:redshift://x.y.us-west-2.redshift.amazonaws.com:5439/dev"; - // or "jdbc:postgresql://x.y.us-west-2.redshift.amazonaws.com:5439/dev"; - static final String dbURL = "***jdbc cluster connection string ****"; - static final String MasterUsername = "***master user name***"; - static final String MasterUserPassword = "***master user password***"; - - public static void main(String[] args) { - Connection conn = null; - Statement stmt = null; - try { - // Dynamically load driver at runtime. - // Redshift JDBC 4.1 driver: com.amazon.redshift.jdbc41.Driver - // Redshift JDBC 4 driver: com.amazon.redshift.jdbc4.Driver - Class.forName("com.amazon.redshift.jdbc.Driver"); - - // Open a connection and define properties. - System.out.println("Connecting to database..."); - Properties props = new Properties(); - - // Uncomment the following line if using a keystore. - // props.setProperty("ssl", "true"); - props.setProperty("user", MasterUsername); - props.setProperty("password", MasterUserPassword); - conn = DriverManager.getConnection(dbURL, props); - - // Try a simple query. - System.out.println("Listing system tables..."); - stmt = conn.createStatement(); - String sql; - sql = "select * from information_schema.tables;"; - ResultSet rs = stmt.executeQuery(sql); - - // Get the data from the result set. - while (rs.next()) { - // Retrieve two columns. - String catalog = rs.getString("table_catalog"); - String name = rs.getString("table_name"); - - // Display values. - System.out.print("Catalog: " + catalog); - System.out.println(", Name: " + name); - } - rs.close(); - stmt.close(); - conn.close(); - } catch (Exception ex) { - // For convenience, handle all errors here. - ex.printStackTrace(); - } finally { - // Finally block to close resources. - try { - if (stmt != null) - stmt.close(); - } catch (Exception ex) { - } // nothing we can do - try { - if (conn != null) - conn.close(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - System.out.println("Finished connectivity test."); - } -} diff --git a/java/example_code/redshift/CreateAndDescribeSnapshot.java b/java/example_code/redshift/CreateAndDescribeSnapshot.java index c9fa3036360..6990c9d3e51 100644 --- a/java/example_code/redshift/CreateAndDescribeSnapshot.java +++ b/java/example_code/redshift/CreateAndDescribeSnapshot.java @@ -3,102 +3,14 @@ // snippet-start:[redshift.java.CreateAndDescribeSnapshot.complete] -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import com.amazonaws.services.redshift.model.*; - public class CreateAndDescribeSnapshot { + /* + The AWS SDK for Java v1 is approaching end-of-support. For more information, see: + https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/ - public static AmazonRedshift client; - public static String clusterIdentifier = "***provide a cluster identifier***"; - public static long sleepTime = 20; - - public static void main(String[] args) throws IOException { - - // Default client using the {@link - // com.amazonaws.auth.DefaultAWSCredentialsProviderChain} - client = AmazonRedshiftClientBuilder.defaultClient(); - - try { - // Unique snapshot identifier - String snapshotId = "my-snapshot-" + (new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss")).format(new Date()); - - Date createDate = createManualSnapshot(snapshotId); - waitForSnapshotAvailable(snapshotId); - describeSnapshots(); - deleteManualSnapshotsBefore(createDate); - describeSnapshots(); - - } catch (Exception e) { - System.err.println("Operation failed: " + e.getMessage()); - } - } - - private static Date createManualSnapshot(String snapshotId) { - - CreateClusterSnapshotRequest request = new CreateClusterSnapshotRequest() - .withClusterIdentifier(clusterIdentifier) - .withSnapshotIdentifier(snapshotId); - Snapshot snapshot = client.createClusterSnapshot(request); - System.out.format("Created cluster snapshot: %s\n", snapshotId); - return snapshot.getSnapshotCreateTime(); - } - - private static void describeSnapshots() { - - DescribeClusterSnapshotsRequest request = new DescribeClusterSnapshotsRequest() - .withClusterIdentifier(clusterIdentifier); - DescribeClusterSnapshotsResult result = client.describeClusterSnapshots(request); - - printResultSnapshots(result); - } - - private static void deleteManualSnapshotsBefore(Date creationDate) { - - DescribeClusterSnapshotsRequest request = new DescribeClusterSnapshotsRequest() - .withEndTime(creationDate) - .withClusterIdentifier(clusterIdentifier) - .withSnapshotType("manual"); - - DescribeClusterSnapshotsResult result = client.describeClusterSnapshots(request); - - for (Snapshot s : result.getSnapshots()) { - DeleteClusterSnapshotRequest deleteRequest = new DeleteClusterSnapshotRequest() - .withSnapshotIdentifier(s.getSnapshotIdentifier()); - Snapshot deleteResult = client.deleteClusterSnapshot(deleteRequest); - System.out.format("Deleted snapshot %s\n", deleteResult.getSnapshotIdentifier()); - } - } - - private static void printResultSnapshots(DescribeClusterSnapshotsResult result) { - System.out.println("\nSnapshot listing:"); - for (Snapshot snapshot : result.getSnapshots()) { - System.out.format("Identifier: %s\n", snapshot.getSnapshotIdentifier()); - System.out.format("Snapshot type: %s\n", snapshot.getSnapshotType()); - System.out.format("Snapshot create time: %s\n", snapshot.getSnapshotCreateTime()); - System.out.format("Snapshot status: %s\n\n", snapshot.getStatus()); - } - } - - private static Boolean waitForSnapshotAvailable(String snapshotId) throws InterruptedException { - Boolean snapshotAvailable = false; - System.out.println("Waiting for snapshot to become available."); - while (!snapshotAvailable) { - DescribeClusterSnapshotsResult result = client - .describeClusterSnapshots(new DescribeClusterSnapshotsRequest() - .withSnapshotIdentifier(snapshotId)); - String status = (result.getSnapshots()).get(0).getStatus(); - if (status.equalsIgnoreCase("available")) { - snapshotAvailable = true; - } else { - System.out.print("."); - Thread.sleep(sleepTime * 1000); - } - } - return snapshotAvailable; - } + See the V2 version here: + https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/redshift + */ } // snippet-end:[redshift.java.CreateAndDescribeSnapshot.complete] diff --git a/java/example_code/redshift/CreateAndModifyCluster.java b/java/example_code/redshift/CreateAndModifyCluster.java index 714884f6632..aacddba59ca 100644 --- a/java/example_code/redshift/CreateAndModifyCluster.java +++ b/java/example_code/redshift/CreateAndModifyCluster.java @@ -16,98 +16,14 @@ */ // snippet-start:[redshift.java.CreateAndModifyCluster.complete] -package com.amazonaws.services.redshift; - -import java.io.IOException; -import com.amazonaws.services.redshift.AmazonRedshift; -import com.amazonaws.services.redshift.AmazonRedshiftClientBuilder; - -import com.amazonaws.services.redshift.model.*; - public class CreateAndModifyCluster { + /* + The AWS SDK for Java v1 is approaching end-of-support. For more information, see: + https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/ - public static AmazonRedshift client; - - public static String clusterIdentifier = "***provide a cluster identifier***"; - public static long sleepTime = 20; - - public static void main(String[] args) throws IOException { - - // Default client using the {@link - // com.amazonaws.auth.DefaultAWSCredentialsProviderChain} - client = AmazonRedshiftClientBuilder.defaultClient(); - - try { - createCluster(); - waitForClusterReady(); - describeClusters(); - modifyCluster(); - describeClusters(); - - } catch (Exception e) { - System.err.println("Operation failed: " + e.getMessage()); - } - } - - private static void createCluster() { - - CreateClusterRequest request = new CreateClusterRequest() - .withClusterIdentifier(clusterIdentifier) - .withMasterUsername("masteruser") - .withMasterUserPassword("12345678Aa") - .withNodeType("ds2.xlarge") - .withNumberOfNodes(2) - .withClusterSubnetGroupName("subnetgroup1"); - - Cluster createResponse = client.createCluster(request); - System.out.println("Created cluster " + createResponse.getClusterIdentifier()); - } - - private static void describeClusters() { - DescribeClustersRequest request = new DescribeClustersRequest() - .withClusterIdentifier(clusterIdentifier); - - DescribeClustersResult result = client.describeClusters(request); - printResult(result); - } - - private static void modifyCluster() { - ModifyClusterRequest request = new ModifyClusterRequest() - .withClusterIdentifier(clusterIdentifier) - .withPreferredMaintenanceWindow("wed:07:30-wed:08:00"); - - client.modifyCluster(request); - System.out.println("Modified cluster " + clusterIdentifier); - - } - - private static void printResult(DescribeClustersResult result) { - if (result == null) { - System.out.println("Describe clusters result is null."); - return; - } - - System.out.println("Cluster property:"); - System.out.format("Preferred Maintenance Window: %s\n", - result.getClusters().get(0).getPreferredMaintenanceWindow()); - } - - private static void waitForClusterReady() throws InterruptedException { - Boolean clusterReady = false; - System.out.println("Waiting for cluster to become available."); - while (!clusterReady) { - DescribeClustersResult result = client.describeClusters(new DescribeClustersRequest() - .withClusterIdentifier(clusterIdentifier)); - - String status = (result.getClusters()).get(0).getClusterStatus(); - if (status.equalsIgnoreCase("available")) { - clusterReady = true; - } else { - System.out.print("."); - Thread.sleep(sleepTime * 1000); - } - } - } + See the V2 version here: + https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/redshift + */ } // snippet-end:[redshift.java.CreateAndModifyCluster.complete] diff --git a/java/example_code/redshift/CreateAndModifyClusterParameterGroup.java b/java/example_code/redshift/CreateAndModifyClusterParameterGroup.java index 3d9febc6b63..a7f79f730ee 100644 --- a/java/example_code/redshift/CreateAndModifyClusterParameterGroup.java +++ b/java/example_code/redshift/CreateAndModifyClusterParameterGroup.java @@ -12,115 +12,13 @@ import com.amazonaws.services.redshift.model.*; public class CreateAndModifyClusterParameterGroup { + /* + The AWS SDK for Java v1 is approaching end-of-support. For more information, see: + https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/ - public static AmazonRedshift client; - public static String clusterParameterGroupName = "parametergroup1"; - public static String clusterIdentifier = "***provide a cluster identifier***"; - - public static String parameterGroupFamily = "redshift-1.0"; - - public static void main(String[] args) throws IOException { - - // Default client using the {@link - // com.amazonaws.auth.DefaultAWSCredentialsProviderChain} - client = AmazonRedshiftClientBuilder.defaultClient(); - - try { - createClusterParameterGroup(); - modifyClusterParameterGroup(); - associateParameterGroupWithCluster(); - describeClusterParameterGroups(); - } catch (Exception e) { - System.err.println("Operation failed: " + e.getMessage()); - } - } - - private static void createClusterParameterGroup() { - CreateClusterParameterGroupRequest request = new CreateClusterParameterGroupRequest() - .withDescription("my cluster parameter group") - .withParameterGroupName(clusterParameterGroupName) - .withParameterGroupFamily(parameterGroupFamily); - client.createClusterParameterGroup(request); - System.out.println("Created cluster parameter group."); - } - - private static void describeClusterParameterGroups() { - DescribeClusterParameterGroupsResult result = client.describeClusterParameterGroups(); - printResultClusterParameterGroups(result); - } - - private static void modifyClusterParameterGroup() { - List parameters = new ArrayList(); - parameters.add(new Parameter() - .withParameterName("extra_float_digits") - .withParameterValue("2")); - // Replace WLM configuration. The new configuration defines a queue (in addition - // to the default). - parameters.add(new Parameter() - .withParameterName("wlm_json_configuration") - .withParameterValue( - "[{\"user_group\":[\"example_user_group1\"],\"query_group\":[\"example_query_group1\"],\"query_concurrency\":7},{\"query_concurrency\":5}]")); - - ModifyClusterParameterGroupRequest request = new ModifyClusterParameterGroupRequest() - .withParameterGroupName(clusterParameterGroupName) - .withParameters(parameters); - client.modifyClusterParameterGroup(request); - - } - - private static void associateParameterGroupWithCluster() { - - ModifyClusterRequest request = new ModifyClusterRequest() - .withClusterIdentifier(clusterIdentifier) - .withClusterParameterGroupName(clusterParameterGroupName); - - Cluster result = client.modifyCluster(request); - - System.out.format("Parameter Group %s is used for Cluster %s\n", - clusterParameterGroupName, result.getClusterParameterGroups().get(0).getParameterGroupName()); - } - - private static void printResultClusterParameterGroups(DescribeClusterParameterGroupsResult result) { - if (result == null) { - System.out.println("\nDescribe cluster parameter groups result is null."); - return; - } - - System.out.println("\nPrinting parameter group results:\n"); - for (ClusterParameterGroup group : result.getParameterGroups()) { - System.out.format("\nDescription: %s\n", group.getDescription()); - System.out.format("Group Family Name: %s\n", group.getParameterGroupFamily()); - System.out.format("Group Name: %s\n", group.getParameterGroupName()); - describeClusterParameters(group.getParameterGroupName()); - } - } - - private static void describeClusterParameters(String parameterGroupName) { - DescribeClusterParametersRequest request = new DescribeClusterParametersRequest() - .withParameterGroupName(parameterGroupName); - - DescribeClusterParametersResult result = client.describeClusterParameters(request); - printResultClusterParameters(result, parameterGroupName); - } - - private static void printResultClusterParameters(DescribeClusterParametersResult result, - String parameterGroupName) { - if (result == null) { - System.out.println("\nCluster parameters is null."); - return; - } - - System.out.format("\nPrinting cluster parameters for \"%s\"\n", parameterGroupName); - for (Parameter parameter : result.getParameters()) { - System.out.println(" Name: " + parameter.getParameterName() + ", Value: " + parameter.getParameterValue()); - System.out.println(" DataType: " + parameter.getDataType() + ", MinEngineVersion: " - + parameter.getMinimumEngineVersion()); - System.out - .println(" AllowedValues: " + parameter.getAllowedValues() + ", Source: " + parameter.getSource()); - System.out.println( - " IsModifiable: " + parameter.getIsModifiable() + ", Description: " + parameter.getDescription()); - } - } + See the V2 version here: + https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/redshift + */ } // snippet-end:[redshift.java.CreateAndModifyClusterParameterGroup.complete] \ No newline at end of file diff --git a/java/example_code/redshift/CreateAndModifyClusterSecurityGroup.java b/java/example_code/redshift/CreateAndModifyClusterSecurityGroup.java index 121e4f8fd28..4464dd5f8d0 100644 --- a/java/example_code/redshift/CreateAndModifyClusterSecurityGroup.java +++ b/java/example_code/redshift/CreateAndModifyClusterSecurityGroup.java @@ -3,7 +3,6 @@ // snippet-start:[redshift.java.CreateAndModifyClusterSecurityGroup.complete] -package com.amazonaws.services.redshift; import java.io.IOException; import java.util.ArrayList; @@ -13,109 +12,12 @@ public class CreateAndModifyClusterSecurityGroup { - public static AmazonRedshift client; - public static String clusterSecurityGroupName = "securitygroup1"; - public static String clusterIdentifier = "***provide a cluster identifier***"; - public static String ownerID = "***provide a 12-digit account number***"; + /* + The AWS SDK for Java v1 is approaching end-of-support. For more information, see: + https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/ - public static void main(String[] args) throws IOException { - - // Default client using the {@link - // com.amazonaws.auth.DefaultAWSCredentialsProviderChain} - client = AmazonRedshiftClientBuilder.defaultClient(); - - try { - createClusterSecurityGroup(); - describeClusterSecurityGroups(); - addIngressRules(); - associateSecurityGroupWithCluster(); - } catch (Exception e) { - System.err.println("Operation failed: " + e.getMessage()); - } - } - - private static void createClusterSecurityGroup() { - CreateClusterSecurityGroupRequest request = new CreateClusterSecurityGroupRequest() - .withDescription("my cluster security group") - .withClusterSecurityGroupName(clusterSecurityGroupName); - - client.createClusterSecurityGroup(request); - System.out.format("Created cluster security group: '%s'\n", clusterSecurityGroupName); - } - - private static void addIngressRules() { - - AuthorizeClusterSecurityGroupIngressRequest request = new AuthorizeClusterSecurityGroupIngressRequest() - .withClusterSecurityGroupName(clusterSecurityGroupName) - .withCIDRIP("192.168.40.5/32"); - - ClusterSecurityGroup result = client.authorizeClusterSecurityGroupIngress(request); - - request = new AuthorizeClusterSecurityGroupIngressRequest() - .withClusterSecurityGroupName(clusterSecurityGroupName) - .withEC2SecurityGroupName("default") - .withEC2SecurityGroupOwnerId(ownerID); - result = client.authorizeClusterSecurityGroupIngress(request); - System.out.format("\nAdded ingress rules to security group '%s'\n", clusterSecurityGroupName); - printResultSecurityGroup(result); - } - - private static void associateSecurityGroupWithCluster() { - - // Get existing security groups used by the cluster. - DescribeClustersRequest request = new DescribeClustersRequest() - .withClusterIdentifier(clusterIdentifier); - - DescribeClustersResult result = client.describeClusters(request); - List membershipList = result.getClusters().get(0).getClusterSecurityGroups(); - - List secGroupNames = new ArrayList(); - for (ClusterSecurityGroupMembership mem : membershipList) { - secGroupNames.add(mem.getClusterSecurityGroupName()); - } - // Add new security group to the list. - secGroupNames.add(clusterSecurityGroupName); - - // Apply the change to the cluster. - ModifyClusterRequest request2 = new ModifyClusterRequest() - .withClusterIdentifier(clusterIdentifier) - .withClusterSecurityGroups(secGroupNames); - - Cluster result2 = client.modifyCluster(request2); - System.out.format("\nAssociated security group '%s' to cluster '%s'.", clusterSecurityGroupName, - clusterIdentifier); - } - - private static void describeClusterSecurityGroups() { - DescribeClusterSecurityGroupsRequest request = new DescribeClusterSecurityGroupsRequest(); - - DescribeClusterSecurityGroupsResult result = client.describeClusterSecurityGroups(request); - printResultSecurityGroups(result.getClusterSecurityGroups()); - } - - private static void printResultSecurityGroups(List groups) { - if (groups == null) { - System.out.println("\nDescribe cluster security groups result is null."); - return; - } - - System.out.println("\nPrinting security group results:"); - for (ClusterSecurityGroup group : groups) { - printResultSecurityGroup(group); - } - } - - private static void printResultSecurityGroup(ClusterSecurityGroup group) { - System.out.format("\nName: '%s', Description: '%s'\n", group.getClusterSecurityGroupName(), - group.getDescription()); - for (EC2SecurityGroup g : group.getEC2SecurityGroups()) { - System.out.format("EC2group: '%s', '%s', '%s'\n", g.getEC2SecurityGroupName(), - g.getEC2SecurityGroupOwnerId(), g.getStatus()); - } - for (IPRange range : group.getIPRanges()) { - System.out.format("IPRanges: '%s', '%s'\n", range.getCIDRIP(), range.getStatus()); - - } - } + See the V2 version here: + https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/redshift + */ } // snippet-end:[redshift.java.CreateAndModifyClusterSecurityGroup.complete] \ No newline at end of file diff --git a/java/example_code/redshift/CreateAndModifyClusterSubnetGroup.java b/java/example_code/redshift/CreateAndModifyClusterSubnetGroup.java index 59b43a71658..f1694108353 100644 --- a/java/example_code/redshift/CreateAndModifyClusterSubnetGroup.java +++ b/java/example_code/redshift/CreateAndModifyClusterSubnetGroup.java @@ -11,86 +11,12 @@ import com.amazonaws.services.redshift.model.*; public class CreateAndModifyClusterSubnetGroup { + /* + The AWS SDK for Java v1 is approaching end-of-support. For more information, see: + https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/ - public static AmazonRedshift client; - public static String clusterSubnetGroupName = "subnet-group-name"; - - // You can use the VPC console to find subnet IDs to use. - public static String subnetId1 = "***provide a subnet ID****"; - public static String subnetId2 = "***provide a subnet ID****"; - - public static void main(String[] args) throws IOException { - - // Default client using the {@link - // com.amazonaws.auth.DefaultAWSCredentialsProviderChain} - client = AmazonRedshiftClientBuilder.defaultClient(); - - try { - createClusterSubnetGroup(); - describeClusterSubnetGroups(); - modifyClusterSubnetGroup(); - } catch (Exception e) { - System.err.println("Operation failed: " + e.getMessage()); - } - } - - private static void createClusterSubnetGroup() { - CreateClusterSubnetGroupRequest request = new CreateClusterSubnetGroupRequest() - .withClusterSubnetGroupName(clusterSubnetGroupName) - .withDescription("my cluster subnet group") - .withSubnetIds(subnetId1); - client.createClusterSubnetGroup(request); - System.out.println("Created cluster subnet group: " + clusterSubnetGroupName); - } - - private static void modifyClusterSubnetGroup() { - // Get existing subnet list. - DescribeClusterSubnetGroupsRequest request1 = new DescribeClusterSubnetGroupsRequest() - .withClusterSubnetGroupName(clusterSubnetGroupName); - DescribeClusterSubnetGroupsResult result1 = client.describeClusterSubnetGroups(request1); - List subnetNames = new ArrayList(); - // We can work with just the first group returned since we requested info about - // one group. - for (Subnet subnet : result1.getClusterSubnetGroups().get(0).getSubnets()) { - subnetNames.add(subnet.getSubnetIdentifier()); - } - // Add to existing subnet list. - subnetNames.add(subnetId2); - - ModifyClusterSubnetGroupRequest request = new ModifyClusterSubnetGroupRequest() - .withClusterSubnetGroupName(clusterSubnetGroupName) - .withSubnetIds(subnetNames); - ClusterSubnetGroup result2 = client.modifyClusterSubnetGroup(request); - System.out.println("\nSubnet group modified."); - printResultSubnetGroup(result2); - } - - private static void describeClusterSubnetGroups() { - DescribeClusterSubnetGroupsRequest request = new DescribeClusterSubnetGroupsRequest() - .withClusterSubnetGroupName(clusterSubnetGroupName); - - DescribeClusterSubnetGroupsResult result = client.describeClusterSubnetGroups(request); - printResultSubnetGroups(result); - } - - private static void printResultSubnetGroups(DescribeClusterSubnetGroupsResult result) { - if (result == null) { - System.out.println("\nDescribe cluster subnet groups result is null."); - return; - } - - for (ClusterSubnetGroup group : result.getClusterSubnetGroups()) { - printResultSubnetGroup(group); - } - - } - - private static void printResultSubnetGroup(ClusterSubnetGroup group) { - System.out.format("Name: %s, Description: %s\n", group.getClusterSubnetGroupName(), group.getDescription()); - for (Subnet subnet : group.getSubnets()) { - System.out.format(" Subnet: %s, %s, %s\n", subnet.getSubnetIdentifier(), - subnet.getSubnetAvailabilityZone().getName(), subnet.getSubnetStatus()); - } - } + See the V2 version here: + https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/redshift + */ } // snippet-end:[redshift.java.CreateAndModifyClusterSubnetGroup.complete] \ No newline at end of file diff --git a/java/example_code/redshift/ListAndPurchaseReservedNodeOffering.java b/java/example_code/redshift/ListAndPurchaseReservedNodeOffering.java index 63bad03ac85..6c8d6191dd9 100644 --- a/java/example_code/redshift/ListAndPurchaseReservedNodeOffering.java +++ b/java/example_code/redshift/ListAndPurchaseReservedNodeOffering.java @@ -13,110 +13,13 @@ import com.amazonaws.services.redshift.model.*; public class ListAndPurchaseReservedNodeOffering { + /* + The AWS SDK for Java v1 is approaching end-of-support. For more information, see: + https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/ - public static AmazonRedshift client; - public static String nodeTypeToPurchase = "dc2.large"; + See the V2 version here: + https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/redshift + */ - public static Double fixedPriceLimit = 10000.00; - public static ArrayList matchingNodes = new ArrayList(); - - public static void main(String[] args) throws IOException { - - // Default client using the {@link - // com.amazonaws.auth.DefaultAWSCredentialsProviderChain} - client = AmazonRedshiftClientBuilder.defaultClient(); - - try { - listReservedNodes(); - findReservedNodeOffer(); - purchaseReservedNodeOffer(); - - } catch (Exception e) { - System.err.println("Operation failed: " + e.getMessage()); - } - } - - private static void listReservedNodes() { - DescribeReservedNodesResult result = client.describeReservedNodes(); - System.out.println("Listing nodes already purchased."); - for (ReservedNode node : result.getReservedNodes()) { - printReservedNodeDetails(node); - } - } - - private static void findReservedNodeOffer() { - DescribeReservedNodeOfferingsRequest request = new DescribeReservedNodeOfferingsRequest(); - DescribeReservedNodeOfferingsResult result = client.describeReservedNodeOfferings(request); - Integer count = 0; - - System.out.println("\nFinding nodes to purchase."); - for (ReservedNodeOffering offering : result.getReservedNodeOfferings()) { - if (offering.getNodeType().equals(nodeTypeToPurchase)) { - - if (offering.getFixedPrice() < fixedPriceLimit) { - matchingNodes.add(offering); - printOfferingDetails(offering); - count += 1; - } - } - } - if (count == 0) { - System.out.println("\nNo reserved node offering matches found."); - } else { - System.out.println("\nFound " + count + " matches."); - } - } - - private static void purchaseReservedNodeOffer() throws IOException { - if (matchingNodes.size() == 0) { - return; - } else { - System.out.println("\nPurchasing nodes."); - - for (ReservedNodeOffering offering : matchingNodes) { - printOfferingDetails(offering); - System.out.println("WARNING: purchasing this offering will incur costs."); - System.out.println("Purchase this offering [Y or N]?"); - DataInput in = new DataInputStream(System.in); - String purchaseOpt = in.readLine(); - if (purchaseOpt.equalsIgnoreCase("y")) { - - try { - PurchaseReservedNodeOfferingRequest request = new PurchaseReservedNodeOfferingRequest() - .withReservedNodeOfferingId(offering.getReservedNodeOfferingId()); - ReservedNode reservedNode = client.purchaseReservedNodeOffering(request); - printReservedNodeDetails(reservedNode); - } catch (ReservedNodeAlreadyExistsException ex1) { - } catch (ReservedNodeOfferingNotFoundException ex2) { - } catch (ReservedNodeQuotaExceededException ex3) { - } catch (Exception ex4) { - } - } - } - System.out.println("Finished."); - - } - } - - private static void printOfferingDetails( - ReservedNodeOffering offering) { - System.out.println("\nOffering Match:"); - System.out.format("Id: %s\n", offering.getReservedNodeOfferingId()); - System.out.format("Node Type: %s\n", offering.getNodeType()); - System.out.format("Fixed Price: %s\n", offering.getFixedPrice()); - System.out.format("Offering Type: %s\n", offering.getOfferingType()); - System.out.format("Duration: %s\n", offering.getDuration()); - } - - private static void printReservedNodeDetails(ReservedNode node) { - System.out.println("\nPurchased Node Details:"); - System.out.format("Id: %s\n", node.getReservedNodeOfferingId()); - System.out.format("State: %s\n", node.getState()); - System.out.format("Node Type: %s\n", node.getNodeType()); - System.out.format("Start Time: %s\n", node.getStartTime()); - System.out.format("Fixed Price: %s\n", node.getFixedPrice()); - System.out.format("Offering Type: %s\n", node.getOfferingType()); - System.out.format("Duration: %s\n", node.getDuration()); - } } // snippet-end:[redshift.java.ListAndPurchaseReservedNodeOffering.complete] \ No newline at end of file diff --git a/java/example_code/redshift/ListEvents.java b/java/example_code/redshift/ListEvents.java index 8a3e737e0ab..c22f4895153 100644 --- a/java/example_code/redshift/ListEvents.java +++ b/java/example_code/redshift/ListEvents.java @@ -2,67 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // snippet-start:[redshift.java.ListEvents.complete] - -package com.amazonaws.services.redshift; - -import java.util.Date; -import java.io.IOException; - -import com.amazonaws.services.redshift.model.*; - public class ListEvents { + /* + The AWS SDK for Java v1 is approaching end-of-support. For more information, see: + https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/ - public static AmazonRedshift client; - public static String clusterIdentifier = "***provide cluster identifier***"; - public static String eventSourceType = "cluster"; // e.g. cluster-snapshot - - public static void main(String[] args) throws IOException { - - // Default client using the {@link - // com.amazonaws.auth.DefaultAWSCredentialsProviderChain} - - client = AmazonRedshiftClientBuilder.defaultClient(); - - try { - listEvents(); - } catch (Exception e) { - System.err.println("Operation failed: " + e.getMessage()); - } - } - - private static void listEvents() { - long oneWeeksAgoMilli = (new Date()).getTime() - (7L * 24L * 60L * 60L * 1000L); - Date oneWeekAgo = new Date(); - oneWeekAgo.setTime(oneWeeksAgoMilli); - String marker = null; - - do { - DescribeEventsRequest request = new DescribeEventsRequest() - .withSourceIdentifier(clusterIdentifier) - .withSourceType(eventSourceType) - .withStartTime(oneWeekAgo) - .withMaxRecords(20); - DescribeEventsResult result = client.describeEvents(request); - marker = result.getMarker(); - for (Event event : result.getEvents()) { - printEvent(event); - } - } while (marker != null); - - } - - static void printEvent(Event event) { - if (event == null) { - System.out.println("\nEvent object is null."); - return; - } - - System.out.println("\nEvent metadata:\n"); - System.out.format("SourceID: %s\n", event.getSourceIdentifier()); - System.out.format("Type: %s\n", event.getSourceType()); - System.out.format("Message: %s\n", event.getMessage()); - System.out.format("Date: %s\n", event.getDate()); - } - + See the V2 version here: + https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/redshift + */ } // snippet-end:[redshift.java.ListEvents.complete]