创建定时器(CreateSchedulerTrigger)

API请求

URLs
POST zstack/v1/scheduler/triggers
Headers
Authorization: OAuth the-session-uuid
Body
{
  "params": {
    "name": "trigger",
    "description": "description",
    "schedulerInterval": 3600.0,
    "repeatCount": 100.0,
    "startTime": 1.510669257141E12,
    "schedulerType": "simple"
  },
  "systemTags": [],
  "userTags": []
}
Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"name":"trigger","description":"description","schedulerInterval":3600.0,"repeatCount":100.0,"startTime":1.510669257141E12,"schedulerType":"simple"}}' \
http://localhost:8080/zstack/v1/scheduler/triggers
参数列表
名字 类型 位置 描述 可选值 起始版本
name String body(包含在params结构中) 资源名称 2.1
description (可选) String body(包含在params结构中) 资源的详细描述 2.1
schedulerInterval (可选) Integer body(包含在params结构中) 间隔时间
  • 当简单定时任务执行超过一次时,必须设置间隔时间;
  • 简单定时任务永远重复时,必须设置间隔时间
2.1
repeatCount (可选) Integer body(包含在params结构中) 2.1
startTime (可选) Long body(包含在params结构中) Unix Time 2.1
schedulerType String body(包含在params结构中)
  • simple
  • cron
2.1
cron (可选) String body(包含在params结构中) 2.1
resourceUuid (可选) String body(包含在params结构中) 2.1
systemTags (可选) List body 2.1
userTags (可选) List body 2.1

API返回

返回示例
{
  "inventory": {
    "uuid": "20c7355021f83597a4cf7854f5788b74",
    "name": "trigger",
    "description": "this is a scheduler trigger",
    "createDate": "Nov 14, 2017 10:20:57 PM",
    "lastOpDate": "Nov 14, 2017 10:20:57 PM"
  }
}
名字 类型 描述 起始版本
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 2.1
inventory SchedulerTriggerInventory 详情参考inventory 2.1
#error
名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 2.1
description String 错误的概要描述 2.1
details String 错误的详细信息 2.1
elaboration String 保留字段,默认为null 2.1
opaque LinkedHashMap 保留字段,默认为null 2.1
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 2.1
#inventory
名字 类型 描述 起始版本
uuid String 资源的UUID,唯一标示该资源 2.1
name String 资源名称 2.1
description String 资源的详细描述 2.1
schedulerType String 2.1
schedulerInterval Integer 2.1
repeatCount Integer 2.1
startTime Timestamp 2.1
stopTime Timestamp 2.1
createDate Timestamp 创建时间 2.1
lastOpDate Timestamp 最后一次修改时间 2.1
jobsUuid List 2.1

SDK示例

Java SDK
CreateSchedulerTriggerAction action = new CreateSchedulerTriggerAction();
action.name = "scheduler trigger";
action.schedulerInterval = 1000.0;
action.repeatCount = 10.0;
action.startTime = 1.500257934165E12;
action.schedulerType = "simple";
action.sessionId = "412d5e5ffaa247c89864f32715c1ae82";
CreateSchedulerTriggerAction.Result res = action.call();
Python SDK
CreateSchedulerTriggerAction action = CreateSchedulerTriggerAction()
action.name = "scheduler trigger"
action.schedulerInterval = 1000.0
action.repeatCount = 10.0
action.startTime = 1.500257934177E12
action.schedulerType = "simple"
action.sessionId = "89bc45d795df44688c7ad4bba232490f"
CreateSchedulerTriggerAction.Result res = action.call()