Search in sources :

Example 21 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class DefaultJsonAsyncClient method eventStreamOperationWithOnlyInput.

/**
 * Invokes the EventStreamOperationWithOnlyInput operation asynchronously.
 *
 * @param eventStreamOperationWithOnlyInputRequest
 * @return A Java Future containing the result of the EventStreamOperationWithOnlyInput operation returned by the
 *         service.<br/>
 *         The CompletableFuture returned by this method can be completed exceptionally with the following
 *         exceptions.
 *         <ul>
 *         <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
 *         Can be used for catch all scenarios.</li>
 *         <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get
 *         credentials, etc.</li>
 *         <li>JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance
 *         of this type.</li>
 *         </ul>
 * @sample JsonAsyncClient.EventStreamOperationWithOnlyInput
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/EventStreamOperationWithOnlyInput"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public CompletableFuture<EventStreamOperationWithOnlyInputResponse> eventStreamOperationWithOnlyInput(EventStreamOperationWithOnlyInputRequest eventStreamOperationWithOnlyInputRequest, Publisher<InputEventStreamTwo> requestStream) {
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, eventStreamOperationWithOnlyInputRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "EventStreamOperationWithOnlyInput");
        eventStreamOperationWithOnlyInputRequest = applySignerOverride(eventStreamOperationWithOnlyInputRequest, EventStreamAws4Signer.create());
        JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
        HttpResponseHandler<EventStreamOperationWithOnlyInputResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, EventStreamOperationWithOnlyInputResponse::builder);
        HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
        EventStreamTaggedUnionJsonMarshaller eventMarshaller = EventStreamTaggedUnionJsonMarshaller.builder().putMarshaller(DefaultInputEventOne.class, new InputEventMarshaller(protocolFactory)).putMarshaller(DefaultInputEventTwo.class, new InputEventTwoMarshaller(protocolFactory)).build();
        SdkPublisher<InputEventStreamTwo> eventPublisher = SdkPublisher.adapt(requestStream);
        Publisher<ByteBuffer> adapted = eventPublisher.map(event -> eventMarshaller.marshall(event)).map(AwsClientHandlerUtils::encodeEventStreamRequestToByteBuffer);
        CompletableFuture<EventStreamOperationWithOnlyInputResponse> executeFuture = clientHandler.execute(new ClientExecutionParams<EventStreamOperationWithOnlyInputRequest, EventStreamOperationWithOnlyInputResponse>().withOperationName("EventStreamOperationWithOnlyInput").withMarshaller(new EventStreamOperationWithOnlyInputRequestMarshaller(protocolFactory)).withAsyncRequestBody(AsyncRequestBody.fromPublisher(adapted)).withInitialRequestEvent(true).withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withMetricCollector(apiCallMetricCollector).withInput(eventStreamOperationWithOnlyInputRequest));
        CompletableFuture<EventStreamOperationWithOnlyInputResponse> 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);
    }
}
Also used : ExceptionMetadata(software.amazon.awssdk.protocols.core.ExceptionMetadata) AwsAsyncClientHandler(software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler) StreamingInputOutputOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.StreamingInputOutputOperationRequestMarshaller) EventStreamOperationResponseHandler(software.amazon.awssdk.services.json.model.EventStreamOperationResponseHandler) AsyncStreamingRequestMarshaller(software.amazon.awssdk.core.runtime.transform.AsyncStreamingRequestMarshaller) AsyncResponseTransformer(software.amazon.awssdk.core.async.AsyncResponseTransformer) InputEventStreamTwo(software.amazon.awssdk.services.json.model.InputEventStreamTwo) StreamingInputOperationRequest(software.amazon.awssdk.services.json.model.StreamingInputOperationRequest) AsyncClientHandler(software.amazon.awssdk.core.client.handler.AsyncClientHandler) PaginatedOperationWithResultKeyResponse(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) PaginatedOperationWithResultKeyPublisher(software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyPublisher) EventStreamOperationWithOnlyInputRequestMarshaller(software.amazon.awssdk.services.json.transform.EventStreamOperationWithOnlyInputRequestMarshaller) APostOperationWithOutputResponse(software.amazon.awssdk.services.json.model.APostOperationWithOutputResponse) EventStream(software.amazon.awssdk.services.json.model.EventStream) APostOperationRequest(software.amazon.awssdk.services.json.model.APostOperationRequest) PaginatedOperationWithoutResultKeyPublisher(software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyPublisher) PaginatedOperationWithoutResultKeyResponse(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyResponse) AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) AsyncAws4Signer(software.amazon.awssdk.auth.signer.AsyncAws4Signer) SdkAdvancedAsyncClientOption(software.amazon.awssdk.core.client.config.SdkAdvancedAsyncClientOption) APostOperationWithOutputRequestMarshaller(software.amazon.awssdk.services.json.transform.APostOperationWithOutputRequestMarshaller) EventStreamOperationRequest(software.amazon.awssdk.services.json.model.EventStreamOperationRequest) HttpResponseHandler(software.amazon.awssdk.core.http.HttpResponseHandler) Generated(software.amazon.awssdk.annotations.Generated) AsyncResponseTransformerUtils(software.amazon.awssdk.core.async.AsyncResponseTransformerUtils) PaginatedOperationWithResultKeyRequestMarshaller(software.amazon.awssdk.services.json.transform.PaginatedOperationWithResultKeyRequestMarshaller) PaginatedOperationWithoutResultKeyRequestMarshaller(software.amazon.awssdk.services.json.transform.PaginatedOperationWithoutResultKeyRequestMarshaller) OperationWithChecksumRequiredResponse(software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredResponse) EventStreamTaggedUnionJsonMarshaller(software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionJsonMarshaller) VoidSdkResponse(software.amazon.awssdk.core.protocol.VoidSdkResponse) CompletableFutureUtils(software.amazon.awssdk.utils.CompletableFutureUtils) SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) VersionInfo(software.amazon.awssdk.core.util.VersionInfo) PaginatedOperationWithResultKeyRequest(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest) CoreMetric(software.amazon.awssdk.core.metrics.CoreMetric) BaseAwsJsonProtocolFactory(software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory) RequestOverrideConfiguration(software.amazon.awssdk.core.RequestOverrideConfiguration) EventStreamOperationWithOnlyOutputResponse(software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputResponse) StreamingOutputOperationRequest(software.amazon.awssdk.services.json.model.StreamingOutputOperationRequest) InputEventTwoMarshaller(software.amazon.awssdk.services.json.transform.InputEventTwoMarshaller) SdkInternalExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Executor(java.util.concurrent.Executor) Publisher(org.reactivestreams.Publisher) APostOperationWithOutputRequest(software.amazon.awssdk.services.json.model.APostOperationWithOutputRequest) EventStreamOperationWithOnlyInputResponse(software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyInputResponse) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) GetWithoutRequiredMembersResponse(software.amazon.awssdk.services.json.model.GetWithoutRequiredMembersResponse) DefaultInputEventTwo(software.amazon.awssdk.services.json.model.inputeventstreamtwo.DefaultInputEventTwo) GetWithoutRequiredMembersRequestMarshaller(software.amazon.awssdk.services.json.transform.GetWithoutRequiredMembersRequestMarshaller) LoggerFactory(org.slf4j.LoggerFactory) StreamingInputOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.StreamingInputOperationRequestMarshaller) ByteBuffer(java.nio.ByteBuffer) JsonException(software.amazon.awssdk.services.json.model.JsonException) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) DefaultInputEvent(software.amazon.awssdk.services.json.model.inputeventstream.DefaultInputEvent) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) EventStreamOperationWithOnlyInputRequest(software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyInputRequest) ApiName(software.amazon.awssdk.core.ApiName) GetWithoutRequiredMembersRequest(software.amazon.awssdk.services.json.model.GetWithoutRequiredMembersRequest) SdkClientOption(software.amazon.awssdk.core.client.config.SdkClientOption) HostnameValidator(software.amazon.awssdk.utils.HostnameValidator) StreamingOutputOperationResponse(software.amazon.awssdk.services.json.model.StreamingOutputOperationResponse) APostOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.APostOperationRequestMarshaller) StreamingInputOperationResponse(software.amazon.awssdk.services.json.model.StreamingInputOperationResponse) EventStreamOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.EventStreamOperationRequestMarshaller) DefaultInputEventOne(software.amazon.awssdk.services.json.model.inputeventstreamtwo.DefaultInputEventOne) SdkPojoBuilder(software.amazon.awssdk.core.SdkPojoBuilder) InputEventMarshaller(software.amazon.awssdk.services.json.transform.InputEventMarshaller) OperationWithChecksumRequiredRequest(software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredRequest) InputEventStream(software.amazon.awssdk.services.json.model.InputEventStream) List(java.util.List) APostOperationResponse(software.amazon.awssdk.services.json.model.APostOperationResponse) StreamingInputOutputOperationRequest(software.amazon.awssdk.services.json.model.StreamingInputOutputOperationRequest) AttachHttpMetadataResponseHandler(software.amazon.awssdk.core.client.handler.AttachHttpMetadataResponseHandler) Aws4UnsignedPayloadSigner(software.amazon.awssdk.auth.signer.Aws4UnsignedPayloadSigner) JsonRequest(software.amazon.awssdk.services.json.model.JsonRequest) EventStreamOperationWithOnlyOutputRequestMarshaller(software.amazon.awssdk.services.json.transform.EventStreamOperationWithOnlyOutputRequestMarshaller) OperationWithChecksumRequiredRequestMarshaller(software.amazon.awssdk.services.json.transform.OperationWithChecksumRequiredRequestMarshaller) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) Signer(software.amazon.awssdk.core.signer.Signer) AwsJsonProtocol(software.amazon.awssdk.protocols.json.AwsJsonProtocol) EventStreamAsyncResponseTransformer(software.amazon.awssdk.awscore.eventstream.EventStreamAsyncResponseTransformer) EventStreamTaggedUnionPojoSupplier(software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionPojoSupplier) CompletableFuture(java.util.concurrent.CompletableFuture) HttpChecksumRequired(software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired) InvalidInputException(software.amazon.awssdk.services.json.model.InvalidInputException) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) PaginatedOperationWithoutResultKeyRequest(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest) Logger(org.slf4j.Logger) EventStreamOperationWithOnlyOutputRequest(software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputRequest) Pair(software.amazon.awssdk.utils.Pair) SdkPublisher(software.amazon.awssdk.core.async.SdkPublisher) EventStreamAws4Signer(software.amazon.awssdk.auth.signer.EventStreamAws4Signer) Consumer(java.util.function.Consumer) StreamingOutputOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.StreamingOutputOperationRequestMarshaller) ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) EventStreamOperationWithOnlyOutputResponseHandler(software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputResponseHandler) StreamingInputOutputOperationResponse(software.amazon.awssdk.services.json.model.StreamingInputOutputOperationResponse) AwsClientHandlerUtils(software.amazon.awssdk.awscore.client.handler.AwsClientHandlerUtils) EventStreamOperationResponse(software.amazon.awssdk.services.json.model.EventStreamOperationResponse) SdkResponse(software.amazon.awssdk.core.SdkResponse) AwsJsonProtocolFactory(software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory) FunctionalUtils.runAndLogError(software.amazon.awssdk.utils.FunctionalUtils.runAndLogError) Collections(java.util.Collections) InputEventStreamTwo(software.amazon.awssdk.services.json.model.InputEventStreamTwo) InputEventMarshaller(software.amazon.awssdk.services.json.transform.InputEventMarshaller) AwsClientHandlerUtils(software.amazon.awssdk.awscore.client.handler.AwsClientHandlerUtils) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) ByteBuffer(java.nio.ByteBuffer) EventStreamTaggedUnionJsonMarshaller(software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionJsonMarshaller) InputEventTwoMarshaller(software.amazon.awssdk.services.json.transform.InputEventTwoMarshaller) EventStreamOperationWithOnlyInputRequestMarshaller(software.amazon.awssdk.services.json.transform.EventStreamOperationWithOnlyInputRequestMarshaller) EventStreamOperationWithOnlyInputResponse(software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyInputResponse) EventStreamOperationWithOnlyInputRequest(software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyInputRequest) DefaultInputEventTwo(software.amazon.awssdk.services.json.model.inputeventstreamtwo.DefaultInputEventTwo) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector)

Example 22 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class DefaultProtocolRestJsonWithCustomContentTypeClient method oneOperation.

/**
 * Invokes the OneOperation operation.
 *
 * @param oneOperationRequest
 * @return Result of the OneOperation operation returned by the service.
 * @throws SdkException
 *         Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
 *         catch all scenarios.
 * @throws SdkClientException
 *         If any client side error occurs such as an IO related failure, failure to get credentials, etc.
 * @throws ProtocolRestJsonWithCustomContentTypeException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample ProtocolRestJsonWithCustomContentTypeClient.OneOperation
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/restjson-2016-03-11/OneOperation" target="_top">AWS API
 *      Documentation</a>
 */
@Override
public OneOperationResponse oneOperation(OneOperationRequest oneOperationRequest) throws AwsServiceException, SdkClientException, ProtocolRestJsonWithCustomContentTypeException {
    JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
    HttpResponseHandler<OneOperationResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, OneOperationResponse::builder);
    HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, oneOperationRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AmazonProtocolRestJsonWithCustomContentType");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OneOperation");
        return clientHandler.execute(new ClientExecutionParams<OneOperationRequest, OneOperationResponse>().withOperationName("OneOperation").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withInput(oneOperationRequest).withMetricCollector(apiCallMetricCollector).withMarshaller(new OneOperationRequestMarshaller(protocolFactory)));
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : OneOperationRequestMarshaller(software.amazon.awssdk.services.protocolrestjsonwithcustomcontenttype.transform.OneOperationRequestMarshaller) OneOperationRequest(software.amazon.awssdk.services.protocolrestjsonwithcustomcontenttype.model.OneOperationRequest) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) OneOperationResponse(software.amazon.awssdk.services.protocolrestjsonwithcustomcontenttype.model.OneOperationResponse)

Example 23 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class DefaultEndpointDiscoveryTestClient method testDiscoveryOptional.

/**
 * Invokes the TestDiscoveryOptional operation.
 *
 * @param testDiscoveryOptionalRequest
 * @return Result of the TestDiscoveryOptional operation returned by the service.
 * @throws SdkException
 *         Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
 *         catch all scenarios.
 * @throws SdkClientException
 *         If any client side error occurs such as an IO related failure, failure to get credentials, etc.
 * @throws EndpointDiscoveryTestException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample EndpointDiscoveryTestClient.TestDiscoveryOptional
 */
