software.amazon.awssdk.services.marketplaceagreement.DefaultMarketplaceAgreementAsyncClient Maven / Gradle / Ivy
Show all versions of marketplaceagreement Show documentation
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.marketplaceagreement;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata;
import software.amazon.awssdk.awscore.internal.AwsServiceProtocol;
import software.amazon.awssdk.awscore.retry.AwsRetryStrategy;
import software.amazon.awssdk.core.RequestOverrideConfiguration;
import software.amazon.awssdk.core.SdkPlugin;
import software.amazon.awssdk.core.SdkRequest;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.client.handler.AsyncClientHandler;
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
import software.amazon.awssdk.core.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.CompletableFutureUtils;
/**
* Internal implementation of {@link MarketplaceAgreementAsyncClient}.
*
* @see MarketplaceAgreementAsyncClient#builder()
*/
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
final class DefaultMarketplaceAgreementAsyncClient implements MarketplaceAgreementAsyncClient {
private static final Logger log = LoggerFactory.getLogger(DefaultMarketplaceAgreementAsyncClient.class);
private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder()
.serviceProtocol(AwsServiceProtocol.AWS_JSON).build();
private final AsyncClientHandler clientHandler;
private final AwsJsonProtocolFactory protocolFactory;
private final SdkClientConfiguration clientConfiguration;
protected DefaultMarketplaceAgreementAsyncClient(SdkClientConfiguration clientConfiguration) {
this.clientHandler = new AwsAsyncClientHandler(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 A Java Future containing the result of the DescribeAgreement operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ValidationException The input fails to satisfy the constraints specified by the service.
* - AccessDeniedException User does not have sufficient access to perform this action.
* - ThrottlingException Request was denied due to request throttling.
* - ResourceNotFoundException Request references a resource which does not exist.
* - InternalServerException Unexpected error during processing of request.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - MarketplaceAgreementException Base class for all service exceptions. Unknown exceptions will be
* thrown as an instance of this type.
*
* @sample MarketplaceAgreementAsyncClient.DescribeAgreement
* @see AWS API Documentation
*/
@Override
public CompletableFuture describeAgreement(DescribeAgreementRequest describeAgreementRequest) {
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");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DescribeAgreementResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DescribeAgreement").withProtocolMetadata(protocolMetadata)
.withMarshaller(new DescribeAgreementRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(describeAgreementRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* 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 A Java Future containing the result of the GetAgreementTerms operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ValidationException The input fails to satisfy the constraints specified by the service.
* - AccessDeniedException User does not have sufficient access to perform this action.
* - ThrottlingException Request was denied due to request throttling.
* - ResourceNotFoundException Request references a resource which does not exist.
* - InternalServerException Unexpected error during processing of request.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - MarketplaceAgreementException Base class for all service exceptions. Unknown exceptions will be
* thrown as an instance of this type.
*
* @sample MarketplaceAgreementAsyncClient.GetAgreementTerms
* @see AWS API Documentation
*/
@Override
public CompletableFuture getAgreementTerms(GetAgreementTermsRequest getAgreementTermsRequest) {
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");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, GetAgreementTermsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("GetAgreementTerms").withProtocolMetadata(protocolMetadata)
.withMarshaller(new GetAgreementTermsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(getAgreementTermsRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* 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 A Java Future containing the result of the SearchAgreements operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ValidationException The input fails to satisfy the constraints specified by the service.
* - AccessDeniedException User does not have sufficient access to perform this action.
* - ThrottlingException Request was denied due to request throttling.
* - InternalServerException Unexpected error during processing of request.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - MarketplaceAgreementException Base class for all service exceptions. Unknown exceptions will be
* thrown as an instance of this type.
*
* @sample MarketplaceAgreementAsyncClient.SearchAgreements
* @see AWS API Documentation
*/
@Override
public CompletableFuture searchAgreements(SearchAgreementsRequest searchAgreementsRequest) {
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");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, SearchAgreementsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("SearchAgreements").withProtocolMetadata(protocolMetadata)
.withMarshaller(new SearchAgreementsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(searchAgreementsRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
@Override
public final MarketplaceAgreementServiceClientConfiguration serviceClientConfiguration() {
return new MarketplaceAgreementServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build();
}
@Override
public final String serviceName() {
return SERVICE_NAME;
}
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());
}
private static List resolveMetricPublishers(SdkClientConfiguration clientConfiguration,
RequestOverrideConfiguration requestOverrideConfiguration) {
List publishers = null;
if (requestOverrideConfiguration != null) {
publishers = requestOverrideConfiguration.metricPublishers();
}
if (publishers == null || publishers.isEmpty()) {
publishers = clientConfiguration.option(SdkClientOption.METRIC_PUBLISHERS);
}
if (publishers == null) {
publishers = Collections.emptyList();
}
return publishers;
}
private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) {
ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder();
RetryMode retryMode = builder.retryMode();
if (retryMode != null) {
configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode));
} else {
Consumer> configurator = builder.retryStrategyConfigurator();
if (configurator != null) {
RetryStrategy.Builder, ?> defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder();
configurator.accept(defaultBuilder);
configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build());
} else {
RetryStrategy retryStrategy = builder.retryStrategy();
if (retryStrategy != null) {
configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy);
}
}
}
configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null);
configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null);
configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null);
}
private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request, SdkClientConfiguration clientConfiguration) {
List plugins = request.overrideConfiguration().map(c -> c.plugins()).orElse(Collections.emptyList());
SdkClientConfiguration.Builder configuration = clientConfiguration.toBuilder();
if (plugins.isEmpty()) {
return configuration.build();
}
MarketplaceAgreementServiceClientConfigurationBuilder serviceConfigBuilder = new MarketplaceAgreementServiceClientConfigurationBuilder(
configuration);
for (SdkPlugin plugin : plugins) {
plugin.configureClient(serviceConfigBuilder);
}
updateRetryStrategyClientConfiguration(configuration);
return configuration.build();
}
private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory,
JsonOperationMetadata operationMetadata) {
return protocolFactory.createErrorResponseHandler(operationMetadata);
}
private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory,
JsonOperationMetadata operationMetadata, Function> exceptionMetadataMapper) {
return protocolFactory.createErrorResponseHandler(operationMetadata, exceptionMetadataMapper);
}
@Override
public void close() {
clientHandler.close();
}
}