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

software.amazon.awssdk.services.costoptimizationhub.DefaultCostOptimizationHubClient 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.costoptimizationhub;

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.costoptimizationhub.internal.CostOptimizationHubServiceClientConfigurationBuilder;
import software.amazon.awssdk.services.costoptimizationhub.model.AccessDeniedException;
import software.amazon.awssdk.services.costoptimizationhub.model.CostOptimizationHubException;
import software.amazon.awssdk.services.costoptimizationhub.model.GetPreferencesRequest;
import software.amazon.awssdk.services.costoptimizationhub.model.GetPreferencesResponse;
import software.amazon.awssdk.services.costoptimizationhub.model.GetRecommendationRequest;
import software.amazon.awssdk.services.costoptimizationhub.model.GetRecommendationResponse;
import software.amazon.awssdk.services.costoptimizationhub.model.InternalServerException;
import software.amazon.awssdk.services.costoptimizationhub.model.ListEnrollmentStatusesRequest;
import software.amazon.awssdk.services.costoptimizationhub.model.ListEnrollmentStatusesResponse;
import software.amazon.awssdk.services.costoptimizationhub.model.ListRecommendationSummariesRequest;
import software.amazon.awssdk.services.costoptimizationhub.model.ListRecommendationSummariesResponse;
import software.amazon.awssdk.services.costoptimizationhub.model.ListRecommendationsRequest;
import software.amazon.awssdk.services.costoptimizationhub.model.ListRecommendationsResponse;
import software.amazon.awssdk.services.costoptimizationhub.model.ResourceNotFoundException;
import software.amazon.awssdk.services.costoptimizationhub.model.ThrottlingException;
import software.amazon.awssdk.services.costoptimizationhub.model.UpdateEnrollmentStatusRequest;
import software.amazon.awssdk.services.costoptimizationhub.model.UpdateEnrollmentStatusResponse;
import software.amazon.awssdk.services.costoptimizationhub.model.UpdatePreferencesRequest;
import software.amazon.awssdk.services.costoptimizationhub.model.UpdatePreferencesResponse;
import software.amazon.awssdk.services.costoptimizationhub.model.ValidationException;
import software.amazon.awssdk.services.costoptimizationhub.transform.GetPreferencesRequestMarshaller;
import software.amazon.awssdk.services.costoptimizationhub.transform.GetRecommendationRequestMarshaller;
import software.amazon.awssdk.services.costoptimizationhub.transform.ListEnrollmentStatusesRequestMarshaller;
import software.amazon.awssdk.services.costoptimizationhub.transform.ListRecommendationSummariesRequestMarshaller;
import software.amazon.awssdk.services.costoptimizationhub.transform.ListRecommendationsRequestMarshaller;
import software.amazon.awssdk.services.costoptimizationhub.transform.UpdateEnrollmentStatusRequestMarshaller;
import software.amazon.awssdk.services.costoptimizationhub.transform.UpdatePreferencesRequestMarshaller;
import software.amazon.awssdk.utils.Logger;

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

    private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder()
            .serviceProtocol(AwsServiceProtocol.AWS_JSON).build();

    private final SyncClientHandler clientHandler;

    private final AwsJsonProtocolFactory protocolFactory;

    private final SdkClientConfiguration clientConfiguration;

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

    /**
     * 

* Returns a set of preferences for an account in order to add account-specific preferences into the service. These * preferences impact how the savings associated with recommendations are presented—estimated savings after * discounts or estimated savings before discounts, for example. *

* * @param getPreferencesRequest * @return Result of the GetPreferences operation returned by the service. * @throws ValidationException * The input fails to satisfy the constraints specified by an Amazon Web Services service. * @throws InternalServerException * An error on the server occurred during the processing of your request. Try again later. * @throws AccessDeniedException * You are not authorized to use this operation with the given parameters. * @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 CostOptimizationHubException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample CostOptimizationHubClient.GetPreferences * @see AWS API Documentation */ @Override public GetPreferencesResponse getPreferences(GetPreferencesRequest getPreferencesRequest) throws ValidationException, InternalServerException, AccessDeniedException, ThrottlingException, AwsServiceException, SdkClientException, CostOptimizationHubException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, GetPreferencesResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getPreferencesRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, getPreferencesRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Cost Optimization Hub"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetPreferences"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("GetPreferences").withProtocolMetadata(protocolMetadata) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withInput(getPreferencesRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new GetPreferencesRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Returns both the current and recommended resource configuration and the estimated cost impact for a * recommendation. *

*

* The recommendationId is only valid for up to a maximum of 24 hours as recommendations are refreshed * daily. To retrieve the recommendationId, use the ListRecommendations API. *

* * @param getRecommendationRequest * @return Result of the GetRecommendation operation returned by the service. * @throws ValidationException * The input fails to satisfy the constraints specified by an Amazon Web Services service. * @throws InternalServerException * An error on the server occurred during the processing of your request. Try again later. * @throws AccessDeniedException * You are not authorized to use this operation with the given parameters. * @throws ResourceNotFoundException * The specified Amazon Resource Name (ARN) in the request doesn't exist. * @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 CostOptimizationHubException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample CostOptimizationHubClient.GetRecommendation * @see AWS API Documentation */ @Override public GetRecommendationResponse getRecommendation(GetRecommendationRequest getRecommendationRequest) throws ValidationException, InternalServerException, AccessDeniedException, ResourceNotFoundException, ThrottlingException, AwsServiceException, SdkClientException, CostOptimizationHubException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, GetRecommendationResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getRecommendationRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, getRecommendationRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Cost Optimization Hub"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetRecommendation"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("GetRecommendation").withProtocolMetadata(protocolMetadata) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withInput(getRecommendationRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new GetRecommendationRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Retrieves the enrollment status for an account. It can also return the list of accounts that are enrolled under * the organization. *

* * @param listEnrollmentStatusesRequest * @return Result of the ListEnrollmentStatuses operation returned by the service. * @throws ValidationException * The input fails to satisfy the constraints specified by an Amazon Web Services service. * @throws InternalServerException * An error on the server occurred during the processing of your request. Try again later. * @throws AccessDeniedException * You are not authorized to use this operation with the given parameters. * @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 CostOptimizationHubException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample CostOptimizationHubClient.ListEnrollmentStatuses * @see AWS API Documentation */ @Override public ListEnrollmentStatusesResponse listEnrollmentStatuses(ListEnrollmentStatusesRequest listEnrollmentStatusesRequest) throws ValidationException, InternalServerException, AccessDeniedException, ThrottlingException, AwsServiceException, SdkClientException, CostOptimizationHubException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, ListEnrollmentStatusesResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listEnrollmentStatusesRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, listEnrollmentStatusesRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Cost Optimization Hub"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListEnrollmentStatuses"); return clientHandler .execute(new ClientExecutionParams() .withOperationName("ListEnrollmentStatuses").withProtocolMetadata(protocolMetadata) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withInput(listEnrollmentStatusesRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new ListEnrollmentStatusesRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Returns a concise representation of savings estimates for resources. Also returns de-duped savings across * different types of recommendations. *

* *

* The following filters are not supported for this API: recommendationIds, resourceArns, * and resourceIds. *

*
* * @param listRecommendationSummariesRequest * @return Result of the ListRecommendationSummaries operation returned by the service. * @throws ValidationException * The input fails to satisfy the constraints specified by an Amazon Web Services service. * @throws InternalServerException * An error on the server occurred during the processing of your request. Try again later. * @throws AccessDeniedException * You are not authorized to use this operation with the given parameters. * @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 CostOptimizationHubException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample CostOptimizationHubClient.ListRecommendationSummaries * @see AWS API Documentation */ @Override public ListRecommendationSummariesResponse listRecommendationSummaries( ListRecommendationSummariesRequest listRecommendationSummariesRequest) throws ValidationException, InternalServerException, AccessDeniedException, ThrottlingException, AwsServiceException, SdkClientException, CostOptimizationHubException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, ListRecommendationSummariesResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listRecommendationSummariesRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, listRecommendationSummariesRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Cost Optimization Hub"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListRecommendationSummaries"); return clientHandler .execute(new ClientExecutionParams() .withOperationName("ListRecommendationSummaries").withProtocolMetadata(protocolMetadata) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withInput(listRecommendationSummariesRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new ListRecommendationSummariesRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Returns a list of recommendations. *

* * @param listRecommendationsRequest * @return Result of the ListRecommendations operation returned by the service. * @throws ValidationException * The input fails to satisfy the constraints specified by an Amazon Web Services service. * @throws InternalServerException * An error on the server occurred during the processing of your request. Try again later. * @throws AccessDeniedException * You are not authorized to use this operation with the given parameters. * @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 CostOptimizationHubException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample CostOptimizationHubClient.ListRecommendations * @see AWS API Documentation */ @Override public ListRecommendationsResponse listRecommendations(ListRecommendationsRequest listRecommendationsRequest) throws ValidationException, InternalServerException, AccessDeniedException, ThrottlingException, AwsServiceException, SdkClientException, CostOptimizationHubException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, ListRecommendationsResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listRecommendationsRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, listRecommendationsRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Cost Optimization Hub"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListRecommendations"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("ListRecommendations").withProtocolMetadata(protocolMetadata) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withInput(listRecommendationsRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new ListRecommendationsRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Updates the enrollment (opt in and opt out) status of an account to the Cost Optimization Hub service. *

*

* If the account is a management account of an organization, this action can also be used to enroll member accounts * of the organization. *

*

* You must have the appropriate permissions to opt in to Cost Optimization Hub and to view its recommendations. * When you opt in, Cost Optimization Hub automatically creates a service-linked role in your account to access its * data. *

* * @param updateEnrollmentStatusRequest * @return Result of the UpdateEnrollmentStatus operation returned by the service. * @throws ValidationException * The input fails to satisfy the constraints specified by an Amazon Web Services service. * @throws InternalServerException * An error on the server occurred during the processing of your request. Try again later. * @throws AccessDeniedException * You are not authorized to use this operation with the given parameters. * @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 CostOptimizationHubException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample CostOptimizationHubClient.UpdateEnrollmentStatus * @see AWS API Documentation */ @Override public UpdateEnrollmentStatusResponse updateEnrollmentStatus(UpdateEnrollmentStatusRequest updateEnrollmentStatusRequest) throws ValidationException, InternalServerException, AccessDeniedException, ThrottlingException, AwsServiceException, SdkClientException, CostOptimizationHubException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, UpdateEnrollmentStatusResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(updateEnrollmentStatusRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, updateEnrollmentStatusRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Cost Optimization Hub"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UpdateEnrollmentStatus"); return clientHandler .execute(new ClientExecutionParams() .withOperationName("UpdateEnrollmentStatus").withProtocolMetadata(protocolMetadata) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withInput(updateEnrollmentStatusRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new UpdateEnrollmentStatusRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Updates a set of preferences for an account in order to add account-specific preferences into the service. These * preferences impact how the savings associated with recommendations are presented. *

* * @param updatePreferencesRequest * @return Result of the UpdatePreferences operation returned by the service. * @throws ValidationException * The input fails to satisfy the constraints specified by an Amazon Web Services service. * @throws InternalServerException * An error on the server occurred during the processing of your request. Try again later. * @throws AccessDeniedException * You are not authorized to use this operation with the given parameters. * @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 CostOptimizationHubException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample CostOptimizationHubClient.UpdatePreferences * @see AWS API Documentation */ @Override public UpdatePreferencesResponse updatePreferences(UpdatePreferencesRequest updatePreferencesRequest) throws ValidationException, InternalServerException, AccessDeniedException, ThrottlingException, AwsServiceException, SdkClientException, CostOptimizationHubException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, UpdatePreferencesResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(updatePreferencesRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, updatePreferencesRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Cost Optimization Hub"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UpdatePreferences"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("UpdatePreferences").withProtocolMetadata(protocolMetadata) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withInput(updatePreferencesRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new UpdatePreferencesRequestMarshaller(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(); } CostOptimizationHubServiceClientConfigurationBuilder serviceConfigBuilder = new CostOptimizationHubServiceClientConfigurationBuilder( configuration); for (SdkPlugin plugin : plugins) { plugin.configureClient(serviceConfigBuilder); } return configuration.build(); } private > T init(T builder) { return builder .clientConfiguration(clientConfiguration) .defaultServiceExceptionSupplier(CostOptimizationHubException::builder) .protocol(AwsJsonProtocol.AWS_JSON) .protocolVersion("1.0") .registerModeledException( ExceptionMetadata.builder().errorCode("AccessDeniedException") .exceptionBuilderSupplier(AccessDeniedException::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("InternalServerException") .exceptionBuilderSupplier(InternalServerException::builder).httpStatusCode(500).build()); } @Override public final CostOptimizationHubServiceClientConfiguration serviceClientConfiguration() { return new CostOptimizationHubServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build(); } @Override public void close() { clientHandler.close(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy