additionalBehaviors) throws BatchErrorException, IOException {
+ CertificateCancelDeletionOptions options = new CertificateCancelDeletionOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this.parentBatchClient.protocolLayer().certificates().cancelDeletion(thumbprintAlgorithm, thumbprint, options);
+ }
+
+ /**
+ * Deletes the certificate from the Batch account.
+ * The delete operation requests that the certificate be deleted. The request puts the certificate in the {@link com.microsoft.azure.batch.protocol.models.CertificateState#DELETING Deleting} state.
+ * The Batch service will perform the actual certificate deletion without any further client action.
+ * You cannot delete a certificate if a resource (pool or compute node) is using it. Before you can delete a certificate, you must therefore make sure that:
+ *
+ * - The certificate is not associated with any pools.
+ * - The certificate is not installed on any compute nodes. (Even if you remove a certificate from a pool, it is not removed from existing compute nodes in that pool until they restart.)
+ *
+ * If you try to delete a certificate that is in use, the deletion fails. The certificate state changes to {@link com.microsoft.azure.batch.protocol.models.CertificateState#DELETE_FAILED Delete Failed}.
+ * You can use {@link #cancelDeleteCertificate(String, String)} to set the status back to Active if you decide that you want to continue using the certificate.
+ *
+ * @param thumbprintAlgorithm The algorithm used to derive the thumbprint parameter. This must be sha1.
+ * @param thumbprint The thumbprint of the certificate to delete.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void deleteCertificate(String thumbprintAlgorithm, String thumbprint) throws BatchErrorException, IOException {
+ deleteCertificate(thumbprintAlgorithm, thumbprint, null);
+ }
+
+ /**
+ * Deletes the certificate from the Batch account.
+ * The delete operation requests that the certificate be deleted. The request puts the certificate in the {@link com.microsoft.azure.batch.protocol.models.CertificateState#DELETING Deleting} state.
+ * The Batch service will perform the actual certificate deletion without any further client action.
+ * You cannot delete a certificate if a resource (pool or compute node) is using it. Before you can delete a certificate, you must therefore make sure that:
+ *
+ * - The certificate is not associated with any pools.
+ * - The certificate is not installed on any compute nodes. (Even if you remove a certificate from a pool, it is not removed from existing compute nodes in that pool until they restart.)
+ *
+ * If you try to delete a certificate that is in use, the deletion fails. The certificate state changes to {@link com.microsoft.azure.batch.protocol.models.CertificateState#DELETE_FAILED Delete Failed}.
+ *
+ * You can use {@link #cancelDeleteCertificate(String, String)} to set the status back to Active if you decide that you want to continue using the certificate.
+ * @param thumbprintAlgorithm The algorithm used to derive the thumbprint parameter. This must be sha1.
+ * @param thumbprint The thumbprint of the certificate to delete.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void deleteCertificate(String thumbprintAlgorithm, String thumbprint, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ CertificateDeleteOptions options = new CertificateDeleteOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this.parentBatchClient.protocolLayer().certificates().delete(thumbprintAlgorithm, thumbprint, options);
+ }
+
+ /**
+ * Gets the specified {@link Certificate}.
+ *
+ * @param thumbprintAlgorithm The algorithm used to derive the thumbprint parameter. This must be sha1.
+ * @param thumbprint The thumbprint of the certificate to get.
+ * @return A {@link Certificate} containing information about the specified certificate in the Azure Batch account.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public Certificate getCertificate(String thumbprintAlgorithm, String thumbprint) throws BatchErrorException, IOException {
+ return getCertificate(thumbprintAlgorithm, thumbprint, null, null);
+ }
+
+ /**
+ * Gets the specified {@link Certificate}.
+ *
+ * @param thumbprintAlgorithm The algorithm used to derive the thumbprint parameter. This must be sha1.
+ * @param thumbprint The thumbprint of the certificate to get.
+ * @param detailLevel A {@link DetailLevel} used for controlling which properties are retrieved from the service.
+ * @return A {@link Certificate} containing information about the specified certificate in the Azure Batch account.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public Certificate getCertificate(String thumbprintAlgorithm, String thumbprint, DetailLevel detailLevel) throws BatchErrorException, IOException {
+ return getCertificate(thumbprintAlgorithm, thumbprint, detailLevel, null);
+ }
+
+ /**
+ * Gets the specified {@link Certificate}.
+ *
+ * @param thumbprintAlgorithm the algorithm used to derive the thumbprint parameter. This must be sha1.
+ * @param thumbprint the thumbprint of the certificate to get.
+ * @param detailLevel A {@link DetailLevel} used for controlling which properties are retrieved from the service.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return A {@link Certificate} containing information about the specified certificate in the Azure Batch account.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public Certificate getCertificate(String thumbprintAlgorithm, String thumbprint, DetailLevel detailLevel, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ CertificateGetOptions getCertificateOptions = new CertificateGetOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(getCertificateOptions);
+
+ return this.parentBatchClient.protocolLayer().certificates().get(thumbprintAlgorithm, thumbprint, getCertificateOptions);
+ }
+
+ /**
+ * Lists the {@link Certificate certificates} in the Batch account.
+ *
+ * @return A list of {@link Certificate} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listCertificates() throws BatchErrorException, IOException {
+ return listCertificates(null, null);
+ }
+
+ /**
+ * Lists the {@link Certificate certificates} in the Batch account.
+ *
+ * @param detailLevel A {@link DetailLevel} used for filtering the list and for controlling which properties are retrieved from the service.
+ * @return A list of {@link Certificate} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listCertificates(DetailLevel detailLevel) throws BatchErrorException, IOException {
+ return listCertificates(detailLevel, null);
+ }
+
+ /**
+ * Lists the {@link Certificate certificates} in the Batch account.
+ *
+ * @param detailLevel A {@link DetailLevel} used for filtering the list and for controlling which properties are retrieved from the service.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return A list of {@link Certificate} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listCertificates(DetailLevel detailLevel, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+
+ CertificateListOptions certificateListOptions = new CertificateListOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(certificateListOptions);
+
+ return this.parentBatchClient.protocolLayer().certificates().list(certificateListOptions);
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/ComputeNodeOperations.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/ComputeNodeOperations.java
new file mode 100644
index 000000000000..698b673a81e7
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/ComputeNodeOperations.java
@@ -0,0 +1,565 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch;
+
+import com.microsoft.azure.PagedList;
+import com.microsoft.azure.batch.protocol.models.*;
+import org.joda.time.DateTime;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Performs compute node-related operations on an Azure Batch account.
+ */
+public class ComputeNodeOperations implements IInheritedBehaviors {
+
+ private Collection _customBehaviors;
+
+ private BatchClient _parentBatchClient;
+
+ ComputeNodeOperations(BatchClient batchClient, Iterable inheritedBehaviors) {
+ _parentBatchClient = batchClient;
+
+ // inherit from instantiating parent
+ InternalHelper.InheritClientBehaviorsAndSetPublicProperty(this, inheritedBehaviors);
+ }
+
+ /**
+ * Gets a collection of behaviors that modify or customize requests to the Batch service.
+ *
+ * @return A collection of {@link BatchClientBehavior} instances.
+ */
+ @Override
+ public Collection customBehaviors() {
+ return _customBehaviors;
+ }
+
+ /**
+ * Sets a collection of behaviors that modify or customize requests to the Batch service.
+ *
+ * @param behaviors The collection of {@link BatchClientBehavior} instances.
+ * @return The current instance.
+ */
+ @Override
+ public IInheritedBehaviors withCustomBehaviors(Collection behaviors) {
+ _customBehaviors = behaviors;
+ return this;
+ }
+
+ /**
+ * Adds a user account to the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node where the user account will be created.
+ * @param user The user account to be created.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void addComputeNodeUser(String poolId, String nodeId, ComputeNodeUser user) throws BatchErrorException, IOException {
+ addComputeNodeUser(poolId, nodeId, user, null);
+ }
+
+ /**
+ * Adds a user account to the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node where the user account will be created.
+ * @param user The user account to be created.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void addComputeNodeUser(String poolId, String nodeId, ComputeNodeUser user, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ ComputeNodeAddUserOptions options = new ComputeNodeAddUserOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().computeNodes().addUser(poolId, nodeId, user, options);
+ }
+
+ /**
+ * Deletes the specified user account from the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node where the user account will be deleted.
+ * @param userName The name of the user account to be deleted.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void deleteComputeNodeUser(String poolId, String nodeId, String userName) throws BatchErrorException, IOException {
+ deleteComputeNodeUser(poolId, nodeId, userName, null);
+ }
+
+ /**
+ * Deletes the specified user account from the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node where the user account will be deleted.
+ * @param userName The name of the user account to be deleted.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void deleteComputeNodeUser(String poolId, String nodeId, String userName, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ ComputeNodeDeleteUserOptions options = new ComputeNodeDeleteUserOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().computeNodes().deleteUser(poolId, nodeId, userName, options);
+ }
+
+ /**
+ * Updates the specified user account on the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node where the user account will be updated.
+ * @param userName The name of the user account to update.
+ * @param password The password of the account. If null, the password is removed.
+ * @param expiryTime The time at which the account should expire. If null, the expiry time is replaced with its default value.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void updateComputeNodeUser(String poolId, String nodeId, String userName, String password, DateTime expiryTime) throws BatchErrorException, IOException {
+ updateComputeNodeUser(poolId, nodeId, userName, password, expiryTime, null);
+ }
+
+ /**
+ * Updates the specified user account on the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node where the user account will be updated.
+ * @param userName The name of the user account to update.
+ * @param password The password of the account. If null, the password is removed.
+ * @param expiryTime The time at which the account should expire. If null, the expiry time is replaced with its default value.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void updateComputeNodeUser(String poolId, String nodeId, String userName, String password, DateTime expiryTime, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ NodeUpdateUserParameter param = new NodeUpdateUserParameter();
+ param.withPassword(password);
+ param.withExpiryTime(expiryTime);
+
+ updateComputeNodeUser(poolId, nodeId, userName, param, additionalBehaviors);
+ }
+
+ /**
+ * Updates the specified user account on the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node where the user account will be updated.
+ * @param userName The name of the user account to update.
+ * @param sshPublicKey The SSH public key that can be used for remote login to the compute node. If null, the SSH public key is removed.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void updateComputeNodeUser(String poolId, String nodeId, String userName, String sshPublicKey) throws BatchErrorException, IOException {
+ updateComputeNodeUser(poolId, nodeId, userName, sshPublicKey, (Iterable)null);
+ }
+
+ /**
+ * Updates the specified user account on the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node where the user account will be updated.
+ * @param userName The name of the user account to update.
+ * @param sshPublicKey The SSH public key that can be used for remote login to the compute node. If null, the SSH public key is removed.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void updateComputeNodeUser(String poolId, String nodeId, String userName, String sshPublicKey, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ NodeUpdateUserParameter param = new NodeUpdateUserParameter();
+ param.withSshPublicKey(sshPublicKey);
+
+ updateComputeNodeUser(poolId, nodeId, userName, param, additionalBehaviors);
+ }
+
+ /**
+ * Updates the specified user account on the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node where the user account will be updated.
+ * @param userName The name of the user account to update.
+ * @param nodeUpdateUserParameter The set of changes to be made to the user account.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ private void updateComputeNodeUser(String poolId, String nodeId, String userName, NodeUpdateUserParameter nodeUpdateUserParameter, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ ComputeNodeUpdateUserOptions options = new ComputeNodeUpdateUserOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().computeNodes().updateUser(poolId, nodeId, userName, nodeUpdateUserParameter, options);
+ }
+
+ /**
+ * Gets the specified compute node.
+ *
+ * @param poolId The ID of the pool.
+ * @param nodeId the ID of the compute node to get from the pool.
+ * @return A {@link ComputeNode} containing information about the specified compute node.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public ComputeNode getComputeNode(String poolId, String nodeId) throws BatchErrorException, IOException {
+ return getComputeNode(poolId, nodeId, null, null);
+ }
+
+ /**
+ * Gets the specified compute node.
+ *
+ * @param poolId The ID of the pool.
+ * @param nodeId The ID of the compute node to get from the pool.
+ * @param detailLevel A {@link DetailLevel} used for controlling which properties are retrieved from the service.
+ * @return A {@link ComputeNode} containing information about the specified compute node.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public ComputeNode getComputeNode(String poolId, String nodeId, DetailLevel detailLevel) throws BatchErrorException, IOException {
+ return getComputeNode(poolId, nodeId, detailLevel, null);
+ }
+
+ /**
+ * Gets the specified compute node.
+ *
+ * @param poolId The ID of the pool.
+ * @param nodeId The ID of the compute node to get from the pool.
+ * @param detailLevel A {@link DetailLevel} used for controlling which properties are retrieved from the service.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return A {@link ComputeNode} containing information about the specified compute node.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public ComputeNode getComputeNode(String poolId, String nodeId, DetailLevel detailLevel, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ ComputeNodeGetOptions options = new ComputeNodeGetOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().computeNodes().get(poolId, nodeId, options);
+ }
+
+ /**
+ * Reboots the specified compute node.
+ * You can reboot a compute node only when it is in the {@link com.microsoft.azure.batch.protocol.models.ComputeNodeState#IDLE Idle} or {@link com.microsoft.azure.batch.protocol.models.ComputeNodeState#RUNNING Running} state.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node to reboot.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void rebootComputeNode(String poolId, String nodeId) throws BatchErrorException, IOException {
+ rebootComputeNode(poolId, nodeId, null, null);
+ }
+
+ /**
+ * Reboots the specified compute node.
+ * You can reboot a compute node only when it is in the {@link com.microsoft.azure.batch.protocol.models.ComputeNodeState#IDLE Idle} or {@link com.microsoft.azure.batch.protocol.models.ComputeNodeState#RUNNING Running} state.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node to reboot.
+ * @param nodeRebootOption Specifies when to reboot the node and what to do with currently running tasks.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void rebootComputeNode(String poolId, String nodeId, ComputeNodeRebootOption nodeRebootOption) throws BatchErrorException, IOException {
+ rebootComputeNode(poolId, nodeId, nodeRebootOption, null);
+ }
+
+ /**
+ * Reboots the specified compute node.
+ * You can reboot a compute node only when it is in the {@link com.microsoft.azure.batch.protocol.models.ComputeNodeState#IDLE Idle} or {@link com.microsoft.azure.batch.protocol.models.ComputeNodeState#RUNNING Running} state.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node to reboot.
+ * @param nodeRebootOption Specifies when to reboot the node and what to do with currently running tasks.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void rebootComputeNode(String poolId, String nodeId, ComputeNodeRebootOption nodeRebootOption, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ ComputeNodeRebootOptions options = new ComputeNodeRebootOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().computeNodes().reboot(poolId, nodeId, nodeRebootOption, options);
+ }
+
+ /**
+ * Reinstalls the operating system on the specified compute node.
+ * You can reimage a compute node only when it is in the {@link com.microsoft.azure.batch.protocol.models.ComputeNodeState#IDLE Idle} or {@link com.microsoft.azure.batch.protocol.models.ComputeNodeState#RUNNING Running} state.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node to reimage.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void reimageComputeNode(String poolId, String nodeId) throws BatchErrorException, IOException {
+ reimageComputeNode(poolId, nodeId, null, null);
+ }
+
+ /**
+ * Reinstalls the operating system on the specified compute node.
+ * You can reimage a compute node only when it is in the {@link com.microsoft.azure.batch.protocol.models.ComputeNodeState#IDLE Idle} or {@link com.microsoft.azure.batch.protocol.models.ComputeNodeState#RUNNING Running} state.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node to reimage.
+ * @param nodeReimageOption Specifies when to reimage the node and what to do with currently running tasks.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void reimageComputeNode(String poolId, String nodeId, ComputeNodeReimageOption nodeReimageOption) throws BatchErrorException, IOException {
+ reimageComputeNode(poolId, nodeId, nodeReimageOption, null);
+ }
+
+ /**
+ * Reinstalls the operating system on the specified compute node.
+ * You can reimage a compute node only when it is in the {@link com.microsoft.azure.batch.protocol.models.ComputeNodeState#IDLE Idle} or {@link com.microsoft.azure.batch.protocol.models.ComputeNodeState#RUNNING Running} state.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node to reimage.
+ * @param nodeReimageOption Specifies when to reimage the node and what to do with currently running tasks.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void reimageComputeNode(String poolId, String nodeId, ComputeNodeReimageOption nodeReimageOption, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ ComputeNodeReimageOptions options = new ComputeNodeReimageOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().computeNodes().reimage(poolId, nodeId, nodeReimageOption, options);
+ }
+
+ /**
+ * Disables task scheduling on the specified compute node.
+ *
+ * @param poolId The ID of the pool.
+ * @param nodeId the ID of the compute node.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void disableComputeNodeScheduling(String poolId, String nodeId) throws BatchErrorException, IOException {
+ disableComputeNodeScheduling(poolId, nodeId, null, null);
+ }
+
+ /**
+ * Disables task scheduling on the specified compute node.
+ *
+ * @param poolId The ID of the pool.
+ * @param nodeId The ID of the compute node.
+ * @param nodeDisableSchedulingOption Specifies what to do with currently running tasks.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void disableComputeNodeScheduling(String poolId, String nodeId, DisableComputeNodeSchedulingOption nodeDisableSchedulingOption) throws BatchErrorException, IOException {
+ disableComputeNodeScheduling(poolId, nodeId, nodeDisableSchedulingOption, null);
+ }
+
+ /**
+ * Disables task scheduling on the specified compute node.
+ *
+ * @param poolId The ID of the pool.
+ * @param nodeId The ID of the compute node.
+ * @param nodeDisableSchedulingOption Specifies what to do with currently running tasks.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void disableComputeNodeScheduling(String poolId, String nodeId, DisableComputeNodeSchedulingOption nodeDisableSchedulingOption, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ ComputeNodeDisableSchedulingOptions options = new ComputeNodeDisableSchedulingOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().computeNodes().disableScheduling(poolId, nodeId, nodeDisableSchedulingOption, options);
+ }
+
+ /**
+ * Enables task scheduling on the specified compute node.
+ *
+ * @param poolId The ID of the pool.
+ * @param nodeId The ID of the compute node.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void enableComputeNodeScheduling(String poolId, String nodeId) throws BatchErrorException, IOException {
+ enableComputeNodeScheduling(poolId, nodeId, null);
+ }
+
+ /**
+ * Enables task scheduling on the specified compute node.
+ *
+ * @param poolId The ID of the pool.
+ * @param nodeId The ID of the compute node.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void enableComputeNodeScheduling(String poolId, String nodeId, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ ComputeNodeEnableSchedulingOptions options = new ComputeNodeEnableSchedulingOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().computeNodes().enableScheduling(poolId, nodeId, options);
+ }
+
+ /**
+ * Gets a Remote Desktop Protocol (RDP) file for the specified node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node for which to get a Remote Desktop file.
+ * @return The RDP file contents.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public String getComputeNodeRemoteDesktop(String poolId, String nodeId) throws BatchErrorException, IOException {
+ return getComputeNodeRemoteDesktop(poolId, nodeId, null);
+ }
+
+ /**
+ * Gets a Remote Desktop Protocol (RDP) file for the specified node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node for which to get a Remote Desktop file.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return The RDP file contents.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public String getComputeNodeRemoteDesktop(String poolId, String nodeId, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ ComputeNodeGetRemoteDesktopOptions options = new ComputeNodeGetRemoteDesktopOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ this._parentBatchClient.protocolLayer().computeNodes().getRemoteDesktop(poolId, nodeId, options, outputStream);
+ String rdpContent = outputStream.toString("UTF-8");
+ outputStream.close();
+ return rdpContent;
+ }
+
+ /**
+ * Gets the settings required for remote login to a compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node for which to get a remote login settings.
+ * @return The remote settings for the specified compute node.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public ComputeNodeGetRemoteLoginSettingsResult getComputeNodeRemoteLoginSettings(String poolId, String nodeId) throws BatchErrorException, IOException {
+ return getComputeNodeRemoteLoginSettings(poolId, nodeId, null);
+ }
+
+ /**
+ * Gets the settings required for remote login to a compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node for which to get a remote login settings.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return The remote login settings for the specified compute node.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public ComputeNodeGetRemoteLoginSettingsResult getComputeNodeRemoteLoginSettings(String poolId, String nodeId, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ ComputeNodeGetRemoteLoginSettingsOptions options = new ComputeNodeGetRemoteLoginSettingsOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().computeNodes().getRemoteLoginSettings(poolId, nodeId, options);
+ }
+
+ /**
+ * Lists the {@link ComputeNode compute nodes} of the specified pool.
+ *
+ * @param poolId The ID of the pool.
+ * @return A list of {@link ComputeNode} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listComputeNodes(String poolId) throws BatchErrorException, IOException {
+ return listComputeNodes(poolId, null, null);
+ }
+
+ /**
+ * Lists the {@link ComputeNode compute nodes} of the specified pool.
+ *
+ * @param poolId The ID of the pool.
+ * @param detailLevel A {@link DetailLevel} used for filtering the list and for controlling which properties are retrieved from the service.
+ * @return A list of {@link ComputeNode} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listComputeNodes(String poolId, DetailLevel detailLevel) throws BatchErrorException, IOException {
+ return listComputeNodes(poolId, detailLevel, null);
+ }
+
+ /**
+ * Lists the {@link ComputeNode compute nodes} of the specified pool.
+ *
+ * @param poolId The ID of the pool.
+ * @param detailLevel A {@link DetailLevel} used for filtering the list and for controlling which properties are retrieved from the service.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return A list of {@link ComputeNode} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listComputeNodes(String poolId, DetailLevel detailLevel, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ ComputeNodeListOptions options = new ComputeNodeListOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().computeNodes().list(poolId, options);
+ }
+
+ /**
+ * Upload Azure Batch service log files from the specified compute node to Azure Blob Storage.
+ * This is for gathering Azure Batch service log files in an automated fashion from nodes if you are experiencing an error and wish to escalate to Azure support. The Azure Batch service log files should be shared with Azure support to aid in debugging issues with the Batch service.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node from which you want to upload the Azure Batch service log files.
+ * @param containerUrl The URL of the container within Azure Blob Storage to which to upload the Batch Service log file(s).
+ * @param startTime The start of the time range from which to upload Batch Service log file(s).
+ * @return The result of uploading Batch service log files from a specific compute node.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public UploadBatchServiceLogsResult uploadBatchServiceLogs(String poolId, String nodeId, String containerUrl, DateTime startTime) throws BatchErrorException, IOException {
+ return uploadBatchServiceLogs(poolId, nodeId, containerUrl, startTime, null, null);
+
+ }
+
+ /**
+ * Upload Azure Batch service log files from the specified compute node to Azure Blob Storage.
+ * This is for gathering Azure Batch service log files in an automated fashion from nodes if you are experiencing an error and wish to escalate to Azure support. The Azure Batch service log files should be shared with Azure support to aid in debugging issues with the Batch service.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node from which you want to upload the Azure Batch service log files.
+ * @param containerUrl The URL of the container within Azure Blob Storage to which to upload the Batch Service log file(s).
+ * @param startTime The start of the time range from which to upload Batch Service log file(s).
+ * @param endTime The end of the time range from which to upload Batch Service log file(s).
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return The result of uploading Batch service log files from a specific compute node.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public UploadBatchServiceLogsResult uploadBatchServiceLogs(String poolId, String nodeId, String containerUrl, DateTime startTime, DateTime endTime, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ UploadBatchServiceLogsConfiguration configuration = new UploadBatchServiceLogsConfiguration();
+ configuration.withContainerUrl(containerUrl);
+ configuration.withStartTime(startTime);
+ configuration.withEndTime(endTime);
+
+ ComputeNodeUploadBatchServiceLogsOptions options = new ComputeNodeUploadBatchServiceLogsOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().computeNodes().uploadBatchServiceLogs(poolId, nodeId, configuration, options);
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/CreateTasksErrorException.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/CreateTasksErrorException.java
new file mode 100644
index 000000000000..3e7fafd4d9f8
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/CreateTasksErrorException.java
@@ -0,0 +1,49 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch;
+
+import com.microsoft.azure.batch.protocol.models.BatchErrorException;
+import com.microsoft.azure.batch.protocol.models.TaskAddParameter;
+import com.microsoft.azure.batch.protocol.models.TaskAddResult;
+
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+
+/**
+ * The exception that is thrown when the {@link TaskOperations#createTasks(String, List)} operation is terminated.
+ */
+public class CreateTasksErrorException extends BatchErrorException {
+
+ /**
+ * Initializes a new instance of the CreateTasksErrorException class.
+ *
+ * @param message The exception message.
+ * @param failureTaskList The list of {@link TaskAddResult} instances containing failure details for tasks that were not successfully created.
+ * @param pendingTaskList The list of {@link TaskAddParameter} instances containing the tasks that were not added, but for which the operation can be retried.
+ */
+ public CreateTasksErrorException(final String message, List failureTaskList, List pendingTaskList) {
+ super(message, null);
+ this.failureTaskList = unmodifiableList(failureTaskList);
+ this.pendingTaskList = unmodifiableList(pendingTaskList);
+ }
+
+ private List failureTaskList;
+
+ private List pendingTaskList;
+
+ /**
+ * @return The list of {@link TaskAddResult} instances containing failure details for tasks that were not successfully created.
+ */
+ public List failureTaskList() {
+ return failureTaskList;
+ }
+
+ /**
+ * @return The list of {@link TaskAddParameter} instances containing the tasks that were not added, but for which the operation can be retried.
+ */
+ public List pendingTaskList() {
+ return pendingTaskList;
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/DetailLevel.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/DetailLevel.java
new file mode 100644
index 000000000000..8feaf5820794
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/DetailLevel.java
@@ -0,0 +1,109 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch;
+
+/**
+ * Controls the amount of detail requested from the Azure Batch service when listing or
+ * retrieving resources.
+ */
+public class DetailLevel {
+
+ private String filterClause;
+
+ private String selectClause;
+
+ private String expandClause;
+
+ /**
+ * The builder class to initiate a {@link DetailLevel} instance.
+ */
+ public static class Builder {
+
+ private String filterClause;
+
+ private String selectClause;
+
+ private String expandClause;
+
+ /**
+ * Initializes a new instance of the Builder class.
+ */
+ public Builder() {}
+
+ /**
+ * Sets the OData filter clause. Used to restrict a list operation to items that match specified criteria.
+ *
+ * @param filter The filter clause.
+ * @return The Builder instance.
+ */
+ public Builder withFilterClause(String filter) {
+ this.filterClause = filter;
+ return this;
+ }
+
+ /**
+ * Sets the OData select clause. Used to retrieve only specific properties instead of all object properties.
+ *
+ * @param select The select clause.
+ * @return The Builder instance.
+ */
+ public Builder withSelectClause(String select) {
+ this.selectClause = select;
+ return this;
+ }
+
+ /**
+ * Sets the OData expand clause. Used to retrieve associated entities of the main entity being retrieved.
+ *
+ * @param expand The expand clause.
+ * @return The Builder instance.
+ */
+ public Builder withExpandClause(String expand) {
+ this.expandClause = expand;
+ return this;
+ }
+
+ /**
+ * Create a DetailLevel class instance.
+ *
+ * @return A DetailLevel instance.
+ */
+ public DetailLevel build() {
+ return new DetailLevel(this);
+ }
+ }
+
+ /**
+ * Gets the OData filter clause. Used to restrict a list operation to items that match specified criteria.
+ *
+ * @return The filter clause.
+ */
+ public String filterClause() {
+ return filterClause;
+ }
+
+ /**
+ * Gets the OData select clause. Used to retrieve only specific properties instead of all object properties.
+ *
+ * @return The select clause.
+ */
+ public String selectClause() {
+ return selectClause;
+ }
+
+ /**
+ * Gets the OData expand clause. Used to retrieve associated entities of the main entity being retrieved.
+ *
+ * @return The expand clause.
+ */
+ public String expandClause() {
+ return expandClause;
+ }
+
+ private DetailLevel(Builder b) {
+ this.selectClause = b.selectClause;
+ this.expandClause = b.expandClause;
+ this.filterClause = b.filterClause;
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/FileOperations.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/FileOperations.java
new file mode 100644
index 000000000000..439dacebe7bc
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/FileOperations.java
@@ -0,0 +1,401 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch;
+
+import com.microsoft.azure.PagedList;
+import com.microsoft.azure.batch.protocol.models.BatchErrorException;
+import com.microsoft.azure.batch.protocol.models.FileDeleteFromComputeNodeOptions;
+import com.microsoft.azure.batch.protocol.models.FileDeleteFromTaskOptions;
+import com.microsoft.azure.batch.protocol.models.FileGetFromComputeNodeOptions;
+import com.microsoft.azure.batch.protocol.models.FileGetFromTaskOptions;
+import com.microsoft.azure.batch.protocol.models.FileGetPropertiesFromComputeNodeHeaders;
+import com.microsoft.azure.batch.protocol.models.FileGetPropertiesFromComputeNodeOptions;
+import com.microsoft.azure.batch.protocol.models.FileGetPropertiesFromTaskHeaders;
+import com.microsoft.azure.batch.protocol.models.FileGetPropertiesFromTaskOptions;
+import com.microsoft.azure.batch.protocol.models.FileListFromComputeNodeOptions;
+import com.microsoft.azure.batch.protocol.models.FileListFromTaskOptions;
+import com.microsoft.azure.batch.protocol.models.FileProperties;
+import com.microsoft.azure.batch.protocol.models.NodeFile;
+import com.microsoft.rest.ServiceResponseWithHeaders;
+
+import java.io.*;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Performs file-related operations on an Azure Batch account.
+ */
+public class FileOperations implements IInheritedBehaviors {
+
+ private Collection _customBehaviors;
+
+ private final BatchClient _parentBatchClient;
+
+ FileOperations(BatchClient batchClient, Iterable inheritedBehaviors) {
+ _parentBatchClient = batchClient;
+
+ // inherit from instantiating parent
+ InternalHelper.InheritClientBehaviorsAndSetPublicProperty(this, inheritedBehaviors);
+ }
+
+ /**
+ * Gets a collection of behaviors that modify or customize requests to the Batch service.
+ *
+ * @return A collection of {@link BatchClientBehavior} instances.
+ */
+ @Override
+ public Collection customBehaviors() {
+ return _customBehaviors;
+ }
+
+ /**
+ * Sets a collection of behaviors that modify or customize requests to the Batch service.
+ *
+ * @param behaviors The collection of {@link BatchClientBehavior} instances.
+ * @return The current instance.
+ */
+ @Override
+ public IInheritedBehaviors withCustomBehaviors(Collection behaviors) {
+ _customBehaviors = behaviors;
+ return this;
+ }
+
+ /**
+ * Lists the files in the specified task's directory on its compute node.
+ *
+ * @param jobId The ID of the job.
+ * @param taskId The ID of the task.
+ * @return A list of {@link NodeFile} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listFilesFromTask(String jobId, String taskId) throws BatchErrorException, IOException {
+ return listFilesFromTask(jobId, taskId, null, null, null);
+ }
+
+ /**
+ * Lists the files in the specified task's directory on its compute node.
+ *
+ * @param jobId The ID of the job.
+ * @param taskId The ID of the task.
+ * @param recursive If true, performs a recursive list of all files of the task. If false or null, returns only the files in the root task directory.
+ * @param detailLevel A {@link DetailLevel} used for filtering the list and for controlling which properties are retrieved from the service.
+ * @return A list of {@link NodeFile} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listFilesFromTask(String jobId, String taskId, Boolean recursive, DetailLevel detailLevel) throws BatchErrorException, IOException {
+ return listFilesFromTask(jobId, taskId, recursive, detailLevel, null);
+ }
+
+ /**
+ * Lists the files in the specified task's directory on its compute node.
+ *
+ * @param jobId The ID of the job.
+ * @param taskId The ID of the task.
+ * @param recursive If true, performs a recursive list of all files of the task. If false or null, returns only the files in the root task directory.
+ * @param detailLevel A {@link DetailLevel} used for filtering the list and for controlling which properties are retrieved from the service.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return A list of {@link NodeFile} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listFilesFromTask(String jobId, String taskId, Boolean recursive, DetailLevel detailLevel, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ FileListFromTaskOptions options = new FileListFromTaskOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().files().listFromTask(jobId, taskId, recursive, options);
+ }
+
+ /**
+ * Lists files on the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node.
+ * @return A list of {@link NodeFile} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listFilesFromComputeNode(String poolId, String nodeId) throws BatchErrorException, IOException {
+ return listFilesFromComputeNode(poolId, nodeId, null, null, null);
+ }
+
+ /**
+ * Lists files on the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node.
+ * @param recursive If true, recursively lists all files on the compute node. If false or null, lists only the files in the compute node root directory.
+ * @param detailLevel A {@link DetailLevel} used for filtering the list and for controlling which properties are retrieved from the service.
+ * @return A list of {@link NodeFile} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listFilesFromComputeNode(String poolId, String nodeId, Boolean recursive, DetailLevel detailLevel) throws BatchErrorException, IOException {
+ return listFilesFromComputeNode(poolId, nodeId, recursive, detailLevel, null);
+ }
+
+ /**
+ * Lists files on the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node.
+ * @param recursive If true, recursively lists all files on the compute node. If false or null, lists only the files in the compute node root directory.
+ * @param detailLevel A {@link DetailLevel} used for filtering the list and for controlling which properties are retrieved from the service.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return A list of {@link NodeFile} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listFilesFromComputeNode(String poolId, String nodeId, Boolean recursive, DetailLevel detailLevel, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ FileListFromComputeNodeOptions options = new FileListFromComputeNodeOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().files().listFromComputeNode(poolId, nodeId, recursive, options);
+ }
+
+ /**
+ * Deletes the specified file from the specified task's directory on its compute node.
+ *
+ * @param jobId The ID of the job containing the task.
+ * @param taskId The ID of the task.
+ * @param fileName The name of the file to delete.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void deleteFileFromTask(String jobId, String taskId, String fileName) throws BatchErrorException, IOException {
+ deleteFileFromTask(jobId, taskId, fileName, null, null);
+ }
+
+ /**
+ * Deletes the specified file from the specified task's directory on its compute node.
+ *
+ * @param jobId The ID of the job containing the task.
+ * @param taskId The ID of the task.
+ * @param fileName The name of the file to delete.
+ * @param recursive If the file-path parameter represents a directory instead of a file, you can set the recursive parameter to true to delete the directory and all of the files and subdirectories in it. If recursive is false or null, then the directory must be empty or deletion will fail.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void deleteFileFromTask(String jobId, String taskId, String fileName, Boolean recursive) throws BatchErrorException, IOException {
+ deleteFileFromTask(jobId, taskId, fileName, recursive, null);
+ }
+
+ /**
+ * Deletes the specified file from the specified task's directory on its compute node.
+ *
+ * @param jobId The ID of the job containing the task.
+ * @param taskId The ID of the task.
+ * @param fileName The name of the file to delete.
+ * @param recursive If the file-path parameter represents a directory instead of a file, you can set the recursive parameter to true to delete the directory and all of the files and subdirectories in it. If recursive is false or null, then the directory must be empty or deletion will fail.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void deleteFileFromTask(String jobId, String taskId, String fileName, Boolean recursive, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ FileDeleteFromTaskOptions options = new FileDeleteFromTaskOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().files().deleteFromTask(jobId, taskId, fileName, recursive, options);
+ }
+
+ /**
+ * Deletes the specified file from the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node.
+ * @param fileName The name of the file to delete.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void deleteFileFromComputeNode(String poolId, String nodeId, String fileName) throws BatchErrorException, IOException {
+ deleteFileFromComputeNode(poolId, nodeId, fileName, null, null);
+ }
+
+ /**
+ * Deletes the specified file from the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node.
+ * @param fileName The name of the file to delete.
+ * @param recursive If the file-path parameter represents a directory instead of a file, you can set the recursive parameter to true to delete the directory and all of the files and subdirectories in it. If recursive is false or null, then the directory must be empty or deletion will fail.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void deleteFileFromComputeNode(String poolId, String nodeId, String fileName, Boolean recursive) throws BatchErrorException, IOException {
+ deleteFileFromComputeNode(poolId, nodeId, fileName, recursive, null);
+ }
+
+ /**
+ * Deletes the specified file from the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node.
+ * @param fileName The name of the file to delete.
+ * @param recursive If the file-path parameter represents a directory instead of a file, you can set the recursive parameter to true to delete the directory and all of the files and subdirectories in it. If recursive is false or null, then the directory must be empty or deletion will fail.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void deleteFileFromComputeNode(String poolId, String nodeId, String fileName, Boolean recursive, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ FileDeleteFromComputeNodeOptions options = new FileDeleteFromComputeNodeOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().files().deleteFromComputeNode(poolId, nodeId, fileName, recursive, options);
+ }
+
+ /**
+ * Downloads the specified file from the specified task's directory on its compute node.
+ *
+ * @param jobId The ID of the job containing the task.
+ * @param taskId The ID of the task.
+ * @param fileName The name of the file to download.
+ * @param outputStream A stream into which the file contents will be written.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void getFileFromTask(String jobId, String taskId, String fileName, OutputStream outputStream) throws BatchErrorException, IOException {
+ getFileFromTask(jobId, taskId, fileName, null, outputStream);
+ }
+
+ /**
+ * Downloads the specified file from the specified task's directory on its compute node.
+ *
+ * @param jobId The ID of the job containing the task.
+ * @param taskId The ID of the task.
+ * @param fileName The name of the file to download.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @param outputStream A stream into which the file contents will be written.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void getFileFromTask(String jobId, String taskId, String fileName, Iterable additionalBehaviors, OutputStream outputStream) throws BatchErrorException, IOException {
+ FileGetFromTaskOptions options = new FileGetFromTaskOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().files().getFromTask(jobId, taskId, fileName, options, outputStream);
+ }
+
+ /**
+ * Downloads the specified file from the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node.
+ * @param fileName The name of the file to download.
+ * @param outputStream A stream into which the file contents will be written.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void getFileFromComputeNode(String poolId, String nodeId, String fileName, OutputStream outputStream) throws BatchErrorException, IOException {
+ getFileFromComputeNode(poolId, nodeId, fileName, null, outputStream);
+ }
+
+ /**
+ * Downloads the specified file from the specified compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId The ID of the compute node.
+ * @param fileName The name of the file to download.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @param outputStream A stream into which the file contents will be written.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void getFileFromComputeNode(String poolId, String nodeId, String fileName, Iterable additionalBehaviors, OutputStream outputStream) throws BatchErrorException, IOException {
+ FileGetFromComputeNodeOptions options = new FileGetFromComputeNodeOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().files().getFromComputeNode(poolId, nodeId, fileName, options, outputStream);
+ }
+
+ /**
+ * Gets information about a file from the specified task's directory on its compute node.
+ *
+ * @param jobId The ID of the job containing the task.
+ * @param taskId The ID of the task.
+ * @param fileName The name of the file to retrieve.
+ * @return A {@link FileProperties} instance containing information about the file.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public FileProperties getFilePropertiesFromTask(String jobId, String taskId, String fileName) throws BatchErrorException, IOException {
+ return getFilePropertiesFromTask(jobId, taskId, fileName, null);
+ }
+
+ /**
+ * Gets information about a file from the specified task's directory on its compute node.
+ *
+ * @param jobId The ID of the job containing the task.
+ * @param taskId The ID of the task.
+ * @param fileName The name of the file to retrieve.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return A {@link FileProperties} instance containing information about the file.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public FileProperties getFilePropertiesFromTask(String jobId, String taskId, String fileName, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ FileGetPropertiesFromTaskOptions options = new FileGetPropertiesFromTaskOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ ServiceResponseWithHeaders response = this._parentBatchClient.protocolLayer().files().
+ getPropertiesFromTaskWithServiceResponseAsync(jobId, taskId, fileName, options).toBlocking().single();
+
+ return new FileProperties()
+ .withContentLength(response.headers().contentLength())
+ .withContentType(response.headers().contentType())
+ .withCreationTime(response.headers().ocpCreationTime())
+ .withLastModified(response.headers().lastModified())
+ .withFileMode(response.headers().ocpBatchFileMode());
+ }
+
+ /**
+ * Gets information about a file on a compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId the ID of the compute node.
+ * @param fileName The name of the file to retrieve.
+ * @return A {@link FileProperties} instance containing information about the file.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public FileProperties getFilePropertiesFromComputeNode(String poolId, String nodeId, String fileName) throws BatchErrorException, IOException {
+ return getFilePropertiesFromComputeNode(poolId, nodeId, fileName, null);
+ }
+
+ /**
+ * Gets information about a file on a compute node.
+ *
+ * @param poolId The ID of the pool that contains the compute node.
+ * @param nodeId the ID of the compute node.
+ * @param fileName The name of the file to retrieve.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return A {@link FileProperties} instance containing information about the file.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public FileProperties getFilePropertiesFromComputeNode(String poolId, String nodeId, String fileName, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ FileGetPropertiesFromComputeNodeOptions options = new FileGetPropertiesFromComputeNodeOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ ServiceResponseWithHeaders response = this._parentBatchClient.protocolLayer().files().
+ getPropertiesFromComputeNodeWithServiceResponseAsync(poolId, nodeId, fileName, options).toBlocking().single();
+
+ return new FileProperties()
+ .withContentLength(response.headers().contentLength())
+ .withContentType(response.headers().contentType())
+ .withCreationTime(response.headers().ocpCreationTime())
+ .withLastModified(response.headers().lastModified())
+ .withFileMode(response.headers().ocpBatchFileMode());
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/IInheritedBehaviors.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/IInheritedBehaviors.java
new file mode 100644
index 000000000000..530f1e4285d5
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/IInheritedBehaviors.java
@@ -0,0 +1,34 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch;
+
+import java.util.Collection;
+
+/**
+ * This interface defines methods and properties that are inherited from the instantiating parent object.
+ * Classes that implement this interface inherit behaviors when they are instantiated.
+ * In this model, the collections are independent but the members are shared references.
+ * Members of this collection alter or customize various behaviors of Azure Batch service client objects.
+ * These behaviors are generally inherited by any child class instances.
+ * Modifications are applied in the order of the collection.
+ * The last write wins.
+ */
+public interface IInheritedBehaviors {
+
+ /**
+ * Gets a collection of behaviors that modify or customize requests to the Batch service.
+ *
+ * @return A collection of {@link BatchClientBehavior} instances.
+ */
+ Collection customBehaviors();
+
+ /**
+ * Sets a collection of behaviors that modify or customize requests to the Batch service.
+ *
+ * @param behaviors The collection of {@link BatchClientBehavior} instances.
+ * @return The current instance.
+ */
+ IInheritedBehaviors withCustomBehaviors(Collection behaviors);
+
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/InternalHelper.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/InternalHelper.java
new file mode 100644
index 000000000000..d05c1aaa0e98
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/InternalHelper.java
@@ -0,0 +1,33 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Internal helper functions
+ */
+class InternalHelper {
+ /**
+ * Inherit the BatchClientBehavior classes from parent object
+ *
+ * @param inheritingObject the inherit object
+ * @param baseBehaviors base class behavior list
+ */
+ public static void InheritClientBehaviorsAndSetPublicProperty(IInheritedBehaviors inheritingObject, Iterable baseBehaviors) {
+ // implement inheritance of behaviors
+ List customBehaviors = new ArrayList<>();
+
+ // if there were any behaviors, pre-populate the collection (ie: inherit)
+ if (null != baseBehaviors)
+ {
+ for (BatchClientBehavior be : baseBehaviors)
+ customBehaviors.add(be);
+ }
+
+ // set the public property
+ inheritingObject.withCustomBehaviors(customBehaviors);
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/JobOperations.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/JobOperations.java
new file mode 100644
index 000000000000..873f9293d7bf
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/JobOperations.java
@@ -0,0 +1,599 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch;
+
+import com.microsoft.azure.PagedList;
+import com.microsoft.azure.batch.protocol.models.*;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Performs job-related operations on an Azure Batch account.
+ */
+public class JobOperations implements IInheritedBehaviors {
+
+ private Collection _customBehaviors;
+
+ private final BatchClient _parentBatchClient;
+
+ JobOperations(BatchClient batchClient, Collection inheritedBehaviors) {
+ _parentBatchClient = batchClient;
+
+ // inherit from instantiating parent
+ InternalHelper.InheritClientBehaviorsAndSetPublicProperty(this, inheritedBehaviors);
+ }
+
+ /**
+ * Gets a collection of behaviors that modify or customize requests to the Batch service.
+ *
+ * @return A collection of {@link BatchClientBehavior} instances.
+ */
+ @Override
+ public Collection customBehaviors() {
+ return _customBehaviors;
+ }
+
+ /**
+ * Sets a collection of behaviors that modify or customize requests to the Batch service.
+ *
+ * @param behaviors The collection of {@link BatchClientBehavior} instances.
+ * @return The current instance.
+ */
+ @Override
+ public IInheritedBehaviors withCustomBehaviors(Collection behaviors) {
+ _customBehaviors = behaviors;
+ return this;
+ }
+
+ /**
+ * Gets lifetime summary statistics for all of the jobs in the current account.
+ *
+ * @return The aggregated job statistics.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public JobStatistics getAllJobsLifetimeStatistics() throws BatchErrorException, IOException {
+ return getAllJobsLifetimeStatistics(null);
+ }
+
+ /**
+ * Gets lifetime summary statistics for all of the jobs in the current account.
+ *
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return The aggregated job statistics.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public JobStatistics getAllJobsLifetimeStatistics(Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobGetAllLifetimeStatisticsOptions options = new JobGetAllLifetimeStatisticsOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().jobs().getAllLifetimeStatistics(options);
+ }
+
+ /**
+ * Gets the specified {@link CloudJob}.
+ *
+ * @param jobId The ID of the job to get.
+ * @return A {@link CloudJob} containing information about the specified Azure Batch job.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public CloudJob getJob(String jobId) throws BatchErrorException, IOException {
+ return getJob(jobId, null, null);
+ }
+
+ /**
+ * Gets the specified {@link CloudJob}.
+ *
+ * @param jobId The ID of the job to get.
+ * @param detailLevel A {@link DetailLevel} used for controlling which properties are retrieved from the service.
+ * @return A {@link CloudJob} containing information about the specified Azure Batch job.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public CloudJob getJob(String jobId, DetailLevel detailLevel) throws BatchErrorException, IOException {
+ return getJob(jobId, detailLevel, null);
+ }
+
+ /**
+ * Gets the specified {@link CloudJob}.
+ *
+ * @param jobId The ID of the job to get.
+ * @param detailLevel A {@link DetailLevel} used for controlling which properties are retrieved from the service.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return A {@link CloudJob} containing information about the specified Azure Batch job.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public CloudJob getJob(String jobId, DetailLevel detailLevel, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobGetOptions getJobOptions = new JobGetOptions();
+
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(getJobOptions);
+
+ return this._parentBatchClient.protocolLayer().jobs().get(jobId, getJobOptions);
+ }
+
+ /**
+ * Lists the {@link CloudJob jobs} in the Batch account.
+ *
+ * @return A list of {@link CloudJob} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listJobs() throws BatchErrorException, IOException {
+ return listJobs(null, (Iterable) null);
+ }
+
+ /**
+ * Lists the {@link CloudJob jobs} in the Batch account.
+ *
+ * @param detailLevel A {@link DetailLevel} used for filtering the list and for controlling which properties are retrieved from the service.
+ * @return A list of {@link CloudJob} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listJobs(DetailLevel detailLevel) throws BatchErrorException, IOException {
+ return listJobs(detailLevel, null);
+ }
+
+ /**
+ * Lists the {@link CloudJob jobs} in the Batch account.
+ *
+ * @param detailLevel A {@link DetailLevel} used for filtering the list and for controlling which properties are retrieved from the service.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return A list of {@link CloudJob} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listJobs(DetailLevel detailLevel, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobListOptions jobListOptions = new JobListOptions();
+
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(jobListOptions);
+
+ return this._parentBatchClient.protocolLayer().jobs().list(jobListOptions);
+ }
+
+ /**
+ * Lists the {@link CloudJob jobs} created under the specified job schedule.
+ *
+ * @param jobScheduleId The ID of job schedule.
+ * @return A list of {@link CloudJob} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listJobs(String jobScheduleId) throws BatchErrorException, IOException {
+ return listJobs(jobScheduleId, null, null);
+ }
+
+ /**
+ * Lists the {@link CloudJob jobs} created under the specified job schedule.
+ *
+ * @param jobScheduleId The ID of job schedule.
+ * @param detailLevel A {@link DetailLevel} used for filtering the list and for controlling which properties are retrieved from the service.
+ * @return A list of {@link CloudJob} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listJobs(String jobScheduleId, DetailLevel detailLevel) throws BatchErrorException, IOException {
+ return listJobs(jobScheduleId, detailLevel, null);
+ }
+
+ /**
+ * Lists the {@link CloudJob jobs} created under the specified jobSchedule.
+ *
+ * @param jobScheduleId The ID of jobSchedule.
+ * @param detailLevel A {@link DetailLevel} used for filtering the list and for controlling which properties are retrieved from the service.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return A list of {@link CloudJob} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listJobs(String jobScheduleId, DetailLevel detailLevel, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobListFromJobScheduleOptions jobListOptions = new JobListFromJobScheduleOptions();
+
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(jobListOptions);
+
+ return this._parentBatchClient.protocolLayer().jobs().listFromJobSchedule(jobScheduleId, jobListOptions);
+ }
+
+ /**
+ * Lists the status of {@link JobPreparationTask} and {@link JobReleaseTask} tasks for the specified job.
+ *
+ * @param jobId The ID of the job.
+ * @return A list of {@link JobPreparationAndReleaseTaskExecutionInformation} instances.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listPreparationAndReleaseTaskStatus(String jobId) throws BatchErrorException, IOException {
+ return listPreparationAndReleaseTaskStatus(jobId, null);
+ }
+
+ /**
+ * Lists the status of {@link JobPreparationTask} and {@link JobReleaseTask} tasks for the specified job.
+ *
+ * @param jobId The ID of the job.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return A list of {@link JobPreparationAndReleaseTaskExecutionInformation} instances.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listPreparationAndReleaseTaskStatus(String jobId, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobListPreparationAndReleaseTaskStatusOptions jobListOptions = new JobListPreparationAndReleaseTaskStatusOptions();
+
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(jobListOptions);
+
+ return this._parentBatchClient.protocolLayer().jobs().listPreparationAndReleaseTaskStatus(jobId, jobListOptions);
+ }
+
+ /**
+ * Adds a job to the Batch account.
+ *
+ * @param jobId The ID of the job to be added.
+ * @param poolInfo Specifies how a job should be assigned to a pool.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void createJob(String jobId, PoolInformation poolInfo) throws BatchErrorException, IOException {
+ createJob(jobId, poolInfo, null);
+ }
+
+ /**
+ * Adds a job to the Batch account.
+ *
+ * @param jobId The ID of the job to be added.
+ * @param poolInfo Specifies how a job should be assigned to a pool.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void createJob(String jobId, PoolInformation poolInfo, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobAddParameter param = new JobAddParameter()
+ .withId(jobId)
+ .withPoolInfo(poolInfo);
+
+ createJob(param, additionalBehaviors);
+ }
+
+ /**
+ * Adds a job to the Batch account.
+ *
+ * @param job The job to be added.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void createJob(JobAddParameter job) throws BatchErrorException, IOException {
+ createJob(job, null);
+ }
+
+ /**
+ * Adds a job to the Batch account.
+ *
+ * @param job The job to be added.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void createJob(JobAddParameter job, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobAddOptions options = new JobAddOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().jobs().add(job, options);
+ }
+
+ /**
+ * Deletes the specified job.
+ *
+ * @param jobId The ID of the job.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void deleteJob(String jobId) throws BatchErrorException, IOException {
+ deleteJob(jobId, null);
+ }
+
+ /**
+ * Deletes the specified job.
+ *
+ * @param jobId The ID of the job.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void deleteJob(String jobId, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobDeleteOptions options = new JobDeleteOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().jobs().delete(jobId, options);
+ }
+
+ /**
+ * Terminates the specified job, marking it as completed.
+ *
+ * @param jobId The ID of the job.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void terminateJob(String jobId) throws BatchErrorException, IOException {
+ terminateJob(jobId, null, null);
+ }
+
+ /**
+ * Terminates the specified job, marking it as completed.
+ *
+ * @param jobId The ID of the job.
+ * @param terminateReason The message to describe the reason the job has terminated. This text will appear when you call {@link JobExecutionInformation#terminateReason()}.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void terminateJob(String jobId, String terminateReason) throws BatchErrorException, IOException {
+ terminateJob(jobId, terminateReason, null);
+ }
+
+ /**
+ * Terminates the specified job, marking it as completed.
+ *
+ * @param jobId The ID of the job.
+ * @param terminateReason The message to describe the reason the job has terminated. This text will appear when you call {@link JobExecutionInformation#terminateReason()}.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void terminateJob(String jobId, String terminateReason, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobTerminateOptions options = new JobTerminateOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().jobs().terminate(jobId, terminateReason, options);
+ }
+
+ /**
+ * Enables the specified job, allowing new tasks to run.
+ *
+ * @param jobId The ID of the job.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void enableJob(String jobId) throws BatchErrorException, IOException {
+ enableJob(jobId, null);
+ }
+
+ /**
+ * Enables the specified job, allowing new tasks to run.
+ *
+ * @param jobId The ID of the job.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void enableJob(String jobId, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobEnableOptions options = new JobEnableOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().jobs().enable(jobId, options);
+ }
+
+ /**
+ * Disables the specified job. Disabled jobs do not run new tasks, but may be re-enabled later.
+ *
+ * @param jobId The ID of the job.
+ * @param disableJobOption Specifies what to do with running tasks associated with the job.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void disableJob(String jobId, DisableJobOption disableJobOption) throws BatchErrorException, IOException {
+ disableJob(jobId, disableJobOption, null);
+ }
+
+ /**
+ * Disables the specified job. Disabled jobs do not run new tasks, but may be re-enabled later.
+ *
+ * @param jobId The ID of the job.
+ * @param disableJobOption Specifies what to do with running tasks associated with the job.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void disableJob(String jobId, DisableJobOption disableJobOption, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobDisableOptions options = new JobDisableOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().jobs().disable(jobId, disableJobOption, options);
+ }
+
+ /**
+ * Updates the specified job.
+ * This method performs a full replace of all updatable properties of the job. For example, if the constraints parameter is null, then the Batch service removes the job's existing constraints and replaces them with the default constraints.
+ *
+ * @param jobId The ID of the job.
+ * @param poolInfo The pool on which the Batch service runs the job's tasks. You may change the pool for a job only when the job is disabled. If you specify an autoPoolSpecification specification in the poolInfo, only the keepAlive property can be updated, and then only if the auto pool has a poolLifetimeOption of job.
+ * @param priority The priority of the job. Priority values can range from -1000 to 1000, with -1000 being the lowest priority and 1000 being the highest priority. If null, it is set to the default value 0.
+ * @param constraints The execution constraints for the job. If null, the constraints are cleared.
+ * @param onAllTasksComplete Specifies an action the Batch service should take when all tasks in the job are in the completed state.
+ * @param metadata A list of name-value pairs associated with the job as metadata. If null, it takes the default value of an empty list; in effect, any existing metadata is deleted.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void updateJob(String jobId, PoolInformation poolInfo, Integer priority, JobConstraints constraints, OnAllTasksComplete onAllTasksComplete,
+ List metadata) throws BatchErrorException, IOException {
+ updateJob(jobId, poolInfo, priority, constraints, onAllTasksComplete, metadata, null);
+ }
+
+ /**
+ * Updates the specified job.
+ * This method performs a full replace of all updatable properties of the job. For example, if the constraints parameter is null, then the Batch service removes the job's existing constraints and replaces them with the default constraints.
+ *
+ * @param jobId The ID of the job.
+ * @param poolInfo The pool on which the Batch service runs the job's tasks. You may change the pool for a job only when the job is disabled. If you specify an autoPoolSpecification specification in the poolInfo, only the keepAlive property can be updated, and then only if the auto pool has a poolLifetimeOption of job.
+ * @param priority The priority of the job. Priority values can range from -1000 to 1000, with -1000 being the lowest priority and 1000 being the highest priority. If null, it is set to the default value 0.
+ * @param constraints The execution constraints for the job. If null, the constraints are cleared.
+ * @param onAllTasksComplete Specifies an action the Batch service should take when all tasks in the job are in the completed state.
+ * @param metadata A list of name-value pairs associated with the job as metadata. If null, it takes the default value of an empty list; in effect, any existing metadata is deleted.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void updateJob(String jobId, PoolInformation poolInfo, Integer priority, JobConstraints constraints, OnAllTasksComplete onAllTasksComplete,
+ List metadata, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobUpdateOptions options = new JobUpdateOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ JobUpdateParameter param = new JobUpdateParameter()
+ .withPriority(priority)
+ .withPoolInfo(poolInfo)
+ .withConstraints(constraints)
+ .withOnAllTasksComplete(onAllTasksComplete)
+ .withMetadata(metadata);
+
+ this._parentBatchClient.protocolLayer().jobs().update(jobId, param, options);
+ }
+
+ /**
+ * Updates the specified job.
+ * This method only replaces the properties specified with non-null values.
+ *
+ * @param jobId The ID of the job.
+ * @param poolInfo The pool on which the Batch service runs the job's tasks. You may change the pool for a job only when the job is disabled. If you specify an autoPoolSpecification specification in the poolInfo, only the keepAlive property can be updated, and then only if the auto pool has a poolLifetimeOption of job. If null, the job continues to run on its current pool.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void patchJob(String jobId, PoolInformation poolInfo) throws BatchErrorException, IOException {
+ patchJob(jobId, poolInfo, null, null, null, null, null);
+ }
+
+ /**
+ * Updates the specified job.
+ * This method only replaces the properties specified with non-null values.
+ *
+ * @param jobId The ID of the job.
+ * @param onAllTasksComplete Specifies an action the Batch service should take when all tasks in the job are in the completed state.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void patchJob(String jobId, OnAllTasksComplete onAllTasksComplete) throws BatchErrorException, IOException {
+ patchJob(jobId, null, null, null, onAllTasksComplete, null, null);
+ }
+
+ /**
+ * Updates the specified job.
+ * This method only replaces the properties specified with non-null values.
+ *
+ * @param jobId The ID of the job.
+ * @param poolInfo The pool on which the Batch service runs the job's tasks. You may change the pool for a job only when the job is disabled. If you specify an autoPoolSpecification specification in the poolInfo, only the keepAlive property can be updated, and then only if the auto pool has a poolLifetimeOption of job. If null, the job continues to run on its current pool.
+ * @param priority The priority of the job. Priority values can range from -1000 to 1000, with -1000 being the lowest priority and 1000 being the highest priority. If null, the priority of the job is left unchanged.
+ * @param constraints The execution constraints for the job. If null, the existing execution constraints are left unchanged.
+ * @param onAllTasksComplete Specifies an action the Batch service should take when all tasks in the job are in the completed state.
+ * @param metadata A list of name-value pairs associated with the job as metadata. If null, the existing job metadata is left unchanged.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void patchJob(String jobId, PoolInformation poolInfo, Integer priority, JobConstraints constraints, OnAllTasksComplete onAllTasksComplete,
+ List metadata) throws BatchErrorException, IOException {
+ patchJob(jobId, poolInfo, priority, constraints, onAllTasksComplete, metadata, null);
+ }
+
+ /**
+ * Updates the specified job.
+ * This method only replaces the properties specified with non-null values.
+ *
+ * @param jobId The ID of the job.
+ * @param poolInfo The pool on which the Batch service runs the job's tasks. You may change the pool for a job only when the job is disabled. If you specify an autoPoolSpecification specification in the poolInfo, only the keepAlive property can be updated, and then only if the auto pool has a poolLifetimeOption of job. If null, the job continues to run on its current pool.
+ * @param priority The priority of the job. Priority values can range from -1000 to 1000, with -1000 being the lowest priority and 1000 being the highest priority. If null, the priority of the job is left unchanged.
+ * @param constraints The execution constraints for the job. If null, the existing execution constraints are left unchanged.
+ * @param onAllTasksComplete Specifies an action the Batch service should take when all tasks in the job are in the completed state.
+ * @param metadata A list of name-value pairs associated with the job as metadata. If null, the existing job metadata is left unchanged.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void patchJob(String jobId, PoolInformation poolInfo, Integer priority, JobConstraints constraints, OnAllTasksComplete onAllTasksComplete,
+ List metadata, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobPatchParameter param = new JobPatchParameter()
+ .withPriority(priority)
+ .withPoolInfo(poolInfo)
+ .withConstraints(constraints)
+ .withOnAllTasksComplete(onAllTasksComplete)
+ .withMetadata(metadata);
+
+ patchJob(jobId, param, additionalBehaviors);
+ }
+
+ /**
+ * Updates the specified job.
+ * This method only replaces the properties specified with non-null values.
+ *
+ * @param jobId The ID of the job.
+ * @param jobPatchParameter The set of changes to be made to a job.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void patchJob(String jobId, JobPatchParameter jobPatchParameter) throws BatchErrorException, IOException {
+ patchJob(jobId, jobPatchParameter, null);
+ }
+
+ /**
+ * Updates the specified job.
+ * This method only replaces the properties specified with non-null values.
+ *
+ * @param jobId The ID of the job.
+ * @param jobPatchParameter The parameter to update the job.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void patchJob(String jobId, JobPatchParameter jobPatchParameter, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobPatchOptions options = new JobPatchOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().jobs().patch(jobId, jobPatchParameter, options);
+ }
+
+ /**
+ * Gets the task counts for the specified job.
+ * Task counts provide a count of the tasks by active, running or completed task state, and a count of tasks which succeeded or failed. Tasks in the preparing state are counted as running.
+ *
+ * @param jobId The ID of the job.
+ * @throws BatchErrorException thrown if the request is rejected by server
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ * @return the TaskCounts object if successful.
+ */
+ public TaskCounts getTaskCounts(String jobId) throws BatchErrorException, IOException {
+ return getTaskCounts(jobId, null);
+ }
+
+ /**
+ * Gets the task counts for the specified job.
+ * Task counts provide a count of the tasks by active, running or completed task state, and a count of tasks which succeeded or failed. Tasks in the preparing state are counted as running.
+ *
+ * @param jobId The ID of the job.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException thrown if the request is rejected by server
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ * @return the TaskCounts object if successful.
+ */
+ public TaskCounts getTaskCounts(String jobId, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobGetTaskCountsOptions options = new JobGetTaskCountsOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().jobs().getTaskCounts(jobId, options);
+ }
+
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/JobScheduleOperations.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/JobScheduleOperations.java
new file mode 100644
index 000000000000..9687557e7d25
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/JobScheduleOperations.java
@@ -0,0 +1,437 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch;
+
+import com.microsoft.azure.PagedList;
+import com.microsoft.azure.batch.protocol.models.*;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Performs job schedule-related operations on an Azure Batch account.
+ */
+public class JobScheduleOperations implements IInheritedBehaviors {
+
+ private Collection _customBehaviors;
+
+ private final BatchClient _parentBatchClient;
+
+ JobScheduleOperations(BatchClient batchClient, Iterable inheritedBehaviors) {
+ _parentBatchClient = batchClient;
+
+ // inherit from instantiating parent
+ InternalHelper.InheritClientBehaviorsAndSetPublicProperty(this, inheritedBehaviors);
+ }
+
+ /**
+ * Gets a collection of behaviors that modify or customize requests to the Batch service.
+ *
+ * @return A collection of {@link BatchClientBehavior} instances.
+ */
+ @Override
+ public Collection customBehaviors() {
+ return _customBehaviors;
+ }
+
+ /**
+ * Sets a collection of behaviors that modify or customize requests to the Batch service.
+ *
+ * @param behaviors The collection of {@link BatchClientBehavior} instances.
+ * @return The current instance.
+ */
+ @Override
+ public IInheritedBehaviors withCustomBehaviors(Collection behaviors) {
+ _customBehaviors = behaviors;
+ return this;
+ }
+
+ /**
+ * Checks whether the specified job schedule exists.
+ *
+ * @param jobScheduleId The ID of the job schedule which you want to check.
+ * @return True if the specified job schedule exists; otherwise, false.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public boolean existsJobSchedule(String jobScheduleId) throws BatchErrorException, IOException {
+ return existsJobSchedule(jobScheduleId, null);
+ }
+
+ /**
+ * Checks whether the specified job schedule exists.
+ *
+ * @param jobScheduleId The ID of the job schedule which you want to check.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return True if the specified job schedule exists; otherwise, false.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public boolean existsJobSchedule(String jobScheduleId, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobScheduleExistsOptions options = new JobScheduleExistsOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().jobSchedules().exists(jobScheduleId, options);
+ }
+
+ /**
+ * Deletes the specified job schedule.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void deleteJobSchedule(String jobScheduleId) throws BatchErrorException, IOException {
+ deleteJobSchedule(jobScheduleId, null);
+ }
+
+ /**
+ * Deletes the specified job schedule.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void deleteJobSchedule(String jobScheduleId, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobScheduleDeleteOptions options = new JobScheduleDeleteOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().jobSchedules().delete(jobScheduleId, options);
+ }
+
+ /**
+ * Gets the specified {@link CloudJobSchedule}.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @return A {@link CloudJobSchedule} containing information about the specified Azure Batch job schedule.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public CloudJobSchedule getJobSchedule(String jobScheduleId) throws BatchErrorException, IOException {
+ return getJobSchedule(jobScheduleId, null, null);
+ }
+
+ /**
+ * Gets the specified {@link CloudJobSchedule}.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @param detailLevel A {@link DetailLevel} used for controlling which properties are retrieved from the service.
+ * @return A {@link CloudJobSchedule} containing information about the specified Azure Batch job schedule.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public CloudJobSchedule getJobSchedule(String jobScheduleId, DetailLevel detailLevel) throws BatchErrorException, IOException {
+ return getJobSchedule(jobScheduleId, detailLevel, null);
+ }
+
+ /**
+ * Gets the specified {@link CloudJobSchedule}.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @param detailLevel A {@link DetailLevel} used for controlling which properties are retrieved from the service.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return A {@link CloudJobSchedule} containing information about the specified Azure Batch job schedule.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public CloudJobSchedule getJobSchedule(String jobScheduleId, DetailLevel detailLevel, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobScheduleGetOptions options = new JobScheduleGetOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().jobSchedules().get(jobScheduleId, options);
+ }
+
+ /**
+ * Updates the specified job schedule.
+ * This method only replaces the properties specified with non-null values.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @param schedule The schedule according to which jobs will be created. If null, any existing schedule is left unchanged.
+ * @param jobSpecification The details of the jobs to be created on this schedule. Updates affect only jobs that are started after the update has taken place. Any currently active job continues with the older specification. If null, the existing job specification is left unchanged.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void patchJobSchedule(String jobScheduleId, Schedule schedule, JobSpecification jobSpecification) throws BatchErrorException, IOException {
+ patchJobSchedule(jobScheduleId, schedule, jobSpecification, null, null);
+ }
+
+ /**
+ * Updates the specified job schedule.
+ * This method only replaces the properties specified with non-null values.
+ *
+ * @param jobScheduleId The ID of the job schedule. If null, any existing schedule is left unchanged.
+ * @param schedule The schedule according to which jobs will be created.
+ * @param jobSpecification The details of the jobs to be created on this schedule. Updates affect only jobs that are started after the update has taken place. Any currently active job continues with the older specification. If null, the existing job specification is left unchanged.
+ * @param metadata A list of name-value pairs associated with the job schedule as metadata. If null, the existing metadata are left unchanged.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void patchJobSchedule(String jobScheduleId, Schedule schedule, JobSpecification jobSpecification, List metadata) throws BatchErrorException, IOException {
+ patchJobSchedule(jobScheduleId, schedule, jobSpecification, metadata, null);
+ }
+
+ /**
+ * Updates the specified job schedule.
+ * This method only replaces the properties specified with non-null values.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @param schedule The schedule according to which jobs will be created. If null, any existing schedule is left unchanged.
+ * @param jobSpecification The details of the jobs to be created on this schedule. Updates affect only jobs that are started after the update has taken place. Any currently active job continues with the older specification. If null, the existing job specification is left unchanged.
+ * @param metadata A list of name-value pairs associated with the job schedule as metadata. If null, the existing metadata are left unchanged.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void patchJobSchedule(String jobScheduleId, Schedule schedule, JobSpecification jobSpecification, List metadata, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobSchedulePatchOptions options = new JobSchedulePatchOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ JobSchedulePatchParameter param = new JobSchedulePatchParameter()
+ .withJobSpecification(jobSpecification)
+ .withMetadata(metadata)
+ .withSchedule(schedule);
+ this._parentBatchClient.protocolLayer().jobSchedules().patch(jobScheduleId, param, options);
+ }
+
+ /**
+ * Updates the specified job schedule.
+ * This method performs a full replace of all the updatable properties of the job schedule. For example, if the schedule parameter is null, then the Batch service removes the job schedule’s existing schedule and replaces it with the default schedule.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @param schedule The schedule according to which jobs will be created. If null, it is equivalent to passing the default schedule: that is, a single job scheduled to run immediately.
+ * @param jobSpecification The details of the jobs to be created on this schedule. Updates affect only jobs that are started after the update has taken place. Any currently active job continues with the older specification.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void updateJobSchedule(String jobScheduleId, Schedule schedule, JobSpecification jobSpecification) throws BatchErrorException, IOException {
+ updateJobSchedule(jobScheduleId, schedule, jobSpecification, null, null);
+ }
+
+ /**
+ * Updates the specified job schedule.
+ * This method performs a full replace of all the updatable properties of the job schedule. For example, if the schedule parameter is null, then the Batch service removes the job schedule’s existing schedule and replaces it with the default schedule.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @param schedule The schedule according to which jobs will be created. If null, it is equivalent to passing the default schedule: that is, a single job scheduled to run immediately.
+ * @param jobSpecification The details of the jobs to be created on this schedule. Updates affect only jobs that are started after the update has taken place. Any currently active job continues with the older specification.
+ * @param metadata A list of name-value pairs associated with the job schedule as metadata. If null, it takes the default value of an empty list; in effect, any existing metadata is deleted.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void updateJobSchedule(String jobScheduleId, Schedule schedule, JobSpecification jobSpecification, List metadata) throws BatchErrorException, IOException {
+ updateJobSchedule(jobScheduleId, schedule, jobSpecification, metadata, null);
+ }
+
+ /**
+ * Updates the specified job schedule.
+ * This method performs a full replace of all the updatable properties of the job schedule. For example, if the schedule parameter is null, then the Batch service removes the job schedule’s existing schedule and replaces it with the default schedule.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @param schedule The schedule according to which jobs will be created. If null, it is equivalent to passing the default schedule: that is, a single job scheduled to run immediately.
+ * @param jobSpecification The details of the jobs to be created on this schedule. Updates affect only jobs that are started after the update has taken place. Any currently active job continues with the older specification.
+ * @param metadata A list of name-value pairs associated with the job schedule as metadata. If null, it takes the default value of an empty list; in effect, any existing metadata is deleted.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void updateJobSchedule(String jobScheduleId, Schedule schedule, JobSpecification jobSpecification, List metadata, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobScheduleUpdateOptions options = new JobScheduleUpdateOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ JobScheduleUpdateParameter param = new JobScheduleUpdateParameter()
+ .withJobSpecification(jobSpecification)
+ .withMetadata(metadata)
+ .withSchedule(schedule);
+ this._parentBatchClient.protocolLayer().jobSchedules().update(jobScheduleId, param, options);
+ }
+
+ /**
+ * Disables the specified job schedule. Disabled schedules do not create new jobs, but may be re-enabled later.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void disableJobSchedule(String jobScheduleId) throws BatchErrorException, IOException {
+ disableJobSchedule(jobScheduleId, null);
+ }
+
+ /**
+ * Disables the specified job schedule. Disabled schedules do not create new jobs, but may be re-enabled later.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void disableJobSchedule(String jobScheduleId, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobScheduleDisableOptions options = new JobScheduleDisableOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().jobSchedules().disable(jobScheduleId, options);
+ }
+
+ /**
+ * Enables the specified job schedule, allowing jobs to be created according to its {@link Schedule}.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void enableJobSchedule(String jobScheduleId) throws BatchErrorException, IOException {
+ enableJobSchedule(jobScheduleId, null);
+ }
+
+ /**
+ * Enables the specified job schedule, allowing jobs to be created according to its {@link Schedule}.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void enableJobSchedule(String jobScheduleId, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobScheduleEnableOptions options = new JobScheduleEnableOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().jobSchedules().enable(jobScheduleId, options);
+ }
+
+ /**
+ * Terminates the specified job schedule.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void terminateJobSchedule(String jobScheduleId) throws BatchErrorException, IOException {
+ terminateJobSchedule(jobScheduleId, null);
+ }
+
+ /**
+ * Terminates the specified job schedule.
+ *
+ * @param jobScheduleId The ID of the job schedule.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void terminateJobSchedule(String jobScheduleId, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobScheduleTerminateOptions options = new JobScheduleTerminateOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().jobSchedules().terminate(jobScheduleId, options);
+ }
+
+ /**
+ * Adds a job schedule to the Batch account.
+ *
+ * @param jobScheduleId A string that uniquely identifies the job schedule within the account.
+ * @param schedule The schedule according to which jobs will be created.
+ * @param jobSpecification Details about the jobs to be created on this schedule.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void createJobSchedule(String jobScheduleId, Schedule schedule, JobSpecification jobSpecification) throws BatchErrorException, IOException {
+ createJobSchedule(jobScheduleId, schedule, jobSpecification, null);
+ }
+
+ /**
+ * Adds a job schedule to the Batch account.
+ *
+ * @param jobScheduleId A string that uniquely identifies the job schedule within the account.
+ * @param schedule The schedule according to which jobs will be created.
+ * @param jobSpecification Details about the jobs to be created on this schedule.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void createJobSchedule(String jobScheduleId, Schedule schedule, JobSpecification jobSpecification, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobScheduleAddParameter param = new JobScheduleAddParameter()
+ .withJobSpecification(jobSpecification)
+ .withSchedule(schedule)
+ .withId(jobScheduleId);
+ createJobSchedule(param, additionalBehaviors);
+ }
+
+ /**
+ * Adds a job schedule to the Batch account.
+ *
+ * @param jobSchedule The job schedule to be added.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void createJobSchedule(JobScheduleAddParameter jobSchedule) throws BatchErrorException, IOException {
+ createJobSchedule(jobSchedule, null);
+ }
+
+ /**
+ * Adds a job schedule to the Batch account.
+ *
+ * @param jobSchedule The job schedule to be added.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public void createJobSchedule(JobScheduleAddParameter jobSchedule, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobScheduleAddOptions options = new JobScheduleAddOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().jobSchedules().add(jobSchedule, options);
+ }
+
+ /**
+ * Lists the {@link CloudJobSchedule job schedules} in the Batch account.
+ *
+ * @return A list of {@link CloudJobSchedule} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listJobSchedules() throws BatchErrorException, IOException {
+ return listJobSchedules(null, null);
+ }
+
+ /**
+ * Lists the {@link CloudJobSchedule job schedules} in the Batch account.
+ *
+ * @param detailLevel A {@link DetailLevel} used for filtering the list and for controlling which properties are retrieved from the service.
+ * @return A list of {@link CloudJobSchedule} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listJobSchedules(DetailLevel detailLevel) throws BatchErrorException, IOException {
+ return listJobSchedules(detailLevel, null);
+ }
+
+ /**
+ * Lists the {@link CloudJobSchedule job schedules} in the Batch account.
+ *
+ * @param detailLevel A {@link DetailLevel} used for filtering the list and for controlling which properties are retrieved from the service.
+ * @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
+ * @return A list of {@link CloudJobSchedule} objects.
+ * @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
+ * @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
+ */
+ public PagedList listJobSchedules(DetailLevel detailLevel, Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ JobScheduleListOptions options = new JobScheduleListOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().jobSchedules().list(options);
+ }
+
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/JobSchedulingErrorCodes.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/JobSchedulingErrorCodes.java
new file mode 100644
index 000000000000..112bc0213ee0
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/JobSchedulingErrorCodes.java
@@ -0,0 +1,39 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch;
+
+/**
+ * Contains error codes specific to job scheduling errors.
+ */
+public final class JobSchedulingErrorCodes
+{
+ /**
+ * The Batch service could not create an auto pool to run the job on, because the account
+ * has reached its quota of compute nodes.
+ */
+ public static final String AutoPoolCreationFailedWithQuotaReached = "AutoPoolCreationFailedWithQuotaReached";
+
+ /**
+ * The auto pool specification for the job has one or more application package references which could not be satisfied.
+ * This occurs if the application ID or version does not exist or is not active, or if the reference did not specify a
+ * version and there is no default version configured.
+ */
+ public static final String InvalidApplicationPackageReferencesInAutoPool = "InvalidApplicationPackageReferencesInAutoPool";
+
+ /**
+ * The auto pool specification for the job has an invalid automatic scaling formula.
+ */
+ public static final String InvalidAutoScaleFormulaInAutoPool = "InvalidAutoScaleFormulaInAutoPool";
+
+ /**
+ * The auto pool specification for the job has an invalid certificate reference (for example, to a
+ * certificate that does not exist).
+ */
+ public static final String InvalidCertificatesInAutoPool = "InvalidCertificatesInAutoPool";
+
+ /**
+ * The reason for the scheduling error is unknown.
+ */
+ public static final String Unknown = "Unknown";
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/PoolOperations.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/PoolOperations.java
new file mode 100644
index 000000000000..b5fc1ccb2e58
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/PoolOperations.java
@@ -0,0 +1,1335 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch;
+
+import com.microsoft.azure.PagedList;
+import com.microsoft.azure.batch.protocol.models.*;
+import org.joda.time.DateTime;
+import org.joda.time.Period;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Performs pool-related operations on an Azure Batch account.
+ */
+public class PoolOperations implements IInheritedBehaviors {
+ PoolOperations(BatchClient batchClient, Collection customBehaviors) {
+ _parentBatchClient = batchClient;
+
+ // inherit from instantiating parent
+ InternalHelper.InheritClientBehaviorsAndSetPublicProperty(this, customBehaviors);
+ }
+
+ private Collection _customBehaviors;
+
+ private final BatchClient _parentBatchClient;
+
+ /**
+ * Gets a collection of behaviors that modify or customize requests to the Batch
+ * service.
+ *
+ * @return A collection of {@link BatchClientBehavior} instances.
+ */
+ @Override
+ public Collection customBehaviors() {
+ return _customBehaviors;
+ }
+
+ /**
+ * Sets a collection of behaviors that modify or customize requests to the Batch
+ * service.
+ *
+ * @param behaviors
+ * The collection of {@link BatchClientBehavior} instances.
+ * @return The current instance.
+ */
+ @Override
+ public IInheritedBehaviors withCustomBehaviors(Collection behaviors) {
+ _customBehaviors = behaviors;
+ return this;
+ }
+
+ /**
+ * Lists the {@link CloudPool pools} in the Batch account.
+ *
+ * @return A list of {@link CloudPool} objects.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public PagedList listPools() throws BatchErrorException, IOException {
+ return listPools(null, null);
+ }
+
+ /**
+ * Lists the {@link CloudPool pools} in the Batch account.
+ *
+ * @param detailLevel
+ * A {@link DetailLevel} used for filtering the list and for
+ * controlling which properties are retrieved from the service.
+ * @return A list of {@link CloudPool} objects.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public PagedList listPools(DetailLevel detailLevel) throws BatchErrorException, IOException {
+ return listPools(detailLevel, null);
+ }
+
+ /**
+ * Lists the {@link CloudPool pools} in the Batch account.
+ *
+ * @param detailLevel
+ * A {@link DetailLevel} used for filtering the list and for
+ * controlling which properties are retrieved from the service.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @return A list of {@link CloudPool} objects.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public PagedList listPools(DetailLevel detailLevel, Iterable additionalBehaviors)
+ throws BatchErrorException, IOException {
+ PoolListOptions options = new PoolListOptions();
+
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().pools().list(options);
+ }
+
+ /**
+ * Gets the specified {@link CloudPool}.
+ *
+ * @param poolId
+ * The ID of the pool to get.
+ * @return A {@link CloudPool} containing information about the specified Azure
+ * Batch pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public CloudPool getPool(String poolId) throws BatchErrorException, IOException {
+ return getPool(poolId, null, null);
+ }
+
+ /**
+ * Gets the specified {@link CloudPool}.
+ *
+ * @param poolId
+ * The ID of the pool to get.
+ * @param detailLevel
+ * A {@link DetailLevel} used for controlling which properties are
+ * retrieved from the service.
+ * @return A {@link CloudPool} containing information about the specified Azure
+ * Batch pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public CloudPool getPool(String poolId, DetailLevel detailLevel) throws BatchErrorException, IOException {
+ return getPool(poolId, detailLevel, null);
+ }
+
+ /**
+ * Gets the specified {@link CloudPool}.
+ *
+ * @param poolId
+ * The ID of the pool to get.
+ * @param detailLevel
+ * A {@link DetailLevel} used for controlling which properties are
+ * retrieved from the service.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @return A {@link CloudPool} containing information about the specified Azure
+ * Batch pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public CloudPool getPool(String poolId, DetailLevel detailLevel, Iterable additionalBehaviors)
+ throws BatchErrorException, IOException {
+ PoolGetOptions options = new PoolGetOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().pools().get(poolId, options);
+ }
+
+ /**
+ * Deletes the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool to delete.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void deletePool(String poolId) throws BatchErrorException, IOException {
+ deletePool(poolId, null);
+ }
+
+ /**
+ * Deletes the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool to delete.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void deletePool(String poolId, Iterable additionalBehaviors)
+ throws BatchErrorException, IOException {
+ PoolDeleteOptions options = new PoolDeleteOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().pools().delete(poolId, options);
+ }
+
+ /**
+ * Adds a pool to the Batch account.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param virtualMachineSize
+ * The size of virtual machines in the pool. See https://azure.microsoft.com/documentation/articles/virtual-machines-size-specs/
+ * for sizes.
+ * @param cloudServiceConfiguration
+ * The {@link CloudServiceConfiguration} for the pool.
+ * @param targetDedicatedNodes
+ * The desired number of dedicated compute nodes in the pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void createPool(String poolId, String virtualMachineSize,
+ CloudServiceConfiguration cloudServiceConfiguration, int targetDedicatedNodes)
+ throws BatchErrorException, IOException {
+ createPool(poolId, virtualMachineSize, cloudServiceConfiguration, targetDedicatedNodes, 0, null);
+ }
+
+ /**
+ * Adds a pool to the Batch account.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param virtualMachineSize
+ * The size of virtual machines in the pool. See https://azure.microsoft.com/documentation/articles/virtual-machines-size-specs/
+ * for sizes.
+ * @param cloudServiceConfiguration
+ * The {@link CloudServiceConfiguration} for the pool.
+ * @param targetDedicatedNodes
+ * The desired number of dedicated compute nodes in the pool.
+ * @param targetLowPriorityNodes
+ * The desired number of low-priority compute nodes in the pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void createPool(String poolId, String virtualMachineSize,
+ CloudServiceConfiguration cloudServiceConfiguration, int targetDedicatedNodes, int targetLowPriorityNodes)
+ throws BatchErrorException, IOException {
+ createPool(poolId, virtualMachineSize, cloudServiceConfiguration, targetDedicatedNodes, targetLowPriorityNodes,
+ null);
+ }
+
+ /**
+ * Adds a pool to the Batch account.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param virtualMachineSize
+ * The size of virtual machines in the pool. See https://azure.microsoft.com/documentation/articles/virtual-machines-size-specs/
+ * for sizes.
+ * @param cloudServiceConfiguration
+ * The {@link CloudServiceConfiguration} for the pool.
+ * @param targetDedicatedNodes
+ * The desired number of dedicated compute nodes in the pool.
+ * @param targetLowPriorityNodes
+ * The desired number of low-priority compute nodes in the pool.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void createPool(String poolId, String virtualMachineSize,
+ CloudServiceConfiguration cloudServiceConfiguration, int targetDedicatedNodes, int targetLowPriorityNodes,
+ Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ PoolAddParameter parameter = new PoolAddParameter().withId(poolId)
+ .withCloudServiceConfiguration(cloudServiceConfiguration).withTargetDedicatedNodes(targetDedicatedNodes)
+ .withTargetLowPriorityNodes(targetLowPriorityNodes).withVmSize(virtualMachineSize);
+
+ createPool(parameter, additionalBehaviors);
+ }
+
+ /**
+ * Adds a pool to the Batch account.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param virtualMachineSize
+ * The size of virtual machines in the pool. See https://azure.microsoft.com/documentation/articles/virtual-machines-size-specs/
+ * for sizes.
+ * @param virtualMachineConfiguration
+ * The {@link VirtualMachineConfiguration} for the pool.
+ * @param targetDedicatedNodes
+ * The desired number of dedicated compute nodes in the pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void createPool(String poolId, String virtualMachineSize,
+ VirtualMachineConfiguration virtualMachineConfiguration, int targetDedicatedNodes)
+ throws BatchErrorException, IOException {
+ createPool(poolId, virtualMachineSize, virtualMachineConfiguration, targetDedicatedNodes, 0, null);
+ }
+
+ /**
+ * Adds a pool to the Batch account.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param virtualMachineSize
+ * The size of virtual machines in the pool. See https://azure.microsoft.com/documentation/articles/virtual-machines-size-specs/
+ * for sizes.
+ * @param virtualMachineConfiguration
+ * The {@link VirtualMachineConfiguration} for the pool.
+ * @param targetDedicatedNodes
+ * The desired number of dedicated compute nodes in the pool.
+ * @param targetLowPriorityNodes
+ * The desired number of low-priority compute nodes in the pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void createPool(String poolId, String virtualMachineSize,
+ VirtualMachineConfiguration virtualMachineConfiguration, int targetDedicatedNodes,
+ int targetLowPriorityNodes) throws BatchErrorException, IOException {
+ createPool(poolId, virtualMachineSize, virtualMachineConfiguration, targetDedicatedNodes,
+ targetLowPriorityNodes, null);
+ }
+
+ /**
+ * Adds a pool to the Batch account.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param virtualMachineSize
+ * The size of virtual machines in the pool. See https://azure.microsoft.com/documentation/articles/virtual-machines-size-specs/
+ * for sizes.
+ * @param virtualMachineConfiguration
+ * The {@link VirtualMachineConfiguration} for the pool.
+ * @param targetDedicatedNodes
+ * The desired number of dedicated compute nodes in the pool.
+ * @param targetLowPriorityNodes
+ * The desired number of low-priority compute nodes in the pool.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void createPool(String poolId, String virtualMachineSize,
+ VirtualMachineConfiguration virtualMachineConfiguration, int targetDedicatedNodes,
+ int targetLowPriorityNodes, Iterable additionalBehaviors)
+ throws BatchErrorException, IOException {
+ PoolAddParameter parameter = new PoolAddParameter().withId(poolId)
+ .withVirtualMachineConfiguration(virtualMachineConfiguration)
+ .withTargetDedicatedNodes(targetDedicatedNodes).withTargetLowPriorityNodes(targetLowPriorityNodes)
+ .withVmSize(virtualMachineSize);
+
+ createPool(parameter, additionalBehaviors);
+ }
+
+ /**
+ * Adds a pool to the Batch account.
+ *
+ * @param pool
+ * The pool to be added.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void createPool(PoolAddParameter pool) throws BatchErrorException, IOException {
+ createPool(pool, null);
+ }
+
+ /**
+ * Adds a pool to the Batch account.
+ *
+ * @param pool
+ * The pool to be added.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void createPool(PoolAddParameter pool, Iterable additionalBehaviors)
+ throws BatchErrorException, IOException {
+ PoolAddOptions options = new PoolAddOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().pools().add(pool, options);
+ }
+
+ /**
+ * Resizes the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param targetDedicatedNodes
+ * The desired number of dedicated compute nodes in the pool.
+ * @param targetLowPriorityNodes
+ * The desired number of low-priority compute nodes in the pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void resizePool(String poolId, Integer targetDedicatedNodes, Integer targetLowPriorityNodes)
+ throws BatchErrorException, IOException {
+ resizePool(poolId, targetDedicatedNodes, targetLowPriorityNodes, null, null, null);
+ }
+
+ /**
+ * Resizes the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param targetDedicatedNodes
+ * The desired number of dedicated compute nodes in the pool.
+ * @param targetLowPriorityNodes
+ * The desired number of low-priority compute nodes in the pool.
+ * @param resizeTimeout
+ * The timeout for allocation of compute nodes to the pool or removal
+ * of compute nodes from the pool. If the pool has not reached the
+ * target size after this time, the resize is stopped.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void resizePool(String poolId, Integer targetDedicatedNodes, Integer targetLowPriorityNodes,
+ Period resizeTimeout) throws BatchErrorException, IOException {
+ resizePool(poolId, targetDedicatedNodes, targetLowPriorityNodes, resizeTimeout, null, null);
+ }
+
+ /**
+ * Resizes the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param targetDedicatedNodes
+ * The desired number of dedicated compute nodes in the pool.
+ * @param targetLowPriorityNodes
+ * The desired number of low-priority compute nodes in the pool.
+ * @param resizeTimeout
+ * The timeout for allocation of compute nodes to the pool or removal
+ * of compute nodes from the pool. If the pool has not reached the
+ * target size after this time, the resize is stopped.
+ * @param deallocationOption
+ * Specifies when nodes may be removed from the pool, if the pool
+ * size is decreasing.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void resizePool(String poolId, Integer targetDedicatedNodes, Integer targetLowPriorityNodes,
+ Period resizeTimeout, ComputeNodeDeallocationOption deallocationOption)
+ throws BatchErrorException, IOException {
+ resizePool(poolId, targetDedicatedNodes, targetLowPriorityNodes, resizeTimeout, deallocationOption, null);
+ }
+
+ /**
+ * Resizes the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param targetDedicatedNodes
+ * The desired number of dedicated compute nodes in the pool.
+ * @param targetLowPriorityNodes
+ * The desired number of low-priority compute nodes in the pool.
+ * @param resizeTimeout
+ * The timeout for allocation of compute nodes to the pool or removal
+ * of compute nodes from the pool. If the pool has not reached the
+ * target size after this time, the resize is stopped.
+ * @param deallocationOption
+ * Specifies when nodes may be removed from the pool, if the pool
+ * size is decreasing.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void resizePool(String poolId, Integer targetDedicatedNodes, Integer targetLowPriorityNodes,
+ Period resizeTimeout, ComputeNodeDeallocationOption deallocationOption,
+ Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ PoolResizeOptions options = new PoolResizeOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ PoolResizeParameter param = new PoolResizeParameter().withResizeTimeout(resizeTimeout)
+ .withNodeDeallocationOption(deallocationOption).withTargetDedicatedNodes(targetDedicatedNodes)
+ .withTargetLowPriorityNodes(targetLowPriorityNodes);
+
+ this._parentBatchClient.protocolLayer().pools().resize(poolId, param, options);
+ }
+
+ /**
+ * Stops a pool resize operation.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void stopResizePool(String poolId) throws BatchErrorException, IOException {
+ stopResizePool(poolId, null);
+ }
+
+ /**
+ * Stops a pool resize operation.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void stopResizePool(String poolId, Iterable additionalBehaviors)
+ throws BatchErrorException, IOException {
+ PoolStopResizeOptions options = new PoolStopResizeOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().pools().stopResize(poolId, options);
+ }
+
+ /**
+ * Enables automatic scaling on the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void enableAutoScale(String poolId) throws BatchErrorException, IOException {
+ enableAutoScale(poolId, null, null, null);
+ }
+
+ /**
+ * Enables automatic scaling on the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param autoScaleFormula
+ * The formula for the desired number of compute nodes in the pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void enableAutoScale(String poolId, String autoScaleFormula) throws BatchErrorException, IOException {
+ enableAutoScale(poolId, autoScaleFormula, null, null);
+ }
+
+ /**
+ * Enables automatic scaling on the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param autoScaleFormula
+ * The formula for the desired number of compute nodes in the pool.
+ * @param autoScaleEvaluationInterval
+ * The time interval at which to automatically adjust the pool size.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void enableAutoScale(String poolId, String autoScaleFormula, Period autoScaleEvaluationInterval)
+ throws BatchErrorException, IOException {
+ enableAutoScale(poolId, autoScaleFormula, autoScaleEvaluationInterval, null);
+ }
+
+ /**
+ * Enables automatic scaling on the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param autoScaleFormula
+ * The formula for the desired number of compute nodes in the pool.
+ * @param autoScaleEvaluationInterval
+ * The time interval at which to automatically adjust the pool size.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void enableAutoScale(String poolId, String autoScaleFormula, Period autoScaleEvaluationInterval,
+ Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ PoolEnableAutoScaleOptions options = new PoolEnableAutoScaleOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ PoolEnableAutoScaleParameter param = new PoolEnableAutoScaleParameter().withAutoScaleFormula(autoScaleFormula)
+ .withAutoScaleEvaluationInterval(autoScaleEvaluationInterval);
+
+ this._parentBatchClient.protocolLayer().pools().enableAutoScale(poolId, param, options);
+ }
+
+ /**
+ * Disables automatic scaling on the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void disableAutoScale(String poolId) throws BatchErrorException, IOException {
+ disableAutoScale(poolId, null);
+ }
+
+ /**
+ * Disables automatic scaling on the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void disableAutoScale(String poolId, Iterable additionalBehaviors)
+ throws BatchErrorException, IOException {
+ PoolDisableAutoScaleOptions options = new PoolDisableAutoScaleOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().pools().disableAutoScale(poolId, options);
+ }
+
+ /**
+ * Gets the result of evaluating an automatic scaling formula on the specified
+ * pool. This is primarily for validating an autoscale formula, as it simply
+ * returns the result without applying the formula to the pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param autoScaleFormula
+ * The formula to be evaluated on the pool.
+ * @return The result of evaluating the formula on the specified pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public AutoScaleRun evaluateAutoScale(String poolId, String autoScaleFormula)
+ throws BatchErrorException, IOException {
+ return evaluateAutoScale(poolId, autoScaleFormula, null);
+ }
+
+ /**
+ * Gets the result of evaluating an automatic scaling formula on the specified
+ * pool. This is primarily for validating an autoscale formula, as it simply
+ * returns the result without applying the formula to the pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param autoScaleFormula
+ * The formula to be evaluated on the pool.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @return The result of evaluating the formula on the specified pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public AutoScaleRun evaluateAutoScale(String poolId, String autoScaleFormula,
+ Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ PoolEvaluateAutoScaleOptions options = new PoolEvaluateAutoScaleOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().pools().evaluateAutoScale(poolId, autoScaleFormula, options);
+ }
+
+ /**
+ * Removes the specified compute node from the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param computeNodeId
+ * The ID of the compute node to remove from the pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void removeNodeFromPool(String poolId, String computeNodeId) throws BatchErrorException, IOException {
+ removeNodeFromPool(poolId, computeNodeId, null, null, null);
+ }
+
+ /**
+ * Removes the specified compute node from the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param computeNodeId
+ * The ID of the compute node to remove from the pool.
+ * @param deallocationOption
+ * Specifies when nodes may be removed from the pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void removeNodeFromPool(String poolId, String computeNodeId,
+ ComputeNodeDeallocationOption deallocationOption) throws BatchErrorException, IOException {
+ removeNodeFromPool(poolId, computeNodeId, deallocationOption, null, null);
+ }
+
+ /**
+ * Removes the specified compute node from the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param computeNodeId
+ * The ID of the compute node to remove from the pool.
+ * @param deallocationOption
+ * Specifies when nodes may be removed from the pool.
+ * @param resizeTimeout
+ * Specifies the timeout for removal of compute nodes from the pool.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void removeNodeFromPool(String poolId, String computeNodeId,
+ ComputeNodeDeallocationOption deallocationOption, Period resizeTimeout,
+ Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ List nodeIds = new LinkedList<>();
+ nodeIds.add(computeNodeId);
+
+ removeNodesFromPool(poolId, nodeIds, deallocationOption, resizeTimeout, additionalBehaviors);
+ }
+
+ /**
+ * Removes the specified compute nodes from the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param computeNodes
+ * The compute nodes to remove from the pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void removeNodesFromPool(String poolId, Collection computeNodes)
+ throws BatchErrorException, IOException {
+ removeNodesFromPool(poolId, computeNodes, null, null, null);
+ }
+
+ /**
+ * Removes the specified compute nodes from the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param computeNodes
+ * The compute nodes to remove from the pool.
+ * @param deallocationOption
+ * Specifies when nodes may be removed from the pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void removeNodesFromPool(String poolId, Collection computeNodes,
+ ComputeNodeDeallocationOption deallocationOption) throws BatchErrorException, IOException {
+ removeNodesFromPool(poolId, computeNodes, deallocationOption, null, null);
+ }
+
+ /**
+ * Removes the specified compute nodes from the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param computeNodes
+ * The compute nodes to remove from the pool.
+ * @param deallocationOption
+ * Specifies when nodes may be removed from the pool.
+ * @param resizeTimeout
+ * Specifies the timeout for removal of compute nodes from the pool.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void removeNodesFromPool(String poolId, Collection computeNodes,
+ ComputeNodeDeallocationOption deallocationOption, Period resizeTimeout,
+ Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ List nodeIds = new LinkedList<>();
+ for (ComputeNode node : computeNodes) {
+ nodeIds.add(node.id());
+ }
+
+ removeNodesFromPool(poolId, nodeIds, deallocationOption, resizeTimeout, additionalBehaviors);
+ }
+
+ /**
+ * Removes the specified compute nodes from the specified pool.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param computeNodeIds
+ * The IDs of the compute nodes to remove from the pool.
+ * @param deallocationOption
+ * Specifies when nodes may be removed from the pool.
+ * @param resizeTimeout
+ * Specifies the timeout for removal of compute nodes from the pool.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void removeNodesFromPool(String poolId, List computeNodeIds,
+ ComputeNodeDeallocationOption deallocationOption, Period resizeTimeout,
+ Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ PoolRemoveNodesOptions options = new PoolRemoveNodesOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ NodeRemoveParameter param = new NodeRemoveParameter().withNodeList(computeNodeIds)
+ .withNodeDeallocationOption(deallocationOption).withResizeTimeout(resizeTimeout);
+
+ this._parentBatchClient.protocolLayer().pools().removeNodes(poolId, param, options);
+ }
+
+ /**
+ * Checks whether the specified pool exists.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @return True if the pool exists; otherwise, false.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public boolean existsPool(String poolId) throws BatchErrorException, IOException {
+ return existsPool(poolId, null);
+ }
+
+ /**
+ * Checks whether the specified pool exists.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @return True if the pool exists; otherwise, false.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public boolean existsPool(String poolId, Iterable additionalBehaviors)
+ throws BatchErrorException, IOException {
+
+ PoolExistsOptions options = new PoolExistsOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().pools().exists(poolId, options);
+ }
+
+ /**
+ * Updates the specified pool. This method fully replaces all the updatable
+ * properties of the pool. For example, if the startTask parameter is null and
+ * the pool has a start task associated with it, then the Batch service will
+ * remove the existing start task.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param startTask
+ * A task to run on each compute node as it joins the pool. If null,
+ * any existing start task is removed from the pool.
+ * @param certificateReferences
+ * A collection of certificates to be installed on each compute node
+ * in the pool. If null, any existing certificate references are
+ * removed from the pool.
+ * @param applicationPackageReferences
+ * A collection of application packages to be installed on each
+ * compute node in the pool. If null, any existing application
+ * packages references are removed from the pool.
+ * @param metadata
+ * A collection of name-value pairs associated with the pool as
+ * metadata. If null, any existing metadata is removed from the pool.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void updatePoolProperties(String poolId, StartTask startTask,
+ Collection certificateReferences,
+ Collection applicationPackageReferences, Collection metadata)
+ throws BatchErrorException, IOException {
+ updatePoolProperties(poolId, startTask, certificateReferences, applicationPackageReferences, metadata, null);
+ }
+
+ /**
+ * Updates the specified pool. This method fully replaces all the updatable
+ * properties of the pool. For example, if the startTask parameter is null and
+ * the pool has a start task associated with it, then the Batch service will
+ * remove the existing start task.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param startTask
+ * A task to run on each compute node as it joins the pool. If null,
+ * any existing start task is removed from the pool.
+ * @param certificateReferences
+ * A collection of certificates to be installed on each compute node
+ * in the pool. If null, any existing certificate references are
+ * removed from the pool.
+ * @param applicationPackageReferences
+ * A collection of application packages to be installed on each
+ * compute node in the pool. If null, any existing application
+ * packages references are removed from the pool.
+ * @param metadata
+ * A collection of name-value pairs associated with the pool as
+ * metadata. If null, any existing metadata is removed from the pool.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void updatePoolProperties(String poolId, StartTask startTask,
+ Collection certificateReferences,
+ Collection applicationPackageReferences, Collection metadata,
+ Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ PoolUpdatePropertiesOptions options = new PoolUpdatePropertiesOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ PoolUpdatePropertiesParameter param = new PoolUpdatePropertiesParameter()
+ .withMetadata(metadata == null ? new LinkedList() : new LinkedList<>(metadata))
+ .withApplicationPackageReferences(
+ applicationPackageReferences == null ? new LinkedList()
+ : new LinkedList<>(applicationPackageReferences))
+ .withCertificateReferences(certificateReferences == null ? new LinkedList()
+ : new LinkedList<>(certificateReferences))
+ .withStartTask(startTask);
+
+ this._parentBatchClient.protocolLayer().pools().updateProperties(poolId, param, options);
+ }
+
+ /**
+ * Updates the specified pool. This method only replaces the properties
+ * specified with non-null values.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param startTask
+ * A task to run on each compute node as it joins the pool. If null,
+ * any existing start task is left unchanged.
+ * @param certificateReferences
+ * A collection of certificates to be installed on each compute node
+ * in the pool. If null, any existing certificate references are left
+ * unchanged.
+ * @param applicationPackageReferences
+ * A collection of application packages to be installed on each
+ * compute node in the pool. If null, any existing application
+ * packages references are left unchanged.
+ * @param metadata
+ * A collection of name-value pairs associated with the pool as
+ * metadata. If null, any existing metadata is left unchanged.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void patchPool(String poolId, StartTask startTask, Collection certificateReferences,
+ Collection applicationPackageReferences, Collection metadata)
+ throws BatchErrorException, IOException {
+ patchPool(poolId, startTask, certificateReferences, applicationPackageReferences, metadata, null);
+ }
+
+ /**
+ * Updates the specified pool. This method only replaces the properties
+ * specified with non-null values.
+ *
+ * @param poolId
+ * The ID of the pool.
+ * @param startTask
+ * A task to run on each compute node as it joins the pool. If null,
+ * any existing start task is left unchanged.
+ * @param certificateReferences
+ * A collection of certificates to be installed on each compute node
+ * in the pool. If null, any existing certificate references are left
+ * unchanged.
+ * @param applicationPackageReferences
+ * A collection of application packages to be installed on each
+ * compute node in the pool. If null, any existing application
+ * packages references are left unchanged.
+ * @param metadata
+ * A collection of name-value pairs associated with the pool as
+ * metadata. If null, any existing metadata is left unchanged.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void patchPool(String poolId, StartTask startTask, Collection certificateReferences,
+ Collection applicationPackageReferences, Collection metadata,
+ Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ PoolPatchOptions options = new PoolPatchOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ PoolPatchParameter param = new PoolPatchParameter().withStartTask(startTask);
+ if (metadata != null) {
+ param.withMetadata(new LinkedList<>(metadata));
+ }
+ if (applicationPackageReferences != null) {
+ param.withApplicationPackageReferences(new LinkedList<>(applicationPackageReferences));
+ }
+ if (certificateReferences != null) {
+ param.withCertificateReferences(new LinkedList<>(certificateReferences));
+ }
+
+ this._parentBatchClient.protocolLayer().pools().patch(poolId, param, options);
+ }
+
+ /**
+ * Lists pool usage metrics.
+ *
+ * @param startTime
+ * The start time of the aggregation interval covered by this entry.
+ * @param endTime
+ * The end time of the aggregation interval for this entry.
+ * @return A list of {@link PoolUsageMetrics} objects.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public PagedList listPoolUsageMetrics(DateTime startTime, DateTime endTime)
+ throws BatchErrorException, IOException {
+ return listPoolUsageMetrics(startTime, endTime, null, null);
+ }
+
+ /**
+ * Lists pool usage metrics.
+ *
+ * @param startTime
+ * The start time of the aggregation interval covered by this entry.
+ * @param endTime
+ * The end time of the aggregation interval for this entry.
+ * @param detailLevel
+ * A {@link DetailLevel} used for filtering the list and for
+ * controlling which properties are retrieved from the service.
+ * @return A list of {@link PoolUsageMetrics} objects.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public PagedList listPoolUsageMetrics(DateTime startTime, DateTime endTime,
+ DetailLevel detailLevel) throws BatchErrorException, IOException {
+ return listPoolUsageMetrics(startTime, endTime, detailLevel, null);
+ }
+
+ /**
+ * Lists pool usage metrics.
+ *
+ * @param startTime
+ * The start time of the aggregation interval covered by this entry.
+ * @param endTime
+ * The end time of the aggregation interval for this entry.
+ * @param detailLevel
+ * A {@link DetailLevel} used for filtering the list and for
+ * controlling which properties are retrieved from the service.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @return A list of {@link PoolUsageMetrics} objects.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public PagedList listPoolUsageMetrics(DateTime startTime, DateTime endTime,
+ DetailLevel detailLevel, Iterable additionalBehaviors)
+ throws BatchErrorException, IOException {
+ PoolListUsageMetricsOptions options = new PoolListUsageMetricsOptions().withStartTime(startTime)
+ .withEndTime(endTime);
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().pools().listUsageMetrics(options);
+ }
+
+ /**
+ * Gets lifetime summary statistics for all of the pools in the current account.
+ * Statistics are aggregated across all pools that have ever existed in the
+ * account, from account creation to the last update time of the statistics.
+ *
+ * @return The aggregated pool statistics.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public PoolStatistics getAllPoolsLifetimeStatistics() throws BatchErrorException, IOException {
+ return getAllPoolsLifetimeStatistics(null);
+ }
+
+ /**
+ * Gets lifetime summary statistics for all of the pools in the current account.
+ * Statistics are aggregated across all pools that have ever existed in the
+ * account, from account creation to the last update time of the statistics.
+ *
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @return The aggregated pool statistics.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public PoolStatistics getAllPoolsLifetimeStatistics(Iterable additionalBehaviors)
+ throws BatchErrorException, IOException {
+ PoolGetAllLifetimeStatisticsOptions options = new PoolGetAllLifetimeStatisticsOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().pools().getAllLifetimeStatistics(options);
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/PoolResizeErrorCodes.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/PoolResizeErrorCodes.java
new file mode 100644
index 000000000000..a3c8d5c8b115
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/PoolResizeErrorCodes.java
@@ -0,0 +1,40 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch;
+
+/**
+ * Contains error codes specific to pool resize errors.
+ */
+public final class PoolResizeErrorCodes
+{
+ /**
+ * The account has reached its quota of compute nodes.
+ */
+ public static final String AccountCoreQuotaReached = "AccountCoreQuotaReached";
+
+ /**
+ * An error occurred while trying to allocate the desired number of compute nodes.
+ */
+ public static final String AllocationFailed = "AllocationFailed";
+
+ /**
+ * The Batch service was unable to allocate the desired number of compute nodes within the resize timeout.
+ */
+ public static final String AllocationTimedOut= "AllocationTimedout";
+
+ /**
+ * An error occurred when removing compute nodes from the pool.
+ */
+ public static final String RemoveNodesFailed = "RemoveNodesFailed";
+
+ /**
+ * The user stopped the resize operation.
+ */
+ public static final String ResizeStopped = "ResizeStopped";
+
+ /**
+ * The reason for the failure is not known.
+ */
+ public static final String Unknown = "Unknown";
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/TaskFailureInformationCodes.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/TaskFailureInformationCodes.java
new file mode 100644
index 000000000000..8666f16bd0eb
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/TaskFailureInformationCodes.java
@@ -0,0 +1,76 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch;
+
+/**
+ * Contains error codes specific to task failure information.
+ */
+public final class TaskFailureInformationCodes
+{
+ /**
+ * An error occurred when trying to deploy a required application package.
+ */
+ public static final String ApplicationPackageError = "ApplicationPackageError";
+
+ /**
+ * Access was denied when trying to download a resource file required for the task.
+ */
+ public static final String BlobAccessDenied = "BlobAccessDenied";
+
+ /**
+ * An error occurred when trying to download a resource file required for the task.
+ */
+ public static final String BlobDownloadMiscError = "BlobDownloadMiscError";
+
+ /**
+ * A timeout occurred when downloading a resource file required for the task.
+ */
+ public static final String BlobDownloadTimedOut = "BlobDownloadTimedOut";
+
+ /**
+ * A resource file required for the task does not exist.
+ */
+ public static final String BlobNotFound = "BlobNotFound";
+
+ /**
+ * An error occurred when launching the task's command line.
+ */
+ public static final String CommandLaunchFailed = "CommandLaunchFailed";
+
+ /**
+ * The program specified in the task's command line was not found.
+ */
+ public static final String CommandProgramNotFound = "CommandProgramNotFound";
+
+ /**
+ * The compute node disk ran out of space when downloading the resource files required for the task.
+ */
+ public static final String DiskFull = "DiskFull";
+
+ /**
+ * The compute node could not create a directory for the task's resource files.
+ */
+ public static final String ResourceDirectoryCreateFailed = "ResourceDirectoryCreateFailed";
+
+ /**
+ * The compute node could not create a local file when trying to download a resource file required for the task.
+ */
+ public static final String ResourceFileCreateFailed = "ResourceFileCreateFailed";
+
+ /**
+ * The compute node could not write to a local file when trying to download a resource file required for the task.
+ */
+ public static final String ResourceFileWriteFailed = "ResourceFileWriteFailed";
+
+ /**
+ * The task ended.
+ */
+ public static final String TaskEnded = "TaskEnded";
+
+ /**
+ * The reason for the scheduling error is unknown.
+ */
+ public static final String Unknown = "Unknown";
+
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/TaskOperations.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/TaskOperations.java
new file mode 100644
index 000000000000..eeac6390e5a8
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/TaskOperations.java
@@ -0,0 +1,785 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch;
+
+import com.microsoft.azure.PagedList;
+import com.microsoft.azure.batch.interceptor.BatchClientParallelOptions;
+import com.microsoft.azure.batch.protocol.models.*;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Performs task-related operations on an Azure Batch account.
+ */
+public class TaskOperations implements IInheritedBehaviors {
+ TaskOperations(BatchClient batchClient, Collection customBehaviors) {
+ _parentBatchClient = batchClient;
+
+ // inherit from instantiating parent
+ InternalHelper.InheritClientBehaviorsAndSetPublicProperty(this, customBehaviors);
+ }
+
+ private Collection _customBehaviors;
+
+ private final BatchClient _parentBatchClient;
+
+ /**
+ * Gets a collection of behaviors that modify or customize requests to the Batch
+ * service.
+ *
+ * @return A collection of {@link BatchClientBehavior} instances.
+ */
+ @Override
+ public Collection customBehaviors() {
+ return _customBehaviors;
+ }
+
+ /**
+ * Sets a collection of behaviors that modify or customize requests to the Batch
+ * service.
+ *
+ * @param behaviors
+ * The collection of {@link BatchClientBehavior} instances.
+ * @return The current instance.
+ */
+ @Override
+ public IInheritedBehaviors withCustomBehaviors(Collection behaviors) {
+ _customBehaviors = behaviors;
+ return this;
+ }
+
+ /**
+ * Adds a single task to a job.
+ *
+ * @param jobId
+ * The ID of the job to which to add the task.
+ * @param taskToAdd
+ * The {@link TaskAddParameter task} to add.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void createTask(String jobId, TaskAddParameter taskToAdd) throws BatchErrorException, IOException {
+ createTask(jobId, taskToAdd, null);
+ }
+
+ /**
+ * Adds a single task to a job.
+ *
+ * @param jobId
+ * The ID of the job to which to add the task.
+ * @param taskToAdd
+ * The {@link TaskAddParameter task} to add.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void createTask(String jobId, TaskAddParameter taskToAdd, Iterable additionalBehaviors)
+ throws BatchErrorException, IOException {
+ TaskAddOptions options = new TaskAddOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().tasks().add(jobId, taskToAdd, options);
+ }
+
+ /**
+ * Adds multiple tasks to a job.
+ *
+ * @param jobId
+ * The ID of the job to which to add the task.
+ * @param taskList
+ * A list of {@link TaskAddParameter tasks} to add.
+ * @throws RuntimeException
+ * Exception thrown when an error response is received from the
+ * Batch service or any network exception.
+ * @throws InterruptedException
+ * Exception thrown if any thread has interrupted the current
+ * thread.
+ */
+ public void createTasks(String jobId, List taskList)
+ throws RuntimeException, InterruptedException {
+ createTasks(jobId, taskList, null);
+ }
+
+ private static class WorkingThread implements Runnable {
+ final static int MAX_TASKS_PER_REQUEST = 100;
+ private static final AtomicInteger currentMaxTasks = new AtomicInteger(MAX_TASKS_PER_REQUEST);
+
+ BatchClient client;
+ BehaviorManager bhMgr;
+ String jobId;
+ Queue pendingList;
+ List failures;
+ volatile Exception exception;
+ final Object lock;
+
+ WorkingThread(BatchClient client, BehaviorManager bhMgr, String jobId, Queue pendingList,
+ List failures, Object lock) {
+ this.client = client;
+ this.bhMgr = bhMgr;
+ this.jobId = jobId;
+ this.pendingList = pendingList;
+ this.failures = failures;
+ this.exception = null;
+ this.lock = lock;
+ }
+
+ public Exception getException() {
+ return this.exception;
+ }
+
+ /**
+ * Submits one chunk of tasks to a job.
+ *
+ * @param taskList
+ * A list of {@link TaskAddParameter tasks} to add.
+ */
+ private void submit_chunk(List taskList) {
+ // The option should be different to every server calls (for example,
+ // client-request-id)
+ TaskAddCollectionOptions options = new TaskAddCollectionOptions();
+ this.bhMgr.applyRequestBehaviors(options);
+ try {
+ TaskAddCollectionResult response = this.client.protocolLayer().tasks().addCollection(this.jobId,
+ taskList, options);
+
+ if (response != null && response.value() != null) {
+ for (TaskAddResult result : response.value()) {
+ if (result.error() != null) {
+ if (result.status() == TaskAddStatus.SERVER_ERROR) {
+ // Server error will be retried
+ for (TaskAddParameter addParameter : taskList) {
+ if (addParameter.id().equals(result.taskId())) {
+ pendingList.add(addParameter);
+ break;
+ }
+ }
+ } else if (result.status() == TaskAddStatus.CLIENT_ERROR
+ && !result.error().code().equals(BatchErrorCodeStrings.TaskExists)) {
+ // Client error will be recorded
+ failures.add(result);
+ }
+ }
+ }
+ }
+ } catch (BatchErrorException e) {
+ // If we get RequestBodyTooLarge could be that we chunked the tasks too large.
+ // Try decreasing the size unless caused by 1 task.
+ if (e.body().code().equals(BatchErrorCodeStrings.RequestBodyTooLarge) && taskList.size() > 1) {
+ // Use binary reduction to decrease size of submitted chunks
+ int midpoint = taskList.size() / 2;
+ // If the midpoint is less than the currentMaxTasks used to create new chunks,
+ // attempt to atomically reduce currentMaxTasks.
+ // In the case where compareAndSet fails, that means that currentMaxTasks which
+ // was the goal
+ int max = currentMaxTasks.get();
+ while (midpoint < max) {
+ currentMaxTasks.compareAndSet(max, midpoint);
+ max = currentMaxTasks.get();
+ }
+ // Resubmit chunk as a smaller list and requeue remaining tasks.
+ pendingList.addAll(taskList.subList(midpoint, taskList.size()));
+ submit_chunk(taskList.subList(0, midpoint));
+ } else {
+ // Any exception will stop further call
+ exception = e;
+ pendingList.addAll(taskList);
+ }
+ } catch (RuntimeException e) {
+ // Any exception will stop further call
+ exception = e;
+ pendingList.addAll(taskList);
+ }
+ }
+
+ @Override
+ public void run() {
+ try {
+ List taskList = new LinkedList<>();
+
+ // Take the task from the queue up to MAX_TASKS_PER_REQUEST
+ int count = 0;
+ int maxAmount = currentMaxTasks.get();
+ while (count < maxAmount) {
+ TaskAddParameter param = pendingList.poll();
+ if (param != null) {
+ taskList.add(param);
+ count++;
+ } else {
+ break;
+ }
+ }
+
+ if (taskList.size() > 0) {
+ submit_chunk(taskList);
+ }
+ } finally {
+ synchronized (lock) {
+ // Notify main thread that sub thread finished
+ lock.notify();
+ }
+ }
+ }
+ }
+
+ /**
+ * Adds multiple tasks to a job.
+ *
+ * @param jobId
+ * The ID of the job to which to add the task.
+ * @param taskList
+ * A list of {@link TaskAddParameter tasks} to add.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws RuntimeException
+ * Exception thrown when an error response is received from the
+ * Batch service or any network exception.
+ * @throws InterruptedException
+ * Exception thrown if any thread has interrupted the current
+ * thread.
+ */
+ public void createTasks(String jobId, List taskList,
+ Iterable additionalBehaviors) throws RuntimeException, InterruptedException {
+
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+
+ // Default thread number is 1
+ int threadNumber = 1;
+
+ // Get user defined thread number
+ for (BatchClientBehavior op : bhMgr.getMasterListOfBehaviors()) {
+ if (op instanceof BatchClientParallelOptions) {
+ threadNumber = ((BatchClientParallelOptions) op).maxDegreeOfParallelism();
+ }
+ }
+
+ final Object lock = new Object();
+ ConcurrentLinkedQueue pendingList = new ConcurrentLinkedQueue<>(taskList);
+ CopyOnWriteArrayList failures = new CopyOnWriteArrayList<>();
+
+ Map threads = new HashMap<>();
+ Exception innerException = null;
+
+ synchronized (lock) {
+ while (!pendingList.isEmpty()) {
+
+ if (threads.size() < threadNumber) {
+ // Kick as many as possible add tasks requests by max allowed threads
+ WorkingThread worker = new WorkingThread(this._parentBatchClient, bhMgr, jobId, pendingList,
+ failures, lock);
+ Thread thread = new Thread(worker);
+ thread.start();
+ threads.put(thread, worker);
+ } else {
+ // Wait for any thread to finish
+ lock.wait();
+
+ List finishedThreads = new ArrayList<>();
+ for (Thread t : threads.keySet()) {
+ if (t.getState() == Thread.State.TERMINATED) {
+ finishedThreads.add(t);
+ // If any exception is encountered, then stop immediately without waiting for
+ // remaining active threads.
+ innerException = threads.get(t).getException();
+ if (innerException != null) {
+ break;
+ }
+ }
+ }
+
+ // Free the thread pool so we can start more threads to send the remaining add
+ // tasks requests.
+ threads.keySet().removeAll(finishedThreads);
+
+ // Any errors happened, we stop.
+ if (innerException != null || !failures.isEmpty()) {
+ break;
+ }
+ }
+ }
+ }
+
+ // Wait for all remaining threads to finish.
+ for (Thread t : threads.keySet()) {
+ t.join();
+ }
+
+ if (innerException == null) {
+ // Check for errors in any of the threads.
+ for (Thread t : threads.keySet()) {
+ innerException = threads.get(t).getException();
+ if (innerException != null) {
+ break;
+ }
+ }
+ }
+
+ if (innerException != null) {
+ // If an exception happened in any of the threads, throw it.
+ if (innerException instanceof BatchErrorException) {
+ throw (BatchErrorException) innerException;
+ } else {
+ // WorkingThread will only catch and store a BatchErrorException or a
+ // RuntimeException in its run() method.
+ // WorkingThread.getException() should therefore only return one of these two
+ // types, making the cast safe.
+ throw (RuntimeException) innerException;
+ }
+ }
+
+ if (!failures.isEmpty()) {
+ // Report any client error with leftover request
+ List notFinished = new ArrayList<>();
+ for (TaskAddParameter param : pendingList) {
+ notFinished.add(param);
+ }
+ throw new CreateTasksErrorException("At least one task failed to be added.", failures, notFinished);
+ }
+
+ // We succeed here
+ }
+
+ /**
+ * Lists the {@link CloudTask tasks} of the specified job.
+ *
+ * @param jobId
+ * The ID of the job.
+ * @return A list of {@link CloudTask} objects.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public PagedList listTasks(String jobId) throws BatchErrorException, IOException {
+ return listTasks(jobId, null, null);
+ }
+
+ /**
+ * Lists the {@link CloudTask tasks} of the specified job.
+ *
+ * @param jobId
+ * The ID of the job.
+ * @param detailLevel
+ * A {@link DetailLevel} used for filtering the list and for
+ * controlling which properties are retrieved from the service.
+ * @return A list of {@link CloudTask} objects.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public PagedList listTasks(String jobId, DetailLevel detailLevel)
+ throws BatchErrorException, IOException {
+ return listTasks(jobId, detailLevel, null);
+ }
+
+ /**
+ * Lists the {@link CloudTask tasks} of the specified job.
+ *
+ * @param jobId
+ * The ID of the job.
+ * @param detailLevel
+ * A {@link DetailLevel} used for filtering the list and for
+ * controlling which properties are retrieved from the service.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @return A list of {@link CloudTask} objects.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public PagedList listTasks(String jobId, DetailLevel detailLevel,
+ Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ TaskListOptions options = new TaskListOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().tasks().list(jobId, options);
+ }
+
+ /**
+ * Lists the {@link SubtaskInformation subtasks} of the specified task.
+ *
+ * @param jobId
+ * The ID of the job containing the task.
+ * @param taskId
+ * The ID of the task.
+ * @return A list of {@link SubtaskInformation} objects.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public List listSubtasks(String jobId, String taskId) throws BatchErrorException, IOException {
+ return listSubtasks(jobId, taskId, null, null);
+ }
+
+ /**
+ * Lists the {@link SubtaskInformation subtasks} of the specified task.
+ *
+ * @param jobId
+ * The ID of the job containing the task.
+ * @param taskId
+ * The ID of the task.
+ * @param detailLevel
+ * A {@link DetailLevel} used for controlling which properties are
+ * retrieved from the service.
+ * @return A list of {@link SubtaskInformation} objects.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public List listSubtasks(String jobId, String taskId, DetailLevel detailLevel)
+ throws BatchErrorException, IOException {
+ return listSubtasks(jobId, taskId, detailLevel, null);
+ }
+
+ /**
+ * Lists the {@link SubtaskInformation subtasks} of the specified task.
+ *
+ * @param jobId
+ * The ID of the job containing the task.
+ * @param taskId
+ * The ID of the task.
+ * @param detailLevel
+ * A {@link DetailLevel} used for controlling which properties are
+ * retrieved from the service.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @return A list of {@link SubtaskInformation} objects.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public List listSubtasks(String jobId, String taskId, DetailLevel detailLevel,
+ Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ TaskListSubtasksOptions options = new TaskListSubtasksOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(options);
+
+ CloudTaskListSubtasksResult response = this._parentBatchClient.protocolLayer().tasks().listSubtasks(jobId,
+ taskId, options);
+
+ if (response != null) {
+ return response.value();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Deletes the specified task.
+ *
+ * @param jobId
+ * The ID of the job containing the task.
+ * @param taskId
+ * The ID of the task.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void deleteTask(String jobId, String taskId) throws BatchErrorException, IOException {
+ deleteTask(jobId, taskId, null);
+ }
+
+ /**
+ * Deletes the specified task.
+ *
+ * @param jobId
+ * The ID of the job containing the task.
+ * @param taskId
+ * The ID of the task.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void deleteTask(String jobId, String taskId, Iterable additionalBehaviors)
+ throws BatchErrorException, IOException {
+ TaskDeleteOptions options = new TaskDeleteOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().tasks().delete(jobId, taskId, options);
+ }
+
+ /**
+ * Gets the specified {@link CloudTask}.
+ *
+ * @param jobId
+ * The ID of the job containing the task.
+ * @param taskId
+ * The ID of the task.
+ * @return A {@link CloudTask} containing information about the specified Azure
+ * Batch task.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public CloudTask getTask(String jobId, String taskId) throws BatchErrorException, IOException {
+ return getTask(jobId, taskId, null, null);
+ }
+
+ /**
+ * Gets the specified {@link CloudTask}.
+ *
+ * @param jobId
+ * The ID of the job containing the task.
+ * @param taskId
+ * The ID of the task.
+ * @param detailLevel
+ * A {@link DetailLevel} used for controlling which properties are
+ * retrieved from the service.
+ * @return A {@link CloudTask} containing information about the specified Azure
+ * Batch task.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public CloudTask getTask(String jobId, String taskId, DetailLevel detailLevel)
+ throws BatchErrorException, IOException {
+ return getTask(jobId, taskId, detailLevel, null);
+ }
+
+ /**
+ * Gets the specified {@link CloudTask}.
+ *
+ * @param jobId
+ * The ID of the job containing the task.
+ * @param taskId
+ * The ID of the task.
+ * @param detailLevel
+ * A {@link DetailLevel} used for controlling which properties are
+ * retrieved from the service.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @return A {@link CloudTask} containing information about the specified Azure
+ * Batch task.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public CloudTask getTask(String jobId, String taskId, DetailLevel detailLevel,
+ Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ TaskGetOptions options = new TaskGetOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.appendDetailLevelToPerCallBehaviors(detailLevel);
+ bhMgr.applyRequestBehaviors(options);
+
+ return this._parentBatchClient.protocolLayer().tasks().get(jobId, taskId, options);
+ }
+
+ /**
+ * Updates the specified task.
+ *
+ * @param jobId
+ * The ID of the job containing the task.
+ * @param taskId
+ * The ID of the task.
+ * @param constraints
+ * Constraints that apply to this task. If null, the task is given
+ * the default constraints.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void updateTask(String jobId, String taskId, TaskConstraints constraints)
+ throws BatchErrorException, IOException {
+ updateTask(jobId, taskId, constraints, null);
+ }
+
+ /**
+ * Updates the specified task.
+ *
+ * @param jobId
+ * The ID of the job containing the task.
+ * @param taskId
+ * The ID of the task.
+ * @param constraints
+ * Constraints that apply to this task. If null, the task is given
+ * the default constraints.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void updateTask(String jobId, String taskId, TaskConstraints constraints,
+ Iterable additionalBehaviors) throws BatchErrorException, IOException {
+ TaskUpdateOptions options = new TaskUpdateOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().tasks().update(jobId, taskId, constraints, options);
+ }
+
+ /**
+ * Terminates the specified task.
+ *
+ * @param jobId
+ * The ID of the job containing the task.
+ * @param taskId
+ * The ID of the task.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void terminateTask(String jobId, String taskId) throws BatchErrorException, IOException {
+ terminateTask(jobId, taskId, null);
+ }
+
+ /**
+ * Terminates the specified task.
+ *
+ * @param jobId
+ * The ID of the job containing the task.
+ * @param taskId
+ * The ID of the task.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void terminateTask(String jobId, String taskId, Iterable additionalBehaviors)
+ throws BatchErrorException, IOException {
+ TaskTerminateOptions options = new TaskTerminateOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().tasks().terminate(jobId, taskId, options);
+ }
+
+ /**
+ * Reactivates a task, allowing it to run again even if its retry count has been
+ * exhausted.
+ *
+ * @param jobId
+ * The ID of the job containing the task.
+ * @param taskId
+ * The ID of the task.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void reactivateTask(String jobId, String taskId) throws BatchErrorException, IOException {
+ reactivateTask(jobId, taskId, null);
+ }
+
+ /**
+ * Reactivates a task, allowing it to run again even if its retry count has been
+ * exhausted.
+ *
+ * @param jobId
+ * The ID of the job containing the task.
+ * @param taskId
+ * The ID of the task.
+ * @param additionalBehaviors
+ * A collection of {@link BatchClientBehavior} instances that are
+ * applied to the Batch service request.
+ * @throws BatchErrorException
+ * Exception thrown when an error response is received from the
+ * Batch service.
+ * @throws IOException
+ * Exception thrown when there is an error in
+ * serialization/deserialization of data sent to/received from the
+ * Batch service.
+ */
+ public void reactivateTask(String jobId, String taskId, Iterable additionalBehaviors)
+ throws BatchErrorException, IOException {
+ TaskReactivateOptions options = new TaskReactivateOptions();
+ BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
+ bhMgr.applyRequestBehaviors(options);
+
+ this._parentBatchClient.protocolLayer().tasks().reactivate(jobId, taskId, options);
+ }
+
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchApplicationTokenCredentials.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchApplicationTokenCredentials.java
new file mode 100644
index 000000000000..cfa2a475b2db
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchApplicationTokenCredentials.java
@@ -0,0 +1,150 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch.auth;
+
+import com.microsoft.aad.adal4j.AuthenticationContext;
+import com.microsoft.aad.adal4j.AuthenticationResult;
+import com.microsoft.aad.adal4j.ClientCredential;
+import com.microsoft.rest.credentials.TokenCredentials;
+import okhttp3.Request;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * Application token based credentials for use with a Batch Service Client.
+ */
+public class BatchApplicationTokenCredentials extends TokenCredentials implements BatchCredentials {
+
+ /** The Active Directory application client id. */
+ final private String clientId;
+ /** The tenant or domain containing the application. */
+ final private String domain;
+ /** The authentication secret for the application. */
+ final private String secret;
+ /** The user's Batch service endpoint */
+ final private String baseUrl;
+ /** The Batch service auth endpoint */
+ final private String batchEndpoint;
+ /** The Active Directory auth endpoint */
+ final private String authenticationEndpoint;
+ /** The cached access token. */
+ private AuthenticationResult authenticationResult;
+
+ /**
+ * Initializes a new instance of the BatchApplicationTokenCredentials.
+ *
+ * @param baseUrl the Batch service endpoint.
+ * @param clientId the Active Directory application client id.
+ * @param secret the authentication secret for the application.
+ * @param domain the domain or tenant id containing this application.
+ * @param batchEndpoint the Batch service endpoint to authenticate with.
+ * @param authenticationEndpoint the Active Directory endpoint to authenticate with.
+ */
+ public BatchApplicationTokenCredentials(String baseUrl, String clientId, String secret, String domain, String batchEndpoint, String authenticationEndpoint) {
+ super(null, null);
+
+ if (baseUrl == null) {
+ throw new IllegalArgumentException("Parameter baseUrl is required and cannot be null.");
+ }
+ if (clientId == null) {
+ throw new IllegalArgumentException("Parameter clientId is required and cannot be null.");
+ }
+ if (secret == null) {
+ throw new IllegalArgumentException("Parameter secret is required and cannot be null.");
+ }
+ if (domain == null) {
+ throw new IllegalArgumentException("Parameter domain is required and cannot be null.");
+ }
+ if (batchEndpoint == null) {
+ batchEndpoint = "https://batch.core.windows.net/";
+ }
+ if (authenticationEndpoint == null) {
+ authenticationEndpoint = "https://login.microsoftonline.com/";
+ }
+
+ this.clientId = clientId;
+ this.baseUrl = baseUrl;
+ this.secret = secret;
+ this.domain = domain;
+ this.batchEndpoint = batchEndpoint;
+ this.authenticationEndpoint = authenticationEndpoint;
+ this.authenticationResult = null;
+ }
+
+ /**
+ * Gets the Active Directory application client id.
+ *
+ * @return the active directory application client id.
+ */
+ public String clientId() {
+ return this.clientId;
+ }
+
+ /**
+ * Gets the tenant or domain containing the application.
+ *
+ * @return the tenant or domain containing the application.
+ */
+ public String domain() {
+ return this.domain;
+ }
+
+ /**
+ * Gets the Active Directory auth endpoint.
+ *
+ * @return the Active Directory auth endpoint.
+ */
+ public String authenticationEndpoint()
+ {
+ return this.authenticationEndpoint;
+ }
+
+ /**
+ * Gets the Batch service auth endpoint.
+ *
+ * @return the Batch service auth endpoint.
+ */
+ public String batchEndpoint()
+ {
+ return this.batchEndpoint;
+ }
+
+ /**
+ * Gets the Batch service endpoint
+ *
+ * @return The Batch service endpoint
+ */
+ @Override
+ public String baseUrl() {
+ return this.baseUrl;
+ }
+
+ @Override
+ public String getToken(Request request) throws IOException {
+ if (authenticationResult == null || authenticationResult.getExpiresOnDate().before(new Date())) {
+ this.authenticationResult = acquireAccessToken();
+ }
+ return authenticationResult.getAccessToken();
+ }
+
+ private AuthenticationResult acquireAccessToken() throws IOException {
+ String authorityUrl = this.authenticationEndpoint() + this.domain();
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+ AuthenticationContext context = new AuthenticationContext(authorityUrl, false, executor);
+ try {
+ this.authenticationResult = context.acquireToken(
+ this.batchEndpoint(),
+ new ClientCredential(this.clientId(), this.secret),
+ null).get();
+ return this.authenticationResult;
+ } catch (Exception e) {
+ throw new IOException(e.getMessage(), e);
+ } finally {
+ executor.shutdown();
+ }
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchCredentials.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchCredentials.java
new file mode 100644
index 000000000000..2ab1e24eceba
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchCredentials.java
@@ -0,0 +1,18 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch.auth;
+
+import com.microsoft.rest.credentials.ServiceClientCredentials;
+
+/**
+ * Interface for credentials used to authenticate access to an Azure Batch account.
+ */
+public interface BatchCredentials extends ServiceClientCredentials {
+ /**
+ * Gets the Batch service endpoint.
+ *
+ * @return The Batch service endpoint.
+ */
+ String baseUrl();
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchSharedKeyCredentials.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchSharedKeyCredentials.java
new file mode 100644
index 000000000000..7a45ba90a7ce
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchSharedKeyCredentials.java
@@ -0,0 +1,75 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch.auth;
+
+import okhttp3.OkHttpClient;
+
+/**
+ * Shared key credentials for an Azure Batch account.
+ */
+public class BatchSharedKeyCredentials implements BatchCredentials {
+
+ private String accountName;
+
+ private String keyValue;
+
+ private String baseUrl;
+
+ /**
+ * Gets the Batch account name.
+ *
+ * @return The Batch account name.
+ */
+ public String accountName() {
+ return accountName;
+ }
+
+ /**
+ * Gets the Base64 encoded account access key.
+ *
+ * @return The Base64 encoded account access key.
+ */
+ public String keyValue() {
+ return keyValue;
+ }
+
+ /**
+ * Initializes a new instance of the {@link BatchSharedKeyCredentials} class with the specified Batch service endpoint, account name, and access key.
+ *
+ * @param baseUrl The Batch service endpoint.
+ * @param accountName The Batch account name.
+ * @param keyValue The Batch access key.
+ */
+ public BatchSharedKeyCredentials(String baseUrl, String accountName, String keyValue) {
+
+ if (baseUrl == null) {
+ throw new IllegalArgumentException("Parameter baseUrl is required and cannot be null.");
+ }
+ if (accountName == null) {
+ throw new IllegalArgumentException("Parameter accountName is required and cannot be null.");
+ }
+ if (keyValue == null) {
+ throw new IllegalArgumentException("Parameter keyValue is required and cannot be null.");
+ }
+
+ this.baseUrl = baseUrl;
+ this.accountName = accountName;
+ this.keyValue = keyValue;
+ }
+
+ /**
+ * Applies the credentials to the Batch service request.
+ *
+ * @param clientBuilder The client builder.
+ */
+ @Override
+ public void applyCredentialsFilter(OkHttpClient.Builder clientBuilder) {
+ clientBuilder.interceptors().add(new BatchSharedKeyCredentialsInterceptor(this));
+ }
+
+ @Override
+ public String baseUrl() {
+ return this.baseUrl;
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchSharedKeyCredentialsInterceptor.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchSharedKeyCredentialsInterceptor.java
new file mode 100644
index 000000000000..2921830cd564
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchSharedKeyCredentialsInterceptor.java
@@ -0,0 +1,177 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch.auth;
+
+import com.microsoft.rest.DateTimeRfc1123;
+import okhttp3.Interceptor;
+import okhttp3.MediaType;
+import okhttp3.Request;
+import okhttp3.Response;
+import org.apache.commons.codec.binary.Base64;
+import org.joda.time.DateTime;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.IOException;
+import java.net.URLDecoder;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * The interceptor class to insert Shared Key credential information to request HEADER.
+ */
+class BatchSharedKeyCredentialsInterceptor implements Interceptor {
+
+ private final BatchSharedKeyCredentials credentials;
+
+ private Mac hmacSha256;
+
+ /**
+ * Constructor for BatchSharedKeyCredentialsInterceptor
+ *
+ * @param batchCredentials The account name/key credential
+ */
+ BatchSharedKeyCredentialsInterceptor(BatchSharedKeyCredentials batchCredentials) {
+ this.credentials = batchCredentials;
+ }
+
+ /**
+ * Inject the new authentication HEADER
+ *
+ * @param chain The interceptor chain
+ * @return Response of the request
+ * @throws IOException Exception thrown from serialization
+ */
+ @Override
+ public Response intercept(Interceptor.Chain chain) throws IOException {
+ Request newRequest = this.signHeader(chain.request());
+ return chain.proceed(newRequest);
+ }
+
+ private String headerValue(Request request, String headerName) {
+ String headerValue = request.header(headerName);
+ if (headerValue == null) {
+ return "";
+ }
+
+ return headerValue;
+ }
+
+ private synchronized String sign(String stringToSign) {
+ try {
+ // Encoding the Signature
+ // Signature=Base64(HMAC-SHA256(UTF8(StringToSign)))
+ byte[] digest = getHmac256().doFinal(stringToSign.getBytes("UTF-8"));
+ return Base64.encodeBase64String(digest);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("accessKey", e);
+ }
+ }
+
+ private synchronized Mac getHmac256() throws NoSuchAlgorithmException, InvalidKeyException {
+ if (this.hmacSha256 == null) {
+ // Initializes the HMAC-SHA256 Mac and SecretKey.
+ this.hmacSha256 = Mac.getInstance("HmacSHA256");
+ this.hmacSha256.init(new SecretKeySpec(Base64.decodeBase64(this.credentials.keyValue()), "HmacSHA256"));
+ }
+ return this.hmacSha256;
+ }
+
+ private Request signHeader(Request request) throws IOException {
+
+ Request.Builder builder = request.newBuilder();
+
+ // Set Headers
+ if (request.headers().get("ocp-date") == null) {
+ DateTimeRfc1123 rfcDate = new DateTimeRfc1123(new DateTime());
+ builder.header("ocp-date", rfcDate.toString());
+ request = builder.build();
+ }
+
+ String signature = request.method() + "\n";
+ signature = signature + headerValue(request, "Content-Encoding")
+ + "\n";
+ signature = signature + headerValue(request, "Content-Language")
+ + "\n";
+
+ // Special handle content length
+ long length = -1;
+ if (request.body() != null) {
+ length = request.body().contentLength();
+ }
+ signature = signature + (length >= 0 ? Long.valueOf(length) : "")
+ + "\n";
+
+ signature = signature + headerValue(request, "Content-MD5") + "\n";
+
+ // Special handle content type header
+ String contentType = request.header("Content-Type");
+ if (contentType == null) {
+ contentType = "";
+ if (request.body() != null) {
+ MediaType mediaType = request.body().contentType();
+ if (mediaType != null) {
+ contentType = mediaType.toString();
+ }
+ }
+ }
+ signature = signature + contentType + "\n";
+
+ signature = signature + headerValue(request, "Date") + "\n";
+ signature = signature + headerValue(request, "If-Modified-Since")
+ + "\n";
+ signature = signature + headerValue(request, "If-Match") + "\n";
+ signature = signature + headerValue(request, "If-None-Match") + "\n";
+ signature = signature + headerValue(request, "If-Unmodified-Since")
+ + "\n";
+ signature = signature + headerValue(request, "Range") + "\n";
+
+ ArrayList customHeaders = new ArrayList<>();
+ for (String name : request.headers().names()) {
+ if (name.toLowerCase().startsWith("ocp-")) {
+ customHeaders.add(name.toLowerCase());
+ }
+ }
+ Collections.sort(customHeaders);
+ for (String canonicalHeader : customHeaders) {
+ String value = request.header(canonicalHeader);
+ value = value.replace('\n', ' ').replace('\r', ' ')
+ .replaceAll("^[ ]+", "");
+ signature = signature + canonicalHeader + ":" + value + "\n";
+ }
+
+ signature = signature + "/"
+ + credentials.accountName().toLowerCase() + "/"
+ + request.url().uri().getRawPath().replaceAll("^[/]+", "");
+
+ String query = request.url().query();
+ if (query != null) {
+ Map queryComponents = new TreeMap<>();
+ String[] pairs = query.split("&");
+ for (String pair : pairs) {
+ int idx = pair.indexOf("=");
+ String key = URLDecoder.decode(pair.substring(0, idx), "UTF-8")
+ .toLowerCase(Locale.US);
+ queryComponents.put(
+ key,
+ key + ":" + URLDecoder.decode(pair.substring(idx + 1),"UTF-8"));
+ }
+
+ for (Map.Entry entry : queryComponents.entrySet()) {
+ signature = signature + "\n" + entry.getValue();
+ }
+ }
+ String signedSignature = sign(signature);
+ String authorization = "SharedKey " + credentials.accountName()
+ + ":" + signedSignature;
+ builder.header("Authorization", authorization);
+
+ return builder.build();
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchUserTokenCredentials.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchUserTokenCredentials.java
new file mode 100644
index 000000000000..0107f687b82f
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/BatchUserTokenCredentials.java
@@ -0,0 +1,165 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch.auth;
+
+import com.microsoft.aad.adal4j.AuthenticationContext;
+import com.microsoft.aad.adal4j.AuthenticationResult;
+import com.microsoft.rest.credentials.TokenCredentials;
+import okhttp3.Request;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * User token based credentials for use with a Batch Service Client.
+ */
+public class BatchUserTokenCredentials extends TokenCredentials implements BatchCredentials {
+
+ /** The Active Directory application client id. */
+ final private String clientId;
+ /** The tenant or domain containing the application. */
+ final private String domain;
+ /** The user name for the Organization Id account. */
+ final private String username;
+ /** The password for the Organization Id account. */
+ final private String password;
+ /** The user's Batch service endpoint */
+ final private String baseUrl;
+ /** The Batch service auth endpoint */
+ final private String batchEndpoint;
+ /** The Active Directory auth endpoint */
+ final private String authenticationEndpoint;
+ /** The cached access token. */
+ private AuthenticationResult authenticationResult;
+
+ /**
+ * Initializes a new instance of the BatchUserTokenCredentials.
+ *
+ * @param baseUrl the Batch service endpoint.
+ * @param clientId the Active Directory application client id.
+ * @param username the user name for the Organization Id account.
+ * @param password the password for the Organization Id account.
+ * @param domain the domain or tenant id containing this application.
+ * @param batchEndpoint the Batch service endpoint to authenticate with.
+ * @param authenticationEndpoint the Active Directory endpoint to authenticate with.
+ */
+ public BatchUserTokenCredentials(String baseUrl, String clientId, String username, String password, String domain, String batchEndpoint, String authenticationEndpoint) {
+ super(null, null);
+
+ if (baseUrl == null) {
+ throw new IllegalArgumentException("Parameter baseUrl is required and cannot be null.");
+ }
+ if (clientId == null) {
+ throw new IllegalArgumentException("Parameter clientId is required and cannot be null.");
+ }
+ if (username == null) {
+ throw new IllegalArgumentException("Parameter username is required and cannot be null.");
+ }
+ if (password == null) {
+ throw new IllegalArgumentException("Parameter password is required and cannot be null.");
+ }
+ if (domain == null) {
+ throw new IllegalArgumentException("Parameter domain is required and cannot be null.");
+ }
+ if (batchEndpoint == null) {
+ batchEndpoint = "https://batch.core.windows.net/";
+ }
+ if (authenticationEndpoint == null) {
+ authenticationEndpoint = "https://login.microsoftonline.com/";
+ }
+
+ this.clientId = clientId;
+ this.baseUrl = baseUrl;
+ this.username = username;
+ this.password = password;
+ this.domain = domain;
+ this.batchEndpoint = batchEndpoint;
+ this.authenticationEndpoint = authenticationEndpoint;
+ this.authenticationResult = null;
+ }
+
+ /**
+ * Gets the Active Directory application client id.
+ *
+ * @return the active directory application client id.
+ */
+ public String clientId() {
+ return this.clientId;
+ }
+
+ /**
+ * Gets the tenant or domain containing the application.
+ *
+ * @return the tenant or domain containing the application.
+ */
+ public String domain() {
+ return this.domain;
+ }
+
+ /**
+ * Gets the user name for the Organization Id account.
+ *
+ * @return the user name.
+ */
+ public String username() { return username; }
+
+ /**
+ * Gets the Active Directory auth endpoint.
+ *
+ * @return the Active Directory auth endpoint.
+ */
+ public String authenticationEndpoint()
+ {
+ return this.authenticationEndpoint;
+ }
+
+ /**
+ * Gets the Batch service auth endpoint.
+ *
+ * @return the Batch service auth endpoint.
+ */
+ public String batchEndpoint()
+ {
+ return this.batchEndpoint;
+ }
+
+ /**
+ * Gets the Batch service endpoint
+ *
+ * @return The Batch service endpoint
+ */
+ @Override
+ public String baseUrl() {
+ return this.baseUrl;
+ }
+
+ @Override
+ public String getToken(Request request) throws IOException {
+ if (authenticationResult == null || authenticationResult.getExpiresOnDate().before(new Date())) {
+ this.authenticationResult = acquireAccessToken();
+ }
+ return authenticationResult.getAccessToken();
+ }
+
+ private AuthenticationResult acquireAccessToken() throws IOException {
+ String authorityUrl = this.authenticationEndpoint() + this.domain();
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+ AuthenticationContext context = new AuthenticationContext(authorityUrl, false, executor);
+ try {
+ this.authenticationResult = context.acquireToken(
+ this.batchEndpoint(),
+ this.clientId(),
+ this.username(),
+ this.password,
+ null).get();
+ return this.authenticationResult;
+ } catch (Exception e) {
+ throw new IOException(e.getMessage(), e);
+ } finally {
+ executor.shutdown();
+ }
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/package-info.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/package-info.java
new file mode 100644
index 000000000000..854998a0ba7d
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/auth/package-info.java
@@ -0,0 +1,7 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+/**
+ * This package contains classes for authenticating requests against the Azure Batch service.
+ */
+package com.microsoft.azure.batch.auth;
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/BatchClientParallelOptions.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/BatchClientParallelOptions.java
new file mode 100644
index 000000000000..05a9ac73d580
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/BatchClientParallelOptions.java
@@ -0,0 +1,57 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch.interceptor;
+
+import com.microsoft.azure.batch.BatchClientBehavior;
+
+/**
+ * Stores options that configure the operation of methods on Batch client parallel operations.
+ */
+public class BatchClientParallelOptions extends BatchClientBehavior {
+
+ private int maxDegreeOfParallelism;
+
+ /**
+ * Gets the maximum number of concurrent tasks enabled by this {@link BatchClientParallelOptions} instance.
+ *
+ * The default value is 1.
+ * @return The maximum number of concurrent tasks.
+ */
+ public int maxDegreeOfParallelism() {
+ return this.maxDegreeOfParallelism;
+ }
+
+ /**
+ * Sets the maximum number of concurrent tasks enabled by this {@link BatchClientParallelOptions} instance.
+ *
+ * @param maxDegreeOfParallelism the maximum number of concurrent tasks.
+ * @return The instance of {@link BatchClientParallelOptions}.
+ */
+ public BatchClientParallelOptions withMaxDegreeOfParallelism(int maxDegreeOfParallelism) {
+ if (maxDegreeOfParallelism > 0) {
+ this.maxDegreeOfParallelism = maxDegreeOfParallelism;
+ }
+ else {
+ throw new IllegalArgumentException("maxDegreeOfParallelism");
+ }
+ return this;
+ }
+
+ /**
+ * Initializes a new instance of the {@link BatchClientParallelOptions} class with default values.
+ */
+ public BatchClientParallelOptions() {
+ this.maxDegreeOfParallelism = 1;
+ }
+
+ /**
+ * Initializes a new instance of the {@link BatchClientParallelOptions} class.
+ *
+ * @param maxDegreeOfParallelism the maximum number of concurrent tasks.
+ */
+ public BatchClientParallelOptions(int maxDegreeOfParallelism) {
+ this.maxDegreeOfParallelism = maxDegreeOfParallelism;
+ }
+
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/BatchRequestInterceptHandler.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/BatchRequestInterceptHandler.java
new file mode 100644
index 000000000000..b37e373b5743
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/BatchRequestInterceptHandler.java
@@ -0,0 +1,16 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch.interceptor;
+
+/**
+ * This interface enables an interceptor to modify a request to the Batch service.
+ */
+public interface BatchRequestInterceptHandler {
+ /**
+ * Modifies the request to the Batch service.
+ *
+ * @param request The outgoing Batch service request.
+ */
+ void modify(Object request);
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/ClientRequestIdInterceptor.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/ClientRequestIdInterceptor.java
new file mode 100644
index 000000000000..b5845aa9bcb8
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/ClientRequestIdInterceptor.java
@@ -0,0 +1,42 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch.interceptor;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.UUID;
+
+/**
+ * Interceptor which contains a function used to generate a client request ID.
+ * If there are multiple instances of this then the last set wins.
+ */
+public class ClientRequestIdInterceptor extends RequestInterceptor {
+ /**
+ * Initializes a new {@link ClientRequestIdInterceptor} for use in setting the client request ID of a request.
+ */
+ public ClientRequestIdInterceptor() {
+ this.withHandler(new BatchRequestInterceptHandler() {
+ @Override
+ public void modify(Object request) {
+ Class> c = request.getClass();
+
+ try {
+ Method clientRequestIdMethod = c.getMethod("withClientRequestId", UUID.class);
+ if (clientRequestIdMethod != null) {
+ UUID clientRequestId = UUID.randomUUID();
+ clientRequestIdMethod.invoke(request, clientRequestId);
+ }
+
+ Method returnClientRequestIdMethod = c.getMethod("withReturnClientRequestId", Boolean.class);
+ if (returnClientRequestIdMethod != null) {
+ returnClientRequestIdMethod.invoke(request, true);
+ }
+ }
+ catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
+ // Ignore exception
+ }
+ }
+ });
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/DetailLevelInterceptor.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/DetailLevelInterceptor.java
new file mode 100644
index 000000000000..712bcf3291b5
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/DetailLevelInterceptor.java
@@ -0,0 +1,72 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch.interceptor;
+
+import com.microsoft.azure.batch.DetailLevel;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Interceptor which contains a function used to apply the {@link DetailLevel}.
+ * If there are multiple instances of this then the last set wins.
+ */
+public class DetailLevelInterceptor extends RequestInterceptor {
+
+ private final DetailLevel detailLevel;
+
+ /**
+ * Initializes a new {@link DetailLevelInterceptor} for applying a {@link DetailLevel} object to a request.
+ *
+ * @param detailLevel The {@link DetailLevel} object.
+ */
+ public DetailLevelInterceptor(final DetailLevel detailLevel) {
+ this.detailLevel = detailLevel;
+ this.withHandler(new BatchRequestInterceptHandler() {
+ @Override
+ public void modify(Object request) {
+ if (detailLevel != null) {
+ Class> c = request.getClass();
+ try {
+ Method selectMethod = c.getMethod("withSelect", String.class);
+ if (selectMethod != null) {
+ selectMethod.invoke(request, detailLevel.selectClause());
+ }
+ }
+ catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
+ // Ignore exception
+ }
+
+ try {
+ Method filterMethod = c.getMethod("withFilter", String.class);
+ if (filterMethod != null) {
+ filterMethod.invoke(request, detailLevel.filterClause());
+ }
+ }
+ catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
+ // Ignore exception
+ }
+
+ try {
+ Method expandMethod = c.getMethod("withExpand", String.class);
+ if (expandMethod != null) {
+ expandMethod.invoke(request, detailLevel.expandClause());
+ }
+ }
+ catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
+ // Ignore exception
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * Gets the detail level applied by this {@link DetailLevelInterceptor} instance.
+ *
+ * @return The detail level applied.
+ */
+ public DetailLevel detailLevel() {
+ return this.detailLevel;
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/PageSizeInterceptor.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/PageSizeInterceptor.java
new file mode 100644
index 000000000000..f907c18535f3
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/PageSizeInterceptor.java
@@ -0,0 +1,48 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch.interceptor;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Interceptor which contains a function used to set the maximum page size of a request.
+ * If there are multiple instances of this then the last set wins.
+ */
+public class PageSizeInterceptor extends RequestInterceptor {
+
+ private final int maxResults;
+
+ /**
+ * Initializes a new {@link PageSizeInterceptor} for setting maximum page size of a request.
+ *
+ * @param pageSize The maximum number of items to return in a response.
+ */
+ public PageSizeInterceptor(int pageSize) {
+ this.maxResults = pageSize;
+ this.withHandler(new BatchRequestInterceptHandler() {
+ @Override
+ public void modify(Object request) {
+ Class> c = request.getClass();
+ try {
+ Method maxResultsMethod = c.getMethod("withMaxResults", Integer.class);
+ if (maxResultsMethod != null) {
+ maxResultsMethod.invoke(request, maxResults);
+ }
+ } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
+ // Ignore exception
+ }
+ }
+ });
+ }
+
+ /**
+ * Gets the maximum number of items applied by this {@link PageSizeInterceptor} instance.
+ *
+ * @return The maximum number of items to return in a response.
+ */
+ public int maxResults() {
+ return this.maxResults;
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/RequestInterceptor.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/RequestInterceptor.java
new file mode 100644
index 000000000000..979562fd8b31
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/RequestInterceptor.java
@@ -0,0 +1,55 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch.interceptor;
+
+import com.microsoft.azure.batch.BatchClientBehavior;
+
+/**
+ * A {@link BatchClientBehavior} that modifies requests to the Batch service.
+ */
+public class RequestInterceptor extends BatchClientBehavior {
+ private BatchRequestInterceptHandler _handler;
+
+ /**
+ * Initializes a new instance of RequestInterceptor.
+ */
+ public RequestInterceptor() {
+ this._handler = new BatchRequestInterceptHandler() {
+
+ @Override
+ public void modify(Object request) {
+ // DO NOTHING
+ }
+ };
+ }
+
+ /**
+ * Initializes a new instance of RequestInterceptor.
+ *
+ * @param handler The handler which will intercept requests to the Batch service.
+ */
+ public RequestInterceptor(BatchRequestInterceptHandler handler) {
+ this._handler = handler;
+ }
+
+ /**
+ * Gets the handler which will intercept requests to the Batch service.
+ *
+ * @return The handler which will intercept requests to the Batch service.
+ */
+ public BatchRequestInterceptHandler handler() {
+ return _handler;
+ }
+
+ /**
+ * Sets the handler which will intercept requests to the Batch service.
+ *
+ * @param handler The handler which will intercept requests to the Batch service.
+ * @return The current instance.
+ */
+ public RequestInterceptor withHandler(BatchRequestInterceptHandler handler) {
+ this._handler = handler;
+ return this;
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/ServerTimeoutInterceptor.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/ServerTimeoutInterceptor.java
new file mode 100644
index 000000000000..9f3f4d9bd069
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/ServerTimeoutInterceptor.java
@@ -0,0 +1,47 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.microsoft.azure.batch.interceptor;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Sets Batch service request timeouts.
+ */
+public class ServerTimeoutInterceptor extends RequestInterceptor {
+
+ private final int serverTimeout;
+
+ /**
+ * Initializes a new {@link ServerTimeoutInterceptor} for setting the service timeout interval for a request issued to the Batch service.
+ *
+ * @param timeout The service timeout interval, in seconds.
+ */
+ public ServerTimeoutInterceptor(int timeout) {
+ this.serverTimeout = timeout;
+ this.withHandler(new BatchRequestInterceptHandler() {
+ @Override
+ public void modify(Object request) {
+ Class> c = request.getClass();
+ try {
+ Method timeoutMethod = c.getMethod("withTimeout", Integer.class);
+ if (timeoutMethod != null) {
+ timeoutMethod.invoke(request, serverTimeout);
+ }
+ } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
+ // Ignore exception
+ }
+ }
+ });
+ }
+
+ /**
+ * Gets the service timeout interval applied by this {@link ServerTimeoutInterceptor} instance.
+ *
+ * @return The service timeout interval, in seconds.
+ */
+ public int serverTimeout() {
+ return this.serverTimeout;
+ }
+}
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/package-info.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/package-info.java
new file mode 100644
index 000000000000..0795b2c99414
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/interceptor/package-info.java
@@ -0,0 +1,6 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+/**
+ * This package contains classes for modifying requests to the Batch service.
+ */
+package com.microsoft.azure.batch.interceptor;
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/package-info.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/package-info.java
new file mode 100644
index 000000000000..b2de32087e41
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/package-info.java
@@ -0,0 +1,7 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+/**
+ * This package contains classes for writing applications that use the Azure Batch service.
+ */
+package com.microsoft.azure.batch;
diff --git a/batch/data-plane/src/main/java/com/microsoft/azure/batch/protocol/Accounts.java b/batch/data-plane/src/main/java/com/microsoft/azure/batch/protocol/Accounts.java
new file mode 100644
index 000000000000..0b2a5fee1275
--- /dev/null
+++ b/batch/data-plane/src/main/java/com/microsoft/azure/batch/protocol/Accounts.java
@@ -0,0 +1,342 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) AutoRest Code Generator
+
+package com.microsoft.azure.batch.protocol;
+
+import com.microsoft.azure.batch.protocol.models.AccountListNodeAgentSkusHeaders;
+import com.microsoft.azure.batch.protocol.models.AccountListNodeAgentSkusNextOptions;
+import com.microsoft.azure.batch.protocol.models.AccountListNodeAgentSkusOptions;
+import com.microsoft.azure.batch.protocol.models.AccountListPoolNodeCountsHeaders;
+import com.microsoft.azure.batch.protocol.models.AccountListPoolNodeCountsNextOptions;
+import com.microsoft.azure.batch.protocol.models.AccountListPoolNodeCountsOptions;
+import com.microsoft.azure.batch.protocol.models.BatchErrorException;
+import com.microsoft.azure.batch.protocol.models.NodeAgentSku;
+import com.microsoft.azure.batch.protocol.models.PoolNodeCounts;
+import com.microsoft.azure.ListOperationCallback;
+import com.microsoft.azure.Page;
+import com.microsoft.azure.PagedList;
+import com.microsoft.rest.ServiceFuture;
+import com.microsoft.rest.ServiceResponseWithHeaders;
+import java.io.IOException;
+import java.util.List;
+import rx.Observable;
+
+/**
+ * An instance of this class provides access to all the operations defined
+ * in Accounts.
+ */
+public interface Accounts {
+ /**
+ * Lists all node agent SKUs supported by the Azure Batch service.
+ *
+ * @throws IllegalArgumentException thrown if parameters fail the validation
+ * @throws BatchErrorException thrown if the request is rejected by server
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
+ * @return the PagedList<NodeAgentSku> object if successful.
+ */
+ PagedList listNodeAgentSkus();
+
+ /**
+ * Lists all node agent SKUs supported by the Azure Batch service.
+ *
+ * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
+ * @throws IllegalArgumentException thrown if parameters fail the validation
+ * @return the {@link ServiceFuture} object
+ */
+ ServiceFuture> listNodeAgentSkusAsync(final ListOperationCallback serviceCallback);
+
+ /**
+ * Lists all node agent SKUs supported by the Azure Batch service.
+ *
+ * @throws IllegalArgumentException thrown if parameters fail the validation
+ * @return the observable to the PagedList<NodeAgentSku> object
+ */
+ Observable> listNodeAgentSkusAsync();
+
+ /**
+ * Lists all node agent SKUs supported by the Azure Batch service.
+ *
+ * @throws IllegalArgumentException thrown if parameters fail the validation
+ * @return the observable to the PagedList<NodeAgentSku> object
+ */
+ Observable, AccountListNodeAgentSkusHeaders>> listNodeAgentSkusWithServiceResponseAsync();
+ /**
+ * Lists all node agent SKUs supported by the Azure Batch service.
+ *
+ * @param accountListNodeAgentSkusOptions Additional parameters for the operation
+ * @throws IllegalArgumentException thrown if parameters fail the validation
+ * @throws BatchErrorException thrown if the request is rejected by server
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
+ * @return the PagedList<NodeAgentSku> object if successful.
+ */
+ PagedList listNodeAgentSkus(final AccountListNodeAgentSkusOptions accountListNodeAgentSkusOptions);
+
+ /**
+ * Lists all node agent SKUs supported by the Azure Batch service.
+ *
+ * @param accountListNodeAgentSkusOptions Additional parameters for the operation
+ * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
+ * @throws IllegalArgumentException thrown if parameters fail the validation
+ * @return the {@link ServiceFuture} object
+ */
+ ServiceFuture> listNodeAgentSkusAsync(final AccountListNodeAgentSkusOptions accountListNodeAgentSkusOptions, final ListOperationCallback serviceCallback);
+
+ /**
+ * Lists all node agent SKUs supported by the Azure Batch service.
+ *
+ * @param accountListNodeAgentSkusOptions Additional parameters for the operation
+ * @throws IllegalArgumentException thrown if parameters fail the validation
+ * @return the observable to the PagedList<NodeAgentSku> object
+ */
+ Observable> listNodeAgentSkusAsync(final AccountListNodeAgentSkusOptions accountListNodeAgentSkusOptions);
+
+ /**
+ * Lists all node agent SKUs supported by the Azure Batch service.
+ *
+ * @param accountListNodeAgentSkusOptions Additional parameters for the operation
+ * @throws IllegalArgumentException thrown if parameters fail the validation
+ * @return the observable to the PagedList<NodeAgentSku> object
+ */
+ Observable, AccountListNodeAgentSkusHeaders>> listNodeAgentSkusWithServiceResponseAsync(final AccountListNodeAgentSkusOptions accountListNodeAgentSkusOptions);
+
+ /**
+ * Gets the number of nodes in each state, grouped by pool.
+ *
+ * @throws IllegalArgumentException thrown if parameters fail the validation
+ * @throws BatchErrorException thrown if the request is rejected by server
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
+ * @return the PagedList<PoolNodeCounts> object if successful.
+ */
+ PagedList listPoolNodeCounts();
+
+ /**
+ * Gets the number of nodes in each state, grouped by pool.
+ *
+ * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
+ * @throws IllegalArgumentException thrown if parameters fail the validation
+ * @return the {@link ServiceFuture} object
+ */
+ ServiceFuture