
software.amazon.awssdk.services.batch.DefaultBatchAsyncClient Maven / Gradle / Ivy
/*
* Copyright 2014-2019 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.concurrent.CompletableFuture;
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.client.handler.AwsAsyncClientHandler;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
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.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.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.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.TerminateJobRequest;
import software.amazon.awssdk.services.batch.model.TerminateJobResponse;
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.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.RegisterJobDefinitionRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.SubmitJobRequestMarshaller;
import software.amazon.awssdk.services.batch.transform.TerminateJobRequestMarshaller;
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 cancelled. Jobs that have progressed to STARTING
or
* RUNNING
are not cancelled (but the API operation still succeeds, even if no job is cancelled); these
* jobs must be terminated with the TerminateJob operation.
*
*
* @param cancelJobRequest
* @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 is 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) {
try {
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).withInput(cancelJobRequest));
return executeFuture;
} catch (Throwable t) {
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Creates an AWS Batch compute environment. You can create MANAGED
or UNMANAGED
compute
* environments.
*
*
* 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 to use Amazon EC2 On-Demand Instances or Spot
* Instances in your managed compute environment. You can optionally set a maximum price so that Spot Instances only
* launch when the Spot Instance price is below 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 compute resources. This provides more compute
* resource configuration options, such as using a custom AMI, but you must ensure 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 is 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 does not upgrade the AMIs in a compute environment after it is created (for example, when a newer
* version of the Amazon ECS-optimized AMI is available). You are 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:
*
*
* -
*
* Create a new compute environment with the new AMI.
*
*
* -
*
* Add the compute environment to an existing job queue.
*
*
* -
*
* Remove the old compute environment from your job queue.
*
*
* -
*
* Delete the old compute environment.
*
*
*
*
*
* @param createComputeEnvironmentRequest
* @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 is 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) {
try {
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)
.withInput(createComputeEnvironmentRequest));
return executeFuture;
} catch (Throwable t) {
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
* @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 is 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) {
try {
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)
.withInput(createJobQueueRequest));
return executeFuture;
} catch (Throwable t) {
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.
*
*
* @param deleteComputeEnvironmentRequest
* @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 is 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) {
try {
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)
.withInput(deleteComputeEnvironmentRequest));
return executeFuture;
} catch (Throwable t) {
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 terminated when you delete a job queue.
*
*
* It is not necessary to disassociate compute environments from a queue before submitting a
* DeleteJobQueue
request.
*
*
* @param deleteJobQueueRequest
* @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 is 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) {
try {
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)
.withInput(deleteJobQueueRequest));
return executeFuture;
} catch (Throwable t) {
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Deregisters an AWS Batch job definition.
*
*
* @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 is 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) {
try {
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)
.withInput(deregisterJobDefinitionRequest));
return executeFuture;
} catch (Throwable t) {
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Describes one or more of your compute environments.
*
*
* If you are 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
* @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 is 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) {
try {
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)
.withInput(describeComputeEnvironmentsRequest));
return executeFuture;
} catch (Throwable t) {
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.
*
*
* @param describeJobDefinitionsRequest
* @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 is 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) {
try {
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)
.withInput(describeJobDefinitionsRequest));
return executeFuture;
} catch (Throwable t) {
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Describes one or more of your job queues.
*
*
* @param describeJobQueuesRequest
* @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 is 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) {
try {
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)
.withInput(describeJobQueuesRequest));
return executeFuture;
} catch (Throwable t) {
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Describes a list of AWS Batch jobs.
*
*
* @param describeJobsRequest
* @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 is 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) {
try {
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)
.withInput(describeJobsRequest));
return executeFuture;
} catch (Throwable t) {
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Returns a list of AWS Batch jobs.
*
*
* You must specify only one of the following:
*
*
* -
*
* 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 do not specify a
* status, only RUNNING
jobs are returned.
*
*
* @param listJobsRequest
* @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 is 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) {
try {
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).withInput(listJobsRequest));
return executeFuture;
} catch (Throwable t) {
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Registers an AWS Batch job definition.
*
*
* @param registerJobDefinitionRequest
* @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 is 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) {
try {
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)
.withInput(registerJobDefinitionRequest));
return executeFuture;
} catch (Throwable t) {
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Submits an AWS Batch job from a job definition. Parameters specified during SubmitJob override parameters
* defined in the job definition.
*
*
* @param submitJobRequest
* @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 is 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) {
try {
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).withInput(submitJobRequest));
return executeFuture;
} catch (Throwable t) {
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
* @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 is 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) {
try {
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)
.withInput(terminateJobRequest));
return executeFuture;
} catch (Throwable t) {
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Updates an AWS Batch compute environment.
*
*
* @param updateComputeEnvironmentRequest
* @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 is 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) {
try {
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)
.withInput(updateComputeEnvironmentRequest));
return executeFuture;
} catch (Throwable t) {
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Updates a job queue.
*
*
* @param updateJobQueueRequest
* @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 is 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) {
try {
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)
.withInput(updateJobQueueRequest));
return executeFuture;
} catch (Throwable t) {
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 HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory,
JsonOperationMetadata operationMetadata) {
return protocolFactory.createErrorResponseHandler(operationMetadata);
}
}