From 65ee903944804633fac3f937c52321dd652e326d Mon Sep 17 00:00:00 2001 From: Amadeo Casas Date: Tue, 11 Jun 2013 16:07:34 -0700 Subject: [PATCH 1/2] Force Delete support in ASGs --- .../com/netflix/asgard/AutoScalingController.groovy | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/grails-app/controllers/com/netflix/asgard/AutoScalingController.groovy b/grails-app/controllers/com/netflix/asgard/AutoScalingController.groovy index f82352cd..c9e00be0 100644 --- a/grails-app/controllers/com/netflix/asgard/AutoScalingController.groovy +++ b/grails-app/controllers/com/netflix/asgard/AutoScalingController.groovy @@ -37,6 +37,7 @@ import com.netflix.asgard.model.GroupedInstance import com.netflix.asgard.model.InstancePriceType import com.netflix.asgard.model.SubnetTarget import com.netflix.asgard.model.Subnets +import com.netflix.asgard.push.GroupDeleteOperation import com.netflix.grails.contextParam.ContextParam import grails.converters.JSON import grails.converters.XML @@ -57,6 +58,7 @@ class AutoScalingController { def configService def instanceTypeService def mergedInstanceService + def pushService def spotInstanceRequestService def stackService @@ -450,13 +452,15 @@ class AutoScalingController { String name = params.name AutoScalingGroup group = awsAutoScalingService.getAutoScalingGroup(userContext, name) Boolean showGroupNext = false + Boolean showTask = false if (!group) { flash.message = "Auto Scaling Group '${name}' not found." } else { if (group?.instances?.size() <= 0) { try { - awsAutoScalingService.deleteAutoScalingGroup(userContext, name) - flash.message = "AutoScaling Group '${name}' has been deleted." + GroupDeleteOperation operation = pushService.startGroupDelete(userContext, group) + showTask = true + redirect(controller: 'task', action: 'show', params: [id: operation.taskId]) } catch (Exception e) { flash.message = "Could not delete Auto Scaling Group: ${e}" showGroupNext = true @@ -467,7 +471,9 @@ class AutoScalingController { showGroupNext = true } } - showGroupNext ? redirect(action: 'show', params: [id: name]) : redirect(action: 'list') + if (!showTask) { + showGroupNext ? redirect(action: 'show', params: [id: name]) : redirect(action: 'list') + } } def postpone = { From 3704f0deead2905a347f1304df7cd2eabb5f6105 Mon Sep 17 00:00:00 2001 From: Amadeo Casas Date: Tue, 11 Jun 2013 17:51:47 -0700 Subject: [PATCH 2/2] Cleaning up code based on code review feedback --- .../asgard/AutoScalingController.groovy | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/grails-app/controllers/com/netflix/asgard/AutoScalingController.groovy b/grails-app/controllers/com/netflix/asgard/AutoScalingController.groovy index c9e00be0..3d84ef66 100644 --- a/grails-app/controllers/com/netflix/asgard/AutoScalingController.groovy +++ b/grails-app/controllers/com/netflix/asgard/AutoScalingController.groovy @@ -451,28 +451,11 @@ class AutoScalingController { UserContext userContext = UserContext.of(request) String name = params.name AutoScalingGroup group = awsAutoScalingService.getAutoScalingGroup(userContext, name) - Boolean showGroupNext = false - Boolean showTask = false if (!group) { flash.message = "Auto Scaling Group '${name}' not found." } else { - if (group?.instances?.size() <= 0) { - try { - GroupDeleteOperation operation = pushService.startGroupDelete(userContext, group) - showTask = true - redirect(controller: 'task', action: 'show', params: [id: operation.taskId]) - } catch (Exception e) { - flash.message = "Could not delete Auto Scaling Group: ${e}" - showGroupNext = true - } - } else { - flash.message = "You cannot delete an auto scaling group that still has instances. " + - "Set the min and max to 0, wait for the instances to disappear, then try deleting again." - showGroupNext = true - } - } - if (!showTask) { - showGroupNext ? redirect(action: 'show', params: [id: name]) : redirect(action: 'list') + GroupDeleteOperation operation = pushService.startGroupDelete(userContext, group) + redirect(controller: 'task', action: 'show', params: [id: operation.taskId]) } }