
software.amazon.awssdk.services.batch.DefaultBatchAsyncClient Maven / Gradle / Ivy
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.batch;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.ApiName;
import software.amazon.awssdk.core.RequestOverrideConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.client.handler.AsyncClientHandler;
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
import software.amazon.awssdk.core.http.HttpResponseHandler;
import software.amazon.awssdk.core.metrics.CoreMetric;
import software.amazon.awssdk.core.util.VersionInfo;
import software.amazon.awssdk.metrics.MetricCollector;
import software.amazon.awssdk.metrics.MetricPublisher;
import software.amazon.awssdk.metrics.NoOpMetricCollector;
import software.amazon.awssdk.protocols.core.ExceptionMetadata;
import software.amazon.awssdk.protocols.json.AwsJsonProtocol;
import software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.JsonOperationMetadata;
import software.amazon.awssdk.services.batch.model.BatchException;
import software.amazon.awssdk.services.batch.model.BatchRequest;
import software.amazon.awssdk.services.batch.model.CancelJobRequest;
import software.amazon.awssdk.services.batch.model.CancelJobResponse;
import software.amazon.awssdk.services.batch.model.ClientException;
import software.amazon.awssdk.services.batch.model.CreateComputeEnvironmentRequest;
import software.amazon.awssdk.services.batch.model.CreateComputeEnvironmentResponse;
import software.amazon.awssdk.services.batch.model.CreateJobQueueRequest;
import software.amazon.awssdk.services.batch.model.CreateJobQueueResponse;
import software.amazon.awssdk.services.batch.model.DeleteComputeEnvironmentRequest;
import software.amazon.awssdk.services.batch.model.DeleteComputeEnvironmentResponse;
import software.amazon.awssdk.services.batch.model.DeleteJobQueueRequest;
import software.amazon.awssdk.services.batch.model.DeleteJobQueueResponse;
import software.amazon.awssdk.services.batch.model.DeregisterJobDefinitionRequest;
import software.amazon.awssdk.services.batch.model.DeregisterJobDefinitionResponse;
import software.amazon.awssdk.services.batch.model.DescribeComputeEnvironmentsRequest;
import software.amazon.awssdk.services.batch.model.DescribeComputeEnvironmentsResponse;
import software.amazon.awssdk.services.batch.model.DescribeJobDefinitionsRequest;
import software.amazon.awssdk.services.batch.model.DescribeJobDefinitionsResponse;
import software.amazon.awssdk.services.batch.model.DescribeJobQueuesRequest;
import software.amazon.awssdk.services.batch.model.DescribeJobQueuesResponse;
import software.amazon.awssdk.services.batch.model.DescribeJobsRequest;
import software.amazon.awssdk.services.batch.model.DescribeJobsResponse;
import software.amazon.awssdk.services.batch.model.ListJobsRequest;
import software.amazon.awssdk.services.batch.model.ListJobsResponse;
import software.amazon.awssdk.services.batch.model.ListTagsForResourceRequest;
import software.amazon.awssdk.services.batch.model.ListTagsForResourceResponse;
import software.amazon.awssdk.services.batch.model.RegisterJobDefinitionRequest;
import software.amazon.awssdk.services.batch.model.RegisterJobDefinitionResponse;
import software.amazon.awssdk.services.batch.model.ServerException;
import software.amazon.awssdk.services.batch.model.SubmitJobRequest;
import software.amazon.awssdk.services.batch.model.SubmitJobResponse;
import software.amazon.awssdk.services.batch.model.TagResourceRequest;
import software.amazon.awssdk.services.batch.model.TagResourceResponse;
import software.amazon.awssdk.services.batch.model.TerminateJobRequest;
import software.amazon.awssdk.services.batch.model.TerminateJobResponse;
import software.amazon.awssdk.services.batch.model.UntagResourceRequest;
import software.amazon.awssdk.services.batch.model.UntagResourceResponse;
import software.amazon.awssdk.services.batch.model.UpdateComputeEnvironmentRequest;
import software.amazon.awssdk.services.batch.model.UpdateComputeEnvironmentResponse;
import software.amazon.awssdk.services.batch.model.UpdateJobQueueRequest;
import software.amazon.awssdk.services.batch.model.UpdateJobQueueResponse;
import software.amazon.awssdk.services.batch.paginators.DescribeComputeEnvironmentsPublisher;
import software.amazon.awssdk.services.batch.paginators.DescribeJobDefinitionsPublisher;
import software.amazon.awssdk.services.batch.paginators.DescribeJobQueuesPublisher;
import software.amazon.awssdk.services.batch.paginators.ListJobsPublisher;
import software.amazon.awssdk.services.batch.transform.CancelJobRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.CreateComputeEnvironmentRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.CreateJobQueueRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.DeleteComputeEnvironmentRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.DeleteJobQueueRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.DeregisterJobDefinitionRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.DescribeComputeEnvironmentsRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.DescribeJobDefinitionsRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.DescribeJobQueuesRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.DescribeJobsRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.ListJobsRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.ListTagsForResourceRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.RegisterJobDefinitionRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.SubmitJobRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.TagResourceRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.TerminateJobRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.UntagResourceRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.UpdateComputeEnvironmentRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.UpdateJobQueueRequestMarshaller;
import software.amazon.awssdk.utils.CompletableFutureUtils;
/**
* Internal implementation of {@link BatchAsyncClient}.
*
* @see BatchAsyncClient#builder()
*/
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
final class DefaultBatchAsyncClient implements BatchAsyncClient {
private static final Logger log = LoggerFactory.getLogger(DefaultBatchAsyncClient.class);
private final AsyncClientHandler clientHandler;
private final AwsJsonProtocolFactory protocolFactory;
private final SdkClientConfiguration clientConfiguration;
protected DefaultBatchAsyncClient(SdkClientConfiguration clientConfiguration) {
this.clientHandler = new AwsAsyncClientHandler(clientConfiguration);
this.clientConfiguration = clientConfiguration;
this.protocolFactory = init(AwsJsonProtocolFactory.builder()).build();
}
@Override
public final String serviceName() {
return SERVICE_NAME;
}
/**
*
* Cancels a job in an AWS Batch job queue. Jobs that are in the SUBMITTED
, PENDING
, or
* RUNNABLE
state are canceled. Jobs that have progressed to STARTING
or
* RUNNING
are not canceled (but the API operation still succeeds, even if no job is canceled); these
* jobs must be terminated with the TerminateJob operation.
*
*
* @param cancelJobRequest
* Contains the parameters for CancelJob
.
* @return A Java Future containing the result of the CancelJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.CancelJob
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture cancelJob(CancelJobRequest cancelJobRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, cancelJobRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CancelJob");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
CancelJobResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams().withOperationName("CancelJob")
.withMarshaller(new CancelJobRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler)
.withErrorResponseHandler(errorResponseHandler).withMetricCollector(apiCallMetricCollector)
.withInput(cancelJobRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = cancelJobRequest.overrideConfiguration().orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Creates an AWS Batch compute environment. You can create MANAGED
or UNMANAGED
compute
* environments. MANAGED
compute environments can use Amazon EC2 or AWS Fargate resources.
* UNMANAGED
compute environments can only use EC2 resources.
*
*
* In a managed compute environment, AWS Batch manages the capacity and instance types of the compute resources
* within the environment. This is based on the compute resource specification that you define or the launch template that you
* specify when you create the compute environment. You can choose either to use EC2 On-Demand Instances and EC2
* Spot Instances, or to use Fargate and Fargate Spot capacity in your managed compute environment. You can
* optionally set a maximum price so that Spot Instances only launch when the Spot Instance price is less than a
* specified percentage of the On-Demand price.
*
*
*
* Multi-node parallel jobs are not supported on Spot Instances.
*
*
*
* In an unmanaged compute environment, you can manage your own EC2 compute resources and have a lot of flexibility
* with how you configure your compute resources. For example, you can use custom AMI. However, you need to verify
* that your AMI meets the Amazon ECS container instance AMI specification. For more information, see container
* instance AMIs in the Amazon Elastic Container Service Developer Guide. After you have created your
* unmanaged compute environment, you can use the DescribeComputeEnvironments operation to find the Amazon
* ECS cluster that's associated with it. Then, manually launch your container instances into that Amazon ECS
* cluster. For more information, see Launching an
* Amazon ECS container instance in the Amazon Elastic Container Service Developer Guide.
*
*
*
* AWS Batch doesn't upgrade the AMIs in a compute environment after it's created. For example, it doesn't update
* the AMIs when a newer version of the Amazon ECS-optimized AMI is available. Therefore, you're responsible for the
* management of the guest operating system (including updates and security patches) and any additional application
* software or utilities that you install on the compute resources. To use a new AMI for your AWS Batch jobs,
* complete these steps:
*
*
* -
*
* Create a new compute environment with the new AMI.
*
*
* -
*
* Add the compute environment to an existing job queue.
*
*
* -
*
* Remove the earlier compute environment from your job queue.
*
*
* -
*
* Delete the earlier compute environment.
*
*
*
*
*
* @param createComputeEnvironmentRequest
* Contains the parameters for CreateComputeEnvironment
.
* @return A Java Future containing the result of the CreateComputeEnvironment operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.CreateComputeEnvironment
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture createComputeEnvironment(
CreateComputeEnvironmentRequest createComputeEnvironmentRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, createComputeEnvironmentRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateComputeEnvironment");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, CreateComputeEnvironmentResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateComputeEnvironment")
.withMarshaller(new CreateComputeEnvironmentRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(createComputeEnvironmentRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = createComputeEnvironmentRequest.overrideConfiguration()
.orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Creates an AWS Batch job queue. When you create a job queue, you associate one or more compute environments to
* the queue and assign an order of preference for the compute environments.
*
*
* You also set a priority to the job queue that determines the order in which the AWS Batch scheduler places jobs
* onto its associated compute environments. For example, if a compute environment is associated with more than one
* job queue, the job queue with a higher priority is given preference for scheduling jobs to that compute
* environment.
*
*
* @param createJobQueueRequest
* Contains the parameters for CreateJobQueue
.
* @return A Java Future containing the result of the CreateJobQueue operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.CreateJobQueue
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture createJobQueue(CreateJobQueueRequest createJobQueueRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, createJobQueueRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateJobQueue");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, CreateJobQueueResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateJobQueue")
.withMarshaller(new CreateJobQueueRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(createJobQueueRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = createJobQueueRequest.overrideConfiguration().orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Deletes an AWS Batch compute environment.
*
*
* Before you can delete a compute environment, you must set its state to DISABLED
with the
* UpdateComputeEnvironment API operation and disassociate it from any job queues with the
* UpdateJobQueue API operation. Compute environments that use AWS Fargate resources must terminate all
* active jobs on that compute environment before deleting the compute environment. If this isn't done, the compute
* environment will end up in an invalid state.
*
*
* @param deleteComputeEnvironmentRequest
* Contains the parameters for DeleteComputeEnvironment
.
* @return A Java Future containing the result of the DeleteComputeEnvironment operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.DeleteComputeEnvironment
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture deleteComputeEnvironment(
DeleteComputeEnvironmentRequest deleteComputeEnvironmentRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, deleteComputeEnvironmentRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DeleteComputeEnvironment");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DeleteComputeEnvironmentResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DeleteComputeEnvironment")
.withMarshaller(new DeleteComputeEnvironmentRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(deleteComputeEnvironmentRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = deleteComputeEnvironmentRequest.overrideConfiguration()
.orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Deletes the specified job queue. You must first disable submissions for a queue with the UpdateJobQueue
* operation. All jobs in the queue are eventually terminated when you delete a job queue. The jobs are terminated
* at a rate of about 16 jobs each second.
*
*
* It's not necessary to disassociate compute environments from a queue before submitting a
* DeleteJobQueue
request.
*
*
* @param deleteJobQueueRequest
* Contains the parameters for DeleteJobQueue
.
* @return A Java Future containing the result of the DeleteJobQueue operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.DeleteJobQueue
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture deleteJobQueue(DeleteJobQueueRequest deleteJobQueueRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, deleteJobQueueRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DeleteJobQueue");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DeleteJobQueueResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DeleteJobQueue")
.withMarshaller(new DeleteJobQueueRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(deleteJobQueueRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = deleteJobQueueRequest.overrideConfiguration().orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Deregisters an AWS Batch job definition. Job definitions are permanently deleted after 180 days.
*
*
* @param deregisterJobDefinitionRequest
* @return A Java Future containing the result of the DeregisterJobDefinition operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.DeregisterJobDefinition
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture deregisterJobDefinition(
DeregisterJobDefinitionRequest deregisterJobDefinitionRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, deregisterJobDefinitionRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DeregisterJobDefinition");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DeregisterJobDefinitionResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DeregisterJobDefinition")
.withMarshaller(new DeregisterJobDefinitionRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(deregisterJobDefinitionRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = deregisterJobDefinitionRequest.overrideConfiguration()
.orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Describes one or more of your compute environments.
*
*
* If you're using an unmanaged compute environment, you can use the DescribeComputeEnvironment
* operation to determine the ecsClusterArn
that you should launch your Amazon ECS container instances
* into.
*
*
* @param describeComputeEnvironmentsRequest
* Contains the parameters for DescribeComputeEnvironments
.
* @return A Java Future containing the result of the DescribeComputeEnvironments operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.DescribeComputeEnvironments
* @see AWS API Documentation
*/
@Override
public CompletableFuture describeComputeEnvironments(
DescribeComputeEnvironmentsRequest describeComputeEnvironmentsRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, describeComputeEnvironmentsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeComputeEnvironments");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DescribeComputeEnvironmentsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DescribeComputeEnvironments")
.withMarshaller(new DescribeComputeEnvironmentsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(describeComputeEnvironmentsRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = describeComputeEnvironmentsRequest.overrideConfiguration()
.orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Describes one or more of your compute environments.
*
*
* If you're using an unmanaged compute environment, you can use the DescribeComputeEnvironment
* operation to determine the ecsClusterArn
that you should launch your Amazon ECS container instances
* into.
*
*
*
* This is a variant of
* {@link #describeComputeEnvironments(software.amazon.awssdk.services.batch.model.DescribeComputeEnvironmentsRequest)}
* operation. The return type is a custom publisher that can be subscribed to request a stream of response pages.
* SDK will internally handle making service calls for you.
*
*
* When the operation is called, an instance of this class is returned. At this point, no service calls are made yet
* and so there is no guarantee that the request is valid. If there are errors in your request, you will see the
* failures only after you start streaming the data. The subscribe method should be called as a request to start
* streaming data. For more info, see
* {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe
* method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the
* starting request.
*
*
*
* The following are few ways to use the response class:
*
* 1) Using the subscribe helper method
*
*
* {@code
* software.amazon.awssdk.services.batch.paginators.DescribeComputeEnvironmentsPublisher publisher = client.describeComputeEnvironmentsPaginator(request);
* CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
* future.get();
* }
*
*
* 2) Using a custom subscriber
*
*
* {@code
* software.amazon.awssdk.services.batch.paginators.DescribeComputeEnvironmentsPublisher publisher = client.describeComputeEnvironmentsPaginator(request);
* publisher.subscribe(new Subscriber() {
*
* public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
*
*
* public void onNext(software.amazon.awssdk.services.batch.model.DescribeComputeEnvironmentsResponse response) { //... };
* });}
*
*
* As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2.
*
* Please notice that the configuration of maxResults won't limit the number of results you get with the
* paginator. It only limits the number of results in each page.
*
*
* Note: If you prefer to have control on service calls, use the
* {@link #describeComputeEnvironments(software.amazon.awssdk.services.batch.model.DescribeComputeEnvironmentsRequest)}
* operation.
*
*
* @param describeComputeEnvironmentsRequest
* Contains the parameters for DescribeComputeEnvironments
.
* @return A custom publisher that can be subscribed to request a stream of response pages.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.DescribeComputeEnvironments
* @see AWS API Documentation
*/
public DescribeComputeEnvironmentsPublisher describeComputeEnvironmentsPaginator(
DescribeComputeEnvironmentsRequest describeComputeEnvironmentsRequest) {
return new DescribeComputeEnvironmentsPublisher(this, applyPaginatorUserAgent(describeComputeEnvironmentsRequest));
}
/**
*
* Describes a list of job definitions. You can specify a status
(such as ACTIVE
) to only
* return job definitions that match that status.
*
*
* @param describeJobDefinitionsRequest
* Contains the parameters for DescribeJobDefinitions
.
* @return A Java Future containing the result of the DescribeJobDefinitions operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.DescribeJobDefinitions
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture describeJobDefinitions(
DescribeJobDefinitionsRequest describeJobDefinitionsRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, describeJobDefinitionsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeJobDefinitions");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DescribeJobDefinitionsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DescribeJobDefinitions")
.withMarshaller(new DescribeJobDefinitionsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(describeJobDefinitionsRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = describeJobDefinitionsRequest.overrideConfiguration().orElse(
null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Describes a list of job definitions. You can specify a status
(such as ACTIVE
) to only
* return job definitions that match that status.
*
*
*
* This is a variant of
* {@link #describeJobDefinitions(software.amazon.awssdk.services.batch.model.DescribeJobDefinitionsRequest)}
* operation. The return type is a custom publisher that can be subscribed to request a stream of response pages.
* SDK will internally handle making service calls for you.
*
*
* When the operation is called, an instance of this class is returned. At this point, no service calls are made yet
* and so there is no guarantee that the request is valid. If there are errors in your request, you will see the
* failures only after you start streaming the data. The subscribe method should be called as a request to start
* streaming data. For more info, see
* {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe
* method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the
* starting request.
*
*
*
* The following are few ways to use the response class:
*
* 1) Using the subscribe helper method
*
*
* {@code
* software.amazon.awssdk.services.batch.paginators.DescribeJobDefinitionsPublisher publisher = client.describeJobDefinitionsPaginator(request);
* CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
* future.get();
* }
*
*
* 2) Using a custom subscriber
*
*
* {@code
* software.amazon.awssdk.services.batch.paginators.DescribeJobDefinitionsPublisher publisher = client.describeJobDefinitionsPaginator(request);
* publisher.subscribe(new Subscriber() {
*
* public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
*
*
* public void onNext(software.amazon.awssdk.services.batch.model.DescribeJobDefinitionsResponse response) { //... };
* });}
*
*
* As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2.
*
* Please notice that the configuration of maxResults won't limit the number of results you get with the
* paginator. It only limits the number of results in each page.
*
*
* Note: If you prefer to have control on service calls, use the
* {@link #describeJobDefinitions(software.amazon.awssdk.services.batch.model.DescribeJobDefinitionsRequest)}
* operation.
*
*
* @param describeJobDefinitionsRequest
* Contains the parameters for DescribeJobDefinitions
.
* @return A custom publisher that can be subscribed to request a stream of response pages.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.DescribeJobDefinitions
* @see AWS
* API Documentation
*/
public DescribeJobDefinitionsPublisher describeJobDefinitionsPaginator(
DescribeJobDefinitionsRequest describeJobDefinitionsRequest) {
return new DescribeJobDefinitionsPublisher(this, applyPaginatorUserAgent(describeJobDefinitionsRequest));
}
/**
*
* Describes one or more of your job queues.
*
*
* @param describeJobQueuesRequest
* Contains the parameters for DescribeJobQueues
.
* @return A Java Future containing the result of the DescribeJobQueues operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.DescribeJobQueues
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture describeJobQueues(DescribeJobQueuesRequest describeJobQueuesRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, describeJobQueuesRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeJobQueues");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DescribeJobQueuesResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DescribeJobQueues")
.withMarshaller(new DescribeJobQueuesRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(describeJobQueuesRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = describeJobQueuesRequest.overrideConfiguration().orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Describes one or more of your job queues.
*
*
*
* This is a variant of
* {@link #describeJobQueues(software.amazon.awssdk.services.batch.model.DescribeJobQueuesRequest)} operation. The
* return type is a custom publisher that can be subscribed to request a stream of response pages. SDK will
* internally handle making service calls for you.
*
*
* When the operation is called, an instance of this class is returned. At this point, no service calls are made yet
* and so there is no guarantee that the request is valid. If there are errors in your request, you will see the
* failures only after you start streaming the data. The subscribe method should be called as a request to start
* streaming data. For more info, see
* {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe
* method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the
* starting request.
*
*
*
* The following are few ways to use the response class:
*
* 1) Using the subscribe helper method
*
*
* {@code
* software.amazon.awssdk.services.batch.paginators.DescribeJobQueuesPublisher publisher = client.describeJobQueuesPaginator(request);
* CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
* future.get();
* }
*
*
* 2) Using a custom subscriber
*
*
* {@code
* software.amazon.awssdk.services.batch.paginators.DescribeJobQueuesPublisher publisher = client.describeJobQueuesPaginator(request);
* publisher.subscribe(new Subscriber() {
*
* public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
*
*
* public void onNext(software.amazon.awssdk.services.batch.model.DescribeJobQueuesResponse response) { //... };
* });}
*
*
* As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2.
*
* Please notice that the configuration of maxResults won't limit the number of results you get with the
* paginator. It only limits the number of results in each page.
*
*
* Note: If you prefer to have control on service calls, use the
* {@link #describeJobQueues(software.amazon.awssdk.services.batch.model.DescribeJobQueuesRequest)} operation.
*
*
* @param describeJobQueuesRequest
* Contains the parameters for DescribeJobQueues
.
* @return A custom publisher that can be subscribed to request a stream of response pages.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.DescribeJobQueues
* @see AWS API
* Documentation
*/
public DescribeJobQueuesPublisher describeJobQueuesPaginator(DescribeJobQueuesRequest describeJobQueuesRequest) {
return new DescribeJobQueuesPublisher(this, applyPaginatorUserAgent(describeJobQueuesRequest));
}
/**
*
* Describes a list of AWS Batch jobs.
*
*
* @param describeJobsRequest
* Contains the parameters for DescribeJobs
.
* @return A Java Future containing the result of the DescribeJobs operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.DescribeJobs
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture describeJobs(DescribeJobsRequest describeJobsRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, describeJobsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeJobs");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
DescribeJobsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DescribeJobs").withMarshaller(new DescribeJobsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(describeJobsRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = describeJobsRequest.overrideConfiguration().orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Returns a list of AWS Batch jobs.
*
*
* You must specify only one of the following items:
*
*
* -
*
* A job queue ID to return a list of jobs in that job queue
*
*
* -
*
* A multi-node parallel job ID to return a list of that job's nodes
*
*
* -
*
* An array job ID to return a list of that job's children
*
*
*
*
* You can filter the results by job status with the jobStatus
parameter. If you don't specify a
* status, only RUNNING
jobs are returned.
*
*
* @param listJobsRequest
* Contains the parameters for ListJobs
.
* @return A Java Future containing the result of the ListJobs operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.ListJobs
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture listJobs(ListJobsRequest listJobsRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, listJobsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListJobs");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
ListJobsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams().withOperationName("ListJobs")
.withMarshaller(new ListJobsRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler)
.withErrorResponseHandler(errorResponseHandler).withMetricCollector(apiCallMetricCollector)
.withInput(listJobsRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = listJobsRequest.overrideConfiguration().orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Returns a list of AWS Batch jobs.
*
*
* You must specify only one of the following items:
*
*
* -
*
* A job queue ID to return a list of jobs in that job queue
*
*
* -
*
* A multi-node parallel job ID to return a list of that job's nodes
*
*
* -
*
* An array job ID to return a list of that job's children
*
*
*
*
* You can filter the results by job status with the jobStatus
parameter. If you don't specify a
* status, only RUNNING
jobs are returned.
*
*
*
* This is a variant of {@link #listJobs(software.amazon.awssdk.services.batch.model.ListJobsRequest)} operation.
* The return type is a custom publisher that can be subscribed to request a stream of response pages. SDK will
* internally handle making service calls for you.
*
*
* When the operation is called, an instance of this class is returned. At this point, no service calls are made yet
* and so there is no guarantee that the request is valid. If there are errors in your request, you will see the
* failures only after you start streaming the data. The subscribe method should be called as a request to start
* streaming data. For more info, see
* {@link org.reactivestreams.Publisher#subscribe(org.reactivestreams.Subscriber)}. Each call to the subscribe
* method will result in a new {@link org.reactivestreams.Subscription} i.e., a new contract to stream data from the
* starting request.
*
*
*
* The following are few ways to use the response class:
*
* 1) Using the subscribe helper method
*
*
* {@code
* software.amazon.awssdk.services.batch.paginators.ListJobsPublisher publisher = client.listJobsPaginator(request);
* CompletableFuture future = publisher.subscribe(res -> { // Do something with the response });
* future.get();
* }
*
*
* 2) Using a custom subscriber
*
*
* {@code
* software.amazon.awssdk.services.batch.paginators.ListJobsPublisher publisher = client.listJobsPaginator(request);
* publisher.subscribe(new Subscriber() {
*
* public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
*
*
* public void onNext(software.amazon.awssdk.services.batch.model.ListJobsResponse response) { //... };
* });}
*
*
* As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2.
*
* Please notice that the configuration of maxResults won't limit the number of results you get with the
* paginator. It only limits the number of results in each page.
*
*
* Note: If you prefer to have control on service calls, use the
* {@link #listJobs(software.amazon.awssdk.services.batch.model.ListJobsRequest)} operation.
*
*
* @param listJobsRequest
* Contains the parameters for ListJobs
.
* @return A custom publisher that can be subscribed to request a stream of response pages.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.ListJobs
* @see AWS API
* Documentation
*/
public ListJobsPublisher listJobsPaginator(ListJobsRequest listJobsRequest) {
return new ListJobsPublisher(this, applyPaginatorUserAgent(listJobsRequest));
}
/**
*
* Lists the tags for an AWS Batch resource. AWS Batch resources that support tags are compute environments, jobs,
* job definitions, and job queues. ARNs for child jobs of array and multi-node parallel (MNP) jobs are not
* supported.
*
*
* @param listTagsForResourceRequest
* @return A Java Future containing the result of the ListTagsForResource operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.ListTagsForResource
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture listTagsForResource(
ListTagsForResourceRequest listTagsForResourceRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, listTagsForResourceRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListTagsForResource");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListTagsForResourceResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListTagsForResource")
.withMarshaller(new ListTagsForResourceRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(listTagsForResourceRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = listTagsForResourceRequest.overrideConfiguration().orElse(
null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Registers an AWS Batch job definition.
*
*
* @param registerJobDefinitionRequest
* Contains the parameters for RegisterJobDefinition
.
* @return A Java Future containing the result of the RegisterJobDefinition operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.RegisterJobDefinition
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture registerJobDefinition(
RegisterJobDefinitionRequest registerJobDefinitionRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, registerJobDefinitionRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "RegisterJobDefinition");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, RegisterJobDefinitionResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("RegisterJobDefinition")
.withMarshaller(new RegisterJobDefinitionRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(registerJobDefinitionRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = registerJobDefinitionRequest.overrideConfiguration().orElse(
null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Submits an AWS Batch job from a job definition. Parameters specified during SubmitJob override parameters
* defined in the job definition.
*
*
*
* Jobs run on Fargate resources don't run for more than 14 days. After 14 days, the Fargate resources might no
* longer be available and the job is terminated.
*
*
*
* @param submitJobRequest
* Contains the parameters for SubmitJob
.
* @return A Java Future containing the result of the SubmitJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.SubmitJob
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture submitJob(SubmitJobRequest submitJobRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, submitJobRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "SubmitJob");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
SubmitJobResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams().withOperationName("SubmitJob")
.withMarshaller(new SubmitJobRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler)
.withErrorResponseHandler(errorResponseHandler).withMetricCollector(apiCallMetricCollector)
.withInput(submitJobRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = submitJobRequest.overrideConfiguration().orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Associates the specified tags to a resource with the specified resourceArn
. If existing tags on a
* resource aren't specified in the request parameters, they aren't changed. When a resource is deleted, the tags
* associated with that resource are deleted as well. AWS Batch resources that support tags are compute
* environments, jobs, job definitions, and job queues. ARNs for child jobs of array and multi-node parallel (MNP)
* jobs are not supported.
*
*
* @param tagResourceRequest
* @return A Java Future containing the result of the TagResource operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.TagResource
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture tagResource(TagResourceRequest tagResourceRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, tagResourceRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TagResource");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
TagResourceResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("TagResource").withMarshaller(new TagResourceRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(tagResourceRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = tagResourceRequest.overrideConfiguration().orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Terminates a job in a job queue. Jobs that are in the STARTING
or RUNNING
state are
* terminated, which causes them to transition to FAILED
. Jobs that have not progressed to the
* STARTING
state are cancelled.
*
*
* @param terminateJobRequest
* Contains the parameters for TerminateJob
.
* @return A Java Future containing the result of the TerminateJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.TerminateJob
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture terminateJob(TerminateJobRequest terminateJobRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, terminateJobRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TerminateJob");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
TerminateJobResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("TerminateJob").withMarshaller(new TerminateJobRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(terminateJobRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = terminateJobRequest.overrideConfiguration().orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Deletes specified tags from an AWS Batch resource.
*
*
* @param untagResourceRequest
* @return A Java Future containing the result of the UntagResource operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.UntagResource
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture untagResource(UntagResourceRequest untagResourceRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, untagResourceRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UntagResource");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
UntagResourceResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("UntagResource")
.withMarshaller(new UntagResourceRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(untagResourceRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = untagResourceRequest.overrideConfiguration().orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Updates an AWS Batch compute environment.
*
*
* @param updateComputeEnvironmentRequest
* Contains the parameters for UpdateComputeEnvironment
.
* @return A Java Future containing the result of the UpdateComputeEnvironment operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.UpdateComputeEnvironment
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture updateComputeEnvironment(
UpdateComputeEnvironmentRequest updateComputeEnvironmentRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, updateComputeEnvironmentRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UpdateComputeEnvironment");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, UpdateComputeEnvironmentResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("UpdateComputeEnvironment")
.withMarshaller(new UpdateComputeEnvironmentRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(updateComputeEnvironmentRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = updateComputeEnvironmentRequest.overrideConfiguration()
.orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Updates a job queue.
*
*
* @param updateJobQueueRequest
* Contains the parameters for UpdateJobQueue
.
* @return A Java Future containing the result of the UpdateJobQueue operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
*
* - ClientException These errors are usually caused by a client action, such as using an action or
* resource on behalf of a user that doesn't have permissions to use the action or resource, or specifying
* an identifier that's not valid.
* - ServerException These errors are usually caused by a server issue.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BatchException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BatchAsyncClient.UpdateJobQueue
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture updateJobQueue(UpdateJobQueueRequest updateJobQueueRequest) {
List metricPublishers = resolveMetricPublishers(clientConfiguration, updateJobQueueRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Batch");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UpdateJobQueue");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, UpdateJobQueueResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("UpdateJobQueue")
.withMarshaller(new UpdateJobQueueRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withMetricCollector(apiCallMetricCollector).withInput(updateJobQueueRequest));
AwsRequestOverrideConfiguration requestOverrideConfig = updateJobQueueRequest.overrideConfiguration().orElse(null);
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
@Override
public void close() {
clientHandler.close();
}
private > T init(T builder) {
return builder
.clientConfiguration(clientConfiguration)
.defaultServiceExceptionSupplier(BatchException::builder)
.protocol(AwsJsonProtocol.REST_JSON)
.protocolVersion("1.1")
.registerModeledException(
ExceptionMetadata.builder().errorCode("ServerException")
.exceptionBuilderSupplier(ServerException::builder).httpStatusCode(500).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("ClientException")
.exceptionBuilderSupplier(ClientException::builder).httpStatusCode(400).build());
}
private static List resolveMetricPublishers(SdkClientConfiguration clientConfiguration,
RequestOverrideConfiguration requestOverrideConfiguration) {
List publishers = null;
if (requestOverrideConfiguration != null) {
publishers = requestOverrideConfiguration.metricPublishers();
}
if (publishers == null || publishers.isEmpty()) {
publishers = clientConfiguration.option(SdkClientOption.METRIC_PUBLISHERS);
}
if (publishers == null) {
publishers = Collections.emptyList();
}
return publishers;
}
private T applyPaginatorUserAgent(T request) {
Consumer userAgentApplier = b -> b.addApiName(ApiName.builder()
.version(VersionInfo.SDK_VERSION).name("PAGINATED").build());
AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration()
.map(c -> c.toBuilder().applyMutation(userAgentApplier).build())
.orElse((AwsRequestOverrideConfiguration.builder().applyMutation(userAgentApplier).build()));
return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build();
}
private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory,
JsonOperationMetadata operationMetadata) {
return protocolFactory.createErrorResponseHandler(operationMetadata);
}
}