Skip to content

Commit

Permalink
add option to keep failing stacks on AWS
Browse files Browse the repository at this point in the history
  • Loading branch information
laDok8 committed Jun 26, 2024
1 parent 1e825b2 commit 6e93ccc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import software.amazon.awssdk.services.cloudformation.model.OnFailure;
import software.amazon.awssdk.services.cloudformation.model.Parameter;
import software.amazon.awssdk.services.cloudformation.waiters.CloudFormationWaiter;
import sunstone.core.CoreConfig;

import java.io.Closeable;
import java.util.ArrayList;
Expand All @@ -22,6 +23,8 @@
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

import static sunstone.core.SunstoneConfigResolver.getValue;

/**
* Purpose: the class handles AWS CloudFormation template - deploy and undeploy the template to and from a stack.
* <p>
Expand Down Expand Up @@ -69,6 +72,15 @@ public void undeploy(String stack) {
CloudFormationClient cfClient = stack2Client.get(stack);
CloudFormationWaiter waiter = cfClient.waiter();

stack2Client.remove(stack);
client2stacks.get(cfClient).remove(stack);

boolean keepResources = getValue(CoreConfig.KEEP_FAIL_DEPLOY, false);
if (keepResources) {
LOGGER.debug("Stack {} is preserved", stack);
return;
}

DeleteStackRequest stackRequest = DeleteStackRequest.builder()
.stackName(stack)
.build();
Expand All @@ -80,8 +92,6 @@ public void undeploy(String stack) {

WaiterResponse<DescribeStacksResponse> waiterResponse = waiter.waitUntilStackDeleteComplete(stacksRequest);
LOGGER.debug("Stack {} is deleted {}", stack, waiterResponse.matched().response().orElse(null));
stack2Client.remove(stack);
client2stacks.get(cfClient).remove(stack);
}

public void close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.slf4j.Logger;
import sunstone.core.CoreConfig;
import sunstone.core.TimeoutUtils;

import java.io.IOException;
Expand Down Expand Up @@ -135,8 +136,14 @@ private String parametersFromMap(String template, Map<String, String> parameters

public void undeploy(String rgName) {
ResourceGroups rgs = armManager.resourceGroups();
boolean keepResources = getValue(CoreConfig.KEEP_FAIL_DEPLOY, false);
if (keepResources) {
LOGGER.debug("Azure resource group '{}' is preserved", rgName);
return;
}
if (rgs.contain(rgName)) {
rgs.deleteByName(rgName);
LOGGER.debug("Azure resource group '{}' is deleted", rgName);
}
usedRG.remove(rgName);
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/sunstone/core/CoreConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
public class CoreConfig {

public static final String TIMEOUT_FACTOR = "sunstone.timeout.factor";
public static final String KEEP_FAIL_DEPLOY = "sunstone.fail.keepResources";
}

0 comments on commit 6e93ccc

Please sign in to comment.