software.amazon.awssdk.services.redshift.waiters.DefaultRedshiftWaiter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redshift Show documentation
Show all versions of redshift Show documentation
The AWS Java SDK for Amazon Redshift module holds the client classes that are used for communicating
with Amazon Redshift Service
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.redshift.waiters;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.annotations.ThreadSafe;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.ApiName;
import software.amazon.awssdk.core.internal.waiters.WaiterAttribute;
import software.amazon.awssdk.core.retry.backoff.BackoffStrategy;
import software.amazon.awssdk.core.retry.backoff.FixedDelayBackoffStrategy;
import software.amazon.awssdk.core.waiters.Waiter;
import software.amazon.awssdk.core.waiters.WaiterAcceptor;
import software.amazon.awssdk.core.waiters.WaiterOverrideConfiguration;
import software.amazon.awssdk.core.waiters.WaiterResponse;
import software.amazon.awssdk.services.redshift.RedshiftClient;
import software.amazon.awssdk.services.redshift.model.DescribeClusterSnapshotsRequest;
import software.amazon.awssdk.services.redshift.model.DescribeClusterSnapshotsResponse;
import software.amazon.awssdk.services.redshift.model.DescribeClustersRequest;
import software.amazon.awssdk.services.redshift.model.DescribeClustersResponse;
import software.amazon.awssdk.services.redshift.model.RedshiftRequest;
import software.amazon.awssdk.services.redshift.waiters.internal.WaitersRuntime;
import software.amazon.awssdk.utils.AttributeMap;
import software.amazon.awssdk.utils.SdkAutoCloseable;
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
@ThreadSafe
final class DefaultRedshiftWaiter implements RedshiftWaiter {
private static final WaiterAttribute CLIENT_ATTRIBUTE = new WaiterAttribute<>(SdkAutoCloseable.class);
private final RedshiftClient client;
private final AttributeMap managedResources;
private final Waiter clusterAvailableWaiter;
private final Waiter clusterDeletedWaiter;
private final Waiter clusterRestoredWaiter;
private final Waiter snapshotAvailableWaiter;
private DefaultRedshiftWaiter(DefaultBuilder builder) {
AttributeMap.Builder attributeMapBuilder = AttributeMap.builder();
if (builder.client == null) {
this.client = RedshiftClient.builder().build();
attributeMapBuilder.put(CLIENT_ATTRIBUTE, this.client);
} else {
this.client = builder.client;
}
managedResources = attributeMapBuilder.build();
this.clusterAvailableWaiter = Waiter.builder(DescribeClustersResponse.class).acceptors(clusterAvailableWaiterAcceptors())
.overrideConfiguration(clusterAvailableWaiterConfig(builder.overrideConfiguration)).build();
this.clusterDeletedWaiter = Waiter.builder(DescribeClustersResponse.class).acceptors(clusterDeletedWaiterAcceptors())
.overrideConfiguration(clusterDeletedWaiterConfig(builder.overrideConfiguration)).build();
this.clusterRestoredWaiter = Waiter.builder(DescribeClustersResponse.class).acceptors(clusterRestoredWaiterAcceptors())
.overrideConfiguration(clusterRestoredWaiterConfig(builder.overrideConfiguration)).build();
this.snapshotAvailableWaiter = Waiter.builder(DescribeClusterSnapshotsResponse.class)
.acceptors(snapshotAvailableWaiterAcceptors())
.overrideConfiguration(snapshotAvailableWaiterConfig(builder.overrideConfiguration)).build();
}
private static String errorCode(Throwable error) {
if (error instanceof AwsServiceException) {
return ((AwsServiceException) error).awsErrorDetails().errorCode();
}
return null;
}
@Override
public WaiterResponse waitUntilClusterAvailable(DescribeClustersRequest describeClustersRequest) {
return clusterAvailableWaiter.run(() -> client.describeClusters(applyWaitersUserAgent(describeClustersRequest)));
}
@Override
public WaiterResponse waitUntilClusterAvailable(DescribeClustersRequest describeClustersRequest,
WaiterOverrideConfiguration overrideConfig) {
return clusterAvailableWaiter.run(() -> client.describeClusters(applyWaitersUserAgent(describeClustersRequest)),
clusterAvailableWaiterConfig(overrideConfig));
}
@Override
public WaiterResponse waitUntilClusterDeleted(DescribeClustersRequest describeClustersRequest) {
return clusterDeletedWaiter.run(() -> client.describeClusters(applyWaitersUserAgent(describeClustersRequest)));
}
@Override
public WaiterResponse waitUntilClusterDeleted(DescribeClustersRequest describeClustersRequest,
WaiterOverrideConfiguration overrideConfig) {
return clusterDeletedWaiter.run(() -> client.describeClusters(applyWaitersUserAgent(describeClustersRequest)),
clusterDeletedWaiterConfig(overrideConfig));
}
@Override
public WaiterResponse waitUntilClusterRestored(DescribeClustersRequest describeClustersRequest) {
return clusterRestoredWaiter.run(() -> client.describeClusters(applyWaitersUserAgent(describeClustersRequest)));
}
@Override
public WaiterResponse waitUntilClusterRestored(DescribeClustersRequest describeClustersRequest,
WaiterOverrideConfiguration overrideConfig) {
return clusterRestoredWaiter.run(() -> client.describeClusters(applyWaitersUserAgent(describeClustersRequest)),
clusterRestoredWaiterConfig(overrideConfig));
}
@Override
public WaiterResponse waitUntilSnapshotAvailable(
DescribeClusterSnapshotsRequest describeClusterSnapshotsRequest) {
return snapshotAvailableWaiter.run(() -> client
.describeClusterSnapshots(applyWaitersUserAgent(describeClusterSnapshotsRequest)));
}
@Override
public WaiterResponse waitUntilSnapshotAvailable(
DescribeClusterSnapshotsRequest describeClusterSnapshotsRequest, WaiterOverrideConfiguration overrideConfig) {
return snapshotAvailableWaiter.run(
() -> client.describeClusterSnapshots(applyWaitersUserAgent(describeClusterSnapshotsRequest)),
snapshotAvailableWaiterConfig(overrideConfig));
}
private static List> clusterAvailableWaiterAcceptors() {
List> result = new ArrayList<>();
result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
WaitersRuntime.Value input = new WaitersRuntime.Value(response);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy