Creates a job and obtains the job ID.
Debugging
Authorization information
The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action
policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:
- Operation: the value that you can use in the Action element to specify the operation on a resource.
- Access level: the access level of each operation. The levels are read, write, and list.
- Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
- The required resource types are displayed in bold characters.
- If the permissions cannot be granted at the resource level,
All Resources
is used in the Resource type column of the operation.
- Condition Key: the condition key that is defined by the cloud service.
- Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
Operation | Access level | Resource type | Condition key | Associated operation |
---|---|---|---|---|
edas:CreateSchedulerxJobCreate | create | *All Resources * |
| none |
Request parameters
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
RegionId | string | Yes | The region ID. | cn-hangzhou |
Namespace | string | Yes | The namespace ID. You can obtain the namespace ID on the Namespace page in the SchedulerX console. | adcfc35d-e2fe-4fe9-bbaa-20e90ffc**** |
NamespaceSource | string | No | The source of the namespace. You must specify this parameter only if the namespace is provided by a third party. | schedulerx |
GroupId | string | Yes | The application ID. You can obtain the application ID on the Application Management page in the SchedulerX console. | testSchedulerx.defaultGroup |
JobType | string | Yes | The job type. Valid values:
| java |
Name | string | Yes | The job name. | helloworld |
Description | string | No | The job description. | Test |
ExecuteMode | string | Yes | The execution mode of the job. Valid values:
| standalone |
ClassName | string | No | The full path of the job interface class. This parameter is available only when you set JobType to java. You must enter a full path. | com.alibaba.schedulerx.test.helloworld |
Content | string | No | The script content. This parameter is required when you set JobType to python, shell, go, or k8s. | echo 'hello' |
Parameters | string | No | The user-defined parameters that you can obtain when the job is running. | test |
MaxConcurrency | integer | No | The maximum number of concurrent instances. By default, only one instance can run at a time. When an instance is running, the next instance is not triggered even if the scheduled start time arrives. | 1 |
MaxAttempt | integer | No | The maximum number of retry attempts in case of a job failure. Specify this parameter based on your business requirements. Default value: 0. | 0 |
AttemptInterval | integer | No | The time interval between retry attempts in case of a job failure. Unit: seconds. Default value: 30. | 30 |
PageSize | integer | No | The number of entries per page. You can specify this parameter for MapReduce jobs. Default value: 100. | 100 |
ConsumerSize | integer | No | The number of threads that a single worker triggers simultaneously. You can specify this parameter for MapReduce jobs. Default value: 5. | 5 |
QueueSize | integer | No | The maximum capacity of the task queue. You can specify this parameter for MapReduce jobs. Default value: 10000. | 10000 |
DispatcherSize | integer | No | The number of task distribution threads. This parameter is an advanced configuration item of the MapReduce job. Default value: 5. | 5 |
TimeType | integer | Yes | The time type. Valid values:
| 1 |
TimeExpression | string | No | The time expression. Specify the time expression based on the value of TimeType:
| 0 0/10 * * * ? |
Calendar | string | No | If you set TimeType to 1 (cron), you can specify calendar days. | This parameter is not supported. You do not need to specify this parameter. |
DataOffset | integer | No | If you set TimeType to 1 (cron), you can specify a time offset. Unit: seconds. | 2400 |
Timezone | string | No | Time zone. | GMT+8 |
TimeoutEnable | boolean | No | Specifies whether to enable the timeout alert feature. If the feature is enabled, an alert will be triggered upon a timeout. Valid values:
| false |
Timeout | long | No | The timeout threshold. Unit: seconds. Default value: 7200. | 7200 |
TimeoutKillEnable | boolean | No | Specifies whether to enable the timeout termination feature. If the feature is enabled, a job will automatically be terminated if it times out. Valid values:
| false |
FailEnable | boolean | No | Specifies whether to trigger an alert when a job fails. Valid values:
| false |
FailTimes | integer | No | The maximum number of consecutive failures before an alert is triggered. An alert will be triggered if the number of consecutive failures reaches the value of this parameter. | 2 |
MissWorkerEnable | boolean | No | Specifies whether to generate an alert if no machines are available to run the job. Valid values:
| false |
SuccessNoticeEnable | boolean | No | Specifies whether to send notifications for successfully running the job. | false |
SendChannel | string | No | The method that is used to send alerts. Set the value to sms. Default value: sms. | sms |
TaskMaxAttempt | integer | No | The maximum number of retry attempts in case of a job failure. This parameter is an advanced configuration item of the MapReduce job. Default value: 0. | 0 |
TaskAttemptInterval | integer | No | The time interval between retry attempts in case of a job failure. This parameter is an advanced configuration item of the MapReduce job. Default value: 0. | 0 |
ContactInfo | array<object> | No | The information about the alert contact. | |
object | No | The information about the array object. | ||
UserPhone | string | No | The mobile number of the alert contact. | 1381111**** |
UserName | string | No | The name of the alert contact. | Tom |
UserMail | string | No | The email address of the alert contact. | test***@***.com |
Ding | string | No | https://oapi.dingtalk.com/robot/send?access_token=********** | |
Status | integer | No | Specifies whether to enable the job. If this parameter is set to 0, the job is disabled. If this parameter is set to 1, the job is enabled. Default value: 1. | 1 |
XAttrs | string | No | The extended attributes. If you set JobType to k8s, this parameter is required. For a job whose resource type is Job-YAML, set this parameter to {"resource":"job"}. For a job whose resource type is Shell-Script, set this parameter to {"image":"busybox","resource":"shell"}. | {"resource":"job"} |
Response parameters
Examples
Sample success responses
JSON
format
{
"Code": 200,
"Message": "message",
"RequestId": "39090022-1F3B-4797-8518-6B61095F1AF0",
"Success": true,
"Data": {
"JobId": 92583
}
}
Error codes
For a list of error codes, visit the Service error codes.
Change history
Change time | Summary of changes | Operation |
---|---|---|
2024-10-21 | The response structure of the API has changed | View Change Details |
2023-03-30 | The internal configuration of the API is changed, but the call is not affected | View Change Details |
2022-12-26 | The internal configuration of the API is changed, but the call is not affected | View Change Details |
2022-09-29 | The internal configuration of the API is changed, but the call is not affected | View Change Details |
2022-09-27 | The request parameters of the API has changed | View Change Details |
2022-06-13 | The request parameters of the API has changed | View Change Details |
Create a Java job
package com.alibaba.schedulerx.pop;
import java.util.ArrayList;
import java.util.List;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobRequest;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobRequest.ContactInfo;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobResponse;
public class CreateJavaJob {
public static void main(String[] args) throws Exception {
// The region ID. Enter a value by referring to the Endpoints topic or based on the region in which you purchased the service.
String regionId = "cn-shanghai";
// The AccessKey ID used for authentication. You can obtain the AccessKey ID in the Resource Access Management (RAM) console.
String accessKeyId = "<yourAccessKeyId>";
// The AccessKey secret used for authentication. You can obtain the AccessKey secret in the RAM console.
String accessKeySecret = "<yourAccessKeySecret>";
// The service name.
String productName ="schedulerx2";
// Refer to the Endpoints topic and enter a domain.
String domain ="schedulerx.cn-shanghai.aliyuncs.com";
// Build an API client.
DefaultProfile.addEndpoint(regionId, productName, domain);
DefaultProfile defaultProfile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(defaultProfile);
CreateJobRequest request = new CreateJobRequest();
request.setJobType("java");
request.setExecuteMode("standalone");
request.setDescription("test");
request.setName("helloworld");
request.setClassName("com.alibaba.schedulerx.test.helloworld");
request.setTimeType(1);
request.setTimeExpression("0 0/10 * * * ?");
request.setNamespace("xxxxx");
request.setGroupId("xxxxxxx");
// monitor
request.setTimeoutEnable(true);
request.setTimeoutKillEnable(true);
request.setFailEnable(true);
request.setTimeout(12300L);
List<ContactInfo> contactInfosList = new ArrayList<>();
ContactInfo contactInfo1 = new ContactInfo();
contactInfo1.setUserName("userA");
contactInfo1.setUserPhone("1381111****");
ContactInfo contactInfo2 = new ContactInfo();
contactInfo2.setUserName("userB");
contactInfo2.setUserPhone("1382222****");
contactInfosList.add(contactInfo1);
contactInfosList.add(contactInfo2);
request.setContactInfos(contactInfosList);
// attrs
//request.setQueueSize(123);
request.setTaskMaxAttempt(1);
request.setTaskAttemptInterval(100);
CreateJobResponse response = client.getAcsResponse(request);
if (response.getSuccess()) {
System.out.println("jobId=" + response.getData().getJobId());
} else {
System.out.println(response.getMessage());
}
}
}
Create an HTTP job
package com.alibaba.schedulerx.pop;
import com.alibaba.schedulerx.common.domain.HttpAttribute;
import com.alibaba.schedulerx.common.util.JsonUtil;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobRequest;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobResponse;
public class CreateHttpJob {
public static void main(String[] args) throws Exception {
// The region ID. Enter a value by referring to the Endpoints topic or based on the region in which you purchased the service.
String regionId = "cn-shanghai";
// The AccessKey ID used for authentication. You can obtain the AccessKey ID in the RAM console.
String accessKeyId = "<yourAccessKeyId>";
// The AccessKey secret used for authentication. You can obtain the AccessKey secret in the RAM console.
String accessKeySecret = "<yourAccessKeySecret>";
// The service name.
String productName ="schedulerx2";
// Refer to the Endpoints topic and enter a domain.
String domain ="schedulerx.cn-shanghai.aliyuncs.com";
// Build an API client.
DefaultProfile.addEndpoint(regionId, productName, domain);
DefaultProfile defaultProfile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(defaultProfile);
CreateJobRequest request = new CreateJobRequest();
request.setNamespace("xxxxxxxx");
request.setGroupId("xxxxxx");
request.setJobType("http");
request.setName("testHttpJob");
request.setDescription("testHttpJob");
request.setTimeType(1);
request.setTimeExpression("20 0/5 * * * ?");
request.setExecuteMode("standalone");
HttpAttribute httpAttribute = new HttpAttribute();
httpAttribute.setUrl("http://192.168.0.0:8080/test");
httpAttribute.setMethod("GET");
httpAttribute.setTimeout(10); // Unit: seconds.
httpAttribute.setRespKey("code");
httpAttribute.setRespValue("200");
request.setContent(JsonUtil.toJson(httpAttribute));
// The POST parameter, in the format of key1=value1&key2=value2.
request.setParameters("key1=value1&key2=value2");
// Send a request.
CreateJobResponse response = client.getAcsResponse(request);
if (!response.getSuccess()) {
System.out.println(response.getMessage());
System.out.println("createApp: "+response.getRequestId());
} else {
System.out.println(JsonUtil.toJson(response));
}
}
}
Create a one-time job
package com.alibaba.schedulerx.pop;
import java.util.ArrayList;
import java.util.List;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobRequest;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobRequest.ContactInfo;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobResponse;
public class CreateJavaJob {
public static void main(String[] args) throws Exception {
// The region ID. Enter a value by referring to the Endpoints topic or based on the region in which you purchased the service.
String regionId = "cn-shanghai";
// The AccessKey ID used for authentication. You can obtain the AccessKey ID in the RAM console.
String accessKeyId = "xxxxxx";
// The AccessKey secret used for authentication. You can obtain the AccessKey secret in the RAM console.
String accessKeySecret = "xxxxxxxx";
// The service name.
String productName ="schedulerx2";
// Refer to the Endpoints topic and enter a domain.
String domain ="schedulerx.cn-shanghai.aliyuncs.com";
// Build an API client.
DefaultProfile.addEndpoint(regionId, productName, domain);
DefaultProfile defaultProfile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(defaultProfile);
CreateJobRequest request = new CreateJobRequest();
request.setJobType("java");
request.setExecuteMode("standalone");
request.setDescription("test");
request.setName("helloworld");
request.setClassName("com.alibaba.schedulerx.test.helloworld");
request.setTimeType(5);
request.setTimeExpression("2021-12-30 12:12:12");
request.setNamespace("xxxxxx");
request.setGroupId("xxxxxxx");
// The alert and monitoring feature.
request.setTimeoutEnable(true);
request.setTimeoutKillEnable(true);
request.setFailEnable(true);
request.setTimeout(12300L);
// Advanced settings.
request.setMaxAttempt(3);
request.setAttemptInterval(30);
CreateJobResponse response = client.getAcsResponse(request);
if (response.getSuccess()) {
System.out.println("jobId=" + response.getData().getJobId());
} else {
System.out.println(response.getMessage());
}
}
}