StackStorm分析(五)Inquiry說明

StackStorm介紹

       StackStorm是一個強大的自動化平臺,結合DevOpsChatOps,提供可擴展、靈活和健壯的工具鏈用於應用、服務和工作流的自動化能力。

 


 

Inquiry

         在自動化任務執行的過程中,往往會需要等待確認的步驟,比如需要人工審覈,需要外部系統的確認。爲此StackStorm提供一種Action的交互機制Inquiry,通過執行core.ask發起Inquiry,進入pending掛起狀態,直到Inquiry收到回覆才繼續執行。

 

下面是一個Mistral Workflow的規格文件examples.mistral-ask-basic.yaml:

version: '2.0'

 

examples.mistral-ask-basic:

    description: A basic Mistral workflow illustrating the use of Inquiries

    type: direct

    output:

        result: <% task(task1).result.response %>

    tasks:

        task1:

            action: core.ask

            input:

              route: developers

              schema:

                type: object

                properties:

                  secondfactor:

                    type: string

                    description: Please enter second factor for authenticating to "foo" service

                    required: True

            on-success:

              - task2

 

        task2:

            action: core.local

            input:

              cmd: echo "We can now authenticate to 'foo' service with <% task(task1).result.response.secondfactor %>"

 

task1的action就是core.ask,core.ask需要提供的入參就是Inquiry的規格:

Parameter

Description

schema

A JSON schema that will be used to validate the response data. A basic schema will be provided by default, or you can provide one here. Only valid responses will cause the action to succeed, and the workflow to continue.

ttl

Time (in minutes) until an unacknowledged Inquiry is garbage-collected. Set to 0 to disable garbage collection for this Inquiry. NOTE - Inquiry garbage collection is not enabled by default, so this field does nothing unless it is turned on.

roles

A list of RBAC roles that are permitted to respond to the action. Defaults to empty list, which permits all roles. This requires enterprise features

users

A list of users that are permitted to respond to the action. Defaults to empty list, which permits all users.

route

An arbitrary string that can be used to filter different Inquiries inside rules. This can be helpful for deciding who to notify of an incoming Inquiry. 

 

執行Workflow,task1就會掛起:

$ st2 run examples.mistral-ask-basic

.

id: 5afbd3802b2556015687ce09

action.ref: examples.mistral-ask-basic

parameters: None

status: paused

start_timestamp: Wed, 16 May 2018 06:45:20 UTC

end_timestamp:

+--------------------------+---------+-------+----------+-------------------------------+

| id                       | status  | task  | action   | start_timestamp               |

+--------------------------+---------+-------+----------+-------------------------------+

| 5afbd3802b2556015687ce0c | pending | task1 | core.ask | Wed, 16 May 2018 06:45:20 UTC |

+--------------------------+---------+-------+----------+-------------------------------+

 

這時候就會產生一個Inquiry:

$ st2 inquiry list

+--------------------------+-------+-------+------------+------+

| id                       | roles | users | route      | ttl  |

+--------------------------+-------+-------+------------+------+

| 5afbd3802b2556015687ce0c |       |       | developers | 1440 |

+--------------------------+-------+-------+------------+------+

 

然後進行回覆:

$ st2 inquiry respond -r '{"secondfactor": "bar"}' 5afbd3802b2556015687ce0c

 

那麼Workflow就會繼續執行:

$ st2 execution get 5afbd3802b2556015687ce09

id: 5afbd3802b2556015687ce09

action.ref: examples.mistral-ask-basic

parameters: None

status: succeeded (450s elapsed)

result_task: task2

result:

  failed: false

  return_code: 0

  stderr: ''

  stdout: We can now authenticate to 'foo' service with bar

  succeeded: true

start_timestamp: Wed, 16 May 2018 06:45:20 UTC

end_timestamp: Wed, 16 May 2018 06:52:50 UTC

+--------------------------+------------------------+-------+------------+-------------------------------+

| id                       | status                 | task  | action     | start_timestamp               |

+--------------------------+------------------------+-------+------------+-------------------------------+

| 5afbd3802b2556015687ce0c | succeeded (1s elapsed) | task1 | core.ask   | Wed, 16 May 2018 06:45:20 UTC |

| 5afbd5402b2556015687ce0e | succeeded (0s elapsed) | task2 | core.local | Wed, 16 May 2018 06:52:48 UTC |

+--------------------------+------------------------+-------+------------+-------------------------------+

 

參考

  • https://github.com/StackStorm/st2docs/blob/master/docs/source/inquiries.rst


作者簡介

吳龍輝,現任網宿科技雲計算架構師,致力於雲計算PaaS的研究和實踐,《Kubernetes實戰》作者,活躍於CloudFoundry,Docker,Kubernetes等開源社區,貢獻代碼和撰寫技術文檔。 
郵箱:[email protected]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章