Skip to content

Commit d5ae5ef

Browse files
authored
Java: Updated v1 Redshift files with end-of-support notice (#6964)
* updated v1 Redshift Java files
1 parent 422a468 commit d5ae5ef

9 files changed

+48
-780
lines changed

java/example_code/redshift/ConnectToCluster.java

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,14 @@
44
// snippet-start:[redshift.java.ConnectToCluster.complete]
55

66
package connection;
7-
8-
import java.sql.*;
9-
import java.util.Properties;
10-
117
public class ConnectToCluster {
12-
// Redshift driver:
13-
// "jdbc:redshift://x.y.us-west-2.redshift.amazonaws.com:5439/dev";
14-
static final String dbURL = "***jdbc cluster connection string ****";
15-
static final String MasterUsername = "***master user name***";
16-
static final String MasterUserPassword = "***master user password***";
17-
18-
public static void main(String[] args) {
19-
Connection conn = null;
20-
Statement stmt = null;
21-
try {
22-
// Dynamically load driver at runtime.
23-
// Redshift JDBC 4.1 driver: com.amazon.redshift.jdbc41.Driver
24-
// Redshift JDBC 4 driver: com.amazon.redshift.jdbc4.Driver
25-
Class.forName("com.amazon.redshift.jdbc.Driver");
26-
27-
// Open a connection and define properties.
28-
System.out.println("Connecting to database...");
29-
Properties props = new Properties();
30-
31-
// Uncomment the following line if using a keystore.
32-
// props.setProperty("ssl", "true");
33-
props.setProperty("user", MasterUsername);
34-
props.setProperty("password", MasterUserPassword);
35-
conn = DriverManager.getConnection(dbURL, props);
36-
37-
// Try a simple query.
38-
System.out.println("Listing system tables...");
39-
stmt = conn.createStatement();
40-
String sql;
41-
sql = "select * from information_schema.tables;";
42-
ResultSet rs = stmt.executeQuery(sql);
8+
/*
9+
The AWS SDK for Java v1 is approaching end-of-support. For more information, see:
10+
https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/
4311
44-
// Get the data from the result set.
45-
while (rs.next()) {
46-
// Retrieve two columns.
47-
String catalog = rs.getString("table_catalog");
48-
String name = rs.getString("table_name");
12+
See the V2 version here:
13+
https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/redshift
14+
*/
4915

50-
// Display values.
51-
System.out.print("Catalog: " + catalog);
52-
System.out.println(", Name: " + name);
53-
}
54-
rs.close();
55-
stmt.close();
56-
conn.close();
57-
} catch (Exception ex) {
58-
// For convenience, handle all errors here.
59-
ex.printStackTrace();
60-
} finally {
61-
// Finally block to close resources.
62-
try {
63-
if (stmt != null)
64-
stmt.close();
65-
} catch (Exception ex) {
66-
} // nothing we can do
67-
try {
68-
if (conn != null)
69-
conn.close();
70-
} catch (Exception ex) {
71-
ex.printStackTrace();
72-
}
73-
}
74-
System.out.println("Finished connectivity test.");
75-
}
7616
}
7717
// snippet-end:[redshift.java.ConnectToCluster.complete]

java/example_code/redshift/ConnectToClusterExample.java

Lines changed: 0 additions & 75 deletions
This file was deleted.

java/example_code/redshift/CreateAndDescribeSnapshot.java

Lines changed: 6 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -3,102 +3,14 @@
33

44
// snippet-start:[redshift.java.CreateAndDescribeSnapshot.complete]
55

