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

software.amazon.awssdk.services.kendraranking.DefaultKendraRankingAsyncClient Maven / Gradle / Ivy

Go to download

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

There is a newer version: 2.30.1
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.kendraranking;

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.kendraranking.internal.KendraRankingServiceClientConfigurationBuilder;
import software.amazon.awssdk.services.kendraranking.model.AccessDeniedException;
import software.amazon.awssdk.services.kendraranking.model.ConflictException;
import software.amazon.awssdk.services.kendraranking.model.CreateRescoreExecutionPlanRequest;
import software.amazon.awssdk.services.kendraranking.model.CreateRescoreExecutionPlanResponse;
import software.amazon.awssdk.services.kendraranking.model.DeleteRescoreExecutionPlanRequest;
import software.amazon.awssdk.services.kendraranking.model.DeleteRescoreExecutionPlanResponse;
import software.amazon.awssdk.services.kendraranking.model.DescribeRescoreExecutionPlanRequest;
import software.amazon.awssdk.services.kendraranking.model.DescribeRescoreExecutionPlanResponse;
import software.amazon.awssdk.services.kendraranking.model.InternalServerException;
import software.amazon.awssdk.services.kendraranking.model.KendraRankingException;
import software.amazon.awssdk.services.kendraranking.model.ListRescoreExecutionPlansRequest;
import software.amazon.awssdk.services.kendraranking.model.ListRescoreExecutionPlansResponse;
import software.amazon.awssdk.services.kendraranking.model.ListTagsForResourceRequest;
import software.amazon.awssdk.services.kendraranking.model.ListTagsForResourceResponse;
import software.amazon.awssdk.services.kendraranking.model.RescoreRequest;
import software.amazon.awssdk.services.kendraranking.model.RescoreResponse;
import software.amazon.awssdk.services.kendraranking.model.ResourceNotFoundException;
import software.amazon.awssdk.services.kendraranking.model.ResourceUnavailableException;
import software.amazon.awssdk.services.kendraranking.model.ServiceQuotaExceededException;
import software.amazon.awssdk.services.kendraranking.model.TagResourceRequest;
import software.amazon.awssdk.services.kendraranking.model.TagResourceResponse;
import software.amazon.awssdk.services.kendraranking.model.ThrottlingException;
import software.amazon.awssdk.services.kendraranking.model.UntagResourceRequest;
import software.amazon.awssdk.services.kendraranking.model.UntagResourceResponse;
import software.amazon.awssdk.services.kendraranking.model.UpdateRescoreExecutionPlanRequest;
import software.amazon.awssdk.services.kendraranking.model.UpdateRescoreExecutionPlanResponse;
import software.amazon.awssdk.services.kendraranking.model.ValidationException;
import software.amazon.awssdk.services.kendraranking.transform.CreateRescoreExecutionPlanRequestMarshaller;
import software.amazon.awssdk.services.kendraranking.transform.DeleteRescoreExecutionPlanRequestMarshaller;
import software.amazon.awssdk.services.kendraranking.transform.DescribeRescoreExecutionPlanRequestMarshaller;
import software.amazon.awssdk.services.kendraranking.transform.ListRescoreExecutionPlansRequestMarshaller;
import software.amazon.awssdk.services.kendraranking.transform.ListTagsForResourceRequestMarshaller;
import software.amazon.awssdk.services.kendraranking.transform.RescoreRequestMarshaller;
import software.amazon.awssdk.services.kendraranking.transform.TagResourceRequestMarshaller;
import software.amazon.awssdk.services.kendraranking.transform.UntagResourceRequestMarshaller;
import software.amazon.awssdk.services.kendraranking.transform.UpdateRescoreExecutionPlanRequestMarshaller;
import software.amazon.awssdk.utils.CompletableFutureUtils;

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

    /**
     * 

* Creates a rescore execution plan. A rescore execution plan is an Amazon Kendra Intelligent Ranking resource used * for provisioning the Rescore API. You set the number of capacity units that you require for Amazon * Kendra Intelligent Ranking to rescore or re-rank a search service's results. *

*

* For an example of using the CreateRescoreExecutionPlan API, including using the Python and Java * SDKs, see Semantically ranking * a search service's results. *

* * @param createRescoreExecutionPlanRequest * @return A Java Future containing the result of the CreateRescoreExecutionPlan 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. *
    *
  • AccessDeniedException You don’t have sufficient access to perform this action. Please ensure you have * the required permission policies and user accounts and try again.
  • *
  • ConflictException A conflict occurred with the request. Please fix any inconsistencies with your * resources and try again.
  • *
  • ServiceQuotaExceededException You have exceeded the set limits for your Amazon Kendra Intelligent * Ranking service. Please see Quotas * for more information, or contact Support to inquire about * an increase of limits.
  • *
  • ThrottlingException The request was denied due to request throttling. Please reduce the number of * requests and try again.
  • *
  • ValidationException The input fails to satisfy the constraints set by the Amazon Kendra Intelligent * Ranking service. Please provide the correct input and try again.
  • *
  • InternalServerException An issue occurred with the internal server used for your Amazon Kendra * Intelligent Ranking service. Please wait a few minutes and try again, or contact Support for help.
  • *
  • 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.
  • *
  • KendraRankingException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample KendraRankingAsyncClient.CreateRescoreExecutionPlan * @see AWS API Documentation */ @Override public CompletableFuture createRescoreExecutionPlan( CreateRescoreExecutionPlanRequest createRescoreExecutionPlanRequest) { SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createRescoreExecutionPlanRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, createRescoreExecutionPlanRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Kendra Ranking"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateRescoreExecutionPlan"); JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, CreateRescoreExecutionPlanResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("CreateRescoreExecutionPlan").withProtocolMetadata(protocolMetadata) .withMarshaller(new CreateRescoreExecutionPlanRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) .withInput(createRescoreExecutionPlanRequest)); 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); } } /** *

* Deletes a rescore execution plan. A rescore execution plan is an Amazon Kendra Intelligent Ranking resource used * for provisioning the Rescore API. *

* * @param deleteRescoreExecutionPlanRequest * @return A Java Future containing the result of the DeleteRescoreExecutionPlan 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. *
    *
  • AccessDeniedException You don’t have sufficient access to perform this action. Please ensure you have * the required permission policies and user accounts and try again.
  • *
  • ValidationException The input fails to satisfy the constraints set by the Amazon Kendra Intelligent * Ranking service. Please provide the correct input and try again.
  • *
  • ConflictException A conflict occurred with the request. Please fix any inconsistencies with your * resources and try again.
  • *
  • ResourceNotFoundException The resource you want to use doesn't exist. Please check you have provided * the correct resource and try again.
  • *
  • ThrottlingException The request was denied due to request throttling. Please reduce the number of * requests and try again.
  • *
  • InternalServerException An issue occurred with the internal server used for your Amazon Kendra * Intelligent Ranking service. Please wait a few minutes and try again, or contact Support for help.
  • *
  • 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.
  • *
  • KendraRankingException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample KendraRankingAsyncClient.DeleteRescoreExecutionPlan * @see AWS API Documentation */ @Override public CompletableFuture deleteRescoreExecutionPlan( DeleteRescoreExecutionPlanRequest deleteRescoreExecutionPlanRequest) { SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(deleteRescoreExecutionPlanRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, deleteRescoreExecutionPlanRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Kendra Ranking"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DeleteRescoreExecutionPlan"); JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, DeleteRescoreExecutionPlanResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("DeleteRescoreExecutionPlan").withProtocolMetadata(protocolMetadata) .withMarshaller(new DeleteRescoreExecutionPlanRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) .withInput(deleteRescoreExecutionPlanRequest)); 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); } } /** *

* Gets information about a rescore execution plan. A rescore execution plan is an Amazon Kendra Intelligent Ranking * resource used for provisioning the Rescore API. *

* * @param describeRescoreExecutionPlanRequest * @return A Java Future containing the result of the DescribeRescoreExecutionPlan 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 set by the Amazon Kendra Intelligent * Ranking service. Please provide the correct input and try again.
  • *
  • ResourceNotFoundException The resource you want to use doesn't exist. Please check you have provided * the correct resource and try again.
  • *
  • ThrottlingException The request was denied due to request throttling. Please reduce the number of * requests and try again.
  • *
  • AccessDeniedException You don’t have sufficient access to perform this action. Please ensure you have * the required permission policies and user accounts and try again.
  • *
  • InternalServerException An issue occurred with the internal server used for your Amazon Kendra * Intelligent Ranking service. Please wait a few minutes and try again, or contact Support for help.
  • *
  • 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.
  • *
  • KendraRankingException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample KendraRankingAsyncClient.DescribeRescoreExecutionPlan * @see AWS API Documentation */ @Override public CompletableFuture describeRescoreExecutionPlan( DescribeRescoreExecutionPlanRequest describeRescoreExecutionPlanRequest) { SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(describeRescoreExecutionPlanRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, describeRescoreExecutionPlanRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Kendra Ranking"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeRescoreExecutionPlan"); JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, DescribeRescoreExecutionPlanResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("DescribeRescoreExecutionPlan").withProtocolMetadata(protocolMetadata) .withMarshaller(new DescribeRescoreExecutionPlanRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) .withInput(describeRescoreExecutionPlanRequest)); 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); } } /** *

* Lists your rescore execution plans. A rescore execution plan is an Amazon Kendra Intelligent Ranking resource * used for provisioning the Rescore API. *

* * @param listRescoreExecutionPlansRequest * @return A Java Future containing the result of the ListRescoreExecutionPlans 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 set by the Amazon Kendra Intelligent * Ranking service. Please provide the correct input and try again.
  • *
  • AccessDeniedException You don’t have sufficient access to perform this action. Please ensure you have * the required permission policies and user accounts and try again.
  • *
  • ThrottlingException The request was denied due to request throttling. Please reduce the number of * requests and try again.
  • *
  • InternalServerException An issue occurred with the internal server used for your Amazon Kendra * Intelligent Ranking service. Please wait a few minutes and try again, or contact Support for help.
  • *
  • 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.
  • *
  • KendraRankingException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample KendraRankingAsyncClient.ListRescoreExecutionPlans * @see AWS API Documentation */ @Override public CompletableFuture listRescoreExecutionPlans( ListRescoreExecutionPlansRequest listRescoreExecutionPlansRequest) { SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listRescoreExecutionPlansRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, listRescoreExecutionPlansRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Kendra Ranking"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListRescoreExecutionPlans"); JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, ListRescoreExecutionPlansResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("ListRescoreExecutionPlans").withProtocolMetadata(protocolMetadata) .withMarshaller(new ListRescoreExecutionPlansRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) .withInput(listRescoreExecutionPlansRequest)); 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); } } /** *

* Gets a list of tags associated with a specified resource. A rescore execution plan is an example of a resource * that can have tags associated with it. *

* * @param listTagsForResourceRequest * The request information for listing tags associated with a rescore execution plan. A rescore execution * plan is an Amazon Kendra Intelligent Ranking resource used for provisioning the Rescore API. * @return A Java Future containing the result of the ListTagsForResource 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 set by the Amazon Kendra Intelligent * Ranking service. Please provide the correct input and try again.
  • *
  • ResourceUnavailableException The resource you want to use is unavailable. Please check you have * provided the correct resource information and try again.
  • *
  • ThrottlingException The request was denied due to request throttling. Please reduce the number of * requests and try again.
  • *
  • AccessDeniedException You don’t have sufficient access to perform this action. Please ensure you have * the required permission policies and user accounts and try again.
  • *
  • InternalServerException An issue occurred with the internal server used for your Amazon Kendra * Intelligent Ranking service. Please wait a few minutes and try again, or contact Support for help.
  • *
  • 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.
  • *
  • KendraRankingException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample KendraRankingAsyncClient.ListTagsForResource * @see AWS API Documentation */ @Override public CompletableFuture listTagsForResource( ListTagsForResourceRequest listTagsForResourceRequest) { SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listTagsForResourceRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, listTagsForResourceRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Kendra Ranking"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListTagsForResource"); JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, ListTagsForResourceResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("ListTagsForResource").withProtocolMetadata(protocolMetadata) .withMarshaller(new ListTagsForResourceRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) .withInput(listTagsForResourceRequest)); 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); } } /** *

* Rescores or re-ranks search results from a search service such as OpenSearch (self managed). You use the semantic * search capabilities of Amazon Kendra Intelligent Ranking to improve the search service's results. *

* * @param rescoreRequest * @return A Java Future containing the result of the Rescore 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 set by the Amazon Kendra Intelligent * Ranking service. Please provide the correct input and try again.
  • *
  • ConflictException A conflict occurred with the request. Please fix any inconsistencies with your * resources and try again.
  • *
  • AccessDeniedException You don’t have sufficient access to perform this action. Please ensure you have * the required permission policies and user accounts and try again.
  • *
  • ResourceNotFoundException The resource you want to use doesn't exist. Please check you have provided * the correct resource and try again.
  • *
  • ThrottlingException The request was denied due to request throttling. Please reduce the number of * requests and try again.
  • *
  • InternalServerException An issue occurred with the internal server used for your Amazon Kendra * Intelligent Ranking service. Please wait a few minutes and try again, or contact Support for help.
  • *
  • 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.
  • *
  • KendraRankingException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample KendraRankingAsyncClient.Rescore * @see AWS API * Documentation */ @Override public CompletableFuture rescore(RescoreRequest rescoreRequest) { SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(rescoreRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, rescoreRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Kendra Ranking"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "Rescore"); JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, RescoreResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams().withOperationName("Rescore") .withProtocolMetadata(protocolMetadata).withMarshaller(new RescoreRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) .withInput(rescoreRequest)); 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); } } /** *

* Adds a specified tag to a specified rescore execution plan. A rescore execution plan is an Amazon Kendra * Intelligent Ranking resource used for provisioning the Rescore API. If the tag already exists, the * existing value is replaced with the new value. *

* * @param tagResourceRequest * The request information for tagging a rescore execution plan. A rescore execution plan is an Amazon Kendra * Intelligent Ranking resource used for provisioning the Rescore API. * @return A Java Future containing the result of the TagResource 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 set by the Amazon Kendra Intelligent * Ranking service. Please provide the correct input and try again.
  • *
  • ResourceUnavailableException The resource you want to use is unavailable. Please check you have * provided the correct resource information and try again.
  • *
  • ThrottlingException The request was denied due to request throttling. Please reduce the number of * requests and try again.
  • *
  • AccessDeniedException You don’t have sufficient access to perform this action. Please ensure you have * the required permission policies and user accounts and try again.
  • *
  • InternalServerException An issue occurred with the internal server used for your Amazon Kendra * Intelligent Ranking service. Please wait a few minutes and try again, or contact Support for help.
  • *
  • 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.
  • *
  • KendraRankingException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample KendraRankingAsyncClient.TagResource * @see AWS * API Documentation */ @Override public CompletableFuture tagResource(TagResourceRequest tagResourceRequest) { SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(tagResourceRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, tagResourceRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Kendra Ranking"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TagResource"); JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, TagResourceResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("TagResource").withProtocolMetadata(protocolMetadata) .withMarshaller(new TagResourceRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) .withInput(tagResourceRequest)); 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); } } /** *

* Removes a tag from a rescore execution plan. A rescore execution plan is an Amazon Kendra Intelligent Ranking * resource used for provisioning the Rescore operation. *

* * @param untagResourceRequest * The request information to remove a tag from a rescore execution plan. A rescore execution plan is an * Amazon Kendra Intelligent Ranking resource used for provisioning the Rescore API. * @return A Java Future containing the result of the UntagResource 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 set by the Amazon Kendra Intelligent * Ranking service. Please provide the correct input and try again.
  • *
  • ResourceUnavailableException The resource you want to use is unavailable. Please check you have * provided the correct resource information and try again.
  • *
  • ThrottlingException The request was denied due to request throttling. Please reduce the number of * requests and try again.
  • *
  • AccessDeniedException You don’t have sufficient access to perform this action. Please ensure you have * the required permission policies and user accounts and try again.
  • *
  • InternalServerException An issue occurred with the internal server used for your Amazon Kendra * Intelligent Ranking service. Please wait a few minutes and try again, or contact Support for help.
  • *
  • 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.
  • *
  • KendraRankingException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample KendraRankingAsyncClient.UntagResource * @see AWS * API Documentation */ @Override public CompletableFuture untagResource(UntagResourceRequest untagResourceRequest) { SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(untagResourceRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, untagResourceRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Kendra Ranking"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UntagResource"); JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, UntagResourceResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("UntagResource").withProtocolMetadata(protocolMetadata) .withMarshaller(new UntagResourceRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) .withInput(untagResourceRequest)); 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); } } /** *

* Updates a rescore execution plan. A rescore execution plan is an Amazon Kendra Intelligent Ranking resource used * for provisioning the Rescore API. You can update the number of capacity units you require for Amazon * Kendra Intelligent Ranking to rescore or re-rank a search service's results. *

* * @param updateRescoreExecutionPlanRequest * @return A Java Future containing the result of the UpdateRescoreExecutionPlan 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 set by the Amazon Kendra Intelligent * Ranking service. Please provide the correct input and try again.
  • *
  • ResourceNotFoundException The resource you want to use doesn't exist. Please check you have provided * the correct resource and try again.
  • *
  • ThrottlingException The request was denied due to request throttling. Please reduce the number of * requests and try again.
  • *
  • AccessDeniedException You don’t have sufficient access to perform this action. Please ensure you have * the required permission policies and user accounts and try again.
  • *
  • ServiceQuotaExceededException You have exceeded the set limits for your Amazon Kendra Intelligent * Ranking service. Please see Quotas * for more information, or contact Support to inquire about * an increase of limits.
  • *
  • ConflictException A conflict occurred with the request. Please fix any inconsistencies with your * resources and try again.
  • *
  • InternalServerException An issue occurred with the internal server used for your Amazon Kendra * Intelligent Ranking service. Please wait a few minutes and try again, or contact Support for help.
  • *
  • 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.
  • *
  • KendraRankingException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.
  • *
* @sample KendraRankingAsyncClient.UpdateRescoreExecutionPlan * @see AWS API Documentation */ @Override public CompletableFuture updateRescoreExecutionPlan( UpdateRescoreExecutionPlanRequest updateRescoreExecutionPlanRequest) { SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(updateRescoreExecutionPlanRequest, this.clientConfiguration); List metricPublishers = resolveMetricPublishers(clientConfiguration, updateRescoreExecutionPlanRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Kendra Ranking"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UpdateRescoreExecutionPlan"); JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, UpdateRescoreExecutionPlanResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); CompletableFuture executeFuture = clientHandler .execute(new ClientExecutionParams() .withOperationName("UpdateRescoreExecutionPlan").withProtocolMetadata(protocolMetadata) .withMarshaller(new UpdateRescoreExecutionPlanRequestMarshaller(protocolFactory)) .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler) .withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector) .withInput(updateRescoreExecutionPlanRequest)); 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 KendraRankingServiceClientConfiguration serviceClientConfiguration() { return new KendraRankingServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build(); } @Override public final String serviceName() { return SERVICE_NAME; } private > T init(T builder) { return builder .clientConfiguration(clientConfiguration) .defaultServiceExceptionSupplier(KendraRankingException::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("ConflictException") .exceptionBuilderSupplier(ConflictException::builder).httpStatusCode(400).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("ServiceQuotaExceededException") .exceptionBuilderSupplier(ServiceQuotaExceededException::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("ResourceUnavailableException") .exceptionBuilderSupplier(ResourceUnavailableException::builder).httpStatusCode(400).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(); } KendraRankingServiceClientConfigurationBuilder serviceConfigBuilder = new KendraRankingServiceClientConfigurationBuilder( 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(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy