实现 Mistral 资源¶
https://blueprints.launchpad.net/heat/+spec/mistral-resources-for-heat
添加对 Mistral 资源的支持,这将允许创建和执行工作流。
问题描述¶
目前 Heat 不支持 Mistral 资源。
Mistral 是一种任务管理服务,也称为工作流即服务。添加到 Heat 的资源将增加新的可能性
工作流,包含用于执行的不同任务。
动作,是与任务关联的特定指令,需要在满足任务依赖关系后执行。
CronTriggers,使其能够根据特定规则运行工作流:定期设置 cron 模式或在外部事件(如 Ceilometer 警报)发生时运行。
Executions,允许执行给定的工作流。
提议的变更¶
Mistral 资源未集成,因此它们将被添加到 contrib 目录。将添加 Mistral 客户端插件用于与 Mistral 通信,后者有其自身的要求。将添加以下资源,语法如下
添加 OS::Mistral::Workflow 资源,如下所示
resources:
workflow:
type: OS::Mistral::Workflow
properties:
definition: |
workflow_name:
type: String
description: String
input: [Value, Value, ...]
output: { ... }
on-success: [Value, Value, ...]
on-error: [Value, Value, ...]
on-complete: [Value, Value, ...]
policies: { ... }
tasks: { ... }
input: { ... }
其中定义指定依赖于 Mistral DSL v2。
添加 OS::Mistral::CronTrigger 资源,如下所示
resources:
cronTrigger:
type: OS::Mistral::CronTrigger
properties:
name: my_cron_trigger
pattern: 1 0 * * *
workflow:
name: String
input: { ... }
有一些用例需要描述
要创建和执行工作流,请按照以下步骤操作:首先,我们使用 OS::Mistral::Workflow 创建模板
heat_template_version: 2013-05-23 resources: workflow: type: OS::Mistral::Workflow properties: definition: | test: type: direct tasks: hello: action: std.echo output='Hello' publish: result: $
当堆栈创建完成后,要执行工作流,请运行以下命令
heat resource-signal stack_name workflow_name \ -D 'Json-type execution input'
执行状态将在 ‘executions’ 属性中作为字典提供。
与 Ceilometer 警报的兼容性,例如使用 webhook url 执行工作流
heat_template_version: 2013-05-23 resources: workflow: type: OS::Mistral::Workflow properties: definition: | test: type: direct tasks: alarm_hello: action: std.echo output='Alarm!' publish: result: $ alarm: type: OS::Ceilometer::Alarm properties: alarm: type: OS::Ceilometer::Alarm properties: meter_name: cpu_util statistic: avg period: 60 evaluation_periods: 1 threshold: 0 alarm_actions: - { get_attr: [workflow, alarm_url] } comparison_operator: ge outputs: executions: value: { get_attr: [workflow, executions] } workflows: value: { get_attr: [workflow, available_workflows] }
在上述模板中,当警报状态变为 ‘alarm’ 时,工作流将开始执行。输出 ‘execution’ 包含有关属于该工作流的所有执行的字典。输出 ‘workflows’ 包含属于该工作流的所有工作流名称的字典,例如 {‘test’: ‘stack_name.workflow.test’}。
在模板中使用 cron 触发器。这里有一个名为 ‘wfdef.yaml’ 的定义
version: 2.0 create_vm: type: direct input: - vm_name - image_ref - flavor_ref output: vm_id: $.vm_id tasks: create_server: action: > nova.servers_create name={$.vm_name} image={$.image_ref} flavor={$.flavor_ref} publish: vm_id: $.id on-success: - check_server_exists check_server_exists: action: nova.servers_get server={$.vm_id} publish: server_exists: True on-success: - wait_instance wait_instance: action: nova.servers_find id={$.vm_id} status='ACTIVE' policies: retry: delay: 5 count: 15
此定义将在模板中使用,该模板还具有 cron 触发器资源
heat_template_version: 2013-05-23 resources: workflow: type: OS::Mistral::Workflow properties: definition: { get_file: wfdef.yaml } input: vm_name: test image_ref: some_image_id flavor_ref: some_flavor_id cron_trigger: type: OS::Mistral::CronTrigger properties: name: test_trigger pattern: 1 0 * * * workflow: { get_attr: [workflow, available_workflows, create_vm]}
需要注意的是,name 是可选属性。
备选方案¶
无
实现¶
负责人¶
- 主要负责人
<prazumovsky>
- 协助者
<tlashchova>
里程碑¶
- 完成目标里程碑
Kilo-2
工作项¶
添加 Mistral 客户端插件到 Heat
添加 Mistral 工作流资源
添加 Mistral cron 触发器资源
依赖项¶
无