New to Claude Skills? Learn how to install them →

sickn33 on GitHub

Azure Batch SDK for Java

Free

Efficiently run high-performance batch jobs in Azure.

Get this skill

Free · Opens the source repo

What Azure Batch SDK for Java does

The Azure Batch SDK for Java allows developers to manage and execute large-scale parallel and high-performance computing (HPC) batch jobs on the Azure platform. This client library provides a structured way to interact with Azure Batch services, enabling the creation and management of pools, jobs, and tasks. By leveraging Azure's infrastructure, users can efficiently scale their computational workloads without the need for extensive local resources.

To get started, users must have an Azure Batch account and a configured pool of compute nodes. The SDK supports both synchronous and asynchronous operations, allowing developers to choose the interaction model that best suits their application. With features like job scheduling, task management, and pool resizing, the SDK provides comprehensive tools for managing batch processes, making it suitable for a variety of computational tasks, from data processing to simulations.

The SDK also supports integration with Microsoft Entra ID for secure authentication, ensuring that access to Azure resources is managed effectively. Developers can create pools of virtual machines, submit jobs, and monitor their execution, all through a straightforward API. This makes it an ideal choice for developers looking to implement HPC solutions in Java, as it abstracts much of the complexity involved in managing cloud resources.

Overall, the Azure Batch SDK for Java is designed for developers and engineers who need to run large-scale batch jobs efficiently in the cloud. Its robust features and ease of use make it a valuable tool for anyone working with high-performance computing on Azure.

When to use it

Use this skill when you need to run parallel and high-performance computing jobs in Azure, particularly when dealing with large datasets or computationally intensive tasks.

When not to use it

This skill is not suitable for small-scale or single-instance computations, where simpler solutions may suffice.

What you can build with it

Running Data Processing Jobs

Use the Azure Batch SDK to manage and execute data processing jobs that require significant computational resources.

Simulating Complex Models

Leverage the SDK to run simulations that require parallel processing across multiple compute nodes.

Automating Batch Tasks

Implement automated workflows for batch tasks using the SDK's job scheduling and task management features.

How to install Azure Batch SDK for Java

View source

1. Install with the skills CLI

npx skills add sickn33/agentic-awesome-skills/azure-compute-batch-java --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by sickn33

Azure Batch SDK for Java

Client library for running large-scale parallel and high-performance computing (HPC) batch jobs in Azure.

Installation

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-compute-batch</artifactId>
    <version>1.0.0-beta.5</version>
</dependency>

Prerequisites

  • Azure Batch account
  • Pool configured with compute nodes
  • Azure subscription

Environment Variables

AZURE_BATCH_ENDPOINT=https://<account>.<region>.batch.azure.com
AZURE_BATCH_ACCOUNT=<account-name>
AZURE_BATCH_ACCESS_KEY=<account-key>

Client Creation

With Microsoft Entra ID (Recommended)

import com.azure.compute.batch.BatchClient;
import com.azure.compute.batch.BatchClientBuilder;
import com.azure.identity.DefaultAzureCredentialBuilder;

BatchClient batchClient = new BatchClientBuilder()
    .credential(new DefaultAzureCredentialBuilder().build())
    .endpoint(System.getenv("AZURE_BATCH_ENDPOINT"))
    .buildClient();

Async Client

import com.azure.compute.batch.BatchAsyncClient;

BatchAsyncClient batchAsyncClient = new BatchClientBuilder()
    .credential(new DefaultAzureCredentialBuilder().build())
    .endpoint(System.getenv("AZURE_BATCH_ENDPOINT"))
    .buildAsyncClient();

With Shared Key Credentials

import com.azure.core.credential.AzureNamedKeyCredential;

String accountName = System.getenv("AZURE_BATCH_ACCOUNT");
String accountKey = System.getenv("AZURE_BATCH_ACCESS_KEY");
AzureNamedKeyCredential sharedKeyCreds = new AzureNamedKeyCredential(accountName, accountKey);

BatchClient batchClient = new BatchClientBuilder()
    .credential(sharedKeyCreds)
    .endpoint(System.getenv("AZURE_BATCH_ENDPOINT"))
    .buildClient();

Key Concepts

ConceptDescription
PoolCollection of compute nodes that run tasks
JobLogical grouping of tasks
TaskUnit of computation (command/script)
NodeVM that executes tasks
Job ScheduleRecurring job creation

Pool Operations

Create Pool

import com.azure.compute.batch.models.*;

batchClient.createPool(new BatchPoolCreateParameters("myPoolId", "STANDARD_DC2s_V2")
    .setVirtualMachineConfiguration(
        new VirtualMachineConfiguration(
            new BatchVmImageReference()
                .setPublisher("Canonical")
                .setOffer("UbuntuServer")
                .setSku("22_04-lts")
                .setVersion("latest"),
            "batch.node.ubuntu 22.04"))
    .setTargetDedicatedNodes(2)
    .setTargetLowPriorityNodes(0), null);

Get Pool

BatchPool pool = batchClient.getPool("myPoolId");
System.out.println("Pool state: " + pool.getState());
System.out.println("Current dedicated nodes: " + pool.getCurrentDedicatedNodes());

List Pools

import com.azure.core.http.rest.PagedIterable;

PagedIterable<BatchPool> pools = batchClient.listPools();
for (BatchPool pool : pools) {
    System.out.println("Pool: " + pool.getId() + ", State: " + pool.getState());
}

Resize Pool

import com.azure.core.util.polling.SyncPoller;

BatchPoolResizeParameters resizeParams = new BatchPoolResizeParameters()
    .setTargetDedicatedNodes(4)
    .setTargetLowPriorityNodes(2);

SyncPoller<BatchPool, BatchPool> poller = batchClient.beginResizePool("myPoolId", resizeParams);
poller.waitForCompletion();
BatchPool resizedPool = poller.getFinalResult();

Enable AutoScale

BatchPoolEnableAutoScaleParameters autoScaleParams = new BatchPoolEnableAutoScaleParameters()
    .setAutoScaleEvaluationInterval(Duration.ofMinutes(5))
    .setAutoScaleFormula("$TargetDedicatedNodes = min(10, $PendingTasks.GetSample(TimeInterval_Minute * 5));");

batchClient.enablePoolAutoScale("myPoolId", autoScaleParams);

Delete Pool

SyncPoller<BatchPool, Void> deletePoller = batchClient.beginDeletePool("myPoolId");
deletePoller.waitForCompletion();

Job Operations

Create Job

batchClient.createJob(
    new BatchJobCreateParameters("myJobId", new BatchPoolInfo().setPoolId("myPoolId"))
        .setPriority(100)
        .setConstraints(new BatchJobConstraints()
            .setMaxWallClockTime(Duration.ofHours(24))
            .setMaxTaskRetryCount(3)),
    null);

Get Job

BatchJob job = batchClient.getJob("myJobId", null, null);
System.out.println("Job state: " + job.getState());

List Jobs

PagedIterable<BatchJob> jobs = batchClient.listJobs(new BatchJobsListOptions());
for (BatchJob job : jobs) {
    System.out.println("Job: " + job.getId() + ", State: " + job.getState());
}

Get Task Counts

BatchTaskCountsResult counts = batchClient.getJobTaskCounts("myJobId");
System.out.println("Active: " + counts.getTaskCounts().getActive());
System.out.println("Running: " + counts.getTaskCounts().getRunning());
System.out.println("Completed: " + counts.getTaskCounts().getCompleted());

Terminate Job

BatchJobTerminateParameters terminateParams = new BatchJobTerminateParameters()
    .setTerminationReason("Manual termination");
BatchJobTerminateOptions options = new BatchJobTerminateOptions().setParameters(terminateParams);

SyncPoller<BatchJob, BatchJob> poller = batchClient.beginTerminateJob("myJobId", options, null);
poller.waitForCompletion();

Delete Job

SyncPoller<BatchJob, Void> deletePoller = batchClient.beginDeleteJob("myJobId");
deletePoller.waitForCompletion();

Task Operations

Create Single Task

BatchTaskCreateParameters task = new BatchTaskCreateParameters("task1", "echo 'Hello World'");
batchClient.createTask("myJobId", task);

Create Task with Exit Conditions

batchClient.createTask("myJobId", new BatchTaskCreateParameters("task2", "cmd /c exit 3")
    .setExitConditions(new ExitConditions()
        .setExitCodeRanges(Arrays.asList(
            new ExitCodeRangeMapping(2, 4, 
                new ExitOptions().setJobAction(BatchJobActionKind.TERMINATE)))))
    .setUserIdentity(new UserIdentity()
        .setAutoUser(new AutoUserSpecification()
            .setScope(AutoUserScope.TASK)
            .setElevationLevel(ElevationLevel.NON_ADMIN))),
    null);

Create Task Collection (up to 100)

List<BatchTaskCreateParameters> taskList = Arrays.asList(
    new BatchTaskCreateParameters("task1", "echo Task 1"),
    new BatchTaskCreateParameters("task2", "echo Task 2"),
    new BatchTaskCreateParameters("task3", "echo Task 3")
);
BatchTaskGroup taskGroup = new BatchTaskGroup(taskList);
BatchCreateTaskCollectionResult result = batchClient.createTaskCollection("myJobId", taskGroup);

Create Many Tasks (no limit)

List<BatchTaskCreateParameters> tasks = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
    tasks.add(new BatchTaskCreateParameters("task" + i, "echo Task " + i));
}
batchClient.createTasks("myJobId", tasks);

Get Task

BatchTask task = batchClient.getTask("myJobId", "task1");
System.out.println("Task state: " + task.getState());
System.out.println("Exit code: " + task.getExecutionInfo().getExitCode());

List Tasks

PagedIterable<BatchTask> tasks = batchClient.listTasks("myJobId");
for (BatchTask task : tasks) {
    System.out.println("Task: " + task.getId() + ", State: " + task.getState());
}

Get Task Output

import com.azure.core.util.BinaryData;
import java.nio.charset.StandardCharsets;

BinaryData stdout = batchClient.getTaskFile("myJobId", "task1", "stdout.txt");
System.out.println(new String(stdout.toBytes(), StandardCharsets.UTF_8));

Terminate Task

batchClient.terminateTask("myJobId", "task1", null, null);

Node Operations

List Nodes

PagedIterable<BatchNode> nodes = batchClient.listNodes("myPoolId", new BatchNodesListOptions());
for (BatchNode node : nodes) {
    System.out.println("Node: " + node.getId() + ", State: " + node.getState());
}

Reboot Node

SyncPoller<BatchNode, BatchNode> rebootPoller = batchClient.beginRebootNode("myPoolId", "nodeId");
rebootPoller.waitForCompletion();

Get Remote Login Settings

BatchNodeRemoteLoginSettings settings = batchClient.getNodeRemoteLoginSettings("myPoolId", "nodeId");
System.out.println("IP: " + settings.getRemoteLoginIpAddress());
System.out.println("Port: " + settings.getRemoteLoginPort());

Job Schedule Operations

Create Job Schedule

batchClient.createJobSchedule(new BatchJobScheduleCreateParameters("myScheduleId",
    new BatchJobScheduleConfiguration()
        .setRecurrenceInterval(Duration.ofHours(6))
        .setDoNotRunUntil(OffsetDateTime.now().plusDays(1)),
    new BatchJobSpecification(new BatchPoolInfo().setPoolId("myPoolId"))
        .setPriority(50)),
    null);

Get Job Schedule

BatchJobSchedule schedule = batchClient.getJobSchedule("myScheduleId");
System.out.println("Schedule state: " + schedule.getState());

Error Handling

import com.azure.compute.batch.models.BatchErrorException;
import com.azure.compute.batch.models.BatchError;

try {
    batchClient.getPool("nonexistent-pool");
} catch (BatchErrorException e) {
    BatchError error = e.getValue();
    System.err.println("Error code: " + error.getCode());
    System.err.println("Message: " + error.getMessage().getValue());
    
    if ("PoolNotFound".equals(error.getCode())) {
        System.err.println("The specified pool does not exist.");
    }
}

Best Practices

  1. Use Entra ID — Preferred over shared key for authentication
  2. Use management SDK for poolsazure-resourcemanager-batch supports managed identities
  3. Batch task creation — Use createTaskCollection or createTasks for multiple tasks
  4. Handle LRO properly — Pool resize, delete operations are long-running
  5. Monitor task counts — Use getJobTaskCounts to track progress
  6. Set constraints — Configure maxWallClockTime and maxTaskRetryCount
  7. Use low-priority nodes — Cost savings for fault-tolerant workloads
  8. Enable autoscale — Dynamically adjust pool size based on workload

Reference Links

ResourceURL
Maven Packagehttps://central.sonatype.com/artifact/com.azure/azure-compute-batch
GitHubhttps://github.com/Azure/azure-sdk-for-java/tree/main/sdk/batch/azure-compute-batch
API Documentationhttps://learn.microsoft.com/java/api/com.azure.compute.batch
Product Docshttps://learn.microsoft.com/azure/batch/
REST APIhttps://learn.microsoft.com/rest/api/batchservice/
Sampleshttps://github.com/azure/azure-batch-samples

When to Use

This skill is applicable to execute the workflow or actions described in the overview.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

Frequently asked questions about Azure Batch SDK for Java

Similar skills