@Override
public TestDiscoveryOptionalResponse testDiscoveryOptional(TestDiscoveryOptionalRequest testDiscoveryOptionalRequest) throws AwsServiceException, SdkClientException, EndpointDiscoveryTestException {
    JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
    HttpResponseHandler<TestDiscoveryOptionalResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, TestDiscoveryOptionalResponse::builder);
    HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
    boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
    boolean endpointOverridden = clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE;
    URI cachedEndpoint = null;
    if (endpointDiscoveryEnabled) {
        String key = testDiscoveryOptionalRequest.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsProvider).orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER)).resolveCredentials().accessKeyId();
        EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(false).defaultEndpoint(clientConfiguration.option(SdkClientOption.ENDPOINT)).overrideConfiguration(testDiscoveryOptionalRequest.overrideConfiguration().orElse(null)).build();
        cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest);
    }
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, testDiscoveryOptionalRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TestDiscoveryOptional");
        return clientHandler.execute(new ClientExecutionParams<TestDiscoveryOptionalRequest, TestDiscoveryOptionalResponse>().withOperationName("TestDiscoveryOptional").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).discoveredEndpoint(cachedEndpoint).withInput(testDiscoveryOptionalRequest).withMetricCollector(apiCallMetricCollector).withMarshaller(new TestDiscoveryOptionalRequestMarshaller(protocolFactory)));
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : TestDiscoveryOptionalResponse(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryOptionalResponse) ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) TestDiscoveryOptionalRequestMarshaller(software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryOptionalRequestMarshaller) EndpointDiscoveryRequest(software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRequest) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) URI(java.net.URI) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 24 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class DefaultEndpointDiscoveryTestClient method testDiscoveryIdentifiersRequired.

/**
 * Invokes the TestDiscoveryIdentifiersRequired operation.
 *
 * @param testDiscoveryIdentifiersRequiredRequest
 * @return Result of the TestDiscoveryIdentifiersRequired operation returned by the service.
 * @throws SdkException
 *         Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
 *         catch all scenarios.
 * @throws SdkClientException
 *         If any client side error occurs such as an IO related failure, failure to get credentials, etc.
 * @throws EndpointDiscoveryTestException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample EndpointDiscoveryTestClient.TestDiscoveryIdentifiersRequired
 */
@Override
public TestDiscoveryIdentifiersRequiredResponse testDiscoveryIdentifiersRequired(TestDiscoveryIdentifiersRequiredRequest testDiscoveryIdentifiersRequiredRequest) throws AwsServiceException, SdkClientException, EndpointDiscoveryTestException {
    JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
    HttpResponseHandler<TestDiscoveryIdentifiersRequiredResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, TestDiscoveryIdentifiersRequiredResponse::builder);
    HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
    boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
    boolean endpointOverridden = clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE;
    if (endpointOverridden) {
        throw new IllegalStateException("This operation requires endpoint discovery, but an endpoint override was specified when the client was created. This is not supported.");
    }
    if (!endpointDiscoveryEnabled) {
        throw new IllegalStateException("This operation requires endpoint discovery, but endpoint discovery was disabled on the client.");
    }
    URI cachedEndpoint = null;
    if (endpointDiscoveryEnabled) {
        String key = testDiscoveryIdentifiersRequiredRequest.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsProvider).orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER)).resolveCredentials().accessKeyId();
        EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true).defaultEndpoint(clientConfiguration.option(SdkClientOption.ENDPOINT)).overrideConfiguration(testDiscoveryIdentifiersRequiredRequest.overrideConfiguration().orElse(null)).build();
        cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest);
    }
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, testDiscoveryIdentifiersRequiredRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TestDiscoveryIdentifiersRequired");
        return clientHandler.execute(new ClientExecutionParams<TestDiscoveryIdentifiersRequiredRequest, TestDiscoveryIdentifiersRequiredResponse>().withOperationName("TestDiscoveryIdentifiersRequired").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).discoveredEndpoint(cachedEndpoint).withInput(testDiscoveryIdentifiersRequiredRequest).withMetricCollector(apiCallMetricCollector).withMarshaller(new TestDiscoveryIdentifiersRequiredRequestMarshaller(protocolFactory)));
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) TestDiscoveryIdentifiersRequiredRequestMarshaller(software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryIdentifiersRequiredRequestMarshaller) TestDiscoveryIdentifiersRequiredResponse(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryIdentifiersRequiredResponse) EndpointDiscoveryRequest(software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRequest) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) URI(java.net.URI) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 25 with MetricCollector

