Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#201] Add option to keep failing deployments #222

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
}
Loading