全部产品
云市场

ACS::WaitFor

更新时间:2019-09-05 10:27:27

用途

使用该动作可以等待资源进入预期的状态。通过调用云产品的OpenAPI去查询指定资源的状态,直到资源的状态和预期的一致。如通过调用ECS的OpenAPIRunInstances创建资源后,可以通过调用ACS::WaitFor等待实例被创建完成,即其状态为运行中(Running)。

语法

  1. Tasks:
  2. - Name: waitForTaskExample
  3. Action: ACS::WaitFor
  4. Properties:
  5. # 以下属性和ACS::ExecuteAPI一致,请参考ACS::ExecuteAPI语法说明。
  6. Service: ECS
  7. API: DescribeInstances
  8. Parameters:
  9. InstanceId: i-12345678abcedfg
  10. # 以下属性为ACS::WaitFor的特殊属性
  11. PropertySelector: "jq selector" # 必填,需要等待的具体的API返回值,参考ACS::ExecuteAPI中的ValueSelector说明
  12. DesiredValues: # DesiredValue,NotDesiredValues 必填其一,指上面截取的值要匹配到以下值之一,匹配则表示成功,否则会超时然后失败。
  13. - value1
  14. - value2
  15. NotDesiredValues: # DesiredValue,NotDesiredValues 必填其一,指上面截取的值要不匹配到以下的所有值,全都不匹配则表示成功,否则会超时然后失败。
  16. - value3
  17. - value4
  18. Outputs: # WaitFor动作所在的任务支持输出,当任务满足NotDesiredValues/DesiredValues的条件时,任务执行成功后会返回输出参数的值。
  19. OutputParameter1:
  20. ValueSelector: 'jq selector' # jq的选择器语法,以OpenAPI的返回作为JSON输入,jq的语法请参考 https://stedolan.github.io/jq/
  21. Type: String/Boolean/List(Array)/Number/Object
  22. # WaitFor高级控制
  23. StopRetryValues: # 可选,一旦任务PropertySelector结果为status1状态时终止任务等待及API重试。比如status1为'Stopped'时,一旦API返回结果筛选后为Stopped,则该任务执行停止。
  24. - status1
  • JSON格式(请参考YAML注释说明)
  1. {
  2. "Tasks": [
  3. {
  4. "Name": "waitForTaskExample",
  5. "Action": "ACS::WaitFor",
  6. "Properties": {
  7. "Service": "ECS",
  8. "API": "DescribeInstances",
  9. "Parameters": {
  10. "InstanceId": "i-12345678abcedfg"
  11. },
  12. "PropertySelector": "jq selector",
  13. "DesiredValues": [
  14. "value1",
  15. "value2"
  16. ],
  17. "NotDesiredValues": [
  18. "value3",
  19. "value4"
  20. ]
  21. },
  22. "StopRetryValues":["status1"],
  23. "Outputs": {
  24. "OutputParameter1": {
  25. "ValueSelector": "jq selector",
  26. "Type": "String/Boolean/List(Array)/Number/Object"
  27. }
  28. }
  29. }
  30. ]
  31. }

示例

如下模板:启动一台指定实例,通过调用WaitFor等待实例的状态变为Running。

  • YAML格式:
  1. ---
  2. FormatVersion: OOS-2019-06-01
  3. Parameters:
  4. InstanceId:
  5. Description: the instance id that you will start.
  6. Type: String
  7. Tasks:
  8. - Name: startInstance
  9. Action: ACS::ExecuteAPI
  10. Description: start instance with specified parameters
  11. Properties:
  12. Service: ECS
  13. API: StartInstance
  14. Parameters:
  15. InstanceId: '{{ InstanceId }}'
  16. - Name: untilInstanceReady
  17. Action: ACS::WaitFor
  18. Description: describe instances with specified parameters
  19. Properties:
  20. Service: ECS
  21. API: DescribeInstances
  22. Parameters:
  23. InstanceIds:
  24. - '{{ InstanceId }}'
  25. PropertySelector: Instances.Instance[].Status
  26. DesiredValues:
  27. - Running
  • JSON格式:
  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Parameters": {
  4. "InstanceId": {
  5. "Description": "the instance id that you will start.",
  6. "Type": "String"
  7. }
  8. },
  9. "Tasks": [
  10. {
  11. "Name": "startInstance",
  12. "Action": "ACS::ExecuteAPI",
  13. "Description": "start instance with specified parameters",
  14. "Properties": {
  15. "Service": "ECS",
  16. "API": "StartInstance",
  17. "Parameters": {
  18. "InstanceId": "{{ InstanceId }}"
  19. }
  20. }
  21. },
  22. {
  23. "Name": "untilInstanceReady",
  24. "Action": "ACS::WaitFor",
  25. "Description": "describe instances with specified parameters",
  26. "Properties": {
  27. "Service": "ECS",
  28. "API": "DescribeInstances",
  29. "Parameters": {
  30. "InstanceIds": [ "{{ InstanceId }}"]
  31. },
  32. "PropertySelector": "Instances.Instance[].Status",
  33. "DesiredValues": [ "Running" ],
  34. }
  35. }
  36. ]
  37. }