Run Java application in Azure Batch

Introduction

** 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

Batch related resource creation

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.

Create Batch account

Type [Batch] in the search box of the Azure portal, and [Batch account] will be displayed as a candidate. Click it. image.png

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. image.png

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). image.png

The latter settings are optional. If there is no problem, create it. image.png

Add pool

Click Add on the left menu of your Batch account, Pool. image.png

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

image.png

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. image.png

(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. image.png

You can set various other settings such as virtual network by adding a pool, but here, minimize it and click [OK]. image.png

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. image.png

Add job

Click [Add] on the left menu [Job] of the Batch account. image.png

Select any job ID and pool to associate with and click OK. image.png

Mode & advanced settings

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. image.png image.png

Add task (Java operation check)

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. image.png

Click Add Task. image.png

Arbitrary & Enter a unique task ID in the job, enter java --version on the command line, and click Submit. image.png

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. image.png

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. image.png

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. image.png

Running 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.

Preparing the executable JAR file

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/

Upload the JAR file to your storage account

Create a suitable blob container in the storage account associated with the Batch account and upload the JAR file. image.png

Add task (Run Java application)

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

image.png

Click Select Storage Blob on the resource file settings screen. image.png

Check Include SAS, enter any value for Expiration Date (default 7 in this case), and click OK. image.png

Specify the JAR file you uploaded and click Select. image.png

Click Submit. This will download the JAR file to the VM's working directory before executing the command line defined in the task. image.png

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. image.png image.png

That is all for the main story.

APPENDIX --Selectable image types

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.

Image type

Image type-Marketplace

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

Run Java application in Azure Batch
Let's run batch in container using Azure Batch
Azure functions in java
Run batch with docker-compose with Java batch
Create Azure Functions in Java
[For beginners] Run Selenium in Java
Run a batch file from Java
Run an application made with Java8 with Java6
Run an external process in Java
ERRORCODE = -4471 occurs in Java application using Db2.
Role of JSP in Web application [Java]
Java application development environment created in VM environment
Partization in Java
Java 9+ application status
Changes in Java 11
Rock-paper-scissors in Java
Pi in Java
FizzBuzz in Java
CICS-Run Java application-(1) Run a simple sample app
Get along with Java containers in Cloud Run
[java] sort in list
Read JSON in Java
Interpreter implementation in Java
Make Blackjack in Java
Rock-paper-scissors app in Java
Constraint programming in Java
Put java8 in centos7
Combine arrays in Java
"Hello World" in Java
Callable Interface in Java
Delete All from Java SDK in Azure Cosmos DB
Change Java heap size in Tomcat in Azure App Service
Comments in Java source
[Tutorial] Download Eclipse → Run Web application with Java (Pleiades)
Run PostgreSQL on Java
Format XML in Java
Simple htmlspecialchars in Java
Boyer-Moore implementation in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java
Android-Upload image files to Azure Blob Storage in Java
Type determination in Java
I dealt with Azure Functions not working in Java
Ping commands in Java
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
ASCII art in Java
Compare Lists in Java
POST JSON in Java
Express failure in Java
Create JSON in Java
Date manipulation in Java 8
What's new in Java 8
Remote debugging of Java applications in Azure Web Apps
Java11: Run Java code in a single file as is
Use PreparedStatement in Java
What's new in Java 9,10,11
Parallel execution in Java
Initializing HashMap in Java