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

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 java.util.function.Consumer;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.ApiName;
import software.amazon.awssdk.core.RequestOverrideConfiguration;
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.core.util.VersionInfo;
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.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.ListSharedEndpointsRequest;
import software.amazon.awssdk.services.s3outposts.model.ListSharedEndpointsResponse;
import software.amazon.awssdk.services.s3outposts.model.ResourceNotFoundException;
import software.amazon.awssdk.services.s3outposts.model.S3OutpostsException;
import software.amazon.awssdk.services.s3outposts.model.S3OutpostsRequest;
import software.amazon.awssdk.services.s3outposts.model.ValidationException;
import software.amazon.awssdk.services.s3outposts.paginators.ListEndpointsIterable;
import software.amazon.awssdk.services.s3outposts.paginators.ListSharedEndpointsIterable;
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.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 final SyncClientHandler clientHandler;

    private final AwsJsonProtocolFactory protocolFactory;

    private final SdkClientConfiguration clientConfiguration;

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

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

    /**
     * 

* 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: *

* * * @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 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, AwsServiceException, SdkClientException, S3OutpostsException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, CreateEndpointResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); 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").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).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: *

* * * @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 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, AwsServiceException, SdkClientException, S3OutpostsException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, DeleteEndpointResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); 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").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).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: *

* * * @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 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, AwsServiceException, SdkClientException, S3OutpostsException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, ListEndpointsResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); 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").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(listEndpointsRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new ListEndpointsRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Lists endpoints associated with the specified Outpost. *

*

* Related actions include: *

* *
*

* This is a variant of * {@link #listEndpoints(software.amazon.awssdk.services.s3outposts.model.ListEndpointsRequest)} operation. The * return type is a custom iterable that can be used to iterate through all the pages. SDK will internally handle * making service calls for you. *

*

* When this operation is called, a custom iterable is returned but no service calls are made yet. So there is no * guarantee that the request is valid. As you iterate through the iterable, SDK will start lazily loading response * pages by making service calls until there are no pages left or your iteration stops. If there are errors in your * request, you will see the failures only after you start iterating through the iterable. *

* *

* The following are few ways to iterate through the response pages: *

* 1) Using a Stream * *
     * {@code
     * software.amazon.awssdk.services.s3outposts.paginators.ListEndpointsIterable responses = client.listEndpointsPaginator(request);
     * responses.stream().forEach(....);
     * }
     * 
* * 2) Using For loop * *
     * {
     *     @code
     *     software.amazon.awssdk.services.s3outposts.paginators.ListEndpointsIterable responses = client
     *             .listEndpointsPaginator(request);
     *     for (software.amazon.awssdk.services.s3outposts.model.ListEndpointsResponse response : responses) {
     *         // do something;
     *     }
     * }
     * 
* * 3) Use iterator directly * *
     * {@code
     * software.amazon.awssdk.services.s3outposts.paginators.ListEndpointsIterable responses = client.listEndpointsPaginator(request);
     * responses.iterator().forEachRemaining(....);
     * }
     * 
*

* Please notice that the configuration of MaxResults won't limit the number of results you get with the * paginator. It only limits the number of results in each page. *

*

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

* * @param listEndpointsRequest * @return A custom iterable that can be used to iterate through all the response pages. * @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 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 ListEndpointsIterable listEndpointsPaginator(ListEndpointsRequest listEndpointsRequest) throws InternalServerException, ResourceNotFoundException, AccessDeniedException, ValidationException, AwsServiceException, SdkClientException, S3OutpostsException { return new ListEndpointsIterable(this, applyPaginatorUserAgent(listEndpointsRequest)); } /** *

* Lists all endpoints associated with an Outpost that has been shared by Amazon Web Services Resource Access * Manager (RAM). *

*

* Related actions include: *

* * * @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 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, AwsServiceException, SdkClientException, S3OutpostsException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, ListSharedEndpointsResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); 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").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(listSharedEndpointsRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new ListSharedEndpointsRequestMarshaller(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: *

* *
*

* This is a variant of * {@link #listSharedEndpoints(software.amazon.awssdk.services.s3outposts.model.ListSharedEndpointsRequest)} * operation. The return type is a custom iterable that can be used to iterate through all the pages. SDK will * internally handle making service calls for you. *

*

* When this operation is called, a custom iterable is returned but no service calls are made yet. So there is no * guarantee that the request is valid. As you iterate through the iterable, SDK will start lazily loading response * pages by making service calls until there are no pages left or your iteration stops. If there are errors in your * request, you will see the failures only after you start iterating through the iterable. *

* *

* The following are few ways to iterate through the response pages: *

* 1) Using a Stream * *
     * {@code
     * software.amazon.awssdk.services.s3outposts.paginators.ListSharedEndpointsIterable responses = client.listSharedEndpointsPaginator(request);
     * responses.stream().forEach(....);
     * }
     * 
* * 2) Using For loop * *
     * {
     *     @code
     *     software.amazon.awssdk.services.s3outposts.paginators.ListSharedEndpointsIterable responses = client
     *             .listSharedEndpointsPaginator(request);
     *     for (software.amazon.awssdk.services.s3outposts.model.ListSharedEndpointsResponse response : responses) {
     *         // do something;
     *     }
     * }
     * 
* * 3) Use iterator directly * *
     * {@code
     * software.amazon.awssdk.services.s3outposts.paginators.ListSharedEndpointsIterable responses = client.listSharedEndpointsPaginator(request);
     * responses.iterator().forEachRemaining(....);
     * }
     * 
*

* Please notice that the configuration of MaxResults won't limit the number of results you get with the * paginator. It only limits the number of results in each page. *

*

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

* * @param listSharedEndpointsRequest * @return A custom iterable that can be used to iterate through all the response pages. * @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 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 ListSharedEndpointsIterable listSharedEndpointsPaginator(ListSharedEndpointsRequest listSharedEndpointsRequest) throws InternalServerException, ResourceNotFoundException, AccessDeniedException, ValidationException, AwsServiceException, SdkClientException, S3OutpostsException { return new ListSharedEndpointsIterable(this, applyPaginatorUserAgent(listSharedEndpointsRequest)); } 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 > 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("ResourceNotFoundException") .exceptionBuilderSupplier(ResourceNotFoundException::builder).httpStatusCode(404).build()); } @Override public void close() { clientHandler.close(); } private T applyPaginatorUserAgent(T request) { Consumer userAgentApplier = b -> b.addApiName(ApiName.builder() .version(VersionInfo.SDK_VERSION).name("PAGINATED").build()); AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration() .map(c -> c.toBuilder().applyMutation(userAgentApplier).build()) .orElse((AwsRequestOverrideConfiguration.builder().applyMutation(userAgentApplier).build())); return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy