software.amazon.awssdk.services.timestreamwrite.DefaultTimestreamWriteAsyncClient Maven / Gradle / Ivy
Show all versions of timestreamwrite 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.timestreamwrite;
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.timestreamwrite.internal.TimestreamWriteServiceClientConfigurationBuilder;
import software.amazon.awssdk.services.timestreamwrite.model.AccessDeniedException;
import software.amazon.awssdk.services.timestreamwrite.model.ConflictException;
import software.amazon.awssdk.services.timestreamwrite.model.CreateBatchLoadTaskRequest;
import software.amazon.awssdk.services.timestreamwrite.model.CreateBatchLoadTaskResponse;
import software.amazon.awssdk.services.timestreamwrite.model.CreateDatabaseRequest;
import software.amazon.awssdk.services.timestreamwrite.model.CreateDatabaseResponse;
import software.amazon.awssdk.services.timestreamwrite.model.CreateTableRequest;
import software.amazon.awssdk.services.timestreamwrite.model.CreateTableResponse;
import software.amazon.awssdk.services.timestreamwrite.model.DeleteDatabaseRequest;
import software.amazon.awssdk.services.timestreamwrite.model.DeleteDatabaseResponse;
import software.amazon.awssdk.services.timestreamwrite.model.DeleteTableRequest;
import software.amazon.awssdk.services.timestreamwrite.model.DeleteTableResponse;
import software.amazon.awssdk.services.timestreamwrite.model.DescribeBatchLoadTaskRequest;
import software.amazon.awssdk.services.timestreamwrite.model.DescribeBatchLoadTaskResponse;
import software.amazon.awssdk.services.timestreamwrite.model.DescribeDatabaseRequest;
import software.amazon.awssdk.services.timestreamwrite.model.DescribeDatabaseResponse;
import software.amazon.awssdk.services.timestreamwrite.model.DescribeEndpointsRequest;
import software.amazon.awssdk.services.timestreamwrite.model.DescribeEndpointsResponse;
import software.amazon.awssdk.services.timestreamwrite.model.DescribeTableRequest;
import software.amazon.awssdk.services.timestreamwrite.model.DescribeTableResponse;
import software.amazon.awssdk.services.timestreamwrite.model.InternalServerException;
import software.amazon.awssdk.services.timestreamwrite.model.InvalidEndpointException;
import software.amazon.awssdk.services.timestreamwrite.model.ListBatchLoadTasksRequest;
import software.amazon.awssdk.services.timestreamwrite.model.ListBatchLoadTasksResponse;
import software.amazon.awssdk.services.timestreamwrite.model.ListDatabasesRequest;
import software.amazon.awssdk.services.timestreamwrite.model.ListDatabasesResponse;
import software.amazon.awssdk.services.timestreamwrite.model.ListTablesRequest;
import software.amazon.awssdk.services.timestreamwrite.model.ListTablesResponse;
import software.amazon.awssdk.services.timestreamwrite.model.ListTagsForResourceRequest;
import software.amazon.awssdk.services.timestreamwrite.model.ListTagsForResourceResponse;
import software.amazon.awssdk.services.timestreamwrite.model.RejectedRecordsException;
import software.amazon.awssdk.services.timestreamwrite.model.ResourceNotFoundException;
import software.amazon.awssdk.services.timestreamwrite.model.ResumeBatchLoadTaskRequest;
import software.amazon.awssdk.services.timestreamwrite.model.ResumeBatchLoadTaskResponse;
import software.amazon.awssdk.services.timestreamwrite.model.ServiceQuotaExceededException;
import software.amazon.awssdk.services.timestreamwrite.model.TagResourceRequest;
import software.amazon.awssdk.services.timestreamwrite.model.TagResourceResponse;
import software.amazon.awssdk.services.timestreamwrite.model.ThrottlingException;
import software.amazon.awssdk.services.timestreamwrite.model.TimestreamWriteException;
import software.amazon.awssdk.services.timestreamwrite.model.UntagResourceRequest;
import software.amazon.awssdk.services.timestreamwrite.model.UntagResourceResponse;
import software.amazon.awssdk.services.timestreamwrite.model.UpdateDatabaseRequest;
import software.amazon.awssdk.services.timestreamwrite.model.UpdateDatabaseResponse;
import software.amazon.awssdk.services.timestreamwrite.model.UpdateTableRequest;
import software.amazon.awssdk.services.timestreamwrite.model.UpdateTableResponse;
import software.amazon.awssdk.services.timestreamwrite.model.ValidationException;
import software.amazon.awssdk.services.timestreamwrite.model.WriteRecordsRequest;
import software.amazon.awssdk.services.timestreamwrite.model.WriteRecordsResponse;
import software.amazon.awssdk.services.timestreamwrite.transform.CreateBatchLoadTaskRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.CreateDatabaseRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.CreateTableRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.DeleteDatabaseRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.DeleteTableRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.DescribeBatchLoadTaskRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.DescribeDatabaseRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.DescribeEndpointsRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.DescribeTableRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.ListBatchLoadTasksRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.ListDatabasesRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.ListTablesRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.ListTagsForResourceRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.ResumeBatchLoadTaskRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.TagResourceRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.UntagResourceRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.UpdateDatabaseRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.UpdateTableRequestMarshaller;
import software.amazon.awssdk.services.timestreamwrite.transform.WriteRecordsRequestMarshaller;
import software.amazon.awssdk.utils.CompletableFutureUtils;
/**
* Internal implementation of {@link TimestreamWriteAsyncClient}.
*
* @see TimestreamWriteAsyncClient#builder()
*/
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
final class DefaultTimestreamWriteAsyncClient implements TimestreamWriteAsyncClient {
private static final Logger log = LoggerFactory.getLogger(DefaultTimestreamWriteAsyncClient.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 DefaultTimestreamWriteAsyncClient(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(TimestreamWriteAsyncEndpointDiscoveryCacheLoader
.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.");
}
}
}
/**
*
* Creates a new Timestream batch load task. A batch load task processes data from a CSV source in an S3 location
* and writes to a Timestream table. A mapping from source to target is defined in a batch load task. Errors and
* events are written to a report at an S3 location. For the report, if the KMS key is not specified, the report
* will be encrypted with an S3 managed key when SSE_S3
is the option. Otherwise an error is thrown.
* For more information, see Amazon Web Services
* managed keys. Service
* quotas apply. For details, see code
* sample.
*
*
* @param createBatchLoadTaskRequest
* @return A Java Future containing the result of the CreateBatchLoadTask 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 Timestream was unable to fully process this request because of an internal
* server error.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - AccessDeniedException You are not authorized to perform this action.
* - ValidationException An invalid or malformed request.
* - ConflictException Timestream was unable to process this request because it contains resource that
* already exists.
* - ResourceNotFoundException The operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - ServiceQuotaExceededException The instance quota of resource exceeded for this account.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.CreateBatchLoadTask
* @see AWS API Documentation
*/
@Override
public CompletableFuture createBatchLoadTask(
CreateBatchLoadTaskRequest createBatchLoadTaskRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createBatchLoadTaskRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, createBatchLoadTaskRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateBatchLoadTask");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, CreateBatchLoadTaskResponse::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 = createBatchLoadTaskRequest
.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(createBatchLoadTaskRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture
.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateBatchLoadTask").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CreateBatchLoadTaskRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(createBatchLoadTaskRequest)));
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);
}
}
/**
*
* Creates a new Timestream database. If the KMS key is not specified, the database will be encrypted with a
* Timestream managed KMS key located in your account. For more information, see Amazon Web Services
* managed keys. Service
* quotas apply. For details, see code sample.
*
*
* @param createDatabaseRequest
* @return A Java Future containing the result of the CreateDatabase 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.
*
* - ConflictException Timestream was unable to process this request because it contains resource that
* already exists.
* - ValidationException An invalid or malformed request.
* - AccessDeniedException You are not authorized to perform this action.
* - ServiceQuotaExceededException The instance quota of resource exceeded for this account.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - InvalidEndpointException The requested endpoint was not valid.
* - InternalServerException Timestream was unable to fully process this request because of an internal
* server error.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.CreateDatabase
* @see AWS API Documentation
*/
@Override
public CompletableFuture createDatabase(CreateDatabaseRequest createDatabaseRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createDatabaseRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, createDatabaseRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateDatabase");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, CreateDatabaseResponse::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 = createDatabaseRequest
.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(createDatabaseRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateDatabase").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CreateDatabaseRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(createDatabaseRequest)));
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);
}
}
/**
*
* Adds a new table to an existing database in your account. In an Amazon Web Services account, table names must be
* at least unique within each Region if they are in the same database. You might have identical table names in the
* same Region if the tables are in separate databases. While creating the table, you must specify the table name,
* database name, and the retention properties. Service quotas apply. See
* code
* sample for details.
*
*
* @param createTableRequest
* @return A Java Future containing the result of the CreateTable 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.
*
* - ConflictException Timestream was unable to process this request because it contains resource that
* already exists.
* - ValidationException An invalid or malformed request.
* - AccessDeniedException You are not authorized to perform this action.
* - ResourceNotFoundException The operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - ServiceQuotaExceededException The instance quota of resource exceeded for this account.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - InvalidEndpointException The requested endpoint was not valid.
* - InternalServerException Timestream was unable to fully process this request because of an internal
* server error.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.CreateTable
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture createTable(CreateTableRequest createTableRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createTableRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, createTableRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateTable");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
CreateTableResponse::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 = createTableRequest.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(createTableRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateTable").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CreateTableRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(createTableRequest)));
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 Timestream database. This is an irreversible operation. After a database is deleted, the
* time-series data from its tables cannot be recovered.
*
*
*
* All tables in the database must be deleted first, or a ValidationException error will be thrown.
*
*
* Due to the nature of distributed retries, the operation can return either success or a ResourceNotFoundException.
* Clients should consider them equivalent.
*
*
*
* See code
* sample for details.
*
*
* @param deleteDatabaseRequest
* @return A Java Future containing the result of the DeleteDatabase 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 Timestream was unable to fully process this request because of an internal
* server error.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - ResourceNotFoundException The operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - ValidationException An invalid or malformed request.
* - AccessDeniedException You are not authorized to perform this action.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.DeleteDatabase
* @see AWS API Documentation
*/
@Override
public CompletableFuture deleteDatabase(DeleteDatabaseRequest deleteDatabaseRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(deleteDatabaseRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, deleteDatabaseRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DeleteDatabase");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DeleteDatabaseResponse::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 = deleteDatabaseRequest
.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(deleteDatabaseRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DeleteDatabase").withProtocolMetadata(protocolMetadata)
.withMarshaller(new DeleteDatabaseRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(deleteDatabaseRequest)));
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 Timestream table. This is an irreversible operation. After a Timestream database table is
* deleted, the time-series data stored in the table cannot be recovered.
*
*
*
* Due to the nature of distributed retries, the operation can return either success or a ResourceNotFoundException.
* Clients should consider them equivalent.
*
*
*
* See code
* sample for details.
*
*
* @param deleteTableRequest
* @return A Java Future containing the result of the DeleteTable 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 Timestream was unable to fully process this request because of an internal
* server error.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - ValidationException An invalid or malformed request.
* - ResourceNotFoundException The operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - AccessDeniedException You are not authorized to perform this action.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.DeleteTable
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture deleteTable(DeleteTableRequest deleteTableRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(deleteTableRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, deleteTableRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DeleteTable");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
DeleteTableResponse::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 = deleteTableRequest.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(deleteTableRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DeleteTable").withProtocolMetadata(protocolMetadata)
.withMarshaller(new DeleteTableRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(deleteTableRequest)));
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);
}
}
/**
*
* Returns information about the batch load task, including configurations, mappings, progress, and other details.
* Service quotas apply.
* See code
* sample for details.
*
*
* @param describeBatchLoadTaskRequest
* @return A Java Future containing the result of the DescribeBatchLoadTask 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 Timestream was unable to fully process this request because of an internal
* server error.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - AccessDeniedException You are not authorized to perform this action.
* - ResourceNotFoundException The operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.DescribeBatchLoadTask
* @see AWS API Documentation
*/
@Override
public CompletableFuture describeBatchLoadTask(
DescribeBatchLoadTaskRequest describeBatchLoadTaskRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(describeBatchLoadTaskRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, describeBatchLoadTaskRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeBatchLoadTask");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DescribeBatchLoadTaskResponse::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 = describeBatchLoadTaskRequest
.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(describeBatchLoadTaskRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture
.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DescribeBatchLoadTask").withProtocolMetadata(protocolMetadata)
.withMarshaller(new DescribeBatchLoadTaskRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(describeBatchLoadTaskRequest)));
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);
}
}
/**
*
* Returns information about the database, including the database name, time that the database was created, and the
* total number of tables found within the database. Service quotas apply. See
* code
* sample for details.
*
*
* @param describeDatabaseRequest
* @return A Java Future containing the result of the DescribeDatabase 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 operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - ValidationException An invalid or malformed request.
* - AccessDeniedException You are not authorized to perform this action.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - InternalServerException Timestream was unable to fully process this request because of an internal
* server error.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.DescribeDatabase
* @see AWS API Documentation
*/
@Override
public CompletableFuture describeDatabase(DescribeDatabaseRequest describeDatabaseRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(describeDatabaseRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, describeDatabaseRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeDatabase");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DescribeDatabaseResponse::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 = describeDatabaseRequest
.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(describeDatabaseRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture
.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DescribeDatabase").withProtocolMetadata(protocolMetadata)
.withMarshaller(new DescribeDatabaseRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(describeDatabaseRequest)));
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);
}
}
/**
*
* Returns a list of available endpoints to make Timestream API calls against. This API operation is available
* through both the Write and Query APIs.
*
*
* Because the Timestream SDKs are designed to transparently work with the service’s architecture, including the
* management and mapping of the service endpoints, we don't recommend that you use this API operation
* 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 Timestream was unable to fully process this request because of an internal
* server error.
* - ValidationException An invalid or malformed request.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.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 Write");
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);
}
}
/**
*
* Returns information about the table, including the table name, database name, retention duration of the memory
* store and the magnetic store. Service quotas apply. See
* code
* sample for details.
*
*
* @param describeTableRequest
* @return A Java Future containing the result of the DescribeTable 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 operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - ValidationException An invalid or malformed request.
* - AccessDeniedException You are not authorized to perform this action.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - InternalServerException Timestream was unable to fully process this request because of an internal
* server error.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.DescribeTable
* @see AWS API Documentation
*/
@Override
public CompletableFuture describeTable(DescribeTableRequest describeTableRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(describeTableRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, describeTableRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeTable");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
DescribeTableResponse::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 = describeTableRequest.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(describeTableRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DescribeTable").withProtocolMetadata(protocolMetadata)
.withMarshaller(new DescribeTableRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(describeTableRequest)));
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 a list of batch load tasks, along with the name, status, when the task is resumable until, and other
* details. See code
* sample for details.
*
*
* @param listBatchLoadTasksRequest
* @return A Java Future containing the result of the ListBatchLoadTasks 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 Timestream was unable to fully process this request because of an internal
* server error.
* - AccessDeniedException You are not authorized to perform this action.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - ValidationException An 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.ListBatchLoadTasks
* @see AWS API Documentation
*/
@Override
public CompletableFuture listBatchLoadTasks(ListBatchLoadTasksRequest listBatchLoadTasksRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listBatchLoadTasksRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listBatchLoadTasksRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListBatchLoadTasks");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListBatchLoadTasksResponse::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 = listBatchLoadTasksRequest
.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(listBatchLoadTasksRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture
.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListBatchLoadTasks").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListBatchLoadTasksRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(listBatchLoadTasksRequest)));
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);
}
}
/**
*
* Returns a list of your Timestream databases. Service quotas apply. See
* code sample
* for details.
*
*
* @param listDatabasesRequest
* @return A Java Future containing the result of the ListDatabases 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 Timestream was unable to fully process this request because of an internal
* server error.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - ValidationException An invalid or malformed request.
* - AccessDeniedException You are not authorized to perform this action.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.ListDatabases
* @see AWS API Documentation
*/
@Override
public CompletableFuture listDatabases(ListDatabasesRequest listDatabasesRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listDatabasesRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listDatabasesRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListDatabases");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
ListDatabasesResponse::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 = listDatabasesRequest.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(listDatabasesRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListDatabases").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListDatabasesRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(listDatabasesRequest)));
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 a list of tables, along with the name, status, and retention properties of each table. See code sample
* for details.
*
*
* @param listTablesRequest
* @return A Java Future containing the result of the ListTables 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 Timestream was unable to fully process this request because of an internal
* server error.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - ValidationException An invalid or malformed request.
* - ResourceNotFoundException The operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - AccessDeniedException You are not authorized to perform this action.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.ListTables
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture listTables(ListTablesRequest listTablesRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listTablesRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listTablesRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListTables");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
ListTablesResponse::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 = listTablesRequest.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(listTablesRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams().withOperationName("ListTables")
.withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListTablesRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(listTablesRequest)));
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);
}
}
/**
*
* Lists all tags on a Timestream 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 operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - ValidationException An 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.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 Write");
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);
}
}
/**
*
*
*
* @param resumeBatchLoadTaskRequest
* @return A Java Future containing the result of the ResumeBatchLoadTask 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 Timestream was unable to fully process this request because of an internal
* server error.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - AccessDeniedException You are not authorized to perform this action.
* - ValidationException An invalid or malformed request.
* - ResourceNotFoundException The operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.ResumeBatchLoadTask
* @see AWS API Documentation
*/
@Override
public CompletableFuture resumeBatchLoadTask(
ResumeBatchLoadTaskRequest resumeBatchLoadTaskRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(resumeBatchLoadTaskRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, resumeBatchLoadTaskRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ResumeBatchLoadTask");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ResumeBatchLoadTaskResponse::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 = resumeBatchLoadTaskRequest
.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(resumeBatchLoadTaskRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture
.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ResumeBatchLoadTask").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ResumeBatchLoadTaskRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(resumeBatchLoadTaskRequest)));
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);
}
}
/**
*
* Associates 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 operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - ServiceQuotaExceededException The instance quota of resource exceeded for this account.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - ValidationException An 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.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 Write");
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 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 An invalid or malformed request.
* - ServiceQuotaExceededException The instance quota of resource exceeded for this account.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - ResourceNotFoundException The operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.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 Write");
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);
}
}
/**
*
* Modifies the KMS key for an existing database. While updating the database, you must specify the database name
* and the identifier of the new KMS key to be used (KmsKeyId
). If there are any concurrent
* UpdateDatabase
requests, first writer wins.
*
*
* See code
* sample for details.
*
*
* @param updateDatabaseRequest
* @return A Java Future containing the result of the UpdateDatabase 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 An invalid or malformed request.
* - AccessDeniedException You are not authorized to perform this action.
* - ResourceNotFoundException The operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - ServiceQuotaExceededException The instance quota of resource exceeded for this account.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - InternalServerException Timestream was unable to fully process this request because of an internal
* server error.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.UpdateDatabase
* @see AWS API Documentation
*/
@Override
public CompletableFuture updateDatabase(UpdateDatabaseRequest updateDatabaseRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(updateDatabaseRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, updateDatabaseRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UpdateDatabase");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, UpdateDatabaseResponse::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 = updateDatabaseRequest
.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(updateDatabaseRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("UpdateDatabase").withProtocolMetadata(protocolMetadata)
.withMarshaller(new UpdateDatabaseRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(updateDatabaseRequest)));
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);
}
}
/**
*
* Modifies the retention duration of the memory store and magnetic store for your Timestream table. Note that the
* change in retention duration takes effect immediately. For example, if the retention period of the memory store
* was initially set to 2 hours and then changed to 24 hours, the memory store will be capable of holding 24 hours
* of data, but will be populated with 24 hours of data 22 hours after this change was made. Timestream does not
* retrieve data from the magnetic store to populate the memory store.
*
*
* See code
* sample for details.
*
*
* @param updateTableRequest
* @return A Java Future containing the result of the UpdateTable 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 Timestream was unable to fully process this request because of an internal
* server error.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - ValidationException An invalid or malformed request.
* - ResourceNotFoundException The operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - AccessDeniedException You are not authorized to perform this action.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.UpdateTable
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture updateTable(UpdateTableRequest updateTableRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(updateTableRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, updateTableRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UpdateTable");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
UpdateTableResponse::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 = updateTableRequest.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(updateTableRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("UpdateTable").withProtocolMetadata(protocolMetadata)
.withMarshaller(new UpdateTableRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(updateTableRequest)));
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);
}
}
/**
*
* Enables you to write your time-series data into Timestream. You can specify a single data point or a batch of
* data points to be inserted into the system. Timestream offers you a flexible schema that auto detects the column
* names and data types for your Timestream tables based on the dimension names and data types of the data points
* you specify when invoking writes into the database.
*
*
* Timestream supports eventual consistency read semantics. This means that when you query data immediately after
* writing a batch of data into Timestream, the query results might not reflect the results of a recently completed
* write operation. The results may also include some stale data. If you repeat the query request after a short
* time, the results should return the latest data. Service quotas apply.
*
*
* See code
* sample for details.
*
*
* Upserts
*
*
* You can use the Version
parameter in a WriteRecords
request to update data points.
* Timestream tracks a version number with each record. Version
defaults to 1
when it's
* not specified for the record in the request. Timestream updates an existing record’s measure value along with its
* Version
when it receives a write request with a higher Version
number for that record.
* When it receives an update request where the measure value is the same as that of the existing record, Timestream
* still updates Version
, if it is greater than the existing value of Version
. You can
* update a data point as many times as desired, as long as the value of Version
continuously
* increases.
*
*
* For example, suppose you write a new record without indicating Version
in the request. Timestream
* stores this record, and set Version
to 1
. Now, suppose you try to update this record
* with a WriteRecords
request of the same record with a different measure value but, like before, do
* not provide Version
. In this case, Timestream will reject this update with a
* RejectedRecordsException
since the updated record’s version is not greater than the existing value
* of Version.
*
*
* However, if you were to resend the update request with Version
set to 2
, Timestream
* would then succeed in updating the record’s value, and the Version
would be set to 2
.
* Next, suppose you sent a WriteRecords
request with this same record and an identical measure value,
* but with Version
set to 3
. In this case, Timestream would only update
* Version
to 3
. Any further updates would need to send a version number greater than
* 3
, or the update requests would receive a RejectedRecordsException
.
*
*
* @param writeRecordsRequest
* @return A Java Future containing the result of the WriteRecords 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 Timestream was unable to fully process this request because of an internal
* server error.
* - ThrottlingException Too many requests were made by a user and they exceeded the service quotas. The
* request was throttled.
* - ValidationException An invalid or malformed request.
* - ResourceNotFoundException The operation tried to access a nonexistent resource. The resource might
* not be specified correctly, or its status might not be ACTIVE.
* - AccessDeniedException You are not authorized to perform this action.
* - RejectedRecordsException WriteRecords would throw this exception in the following cases:
*
* -
*
* Records with duplicate data where there are multiple records with the same dimensions, timestamps, and
* measure names but:
*
*
* -
*
* Measure values are different
*
*
* -
*
* Version is not present in the request or the value of version in the new record is equal to or
* lower than the existing value
*
*
*
*
* In this case, if Timestream rejects data, the ExistingVersion
field in the
* RejectedRecords
response will indicate the current record’s version. To force an update, you
* can resend the request with a version for the record set to a value greater than the
* ExistingVersion
.
*
*
* -
*
* Records with timestamps that lie outside the retention duration of the memory store.
*
*
* -
*
* Records with dimensions or measures that exceed the Timestream defined limits.
*
*
*
*
* For more information, see Quotas in the
* Amazon Timestream Developer Guide.
* - 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.
* - TimestreamWriteException Base class for all service exceptions. Unknown exceptions will be thrown as
* an instance of this type.
*
* @sample TimestreamWriteAsyncClient.WriteRecords
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture writeRecords(WriteRecordsRequest writeRecordsRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(writeRecordsRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, writeRecordsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Timestream Write");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "WriteRecords");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
WriteRecordsResponse::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 = writeRecordsRequest.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(writeRecordsRequest.overrideConfiguration().orElse(null)).build();
return endpointDiscoveryCache.getAsync(credentials.accessKeyId(), endpointDiscoveryRequest);
});
}
CompletableFuture executeFuture = endpointFuture.thenCompose(cachedEndpoint -> clientHandler
.execute(new ClientExecutionParams()
.withOperationName("WriteRecords").withProtocolMetadata(protocolMetadata)
.withMarshaller(new WriteRecordsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.discoveredEndpoint(cachedEndpoint).withInput(writeRecordsRequest)));
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 TimestreamWriteServiceClientConfiguration serviceClientConfiguration() {
return new TimestreamWriteServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build();
}
@Override
public final String serviceName() {
return SERVICE_NAME;
}
private > T init(T builder) {
return builder
.clientConfiguration(clientConfiguration)
.defaultServiceExceptionSupplier(TimestreamWriteException::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(500).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("RejectedRecordsException")
.exceptionBuilderSupplier(RejectedRecordsException::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();
}
TimestreamWriteServiceClientConfigurationBuilder serviceConfigBuilder = new TimestreamWriteServiceClientConfigurationBuilder(
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();
}
}