software.amazon.awssdk.services.elasticbeanstalk.waiters.DefaultElasticBeanstalkWaiter Maven / Gradle / Ivy
/*
* 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.elasticbeanstalk.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.elasticbeanstalk.ElasticBeanstalkClient;
import software.amazon.awssdk.services.elasticbeanstalk.model.DescribeEnvironmentsRequest;
import software.amazon.awssdk.services.elasticbeanstalk.model.DescribeEnvironmentsResponse;
import software.amazon.awssdk.services.elasticbeanstalk.model.ElasticBeanstalkRequest;
import software.amazon.awssdk.services.elasticbeanstalk.waiters.internal.WaitersRuntime;
import software.amazon.awssdk.utils.AttributeMap;
import software.amazon.awssdk.utils.SdkAutoCloseable;
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
@ThreadSafe
final class DefaultElasticBeanstalkWaiter implements ElasticBeanstalkWaiter {
private static final WaiterAttribute CLIENT_ATTRIBUTE = new WaiterAttribute<>(SdkAutoCloseable.class);
private final ElasticBeanstalkClient client;
private final AttributeMap managedResources;
private final Waiter environmentExistsWaiter;
private final Waiter environmentUpdatedWaiter;
private final Waiter environmentTerminatedWaiter;
private DefaultElasticBeanstalkWaiter(DefaultBuilder builder) {
AttributeMap.Builder attributeMapBuilder = AttributeMap.builder();
if (builder.client == null) {
this.client = ElasticBeanstalkClient.builder().build();
attributeMapBuilder.put(CLIENT_ATTRIBUTE, this.client);
} else {
this.client = builder.client;
}
managedResources = attributeMapBuilder.build();
this.environmentExistsWaiter = Waiter.builder(DescribeEnvironmentsResponse.class)
.acceptors(environmentExistsWaiterAcceptors())
.overrideConfiguration(environmentExistsWaiterConfig(builder.overrideConfiguration)).build();
this.environmentUpdatedWaiter = Waiter.builder(DescribeEnvironmentsResponse.class)
.acceptors(environmentUpdatedWaiterAcceptors())
.overrideConfiguration(environmentUpdatedWaiterConfig(builder.overrideConfiguration)).build();
this.environmentTerminatedWaiter = Waiter.builder(DescribeEnvironmentsResponse.class)
.acceptors(environmentTerminatedWaiterAcceptors())
.overrideConfiguration(environmentTerminatedWaiterConfig(builder.overrideConfiguration)).build();
}
private static String errorCode(Throwable error) {
if (error instanceof AwsServiceException) {
return ((AwsServiceException) error).awsErrorDetails().errorCode();
}
return null;
}
@Override
public WaiterResponse waitUntilEnvironmentExists(
DescribeEnvironmentsRequest describeEnvironmentsRequest) {
return environmentExistsWaiter.run(() -> client.describeEnvironments(applyWaitersUserAgent(describeEnvironmentsRequest)));
}
@Override
public WaiterResponse waitUntilEnvironmentExists(
DescribeEnvironmentsRequest describeEnvironmentsRequest, WaiterOverrideConfiguration overrideConfig) {
return environmentExistsWaiter.run(() -> client.describeEnvironments(applyWaitersUserAgent(describeEnvironmentsRequest)),
environmentExistsWaiterConfig(overrideConfig));
}
@Override
public WaiterResponse waitUntilEnvironmentTerminated(
DescribeEnvironmentsRequest describeEnvironmentsRequest) {
return environmentTerminatedWaiter.run(() -> client
.describeEnvironments(applyWaitersUserAgent(describeEnvironmentsRequest)));
}
@Override
public WaiterResponse waitUntilEnvironmentTerminated(
DescribeEnvironmentsRequest describeEnvironmentsRequest, WaiterOverrideConfiguration overrideConfig) {
return environmentTerminatedWaiter.run(
() -> client.describeEnvironments(applyWaitersUserAgent(describeEnvironmentsRequest)),
environmentTerminatedWaiterConfig(overrideConfig));
}
@Override
public WaiterResponse waitUntilEnvironmentUpdated(
DescribeEnvironmentsRequest describeEnvironmentsRequest) {
return environmentUpdatedWaiter
.run(() -> client.describeEnvironments(applyWaitersUserAgent(describeEnvironmentsRequest)));
}
@Override
public WaiterResponse waitUntilEnvironmentUpdated(
DescribeEnvironmentsRequest describeEnvironmentsRequest, WaiterOverrideConfiguration overrideConfig) {
return environmentUpdatedWaiter.run(
() -> client.describeEnvironments(applyWaitersUserAgent(describeEnvironmentsRequest)),
environmentUpdatedWaiterConfig(overrideConfig));
}
private static List> environmentExistsWaiterAcceptors() {
List> result = new ArrayList<>();
result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
WaitersRuntime.Value input = new WaitersRuntime.Value(response);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy