Skip to content

Commit

Permalink
Merge pull request #222 from laDok8/aws_keep_fail
Browse files Browse the repository at this point in the history
add option to keep failing deployments
  • Loading branch information
istraka authored Jul 25, 2024
2 parents e0d6467 + d73e3ad commit ee90692
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 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 All @@ -48,12 +51,19 @@ String deploy(CloudFormationClient cfClient, String template, Map<String, String
List<Parameter> cfParameters = new ArrayList<>();
parameters.forEach((k, v) -> cfParameters.add(Parameter.builder().parameterKey(k).parameterValue(v).build()));

CreateStackRequest stackRequest = CreateStackRequest.builder()
CreateStackRequest.Builder stackBuilder = CreateStackRequest.builder()
.stackName(stackName)
.templateBody(template)//templateURL(location)
.parameters(cfParameters)
.onFailure(OnFailure.ROLLBACK)
.build();
.onFailure(OnFailure.ROLLBACK);

Boolean keepOnFailure = getValue(CoreConfig.KEEP_FAILED_DEPLOY, false);
if (keepOnFailure) {
stackBuilder.onFailure(OnFailure.DO_NOTHING);
LOGGER.debug("Stack will be {} preserved on failure due to {}", stackName, CoreConfig.KEEP_FAILED_DEPLOY);
}

CreateStackRequest stackRequest = stackBuilder.build();

cfClient.createStack(stackRequest);
DescribeStacksRequest stacksRequest = DescribeStacksRequest.builder()
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 @@ -92,7 +93,13 @@ void deploy(String template, Map<String, String> parameters, String group, Strin
if (pollStatus != LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) {
LOGGER.error("Azure deployment from template {} in \"{}\" group failed", deploymentName, group);
AzureUtils.downloadResourceGroupLogs(armManager, group);
undeploy(group);
boolean keepOnFailure = getValue(CoreConfig.KEEP_FAILED_DEPLOY, false);
if (keepOnFailure) {
LOGGER.debug("Resource group {} is preserved due to {}", group, CoreConfig.KEEP_FAILED_DEPLOY);
} else {
undeploy(group);
}

throw new RuntimeException("Deployment failed for group:" + group);
}

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_FAILED_DEPLOY = "sunstone.fail.keepFailedDeploy";
}

0 comments on commit ee90692

Please sign in to comment.