You can upload an application image to the Container Service for Kubernetes (ACK) console and connect the application to XXL-JOB. This allows you to schedule jobs and perform job sharding in an efficient manner.
Prerequisites
The RAM user is granted the required permissions on XXL-JOB. For more information, see XXL-JOB authorization.
An XXL-JOB instance is created. For more information, see Create an instance.
Overview
This solution provides an example on how to deploy an image to a container by using ACK Serverless or Serverless App Engine (SAE) to develop and deploy an application, connect the application to XXL-JOB, and then test the connected application by using standalone and sharding broadcast jobs. In this example, the demo application image provided by XXL-JOB is used. This helps you understand the use and configuration of XXL-JOB. To implement this solution, perform the following steps:
Create an application: You can create an application in XXL-JOB to manage jobs in a centralized manner. This allows you to view, configure, and schedule jobs with ease and improves job management efficiency.
Deploy a demo project to a container: You can quickly deploy and scale the demo image by using ACK Serverless or SAE.
Perform testing and verification: You can verify that jobs on the connected application can be automatically scheduled and managed in XXL-JOB, and the jobs can be executed at the specified point in time.
Step 1: Create an application
Log on to the MSE console, and select a region in the top navigation bar.
On the page that appears, click the ID of your instance to go to the instance details page. On the instance details page, click in the left-side navigation pane. On the page that appears, click CreateApplication. In the CreateApplication panel, configure the AppName and Name parameters, click Automatic Generation for AccessToken to obtain an access token, and then click OK.
Step 2: Deploy a demo project to a container
XXL-JOB provides the following public demo application image: registry.cn-hangzhou.aliyuncs.com/schedulerx/xxljob-demo:2.4.1. You can use one of the following methods to deploy the demo application and connect it to XXL-JOB.
Make sure that the cluster in which the application is deployed resides in the same virtual private cloud (VPC) as the XXL-JOB instance, and that the inbound rules of the security group to which the application node belongs allow access from the CIDR blocks of the VPC.
ACK Serverless
Log on to the ACK console. On the Clusters page, click Create Kubernetes Cluster. On the ACK Serverless tab of the buy page, select Configure SNAT for VPC to facilitate image pulling. Skip this operation if SNAT is already configured for the VPC.
On the page that appears, click in the left-side navigation pane. Then, find the desired application and click Access Configuration in the Operation column.
On the Clusters page of the ACK console, click the name of the created cluster. In the left-side navigation pane, choose . On the Deployments page, click Create from YAML. In this example, Access Method 2 is used and the application is restarted by using the -D parameter. Copy the code provided by the access method and replace the value of the JAVA_OPTS environment variable with the copied code.

apiVersion: apps/v1 kind: Deployment metadata: name: xxljob-demo labels: app: xxljob-demo spec: replicas: 2 selector: matchLabels: app: xxljob-demo template: metadata: labels: app: xxljob-demo spec: containers: - name: xxljob-executor image: registry.cn-hangzhou.aliyuncs.com/schedulerx/xxljob-demo:2.4.1 ports: - containerPort: 9999 env: - name: JAVA_OPTS value: >- -Dxxl.job.admin.addresses=http://xxljob-xxxxx.schedulerx.mse.aliyuncs.com -Dxxl.job.executor.appname=xxxxx -Dxxl.job.accessToken=xxxxxxx
SAE
Log on to the SAE console and choose in the left-side navigation pane. On the Applications page, click Create Application to create an application.
Configure the basic information about the application. Select an existing namespace, and select a vSwitch and a security group in the VPC associated with the namespace. Click Specify Image in the Application Deployment Method section. In the Specify Image panel, enter the following URL of the demo image on the Custom Image tab:
registry.cn-hangzhou.aliyuncs.com/schedulerx/xxljob-demo:2.4.1. Then, click OK.ImportantThe namespace that you select must be associated with the VPC in which the XXL-JOB instance resides.
3. In the Advanced Settings step, configure the JAVA_OPTS environment variable.
You can obtain the value of the environment variable by performing the following operations:
Log on to the MSE console, and select a region in the top navigation bar. On the XXL-JOBVersion page, find the instance to which you want to connect the application and click the instance ID. The instance details page appears. In the left-side navigation pane, click Application Management. On the page that appears, find the created application and click Access Configuration in the Operation column. In this example, Access Method 2 is used. Copy the code provided by the access method and use the copied code as the value of the JAVA_OPTS environment variable.

4. Click Create Application with One Click. The application is created in the SAE console.
Step 3: Perform testing and verification
1. Check executors
On the instance details page of the MSE console, click Application Management in the left-side navigation pane. On the Application Management page, find the deployed application and click the value in the Number of actuators column to view the IP address and online status of each executor.

2. Test jobs
The demo image contains the code for testing jobs, including the JobHandler of different types of jobs:
JobHandler of standalone jobs: helloworld
JobHandler of sharding broadcast jobs: shardingJobHandler
Standalone job
A standalone job is executed in an idempotent manner in an executor selected based on the routing policy.
On the instance details page, click Task Management in the left-side navigation pane. On the page that appears, click Create Task. In the Basic configuration step of the Create Task panel, configure the Task Name and jobhandler Name parameters, select the deployed application from the Associated Applications drop-down list, set the Routing Policy parameter to Polling, and then click Next step.

In the Timing Configuration step, set the Time Type parameter to cron and click Using the Build Tool to generate a cron expression. In this example, the job is executed once every day at 12:00. Then, click Next step.

In the Notification Configuration step, you can configure alerts for execution timeout, execution success, and execution failure, and specify notification methods and alert contacts. In this example, the default configurations in the console are used.

After the job is created, find the job on the Task Management page and click Run once in the Operation column. In the Perform tasks manually dialog box, select a machine on which you want to execute the job, enter instance parameters, and then click OK.

Find the job on the Task Management page and choose in the Operation column to view the execution records of the job.
On the instance details page, click Execution List in the left-side navigation pane. On the page that appears, find the execution record that you want to view and click Log in the Operation column to view the logs of the job execution.

Sharding broadcast job
A sharding broadcast job is executed in all executors of the application, and each executor is assigned a unique shard number. This type of job is applicable to distributed batch processing. Unlike open source XXL-JOB that does not support the aggregation feature, XXL-JOB aggregates and displays the execution of a sharding broadcast job on each shard.
On the instance details page, click Task Management in the left-side navigation pane. On the page that appears, click Create Task. In the Basic configuration step of the Create Task panel, configure the Task Name and jobhandler Name parameters, select the deployed application from the Associated Applications drop-down list, set the Routing Policy parameter to Multipart Broadcast, and then click Next step.

In the Timing Configuration step, set the Time Type parameter to cron and click Using the Build Tool to generate a cron expression. In this example, the job is executed at the 10th minute of every hour. Then, click Next step.

In the Notification Configuration step, you can configure alerts for execution timeout, execution success, and execution failure, and specify notification methods and alert contacts. In this example, the default configurations in the console are used.

After the job is created, find the job on the Task Management page and click Run once in the Operation column. In the Perform tasks manually dialog box, select one or more machines on which you want to execute the job, enter instance parameters, and then click OK.

Find the job on the Task Management page and choose in the Operation column to view the execution records of the job.
On the instance details page, click Execution List in the left-side navigation pane. On the page that appears, find the execution record that you want to view and click Details in the Operation column. In the Scheduling Details panel, view the execution details on each machine on the Slice Details tab.

Find a shard and click Log in the Operation column to view the logs of the job execution of the shard.
