文档

ALIYUN::ROS::WaitConditionHandle

更新时间:

ALIYUN::ROS::WaitConditionHandle用于接收信号,与ALIYUN::ROS::WaitCondition配合使用以控制资源栈的执行流程。创建ECS实例时,在自定义数据执行过程中发送信号。

语法

{
  "Type": "ALIYUN::ROS::WaitConditionHandle",
  "Properties": {
    "Mode": String,
    "Count": Integer
  }
}

属性

属性名称

类型

必须

允许更新

描述

约束

Mode

String

控制旧信号在资源更新前如何删除。

取值:

  • Increment:所有旧信号将在资源更新前被删除。

    说明

    更新过程中ALIYUN::ROS::WaitCondition等待的信号数量 = ALIYUN::ROS::WaitCondition的Count属性的取值。

  • Full(默认值):如果Count属性生效,在资源更新前会对旧信号进行删除,否则不删除。

    说明

    更新过程中ALIYUN::ROS::WaitCondition等待的信号数量 = ALIYUN::ROS::WaitCondition的Count属性取值 - 删除操作后剩余的旧信号的数量。

Count

Integer

Mode取值为Full时,ID为整数且大于Count的旧信号在资源更新前会被删除。

默认值为-1。

当满足以下2个条件时,该属性生效:

  • Mode取值为Full。

  • Count≥0。

如果该属性生效,则ID>Count的旧信号将在更新前删除。如果存在非整数ID的旧信号,则资源更新失败。

说明

在需要通过更新资源栈进行弹性扩容或缩容的场景下,推荐设置该值,并与ALIYUN::ROS::WaitCondition的Count属性取值相同。

返回值

