Search in sources :

Example 66 with MetricPublisher

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

the class DefaultJsonClient method paginatedOperationWithoutResultKey.

/**
 * Some paginated operation without result_key in paginators.json file
 *
 * @param paginatedOperationWithoutResultKeyRequest
 * @return Result of the PaginatedOperationWithoutResultKey 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 JsonException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample JsonClient.PaginatedOperationWithoutResultKey
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/PaginatedOperationWithoutResultKey"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public PaginatedOperationWithoutResultKeyResponse paginatedOperationWithoutResultKey(PaginatedOperationWithoutResultKeyRequest paginatedOperationWithoutResultKeyRequest) throws AwsServiceException, SdkClientException, JsonException {
    JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
    HttpResponseHandler<PaginatedOperationWithoutResultKeyResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, PaginatedOperationWithoutResultKeyResponse::builder);
    HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, paginatedOperationWithoutResultKeyRequest.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, "PaginatedOperationWithoutResultKey");
        return clientHandler.execute(new ClientExecutionParams<PaginatedOperationWithoutResultKeyRequest, PaginatedOperationWithoutResultKeyResponse>().withOperationName("PaginatedOperationWithoutResultKey").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withInput(paginatedOperationWithoutResultKeyRequest).withMetricCollector(apiCallMetricCollector).withMarshaller(new PaginatedOperationWithoutResultKeyRequestMarshaller(protocolFactory)));
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : 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) PaginatedOperationWithoutResultKeyRequest(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest) PaginatedOperationWithoutResultKeyResponse(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyResponse) PaginatedOperationWithoutResultKeyRequestMarshaller(software.amazon.awssdk.services.json.transform.PaginatedOperationWithoutResultKeyRequestMarshaller)

Example 67 with MetricPublisher

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

the class DefaultJsonClient method streamingOutputOperation.

/**
 * Some operation with a streaming output
 *
 * @param streamingOutputOperationRequest
 * @param responseTransformer
 *        Functional interface for processing the streamed response content. The unmarshalled
 *        StreamingOutputOperationResponse and an InputStream to the response content are provided as parameters to
 *        the callback. The callback may return a transformed type which will be the return value of this method.
 *        See {@link software.amazon.awssdk.core.sync.ResponseTransformer} for details on implementing this
 *        interface and for links to pre-canned implementations for common scenarios like downloading to a file. The
 *        service documentation for the response content is as follows 'This be a stream'.
 * @return The transformed result of the ResponseTransformer.
 * @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 JsonException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample JsonClient.StreamingOutputOperation
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/StreamingOutputOperation"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public <ReturnT> ReturnT streamingOutputOperation(StreamingOutputOperationRequest streamingOutputOperationRequest, ResponseTransformer<StreamingOutputOperationResponse, ReturnT> responseTransformer) throws AwsServiceException, SdkClientException, JsonException {
    JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true).isPayloadJson(false).build();
    HttpResponseHandler<StreamingOutputOperationResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, StreamingOutputOperationResponse::builder);
    HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, streamingOutputOperationRequest.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, "StreamingOutputOperation");
        return clientHandler.execute(new ClientExecutionParams<StreamingOutputOperationRequest, StreamingOutputOperationResponse>().withOperationName("StreamingOutputOperation").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withInput(streamingOutputOperationRequest).withMetricCollector(apiCallMetricCollector).withMarshaller(new StreamingOutputOperationRequestMarshaller(protocolFactory)), responseTransformer);
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : StreamingOutputOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.StreamingOutputOperationRequestMarshaller) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) StreamingOutputOperationRequest(software.amazon.awssdk.services.json.model.StreamingOutputOperationRequest) StreamingOutputOperationResponse(software.amazon.awssdk.services.json.model.StreamingOutputOperationResponse) 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)

Example 68 with MetricPublisher

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

the class DefaultJsonClient method streamingInputOperation.

/**
 * Some operation with a streaming input
 *
 * @param streamingInputOperationRequest
 * @param requestBody
 *        The content to send to the service. A {@link RequestBody} can be created using one of several factory
 *        methods for various sources of data. For example, to create a request body from a file you can do the
 *        following.
 *
 *        <pre>
 * {@code RequestBody.fromFile(new File("myfile.txt"))}
 * </pre>
 *
 *        See documentation in {@link RequestBody} for additional details and which sources of data are supported.
 *        The service documentation for the request content is as follows 'This be a stream'
 * @return Result of the StreamingInputOperation 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 JsonException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample JsonClient.StreamingInputOperation
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/StreamingInputOperation"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public StreamingInputOperationResponse streamingInputOperation(StreamingInputOperationRequest streamingInputOperationRequest, RequestBody requestBody) throws AwsServiceException, SdkClientException, JsonException {
    JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
    HttpResponseHandler<StreamingInputOperationResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, StreamingInputOperationResponse::builder);
    HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, streamingInputOperationRequest.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, "StreamingInputOperation");
        return clientHandler.execute(new ClientExecutionParams<StreamingInputOperationRequest, StreamingInputOperationResponse>().withOperationName("StreamingInputOperation").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withInput(streamingInputOperationRequest).withMetricCollector(apiCallMetricCollector).withRequestBody(requestBody).withMarshaller(StreamingRequestMarshaller.builder().delegateMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory)).requestBody(requestBody).build()));
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) StreamingInputOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.StreamingInputOperationRequestMarshaller) StreamingInputOperationResponse(software.amazon.awssdk.services.json.model.StreamingInputOperationResponse) 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)

Example 69 with MetricPublisher

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

the class DefaultJsonClient method getOperationWithChecksum.

/**
 * Invokes the GetOperationWithChecksum operation.
 *
 * @param getOperationWithChecksumRequest
 * @return Result of the GetOperationWithChecksum 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 JsonException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample JsonClient.GetOperationWithChecksum
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/GetOperationWithChecksum"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public GetOperationWithChecksumResponse getOperationWithChecksum(GetOperationWithChecksumRequest getOperationWithChecksumRequest) throws AwsServiceException, SdkClientException, JsonException {
    JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
    HttpResponseHandler<GetOperationWithChecksumResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, GetOperationWithChecksumResponse::builder);
    HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, getOperationWithChecksumRequest.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, "GetOperationWithChecksum");
        return clientHandler.execute(new ClientExecutionParams<GetOperationWithChecksumRequest, GetOperationWithChecksumResponse>().withOperationName("GetOperationWithChecksum").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withInput(getOperationWithChecksumRequest).withMetricCollector(apiCallMetricCollector).putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM, HttpChecksum.builder().requestChecksumRequired(true).requestAlgorithm(getOperationWithChecksumRequest.checksumAlgorithmAsString()).isRequestStreaming(false).build()).withMarshaller(new GetOperationWithChecksumRequestMarshaller(protocolFactory)));
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) GetOperationWithChecksumResponse(software.amazon.awssdk.services.json.model.GetOperationWithChecksumResponse) 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) GetOperationWithChecksumRequestMarshaller(software.amazon.awssdk.services.json.transform.GetOperationWithChecksumRequestMarshaller)

Example 70 with MetricPublisher

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

the class DefaultJsonClient method streamingInputOutputOperation.

/**
 * Some operation with streaming input and streaming output
 *
 * @param streamingInputOutputOperationRequest
 * @param requestBody
 *        The content to send to the service. A {@link RequestBody} can be created using one of several factory
 *        methods for various sources of data. For example, to create a request body from a file you can do the
 *        following.
 *
 *        <pre>
 * {@code RequestBody.fromFile(new File("myfile.txt"))}
 * </pre>
 *
 *        See documentation in {@link RequestBody} for additional details and which sources of data are supported.
 *        The service documentation for the request content is as follows 'This be a stream'
 * @param responseTransformer
 *        Functional interface for processing the streamed response content. The unmarshalled
 *        StreamingInputOutputOperationResponse and an InputStream to the response content are provided as
 *        parameters to the callback. The callback may return a transformed type which will be the return value of
 *        this method. See {@link software.amazon.awssdk.core.sync.ResponseTransformer} for details on implementing
 *        this interface and for links to pre-canned implementations for common scenarios like downloading to a
 *        file. The service documentation for the response content is as follows 'This be a stream'.
 * @return The transformed result of the ResponseTransformer.
 * @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 JsonException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample JsonClient.StreamingInputOutputOperation
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/StreamingInputOutputOperation"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public <ReturnT> ReturnT streamingInputOutputOperation(StreamingInputOutputOperationRequest streamingInputOutputOperationRequest, RequestBody requestBody, ResponseTransformer<StreamingInputOutputOperationResponse, ReturnT> responseTransformer) throws AwsServiceException, SdkClientException, JsonException {
    streamingInputOutputOperationRequest = applySignerOverride(streamingInputOutputOperationRequest, Aws4UnsignedPayloadSigner.create());
    JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true).isPayloadJson(false).build();
    HttpResponseHandler<StreamingInputOutputOperationResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, StreamingInputOutputOperationResponse::builder);
    HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, streamingInputOutputOperationRequest.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, "StreamingInputOutputOperation");
        return clientHandler.execute(new ClientExecutionParams<StreamingInputOutputOperationRequest, StreamingInputOutputOperationResponse>().withOperationName("StreamingInputOutputOperation").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withInput(streamingInputOutputOperationRequest).withMetricCollector(apiCallMetricCollector).withRequestBody(requestBody).withMarshaller(StreamingRequestMarshaller.builder().delegateMarshaller(new StreamingInputOutputOperationRequestMarshaller(protocolFactory)).requestBody(requestBody).transferEncoding(true).build()), responseTransformer);
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) StreamingInputOutputOperationResponse(software.amazon.awssdk.services.json.model.StreamingInputOutputOperationResponse) 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) StreamingInputOutputOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.StreamingInputOutputOperationRequestMarshaller)

Aggregations

MetricPublisher (software.amazon.awssdk.metrics.MetricPublisher)80 MetricCollector (software.amazon.awssdk.metrics.MetricCollector)64 NoOpMetricCollector (software.amazon.awssdk.metrics.NoOpMetricCollector)64 AwsServiceException (software.amazon.awssdk.awscore.exception.AwsServiceException)59 ClientExecutionParams (software.amazon.awssdk.core.client.handler.ClientExecutionParams)47 List (java.util.List)40 CompletableFuture (java.util.concurrent.CompletableFuture)36 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)36 SdkClientOption (software.amazon.awssdk.core.client.config.SdkClientOption)36 CoreMetric (software.amazon.awssdk.core.metrics.CoreMetric)36 JsonOperationMetadata (software.amazon.awssdk.protocols.json.JsonOperationMetadata)35 Collections (java.util.Collections)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 AsyncClientHandler (software.amazon.awssdk.core.client.handler.AsyncClientHandler)34 HttpResponseHandler (software.amazon.awssdk.core.http.HttpResponseHandler)34