use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.

the class DefaultEndpointDiscoveryTestClient method testDiscoveryRequired.

/**
 * Invokes the TestDiscoveryRequired operation.
 *
 * @param testDiscoveryRequiredRequest
 * @return Result of the TestDiscoveryRequired operation returned by the service.
 * @throws SdkException
 *         Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
 *         catch all scenarios.
 * @throws SdkClientException
 *         If any client side error occurs such as an IO related failure, failure to get credentials, etc.
 * @throws EndpointDiscoveryTestException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample EndpointDiscoveryTestClient.TestDiscoveryRequired
 */
@Override
public TestDiscoveryRequiredResponse testDiscoveryRequired(TestDiscoveryRequiredRequest testDiscoveryRequiredRequest) throws AwsServiceException, SdkClientException, EndpointDiscoveryTestException {
    JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
    HttpResponseHandler<TestDiscoveryRequiredResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, TestDiscoveryRequiredResponse::builder);
    HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
    boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
    boolean endpointOverridden = clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE;
    if (endpointOverridden) {
        throw new IllegalStateException("This operation requires endpoint discovery, but an endpoint override was specified when the client was created. This is not supported.");
    }
    if (!endpointDiscoveryEnabled) {
        throw new IllegalStateException("This operation requires endpoint discovery, but endpoint discovery was disabled on the client.");
    }
    URI cachedEndpoint = null;
    if (endpointDiscoveryEnabled) {
        String key = testDiscoveryRequiredRequest.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsProvider).orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER)).resolveCredentials().accessKeyId();
        EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true).defaultEndpoint(clientConfiguration.option(SdkClientOption.ENDPOINT)).overrideConfiguration(testDiscoveryRequiredRequest.overrideConfiguration().orElse(null)).build();
        cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest);
    }
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, testDiscoveryRequiredRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TestDiscoveryRequired");
        return clientHandler.execute(new ClientExecutionParams<TestDiscoveryRequiredRequest, TestDiscoveryRequiredResponse>().withOperationName("TestDiscoveryRequired").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).discoveredEndpoint(cachedEndpoint).withInput(testDiscoveryRequiredRequest).withMetricCollector(apiCallMetricCollector).withMarshaller(new TestDiscoveryRequiredRequestMarshaller(protocolFactory)));
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) TestDiscoveryRequiredResponse(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryRequiredResponse) TestDiscoveryRequiredRequestMarshaller(software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryRequiredRequestMarshaller) EndpointDiscoveryRequest(software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRequest) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) URI(java.net.URI) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Aggregations

