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

software.amazon.awssdk.services.synthetics.DefaultSyntheticsAsyncClient 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.synthetics;

import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.ApiName;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.handler.AsyncClientHandler;
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
import software.amazon.awssdk.core.http.HttpResponseHandler;
import software.amazon.awssdk.core.util.VersionInfo;
import software.amazon.awssdk.protocols.core.ExceptionMetadata;
import software.amazon.awssdk.protocols.json.AwsJsonProtocol;
import software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.JsonOperationMetadata;
import software.amazon.awssdk.services.synthetics.model.ConflictException;
import software.amazon.awssdk.services.synthetics.model.CreateCanaryRequest;
import software.amazon.awssdk.services.synthetics.model.CreateCanaryResponse;
import software.amazon.awssdk.services.synthetics.model.DeleteCanaryRequest;
import software.amazon.awssdk.services.synthetics.model.DeleteCanaryResponse;
import software.amazon.awssdk.services.synthetics.model.DescribeCanariesLastRunRequest;
import software.amazon.awssdk.services.synthetics.model.DescribeCanariesLastRunResponse;
import software.amazon.awssdk.services.synthetics.model.DescribeCanariesRequest;
import software.amazon.awssdk.services.synthetics.model.DescribeCanariesResponse;
import software.amazon.awssdk.services.synthetics.model.DescribeRuntimeVersionsRequest;
import software.amazon.awssdk.services.synthetics.model.DescribeRuntimeVersionsResponse;
import software.amazon.awssdk.services.synthetics.model.GetCanaryRequest;
import software.amazon.awssdk.services.synthetics.model.GetCanaryResponse;
import software.amazon.awssdk.services.synthetics.model.GetCanaryRunsRequest;
import software.amazon.awssdk.services.synthetics.model.GetCanaryRunsResponse;
import software.amazon.awssdk.services.synthetics.model.InternalServerException;
import software.amazon.awssdk.services.synthetics.model.ListTagsForResourceRequest;
import software.amazon.awssdk.services.synthetics.model.ListTagsForResourceResponse;
import software.amazon.awssdk.services.synthetics.model.ResourceNotFoundException;
import software.amazon.awssdk.services.synthetics.model.StartCanaryRequest;
import software.amazon.awssdk.services.synthetics.model.StartCanaryResponse;
import software.amazon.awssdk.services.synthetics.model.StopCanaryRequest;
import software.amazon.awssdk.services.synthetics.model.StopCanaryResponse;
import software.amazon.awssdk.services.synthetics.model.SyntheticsException;
import software.amazon.awssdk.services.synthetics.model.SyntheticsRequest;
import software.amazon.awssdk.services.synthetics.model.TagResourceRequest;
import software.amazon.awssdk.services.synthetics.model.TagResourceResponse;
import software.amazon.awssdk.services.synthetics.model.UntagResourceRequest;
import software.amazon.awssdk.services.synthetics.model.UntagResourceResponse;
import software.amazon.awssdk.services.synthetics.model.UpdateCanaryRequest;
import software.amazon.awssdk.services.synthetics.model.UpdateCanaryResponse;
import software.amazon.awssdk.services.synthetics.model.ValidationException;
import software.amazon.awssdk.services.synthetics.paginators.DescribeCanariesLastRunPublisher;
import software.amazon.awssdk.services.synthetics.paginators.DescribeCanariesPublisher;
import software.amazon.awssdk.services.synthetics.paginators.DescribeRuntimeVersionsPublisher;
import software.amazon.awssdk.services.synthetics.paginators.GetCanaryRunsPublisher;
import software.amazon.awssdk.services.synthetics.transform.CreateCanaryRequestMarshaller;
import software.amazon.awssdk.services.synthetics.transform.DeleteCanaryRequestMarshaller;
import software.amazon.awssdk.services.synthetics.transform.DescribeCanariesLastRunRequestMarshaller;
import software.amazon.awssdk.services.synthetics.transform.DescribeCanariesRequestMarshaller;
import software.amazon.awssdk.services.synthetics.transform.DescribeRuntimeVersionsRequestMarshaller;
import software.amazon.awssdk.services.synthetics.transform.GetCanaryRequestMarshaller;
import software.amazon.awssdk.services.synthetics.transform.GetCanaryRunsRequestMarshaller;
import software.amazon.awssdk.services.synthetics.transform.ListTagsForResourceRequestMarshaller;
import software.amazon.awssdk.services.synthetics.transform.StartCanaryRequestMarshaller;
import software.amazon.awssdk.services.synthetics.transform.StopCanaryRequestMarshaller;
import software.amazon.awssdk.services.synthetics.transform.TagResourceRequestMarshaller;
import software.amazon.awssdk.services.synthetics.transform.UntagResourceRequestMarshaller;
import software.amazon.awssdk.services.synthetics.transform.UpdateCanaryRequestMarshaller;
import software.amazon.awssdk.utils.CompletableFutureUtils;

/**
 * Internal implementation of {@link SyntheticsAsyncClient}.
 *
 * @see SyntheticsAsyncClient#builder()
 */
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
final class DefaultSyntheticsAsyncClient implements SyntheticsAsyncClient {
    private static final Logger log = LoggerFactory.getLogger(DefaultSyntheticsAsyncClient.class);

    private final AsyncClientHandler clientHandler;

    private final AwsJsonProtocolFactory protocolFactory;

    private final SdkClientConfiguration clientConfiguration;

    protected DefaultSyntheticsAsyncClient(SdkClientConfiguration clientConfiguration) {
        this.clientHandler = new AwsAsyncClientHandler(clientConfiguration);
        this.clientConfiguration = clientConfiguration;
        this.protocolFactory = init(AwsJsonProtocolFactory.builder()).build();
    }

    @Override
    public final String serviceName() {
        return SERVICE_NAME;
    }

    /**
     * 

* Creates a canary. Canaries are scripts that monitor your endpoints and APIs from the outside-in. Canaries help * you check the availability and latency of your web services and troubleshoot anomalies by investigating load time * data, screenshots of the UI, logs, and metrics. You can set up a canary to run continuously or just once. *

*

* Do not use CreateCanary to modify an existing canary. Use UpdateCanary instead. *

*

* To create canaries, you must have the CloudWatchSyntheticsFullAccess policy. If you are creating a * new IAM role for the canary, you also need the the iam:CreateRole, iam:CreatePolicy and * iam:AttachRolePolicy permissions. For more information, see Necessary Roles and Permissions. *

*

* Do not include secrets or proprietary information in your canary names. The canary name makes up part of the * Amazon Resource Name (ARN) for the canary, and the ARN is included in outbound calls over the internet. For more * information, see Security * Considerations for Synthetics Canaries. *

* * @param createCanaryRequest * @return A Java Future containing the result of the CreateCanary operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.CreateCanary * @see AWS API * Documentation */ @Override public CompletableFuture createCanary(CreateCanaryRequest createCanaryRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, CreateCanaryResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("CreateCanary").withMarshaller(new CreateCanaryRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(createCanaryRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Permanently deletes the specified canary. *

*

* When you delete a canary, resources used and created by the canary are not automatically deleted. After you * delete a canary that you do not intend to use again, you should also delete the following: *

*
    *
  • *

    * The Lambda functions and layers used by this canary. These have the prefix * cwsyn-MyCanaryName . *

    *
  • *
  • *

    * The CloudWatch alarms created for this canary. These alarms have a name of * Synthetics-SharpDrop-Alarm-MyCanaryName . *

    *
  • *
  • *

    * Amazon S3 objects and buckets, such as the canary's artifact location. *

    *
  • *
  • *

    * IAM roles created for the canary. If they were created in the console, these roles have the name * role/service-role/CloudWatchSyntheticsRole-MyCanaryName . *

    *
  • *
  • *

    * CloudWatch Logs log groups created for the canary. These logs groups have the name * /aws/lambda/cwsyn-MyCanaryName . *

    *
  • *
*

* Before you delete a canary, you might want to use GetCanary to display the information about this * canary. Make note of the information returned by this operation so that you can delete these resources after you * delete the canary. *

* * @param deleteCanaryRequest * @return A Java Future containing the result of the DeleteCanary operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • ResourceNotFoundException One of the specified resources was not found.
  • *
  • ConflictException A conflicting operation is already in progress.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.DeleteCanary * @see AWS API * Documentation */ @Override public CompletableFuture deleteCanary(DeleteCanaryRequest deleteCanaryRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, DeleteCanaryResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("DeleteCanary").withMarshaller(new DeleteCanaryRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(deleteCanaryRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* This operation returns a list of the canaries in your account, along with full details about each canary. *

*

* This operation does not have resource-level authorization, so if a user is able to use * DescribeCanaries, the user can see all of the canaries in the account. A deny policy can only be * used to restrict access to all canaries. It cannot be used on specific resources. *

* * @param describeCanariesRequest * @return A Java Future containing the result of the DescribeCanaries operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.DescribeCanaries * @see AWS * API Documentation */ @Override public CompletableFuture describeCanaries(DescribeCanariesRequest describeCanariesRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, DescribeCanariesResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("DescribeCanaries") .withMarshaller(new DescribeCanariesRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(describeCanariesRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Use this operation to see information from the most recent run of each canary that you have created. *

* * @param describeCanariesLastRunRequest * @return A Java Future containing the result of the DescribeCanariesLastRun operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.DescribeCanariesLastRun * @see AWS API Documentation */ @Override public CompletableFuture describeCanariesLastRun( DescribeCanariesLastRunRequest describeCanariesLastRunRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, DescribeCanariesLastRunResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("DescribeCanariesLastRun") .withMarshaller(new DescribeCanariesLastRunRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(describeCanariesLastRunRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Use this operation to see information from the most recent run of each canary that you have created. *

*
*

* This is a variant of * {@link #describeCanariesLastRun(software.amazon.awssdk.services.synthetics.model.DescribeCanariesLastRunRequest)} * operation. The return type is a custom publisher that can be subscribed to request a stream of response pages. * SDK will internally handle making service calls for you. *

*

* When the operation is called, an instance of this class is returned. At this point, no service calls are made yet * and so there is no guarantee that the request is valid. If there are errors in your request, you will see the * failures only after you start streaming the data. The subscribe method should be called as a request to start * streaming data. For more info, see * {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe * method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the * starting request. *

* *

* The following are few ways to use the response class: *

* 1) Using the subscribe helper method * *
     * {@code
     * software.amazon.awssdk.services.synthetics.paginators.DescribeCanariesLastRunPublisher publisher = client.describeCanariesLastRunPaginator(request);
     * CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
     * future.get();
     * }
     * 
* * 2) Using a custom subscriber * *
     * {@code
     * software.amazon.awssdk.services.synthetics.paginators.DescribeCanariesLastRunPublisher publisher = client.describeCanariesLastRunPaginator(request);
     * publisher.subscribe(new Subscriber() {
     * 
     * public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
     * 
     * 
     * public void onNext(software.amazon.awssdk.services.synthetics.model.DescribeCanariesLastRunResponse response) { //... };
     * });}
     * 
* * As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2. *

* Note: If you prefer to have control on service calls, use the * {@link #describeCanariesLastRun(software.amazon.awssdk.services.synthetics.model.DescribeCanariesLastRunRequest)} * operation. *

* * @param describeCanariesLastRunRequest * @return A custom publisher that can be subscribed to request a stream of response pages.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.DescribeCanariesLastRun * @see AWS API Documentation */ public DescribeCanariesLastRunPublisher describeCanariesLastRunPaginator( DescribeCanariesLastRunRequest describeCanariesLastRunRequest) { return new DescribeCanariesLastRunPublisher(this, applyPaginatorUserAgent(describeCanariesLastRunRequest)); } /** *

* This operation returns a list of the canaries in your account, along with full details about each canary. *

*

* This operation does not have resource-level authorization, so if a user is able to use * DescribeCanaries, the user can see all of the canaries in the account. A deny policy can only be * used to restrict access to all canaries. It cannot be used on specific resources. *

*
*

* This is a variant of * {@link #describeCanaries(software.amazon.awssdk.services.synthetics.model.DescribeCanariesRequest)} operation. * The return type is a custom publisher that can be subscribed to request a stream of response pages. SDK will * internally handle making service calls for you. *

*

* When the operation is called, an instance of this class is returned. At this point, no service calls are made yet * and so there is no guarantee that the request is valid. If there are errors in your request, you will see the * failures only after you start streaming the data. The subscribe method should be called as a request to start * streaming data. For more info, see * {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe * method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the * starting request. *

* *

* The following are few ways to use the response class: *

* 1) Using the subscribe helper method * *
     * {@code
     * software.amazon.awssdk.services.synthetics.paginators.DescribeCanariesPublisher publisher = client.describeCanariesPaginator(request);
     * CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
     * future.get();
     * }
     * 
* * 2) Using a custom subscriber * *
     * {@code
     * software.amazon.awssdk.services.synthetics.paginators.DescribeCanariesPublisher publisher = client.describeCanariesPaginator(request);
     * publisher.subscribe(new Subscriber() {
     * 
     * public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
     * 
     * 
     * public void onNext(software.amazon.awssdk.services.synthetics.model.DescribeCanariesResponse response) { //... };
     * });}
     * 
* * As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2. *

* Note: If you prefer to have control on service calls, use the * {@link #describeCanaries(software.amazon.awssdk.services.synthetics.model.DescribeCanariesRequest)} * operation. *

* * @param describeCanariesRequest * @return A custom publisher that can be subscribed to request a stream of response pages.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.DescribeCanaries * @see AWS * API Documentation */ public DescribeCanariesPublisher describeCanariesPaginator(DescribeCanariesRequest describeCanariesRequest) { return new DescribeCanariesPublisher(this, applyPaginatorUserAgent(describeCanariesRequest)); } /** *

* Returns a list of Synthetics canary runtime versions. For more information, see * Canary Runtime Versions. *

* * @param describeRuntimeVersionsRequest * @return A Java Future containing the result of the DescribeRuntimeVersions operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.DescribeRuntimeVersions * @see AWS API Documentation */ @Override public CompletableFuture describeRuntimeVersions( DescribeRuntimeVersionsRequest describeRuntimeVersionsRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, DescribeRuntimeVersionsResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("DescribeRuntimeVersions") .withMarshaller(new DescribeRuntimeVersionsRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(describeRuntimeVersionsRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Returns a list of Synthetics canary runtime versions. For more information, see * Canary Runtime Versions. *

*
*

* This is a variant of * {@link #describeRuntimeVersions(software.amazon.awssdk.services.synthetics.model.DescribeRuntimeVersionsRequest)} * operation. The return type is a custom publisher that can be subscribed to request a stream of response pages. * SDK will internally handle making service calls for you. *

*

* When the operation is called, an instance of this class is returned. At this point, no service calls are made yet * and so there is no guarantee that the request is valid. If there are errors in your request, you will see the * failures only after you start streaming the data. The subscribe method should be called as a request to start * streaming data. For more info, see * {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe * method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the * starting request. *

* *

* The following are few ways to use the response class: *

* 1) Using the subscribe helper method * *
     * {@code
     * software.amazon.awssdk.services.synthetics.paginators.DescribeRuntimeVersionsPublisher publisher = client.describeRuntimeVersionsPaginator(request);
     * CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
     * future.get();
     * }
     * 
* * 2) Using a custom subscriber * *
     * {@code
     * software.amazon.awssdk.services.synthetics.paginators.DescribeRuntimeVersionsPublisher publisher = client.describeRuntimeVersionsPaginator(request);
     * publisher.subscribe(new Subscriber() {
     * 
     * public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
     * 
     * 
     * public void onNext(software.amazon.awssdk.services.synthetics.model.DescribeRuntimeVersionsResponse response) { //... };
     * });}
     * 
* * As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2. *

* Note: If you prefer to have control on service calls, use the * {@link #describeRuntimeVersions(software.amazon.awssdk.services.synthetics.model.DescribeRuntimeVersionsRequest)} * operation. *

* * @param describeRuntimeVersionsRequest * @return A custom publisher that can be subscribed to request a stream of response pages.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.DescribeRuntimeVersions * @see AWS API Documentation */ public DescribeRuntimeVersionsPublisher describeRuntimeVersionsPaginator( DescribeRuntimeVersionsRequest describeRuntimeVersionsRequest) { return new DescribeRuntimeVersionsPublisher(this, applyPaginatorUserAgent(describeRuntimeVersionsRequest)); } /** *

* Retrieves complete information about one canary. You must specify the name of the canary that you want. To get a * list of canaries and their names, use DescribeCanaries. *

* * @param getCanaryRequest * @return A Java Future containing the result of the GetCanary operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.GetCanary * @see AWS API * Documentation */ @Override public CompletableFuture getCanary(GetCanaryRequest getCanaryRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, GetCanaryResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams().withOperationName("GetCanary") .withMarshaller(new GetCanaryRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(getCanaryRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Retrieves a list of runs for a specified canary. *

* * @param getCanaryRunsRequest * @return A Java Future containing the result of the GetCanaryRuns operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • ResourceNotFoundException One of the specified resources was not found.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.GetCanaryRuns * @see AWS API * Documentation */ @Override public CompletableFuture getCanaryRuns(GetCanaryRunsRequest getCanaryRunsRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, GetCanaryRunsResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("GetCanaryRuns") .withMarshaller(new GetCanaryRunsRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(getCanaryRunsRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Retrieves a list of runs for a specified canary. *

*
*

* This is a variant of * {@link #getCanaryRuns(software.amazon.awssdk.services.synthetics.model.GetCanaryRunsRequest)} operation. The * return type is a custom publisher that can be subscribed to request a stream of response pages. SDK will * internally handle making service calls for you. *

*

* When the operation is called, an instance of this class is returned. At this point, no service calls are made yet * and so there is no guarantee that the request is valid. If there are errors in your request, you will see the * failures only after you start streaming the data. The subscribe method should be called as a request to start * streaming data. For more info, see * {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe * method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the * starting request. *

* *

* The following are few ways to use the response class: *

* 1) Using the subscribe helper method * *
     * {@code
     * software.amazon.awssdk.services.synthetics.paginators.GetCanaryRunsPublisher publisher = client.getCanaryRunsPaginator(request);
     * CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
     * future.get();
     * }
     * 
* * 2) Using a custom subscriber * *
     * {@code
     * software.amazon.awssdk.services.synthetics.paginators.GetCanaryRunsPublisher publisher = client.getCanaryRunsPaginator(request);
     * publisher.subscribe(new Subscriber() {
     * 
     * public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
     * 
     * 
     * public void onNext(software.amazon.awssdk.services.synthetics.model.GetCanaryRunsResponse response) { //... };
     * });}
     * 
* * As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2. *

* Note: If you prefer to have control on service calls, use the * {@link #getCanaryRuns(software.amazon.awssdk.services.synthetics.model.GetCanaryRunsRequest)} operation. *

* * @param getCanaryRunsRequest * @return A custom publisher that can be subscribed to request a stream of response pages.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • ResourceNotFoundException One of the specified resources was not found.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.GetCanaryRuns * @see AWS API * Documentation */ public GetCanaryRunsPublisher getCanaryRunsPaginator(GetCanaryRunsRequest getCanaryRunsRequest) { return new GetCanaryRunsPublisher(this, applyPaginatorUserAgent(getCanaryRunsRequest)); } /** *

* Displays the tags associated with a canary. *

* * @param listTagsForResourceRequest * @return A Java Future containing the result of the ListTagsForResource operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ResourceNotFoundException One of the specified resources was not found.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.ListTagsForResource * @see AWS * API Documentation */ @Override public CompletableFuture listTagsForResource( ListTagsForResourceRequest listTagsForResourceRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, ListTagsForResourceResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("ListTagsForResource") .withMarshaller(new ListTagsForResourceRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(listTagsForResourceRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Use this operation to run a canary that has already been created. The frequency of the canary runs is determined * by the value of the canary's Schedule. To see a canary's schedule, use GetCanary. *

* * @param startCanaryRequest * @return A Java Future containing the result of the StartCanary operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • ResourceNotFoundException One of the specified resources was not found.
  • *
  • ConflictException A conflicting operation is already in progress.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.StartCanary * @see AWS API * Documentation */ @Override public CompletableFuture startCanary(StartCanaryRequest startCanaryRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, StartCanaryResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("StartCanary").withMarshaller(new StartCanaryRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(startCanaryRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Stops the canary to prevent all future runs. If the canary is currently running, Synthetics stops waiting for the * current run of the specified canary to complete. The run that is in progress completes on its own, publishes * metrics, and uploads artifacts, but it is not recorded in Synthetics as a completed run. *

*

* You can use StartCanary to start it running again with the canary’s current schedule at any point in * the future. *

* * @param stopCanaryRequest * @return A Java Future containing the result of the StopCanary operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • ResourceNotFoundException One of the specified resources was not found.
  • *
  • ConflictException A conflicting operation is already in progress.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.StopCanary * @see AWS API * Documentation */ @Override public CompletableFuture stopCanary(StopCanaryRequest stopCanaryRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, StopCanaryResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams().withOperationName("StopCanary") .withMarshaller(new StopCanaryRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(stopCanaryRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Assigns one or more tags (key-value pairs) to the specified canary. *

*

* Tags can help you organize and categorize your resources. You can also use them to scope user permissions, by * granting a user permission to access or change only resources with certain tag values. *

*

* Tags don't have any semantic meaning to AWS and are interpreted strictly as strings of characters. *

*

* You can use the TagResource action with a canary that already has tags. If you specify a new tag key * for the alarm, this tag is appended to the list of tags associated with the alarm. If you specify a tag key that * is already associated with the alarm, the new tag value that you specify replaces the previous value for that * tag. *

*

* You can associate as many as 50 tags with a canary. *

* * @param tagResourceRequest * @return A Java Future containing the result of the TagResource operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ResourceNotFoundException One of the specified resources was not found.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.TagResource * @see AWS API * Documentation */ @Override public CompletableFuture tagResource(TagResourceRequest tagResourceRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, TagResourceResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("TagResource").withMarshaller(new TagResourceRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(tagResourceRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Removes one or more tags from the specified canary. *

* * @param untagResourceRequest * @return A Java Future containing the result of the UntagResource operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ResourceNotFoundException One of the specified resources was not found.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.UntagResource * @see AWS API * Documentation */ @Override public CompletableFuture untagResource(UntagResourceRequest untagResourceRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, UntagResourceResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("UntagResource") .withMarshaller(new UntagResourceRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(untagResourceRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } /** *

* Use this operation to change the settings of a canary that has already been created. *

*

* You can't use this operation to update the tags of an existing canary. To change the tags of an existing canary, * use TagResource. *

* * @param updateCanaryRequest * @return A Java Future containing the result of the UpdateCanary operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • InternalServerException An unknown internal error occurred.
  • *
  • ValidationException A parameter could not be validated.
  • *
  • ResourceNotFoundException One of the specified resources was not found.
  • *
  • ConflictException A conflicting operation is already in progress.
  • *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • SyntheticsException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample SyntheticsAsyncClient.UpdateCanary * @see AWS API * Documentation */ @Override public CompletableFuture updateCanary(UpdateCanaryRequest updateCanaryRequest) { try { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, UpdateCanaryResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("UpdateCanary").withMarshaller(new UpdateCanaryRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withInput(updateCanaryRequest)); return executeFuture; } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } @Override public void close() { clientHandler.close(); } private > T init(T builder) { return builder .clientConfiguration(clientConfiguration) .defaultServiceExceptionSupplier(SyntheticsException::builder) .protocol(AwsJsonProtocol.REST_JSON) .protocolVersion("1.1") .registerModeledException( ExceptionMetadata.builder().errorCode("ConflictException") .exceptionBuilderSupplier(ConflictException::builder).httpStatusCode(409).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("ResourceNotFoundException") .exceptionBuilderSupplier(ResourceNotFoundException::builder).httpStatusCode(404).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("ValidationException") .exceptionBuilderSupplier(ValidationException::builder).httpStatusCode(400).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("InternalServerException") .exceptionBuilderSupplier(InternalServerException::builder).httpStatusCode(500).build()); } private T applyPaginatorUserAgent(T request) { Consumer userAgentApplier = b -> b.addApiName(ApiName.builder() .version(VersionInfo.SDK_VERSION).name("PAGINATED").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(); } private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory, JsonOperationMetadata operationMetadata) { return protocolFactory.createErrorResponseHandler(operationMetadata); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy