Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch: Data plane TypeSpec #37319

Merged
merged 98 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
636237e
Created Batch TypeSpec local project
NickKouds Mar 31, 2023
f43744f
Generated Java Batch SDK
NickKouds Apr 1, 2023
1f808c8
Added README for compiling and emitting Track 2 SDK from TypeSpec
NickKouds Apr 11, 2023
e3a81ef
Extended the BatchServiceClientTestBase and created additional tests
NickKouds Apr 18, 2023
3c46ff4
Created Task test and fixed TypeSpec test generation configuration
NickKouds Apr 20, 2023
d5ded54
More test modifications and updated TypeSpec with RPC operations
NickKouds Apr 21, 2023
6c069e2
Adding Java SDK generated changes from TypeSpec RPC Operation and vis…
NickKouds Apr 25, 2023
0fe162e
Applied secret decorator to password TypeSpec property and incorporat…
NickKouds Apr 25, 2023
110093f
Implemented Shared Key authentication for Batch Track 2 (#34871)
NickKouds May 22, 2023
e6db859
Replaced Base64 from codec with java.util.Base64 (#35214)
NickKouds Jun 1, 2023
6696d79
Modified Batch Track 2 Test format and included sanitizers with custo…
NickKouds Jun 20, 2023
29884af
Applying Unified Model and miscellaneous TypeSpec changes to Java SDK…
NickKouds Jul 27, 2023
4996938
Added the Bulk Task Create Utility, removed older compute node client…
NickKouds Aug 4, 2023
dd31c91
Migrated rest of track 1 Batch tests into track 2 and ported 2023-05-…
NickKouds Aug 23, 2023
067c4e6
Remove `throws` for RuntimeException, InterruptedException (#36841)
dpwatrous Sep 19, 2023
eec6430
Flatten TypeSpec and replace BatchSharedKeyCreds with AzureNamedKeyCr…
skapur12 Oct 16, 2023
2cba52f
Update tspconfig and SDK to remove ocp date header
skapur12 Oct 19, 2023
865d8d2
Fix timeOut description
skapur12 Oct 22, 2023
5b5ff10
Fix typo in extensionName property
skapur12 Oct 22, 2023
8a528c3
Group optional arguments into options bag
skapur12 Oct 23, 2023
610b9bb
Update Record tests
skapur12 Oct 23, 2023
6ed2290
Refactor Options Bag grouping and update clients
skapur12 Oct 26, 2023
dc4e009
Update TypeSpec with renaming changes
skapur12 Oct 30, 2023
455b627
Tag internal methods, add subclass per options bag
skapur12 Nov 6, 2023
6de31a0
Update tests for renames and options bag support
skapur12 Nov 6, 2023
c1634d9
Update Record tests
skapur12 Nov 6, 2023
ec2b8a0
Rename BatchServiceClientTestBase
skapur12 Nov 13, 2023
9ff6fe7
Fix checkstyle and spotbug warnings
skapur12 Nov 13, 2023
2d7114f
Return object in setter methods instead of void
skapur12 Nov 13, 2023
41badd5
Update the Record Tests
skapur12 Nov 13, 2023
3de159a
Fix checkstyle errors in tests
dpwatrous Nov 17, 2023
db6854b
Add return javadoc to options bag setter methods
skapur12 Nov 20, 2023
be9493b
Fix name of GetBatchNodeRemoteLoginSettingsOptions
skapur12 Nov 20, 2023
6e0ca54
Improve setMaxDegreeOfParallelism error message
skapur12 Nov 20, 2023
5c352fe
Add final keyword to WorkingThread instance fields
skapur12 Nov 20, 2023
62421cd
Add createTasks async implementation and test
skapur12 Nov 29, 2023
bff7f2b
Ignore SpotBugs SE_BAD_FIELD for CreateTasksErrorException
dpwatrous Nov 21, 2023
f9715c8
Update Record Tests
skapur12 Nov 29, 2023
f1b1467
Added tsp-location.yaml
dpwatrous Dec 12, 2023
a1c8c37
Update tsp-location.yaml
dpwatrous Dec 19, 2023
273ca65
Generate SDK from official TypeSpec compiler
skapur12 Jan 9, 2024
29ace75
Make async task functions execute asynchronously
skapur12 Jan 9, 2024
b20992c
Update Record tests
skapur12 Jan 9, 2024
cce1c63
Rename parameter to azureNamedKeyCredential
skapur12 Jan 23, 2024
885e1a2
Remove InterruptedException from createTasks
skapur12 Jan 25, 2024
19707b7
Regenerate SDK based off of updated TypeSpec files
skapur12 Jan 30, 2024
e38ae09
Change kernelCPUTime to kernelCpuTime
skapur12 Jan 30, 2024
654d50c
Change userCPUTime to userCpuTime
skapur12 Jan 30, 2024
2335d42
Change lun to logicalUnitNumber
skapur12 Jan 30, 2024
77b9a11
Edit logicalUnitNumber docstring and update test
skapur12 Jan 30, 2024
3d9bbfb
Change terminateReason to terminationReason
skapur12 Jan 30, 2024
098ecf1
Make getNodeFile return streaming data type
skapur12 Jan 30, 2024
d1d5e04
Change capitalization in models for accuracy
skapur12 Jan 31, 2024
72902e7
Revamp BatchClientParallelOptions and fix tests
skapur12 Jan 31, 2024
a87d622
Edit docstring for clarity
skapur12 Jan 31, 2024
8048b51
Remove dependency on management library
skapur12 Jan 31, 2024
443fe1a
Remove setPoolInfo method from BatchJob
skapur12 Feb 5, 2024
f3b5502
Make getNodeFileProperties return file properties
skapur12 Feb 6, 2024
a9b0c28
Run Record Tests again
skapur12 Feb 6, 2024
bd9fbba
Regenerate SDK with Parameters to Content change
skapur12 Mar 11, 2024
fefc887
Update Record Tests
skapur12 Mar 11, 2024
5ca549a
Delete batch-typespec directory as it is unneeded
skapur12 Mar 11, 2024
3146cd3
Regenerate Java SDK
skapur12 Mar 26, 2024
2ec1a0f
Update Record Tests
skapur12 Mar 27, 2024
1ab0a4c
Change getRecursive to isRecursive
skapur12 Mar 29, 2024
a0c7119
Add get prefix to maxDegreeOfParallelism function
skapur12 Mar 29, 2024
e4d9a85
Annotate all applicable methods with ServiceMethod
skapur12 Apr 3, 2024
b0c09cc
Add overload for list operations
skapur12 Apr 3, 2024
7f152a3
Update dependencies in pom file
skapur12 Apr 4, 2024
ffa964a
Fix return type of getTaskFileProperties
skapur12 Apr 5, 2024
1eec8dd
Regenerate Java SDK with new emitter
skapur12 Apr 5, 2024
a918784
Update Record Tests
skapur12 Apr 5, 2024
1f836e6
Update ci.yml
weidongxu-microsoft Apr 7, 2024
e5bad4d
Add test proxy configuration
skapur12 Apr 10, 2024
cdc513f
Update assets tag
skapur12 Apr 10, 2024
bd25f61
Update pom.xml versions
skapur12 Apr 10, 2024
6ff9228
Fix endpoint URL
skapur12 Apr 10, 2024
dde3f3c
Update assets tag for Record Tests
skapur12 Apr 10, 2024
d14af7c
Fix Playback test errors
skapur12 Apr 10, 2024
929a8ea
Skip test coverage check for preview
skapur12 Apr 11, 2024
20b7eb3
Add spelling exceptions to cpsell config file
skapur12 Apr 11, 2024
f10e4ff
Add example and troubleshooting sections to Readme
skapur12 Apr 12, 2024
004a988
Regenerate Java SDK from latest TypeSpec
skapur12 Apr 16, 2024
f82a3e6
Update assets tag for Record Tests
skapur12 Apr 16, 2024
c1d407d
Regenerate SDK with stream style serialization
skapur12 Apr 18, 2024
70e7a1b
Fix contentLength parsing error in FileProperties
skapur12 Apr 19, 2024
5d1831c
Regenerate SDK with certificates removed
skapur12 Apr 19, 2024
c8d0648
Override serialization function to fix cert issue
skapur12 Apr 19, 2024
bc94a14
Update assets tag for Record Tests
skapur12 Apr 19, 2024
2bfa18f
Update pom.xml dependency version
skapur12 Apr 19, 2024
fae103f
Update pom.xml
skapur12 Apr 26, 2024
596c2ed
Update tsp-location.yaml and regenerate SDK
skapur12 Apr 29, 2024
6d783a8
Update pom.xml
skapur12 May 12, 2024
651e65c
Regenerate SDK
skapur12 May 12, 2024
4677095
Fix capitalization on InboundNatPool file name
skapur12 May 12, 2024
ada71c3
Fix capitalization in tests
skapur12 May 12, 2024
2aa95f0
Remove unused imports
skapur12 May 12, 2024
7f1e37c
Regenerate SDK
skapur12 May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 15 additions & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,21 @@
"XLint"
],
"overrides": [
{
"filename": "sdk/batch/azure-compute-batch/**",
"words": [
"Dtest",
"osdisk",
"nopublicipaddresses",
"cifs",
"noaction",
"upgradingos",
"VMSS",
"reimaged",
"isdirectory",
"SSDLRS"
]
},
{
"filename": "sdk/search/azure-search-documents/**",
"words": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@
<Package name="~com\.microsoft\.azure\.batch(\..+)?"/>
</Match>

<!-- Batch CreateTasksErrorException task fields do not need to be serializable -->
<Match>
<Class name="com.microsoft.azure.batch.CreateTasksErrorException"/>
<Or>
Expand All @@ -377,6 +378,15 @@
<Bug pattern="SE_BAD_FIELD"/>
</Match>

<Match>
<Class name="com.azure.compute.batch.models.CreateTasksErrorException"/>
<Or>
<Field name="failureTaskList"/>
<Field name="pendingTaskList"/>
</Or>
<Bug pattern="SE_BAD_FIELD"/>
</Match>

<!-- The fields are checked for null in the build method and throw exceptions if values for fields are not specified. -->
<Match>
<Class name="com.azure.identity.InteractiveBrowserCredentialBuilder"/>
Expand Down
1 change: 1 addition & 0 deletions eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ com.azure:azure-communication-messages;1.0.2;1.1.0-beta.1
com.azure:azure-communication-phonenumbers;1.1.12;1.2.0-beta.4
com.azure:azure-communication-rooms;1.1.1;1.2.0-beta.1
com.azure:azure-communication-sms;1.1.23;1.2.0-beta.1
com.azure:azure-compute-batch;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-containers-containerregistry;1.2.7;1.3.0-beta.1
com.azure:azure-containers-containerregistry-perf;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-core;1.49.0;1.50.0-beta.1
Expand Down
13 changes: 13 additions & 0 deletions sdk/batch/azure-compute-batch/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Release History

## 1.0.0-beta.1 (Unreleased)

- Azure Batch client library for Java. This package contains Microsoft Azure Batch client library.

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
255 changes: 255 additions & 0 deletions sdk/batch/azure-compute-batch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
# Azure Batch client library for Java

This README is based on the latest released version of the Azure Compute Batch SDK, otherwise known as the track 2 Azure Batch Data Plane SDK.

> The SDK supports features of the Azure Batch service starting from API version **2023-05-01.16.0**. We will be adding support for more new features and tweaking the API associated with Azure Batch service newer release.

## Documentation

Various documentation is available to help you get started

- [API reference documentation][docs]
- [Product documentation][product_documentation]

## Getting started

### Prerequisites

- [Java Development Kit (JDK)][jdk] with version 8 or above
- [Azure Subscription][azure_subscription]

### Adding the package to your product

[//]: # ({x-version-update-start;com.azure:azure-compute-batch;current})

```xml
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-compute-batch</artifactId>
<version>1.0.0-beta.1</version>
</dependency>
```

[//]: # ({x-version-update-end})

### Authentication

You can authenticate with Microsoft Entra ID authentication.

## Key concepts

### Azure Batch Authentication

You need to create a Batch account through the [Azure portal](https://portal.azure.com) or Azure cli.

- Use the account name, key, and URL to create a `BatchSharedKeyCredentials` instance for authentication with the Azure Batch service.
The `BatchServiceClientBuilder` class is the simplest entry point for creating and interacting with Azure Batch objects.

```java
BatchServiceClientBuilder batchClientBuilder = new BatchServiceClientBuilder()
.endpoint(batchEndpoint)
.httpClient(HttpClient.createDefault());

BatchSharedKeyCredentials sharedKeyCred = new BatchSharedKeyCredentials(batchEndpoint, accountName, accountKey);

batchClientBuilder.credential(sharedKeyCred);
```

- The other way is using Entra ID authentication to create the client. See this [document](https://docs.microsoft.com/azure/batch/batch-aad-auth) for details on authenticating to Batch with Entra ID.
For example:

```java
batchClientBuilder.credential(new DefaultAzureCredentialBuilder().build());
```

### Create a pool using an Azure Marketplace image

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

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

ImageReference imgRef = new ImageReference().setPublisher("Canonical").setOffer("UbuntuServer")
.setSku("18.04-LTS").setVersion("latest");

String poolVmSize = "STANDARD_D1_V2";
VirtualMachineConfiguration configuration = new VirtualMachineConfiguration(imgRef, "batch.node.ubuntu 18.04");

BatchPoolCreateParameters poolCreateParameters = new BatchPoolCreateParameters(poolId, poolVmSize);
poolCreateParameters.setTargetDedicatedNodes(1)
.setVirtualMachineConfiguration(configuration)
.setUserAccounts(userList)
.setNetworkConfiguration(networkConfiguration);

batchClientBuilder.buildPoolClient().create(poolCreateParameters);

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

### Create a Job

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

```java
PoolInformation poolInfo = new PoolInformation();
poolInfo.setPoolId(poolId);
BatchJobCreateParameters jobCreateParameters = new BatchJobCreateParameters(jobId, poolInfo);
batchClientBuilder.buildJobClient().create(jobCreateParameters);
```

## Sample Code

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

## Examples

Create a pool with 3 Small VMs

```java
String poolId = "ExamplePoolId";

String poolVmSize = "STANDARD_D1_V2";
int poolVmCount = 2;
int poolLowPriVmCount = 2;

// 10 minutes
long poolSteadyTimeoutInMilliseconds = 10 * 60 * 1000;

// Create pool if it doesn't exist
if (!batchClient.poolExists(poolId)) {
ImageReference imgRef = new ImageReference().setPublisher("Canonical").setOffer("UbuntuServer")
.setSku("18.04-LTS").setVersion("latest");

VirtualMachineConfiguration configuration = new VirtualMachineConfiguration(imgRef, "batch.node.ubuntu 18.04");

NetworkConfiguration netConfig = createNetworkConfiguration();
List<InboundNATPool> inbounds = new ArrayList<>();
inbounds.add(new InboundNATPool("testinbound", InboundEndpointProtocol.TCP, 5000, 60000, 60040));

BatchPoolEndpointConfiguration endpointConfig = new BatchPoolEndpointConfiguration(inbounds);
netConfig.setEndpointConfiguration(endpointConfig);

BatchPoolCreateContent poolToCreate = new BatchPoolCreateContent(poolId, poolVmSize);
poolToCreate.setTargetDedicatedNodes(poolVmCount)
.setTargetLowPriorityNodes(poolLowPriVmCount)
.setVirtualMachineConfiguration(configuration).setNetworkConfiguration(netConfig)
.setTargetNodeCommunicationMode(BatchNodeCommunicationMode.DEFAULT);

batchClient.createPool(poolToCreate);
}
```

Create a job

```java
String jobId = "ExampleJobId";

BatchPoolInfo poolInfo = new BatchPoolInfo();
poolInfo.setPoolId(poolId);
BatchJobCreateContent jobToCreate = new BatchJobCreateContent(jobId, poolInfo);

batchClient.createJob(jobToCreate);
```

Create a task

```java
String taskId = "ExampleTaskId";
BatchTaskCreateContent taskToCreate = new BatchTaskCreateContent(taskId, "echo hello world");
batchClient.createTask(jobId, taskToCreate);
```

## Help

If you encounter any bugs with these libraries, please file issues via [Issues](https://github.com/Azure/azure-sdk-for-java) or check out [StackOverflow for Azure Java SDK](https://stackoverflow.com/questions/tagged/azure-java-sdk).

## Troubleshooting

Consult the Full Documentation: The full documentation is available at <https://learn.microsoft.com/azure/batch/>.

Check the Error Code and Consult Documentation: The Batch service utilizes specific error codes that may be returned in the error response when a request fails due to various reasons. For a comprehensive list of error codes, their meanings, and detailed troubleshooting steps, refer to the Azure Batch service error codes documentation: <https://learn.microsoft.com/rest/api/batchservice/batch-status-and-error-codes>

Review Your Request Parameters: Errors such as InvalidPropertyValue and MissingRequiredProperty indicate that there might be a mistake in the request payload. Review your parameters to ensure they meet the API specifications.

Manage Resources: For errors related to limits and quotas (like AccountCoreQuotaReached), consider scaling down your usage or requesting an increase in your quota.

Check Azure Service Health: Sometimes, the issue may be with Azure services rather than your application. Check the Azure Status Dashboard for any ongoing issues that might be affecting Batch services.

Handle Transient Errors: Implement retry logic in your application to handle transient failures in Batch.

## Next steps

## Contributing

For details on contributing to this repository, see the [contributing guide](https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md).

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 project subdirectory (sdk/batch/azure-compute-batch/), and run

```java
mvn install -f pom.xml
```

For more information about building the client library including installing the associated build tools, please see the [Azure Java SDK Building wiki][java_building_wiki]

## Test Code

All tests are run from the `sdk/batch/azure-compute-batch` directory. They can be run either on the command line or from a Java IDE, such as IntelliJ as Junit (Note that if you wish to run the tests within IntelliJ, you will need to temporarily delete the module-info.java file).
If you are working on either the src or test code within an IDE, be sure you are also building the client library with Maven commands in the CLI as the build system is configured to target both JDK 8 and 11. Please see the [Build Code section](#build-code).

Tests are run in two phases: Record and Playback. During the first Record phase, integration tests create real Batch resources on Azure using the Batch API, and JSON files are created locally to capture the response from Azure. In the second Playback phase, the integrations tests only exercise assertions against the JSON files themselves. To record sessions locally, several resources need to already exist in Azure:

- A valid Azure subscription that can create resources
- A service principal with contributor access to the subscription. If not already available, create an app registration in "Azure Active Directory". Generate a client secret for this principal
- A clean Batch account
- A storage account
- A virtual network

## Step 1: Run tests in Record mode

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

- AZURE_CLIENT_SECRET
- AZURE_TENANT_ID
- AZURE_BATCH_ACCESS_KEY
- AZURE_BATCH_ACCOUNT
- AZURE_BATCH_ENDPOINT
- AZURE_BATCH_REGION
- AZURE_VNET
- AZURE_VNET_ADDRESS_SPACE
- AZURE_VNET_RESOURCE_GROUP
- AZURE_VNET_SUBNET
- AZURE_VNET_SUBNET_ADDRESS_SPACE
- AZURE_CLIENT_ID
- STORAGE_ACCOUNT_KEY
- STORAGE_ACCOUNT_NAME
- AZURE_SUBSCRIPTION_ID

2. If running as Junit in an IDE, Set the `AZURE_TEST_MODE` environment variable to `Record`, then run the tests in `src/test/java`
3. If running 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/modified in `azure-compute-batch/src/test/resources/session-records`

Note: Whether you are running in record or playback mode through mvn, you can also run a specific test file i.e. PoolsTests, JobScheduleTests, etc. by passing the -Dtest parameter such as:

```java
mvn test -DAZURE_TEST_MODE=Playback -Dtest=JobScheduleTests
```

## Step 2: Run tests in Playback mode

1. If running as Junit in an IDE, Set the `AZURE_TEST_MODE` environment variable to `Playback`, then run the tests in `src/test/java`
2. If running from the command-line, run `mvn test -DAZURE_TEST_MODE=Playback`

<!-- LINKS -->
[product_documentation]: https://azure.microsoft.com/services/
[docs]: https://azure.github.io/azure-sdk-for-java/
[jdk]: https://docs.microsoft.com/java/azure/jdk/
[azure_subscription]: https://azure.microsoft.com/free/
[java_building_wiki]: https://github.com/Azure/azure-sdk-for-java/wiki/Building
6 changes: 6 additions & 0 deletions sdk/batch/azure-compute-batch/assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/batch/azure-compute-batch",
"Tag": "java/batch/azure-compute-batch_aff1c3044f"
}
Loading