6-
import java.io.IOException;
7-
import java.text.SimpleDateFormat;
8-
import java.util.Date;
9-
10-
import com.amazonaws.services.redshift.model.*;
11-
126
public class CreateAndDescribeSnapshot {
7+
/*
8+
The AWS SDK for Java v1 is approaching end-of-support. For more information, see:
9+
https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/
1310
14-
public static AmazonRedshift client;
15-
public static String clusterIdentifier = "***provide a cluster identifier***";
16-
public static long sleepTime = 20;
17-
18-
public static void main(String[] args) throws IOException {
19-
20-
// Default client using the {@link
21-
// com.amazonaws.auth.DefaultAWSCredentialsProviderChain}
22-
client = AmazonRedshiftClientBuilder.defaultClient();
23-
24-
try {
25-
// Unique snapshot identifier
26-
String snapshotId = "my-snapshot-" + (new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss")).format(new Date());
27-
28-
Date createDate = createManualSnapshot(snapshotId);
29-
waitForSnapshotAvailable(snapshotId);
30-
describeSnapshots();
31-
deleteManualSnapshotsBefore(createDate);
32-
describeSnapshots();
33-
34-
} catch (Exception e) {
35-
System.err.println("Operation failed: " + e.getMessage());
36-
}
37-
}
38-
39-
private static Date createManualSnapshot(String snapshotId) {
40-
41-
CreateClusterSnapshotRequest request = new CreateClusterSnapshotRequest()
42-
.withClusterIdentifier(clusterIdentifier)
43-
.withSnapshotIdentifier(snapshotId);
44-
Snapshot snapshot = client.createClusterSnapshot(request);
45-
System.out.format("Created cluster snapshot: %s\n", snapshotId);
46-
return snapshot.getSnapshotCreateTime();
47-
}
48-
49-
private static void describeSnapshots() {
50-
51-
DescribeClusterSnapshotsRequest request = new DescribeClusterSnapshotsRequest()
52-
.withClusterIdentifier(clusterIdentifier);
53-
DescribeClusterSnapshotsResult result = client.describeClusterSnapshots(request);
54-
55-
printResultSnapshots(result);
56-
}
57-
58-
private static void deleteManualSnapshotsBefore(Date creationDate) {
59-
60-
DescribeClusterSnapshotsRequest request = new DescribeClusterSnapshotsRequest()
61-
.withEndTime(creationDate)
62-
.withClusterIdentifier(clusterIdentifier)
63-
.withSnapshotType("manual");
64-
65-
DescribeClusterSnapshotsResult result = client.describeClusterSnapshots(request);
66-
67-
for (Snapshot s : result.getSnapshots()) {
68-
DeleteClusterSnapshotRequest deleteRequest = new DeleteClusterSnapshotRequest()
69-
.withSnapshotIdentifier(s.getSnapshotIdentifier());
70-
Snapshot deleteResult = client.deleteClusterSnapshot(deleteRequest);
71-
System.out.format("Deleted snapshot %s\n", deleteResult.getSnapshotIdentifier());
72-
}
73-
}
74-
75-
private static void printResultSnapshots(DescribeClusterSnapshotsResult result) {
76-
System.out.println("\nSnapshot listing:");
77-
for (Snapshot snapshot : result.getSnapshots()) {
78-
System.out.format("Identifier: %s\n", snapshot.getSnapshotIdentifier());
79-
System.out.format("Snapshot type: %s\n", snapshot.getSnapshotType());
80-
System.out.format("Snapshot create time: %s\n", snapshot.getSnapshotCreateTime());
81-
System.out.format("Snapshot status: %s\n\n", snapshot.getStatus());
82-
}
83-
}
84-
85-
private static Boolean waitForSnapshotAvailable(String snapshotId) throws InterruptedException {
86-
Boolean snapshotAvailable = false;
87-
System.out.println("Waiting for snapshot to become available.");
88-
while (!snapshotAvailable) {
89-
DescribeClusterSnapshotsResult result = client
90-
.describeClusterSnapshots(new DescribeClusterSnapshotsRequest()
91-
.withSnapshotIdentifier(snapshotId));
92-
String status = (result.getSnapshots()).get(0).getStatus();
93-
if (status.equalsIgnoreCase("available")) {
94-
snapshotAvailable = true;
95-
} else {
96-
System.out.print(".");
97-
Thread.sleep(sleepTime * 1000);
98-
}
99-
}
100-
return snapshotAvailable;
101-
}
11+
See the V2 version here:
12+
https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/redshift
13+
*/
10214

10315
}
10416
// snippet-end:[redshift.java.CreateAndDescribeSnapshot.complete]

java/example_code/redshift/CreateAndModifyCluster.java

Lines changed: 6 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -16,98 +16,14 @@
1616
*/
1717
// snippet-start:[redshift.java.CreateAndModifyCluster.complete]
1818

19-
package com.amazonaws.services.redshift;
20-
21-
import java.io.IOException;
22-
import com.amazonaws.services.redshift.AmazonRedshift;
23-
import com.amazonaws.services.redshift.AmazonRedshiftClientBuilder;
24-
25-
import com.amazonaws.services.redshift.model.*;
26-
2719
public class CreateAndModifyCluster {
20+
/*
21+
The AWS SDK for Java v1 is approaching end-of-support. For more information, see:
22+
https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/
2823
29-
public static AmazonRedshift client;
30-
31-
public static String clusterIdentifier = "***provide a cluster identifier***";
32-
public static long sleepTime = 20;
33-
34-
public static void main(String[] args) throws IOException {
35-
36-
// Default client using the {@link
37-
// com.amazonaws.auth.DefaultAWSCredentialsProviderChain}
38-
client = AmazonRedshiftClientBuilder.defaultClient();
39-
40-
try {
41-
createCluster();
42-
waitForClusterReady();
43-
describeClusters();
44-
modifyCluster();
45-
describeClusters();
46-
47-
} catch (Exception e) {
48-
System.err.println("Operation failed: " + e.getMessage());
49-
}
50-
}
51-
52-
private static void createCluster() {
53-
54-
CreateClusterRequest request = new CreateClusterRequest()
55-
.withClusterIdentifier(clusterIdentifier)
56-
.withMasterUsername("masteruser")
57-
.withMasterUserPassword("12345678Aa")
58-
.withNodeType("ds2.xlarge")
59-
.withNumberOfNodes(2)
60-
.withClusterSubnetGroupName("subnetgroup1");
61-
62-
Cluster createResponse = client.createCluster(request);
63-
System.out.println("Created cluster " + createResponse.getClusterIdentifier());
64-
}
65-
66-
private static void describeClusters() {
67-
DescribeClustersRequest request = new DescribeClustersRequest()
68-
.withClusterIdentifier(clusterIdentifier);
69-
70-
DescribeClustersResult result = client.describeClusters(request);
71-
printResult(result);
72-
}
73-
74-
private static void modifyCluster() {
75-
ModifyClusterRequest request = new ModifyClusterRequest()
76-
.withClusterIdentifier(clusterIdentifier)
77-
.withPreferredMaintenanceWindow("wed:07:30-wed:08:00");
78-
79-
client.modifyCluster(request);
80-
System.out.println("Modified cluster " + clusterIdentifier);
81-
82-
}
83-
84-
private static void printResult(DescribeClustersResult result) {
85-
if (result == null) {
86-
System.out.println("Describe clusters result is null.");
87-
return;
88-
}
89-
90-
System.out.println("Cluster property:");
91-
System.out.format("Preferred Maintenance Window: %s\n",
92-
result.getClusters().get(0).getPreferredMaintenanceWindow());
93-
}
94-
95-
private static void waitForClusterReady() throws InterruptedException {
96-
Boolean clusterReady = false;
97-
System.out.println("Waiting for cluster to become available.");
98-
while (!clusterReady) {
99-
DescribeClustersResult result = client.describeClusters(new DescribeClustersRequest()
100-
.withClusterIdentifier(clusterIdentifier));
101-
102-
String status = (result.getClusters()).get(0).getClusterStatus();
103-
if (status.equalsIgnoreCase("available")) {
104-
clusterReady = true;
105-
} else {
106-
System.out.print(".");
107-
Thread.sleep(sleepTime * 1000);
108-
}
109-
}
110-
}
24+
See the V2 version here:
25+
https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/redshift
26+
*/
11127
}
11228

11329
// snippet-end:[redshift.java.CreateAndModifyCluster.complete]

0 commit comments

Comments
 (0)