Skip to content

Commit

Permalink
Merge pull request #1262 from avano/redshift
Browse files Browse the repository at this point in the history
  • Loading branch information
avano authored Dec 3, 2024
2 parents 9cec969 + b12d3e2 commit 957c68a
Showing 1 changed file with 0 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@

import com.google.auto.service.AutoService;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Date;

import software.amazon.awssdk.services.redshift.RedshiftClient;
import software.amazon.awssdk.services.redshift.model.Cluster;
import software.amazon.awssdk.services.redshift.model.DescribeClusterSnapshotsResponse;
import software.amazon.awssdk.services.redshift.model.RedshiftException;
import software.amazon.awssdk.services.redshiftdata.RedshiftDataClient;

Expand Down Expand Up @@ -61,7 +56,6 @@ private void resumeCluster() {

private void pauseCluster() {
if (!cluster().clusterAvailabilityStatus().equalsIgnoreCase("paused")) {
checkSnapshots();
try {
redshiftClient.pauseCluster(builder -> builder.clusterIdentifier(account.clusterIdentifier()).build());
//wait for paused
Expand All @@ -73,30 +67,4 @@ private void pauseCluster() {
}
}
}

private void checkSnapshots() {
DescribeClusterSnapshotsResponse respRecent = redshiftClient.describeClusterSnapshots(builder -> builder
.clusterIdentifier(account.clusterIdentifier())
.startTime(Instant.now().minus(5, ChronoUnit.HOURS)) //any - manual/automated
);

if (respRecent.snapshots().isEmpty()) {
LOG.debug("Create a snapshot");
//needs to be created new snapshot
String id = "snapshot-tnb-" + new Date().getTime();
redshiftClient.createClusterSnapshot(builder -> builder
.clusterIdentifier(account.clusterIdentifier())
.snapshotIdentifier(id)
.manualSnapshotRetentionPeriod(1)); //1 day
//wait for snapshot to be available
WaitUtils.waitFor(() -> redshiftClient.describeClusterSnapshots(builder -> builder
.snapshotIdentifier(id)).snapshots().get(0).status().equals("available"), 30,
10000, "Waiting for snapshot " + id + " to be available");

//wait till cluster leaves "Modifying" state
WaitUtils
.waitFor(() -> !cluster().clusterAvailabilityStatus().equalsIgnoreCase("modifying"), 60, 30000,
"Waiting for Cluster " + cluster().clusterIdentifier() + " to process the snapshot");
}
}
}

0 comments on commit 957c68a

Please sign in to comment.