
software.amazon.awssdk.services.s3outposts.DefaultS3OutpostsClient Maven / Gradle / Ivy
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.s3outposts;
import java.util.Collections;
import java.util.List;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler;
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.core.RequestOverrideConfiguration;
import software.amazon.awssdk.core.SdkPlugin;
import software.amazon.awssdk.core.SdkRequest;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
import software.amazon.awssdk.core.client.handler.SyncClientHandler;
import software.amazon.awssdk.core.exception.SdkClientException;
import software.amazon.awssdk.core.http.HttpResponseHandler;
import software.amazon.awssdk.core.metrics.CoreMetric;
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.services.s3outposts.internal.S3OutpostsServiceClientConfigurationBuilder;
import software.amazon.awssdk.services.s3outposts.model.AccessDeniedException;
import software.amazon.awssdk.services.s3outposts.model.ConflictException;
import software.amazon.awssdk.services.s3outposts.model.CreateEndpointRequest;
import software.amazon.awssdk.services.s3outposts.model.CreateEndpointResponse;
import software.amazon.awssdk.services.s3outposts.model.DeleteEndpointRequest;
import software.amazon.awssdk.services.s3outposts.model.DeleteEndpointResponse;
import software.amazon.awssdk.services.s3outposts.model.InternalServerException;
import software.amazon.awssdk.services.s3outposts.model.ListEndpointsRequest;
import software.amazon.awssdk.services.s3outposts.model.ListEndpointsResponse;
import software.amazon.awssdk.services.s3outposts.model.ListOutpostsWithS3Request;
import software.amazon.awssdk.services.s3outposts.model.ListOutpostsWithS3Response;
import software.amazon.awssdk.services.s3outposts.model.ListSharedEndpointsRequest;
import software.amazon.awssdk.services.s3outposts.model.ListSharedEndpointsResponse;
import software.amazon.awssdk.services.s3outposts.model.OutpostOfflineException;
import software.amazon.awssdk.services.s3outposts.model.ResourceNotFoundException;
import software.amazon.awssdk.services.s3outposts.model.S3OutpostsException;
import software.amazon.awssdk.services.s3outposts.model.ThrottlingException;
import software.amazon.awssdk.services.s3outposts.model.ValidationException;
import software.amazon.awssdk.services.s3outposts.transform.CreateEndpointRequestMarshaller;
import software.amazon.awssdk.services.s3outposts.transform.DeleteEndpointRequestMarshaller;
import software.amazon.awssdk.services.s3outposts.transform.ListEndpointsRequestMarshaller;
import software.amazon.awssdk.services.s3outposts.transform.ListOutpostsWithS3RequestMarshaller;
import software.amazon.awssdk.services.s3outposts.transform.ListSharedEndpointsRequestMarshaller;
import software.amazon.awssdk.utils.Logger;
/**
* Internal implementation of {@link S3OutpostsClient}.
*
* @see S3OutpostsClient#builder()
*/
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
final class DefaultS3OutpostsClient implements S3OutpostsClient {
private static final Logger log = Logger.loggerFor(DefaultS3OutpostsClient.class);
private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder()
.serviceProtocol(AwsServiceProtocol.REST_JSON).build();
private final SyncClientHandler clientHandler;
private final AwsJsonProtocolFactory protocolFactory;
private final SdkClientConfiguration clientConfiguration;
protected DefaultS3OutpostsClient(SdkClientConfiguration clientConfiguration) {
this.clientHandler = new AwsSyncClientHandler(clientConfiguration);
this.clientConfiguration = clientConfiguration.toBuilder().option(SdkClientOption.SDK_CLIENT, this).build();
this.protocolFactory = init(AwsJsonProtocolFactory.builder()).build();
}
/**
*
* Creates an endpoint and associates it with the specified Outpost.
*
*
*
* It can take up to 5 minutes for this action to finish.
*
*
*
*
* Related actions include:
*
*
* -
*
* DeleteEndpoint
*
*
* -
*
* ListEndpoints
*
*
*
*
* @param createEndpointRequest
* @return Result of the CreateEndpoint operation returned by the service.
* @throws InternalServerException
* There was an exception with the internal server.
* @throws ValidationException
* There was an exception validating this data.
* @throws AccessDeniedException
* Access was denied for this action.
* @throws ResourceNotFoundException
* The requested resource was not found.
* @throws ConflictException
* There was a conflict with this action, and it could not be completed.
* @throws ThrottlingException
* The request was denied due to request throttling.
* @throws OutpostOfflineException
* The service link connection to your Outposts home Region is down. Check your connection and try again.
* @throws SdkException
* Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
* catch all scenarios.
* @throws SdkClientException
* If any client side error occurs such as an IO related failure, failure to get credentials, etc.
* @throws S3OutpostsException
* Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
* @sample S3OutpostsClient.CreateEndpoint
* @see AWS API
* Documentation
*/
@Override
public CreateEndpointResponse createEndpoint(CreateEndpointRequest createEndpointRequest) throws InternalServerException,
ValidationException, AccessDeniedException, ResourceNotFoundException, ConflictException, ThrottlingException,
OutpostOfflineException, AwsServiceException, SdkClientException, S3OutpostsException {
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
CreateEndpointResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createEndpointRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, createEndpointRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "S3Outposts");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateEndpoint");
return clientHandler.execute(new ClientExecutionParams()
.withOperationName("CreateEndpoint").withProtocolMetadata(protocolMetadata)
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withInput(createEndpointRequest)
.withMetricCollector(apiCallMetricCollector)
.withMarshaller(new CreateEndpointRequestMarshaller(protocolFactory)));
} finally {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
}
}
/**
*
* Deletes an endpoint.
*
*
*
* It can take up to 5 minutes for this action to finish.
*
*
*
*
* Related actions include:
*
*
* -
*
* CreateEndpoint
*
*
* -
*
* ListEndpoints
*
*
*
*
* @param deleteEndpointRequest
* @return Result of the DeleteEndpoint operation returned by the service.
* @throws InternalServerException
* There was an exception with the internal server.
* @throws AccessDeniedException
* Access was denied for this action.
* @throws ResourceNotFoundException
* The requested resource was not found.
* @throws ValidationException
* There was an exception validating this data.
* @throws ThrottlingException
* The request was denied due to request throttling.
* @throws OutpostOfflineException
* The service link connection to your Outposts home Region is down. Check your connection and try again.
* @throws SdkException
* Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
* catch all scenarios.
* @throws SdkClientException
* If any client side error occurs such as an IO related failure, failure to get credentials, etc.
* @throws S3OutpostsException
* Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
* @sample S3OutpostsClient.DeleteEndpoint
* @see AWS API
* Documentation
*/
@Override
public DeleteEndpointResponse deleteEndpoint(DeleteEndpointRequest deleteEndpointRequest) throws InternalServerException,
AccessDeniedException, ResourceNotFoundException, ValidationException, ThrottlingException, OutpostOfflineException,
AwsServiceException, SdkClientException, S3OutpostsException {
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
DeleteEndpointResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(deleteEndpointRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, deleteEndpointRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "S3Outposts");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DeleteEndpoint");
return clientHandler.execute(new ClientExecutionParams()
.withOperationName("DeleteEndpoint").withProtocolMetadata(protocolMetadata)
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withInput(deleteEndpointRequest)
.withMetricCollector(apiCallMetricCollector)
.withMarshaller(new DeleteEndpointRequestMarshaller(protocolFactory)));
} finally {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
}
}
/**
*
* Lists endpoints associated with the specified Outpost.
*
*
* Related actions include:
*
*
* -
*
* CreateEndpoint
*
*
* -
*
* DeleteEndpoint
*
*
*
*
* @param listEndpointsRequest
* @return Result of the ListEndpoints operation returned by the service.
* @throws InternalServerException
* There was an exception with the internal server.
* @throws ResourceNotFoundException
* The requested resource was not found.
* @throws AccessDeniedException
* Access was denied for this action.
* @throws ValidationException
* There was an exception validating this data.
* @throws ThrottlingException
* The request was denied due to request throttling.
* @throws SdkException
* Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
* catch all scenarios.
* @throws SdkClientException
* If any client side error occurs such as an IO related failure, failure to get credentials, etc.
* @throws S3OutpostsException
* Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
* @sample S3OutpostsClient.ListEndpoints
* @see AWS API
* Documentation
*/
@Override
public ListEndpointsResponse listEndpoints(ListEndpointsRequest listEndpointsRequest) throws InternalServerException,
ResourceNotFoundException, AccessDeniedException, ValidationException, ThrottlingException, AwsServiceException,
SdkClientException, S3OutpostsException {
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
ListEndpointsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listEndpointsRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listEndpointsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "S3Outposts");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListEndpoints");
return clientHandler.execute(new ClientExecutionParams()
.withOperationName("ListEndpoints").withProtocolMetadata(protocolMetadata)
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withInput(listEndpointsRequest)
.withMetricCollector(apiCallMetricCollector)
.withMarshaller(new ListEndpointsRequestMarshaller(protocolFactory)));
} finally {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
}
}
/**
*
* Lists the Outposts with S3 on Outposts capacity for your Amazon Web Services account. Includes S3 on Outposts
* that you have access to as the Outposts owner, or as a shared user from Resource Access Manager (RAM).
*
*
* @param listOutpostsWithS3Request
* @return Result of the ListOutpostsWithS3 operation returned by the service.
* @throws InternalServerException
* There was an exception with the internal server.
* @throws AccessDeniedException
* Access was denied for this action.
* @throws ValidationException
* There was an exception validating this data.
* @throws ThrottlingException
* The request was denied due to request throttling.
* @throws SdkException
* Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
* catch all scenarios.
* @throws SdkClientException
* If any client side error occurs such as an IO related failure, failure to get credentials, etc.
* @throws S3OutpostsException
* Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
* @sample S3OutpostsClient.ListOutpostsWithS3
* @see AWS
* API Documentation
*/
@Override
public ListOutpostsWithS3Response listOutpostsWithS3(ListOutpostsWithS3Request listOutpostsWithS3Request)
throws InternalServerException, AccessDeniedException, ValidationException, ThrottlingException, AwsServiceException,
SdkClientException, S3OutpostsException {
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListOutpostsWithS3Response::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listOutpostsWithS3Request,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listOutpostsWithS3Request
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "S3Outposts");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListOutpostsWithS3");
return clientHandler.execute(new ClientExecutionParams()
.withOperationName("ListOutpostsWithS3").withProtocolMetadata(protocolMetadata)
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withInput(listOutpostsWithS3Request)
.withMetricCollector(apiCallMetricCollector)
.withMarshaller(new ListOutpostsWithS3RequestMarshaller(protocolFactory)));
} finally {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
}
}
/**
*
* Lists all endpoints associated with an Outpost that has been shared by Amazon Web Services Resource Access
* Manager (RAM).
*
*
* Related actions include:
*
*
* -
*
* CreateEndpoint
*
*
* -
*
* DeleteEndpoint
*
*
*
*
* @param listSharedEndpointsRequest
* @return Result of the ListSharedEndpoints operation returned by the service.
* @throws InternalServerException
* There was an exception with the internal server.
* @throws ResourceNotFoundException
* The requested resource was not found.
* @throws AccessDeniedException
* Access was denied for this action.
* @throws ValidationException
* There was an exception validating this data.
* @throws ThrottlingException
* The request was denied due to request throttling.
* @throws SdkException
* Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
* catch all scenarios.
* @throws SdkClientException
* If any client side error occurs such as an IO related failure, failure to get credentials, etc.
* @throws S3OutpostsException
* Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
* @sample S3OutpostsClient.ListSharedEndpoints
* @see AWS API Documentation
*/
@Override
public ListSharedEndpointsResponse listSharedEndpoints(ListSharedEndpointsRequest listSharedEndpointsRequest)
throws InternalServerException, ResourceNotFoundException, AccessDeniedException, ValidationException,
ThrottlingException, AwsServiceException, SdkClientException, S3OutpostsException {
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListSharedEndpointsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listSharedEndpointsRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listSharedEndpointsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "S3Outposts");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListSharedEndpoints");
return clientHandler.execute(new ClientExecutionParams()
.withOperationName("ListSharedEndpoints").withProtocolMetadata(protocolMetadata)
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withInput(listSharedEndpointsRequest)
.withMetricCollector(apiCallMetricCollector)
.withMarshaller(new ListSharedEndpointsRequestMarshaller(protocolFactory)));
} finally {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
}
}
@Override
public final String serviceName() {
return SERVICE_NAME;
}
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 HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory,
JsonOperationMetadata operationMetadata) {
return protocolFactory.createErrorResponseHandler(operationMetadata);
}
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();
}
S3OutpostsServiceClientConfigurationBuilder serviceConfigBuilder = new S3OutpostsServiceClientConfigurationBuilder(
configuration);
for (SdkPlugin plugin : plugins) {
plugin.configureClient(serviceConfigBuilder);
}
return configuration.build();
}
private > T init(T builder) {
return builder
.clientConfiguration(clientConfiguration)
.defaultServiceExceptionSupplier(S3OutpostsException::builder)
.protocol(AwsJsonProtocol.REST_JSON)
.protocolVersion("1.1")
.registerModeledException(
ExceptionMetadata.builder().errorCode("AccessDeniedException")
.exceptionBuilderSupplier(AccessDeniedException::builder).httpStatusCode(403).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("ValidationException")
.exceptionBuilderSupplier(ValidationException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("ConflictException")
.exceptionBuilderSupplier(ConflictException::builder).httpStatusCode(409).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("InternalServerException")
.exceptionBuilderSupplier(InternalServerException::builder).httpStatusCode(500).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("OutpostOfflineException")
.exceptionBuilderSupplier(OutpostOfflineException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("ThrottlingException")
.exceptionBuilderSupplier(ThrottlingException::builder).httpStatusCode(429).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("ResourceNotFoundException")
.exceptionBuilderSupplier(ResourceNotFoundException::builder).httpStatusCode(404).build());
}
@Override
public final S3OutpostsServiceClientConfiguration serviceClientConfiguration() {
return new S3OutpostsServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build();
}
@Override
public void close() {
clientHandler.close();
}
}