MetricCollector (software.amazon.awssdk.metrics.MetricCollector)115 NoOpMetricCollector (software.amazon.awssdk.metrics.NoOpMetricCollector)65 MetricPublisher (software.amazon.awssdk.metrics.MetricPublisher)64 AwsServiceException (software.amazon.awssdk.awscore.exception.AwsServiceException)59 ClientExecutionParams (software.amazon.awssdk.core.client.handler.ClientExecutionParams)47 CompletableFuture (java.util.concurrent.CompletableFuture)37 JsonOperationMetadata (software.amazon.awssdk.protocols.json.JsonOperationMetadata)35 Collections (java.util.Collections)34 List (java.util.List)34 Logger (org.slf4j.Logger)34 LoggerFactory (org.slf4j.LoggerFactory)34 Generated (software.amazon.awssdk.annotations.Generated)34 SdkInternalApi (software.amazon.awssdk.annotations.SdkInternalApi)34 AwsAsyncClientHandler (software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler)34 RequestOverrideConfiguration (software.amazon.awssdk.core.RequestOverrideConfiguration)34 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)34 SdkClientOption (software.amazon.awssdk.core.client.config.SdkClientOption)34 AsyncClientHandler (software.amazon.awssdk.core.client.handler.AsyncClientHandler)34 HttpResponseHandler (software.amazon.awssdk.core.http.HttpResponseHandler)34 CoreMetric (software.amazon.awssdk.core.metrics.CoreMetric)34