All Products
Search
Document Center

CloudOps Orchestration Service:ACS::CheckFor

Last Updated:Apr 12, 2023

Features

The ACS::CheckFor action is used to check whether the cloud product instances are in the expected status. If the instances are in the specified status, the task is successful. If the instances are not in the specified status, the task fails. This action is usually used to perform pre-checks. For example, if you want to stop an ECS instance, you can check whether the instance is in the Running status first. If it is not in the Running status, you cannot perform the operation.

Syntax

Except that the Type attribute is set to ACS::CheckFor, all other attributes of the ACS::CheckFor action are the same as those of the ACS::WaitFor action. For more information, see the syntax description for the ACS::WaitFor action.

  • YAML format

Tasks:
  - Name: checkForTaskExample
    Type: ACS::CheckFor
    Properties: 
      # The following attributes are the same as those of the ACS::ExecuteAPI action. For more information, see the syntax description for the ACS::ExecuteAPI action.
      Service: ECS
      API: DescribeInstances
      Parameters: 
        InstanceId: i-12345678abcedfg
      # The following attributes are unique attributes of the ACS::CheckFor action.
      PropertySelector: "jq selector" # Required. The jQuery selector for selecting the JSON data to wait for. For more information, see the description of ValueSelector in ACS::ExecuteAPI.
      DesiredValues: # Either DesiredValues or NotDesiredValues is required. This attribute specifies the expected values. If the value selected by PropertySelector matches one of the following values, the operation is successful. If the value selected by PropertySelector does not match any of the following values, the operation times out and fails.
        - value1
        - value2
      NotDesiredValues: # Either DesiredValues or NotDesiredValues is required. This attribute specifies the values that are not expected. If the value selected by PropertySelector does not match any of the following values, the operation is successful. If the value selected by PropertySelector matches one of the following values, the operation times out and fails.
        - value3
        - value4
    Outputs: # The output parameters of the task where the ACS::CheckFor action resides. When the task is successfully executed, the output parameter values that meet the NotDesiredValues or DesiredValues condition are returned.
      OutputParameter1: 
        ValueSelector: 'jq selector' # The jQuery selector for selecting the required JSON data. For example, when you call an API operation for a task, the jQuery selector extracts the required information from the returned JSON data. For more information, see https://stedolan.github.io/jq/.
        Type: String/Boolean/List(Array)/Number/Object
  • JSON format (For more information, see the parameter description for the YAML format.)

{
    "Tasks": [
        {
            "Name": "checkForTaskExample",
            "Type": "ACS::CheckFor",
            "Properties": {
                "Service": "ECS",
                "API": "DescribeInstances",
                "Parameters": {
                    "InstanceId": "i-12345678abcedfg"
                },
                "PropertySelector": "jq selector",
                "DesiredValues": [
                    "value1",
                    "value2"
                ],
                "NotDesiredValues": [
                    "value3",
                    "value4"
                                    ]
                          },
        "Outputs": {
        "OutputParameter1": {
          "ValueSelector": "jq selector",
          "Type": "String/Boolean/List(Array)/Number/Object"
        }
      }
        }
            ]
}

Example

The following template is used to create a snapshot for the specified disk: Use the ACS::CheckFor action to check whether the specified instance is in the Running or Stopped status.

  • YAML format

FormatVersion: OOS-2019-06-01
Parameters:
  DiskId:
    Description: the disk id of the snap shot to copy 
    Type: String
  InstanceId:
    Description: the instances id  of the snap shot to copy 
    Type: String
  SnapshotName:
    Description: snap shot name of the new snap
    Type: String

Tasks:
- Name: checkInstanceReady
    Action: ACS::CheckFor
  Properties:
      Service: ECS
    API: DescribeInstances
    DesiredValues:
    - Running
    - Stopped
    Parameters:
      InstanceIds:
      - '{{ InstanceId }} '
    PropertySelector: Instances.Instance[].Status

- Name: createSnapshot
    Action: ACS::ExecuteAPI
  Properties:
      Service: ECS
    API: CreateSnapshot
    Parameters:
      DiskId: '{{ DiskId }}'
      SnapshotName: '{{ SnapshotName }}'
        Outputs:
      SnapshotId:
        Type: String
        ValueSelector: SnapshotId

- Name: waitSnapshotsReady
    Action: ACS::WaitFor
  Properties:
      Service: ECS
    API: DescribeSnapshots
    DesiredValues:
    - accomplished
    Parameters:
      SnapshotIds:
      - '{{ createSnapshot.SnapshotId }}'
    PropertySelector: Snapshots.Snapshot[].Status

Outputs:
  SnapshotId:
    Type: String
    Value: '{{ createSnapshot.SnapshotId }}'
  • JSON format

{
    "FormatVersion": "OOS-2019-06-01",
    "Parameters": {
        "DiskId": {
            "Description": "the disk id of the snap shot to copy ",
            "Type": "String"
        },
        "InstanceId": {
            "Description": "the instances id  of the snap shot to copy ",
            "Type": "String"
        },
        "SnapshotName": {
            "Description": "snap shot name of the new snap",
            "Type": "String"
        }
    },
    "Tasks": [
        {   
            "Name": "checkInstanceReady",
            "Action": "ACS::CheckFor",
            "Properties": {
                "Service": "ECS",
                "API": "DescribeInstances",
                "DesiredValues": ["Running", "Stopped"],
                "Parameters": {
                    "InstanceIds": ["{{ InstanceId }} "]
                },
                "PropertySelector": "Instances.Instance[].Status"
            }
        },
        {   
            "Name": "createSnapshot",
            "Action": "ACS::ExecuteAPI",
            "Properties": {
                "Service": "ECS",
                "API": "CreateSnapshot",
                "Parameters": {
                    "DiskId": "{{ DiskId }}",
                    "SnapshotName": "{{ SnapshotName }}"
                }
            },
            "Outputs": {
                "SnapshotId": {
                    "Type": "String",
                    "ValueSelector": "SnapshotId"
                }
            }
        },
        {   
            "Name": "waitSnapshotsReady",
            "Action": "ACS::WaitFor",
            "Properties": {
                "Service": "ECS",
                "API": "DescribeSnapshots",
                "DesiredValues": ["accomplished"],
                "Parameters": {
                    "SnapshotIds": ["{{ createSnapshot.SnapshotId }}"]
                },
                "PropertySelector": "Snapshots.Snapshot[].Status"
            }
        }
    ],
    "Outputs": {
        "SnapshotId": {
            "Type": "String",
            "Value": "{{ createSnapshot.SnapshotId }}"
        }
    }
}