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);
}
}
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()));
}
}
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()));
}
}
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()));
}
}
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()));
}
}
Aggregations