Current version is 9.0.0, click here for the index

Azure Batch Libraries for Java

This README is based on the latest released version Azure Batch SDK (7.0.0). If you are looking for other releases, see the More Information section below.

The Azure Batch Libraries for Java is a higher-level, object-oriented API for interacting with the Azure Batch service.

7.0.0 is a release that supports all features of Azure Batch service with API version "2019-08-01.10.0". We will be adding support for more new features and tweaking the API associated with Azure Batch service newer release.

Azure Batch Authentication

You need to create a Batch account through the Azure portal or Azure cli.

  • Use the account name, key, and URL to create a BatchSharedKeyCredentials instance for authentication with the Azure Batch service. The BatchClient class is the simplest entry point for creating and interacting with Azure Batch objects.
BatchSharedKeyCredentials cred = new BatchSharedKeyCredentials(batchUri, batchAccount, batchKey);
BatchClient client = BatchClient.open(cred);
  • The other way is using AAD (Azure Active Directory) authentication to create the client. See this document for detail.
BatchApplicationTokenCredentials cred = new BatchApplicationTokenCredentials(batchEndpoint, clientId, applicationSecret, applicationDomain, null, null);
BatchClient client = BatchClient.open(cred);

Create a pool using an Azure Marketplace image

You can create a pool of Azure virtual machines which can be used to execute tasks.

System.out.println("Created a pool using an Azure Marketplace image.");

VirtualMachineConfiguration configuration = new VirtualMachineConfiguration();
configuration.withNodeAgentSKUId(skuId).withImageReference(imageRef);
client.poolOperations().createPool(poolId, poolVMSize, configuration, poolVMCount);

System.out.println("Created a Pool: " + poolId);

Create a Job

You can create a job by using the recently created pool.

PoolInformation poolInfo = new PoolInformation();
poolInfo.withPoolId(poolId);
client.jobOperations().createJob(jobId, poolInfo);

Sample Code

You can find sample code that illustrates Batch usage scenarios in https://github.com/azure/azure-batch-samples

Download

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-batch</artifactId>
    <version>8.1.0</version>
</dependency>

Pre-requisites

Help

If you encounter any bugs with these libraries, please file issues via Issues or checkout StackOverflow for Azure Java SDK.

Contribute Code

For details on contributing to this repository, see the contributing guide.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Build Code

To build the code open a console, navigate to the git repository, and run

maven build

Test Code

All tests are run from the sdk/batch directory. They can be run either on the command line or from a Java IDE, such as Eclipse.

Step 1: Run tests in Record mode

  1. Deploy test resources in Azure and set the following environment variables:

    • APPLICATION_SECRET
    • AZUREBATCHACCESS_KEY
    • AZUREBATCHACCOUNT
    • AZUREBATCHENDPOINT
    • AZUREBATCHREGION
    • AZURE_VNET
    • AZUREVNETADDRESS_SPACE
    • AZUREVNETRESOURCE_GROUP
    • AZUREVNETSUBNET
    • AZUREVNETSUBNETADDRESSSPACE
    • CLIENT_ID
    • STORAGEACCOUNTKEY
    • STORAGEACCOUNTNAME
    • SUBSCRIPTION_ID
  2. Set AZURE_TEST_MODE to Record

  3. Run the tests in src/test/java
    1. From the command-line, run mvn test (can also supply -DAZURE_TEST_MODE=Record instead of setting environment variable)
  4. Test recordings will be created in microsoft-azure-batch/target/test-classes/session-records
  5. Copy these recordings to microsoft-azure-batch/src/test/resources/test-recordings

Step 2: Run tests in Playback mode

  1. Set AZURE_TEST_MODE to Playback
  2. Run the Jetty test server
    1. CLI: mvn jetty:start
    2. Eclipse: Install Jetty plugin for Eclipse from marketplace and create two run configurations (one for 11080 and one for 11081)
  3. Run the tests
    1. CLI: mvn test -DAZURE_TEST_MODE=Playback

More Information


This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Impressions

Azure Batch 
Package Description
com.microsoft.azure.batch
This package contains the classes for BatchServiceClient.
com.microsoft.azure.batch.auth
This package contains classes for authenticating requests against the Azure Batch service.
com.microsoft.azure.batch.interceptor
This package contains classes for modifying requests to the Batch service.
com.microsoft.azure.batch.protocol
This package contains the classes for BatchServiceClient.
com.microsoft.azure.batch.protocol.implementation
This package contains the implementation classes for BatchServiceClient.
com.microsoft.azure.batch.protocol.models
This package contains the models classes for BatchServiceClient.