** Azure Batch ** is a convenient service that allows you to run arbitrary scripts and applications on autoscaleable virtual machines (VMs). Java applications can also be run if the VM has a Java Virtual Machine (JVM) installed.
The official documentation has a quick start on .NET and Python applications, but there is currently no Java documentation, so in this article I'd like to briefly summarize the flow of running a Java application on Azure Batch.
The outline is in line with the following quick start article, so please refer to it as well. Azure Quick Start: Run the first Batch job in the Azure portal-Azure Batch | Microsoft Docs
Now let's create Batch related resources (accounts, pools, jobs, tasks) in order. A rough explanation of each resource is as follows.
--Account: The top-level resource in Azure Batch. --Pool: A collection of VMs that serves as a computational resource. You can create multiple pools in one account. --Job: A set of tasks that are the units of calculation. Jobs can be associated with one or more pools. The subordinate task group uses the pool associated with the job as a computational resource. --Task: A unit of calculation. Defines the execution command of the application.
Type [Batch] in the search box of the Azure portal, and [Batch account] will be displayed as a candidate. Click it.
On the new Batch account screen, enter any resource group name or account name. You can associate a storage account with your Batch account, so click the Select Storage Account link.
You can choose to have an existing storage account or create a new one. Here, create a new storage account. Unless you are particular about it, select the recommended Storage V2 (general purpose v2). Set any level of replication to suit your requirements (here we choose the cheapest local superior storage).
The latter settings are optional. If there is no problem, create it.
Click Add on the left menu of your Batch account, Pool.
Since we are creating a VM (a set of) here, there are quite a lot of setting items. First of all, as an image, you can choose various types. Here, the following contents are selected.
--Publisher: canonical --Offer: ubuntuserver
The selectable images are summarized in tabular form at the end of this article. [APPENDIX --Selectable image types](https://qiita.com/nakazax/items/47daae65708bc3188cbf#appendix ---% E9% 81% B8% E6% 8A% 9E% E5% 8F% AF% E8% 83% BD% E3% 81% AA% E3% 82% A4% E3% 83% A1% E3% 83% BC% E3% 82% B8% E3% 81% AE% E7% A8% AE% E9% A1% 9E)
See the following documents for selectable VM sizes. Choose a pool VM size-Azure Batch | Microsoft Docs
Here, the default VM size is selected as [Standard A1]. You can select fixed number or automatic scaling for scaling, but here it is set to Fixed so that one VM can be started. The start task allows you to define the commands to execute when the VM starts. Select Enabled.
(Start task) Since the JVM is not installed in the Ubuntu 18.04-lts image you selected earlier, define the JVM installation command ʻapt install -y openjdk-11-jdk` in the Start Task Command Line. Also change the User ID to Pool autouser, Administrator. The rest of the settings are optional, and if you are satisfied, click OK.
You can set various other settings such as virtual network by adding a pool, but here, minimize it and click [OK].
This completes the pool creation. The dedicated node is 0-> 1, which means the VM is booting. When this becomes 1, the VM startup is complete. If it does not become 1, the node startup has failed. There is a possibility that the start task is not set correctly, so let's review it for any mistakes.
Click [Add] on the left menu [Job] of the Batch account.
Select any job ID and pool to associate with and click OK.
You can make finer control with the mode and detailed settings, but here I will only show the capture as a reference without setting it in particular.
In order to confirm that Java is installed without any problem, execute the Java version confirmation command as a task.
Click the job you created earlier.
Click Add Task.
Arbitrary & Enter a unique task ID in the job, enter java --version
on the command line, and click Submit.
Then, the task is sent to the job queue and makes a state transition of active → running → completed. The task execution should be completed in a short time because no other task is being executed. Click the task you submitted to see the details.
If the task is completed normally, you should see the output result "stderr.txt" to the standard error and the output result "stdout.txt" to the standard output. Click stdout.txt.
It is OK if the Java version information is output as shown below. The Batch-related resources are now ready to run your Java application.
From here, we will start running the Java application of the main subject. The flow is to upload the executable JAR file to the storage account, download the JAR file in a Batch task, and execute it.
Prepare a suitable executable JAR file. Here, we will use the executable JAR file that can be generated by following the steps for creating a sample application for Spring Boot + Sprint Batch.
https://spring.io/guides/gs/batch-processing/
Create a suitable blob container in the storage account associated with the Batch account and upload the JAR file.
Add tasks from jobs in Batch account. At the command line, enter the following JAR execution command: Click Resource File for the JAR file download settings.
java -jar batch-processing-0.0.1-SNAPSHOT.jar
Click Select Storage Blob on the resource file settings screen.
Check Include SAS, enter any value for Expiration Date (default 7 in this case), and click OK.
Specify the JAR file you uploaded and click Select.
Click Submit. This will download the JAR file to the VM's working directory before executing the command line defined in the task.
After sending and executing the task, if the status is completed as shown below and the standard output result is output to stdout.txt, the process is completed normally.
That is all for the main story.
Image Types as of September 20, 2020-A list of items available from the Marketplace. Please check the Azure portal for the latest information as it is just a snapshot of the temporary point.
Issuer | Offer | SKU |
---|---|---|
canonical | ubuntuserver | 16.04-lts |
canonical | ubuntuserver | 18.04-lts |
credativ | debian | 8 |
credativ | debian | 9 |
debian | debian-10 | 10 |
micrsoft-azure-batch | centos-container | 7-7 |
micrsoft-azure-batch | centos-container-rdma | 7-4 |
micrsoft-azure-batch | centos-container-rdma | 7-7 |
micrsoft-azure-batch | ubuntu-server-container | 16-04-lts |
micrsoft-azure-batch | ubuntu-server-container-rdma | 16-04-lts |
micrsoftwindowsserver | windowsserver | 2008-r2-sp1 |
micrsoftwindowsserver | windowsserver | 2008-r2-sp1-smalldisk |
micrsoftwindowsserver | windowsserver | 2012-datacenter |
micrsoftwindowsserver | windowsserver | 2012-datacenter-smalldisk |
micrsoftwindowsserver | windowsserver | 2012-r2-datacenter |
micrsoftwindowsserver | windowsserver | 2012-r2-datacenter-smalldisk |
micrsoftwindowsserver | windowsserver | 2016-datacenter |
micrsoftwindowsserver | windowsserver | 2016-datacenter-smalldisk |
micrsoftwindowsserver | windowsserver | 2016-datacenter-with-containers |
micrsoftwindowsserver | windowsserver | 2019-datacenter |
micrsoftwindowsserver | windowsserver | 2019-datacenter-core |
micrsoftwindowsserver | windowsserver | 2019-datacenter-core-smalldisk |
micrsoftwindowsserver | windowsserver | 2019-datacenter-core-with-containers |
micrsoftwindowsserver | windowsserver | 2019-datacenter-core-with-containers-smalldisk |
micrsoftwindowsserver | windowsserver | 2019-datacenter-smalldisk |
micrsoftwindowsserver | windowsserver | 2019-datacenter-with-containers |
micrsoftwindowsserver | windowsserver | 2019-datacenter-with-containers-smalldisk |
that's all.
Recommended Posts