Fn::GetAtt

  • CurlCli:该资源产生的curl命令。通过该命令发送自定义数据执行的结果或者状态到资源编排服务。

  • WindowsCurlCli:为Windows提供curl CLI命令前缀,可用于发送处理完成或失败的信号。由于Windows不支持curl命令,您需要先安装curl.exe并将其添加到PATH中。您可以通过添加-d "{\"status\": \" SUCCESS \"}表示成功、添加-d "{\"status\": \" FAILURE \"}表示失败。

  • PowerShellCurlCli:为PowerShell提供curl CLI命令前缀,可用于发送处理完成或失败的信号。由于此cmdlet是在PowerShell 3.0中引入的,所以要确保PowerShell的版本满足此约束,PowerShell的版本可以通过$PSVersionTable.PSVersion显示。您可以通过添加-Body '{"status": " SUCCESS "}表示成功、添加-Body '{"status": " FAILURE "}表示失败。

  • Headers:HTTP POST请求头,可用于在程序中发送处理完成或失败的信号。

  • URL:HTTP POST请求地址,可用于在程序中发送处理完成或失败的信号。

说明
  • CurlCli、WindowsCurlCli、PowerShellCurlCli的请求体中均可通过设置ID字段(字符串)明确指定信号ID。

    例如:-d "{\"status\": \" SUCCESS \", \"id\": \"test\"}

    相同ID的信号会被当作同一信号,后面收到的信号会覆盖前面收到的。

    如果没有指定ID,ROS会使用整数作为信号ID,这个整数=已有信号的数量+1。

  • CurlCli、WindowsCurlCli、PowerShellCurlCli的请求体中均可通过设置reason字段(字符串)设置信号成功或失败原因,这个原因会出现在ROS资源栈事件(信号通知类型)当中。

    例如:-d "{\"status\": \" SUCCESS \", \"reason\": \"nginx is installed successfully.\"}"

    指定了reason字段之后,这个请求的内容就会出现在资源栈事件(信号通知类型)当中。

  • CurlCli、WindowsCurlCli、PowerShellCurlCli的请求体中均可通过设置了data字段(字符串)设置信号关联的数据,这个数据可以通过ALIYUN::ROS::WaitCondition的输出属性Data、ErrorData、JoinedErrorData获取。

    例如:-d "{\"id\" : \"ssh_pub_key\", \"data\" : \"$pub_key\"}"

  • 通过status字段可以指定信号类型,包括SUCCESSFAILUREWARNING。信号类型与资源操作结果的关系如下:(优先级从高到低)

    • 如果收到FAILURE信号,则资源操作失败。

    • 如果在设定时间内,收到的信号数量未满足要求,则资源操作超时失败。

    • 如果收到的信号数量满足了要求,且所有信号均为WARNING,则资源操作失败。

    • 其他情况下,资源操作成功。

示例

  • YAML格式

    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      InstanceId:
        Type: String
        AssociationProperty: ALIYUN::ECS::Instance::InstanceId
    Resources:
      InstallNginx:
        Type: 'ALIYUN::ECS::RunCommand'
        Properties:
          Type: RunShellScript
          CommandContent:
            Fn::Sub: |
                #!/bin/sh
                yum install -y nginx
                systemctl restart nginx
                if [[ $? -eq 0 ]];
                then
                ${InstallNginxWaitConditionHandle.CurlCli} --data-binary "{\"status\": \"SUCCESS\", \"data\": \"Nginx is installed successfully.\"}"
                else
                ${InstallNginxWaitConditionHandle.CurlCli} --data-binary "{\"status\": \"FAILURE\", \"reason\": \"Failed to install and start nginx.\"}"
                fi
          Name: InstallNginxScript
          InstanceIds:
            - Ref:
                InstanceId
          Timeout: 60
      InstallNginxWaitConditionHandle:
        Type: 'ALIYUN::ROS::WaitConditionHandle'
      InstallNginxWaitCondition:
        Type: 'ALIYUN::ROS::WaitCondition'
        Properties:
          Handle:
            Ref: InstallNginxWaitConditionHandle
          Timeout: 60
    Outputs:
      InstallNginxData:
        Description: Received the data sent by the first ecs, JSON serialized dict containing
          data associated with wait condition signals sent to the handle.
        Value:
          Fn::GetAtt:
          - InstallNginxWaitCondition
          - Data
  • JSON格式

    {
      "ROSTemplateFormatVersion": "2015-09-01",
      "Parameters": {
        "InstanceId": {
          "Type": "String",
          "AssociationProperty": "ALIYUN::ECS::Instance::InstanceId"
        }
      },
      "Resources": {
        "InstallNginx": {
          "Type": "ALIYUN::ECS::RunCommand",
          "Properties": {
            "Type": "RunShellScript",
            "CommandContent": {
              "Fn::Sub": "#!/bin/sh\nyum install -y nginx\nsystemctl restart nginx\nif [[ $? -eq 0 ]];\nthen\n${InstallNginxWaitConditionHandle.CurlCli} --data-binary \"{\\\"status\\\": \\\"SUCCESS\\\", \\\"data\\\": \\\"Nginx is installed successfully.\\\"}\"\nelse\n${InstallNginxWaitConditionHandle.CurlCli} --data-binary \"{\\\"status\\\": \\\"FAILURE\\\", \\\"reason\\\": \\\"Failed to install and start nginx.\\\"}\"\nfi\n"
            },
            "Name": "InstallNginxScript",
            "InstanceIds": [
              {
                "Ref": "InstanceId"
              }
            ],
            "Timeout": 60
          }
        },
        "InstallNginxWaitConditionHandle": {
          "Type": "ALIYUN::ROS::WaitConditionHandle"
        },
        "InstallNginxWaitCondition": {
          "Type": "ALIYUN::ROS::WaitCondition",
          "Properties": {
            "Handle": {
              "Ref": "InstallNginxWaitConditionHandle"
            },
            "Timeout": 60
          }
        }
      },
      "Outputs": {
        "InstallNginxData": {
          "Description": "Received the data sent by the first ecs, JSON serialized dict containing data associated with wait condition signals sent to the handle.",
          "Value": {
            "Fn::GetAtt": [
              "InstallNginxWaitCondition",
              "Data"
            ]
          }
        }
      }
    }

更多示例,请参见JSON示例YAML示例

  • 本页导读 (1)
文档反馈