All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.databasemigration.waiters.DefaultDatabaseMigrationWaiter 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.databasemigration.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.databasemigration.DatabaseMigrationClient;
import software.amazon.awssdk.services.databasemigration.model.DatabaseMigrationRequest;
import software.amazon.awssdk.services.databasemigration.model.DescribeConnectionsRequest;
import software.amazon.awssdk.services.databasemigration.model.DescribeConnectionsResponse;
import software.amazon.awssdk.services.databasemigration.model.DescribeEndpointsRequest;
import software.amazon.awssdk.services.databasemigration.model.DescribeEndpointsResponse;
import software.amazon.awssdk.services.databasemigration.model.DescribeReplicationInstancesRequest;
import software.amazon.awssdk.services.databasemigration.model.DescribeReplicationInstancesResponse;
import software.amazon.awssdk.services.databasemigration.model.DescribeReplicationTasksRequest;
import software.amazon.awssdk.services.databasemigration.model.DescribeReplicationTasksResponse;
import software.amazon.awssdk.services.databasemigration.waiters.internal.WaitersRuntime;
import software.amazon.awssdk.utils.AttributeMap;
import software.amazon.awssdk.utils.SdkAutoCloseable;

@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
@ThreadSafe
final class DefaultDatabaseMigrationWaiter implements DatabaseMigrationWaiter {
    private static final WaiterAttribute CLIENT_ATTRIBUTE = new WaiterAttribute<>(SdkAutoCloseable.class);

    private final DatabaseMigrationClient client;

    private final AttributeMap managedResources;

    private final Waiter testConnectionSucceedsWaiter;

    private final Waiter endpointDeletedWaiter;

    private final Waiter replicationInstanceAvailableWaiter;

    private final Waiter replicationInstanceDeletedWaiter;

    private final Waiter replicationTaskReadyWaiter;

    private final Waiter replicationTaskStoppedWaiter;

    private final Waiter replicationTaskRunningWaiter;

    private final Waiter replicationTaskDeletedWaiter;

    private DefaultDatabaseMigrationWaiter(DefaultBuilder builder) {
        AttributeMap.Builder attributeMapBuilder = AttributeMap.builder();
        if (builder.client == null) {
            this.client = DatabaseMigrationClient.builder().build();
            attributeMapBuilder.put(CLIENT_ATTRIBUTE, this.client);
        } else {
            this.client = builder.client;
        }
        managedResources = attributeMapBuilder.build();
        this.testConnectionSucceedsWaiter = Waiter.builder(DescribeConnectionsResponse.class)
                .acceptors(testConnectionSucceedsWaiterAcceptors())
                .overrideConfiguration(testConnectionSucceedsWaiterConfig(builder.overrideConfiguration)).build();
        this.endpointDeletedWaiter = Waiter.builder(DescribeEndpointsResponse.class).acceptors(endpointDeletedWaiterAcceptors())
                .overrideConfiguration(endpointDeletedWaiterConfig(builder.overrideConfiguration)).build();
        this.replicationInstanceAvailableWaiter = Waiter.builder(DescribeReplicationInstancesResponse.class)
                .acceptors(replicationInstanceAvailableWaiterAcceptors())
                .overrideConfiguration(replicationInstanceAvailableWaiterConfig(builder.overrideConfiguration)).build();
        this.replicationInstanceDeletedWaiter = Waiter.builder(DescribeReplicationInstancesResponse.class)
                .acceptors(replicationInstanceDeletedWaiterAcceptors())
                .overrideConfiguration(replicationInstanceDeletedWaiterConfig(builder.overrideConfiguration)).build();
        this.replicationTaskReadyWaiter = Waiter.builder(DescribeReplicationTasksResponse.class)
                .acceptors(replicationTaskReadyWaiterAcceptors())
                .overrideConfiguration(replicationTaskReadyWaiterConfig(builder.overrideConfiguration)).build();
        this.replicationTaskStoppedWaiter = Waiter.builder(DescribeReplicationTasksResponse.class)
                .acceptors(replicationTaskStoppedWaiterAcceptors())
                .overrideConfiguration(replicationTaskStoppedWaiterConfig(builder.overrideConfiguration)).build();
        this.replicationTaskRunningWaiter = Waiter.builder(DescribeReplicationTasksResponse.class)
                .acceptors(replicationTaskRunningWaiterAcceptors())
                .overrideConfiguration(replicationTaskRunningWaiterConfig(builder.overrideConfiguration)).build();
        this.replicationTaskDeletedWaiter = Waiter.builder(DescribeReplicationTasksResponse.class)
                .acceptors(replicationTaskDeletedWaiterAcceptors())
                .overrideConfiguration(replicationTaskDeletedWaiterConfig(builder.overrideConfiguration)).build();
    }

    private static String errorCode(Throwable error) {
        if (error instanceof AwsServiceException) {
            return ((AwsServiceException) error).awsErrorDetails().errorCode();
        }
        return null;
    }

    @Override
    public WaiterResponse waitUntilEndpointDeleted(DescribeEndpointsRequest describeEndpointsRequest) {
        return endpointDeletedWaiter.run(() -> client.describeEndpoints(applyWaitersUserAgent(describeEndpointsRequest)));
    }

    @Override
    public WaiterResponse waitUntilEndpointDeleted(DescribeEndpointsRequest describeEndpointsRequest,
            WaiterOverrideConfiguration overrideConfig) {
        return endpointDeletedWaiter.run(() -> client.describeEndpoints(applyWaitersUserAgent(describeEndpointsRequest)),
                endpointDeletedWaiterConfig(overrideConfig));
    }

    @Override
    public WaiterResponse waitUntilReplicationInstanceAvailable(
            DescribeReplicationInstancesRequest describeReplicationInstancesRequest) {
        return replicationInstanceAvailableWaiter.run(() -> client
                .describeReplicationInstances(applyWaitersUserAgent(describeReplicationInstancesRequest)));
    }

    @Override
    public WaiterResponse waitUntilReplicationInstanceAvailable(
            DescribeReplicationInstancesRequest describeReplicationInstancesRequest, WaiterOverrideConfiguration overrideConfig) {
        return replicationInstanceAvailableWaiter.run(
                () -> client.describeReplicationInstances(applyWaitersUserAgent(describeReplicationInstancesRequest)),
                replicationInstanceAvailableWaiterConfig(overrideConfig));
    }

    @Override
    public WaiterResponse waitUntilReplicationInstanceDeleted(
            DescribeReplicationInstancesRequest describeReplicationInstancesRequest) {
        return replicationInstanceDeletedWaiter.run(() -> client
                .describeReplicationInstances(applyWaitersUserAgent(describeReplicationInstancesRequest)));
    }

    @Override
    public WaiterResponse waitUntilReplicationInstanceDeleted(
            DescribeReplicationInstancesRequest describeReplicationInstancesRequest, WaiterOverrideConfiguration overrideConfig) {
        return replicationInstanceDeletedWaiter.run(
                () -> client.describeReplicationInstances(applyWaitersUserAgent(describeReplicationInstancesRequest)),
                replicationInstanceDeletedWaiterConfig(overrideConfig));
    }

    @Override
    public WaiterResponse waitUntilReplicationTaskDeleted(
            DescribeReplicationTasksRequest describeReplicationTasksRequest) {
        return replicationTaskDeletedWaiter.run(() -> client
                .describeReplicationTasks(applyWaitersUserAgent(describeReplicationTasksRequest)));
    }

    @Override
    public WaiterResponse waitUntilReplicationTaskDeleted(
            DescribeReplicationTasksRequest describeReplicationTasksRequest, WaiterOverrideConfiguration overrideConfig) {
        return replicationTaskDeletedWaiter.run(
                () -> client.describeReplicationTasks(applyWaitersUserAgent(describeReplicationTasksRequest)),
                replicationTaskDeletedWaiterConfig(overrideConfig));
    }

    @Override
    public WaiterResponse waitUntilReplicationTaskReady(
            DescribeReplicationTasksRequest describeReplicationTasksRequest) {
        return replicationTaskReadyWaiter.run(() -> client
                .describeReplicationTasks(applyWaitersUserAgent(describeReplicationTasksRequest)));
    }

    @Override
    public WaiterResponse waitUntilReplicationTaskReady(
            DescribeReplicationTasksRequest describeReplicationTasksRequest, WaiterOverrideConfiguration overrideConfig) {
        return replicationTaskReadyWaiter.run(
                () -> client.describeReplicationTasks(applyWaitersUserAgent(describeReplicationTasksRequest)),
                replicationTaskReadyWaiterConfig(overrideConfig));
    }

    @Override
    public WaiterResponse waitUntilReplicationTaskRunning(
            DescribeReplicationTasksRequest describeReplicationTasksRequest) {
        return replicationTaskRunningWaiter.run(() -> client
                .describeReplicationTasks(applyWaitersUserAgent(describeReplicationTasksRequest)));
    }

    @Override
    public WaiterResponse waitUntilReplicationTaskRunning(
            DescribeReplicationTasksRequest describeReplicationTasksRequest, WaiterOverrideConfiguration overrideConfig) {
        return replicationTaskRunningWaiter.run(
                () -> client.describeReplicationTasks(applyWaitersUserAgent(describeReplicationTasksRequest)),
                replicationTaskRunningWaiterConfig(overrideConfig));
    }

    @Override
    public WaiterResponse waitUntilReplicationTaskStopped(
            DescribeReplicationTasksRequest describeReplicationTasksRequest) {
        return replicationTaskStoppedWaiter.run(() -> client
                .describeReplicationTasks(applyWaitersUserAgent(describeReplicationTasksRequest)));
    }

    @Override
    public WaiterResponse waitUntilReplicationTaskStopped(
            DescribeReplicationTasksRequest describeReplicationTasksRequest, WaiterOverrideConfiguration overrideConfig) {
        return replicationTaskStoppedWaiter.run(
                () -> client.describeReplicationTasks(applyWaitersUserAgent(describeReplicationTasksRequest)),
                replicationTaskStoppedWaiterConfig(overrideConfig));
    }

    @Override
    public WaiterResponse waitUntilTestConnectionSucceeds(
            DescribeConnectionsRequest describeConnectionsRequest) {
        return testConnectionSucceedsWaiter.run(() -> client
                .describeConnections(applyWaitersUserAgent(describeConnectionsRequest)));
    }

    @Override
    public WaiterResponse waitUntilTestConnectionSucceeds(
            DescribeConnectionsRequest describeConnectionsRequest, WaiterOverrideConfiguration overrideConfig) {
        return testConnectionSucceedsWaiter.run(
                () -> client.describeConnections(applyWaitersUserAgent(describeConnectionsRequest)),
                testConnectionSucceedsWaiterConfig(overrideConfig));
    }

