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

com.amazonaws.services.braket.AWSBraketClient Maven / Gradle / Ivy

/*
 * Copyright 2015-2020 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 com.amazonaws.services.braket;

import org.w3c.dom.*;

import java.net.*;
import java.util.*;

import javax.annotation.Generated;

import org.apache.commons.logging.*;

import com.amazonaws.*;
import com.amazonaws.annotation.SdkInternalApi;
import com.amazonaws.auth.*;

import com.amazonaws.handlers.*;
import com.amazonaws.http.*;
import com.amazonaws.internal.*;
import com.amazonaws.internal.auth.*;
import com.amazonaws.metrics.*;
import com.amazonaws.regions.*;
import com.amazonaws.transform.*;
import com.amazonaws.util.*;
import com.amazonaws.protocol.json.*;
import com.amazonaws.util.AWSRequestMetrics.Field;
import com.amazonaws.annotation.ThreadSafe;
import com.amazonaws.client.AwsSyncClientParams;
import com.amazonaws.client.builder.AdvancedConfig;

import com.amazonaws.services.braket.AWSBraketClientBuilder;

import com.amazonaws.AmazonServiceException;

import com.amazonaws.services.braket.model.*;
import com.amazonaws.services.braket.model.transform.*;

/**
 * Client for accessing Braket. All service calls made using this client are blocking, and will not return until the
 * service call completes.
 * 

*

* The Amazon Braket API Reference provides information about the operations and structures supported in Amazon Braket. *

*/ @ThreadSafe @Generated("com.amazonaws:aws-java-sdk-code-generator") public class AWSBraketClient extends AmazonWebServiceClient implements AWSBraket { /** Provider for AWS credentials. */ private final AWSCredentialsProvider awsCredentialsProvider; private static final Log log = LogFactory.getLog(AWSBraket.class); /** Default signing name for the service. */ private static final String DEFAULT_SIGNING_NAME = "braket"; /** Client configuration factory providing ClientConfigurations tailored to this client */ protected static final ClientConfigurationFactory configFactory = new ClientConfigurationFactory(); private final AdvancedConfig advancedConfig; private static final com.amazonaws.protocol.json.SdkJsonProtocolFactory protocolFactory = new com.amazonaws.protocol.json.SdkJsonProtocolFactory( new JsonClientMetadata() .withProtocolVersion("1.1") .withSupportsCbor(false) .withSupportsIon(false) .withContentTypeOverride("") .addErrorMetadata( new JsonErrorShapeMetadata().withErrorCode("AccessDeniedException").withExceptionUnmarshaller( com.amazonaws.services.braket.model.transform.AccessDeniedExceptionUnmarshaller.getInstance())) .addErrorMetadata( new JsonErrorShapeMetadata().withErrorCode("ValidationException").withExceptionUnmarshaller( com.amazonaws.services.braket.model.transform.ValidationExceptionUnmarshaller.getInstance())) .addErrorMetadata( new JsonErrorShapeMetadata().withErrorCode("ConflictException").withExceptionUnmarshaller( com.amazonaws.services.braket.model.transform.ConflictExceptionUnmarshaller.getInstance())) .addErrorMetadata( new JsonErrorShapeMetadata().withErrorCode("ResourceNotFoundException").withExceptionUnmarshaller( com.amazonaws.services.braket.model.transform.ResourceNotFoundExceptionUnmarshaller.getInstance())) .addErrorMetadata( new JsonErrorShapeMetadata().withErrorCode("ServiceQuotaExceededException").withExceptionUnmarshaller( com.amazonaws.services.braket.model.transform.ServiceQuotaExceededExceptionUnmarshaller.getInstance())) .addErrorMetadata( new JsonErrorShapeMetadata().withErrorCode("InternalServiceException").withExceptionUnmarshaller( com.amazonaws.services.braket.model.transform.InternalServiceExceptionUnmarshaller.getInstance())) .addErrorMetadata( new JsonErrorShapeMetadata().withErrorCode("DeviceOfflineException").withExceptionUnmarshaller( com.amazonaws.services.braket.model.transform.DeviceOfflineExceptionUnmarshaller.getInstance())) .addErrorMetadata( new JsonErrorShapeMetadata().withErrorCode("ThrottlingException").withExceptionUnmarshaller( com.amazonaws.services.braket.model.transform.ThrottlingExceptionUnmarshaller.getInstance())) .withBaseServiceExceptionClass(com.amazonaws.services.braket.model.AWSBraketException.class)); public static AWSBraketClientBuilder builder() { return AWSBraketClientBuilder.standard(); } /** * Constructs a new client to invoke service methods on Braket using the specified parameters. * *

* All service calls made using this new client object are blocking, and will not return until the service call * completes. * * @param clientParams * Object providing client parameters. */ AWSBraketClient(AwsSyncClientParams clientParams) { this(clientParams, false); } /** * Constructs a new client to invoke service methods on Braket using the specified parameters. * *

* All service calls made using this new client object are blocking, and will not return until the service call * completes. * * @param clientParams * Object providing client parameters. */ AWSBraketClient(AwsSyncClientParams clientParams, boolean endpointDiscoveryEnabled) { super(clientParams); this.awsCredentialsProvider = clientParams.getCredentialsProvider(); this.advancedConfig = clientParams.getAdvancedConfig(); init(); } private void init() { setServiceNameIntern(DEFAULT_SIGNING_NAME); setEndpointPrefix(ENDPOINT_PREFIX); // calling this.setEndPoint(...) will also modify the signer accordingly setEndpoint("braket.us-east-1.amazonaws.com"); HandlerChainFactory chainFactory = new HandlerChainFactory(); requestHandler2s.addAll(chainFactory.newRequestHandlerChain("/com/amazonaws/services/braket/request.handlers")); requestHandler2s.addAll(chainFactory.newRequestHandler2Chain("/com/amazonaws/services/braket/request.handler2s")); requestHandler2s.addAll(chainFactory.getGlobalHandlers()); } /** *

* Cancels the specified task. *

* * @param cancelQuantumTaskRequest * @return Result of the CancelQuantumTask operation returned by the service. * @throws ResourceNotFoundException * The specified resource was not found. * @throws AccessDeniedException * You do not have sufficient access to perform this action. * @throws ConflictException * An error occurred due to a conflict. * @throws ThrottlingException * The throttling rate limit is met. * @throws InternalServiceException * The request processing has failed because of an unknown error, exception or failure. * @throws ValidationException * The input fails to satisfy the constraints specified by an AWS service. * @sample AWSBraket.CancelQuantumTask * @see AWS API * Documentation */ @Override public CancelQuantumTaskResult cancelQuantumTask(CancelQuantumTaskRequest request) { request = beforeClientExecution(request); return executeCancelQuantumTask(request); } @SdkInternalApi final CancelQuantumTaskResult executeCancelQuantumTask(CancelQuantumTaskRequest cancelQuantumTaskRequest) { ExecutionContext executionContext = createExecutionContext(cancelQuantumTaskRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); Request request = null; Response response = null; try { awsRequestMetrics.startEvent(Field.RequestMarshallTime); try { request = new CancelQuantumTaskRequestProtocolMarshaller(protocolFactory).marshall(super.beforeMarshalling(cancelQuantumTaskRequest)); // Binds the request metrics to the current request. request.setAWSRequestMetrics(awsRequestMetrics); request.addHandlerContext(HandlerContextKey.SIGNING_REGION, getSigningRegion()); request.addHandlerContext(HandlerContextKey.SERVICE_ID, "Braket"); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "CancelQuantumTask"); request.addHandlerContext(HandlerContextKey.ADVANCED_CONFIG, advancedConfig); } finally { awsRequestMetrics.endEvent(Field.RequestMarshallTime); } HttpResponseHandler> responseHandler = protocolFactory.createResponseHandler( new JsonOperationMetadata().withPayloadJson(true).withHasStreamingSuccessResponse(false), new CancelQuantumTaskResultJsonUnmarshaller()); response = invoke(request, responseHandler, executionContext); return response.getAwsResponse(); } finally { endClientExecution(awsRequestMetrics, request, response); } } /** *

* Creates a quantum task. *

* * @param createQuantumTaskRequest * @return Result of the CreateQuantumTask operation returned by the service. * @throws AccessDeniedException * You do not have sufficient access to perform this action. * @throws ThrottlingException * The throttling rate limit is met. * @throws DeviceOfflineException * The specified device is currently offline. * @throws InternalServiceException * The request processing has failed because of an unknown error, exception or failure. * @throws ServiceQuotaExceededException * The request failed because a service quota is met. * @throws ValidationException * The input fails to satisfy the constraints specified by an AWS service. * @sample AWSBraket.CreateQuantumTask * @see AWS API * Documentation */ @Override public CreateQuantumTaskResult createQuantumTask(CreateQuantumTaskRequest request) { request = beforeClientExecution(request); return executeCreateQuantumTask(request); } @SdkInternalApi final CreateQuantumTaskResult executeCreateQuantumTask(CreateQuantumTaskRequest createQuantumTaskRequest) { ExecutionContext executionContext = createExecutionContext(createQuantumTaskRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); Request request = null; Response response = null; try { awsRequestMetrics.startEvent(Field.RequestMarshallTime); try { request = new CreateQuantumTaskRequestProtocolMarshaller(protocolFactory).marshall(super.beforeMarshalling(createQuantumTaskRequest)); // Binds the request metrics to the current request. request.setAWSRequestMetrics(awsRequestMetrics); request.addHandlerContext(HandlerContextKey.SIGNING_REGION, getSigningRegion()); request.addHandlerContext(HandlerContextKey.SERVICE_ID, "Braket"); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "CreateQuantumTask"); request.addHandlerContext(HandlerContextKey.ADVANCED_CONFIG, advancedConfig); } finally { awsRequestMetrics.endEvent(Field.RequestMarshallTime); } HttpResponseHandler> responseHandler = protocolFactory.createResponseHandler( new JsonOperationMetadata().withPayloadJson(true).withHasStreamingSuccessResponse(false), new CreateQuantumTaskResultJsonUnmarshaller()); response = invoke(request, responseHandler, executionContext); return response.getAwsResponse(); } finally { endClientExecution(awsRequestMetrics, request, response); } } /** *

* Retrieves the devices available in Amazon Braket. *

* * @param getDeviceRequest * @return Result of the GetDevice operation returned by the service. * @throws ResourceNotFoundException * The specified resource was not found. * @throws AccessDeniedException * You do not have sufficient access to perform this action. * @throws ThrottlingException * The throttling rate limit is met. * @throws InternalServiceException * The request processing has failed because of an unknown error, exception or failure. * @throws ValidationException * The input fails to satisfy the constraints specified by an AWS service. * @sample AWSBraket.GetDevice * @see AWS API * Documentation */ @Override public GetDeviceResult getDevice(GetDeviceRequest request) { request = beforeClientExecution(request); return executeGetDevice(request); } @SdkInternalApi final GetDeviceResult executeGetDevice(GetDeviceRequest getDeviceRequest) { ExecutionContext executionContext = createExecutionContext(getDeviceRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); Request request = null; Response response = null; try { awsRequestMetrics.startEvent(Field.RequestMarshallTime); try { request = new GetDeviceRequestProtocolMarshaller(protocolFactory).marshall(super.beforeMarshalling(getDeviceRequest)); // Binds the request metrics to the current request. request.setAWSRequestMetrics(awsRequestMetrics); request.addHandlerContext(HandlerContextKey.SIGNING_REGION, getSigningRegion()); request.addHandlerContext(HandlerContextKey.SERVICE_ID, "Braket"); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "GetDevice"); request.addHandlerContext(HandlerContextKey.ADVANCED_CONFIG, advancedConfig); } finally { awsRequestMetrics.endEvent(Field.RequestMarshallTime); } HttpResponseHandler> responseHandler = protocolFactory.createResponseHandler(new JsonOperationMetadata() .withPayloadJson(true).withHasStreamingSuccessResponse(false), new GetDeviceResultJsonUnmarshaller()); response = invoke(request, responseHandler, executionContext); return response.getAwsResponse(); } finally { endClientExecution(awsRequestMetrics, request, response); } } /** *

* Retrieves the specified quantum task. *

* * @param getQuantumTaskRequest * @return Result of the GetQuantumTask operation returned by the service. * @throws ResourceNotFoundException * The specified resource was not found. * @throws AccessDeniedException * You do not have sufficient access to perform this action. * @throws ThrottlingException * The throttling rate limit is met. * @throws InternalServiceException * The request processing has failed because of an unknown error, exception or failure. * @throws ValidationException * The input fails to satisfy the constraints specified by an AWS service. * @sample AWSBraket.GetQuantumTask * @see AWS API * Documentation */ @Override public GetQuantumTaskResult getQuantumTask(GetQuantumTaskRequest request) { request = beforeClientExecution(request); return executeGetQuantumTask(request); } @SdkInternalApi final GetQuantumTaskResult executeGetQuantumTask(GetQuantumTaskRequest getQuantumTaskRequest) { ExecutionContext executionContext = createExecutionContext(getQuantumTaskRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); Request request = null; Response response = null; try { awsRequestMetrics.startEvent(Field.RequestMarshallTime); try { request = new GetQuantumTaskRequestProtocolMarshaller(protocolFactory).marshall(super.beforeMarshalling(getQuantumTaskRequest)); // Binds the request metrics to the current request. request.setAWSRequestMetrics(awsRequestMetrics); request.addHandlerContext(HandlerContextKey.SIGNING_REGION, getSigningRegion()); request.addHandlerContext(HandlerContextKey.SERVICE_ID, "Braket"); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "GetQuantumTask"); request.addHandlerContext(HandlerContextKey.ADVANCED_CONFIG, advancedConfig); } finally { awsRequestMetrics.endEvent(Field.RequestMarshallTime); } HttpResponseHandler> responseHandler = protocolFactory.createResponseHandler( new JsonOperationMetadata().withPayloadJson(true).withHasStreamingSuccessResponse(false), new GetQuantumTaskResultJsonUnmarshaller()); response = invoke(request, responseHandler, executionContext); return response.getAwsResponse(); } finally { endClientExecution(awsRequestMetrics, request, response); } } /** *

* Searches for devices using the specified filters. *

* * @param searchDevicesRequest * @return Result of the SearchDevices operation returned by the service. * @throws AccessDeniedException * You do not have sufficient access to perform this action. * @throws ThrottlingException * The throttling rate limit is met. * @throws InternalServiceException * The request processing has failed because of an unknown error, exception or failure. * @throws ValidationException * The input fails to satisfy the constraints specified by an AWS service. * @sample AWSBraket.SearchDevices * @see AWS API * Documentation */ @Override public SearchDevicesResult searchDevices(SearchDevicesRequest request) { request = beforeClientExecution(request); return executeSearchDevices(request); } @SdkInternalApi final SearchDevicesResult executeSearchDevices(SearchDevicesRequest searchDevicesRequest) { ExecutionContext executionContext = createExecutionContext(searchDevicesRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); Request request = null; Response response = null; try { awsRequestMetrics.startEvent(Field.RequestMarshallTime); try { request = new SearchDevicesRequestProtocolMarshaller(protocolFactory).marshall(super.beforeMarshalling(searchDevicesRequest)); // Binds the request metrics to the current request. request.setAWSRequestMetrics(awsRequestMetrics); request.addHandlerContext(HandlerContextKey.SIGNING_REGION, getSigningRegion()); request.addHandlerContext(HandlerContextKey.SERVICE_ID, "Braket"); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "SearchDevices"); request.addHandlerContext(HandlerContextKey.ADVANCED_CONFIG, advancedConfig); } finally { awsRequestMetrics.endEvent(Field.RequestMarshallTime); } HttpResponseHandler> responseHandler = protocolFactory.createResponseHandler( new JsonOperationMetadata().withPayloadJson(true).withHasStreamingSuccessResponse(false), new SearchDevicesResultJsonUnmarshaller()); response = invoke(request, responseHandler, executionContext); return response.getAwsResponse(); } finally { endClientExecution(awsRequestMetrics, request, response); } } /** *

* Searches for tasks that match the specified filter values. *

* * @param searchQuantumTasksRequest * @return Result of the SearchQuantumTasks operation returned by the service. * @throws AccessDeniedException * You do not have sufficient access to perform this action. * @throws ThrottlingException * The throttling rate limit is met. * @throws InternalServiceException * The request processing has failed because of an unknown error, exception or failure. * @throws ValidationException * The input fails to satisfy the constraints specified by an AWS service. * @sample AWSBraket.SearchQuantumTasks * @see AWS API * Documentation */ @Override public SearchQuantumTasksResult searchQuantumTasks(SearchQuantumTasksRequest request) { request = beforeClientExecution(request); return executeSearchQuantumTasks(request); } @SdkInternalApi final SearchQuantumTasksResult executeSearchQuantumTasks(SearchQuantumTasksRequest searchQuantumTasksRequest) { ExecutionContext executionContext = createExecutionContext(searchQuantumTasksRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); Request request = null; Response response = null; try { awsRequestMetrics.startEvent(Field.RequestMarshallTime); try { request = new SearchQuantumTasksRequestProtocolMarshaller(protocolFactory).marshall(super.beforeMarshalling(searchQuantumTasksRequest)); // Binds the request metrics to the current request. request.setAWSRequestMetrics(awsRequestMetrics); request.addHandlerContext(HandlerContextKey.SIGNING_REGION, getSigningRegion()); request.addHandlerContext(HandlerContextKey.SERVICE_ID, "Braket"); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "SearchQuantumTasks"); request.addHandlerContext(HandlerContextKey.ADVANCED_CONFIG, advancedConfig); } finally { awsRequestMetrics.endEvent(Field.RequestMarshallTime); } HttpResponseHandler> responseHandler = protocolFactory.createResponseHandler( new JsonOperationMetadata().withPayloadJson(true).withHasStreamingSuccessResponse(false), new SearchQuantumTasksResultJsonUnmarshaller()); response = invoke(request, responseHandler, executionContext); return response.getAwsResponse(); } finally { endClientExecution(awsRequestMetrics, request, response); } } /** * Returns additional metadata for a previously executed successful, request, typically used for debugging issues * where a service isn't acting as expected. This data isn't considered part of the result data returned by an * operation, so it's available through this separate, diagnostic interface. *

* Response metadata is only cached for a limited period of time, so if you need to access this extra diagnostic * information for an executed request, you should use this method to retrieve it as soon as possible after * executing the request. * * @param request * The originally executed request * * @return The response metadata for the specified request, or null if none is available. */ public ResponseMetadata getCachedResponseMetadata(AmazonWebServiceRequest request) { return client.getResponseMetadataForRequest(request); } /** * Normal invoke with authentication. Credentials are required and may be overriden at the request level. **/ private Response invoke(Request request, HttpResponseHandler> responseHandler, ExecutionContext executionContext) { return invoke(request, responseHandler, executionContext, null, null); } /** * Normal invoke with authentication. Credentials are required and may be overriden at the request level. **/ private Response invoke(Request request, HttpResponseHandler> responseHandler, ExecutionContext executionContext, URI cachedEndpoint, URI uriFromEndpointTrait) { executionContext.setCredentialsProvider(CredentialUtils.getCredentialsProvider(request.getOriginalRequest(), awsCredentialsProvider)); return doInvoke(request, responseHandler, executionContext, cachedEndpoint, uriFromEndpointTrait); } /** * Invoke with no authentication. Credentials are not required and any credentials set on the client or request will * be ignored for this operation. **/ private Response anonymousInvoke(Request request, HttpResponseHandler> responseHandler, ExecutionContext executionContext) { return doInvoke(request, responseHandler, executionContext, null, null); } /** * Invoke the request using the http client. Assumes credentials (or lack thereof) have been configured in the * ExecutionContext beforehand. **/ private Response doInvoke(Request request, HttpResponseHandler> responseHandler, ExecutionContext executionContext, URI discoveredEndpoint, URI uriFromEndpointTrait) { if (discoveredEndpoint != null) { request.setEndpoint(discoveredEndpoint); request.getOriginalRequest().getRequestClientOptions().appendUserAgent("endpoint-discovery"); } else if (uriFromEndpointTrait != null) { request.setEndpoint(uriFromEndpointTrait); } else { request.setEndpoint(endpoint); } request.setTimeOffset(timeOffset); HttpResponseHandler errorResponseHandler = protocolFactory.createErrorResponseHandler(new JsonErrorResponseMetadata()); return client.execute(request, responseHandler, errorResponseHandler, executionContext); } @com.amazonaws.annotation.SdkInternalApi static com.amazonaws.protocol.json.SdkJsonProtocolFactory getProtocolFactory() { return protocolFactory; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy