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

software.amazon.awssdk.services.nimble.waiters.DefaultNimbleAsyncWaiter Maven / Gradle / Ivy

Go to download

The AWS Java SDK for Nimble module holds the client classes that are used for communicating with Nimble.

There is a newer version: 2.29.0
Show newest version
/*
 * 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.nimble.waiters;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
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.waiters.AsyncWaiter;
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.retries.api.BackoffStrategy;
import software.amazon.awssdk.services.nimble.NimbleAsyncClient;
import software.amazon.awssdk.services.nimble.jmespath.internal.JmesPathRuntime;
import software.amazon.awssdk.services.nimble.model.GetLaunchProfileRequest;
import software.amazon.awssdk.services.nimble.model.GetLaunchProfileResponse;
import software.amazon.awssdk.services.nimble.model.GetStreamingImageRequest;
import software.amazon.awssdk.services.nimble.model.GetStreamingImageResponse;
import software.amazon.awssdk.services.nimble.model.GetStreamingSessionRequest;
import software.amazon.awssdk.services.nimble.model.GetStreamingSessionResponse;
import software.amazon.awssdk.services.nimble.model.GetStreamingSessionStreamRequest;
import software.amazon.awssdk.services.nimble.model.GetStreamingSessionStreamResponse;
import software.amazon.awssdk.services.nimble.model.GetStudioComponentRequest;
import software.amazon.awssdk.services.nimble.model.GetStudioComponentResponse;
import software.amazon.awssdk.services.nimble.model.GetStudioRequest;
import software.amazon.awssdk.services.nimble.model.GetStudioResponse;
import software.amazon.awssdk.services.nimble.model.NimbleRequest;
import software.amazon.awssdk.services.nimble.waiters.internal.WaitersRuntime;
import software.amazon.awssdk.utils.AttributeMap;
import software.amazon.awssdk.utils.SdkAutoCloseable;
import software.amazon.awssdk.utils.ThreadFactoryBuilder;

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

    private static final WaiterAttribute SCHEDULED_EXECUTOR_SERVICE_ATTRIBUTE = new WaiterAttribute<>(
            ScheduledExecutorService.class);

    private final NimbleAsyncClient client;

    private final AttributeMap managedResources;

    private final AsyncWaiter launchProfileDeletedWaiter;

    private final AsyncWaiter launchProfileReadyWaiter;

    private final AsyncWaiter streamingImageDeletedWaiter;

    private final AsyncWaiter streamingImageReadyWaiter;

    private final AsyncWaiter streamingSessionDeletedWaiter;

    private final AsyncWaiter streamingSessionReadyWaiter;

    private final AsyncWaiter streamingSessionStoppedWaiter;

    private final AsyncWaiter streamingSessionStreamReadyWaiter;

    private final AsyncWaiter studioComponentDeletedWaiter;

    private final AsyncWaiter studioComponentReadyWaiter;

    private final AsyncWaiter studioDeletedWaiter;

    private final AsyncWaiter studioReadyWaiter;

    private final ScheduledExecutorService executorService;

    private DefaultNimbleAsyncWaiter(DefaultBuilder builder) {
        AttributeMap.Builder attributeMapBuilder = AttributeMap.builder();
        if (builder.client == null) {
            this.client = NimbleAsyncClient.builder().build();
            attributeMapBuilder.put(CLIENT_ATTRIBUTE, this.client);
        } else {
            this.client = builder.client;
        }
        if (builder.executorService == null) {
            this.executorService = Executors.newScheduledThreadPool(1,
                    new ThreadFactoryBuilder().threadNamePrefix("waiters-ScheduledExecutor").build());
            attributeMapBuilder.put(SCHEDULED_EXECUTOR_SERVICE_ATTRIBUTE, this.executorService);
        } else {
            this.executorService = builder.executorService;
        }
        managedResources = attributeMapBuilder.build();
        this.launchProfileDeletedWaiter = AsyncWaiter.builder(GetLaunchProfileResponse.class)
                .acceptors(launchProfileDeletedWaiterAcceptors())
                .overrideConfiguration(launchProfileDeletedWaiterConfig(builder.overrideConfiguration))
                .scheduledExecutorService(executorService).build();
        this.launchProfileReadyWaiter = AsyncWaiter.builder(GetLaunchProfileResponse.class)
                .acceptors(launchProfileReadyWaiterAcceptors())
                .overrideConfiguration(launchProfileReadyWaiterConfig(builder.overrideConfiguration))
                .scheduledExecutorService(executorService).build();
        this.streamingImageDeletedWaiter = AsyncWaiter.builder(GetStreamingImageResponse.class)
                .acceptors(streamingImageDeletedWaiterAcceptors())
                .overrideConfiguration(streamingImageDeletedWaiterConfig(builder.overrideConfiguration))
                .scheduledExecutorService(executorService).build();
        this.streamingImageReadyWaiter = AsyncWaiter.builder(GetStreamingImageResponse.class)
                .acceptors(streamingImageReadyWaiterAcceptors())
                .overrideConfiguration(streamingImageReadyWaiterConfig(builder.overrideConfiguration))
                .scheduledExecutorService(executorService).build();
        this.streamingSessionDeletedWaiter = AsyncWaiter.builder(GetStreamingSessionResponse.class)
                .acceptors(streamingSessionDeletedWaiterAcceptors())
                .overrideConfiguration(streamingSessionDeletedWaiterConfig(builder.overrideConfiguration))
                .scheduledExecutorService(executorService).build();
        this.streamingSessionReadyWaiter = AsyncWaiter.builder(GetStreamingSessionResponse.class)
                .acceptors(streamingSessionReadyWaiterAcceptors())
                .overrideConfiguration(streamingSessionReadyWaiterConfig(builder.overrideConfiguration))
                .scheduledExecutorService(executorService).build();
        this.streamingSessionStoppedWaiter = AsyncWaiter.builder(GetStreamingSessionResponse.class)
                .acceptors(streamingSessionStoppedWaiterAcceptors())
                .overrideConfiguration(streamingSessionStoppedWaiterConfig(builder.overrideConfiguration))
                .scheduledExecutorService(executorService).build();
        this.streamingSessionStreamReadyWaiter = AsyncWaiter.builder(GetStreamingSessionStreamResponse.class)
                .acceptors(streamingSessionStreamReadyWaiterAcceptors())
                .overrideConfiguration(streamingSessionStreamReadyWaiterConfig(builder.overrideConfiguration))
                .scheduledExecutorService(executorService).build();
        this.studioComponentDeletedWaiter = AsyncWaiter.builder(GetStudioComponentResponse.class)
                .acceptors(studioComponentDeletedWaiterAcceptors())
                .overrideConfiguration(studioComponentDeletedWaiterConfig(builder.overrideConfiguration))
                .scheduledExecutorService(executorService).build();
        this.studioComponentReadyWaiter = AsyncWaiter.builder(GetStudioComponentResponse.class)
                .acceptors(studioComponentReadyWaiterAcceptors())
                .overrideConfiguration(studioComponentReadyWaiterConfig(builder.overrideConfiguration))
                .scheduledExecutorService(executorService).build();
        this.studioDeletedWaiter = AsyncWaiter.builder(GetStudioResponse.class).acceptors(studioDeletedWaiterAcceptors())
                .overrideConfiguration(studioDeletedWaiterConfig(builder.overrideConfiguration))
                .scheduledExecutorService(executorService).build();
        this.studioReadyWaiter = AsyncWaiter.builder(GetStudioResponse.class).acceptors(studioReadyWaiterAcceptors())
                .overrideConfiguration(studioReadyWaiterConfig(builder.overrideConfiguration))
                .scheduledExecutorService(executorService).build();
    }

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

    @Override
    public CompletableFuture> waitUntilLaunchProfileDeleted(
            GetLaunchProfileRequest getLaunchProfileRequest) {
        return launchProfileDeletedWaiter.runAsync(() -> client.getLaunchProfile(applyWaitersUserAgent(getLaunchProfileRequest)));
    }

    @Override
    public CompletableFuture> waitUntilLaunchProfileDeleted(
            GetLaunchProfileRequest getLaunchProfileRequest, WaiterOverrideConfiguration overrideConfig) {
        return launchProfileDeletedWaiter.runAsync(() -> client.getLaunchProfile(applyWaitersUserAgent(getLaunchProfileRequest)),
                launchProfileDeletedWaiterConfig(overrideConfig));
    }

    @Override
    public CompletableFuture> waitUntilLaunchProfileReady(
            GetLaunchProfileRequest getLaunchProfileRequest) {
        return launchProfileReadyWaiter.runAsync(() -> client.getLaunchProfile(applyWaitersUserAgent(getLaunchProfileRequest)));
    }

    @Override
    public CompletableFuture> waitUntilLaunchProfileReady(
            GetLaunchProfileRequest getLaunchProfileRequest, WaiterOverrideConfiguration overrideConfig) {
        return launchProfileReadyWaiter.runAsync(() -> client.getLaunchProfile(applyWaitersUserAgent(getLaunchProfileRequest)),
                launchProfileReadyWaiterConfig(overrideConfig));
    }

    @Override
    public CompletableFuture> waitUntilStreamingImageDeleted(
            GetStreamingImageRequest getStreamingImageRequest) {
        return streamingImageDeletedWaiter.runAsync(() -> client
                .getStreamingImage(applyWaitersUserAgent(getStreamingImageRequest)));
    }

    @Override
    public CompletableFuture> waitUntilStreamingImageDeleted(
            GetStreamingImageRequest getStreamingImageRequest, WaiterOverrideConfiguration overrideConfig) {
        return streamingImageDeletedWaiter.runAsync(
                () -> client.getStreamingImage(applyWaitersUserAgent(getStreamingImageRequest)),
                streamingImageDeletedWaiterConfig(overrideConfig));
    }

    @Override
    public CompletableFuture> waitUntilStreamingImageReady(
            GetStreamingImageRequest getStreamingImageRequest) {
        return streamingImageReadyWaiter
                .runAsync(() -> client.getStreamingImage(applyWaitersUserAgent(getStreamingImageRequest)));
    }

    @Override
    public CompletableFuture> waitUntilStreamingImageReady(
            GetStreamingImageRequest getStreamingImageRequest, WaiterOverrideConfiguration overrideConfig) {
        return streamingImageReadyWaiter.runAsync(
                () -> client.getStreamingImage(applyWaitersUserAgent(getStreamingImageRequest)),
                streamingImageReadyWaiterConfig(overrideConfig));
    }

    @Override
    public CompletableFuture> waitUntilStreamingSessionDeleted(
            GetStreamingSessionRequest getStreamingSessionRequest) {
        return streamingSessionDeletedWaiter.runAsync(() -> client
                .getStreamingSession(applyWaitersUserAgent(getStreamingSessionRequest)));
    }

    @Override
    public CompletableFuture> waitUntilStreamingSessionDeleted(
            GetStreamingSessionRequest getStreamingSessionRequest, WaiterOverrideConfiguration overrideConfig) {
        return streamingSessionDeletedWaiter.runAsync(
                () -> client.getStreamingSession(applyWaitersUserAgent(getStreamingSessionRequest)),
                streamingSessionDeletedWaiterConfig(overrideConfig));
    }

    @Override
    public CompletableFuture> waitUntilStreamingSessionReady(
            GetStreamingSessionRequest getStreamingSessionRequest) {
        return streamingSessionReadyWaiter.runAsync(() -> client
                .getStreamingSession(applyWaitersUserAgent(getStreamingSessionRequest)));
    }

    @Override
    public CompletableFuture> waitUntilStreamingSessionReady(
            GetStreamingSessionRequest getStreamingSessionRequest, WaiterOverrideConfiguration overrideConfig) {
        return streamingSessionReadyWaiter.runAsync(
                () -> client.getStreamingSession(applyWaitersUserAgent(getStreamingSessionRequest)),
                streamingSessionReadyWaiterConfig(overrideConfig));
    }

    @Override
    public CompletableFuture> waitUntilStreamingSessionStopped(
            GetStreamingSessionRequest getStreamingSessionRequest) {
        return streamingSessionStoppedWaiter.runAsync(() -> client
                .getStreamingSession(applyWaitersUserAgent(getStreamingSessionRequest)));
    }

    @Override
    public CompletableFuture> waitUntilStreamingSessionStopped(
            GetStreamingSessionRequest getStreamingSessionRequest, WaiterOverrideConfiguration overrideConfig) {
        return streamingSessionStoppedWaiter.runAsync(
                () -> client.getStreamingSession(applyWaitersUserAgent(getStreamingSessionRequest)),
                streamingSessionStoppedWaiterConfig(overrideConfig));
    }

    @Override
    public CompletableFuture> waitUntilStreamingSessionStreamReady(
            GetStreamingSessionStreamRequest getStreamingSessionStreamRequest) {
        return streamingSessionStreamReadyWaiter.runAsync(() -> client
                .getStreamingSessionStream(applyWaitersUserAgent(getStreamingSessionStreamRequest)));
    }

    @Override
    public CompletableFuture> waitUntilStreamingSessionStreamReady(
            GetStreamingSessionStreamRequest getStreamingSessionStreamRequest, WaiterOverrideConfiguration overrideConfig) {
        return streamingSessionStreamReadyWaiter.runAsync(
                () -> client.getStreamingSessionStream(applyWaitersUserAgent(getStreamingSessionStreamRequest)),
                streamingSessionStreamReadyWaiterConfig(overrideConfig));
    }

    @Override
    public CompletableFuture> waitUntilStudioComponentDeleted(
            GetStudioComponentRequest getStudioComponentRequest) {
        return studioComponentDeletedWaiter.runAsync(() -> client
                .getStudioComponent(applyWaitersUserAgent(getStudioComponentRequest)));
    }

    @Override
    public CompletableFuture> waitUntilStudioComponentDeleted(
            GetStudioComponentRequest getStudioComponentRequest, WaiterOverrideConfiguration overrideConfig) {
        return studioComponentDeletedWaiter.runAsync(
                () -> client.getStudioComponent(applyWaitersUserAgent(getStudioComponentRequest)),
                studioComponentDeletedWaiterConfig(overrideConfig));
    }

    @Override
    public CompletableFuture> waitUntilStudioComponentReady(
            GetStudioComponentRequest getStudioComponentRequest) {
        return studioComponentReadyWaiter.runAsync(() -> client
                .getStudioComponent(applyWaitersUserAgent(getStudioComponentRequest)));
    }

    @Override
    public CompletableFuture> waitUntilStudioComponentReady(
            GetStudioComponentRequest getStudioComponentRequest, WaiterOverrideConfiguration overrideConfig) {
        return studioComponentReadyWaiter.runAsync(
                () -> client.getStudioComponent(applyWaitersUserAgent(getStudioComponentRequest)),
                studioComponentReadyWaiterConfig(overrideConfig));
    }

    @Override
    public CompletableFuture> waitUntilStudioDeleted(GetStudioRequest getStudioRequest) {
        return studioDeletedWaiter.runAsync(() -> client.getStudio(applyWaitersUserAgent(getStudioRequest)));
    }

    @Override
    public CompletableFuture> waitUntilStudioDeleted(GetStudioRequest getStudioRequest,
            WaiterOverrideConfiguration overrideConfig) {
        return studioDeletedWaiter.runAsync(() -> client.getStudio(applyWaitersUserAgent(getStudioRequest)),
                studioDeletedWaiterConfig(overrideConfig));
    }

    @Override
    public CompletableFuture> waitUntilStudioReady(GetStudioRequest getStudioRequest) {
        return studioReadyWaiter.runAsync(() -> client.getStudio(applyWaitersUserAgent(getStudioRequest)));
    }

    @Override
    public CompletableFuture> waitUntilStudioReady(GetStudioRequest getStudioRequest,
            WaiterOverrideConfiguration overrideConfig) {
        return studioReadyWaiter.runAsync(() -> client.getStudio(applyWaitersUserAgent(getStudioRequest)),
                studioReadyWaiterConfig(overrideConfig));
    }

    private static List> launchProfileDeletedWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
            return Objects.equals(input.field("launchProfile").field("state").value(), "DELETED");
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("launchProfile").field("state").value(), "DELETE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (launchProfile.state=DELETE_FAILED) and transitioned the waiter to failure state"));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> launchProfileReadyWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
            return Objects.equals(input.field("launchProfile").field("state").value(), "READY");
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("launchProfile").field("state").value(), "CREATE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (launchProfile.state=CREATE_FAILED) and transitioned the waiter to failure state"));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("launchProfile").field("state").value(), "UPDATE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (launchProfile.state=UPDATE_FAILED) and transitioned the waiter to failure state"));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> streamingImageDeletedWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
            return Objects.equals(input.field("streamingImage").field("state").value(), "DELETED");
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("streamingImage").field("state").value(), "DELETE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (streamingImage.state=DELETE_FAILED) and transitioned the waiter to failure state"));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> streamingImageReadyWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
            return Objects.equals(input.field("streamingImage").field("state").value(), "READY");
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("streamingImage").field("state").value(), "CREATE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (streamingImage.state=CREATE_FAILED) and transitioned the waiter to failure state"));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("streamingImage").field("state").value(), "UPDATE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (streamingImage.state=UPDATE_FAILED) and transitioned the waiter to failure state"));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> streamingSessionDeletedWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
            return Objects.equals(input.field("session").field("state").value(), "DELETED");
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("session").field("state").value(), "DELETE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (session.state=DELETE_FAILED) and transitioned the waiter to failure state"));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> streamingSessionReadyWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
            return Objects.equals(input.field("session").field("state").value(), "READY");
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("session").field("state").value(), "CREATE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (session.state=CREATE_FAILED) and transitioned the waiter to failure state"));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("session").field("state").value(), "START_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (session.state=START_FAILED) and transitioned the waiter to failure state"));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> streamingSessionStoppedWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
            return Objects.equals(input.field("session").field("state").value(), "STOPPED");
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("session").field("state").value(), "STOP_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (session.state=STOP_FAILED) and transitioned the waiter to failure state"));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> streamingSessionStreamReadyWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
            return Objects.equals(input.field("stream").field("state").value(), "READY");
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("stream").field("state").value(), "CREATE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (stream.state=CREATE_FAILED) and transitioned the waiter to failure state"));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> studioComponentDeletedWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
            return Objects.equals(input.field("studioComponent").field("state").value(), "DELETED");
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("studioComponent").field("state").value(), "DELETE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (studioComponent.state=DELETE_FAILED) and transitioned the waiter to failure state"));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> studioComponentReadyWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
            return Objects.equals(input.field("studioComponent").field("state").value(), "READY");
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("studioComponent").field("state").value(), "CREATE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (studioComponent.state=CREATE_FAILED) and transitioned the waiter to failure state"));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("studioComponent").field("state").value(), "UPDATE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (studioComponent.state=UPDATE_FAILED) and transitioned the waiter to failure state"));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> studioDeletedWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
            return Objects.equals(input.field("studio").field("state").value(), "DELETED");
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("studio").field("state").value(), "DELETE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (studio.state=DELETE_FAILED) and transitioned the waiter to failure state"));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static List> studioReadyWaiterAcceptors() {
        List> result = new ArrayList<>();
        result.add(WaiterAcceptor.successOnResponseAcceptor(response -> {
            JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
            return Objects.equals(input.field("studio").field("state").value(), "READY");
        }));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("studio").field("state").value(), "CREATE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (studio.state=CREATE_FAILED) and transitioned the waiter to failure state"));
        result.add(WaiterAcceptor.errorOnResponseAcceptor(
                response -> {
                    JmesPathRuntime.Value input = new JmesPathRuntime.Value(response);
                    return Objects.equals(input.field("studio").field("state").value(), "UPDATE_FAILED");
                },
                "A waiter acceptor with the matcher (path) was matched on parameter (studio.state=UPDATE_FAILED) and transitioned the waiter to failure state"));
        result.addAll(WaitersRuntime.DEFAULT_ACCEPTORS);
        return result;
    }

    private static WaiterOverrideConfiguration launchProfileDeletedWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(150);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategyV2).orElse(
                BackoffStrategy.fixedDelayWithoutJitter(Duration.ofSeconds(5)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategyV2(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

    private static WaiterOverrideConfiguration launchProfileReadyWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(150);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategyV2).orElse(
                BackoffStrategy.fixedDelayWithoutJitter(Duration.ofSeconds(5)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategyV2(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

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

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

    private static WaiterOverrideConfiguration streamingSessionDeletedWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(180);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategyV2).orElse(
                BackoffStrategy.fixedDelayWithoutJitter(Duration.ofSeconds(5)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategyV2(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

    private static WaiterOverrideConfiguration streamingSessionReadyWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(180);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategyV2).orElse(
                BackoffStrategy.fixedDelayWithoutJitter(Duration.ofSeconds(10)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategyV2(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

    private static WaiterOverrideConfiguration streamingSessionStoppedWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(180);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategyV2).orElse(
                BackoffStrategy.fixedDelayWithoutJitter(Duration.ofSeconds(5)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategyV2(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

    private static WaiterOverrideConfiguration streamingSessionStreamReadyWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(30);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategyV2).orElse(
                BackoffStrategy.fixedDelayWithoutJitter(Duration.ofSeconds(5)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategyV2(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

    private static WaiterOverrideConfiguration studioComponentDeletedWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
        Optional optionalOverrideConfig = Optional.ofNullable(overrideConfig);
        int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(120);
        BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategyV2).orElse(
                BackoffStrategy.fixedDelayWithoutJitter(Duration.ofSeconds(1)));
        Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
        return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategyV2(backoffStrategy)
                .waitTimeout(waitTimeout).build();
    }

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

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

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

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

    public static NimbleAsyncWaiter.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 NimbleAsyncWaiter.Builder {
        private NimbleAsyncClient client;

        private WaiterOverrideConfiguration overrideConfiguration;

        private ScheduledExecutorService executorService;

        private DefaultBuilder() {
        }

        @Override
        public NimbleAsyncWaiter.Builder scheduledExecutorService(ScheduledExecutorService executorService) {
            this.executorService = executorService;
            return this;
        }

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

        @Override
        public NimbleAsyncWaiter.Builder client(NimbleAsyncClient client) {
            this.client = client;
            return this;
        }

        public NimbleAsyncWaiter build() {
            return new DefaultNimbleAsyncWaiter(this);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy