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

software.amazon.awssdk.services.marketplaceagreement.DefaultMarketplaceAgreementClient Maven / Gradle / Ivy

Go to download

The AWS Java SDK for Marketplace Agreement module holds the client classes that are used for communicating with Marketplace Agreement.

There is a newer version: 2.28.3
Show newest version
/*
 * 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.marketplaceagreement;

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.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.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.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.retry.RetryMode;
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.marketplaceagreement.internal.MarketplaceAgreementServiceClientConfigurationBuilder;
import software.amazon.awssdk.services.marketplaceagreement.model.AccessDeniedException;
import software.amazon.awssdk.services.marketplaceagreement.model.DescribeAgreementRequest;
import software.amazon.awssdk.services.marketplaceagreement.model.DescribeAgreementResponse;
import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsRequest;
import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsResponse;
import software.amazon.awssdk.services.marketplaceagreement.model.InternalServerException;
import software.amazon.awssdk.services.marketplaceagreement.model.MarketplaceAgreementException;
import software.amazon.awssdk.services.marketplaceagreement.model.ResourceNotFoundException;
import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsRequest;
import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsResponse;
import software.amazon.awssdk.services.marketplaceagreement.model.ThrottlingException;
import software.amazon.awssdk.services.marketplaceagreement.model.ValidationException;
import software.amazon.awssdk.services.marketplaceagreement.transform.DescribeAgreementRequestMarshaller;
import software.amazon.awssdk.services.marketplaceagreement.transform.GetAgreementTermsRequestMarshaller;
import software.amazon.awssdk.services.marketplaceagreement.transform.SearchAgreementsRequestMarshaller;
import software.amazon.awssdk.utils.Logger;

/**
 * Internal implementation of {@link MarketplaceAgreementClient}.
 *
 * @see MarketplaceAgreementClient#builder()
 */
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
final class DefaultMarketplaceAgreementClient implements MarketplaceAgreementClient {
    private static final Logger log = Logger.loggerFor(DefaultMarketplaceAgreementClient.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 DefaultMarketplaceAgreementClient(SdkClientConfiguration clientConfiguration) {
        this.clientHandler = new AwsSyncClientHandler(clientConfiguration);
        this.clientConfiguration = clientConfiguration.toBuilder().option(SdkClientOption.SDK_CLIENT, this).build();
        this.protocolFactory = init(AwsJsonProtocolFactory.builder()).build();
    }

    /**
     * 

* Provides details about an agreement, such as the proposer, acceptor, start date, and end date. *

* * @param describeAgreementRequest * @return Result of the DescribeAgreement operation returned by the service. * @throws ValidationException * The input fails to satisfy the constraints specified by the service. * @throws AccessDeniedException * User does not have sufficient access to perform this action. * @throws ThrottlingException * Request was denied due to request throttling. * @throws ResourceNotFoundException * Request references a resource which does not exist. * @throws InternalServerException * Unexpected error during processing of request. * @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 MarketplaceAgreementException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample MarketplaceAgreementClient.DescribeAgreement * @see AWS API Documentation */ @Override public DescribeAgreementResponse describeAgreement(DescribeAgreementRequest describeAgreementRequest) throws ValidationException, AccessDeniedException, ThrottlingException, ResourceNotFoundException, InternalServerException, AwsServiceException, SdkClientException, MarketplaceAgreementException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, DescribeAgreementResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(describeAgreementRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, describeAgreementRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Marketplace Agreement"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeAgreement"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("DescribeAgreement").withProtocolMetadata(protocolMetadata) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withInput(describeAgreementRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new DescribeAgreementRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Obtains details about the terms in an agreement that you participated in as proposer or acceptor. *

*

* The details include: *

*
    *
  • *

    * TermType – The type of term, such as LegalTerm, RenewalTerm, or * ConfigurableUpfrontPricingTerm. *

    *
  • *
  • *

    * TermID – The ID of the particular term, which is common between offer and agreement. *

    *
  • *
  • *

    * TermPayload – The key information contained in the term, such as the EULA for LegalTerm * or pricing and dimensions for various pricing terms, such as ConfigurableUpfrontPricingTerm or * UsageBasedPricingTerm. *

    *
  • *
*
    *
  • *

    * Configuration – The buyer/acceptor's selection at the time of agreement creation, such as the number * of units purchased for a dimension or setting the EnableAutoRenew flag. *

    *
  • *
* * @param getAgreementTermsRequest * @return Result of the GetAgreementTerms operation returned by the service. * @throws ValidationException * The input fails to satisfy the constraints specified by the service. * @throws AccessDeniedException * User does not have sufficient access to perform this action. * @throws ThrottlingException * Request was denied due to request throttling. * @throws ResourceNotFoundException * Request references a resource which does not exist. * @throws InternalServerException * Unexpected error during processing of request. * @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 MarketplaceAgreementException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample MarketplaceAgreementClient.GetAgreementTerms * @see AWS API Documentation */ @Override public GetAgreementTermsResponse getAgreementTerms(GetAgreementTermsRequest getAgreementTermsRequest) throws ValidationException, AccessDeniedException, ThrottlingException, ResourceNotFoundException, InternalServerException, AwsServiceException, SdkClientException, MarketplaceAgreementException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, GetAgreementTermsResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getAgreementTermsRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, getAgreementTermsRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Marketplace Agreement"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetAgreementTerms"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("GetAgreementTerms").withProtocolMetadata(protocolMetadata) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withInput(getAgreementTermsRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new GetAgreementTermsRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Searches across all agreements that a proposer or an acceptor has in AWS Marketplace. The search returns a list * of agreements with basic agreement information. *

*

* The following filter combinations are supported: *

*
    *
  • *

    * PartyType as Proposer + AgreementType + ResourceIdentifier *

    *
  • *
  • *

    * PartyType as Proposer + AgreementType + OfferId *

    *
  • *
  • *

    * PartyType as Proposer + AgreementType + AcceptorAccountId *

    *
  • *
  • *

    * PartyType as Proposer + AgreementType + Status *

    *
  • *
  • *

    * PartyType as Proposer + AgreementType + ResourceIdentifier + * Status *

    *
  • *
  • *

    * PartyType as Proposer + AgreementType + OfferId + * Status *

    *
  • *
  • *

    * PartyType as Proposer + AgreementType + AcceptorAccountId + * Status *

    *
  • *
  • *

    * PartyType as Proposer + AgreementType + ResourceType + * Status *

    *
  • *
  • *

    * PartyType as Proposer + AgreementType + AcceptorAccountId + * ResourceType + Status *

    *
  • *
  • *

    * PartyType as Proposer + AgreementType + AcceptorAccountId + * OfferId *

    *
  • *
  • *

    * PartyType as Proposer + AgreementType + AcceptorAccountId + * OfferId + Status *

    *
  • *
  • *

    * PartyType as Proposer + AgreementType + AcceptorAccountId + * ResourceIdentifier *

    *
  • *
  • *

    * PartyType as Proposer + AgreementType + AcceptorAccountId + * ResourceIdentifier + Status *

    *
  • *
  • *

    * PartyType as Proposer + AgreementType + AcceptorAccountId + * ResourceType *

    *
  • *
* * @param searchAgreementsRequest * @return Result of the SearchAgreements operation returned by the service. * @throws ValidationException * The input fails to satisfy the constraints specified by the service. * @throws AccessDeniedException * User does not have sufficient access to perform this action. * @throws ThrottlingException * Request was denied due to request throttling. * @throws InternalServerException * Unexpected error during processing of request. * @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 MarketplaceAgreementException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample MarketplaceAgreementClient.SearchAgreements * @see AWS API Documentation */ @Override public SearchAgreementsResponse searchAgreements(SearchAgreementsRequest searchAgreementsRequest) throws ValidationException, AccessDeniedException, ThrottlingException, InternalServerException, AwsServiceException, SdkClientException, MarketplaceAgreementException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, SearchAgreementsResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(searchAgreementsRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, searchAgreementsRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Marketplace Agreement"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "SearchAgreements"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("SearchAgreements").withProtocolMetadata(protocolMetadata) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withInput(searchAgreementsRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new SearchAgreementsRequestMarshaller(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 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(); } MarketplaceAgreementServiceClientConfigurationBuilder serviceConfigBuilder = new MarketplaceAgreementServiceClientConfigurationBuilder( configuration); for (SdkPlugin plugin : plugins) { plugin.configureClient(serviceConfigBuilder); } updateRetryStrategyClientConfiguration(configuration); return configuration.build(); } private > T init(T builder) { return builder .clientConfiguration(clientConfiguration) .defaultServiceExceptionSupplier(MarketplaceAgreementException::builder) .protocol(AwsJsonProtocol.AWS_JSON) .protocolVersion("1.0") .registerModeledException( ExceptionMetadata.builder().errorCode("AccessDeniedException") .exceptionBuilderSupplier(AccessDeniedException::builder).httpStatusCode(400).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("ValidationException") .exceptionBuilderSupplier(ValidationException::builder).httpStatusCode(400).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("ResourceNotFoundException") .exceptionBuilderSupplier(ResourceNotFoundException::builder).httpStatusCode(400).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("InternalServerException") .exceptionBuilderSupplier(InternalServerException::builder).httpStatusCode(500).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("ThrottlingException") .exceptionBuilderSupplier(ThrottlingException::builder).httpStatusCode(400).build()); } @Override public final MarketplaceAgreementServiceClientConfiguration serviceClientConfiguration() { return new MarketplaceAgreementServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build(); } @Override public void close() { clientHandler.close(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy