software.amazon.awssdk.services.timestreamquery.DefaultTimestreamQueryAsyncClient Maven / Gradle / Ivy
Show all versions of timestreamquery Show documentation
/*
* 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.timestreamquery;
import java.net.URI;
import java.util.Collections;
import java.util.List;
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.config.AwsClientOption;
import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata;
import software.amazon.awssdk.awscore.internal.AwsServiceProtocol;
import software.amazon.awssdk.awscore.retry.AwsRetryStrategy;
import software.amazon.awssdk.core.RequestOverrideConfiguration;
import software.amazon.awssdk.core.SdkPlugin;
import software.amazon.awssdk.core.SdkRequest;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.client.handler.AsyncClientHandler;
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
import software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRefreshCache;
import software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRequest;
import software.amazon.awssdk.core.http.HttpResponseHandler;
import software.amazon.awssdk.core.metrics.CoreMetric;
import software.amazon.awssdk.core.retry.RetryMode;
import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity;
import software.amazon.awssdk.metrics.MetricCollector;
import software.amazon.awssdk.metrics.MetricPublisher;
import software.amazon.awssdk.metrics.NoOpMetricCollector;
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.retries.api.RetryStrategy;
import software.amazon.awssdk.services.timestreamquery.internal.TimestreamQueryServiceClientConfigurationBuilder;
import software.amazon.awssdk.services.timestreamquery.model.AccessDeniedException;
import software.amazon.awssdk.services.timestreamquery.model.CancelQueryRequest;
import software.amazon.awssdk.services.timestreamquery.model.CancelQueryResponse;
import software.amazon.awssdk.services.timestreamquery.model.ConflictException;
import software.amazon.awssdk.services.timestreamquery.model.CreateScheduledQueryRequest;
import software.amazon.awssdk.services.timestreamquery.model.CreateScheduledQueryResponse;
import software.amazon.awssdk.services.timestreamquery.model.DeleteScheduledQueryRequest;
import software.amazon.awssdk.services.timestreamquery.model.DeleteScheduledQueryResponse;
import software.amazon.awssdk.services.timestreamquery.model.DescribeAccountSettingsRequest;
import software.amazon.awssdk.services.timestreamquery.model.DescribeAccountSettingsResponse;
import software.amazon.awssdk.services.timestreamquery.model.DescribeEndpointsRequest;
import software.amazon.awssdk.services.timestreamquery.model.DescribeEndpointsResponse;
import software.amazon.awssdk.services.timestreamquery.model.DescribeScheduledQueryRequest;
import software.amazon.awssdk.services.timestreamquery.model.DescribeScheduledQueryResponse;
import software.amazon.awssdk.services.timestreamquery.model.ExecuteScheduledQueryRequest;
import software.amazon.awssdk.services.timestreamquery.model.ExecuteScheduledQueryResponse;
import software.amazon.awssdk.services.timestreamquery.model.InternalServerException;
import software.amazon.awssdk.services.timestreamquery.model.InvalidEndpointException;
import software.amazon.awssdk.services.timestreamquery.model.ListScheduledQueriesRequest;
import software.amazon.awssdk.services.timestreamquery.model.ListScheduledQueriesResponse;
import software.amazon.awssdk.services.timestreamquery.model.ListTagsForResourceRequest;
import software.amazon.awssdk.services.timestreamquery.model.ListTagsForResourceResponse;
import software.amazon.awssdk.services.timestreamquery.model.PrepareQueryRequest;
import software.amazon.awssdk.services.timestreamquery.model.PrepareQueryResponse;
import software.amazon.awssdk.services.timestreamquery.model.QueryExecutionException;
import software.amazon.awssdk.services.timestreamquery.model.QueryRequest;
import software.amazon.awssdk.services.timestreamquery.model.QueryResponse;
import software.amazon.awssdk.services.timestreamquery.model.ResourceNotFoundException;
import software.amazon.awssdk.services.timestreamquery.model.ServiceQuotaExceededException;
import software.amazon.awssdk.services.timestreamquery.model.TagResourceRequest;
import software.amazon.awssdk.services.timestreamquery.model.TagResourceResponse;
import software.amazon.awssdk.services.timestreamquery.model.ThrottlingException;
import software.amazon.awssdk.services.timestreamquery.model.TimestreamQueryException;
import software.amazon.awssdk.services.timestreamquery.model.UntagResourceRequest;
import software.amazon.awssdk.services.timestreamquery.model.UntagResourceResponse;
import software.amazon.awssdk.services.timestreamquery.model.UpdateAccountSettingsRequest;
import software.amazon.awssdk.services.timestreamquery.model.UpdateAccountSettingsResponse;
import software.amazon.awssdk.services.timestreamquery.model.UpdateScheduledQueryRequest;
import software.amazon.awssdk.services.timestreamquery.model.UpdateScheduledQueryResponse;
import software.amazon.awssdk.services.timestreamquery.model.ValidationException;
import software.amazon.awssdk.services.timestreamquery.transform.CancelQueryRequestMarshaller;
import software.amazon.awssdk.services.timestreamquery.transform.CreateScheduledQueryRequestMarshaller;
import software.amazon.awssdk.services.timestreamquery.transform.DeleteScheduledQueryRequestMarshaller;
import software.amazon.awssdk.services.timestreamquery.transform.DescribeAccountSettingsRequestMarshaller;
import software.amazon.awssdk.services.timestreamquery.transform.DescribeEndpointsRequestMarshaller;
import software.amazon.awssdk.services.timestreamquery.transform.DescribeScheduledQueryRequestMarshaller;
import software.amazon.awssdk.services.timestreamquery.transform.ExecuteScheduledQueryRequestMarshaller;
import software.amazon.awssdk.services.timestreamquery.transform.ListScheduledQueriesRequestMarshaller;
import software.amazon.awssdk.services.timestreamquery.transform.ListTagsForResourceRequestMarshaller;
import software.amazon.awssdk.services.timestreamquery.transform.PrepareQueryRequestMarshaller;
import software.amazon.awssdk.services.timestreamquery.transform.QueryRequestMarshaller;
import software.amazon.awssdk.services.timestreamquery.transform.TagResourceRequestMarshaller;
import software.amazon.awssdk.services.timestreamquery.transform.UntagResourceRequestMarshaller;
import software.amazon.awssdk.services.timestreamquery.transform.UpdateAccountSettingsRequestMarshaller;
import software.amazon.awssdk.services.timestreamquery.transform.UpdateScheduledQueryRequestMarshaller;
import software.amazon.awssdk.utils.CompletableFutureUtils;
/**
* Internal implementation of {@link TimestreamQueryAsyncClient}.
*
* @see TimestreamQueryAsyncClient#builder()
*/
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
final class DefaultTimestreamQueryAsyncClient implements TimestreamQueryAsyncClient {
private static final Logger log = LoggerFactory.getLogger(DefaultTimestreamQueryAsyncClient.class);
private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder()
.serviceProtocol(AwsServiceProtocol.AWS_JSON).build();
private final AsyncClientHandler clientHandler;
private final AwsJsonProtocolFactory protocolFactory;
private final SdkClientConfiguration clientConfiguration;
private EndpointDiscoveryRefreshCache endpointDiscoveryCache;
protected DefaultTimestreamQueryAsyncClient(SdkClientConfiguration clientConfiguration) {
this.clientHandler = new AwsAsyncClientHandler(clientConfiguration);
this.clientConfiguration = clientConfiguration.toBuilder().option(SdkClientOption.SDK_CLIENT, this).build();
this.protocolFactory = init(AwsJsonProtocolFactory.builder()).build();
if (clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED)) {
this.endpointDiscoveryCache = EndpointDiscoveryRefreshCache.create(TimestreamQueryAsyncEndpointDiscoveryCacheLoader
.create(this));
if (clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).isEndpointOverridden()) {
log.warn("Endpoint discovery is enabled for this client, and an endpoint override was also specified. This will disable endpoint discovery for methods that require it, instead using the specified endpoint override. This may or may not be what you intended.");
}
}
}
/**
*
* Cancels a query that has been issued. Cancellation is provided only if the query has not completed running before
* the cancellation request was issued. Because cancellation is an idempotent operation, subsequent cancellation
* requests will return a CancellationMessage
, indicating that the query has already been canceled. See
* code
* sample for details.
*
*
* @param cancelQueryRequest
* @return A Java Future containing the result of the CancelQuery operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException You are not authorized to perform this action.
* - InternalServerException The service was unable to fully process this request because of an internal
* server error.
* - ThrottlingException The request was denied due to request throttling.
* - ValidationException Invalid or malformed request.
* - InvalidEndpointException The requested endpoint was not valid.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.CancelQuery
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture cancelQuery(CancelQueryRequest cancelQueryRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(cancelQueryRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, cancelQueryRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CancelQuery");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
CancelQueryResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER)
.isEndpointOverridden();
if (endpointOverridden) {
endpointDiscoveryEnabled = false;
} else if (!endpointDiscoveryEnabled) {
throw new IllegalStateException(
"This operation requires endpoint discovery to be enabled, or for you to specify an endpoint override when the client is created.");
}
CompletableFuture endpointFuture = CompletableFuture.completedFuture(null);
if (endpointDiscoveryEnabled) {
CompletableFuture extends AwsCredentialsIdentity> identityFuture = cancelQueryRequest.overrideConfiguration()
.flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider)
.orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER))
.resolveIdentity();
endpointFuture = identityFuture.thenCompose(credentials -> {
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest
.builder()
.required(true)
.defaultEndpoint(
clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint())
.overrideConfiguration(cancelQueryRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CancelQuery").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CancelQueryRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(cancelQueryRequest)));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Create a scheduled query that will be run on your behalf at the configured schedule. Timestream assumes the
* execution role provided as part of the ScheduledQueryExecutionRoleArn
parameter to run the query.
* You can use the NotificationConfiguration
parameter to configure notification for your scheduled
* query operations.
*
*
* @param createScheduledQueryRequest
* @return A Java Future containing the result of the CreateScheduledQuery operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException You are not authorized to perform this action.
* - ConflictException Unable to poll results for a cancelled query.
* - InternalServerException The service was unable to fully process this request because of an internal
* server error.
* - ServiceQuotaExceededException You have exceeded the service quota.
* - ThrottlingException The request was denied due to request throttling.
* - ValidationException Invalid or malformed request.
* - InvalidEndpointException The requested endpoint was not valid.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.CreateScheduledQuery
* @see AWS API Documentation
*/
@Override
public CompletableFuture createScheduledQuery(
CreateScheduledQueryRequest createScheduledQueryRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createScheduledQueryRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, createScheduledQueryRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateScheduledQuery");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, CreateScheduledQueryResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER)
.isEndpointOverridden();
if (endpointOverridden) {
endpointDiscoveryEnabled = false;
} else if (!endpointDiscoveryEnabled) {
throw new IllegalStateException(
"This operation requires endpoint discovery to be enabled, or for you to specify an endpoint override when the client is created.");
}
CompletableFuture endpointFuture = CompletableFuture.completedFuture(null);
if (endpointDiscoveryEnabled) {
CompletableFuture extends AwsCredentialsIdentity> identityFuture = createScheduledQueryRequest
.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider)
.orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER))
.resolveIdentity();
endpointFuture = identityFuture.thenCompose(credentials -> {
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest
.builder()
.required(true)
.defaultEndpoint(
clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint())
.overrideConfiguration(createScheduledQueryRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture
.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateScheduledQuery").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CreateScheduledQueryRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(createScheduledQueryRequest)));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Deletes a given scheduled query. This is an irreversible operation.
*
*
* @param deleteScheduledQueryRequest
* @return A Java Future containing the result of the DeleteScheduledQuery operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException You are not authorized to perform this action.
* - InternalServerException The service was unable to fully process this request because of an internal
* server error.
* - ResourceNotFoundException The requested resource could not be found.
* - ThrottlingException The request was denied due to request throttling.
* - ValidationException Invalid or malformed request.
* - InvalidEndpointException The requested endpoint was not valid.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.DeleteScheduledQuery
* @see AWS API Documentation
*/
@Override
public CompletableFuture deleteScheduledQuery(
DeleteScheduledQueryRequest deleteScheduledQueryRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(deleteScheduledQueryRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, deleteScheduledQueryRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DeleteScheduledQuery");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DeleteScheduledQueryResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER)
.isEndpointOverridden();
if (endpointOverridden) {
endpointDiscoveryEnabled = false;
} else if (!endpointDiscoveryEnabled) {
throw new IllegalStateException(
"This operation requires endpoint discovery to be enabled, or for you to specify an endpoint override when the client is created.");
}
CompletableFuture endpointFuture = CompletableFuture.completedFuture(null);
if (endpointDiscoveryEnabled) {
CompletableFuture extends AwsCredentialsIdentity> identityFuture = deleteScheduledQueryRequest
.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider)
.orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER))
.resolveIdentity();
endpointFuture = identityFuture.thenCompose(credentials -> {
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest
.builder()
.required(true)
.defaultEndpoint(
clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint())
.overrideConfiguration(deleteScheduledQueryRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture
.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DeleteScheduledQuery").withProtocolMetadata(protocolMetadata)
.withMarshaller(new DeleteScheduledQueryRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(deleteScheduledQueryRequest)));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Describes the settings for your account that include the query pricing model and the configured maximum TCUs the
* service can use for your query workload.
*
*
* You're charged only for the duration of compute units used for your workloads.
*
*
* @param describeAccountSettingsRequest
* @return A Java Future containing the result of the DescribeAccountSettings operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException You are not authorized to perform this action.
* - InternalServerException The service was unable to fully process this request because of an internal
* server error.
* - ThrottlingException The request was denied due to request throttling.
* - InvalidEndpointException The requested endpoint was not valid.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.DescribeAccountSettings
* @see AWS API Documentation
*/
@Override
public CompletableFuture describeAccountSettings(
DescribeAccountSettingsRequest describeAccountSettingsRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(describeAccountSettingsRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, describeAccountSettingsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeAccountSettings");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DescribeAccountSettingsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER)
.isEndpointOverridden();
if (endpointOverridden) {
endpointDiscoveryEnabled = false;
} else if (!endpointDiscoveryEnabled) {
throw new IllegalStateException(
"This operation requires endpoint discovery to be enabled, or for you to specify an endpoint override when the client is created.");
}
CompletableFuture endpointFuture = CompletableFuture.completedFuture(null);
if (endpointDiscoveryEnabled) {
CompletableFuture extends AwsCredentialsIdentity> identityFuture = describeAccountSettingsRequest
.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider)
.orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER))
.resolveIdentity();
endpointFuture = identityFuture.thenCompose(credentials -> {
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest
.builder()
.required(true)
.defaultEndpoint(
clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint())
.overrideConfiguration(describeAccountSettingsRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture
.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DescribeAccountSettings").withProtocolMetadata(protocolMetadata)
.withMarshaller(new DescribeAccountSettingsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(describeAccountSettingsRequest)));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* DescribeEndpoints returns a list of available endpoints to make Timestream API calls against. This API is
* available through both Write and Query.
*
*
* Because the Timestream SDKs are designed to transparently work with the service’s architecture, including the
* management and mapping of the service endpoints, it is not recommended that you use this API unless:
*
*
* -
*
* You are using VPC endpoints
* (Amazon Web Services PrivateLink) with Timestream
*
*
* -
*
* Your application uses a programming language that does not yet have SDK support
*
*
* -
*
* You require better control over the client-side implementation
*
*
*
*
* For detailed information on how and when to use and implement DescribeEndpoints, see The Endpoint Discovery Pattern.
*
*
* @param describeEndpointsRequest
* @return A Java Future containing the result of the DescribeEndpoints operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - InternalServerException The service was unable to fully process this request because of an internal
* server error.
* - ValidationException Invalid or malformed request.
* - ThrottlingException The request was denied due to request throttling.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.DescribeEndpoints
* @see AWS API Documentation
*/
@Override
public CompletableFuture describeEndpoints(DescribeEndpointsRequest describeEndpointsRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(describeEndpointsRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, describeEndpointsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeEndpoints");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DescribeEndpointsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DescribeEndpoints").withProtocolMetadata(protocolMetadata)
.withMarshaller(new DescribeEndpointsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(describeEndpointsRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Provides detailed information about a scheduled query.
*
*
* @param describeScheduledQueryRequest
* @return A Java Future containing the result of the DescribeScheduledQuery operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException You are not authorized to perform this action.
* - InternalServerException The service was unable to fully process this request because of an internal
* server error.
* - ResourceNotFoundException The requested resource could not be found.
* - ThrottlingException The request was denied due to request throttling.
* - ValidationException Invalid or malformed request.
* - InvalidEndpointException The requested endpoint was not valid.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.DescribeScheduledQuery
* @see AWS API Documentation
*/
@Override
public CompletableFuture describeScheduledQuery(
DescribeScheduledQueryRequest describeScheduledQueryRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(describeScheduledQueryRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, describeScheduledQueryRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeScheduledQuery");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DescribeScheduledQueryResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER)
.isEndpointOverridden();
if (endpointOverridden) {
endpointDiscoveryEnabled = false;
} else if (!endpointDiscoveryEnabled) {
throw new IllegalStateException(
"This operation requires endpoint discovery to be enabled, or for you to specify an endpoint override when the client is created.");
}
CompletableFuture endpointFuture = CompletableFuture.completedFuture(null);
if (endpointDiscoveryEnabled) {
CompletableFuture extends AwsCredentialsIdentity> identityFuture = describeScheduledQueryRequest
.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider)
.orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER))
.resolveIdentity();
endpointFuture = identityFuture.thenCompose(credentials -> {
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest
.builder()
.required(true)
.defaultEndpoint(
clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint())
.overrideConfiguration(describeScheduledQueryRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture
.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DescribeScheduledQuery").withProtocolMetadata(protocolMetadata)
.withMarshaller(new DescribeScheduledQueryRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(describeScheduledQueryRequest)));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* You can use this API to run a scheduled query manually.
*
*
* @param executeScheduledQueryRequest
* @return A Java Future containing the result of the ExecuteScheduledQuery operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException You are not authorized to perform this action.
* - InternalServerException The service was unable to fully process this request because of an internal
* server error.
* - ResourceNotFoundException The requested resource could not be found.
* - ThrottlingException The request was denied due to request throttling.
* - ValidationException Invalid or malformed request.
* - InvalidEndpointException The requested endpoint was not valid.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.ExecuteScheduledQuery
* @see AWS API Documentation
*/
@Override
public CompletableFuture executeScheduledQuery(
ExecuteScheduledQueryRequest executeScheduledQueryRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(executeScheduledQueryRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, executeScheduledQueryRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ExecuteScheduledQuery");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ExecuteScheduledQueryResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER)
.isEndpointOverridden();
if (endpointOverridden) {
endpointDiscoveryEnabled = false;
} else if (!endpointDiscoveryEnabled) {
throw new IllegalStateException(
"This operation requires endpoint discovery to be enabled, or for you to specify an endpoint override when the client is created.");
}
CompletableFuture endpointFuture = CompletableFuture.completedFuture(null);
if (endpointDiscoveryEnabled) {
CompletableFuture extends AwsCredentialsIdentity> identityFuture = executeScheduledQueryRequest
.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider)
.orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER))
.resolveIdentity();
endpointFuture = identityFuture.thenCompose(credentials -> {
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest
.builder()
.required(true)
.defaultEndpoint(
clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint())
.overrideConfiguration(executeScheduledQueryRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture
.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ExecuteScheduledQuery").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ExecuteScheduledQueryRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(executeScheduledQueryRequest)));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Gets a list of all scheduled queries in the caller's Amazon account and Region. ListScheduledQueries
* is eventually consistent.
*
*
* @param listScheduledQueriesRequest
* @return A Java Future containing the result of the ListScheduledQueries operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException You are not authorized to perform this action.
* - InternalServerException The service was unable to fully process this request because of an internal
* server error.
* - ThrottlingException The request was denied due to request throttling.
* - ValidationException Invalid or malformed request.
* - InvalidEndpointException The requested endpoint was not valid.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.ListScheduledQueries
* @see AWS API Documentation
*/
@Override
public CompletableFuture listScheduledQueries(
ListScheduledQueriesRequest listScheduledQueriesRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listScheduledQueriesRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listScheduledQueriesRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListScheduledQueries");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListScheduledQueriesResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER)
.isEndpointOverridden();
if (endpointOverridden) {
endpointDiscoveryEnabled = false;
} else if (!endpointDiscoveryEnabled) {
throw new IllegalStateException(
"This operation requires endpoint discovery to be enabled, or for you to specify an endpoint override when the client is created.");
}
CompletableFuture endpointFuture = CompletableFuture.completedFuture(null);
if (endpointDiscoveryEnabled) {
CompletableFuture extends AwsCredentialsIdentity> identityFuture = listScheduledQueriesRequest
.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider)
.orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER))
.resolveIdentity();
endpointFuture = identityFuture.thenCompose(credentials -> {
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest
.builder()
.required(true)
.defaultEndpoint(
clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint())
.overrideConfiguration(listScheduledQueriesRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture
.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListScheduledQueries").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListScheduledQueriesRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(listScheduledQueriesRequest)));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* List all tags on a Timestream query resource.
*
*
* @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. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The requested resource could not be found.
* - ThrottlingException The request was denied due to request throttling.
* - ValidationException Invalid or malformed request.
* - InvalidEndpointException The requested endpoint was not valid.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.ListTagsForResource
* @see AWS API Documentation
*/
@Override
public CompletableFuture listTagsForResource(
ListTagsForResourceRequest listTagsForResourceRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listTagsForResourceRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listTagsForResourceRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListTagsForResource");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListTagsForResourceResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER)
.isEndpointOverridden();
if (endpointOverridden) {
endpointDiscoveryEnabled = false;
} else if (!endpointDiscoveryEnabled) {
throw new IllegalStateException(
"This operation requires endpoint discovery to be enabled, or for you to specify an endpoint override when the client is created.");
}
CompletableFuture endpointFuture = CompletableFuture.completedFuture(null);
if (endpointDiscoveryEnabled) {
CompletableFuture extends AwsCredentialsIdentity> identityFuture = listTagsForResourceRequest
.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider)
.orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER))
.resolveIdentity();
endpointFuture = identityFuture.thenCompose(credentials -> {
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest
.builder()
.required(true)
.defaultEndpoint(
clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint())
.overrideConfiguration(listTagsForResourceRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture
.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListTagsForResource").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListTagsForResourceRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(listTagsForResourceRequest)));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* A synchronous operation that allows you to submit a query with parameters to be stored by Timestream for later
* running. Timestream only supports using this operation with ValidateOnly
set to true
.
*
*
* @param prepareQueryRequest
* @return A Java Future containing the result of the PrepareQuery operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException You are not authorized to perform this action.
* - InternalServerException The service was unable to fully process this request because of an internal
* server error.
* - ThrottlingException The request was denied due to request throttling.
* - ValidationException Invalid or malformed request.
* - InvalidEndpointException The requested endpoint was not valid.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.PrepareQuery
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture prepareQuery(PrepareQueryRequest prepareQueryRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(prepareQueryRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, prepareQueryRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PrepareQuery");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
PrepareQueryResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER)
.isEndpointOverridden();
if (endpointOverridden) {
endpointDiscoveryEnabled = false;
} else if (!endpointDiscoveryEnabled) {
throw new IllegalStateException(
"This operation requires endpoint discovery to be enabled, or for you to specify an endpoint override when the client is created.");
}
CompletableFuture endpointFuture = CompletableFuture.completedFuture(null);
if (endpointDiscoveryEnabled) {
CompletableFuture extends AwsCredentialsIdentity> identityFuture = prepareQueryRequest.overrideConfiguration()
.flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider)
.orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER))
.resolveIdentity();
endpointFuture = identityFuture.thenCompose(credentials -> {
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest
.builder()
.required(true)
.defaultEndpoint(
clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint())
.overrideConfiguration(prepareQueryRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("PrepareQuery").withProtocolMetadata(protocolMetadata)
.withMarshaller(new PrepareQueryRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(prepareQueryRequest)));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Query
is a synchronous operation that enables you to run a query against your Amazon Timestream
* data. Query
will time out after 60 seconds. You must update the default timeout in the SDK to
* support a timeout of 60 seconds. See the code sample
* for details.
*
*
* Your query request will fail in the following cases:
*
*
* -
*
* If you submit a Query
request with the same client token outside of the 5-minute idempotency window.
*
*
* -
*
* If you submit a Query
request with the same client token, but change other parameters, within the
* 5-minute idempotency window.
*
*
* -
*
* If the size of the row (including the query metadata) exceeds 1 MB, then the query will fail with the following
* error message:
*
*
* Query aborted as max page response size has been exceeded by the output result row
*
*
* -
*
* If the IAM principal of the query initiator and the result reader are not the same and/or the query initiator and
* the result reader do not have the same query string in the query requests, the query will fail with an
* Invalid pagination token
error.
*
*
*
*
* @param queryRequest
* @return A Java Future containing the result of the Query operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException You are not authorized to perform this action.
* - ConflictException Unable to poll results for a cancelled query.
* - InternalServerException The service was unable to fully process this request because of an internal
* server error.
* - QueryExecutionException Timestream was unable to run the query successfully.
* - ThrottlingException The request was denied due to request throttling.
* - ValidationException Invalid or malformed request.
* - InvalidEndpointException The requested endpoint was not valid.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.Query
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture query(QueryRequest queryRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(queryRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, queryRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "Query");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
QueryResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER)
.isEndpointOverridden();
if (endpointOverridden) {
endpointDiscoveryEnabled = false;
} else if (!endpointDiscoveryEnabled) {
throw new IllegalStateException(
"This operation requires endpoint discovery to be enabled, or for you to specify an endpoint override when the client is created.");
}
CompletableFuture endpointFuture = CompletableFuture.completedFuture(null);
if (endpointDiscoveryEnabled) {
CompletableFuture extends AwsCredentialsIdentity> identityFuture = queryRequest.overrideConfiguration()
.flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider)
.orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER))
.resolveIdentity();
endpointFuture = identityFuture.thenCompose(credentials -> {
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest
.builder()
.required(true)
.defaultEndpoint(
clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint())
.overrideConfiguration(queryRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams().withOperationName("Query")
.withProtocolMetadata(protocolMetadata).withMarshaller(new QueryRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(queryRequest)));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Associate a set of tags with a Timestream resource. You can then activate these user-defined tags so that they
* appear on the Billing and Cost Management console for cost allocation tracking.
*
*
* @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. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The requested resource could not be found.
* - ServiceQuotaExceededException You have exceeded the service quota.
* - ThrottlingException The request was denied due to request throttling.
* - ValidationException Invalid or malformed request.
* - InvalidEndpointException The requested endpoint was not valid.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.TagResource
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture tagResource(TagResourceRequest tagResourceRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(tagResourceRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, tagResourceRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TagResource");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
TagResourceResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER)
.isEndpointOverridden();
if (endpointOverridden) {
endpointDiscoveryEnabled = false;
} else if (!endpointDiscoveryEnabled) {
throw new IllegalStateException(
"This operation requires endpoint discovery to be enabled, or for you to specify an endpoint override when the client is created.");
}
CompletableFuture endpointFuture = CompletableFuture.completedFuture(null);
if (endpointDiscoveryEnabled) {
CompletableFuture extends AwsCredentialsIdentity> identityFuture = tagResourceRequest.overrideConfiguration()
.flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider)
.orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER))
.resolveIdentity();
endpointFuture = identityFuture.thenCompose(credentials -> {
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest
.builder()
.required(true)
.defaultEndpoint(
clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint())
.overrideConfiguration(tagResourceRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("TagResource").withProtocolMetadata(protocolMetadata)
.withMarshaller(new TagResourceRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(tagResourceRequest)));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Removes the association of tags from a Timestream query resource.
*
*
* @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. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ValidationException Invalid or malformed request.
* - ThrottlingException The request was denied due to request throttling.
* - ResourceNotFoundException The requested resource could not be found.
* - InvalidEndpointException The requested endpoint was not valid.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.UntagResource
* @see AWS API Documentation
*/
@Override
public CompletableFuture untagResource(UntagResourceRequest untagResourceRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(untagResourceRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, untagResourceRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UntagResource");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
UntagResourceResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER)
.isEndpointOverridden();
if (endpointOverridden) {
endpointDiscoveryEnabled = false;
} else if (!endpointDiscoveryEnabled) {
throw new IllegalStateException(
"This operation requires endpoint discovery to be enabled, or for you to specify an endpoint override when the client is created.");
}
CompletableFuture endpointFuture = CompletableFuture.completedFuture(null);
if (endpointDiscoveryEnabled) {
CompletableFuture extends AwsCredentialsIdentity> identityFuture = untagResourceRequest.overrideConfiguration()
.flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider)
.orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER))
.resolveIdentity();
endpointFuture = identityFuture.thenCompose(credentials -> {
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest
.builder()
.required(true)
.defaultEndpoint(
clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint())
.overrideConfiguration(untagResourceRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("UntagResource").withProtocolMetadata(protocolMetadata)
.withMarshaller(new UntagResourceRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(untagResourceRequest)));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Transitions your account to use TCUs for query pricing and modifies the maximum query compute units that you've
* configured. If you reduce the value of MaxQueryTCU
to a desired configuration, the new value can
* take up to 24 hours to be effective.
*
*
*
* After you've transitioned your account to use TCUs for query pricing, you can't transition to using bytes scanned
* for query pricing.
*
*
*
* @param updateAccountSettingsRequest
* @return A Java Future containing the result of the UpdateAccountSettings operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException You are not authorized to perform this action.
* - InternalServerException The service was unable to fully process this request because of an internal
* server error.
* - ThrottlingException The request was denied due to request throttling.
* - ValidationException Invalid or malformed request.
* - InvalidEndpointException The requested endpoint was not valid.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.UpdateAccountSettings
* @see AWS API Documentation
*/
@Override
public CompletableFuture updateAccountSettings(
UpdateAccountSettingsRequest updateAccountSettingsRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(updateAccountSettingsRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, updateAccountSettingsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UpdateAccountSettings");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, UpdateAccountSettingsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER)
.isEndpointOverridden();
if (endpointOverridden) {
endpointDiscoveryEnabled = false;
} else if (!endpointDiscoveryEnabled) {
throw new IllegalStateException(
"This operation requires endpoint discovery to be enabled, or for you to specify an endpoint override when the client is created.");
}
CompletableFuture endpointFuture = CompletableFuture.completedFuture(null);
if (endpointDiscoveryEnabled) {
CompletableFuture extends AwsCredentialsIdentity> identityFuture = updateAccountSettingsRequest
.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider)
.orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER))
.resolveIdentity();
endpointFuture = identityFuture.thenCompose(credentials -> {
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest
.builder()
.required(true)
.defaultEndpoint(
clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint())
.overrideConfiguration(updateAccountSettingsRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture
.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("UpdateAccountSettings").withProtocolMetadata(protocolMetadata)
.withMarshaller(new UpdateAccountSettingsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(updateAccountSettingsRequest)));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Update a scheduled query.
*
*
* @param updateScheduledQueryRequest
* @return A Java Future containing the result of the UpdateScheduledQuery operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException You are not authorized to perform this action.
* - InternalServerException The service was unable to fully process this request because of an internal
* server error.
* - ResourceNotFoundException The requested resource could not be found.
* - ThrottlingException The request was denied due to request throttling.
* - ValidationException Invalid or malformed request.
* - InvalidEndpointException The requested endpoint was not valid.
* - 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.
* - TimestreamQueryException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamQueryAsyncClient.UpdateScheduledQuery
* @see AWS API Documentation
*/
@Override
public CompletableFuture updateScheduledQuery(
UpdateScheduledQueryRequest updateScheduledQueryRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(updateScheduledQueryRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, updateScheduledQueryRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Query");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UpdateScheduledQuery");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, UpdateScheduledQueryResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER)
.isEndpointOverridden();
if (endpointOverridden) {
endpointDiscoveryEnabled = false;
} else if (!endpointDiscoveryEnabled) {
throw new IllegalStateException(
"This operation requires endpoint discovery to be enabled, or for you to specify an endpoint override when the client is created.");
}
CompletableFuture endpointFuture = CompletableFuture.completedFuture(null);
if (endpointDiscoveryEnabled) {
CompletableFuture extends AwsCredentialsIdentity> identityFuture = updateScheduledQueryRequest
.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider)
.orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER))
.resolveIdentity();
endpointFuture = identityFuture.thenCompose(credentials -> {
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest
.builder()
.required(true)
.defaultEndpoint(
clientConfiguration.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint())
.overrideConfiguration(updateScheduledQueryRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture
.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("UpdateScheduledQuery").withProtocolMetadata(protocolMetadata)
.withMarshaller(new UpdateScheduledQueryRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(updateScheduledQueryRequest)));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
@Override
public final TimestreamQueryServiceClientConfiguration serviceClientConfiguration() {
return new TimestreamQueryServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build();
}
@Override
public final String serviceName() {
return SERVICE_NAME;
}
private > T init(T builder) {
return builder
.clientConfiguration(clientConfiguration)
.defaultServiceExceptionSupplier(TimestreamQueryException::builder)
.protocol(AwsJsonProtocol.AWS_JSON)
.protocolVersion("1.0")
.registerModeledException(
ExceptionMetadata.builder().errorCode("AccessDeniedException")
.exceptionBuilderSupplier(AccessDeniedException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("ConflictException")
.exceptionBuilderSupplier(ConflictException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("InvalidEndpointException")
.exceptionBuilderSupplier(InvalidEndpointException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("ResourceNotFoundException")
.exceptionBuilderSupplier(ResourceNotFoundException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("ThrottlingException")
.exceptionBuilderSupplier(ThrottlingException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("ValidationException")
.exceptionBuilderSupplier(ValidationException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("ServiceQuotaExceededException")
.exceptionBuilderSupplier(ServiceQuotaExceededException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("InternalServerException")
.exceptionBuilderSupplier(InternalServerException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("QueryExecutionException")
.exceptionBuilderSupplier(QueryExecutionException::builder).httpStatusCode(400).build());
}
private static List resolveMetricPublishers(SdkClientConfiguration clientConfiguration,
RequestOverrideConfiguration requestOverrideConfiguration) {
List publishers = null;
if (requestOverrideConfiguration != null) {
publishers = requestOverrideConfiguration.metricPublishers();
}
if (publishers == null || publishers.isEmpty()) {
publishers = clientConfiguration.option(SdkClientOption.METRIC_PUBLISHERS);
}
if (publishers == null) {
publishers = Collections.emptyList();
}
return publishers;
}
private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) {
ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder();
RetryMode retryMode = builder.retryMode();
if (retryMode != null) {
configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode));
} else {
Consumer> configurator = builder.retryStrategyConfigurator();
if (configurator != null) {
RetryStrategy.Builder, ?> defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder();
configurator.accept(defaultBuilder);
configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build());
} else {
RetryStrategy retryStrategy = builder.retryStrategy();
if (retryStrategy != null) {
configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy);
}
}
}
configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null);
configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null);
configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null);
}
private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request, SdkClientConfiguration clientConfiguration) {
List plugins = request.overrideConfiguration().map(c -> c.plugins()).orElse(Collections.emptyList());
SdkClientConfiguration.Builder configuration = clientConfiguration.toBuilder();
if (plugins.isEmpty()) {
return configuration.build();
}
TimestreamQueryServiceClientConfigurationBuilder serviceConfigBuilder = new TimestreamQueryServiceClientConfigurationBuilder(
configuration);
for (SdkPlugin plugin : plugins) {
plugin.configureClient(serviceConfigBuilder);
}
updateRetryStrategyClientConfiguration(configuration);
return configuration.build();
}
private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory,
JsonOperationMetadata operationMetadata) {
return protocolFactory.createErrorResponseHandler(operationMetadata);
}
@Override
public void close() {
clientHandler.close();
}
}