Use the ACS::Loop action to run a series of O&M tasks in a loop. You can define a sequence of tasks supported by Operation Orchestration Service (OOS) as the loop body.
Syntax
- Name: exampleTask
Action: 'ACS::Loop'
Properties:
LoopItems: # The loop array. It accepts a list of items. The elements traversed from the list are used as parameters for each execution of the loop task.
- i-aaaaa
- 1-bbbbb
LoopRateControl:
MaxErrors: 0 # Optional. The value can be a number or a percentage, such as 10 or 10%. The default value is 0.
Mode: "Batch/Concurrency" # Required. The mode for controlling the loop execution rate. Valid values: Concurrency and Batch. Concurrency specifies concurrent execution. Batch specifies batch execution.
Batch: [1, 2, 3] # Optional. This parameter takes effect when Mode is set to Batch. It specifies batch control. For information about how to define this parameter, see the "Batch control" section below.
ConcurrencyInBatches: [1, 1, 1] # Optional. This parameter takes effect when Mode is set to Batch. It controls the degree of concurrency for each batch in Batch mode. The default value is 20. To define this parameter, specify the concurrency for each batch in [].
Concurrency: 1 # Optional. This parameter takes effect when Mode is set to Concurrency. It controls the concurrency for all executions. The value can be a number or a percentage. The default value is 1.
BatchPauseOption: "FirstBatchPause/Automatic/EveryBatchPause" # Optional. This parameter takes effect when Mode is set to Batch. It specifies the pause option after each batch is executed. Valid values: FirstBatchPause, Automatic, and EveryBatchPause. FirstBatchPause: Pauses after the first batch. Automatic: Does not pause. EveryBatchPause: Pauses after every batch.
LoopTasks: # The task array. It can include multiple tasks supported by OOS.
- Name: deployRevisions
Action: ACS::CICD::DeployRevisionOnEcs
Properties:
regionId: 'cn-hangzhou'
instanceId: '{{ ACS::TaskLoopItem }}' # ACS::TaskLoopItem references the element traversed in each iteration of the loop array.
deployRevisionId: 'xxxx'
Outputs:
deployCommandOutput: # The custom output of the loop task.
Type: String
ValueSelector: '{{ deployRevisions.commandOutput }}' # Selects the output of a task in the task array. The final output of deployCommandOutput is an array that aggregates the outputs of each loop.Loop array
The Items parameter accepts a list, such as a literal list: [item1, item2, item3].
The Items parameter can also be the name of a parameter that contains a list, such as the Outputs of a previous task.
Items is a list.
Loop: Items: [item1,item2,item3,item4] # A list of items, such as [i-id1, i-id2, i-id3, i-id4]. The items are iterated as parameters for the task where the loop is located.{ "Items": [ "item1", "item2", "item3", "item4" ] }Items is the name of a list-type parameter.
Items: '{{ParameterName1}}' # The name of a parameter that can be parsed as a list, such as describeInstance.InstanceIds. The items are iterated as parameters for the task where the loop is located.{ "Items": "{{ParameterName1}}" }
Task execution rate
Two modes are available:
Concurrency control: Executes a specified number of items concurrently until all items are processed.
Batch control: Divides items into multiple batches. The next batch starts only after the previous batch is complete.
Concurrency control (Concurrency)
If Items contains 10 items and Concurrency is set to 3, three items are executed concurrently until all items are processed.
Concurrency: 3 # The value can be a number or a percentage for concurrency control, such as 3. Mode: Concurrency{ "Concurrency": 3, "Mode": "Concurrency" }If Items contains 10 items and Concurrency is set to 20%, the concurrency is 2 (10 × 20%). Two items are executed concurrently until all items are processed.
Concurrency: 20% # Optional. The value can be a number or a percentage, such as 20%. Mode: Concurrency{ "Concurrency": "20%", "Mode": "Concurrency" }
Batch control (Batch)
If Items contains 10 items and Batch is set to [3], the items are divided into batches of three. This results in four batches that contain 3, 3, 3, and 1 items, assuming all item executions are successful.
Batch: [1, 2, 3] # Optional. You can define batch control using a list that contains numbers or percentages, such as [3]. Mode: Batch{ "Batch": [ 1, 2, 3 ], "Mode": "Batch" }If Items contains 10 items and Batch is set to [30%], the batch size is three items (10 × 30% = 3). This results in four batches that contain 3, 3, 3, and 1 items, assuming all item executions are successful.
Batch: [30%] # Optional. You can define batch control using a list that contains numbers or percentages, such as [30%]. Mode: Batch{ "Batch": [ "30%" ], "Mode": "Batch" }If Items contains 10 items and Batch is set to [3, 10%, 30%], the first batch contains 3 items, the second batch contains 1 item (10% of the total), and the third and subsequent batches each contain 3 items (30% of the total). This results in four batches that contain 3, 1, 3, and 3 items, assuming all item executions are successful.
Mode: Batch Batch: [3, 10%,30%] # Optional. You can define batch control using a list that contains multiple numbers or percentages, such as [3, 10%, 30%].{ "Mode": "Batch", "Batch": [ 3, "10%", "30%" ] }
Fault control: MaxErrors
In a loop, you can also define MaxErrors. This parameter works as follows:
The value can be a number or a percentage of the total number of items, such as 10 or 10%. The default value is 0. A value of 0 means that the loop task fails if any item execution results in a fault.
The first item in the loop is always executed.
Whether subsequent items can be executed depends on the current ErrorCount value relative to the MaxErrors value.
If the ErrorCount value exceeds the MaxErrors value, the execution of subsequent items stops and the loop task is marked as failed.
If the ErrorCount value is less than or equal to the MaxErrors value, the execution continues.
The final status of the loop task is determined by whether the ErrorCount value is greater than the MaxErrors value. If it is greater, the status is Failed. Otherwise, the status is Success.
By number
MaxErrors: 2 # Optional. The value can be a number or a percentage, such as 2. This indicates that the maximum ErrorCount is 2.{ "MaxErrors": 2 }By percentage
MaxErrors: 25% # Optional. The value can be a number or a percentage, such as 25%. If there are 4 items in total, the maximum ErrorCount is 1 (4 × 25% = 1).{ "MaxErrors": "25%" }
Task outputs
You can customize the outputs of an ACS::Loop task. In ValueSelector, you can select the outputs of tasks within LoopTasks. The final output is an array that aggregates the task outputs from each loop iteration.
For example, in the syntax example, assume that the deployRevisions task returns "deployRevisions example output".
The final output of deployCommandOutput is:
["deployRevisions example output",
"deployRevisions example output"] Example
FormatVersion: OOS-2019-06-01
Description: An example template for acsLoop.
Tasks:
- Name: exampleTask
Action: ACS::Loop
Properties:
LoopItems:
- cn-hangzhou
- cn-qingdao
LoopTasks:
- Name: DescribeRegions
Action: ACS::ExecuteApi
Properties:
Parameters:
RegionId: '{{ ACS::TaskLoopItem }}'
Service: ecs
API: DescribeRegions
Outputs:
regions:
Type: String
ValueSelector: DescribeRegions.Regions.Region[]?.LocalName
Outputs:
outputRegions:
Type: List
Value: '{{ exampleTask.regions }}'