    private static List> testConnectionSucceedsWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("Connections").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().allMatch(v -> Objects.equals(v, "successful"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("Connections").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "failed"));
        }));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> endpointDeletedWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnExceptionAcceptor(error -> Objects.equals(errorCode(error), "ResourceNotFoundFault")));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("Endpoints").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "active"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("Endpoints").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "creating"));
        }));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> replicationInstanceAvailableWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor
                .successOnResponseAcceptor(response -> {
                    WaitersRuntime.Value input = new WaitersRuntime.Value(response);
                    List resultValues = input.field("ReplicationInstances").flatten().field("ReplicationInstanceStatus")
                            .values();
                    return !resultValues.isEmpty() && resultValues.stream().allMatch(v -> Objects.equals(v, "available"));
                }));
        result.add(WaiterAcceptor
                .errorOnResponseAcceptor(response -> {
                    WaitersRuntime.Value input = new WaitersRuntime.Value(response);
                    List resultValues = input.field("ReplicationInstances").flatten().field("ReplicationInstanceStatus")
                            .values();
                    return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "deleting"));
                }));
        result.add(WaiterAcceptor
                .errorOnResponseAcceptor(response -> {
                    WaitersRuntime.Value input = new WaitersRuntime.Value(response);
                    List resultValues = input.field("ReplicationInstances").flatten().field("ReplicationInstanceStatus")
                            .values();
                    return !resultValues.isEmpty()
                            && resultValues.stream().anyMatch(v -> Objects.equals(v, "incompatible-credentials"));
                }));
        result.add(WaiterAcceptor
                .errorOnResponseAcceptor(response -> {
                    WaitersRuntime.Value input = new WaitersRuntime.Value(response);
                    List resultValues = input.field("ReplicationInstances").flatten().field("ReplicationInstanceStatus")
                            .values();
                    return !resultValues.isEmpty()
                            && resultValues.stream().anyMatch(v -> Objects.equals(v, "incompatible-network"));
                }));
        result.add(WaiterAcceptor
                .errorOnResponseAcceptor(response -> {
                    WaitersRuntime.Value input = new WaitersRuntime.Value(response);
                    List resultValues = input.field("ReplicationInstances").flatten().field("ReplicationInstanceStatus")
                            .values();
                    return !resultValues.isEmpty()
                            && resultValues.stream().anyMatch(v -> Objects.equals(v, "inaccessible-encryption-credentials"));
                }));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> replicationInstanceDeletedWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor
                .errorOnResponseAcceptor(response -> {
                    WaitersRuntime.Value input = new WaitersRuntime.Value(response);
                    List resultValues = input.field("ReplicationInstances").flatten().field("ReplicationInstanceStatus")
                            .values();
                    return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "available"));
                }));
        result.add(WaiterAcceptor.successOnExceptionAcceptor(error -> Objects.equals(errorCode(error), "ResourceNotFoundFault")));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> replicationTaskReadyWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().allMatch(v -> Objects.equals(v, "ready"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "starting"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "running"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "stopping"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "stopped"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "failed"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "modifying"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "testing"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "deleting"));
        }));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> replicationTaskStoppedWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().allMatch(v -> Objects.equals(v, "stopped"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "ready"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "creating"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "starting"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "failed"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "modifying"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "testing"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "deleting"));
        }));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> replicationTaskRunningWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().allMatch(v -> Objects.equals(v, "running"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "ready"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "creating"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "stopping"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "stopped"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "failed"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "modifying"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "testing"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "deleting"));
        }));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> replicationTaskDeletedWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "ready"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "creating"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "stopped"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "running"));
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(response -> {
            WaitersRuntime.Value input = new WaitersRuntime.Value(response);
            List resultValues = input.field("ReplicationTasks").flatten().field("Status").values();
            return !resultValues.isEmpty() && resultValues.stream().anyMatch(v -> Objects.equals(v, "failed"));
        }));
        result.add(WaiterAcceptor.successOnExceptionAcceptor(error -> Objects.equals(errorCode(error), "ResourceNotFoundFault")));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static WaiterOverrideConfiguration testConnectionSucceedsWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(60);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategy).orElse(
                FixedDelayBackoffStrategy.create(Duration.ofSeconds(5)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategy(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

    private static WaiterOverrideConfiguration endpointDeletedWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(60);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategy).orElse(
                FixedDelayBackoffStrategy.create(Duration.ofSeconds(5)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategy(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

    private static WaiterOverrideConfiguration replicationInstanceAvailableWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(60);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategy).orElse(
                FixedDelayBackoffStrategy.create(Duration.ofSeconds(60)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategy(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

    private static WaiterOverrideConfiguration replicationInstanceDeletedWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(60);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategy).orElse(
                FixedDelayBackoffStrategy.create(Duration.ofSeconds(15)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategy(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

    private static WaiterOverrideConfiguration replicationTaskReadyWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(60);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategy).orElse(
                FixedDelayBackoffStrategy.create(Duration.ofSeconds(15)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategy(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

    private static WaiterOverrideConfiguration replicationTaskStoppedWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(60);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategy).orElse(
                FixedDelayBackoffStrategy.create(Duration.ofSeconds(15)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategy(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

    private static WaiterOverrideConfiguration replicationTaskRunningWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(60);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategy).orElse(
                FixedDelayBackoffStrategy.create(Duration.ofSeconds(15)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategy(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

    private static WaiterOverrideConfiguration replicationTaskDeletedWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(60);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategy).orElse(
                FixedDelayBackoffStrategy.create(Duration.ofSeconds(15)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategy(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

    @Override
    public void close() {
        managedResources.close();
    }

    public static DatabaseMigrationWaiter.Builder builder() {
        return new DefaultBuilder();
    }

    private  T applyWaitersUserAgent(T request) {
        Consumer userAgentApplier = b -> b.addApiName(ApiName.builder()
                .version("waiter").name("hll").build());
        AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration()
                .map(c -> c.toBuilder().applyMutation(userAgentApplier).build())
                .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(userAgentApplier).build()));
        return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build();
    }

    public static final class DefaultBuilder implements DatabaseMigrationWaiter.Builder {
        private DatabaseMigrationClient client;

        private WaiterOverrideConfiguration overrideConfiguration;

        private DefaultBuilder() {
        }

        @Override
        public DatabaseMigrationWaiter.Builder overrideConfiguration(WaiterOverrideConfiguration overrideConfiguration) {
            this.overrideConfiguration = overrideConfiguration;
            return this;
        }

        @Override
        public DatabaseMigrationWaiter.Builder client(DatabaseMigrationClient client) {
            this.client = client;
            return this;
        }

        public DatabaseMigrationWaiter build() {
            return new DefaultDatabaseMigrationWaiter(this);
        }
    }
}