-
Notifications
You must be signed in to change notification settings - Fork 17
/
ACS-ESS-RollingUpdateByDownloadOSSFileAndRunCommand.yml
470 lines (470 loc) · 15.2 KB
/
ACS-ESS-RollingUpdateByDownloadOSSFileAndRunCommand.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
FormatVersion: OOS-2019-06-01
Description:
en: Rolling update ECS instances that in scaling group by download OOS file and run command
zh-cn: 通过下载OSS文件并执行命令的方式滚动更新伸缩组内的ECS实例
name-en: ACS-ESS-RollingUpdateByDownloadOSSFileAndRunCommand
name-zh-cn: 通过下载OSS文件并执行命令的方式滚动更新伸缩组内的ECS实例
categories:
- elastic_manage
Parameters:
invokeType:
Label:
en: InvokeType
zh-cn: 操作类型
Type: String
AllowedValues:
- invoke
- rollback
scalingGroupId:
Label:
en: ScalingGroupId
zh-cn: 伸缩组ID
Type: String
enterProcess:
Label:
en: EnterProcess
zh-cn: 执行开始要暂停的伸缩组流程
Type: List
Default:
- ScaleIn
- ScaleOut
- HealthCheck
- AlarmNotification
- ScheduledAction
exitProcess:
Label:
en: ExitProcess
zh-cn: 执行结束要恢复的伸缩组流程
Type: List
Default:
- ScaleIn
- ScaleOut
- HealthCheck
- AlarmNotification
- ScheduledAction
invokeBucketName:
Type: String
Label:
en: InvokeBucketName
zh-cn: 用于升级的Bucket名称
invokeObjectName:
Label:
en: InvokeObjectName
zh-cn: 用于升级的Object名称
Type: String
invokeDestinationDir:
Label:
en: InvokeDestinationDir
zh-cn: 用于升级的文件存储目录
Type: String
invokeScript:
Label:
en: InvokeScript
zh-cn: 用于升级的脚本
Type: String
AssociationProperty: Code
Default: ''
rollbackBucketName:
Type: String
Label:
en: RollbackBucketName
zh-cn: 用于回滚的Bucket名称
rollbackObjectName:
Label:
en: RollbackObjectName
zh-cn: 用于回滚的Object名称
Type: String
rollbackDestinationDir:
Label:
en: InvokeDestinationDir
zh-cn: 用于回滚的文件存储目录
Type: String
rollbackScript:
Label:
en: RollbackScript
zh-cn: 用于回滚的脚本
Type: String
AssociationProperty: Code
Default: ''
sourceExecutionId:
Label:
en: SourceExecutionId
zh-cn: 用于回滚的OOS执行ID
Type: String
Default: ''
whetherSaveToFile:
Label:
en: whetherSaveToFile
zh-cn: 是否将内容下载到特定文件
Type: Boolean
Default: true
URLExpirationTime:
Label:
en: OOSFileDownloadURLExpirationTime
zh-cn: OSS文件下载链接的过期时间
Type: Number
Default: 6000
OSSRegion:
Label:
en: OSSRegion
zh-cn: OSS所在地域
Description:
en: When the region where the OSS is located is different from the current region, the OSS file will be downloaded through the public network, and the ECS in the scaling group must be able to access the public network.
zh-cn: OSS所在地域和当前地域不同时会通过公网下载OSS文件,需要伸缩组内的ECS能访问公网。
Type: String
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
batchPauseOption:
Label:
en: BatchPauseOption
zh-cn: 分批模式
Type: String
AllowedValues:
- Automatic
- FirstBatchPause
- EveryBatchPause
Default: Automatic
batchNumber:
Label:
en: BatchNumber
zh-cn: 分批执行的批次
Type: Number
MinValue: 1
MaxValue: 100
Default: 5
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: OOS扮演的RAM角色
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: getLifecycleHook
Action: ACS::ExecuteAPI
Description:
en: Get lifecycle hook
zh-cn: 获取生命周期挂钩
Properties:
Service: ESS
API: DescribeLifecycleHooks
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
LifecycleHookName: ACS-ESS-LifeCycleDownloadOSSFileAndRunCommand
Outputs:
totalCount:
Type: String
ValueSelector: .TotalCount
- Name: choiceNextTask
Action: 'ACS::Choice'
Description:
en: Choose next task by invoke type
zh-cn: 根据升级类型选择任务
Properties:
DefaultTask: getInstance
Choices:
- When:
'Fn::Equals':
- rollback
- '{{ invokeType }}'
NextTask: getExecutionInstanceIds
- Name: getInstance
Description:
en: Views the ECS instances
zh-cn: 获取ECS实例
Action: 'ACS::ExecuteApi'
Properties:
Service: ESS
API: DescribeScalingInstances
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
LifecycleState: InService
CreationTypes:
- AutoCreated
- Attached
Outputs:
instanceIds:
Type: List
ValueSelector: 'ScalingInstances.ScalingInstance[].InstanceId'
- Name: whetherTheScalingGroupInstanceIsEmpty
Action: 'ACS::Choice'
Description:
en: Check whether the instances in the services in the scaling group are empty
zh-cn: 检查伸缩组内服务中的实例是否为空
Properties:
DefaultTask: whetherToSuspendProcess
Choices:
- When:
'Fn::Equals':
- [ ]
- '{{ getInstance.instanceIds }}'
NextTask: 'ACS::END'
- Name: whetherToSuspendProcess
Action: 'ACS::Choice'
Description:
en: Choose next task by process
zh-cn: 根据流程值判断是否暂停流程
Properties:
DefaultTask: suspendProcess
Choices:
- When:
'Fn::Equals':
- []
- '{{ enterProcess }}'
NextTask: invokeByDownloadOSSFileAndRunCommand
- Name: suspendProcess
Action: 'ACS::ExecuteAPI'
Description:
en: Suspend process
zh-cn: 暂停伸缩组流程
Properties:
Service: ESS
API: SuspendProcesses
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
Process: '{{ enterProcess }}'
- Name: invokeByDownloadOSSFileAndRunCommand
Action: ACS::ECS::DownloadOSSFileAndRunCommand
Description:
en: Upgrade by downloading files to the instance and executing commands
zh-cn: 通过下载文件到实例并执行命令的方式进行升级
Properties:
instanceId: '{{ ACS::TaskLoopItem }}'
bucketName: '{{ invokeBucketName }}'
objectName: '{{ invokeObjectName }}'
URLExpirationTime: '{{ URLExpirationTime }}'
OSSRegion: '{{ OSSRegion }}'
commandContent: '{{ invokeScript }}'
destinationDir: '{{ invokeDestinationDir }}'
whetherSaveToFile: '{{ whetherSaveToFile }}'
Loop:
Items: '{{ getInstance.instanceIds }}'
BatchPauseOption: '{{ batchPauseOption }}'
Concurrency:
'Fn::CalculateBatch':
- '{{ batchNumber }}'
- '{{ getInstance.instanceIds }}'
Outputs:
commandOutputs:
AggregateType: 'Fn::ListJoin'
AggregateField: commandOutput
Outputs:
commandOutput:
Type: String
ValueSelector: runCommandOutput
- Name: tagInstance
Action: ACS::ExecuteApi
Description:
en: Creates and attaches tag to ECS instance
zh-cn: 创建并挂载标签到ECS实例
Properties:
Service: ECS
API: TagResources
Parameters:
ResourceIds:
- '{{ ACS::TaskLoopItem }}'
ResourceType: Instance
Tags:
- Key: 'ess:rollingupdate'
Value: 'oos:{{ ACS::ExecutionId }}'
Loop:
Items: '{{ getInstance.instanceIds }}'
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
- Name: createLifecycleHookOfUpgrade
When:
Fn::Equals:
- '{{ getLifecycleHook.totalCount }}'
- 0
Action: ACS::ExecuteAPI
Description:
en: Create lifecycle hook of upgrade
zh-cn: 创建用于升级的生命周期挂钩
Properties:
Service: ESS
API: CreateLifecycleHook
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
NotificationMetadata: '{"bucketName":"{{ invokeBucketName }}","objectName":"{{ invokeObjectName }}","URLExpirationTime":"{{ URLExpirationTime }}","OSSRegion":"{{ OSSRegion }}","destinationDir":"{{ invokeDestinationDir }}","OSSRegion":"{{ OSSRegion }}","commandContent":"{{ invokeScript }}","timeout":"600","regionId":"${regionId}","instanceIds":"${instanceIds}","lifecycleHookId":"${lifecycleHookId}","lifecycleActionToken":"${lifecycleActionToken}","rateControl":"{\"Mode\":\"Concurrency\",\"MaxErrors\":0,\"Concurrency\":10}","OOSAssumeRole":"OOSServiceRole"}'
LifecycleTransition: SCALE_OUT
LifecycleHookName: ACS-ESS-LifeCycleDownloadOSSFileAndRunCommand
NotificationArn: acs:oos:{{ ACS::RegionId }}:{{ACS::AccountId}}:template/ACS-ESS-LifeCycleDownloadOSSFileAndRunCommand
- Name: modifyLifecycleHookOfUpgrade
When:
Fn::Equals:
- '{{ getLifecycleHook.totalCount }}'
- 1
Action: ACS::ExecuteAPI
Description:
en: Modify lifecycle hook of upgrade
zh-cn: 修改用于升级的生命周期挂钩
Properties:
Service: ESS
API: ModifyLifecycleHook
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
NotificationMetadata: '{"bucketName":"{{ invokeBucketName }}","objectName":"{{ invokeObjectName }}","URLExpirationTime":"{{ URLExpirationTime }}","OSSRegion":"{{ OSSRegion }}","destinationDir":"{{ invokeDestinationDir }}","commandContent":"{{ invokeScript }}","timeout":"600","regionId":"${regionId}","instanceIds":"${instanceIds}","lifecycleHookId":"${lifecycleHookId}","lifecycleActionToken":"${lifecycleActionToken}","rateControl":"{\"Mode\":\"Concurrency\",\"MaxErrors\":0,\"Concurrency\":10}","OOSAssumeRole":"OOSServiceRole"}'
LifecycleTransition: SCALE_OUT
LifecycleHookName: ACS-ESS-LifeCycleDownloadOSSFileAndRunCommand
- Name: whetherToResumeProcesses
Action: 'ACS::Choice'
Description:
en: Choose next task by process
zh-cn: 根据流程值判断是否恢复流程
Properties:
DefaultTask: resumeProcesses
Choices:
- When:
'Fn::Equals':
- []
- '{{ exitProcess }}'
NextTask: 'ACS::END'
- Name: resumeProcesses
Action: 'ACS::ExecuteAPI'
OnSuccess: 'ACS::END'
Description:
en: Resume process
zh-cn: 恢复伸缩组流程
Properties:
Service: ESS
API: ResumeProcesses
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
Process: '{{ exitProcess }}'
- Name: getExecutionInstanceIds
Action: 'ACS::ExecuteAPI'
Description:
en: Get the instance that has been executed
zh-cn: 获取已经执行过执行脚本的实例
Properties:
Service: OOS
API: ListExecutions
Parameters:
ParentExecutionId: '{{ sourceExecutionId }}'
Outputs:
instanceIds:
Type: List
ValueSelector: 'Executions[].Parameters.instanceId'
- Name: getExistInstanceIds
Description:
en: Views the ECS instances
zh-cn: 获取ECS实例
Action: ACS::SelectTargets
Properties:
ResourceType: ALIYUN::ECS::Instance
Filters:
- Type: ResourceIds
ResourceIds: '{{ getExecutionInstanceIds.instanceIds }}'
Outputs:
instanceIds:
Type: List
ValueSelector: Instances.Instance[].InstanceId
- Name: getRollbackProcess
Action: 'ACS::ExecuteAPI'
Description:
en: Views resource parameters
zh-cn: 获取源执行的参数
Properties:
Service: OOS
API: ListExecutions
Parameters:
ExecutionId: '{{ sourceExecutionId }}'
Outputs:
enterProcess:
Type: List
ValueSelector: 'Executions[].Parameters.enterProcess[]'
exitProcess:
Type: List
ValueSelector: 'Executions[].Parameters.exitProcess[]'
- Name: suspendProcessWithRollBack
Action: 'ACS::ExecuteAPI'
Description:
en: Suspend process
zh-cn: 暂停伸缩组流程
Properties:
Service: ESS
API: SuspendProcesses
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
Process: '{{ getRollbackProcess.enterProcess }}'
- Name: rollbackByDownloadOSSFileAndRunCommand
Action: ACS::ECS::DownloadOSSFileAndRunCommand
Description:
en: Rollback by downloading files to the instance and executing commands
zh-cn: 通过下载文件到实例并执行命令的方式进行回滚
Properties:
instanceId: '{{ ACS::TaskLoopItem }}'
bucketName: '{{ rollbackBucketName }}'
objectName: '{{ rollbackObjectName }}'
URLExpirationTime: '{{ URLExpirationTime }}'
OSSRegion: '{{ OSSRegion }}'
commandContent: '{{ rollbackScript }}'
destinationDir: '{{ rollbackDestinationDir }}'
whetherSaveToFile: '{{ whetherSaveToFile }}'
Loop:
Items: '{{ getExistInstanceIds.instanceIds }}'
BatchPauseOption: '{{ batchPauseOption }}'
Concurrency:
'Fn::CalculateBatch':
- '{{ batchNumber }}'
- '{{ getExistInstanceIds.instanceIds }}'
Outputs:
commandOutputs:
AggregateType: 'Fn::ListJoin'
AggregateField: commandOutput
Outputs:
commandOutput:
Type: String
ValueSelector: runCommandOutput
- Name: modifyLifecycleHookOfRollback
When:
Fn::Equals:
- '{{ getLifecycleHook.totalCount }}'
- 1
Action: ACS::ExecuteAPI
Description:
en: Modify lifecycle hook of rollback
zh-cn: 修改用于回滚的生命周期挂钩
Properties:
Service: ESS
API: ModifyLifecycleHook
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
NotificationMetadata: '{"bucketName":"{{ rollbackBucketName }}","objectName":"{{ rollbackObjectName }}","URLExpirationTime":"{{ URLExpirationTime }}","OSSRegion":"{{ OSSRegion }}","destinationDir":"{{ rollbackDestinationDir }}","commandContent":"{{ rollbackScript }}","timeout":"600","regionId":"${regionId}","instanceIds":"${instanceIds}","lifecycleHookId":"${lifecycleHookId}","lifecycleActionToken":"${lifecycleActionToken}","rateControl":"{\"Mode\":\"Concurrency\",\"MaxErrors\":0,\"Concurrency\":10}","OOSAssumeRole":"OOSServiceRole"}'
LifecycleTransition: SCALE_OUT
LifecycleHookName: ACS-ESS-LifeCycleDownloadOSSFileAndRunCommand
- Name: whetherToResumeProcessesWithRollback
Action: 'ACS::Choice'
Description:
en: Choose next task by process
zh-cn: 根据流程值判断是否恢复流程
Properties:
DefaultTask: resumeProcessesWithRollback
Choices:
- When:
'Fn::Equals':
- []
- '{{ getRollbackProcess.exitProcess }}'
NextTask: 'ACS::END'
- Name: resumeProcessesWithRollback
Action: 'ACS::ExecuteAPI'
Description:
en: Resume process
zh-cn: 恢复伸缩组流程
Properties:
Service: ESS
API: ResumeProcesses
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
Process: '{{ getRollbackProcess.exitProcess }}'
Outputs:
commandOutputs:
Type: List
Value:
'Fn::If':
- 'Fn::Equals':
- invoke
- '{{ invokeType }}'
- '{{ invokeByDownloadOSSFileAndRunCommand.commandOutputs }}'
- '{{ rollbackByDownloadOSSFileAndRunCommand.commandOutputs }}'