Skip to content

Commit

Permalink
perform rollback only when resources are provisioned
Browse files Browse the repository at this point in the history
  • Loading branch information
swaroopar committed Dec 1, 2023
1 parent d7f5d86 commit 28c6f53
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private void deploy(Deployment deployment, DeployTask deployTask) {
validateDeploymentWithPolicies(deployment, deployTask);
deployResult = deployment.deploy(deployTask);
} catch (RuntimeException e) {
log.info("Deploy service with id:{} failed. error:{}", deployTask.getId(), e);
log.info("Deploy service with id:{} failed.", deployTask.getId(), e);
deployResult = new DeployResult();
deployResult.setId(deployTask.getId());
deployResult.setState(TerraformExecState.DEPLOY_FAILED);
Expand All @@ -249,7 +249,7 @@ private void deploy(Deployment deployment, DeployTask deployTask) {
rollbackOnDeploymentFailure(deployment, deployTask, updatedDeployServiceEntity);
}
} catch (RuntimeException e) {
log.info("Deploy service with id:{} update database entity failed. error:{}",
log.info("Deploy service with id:{} update database entity failed.",
deployTask.getId(), e);
}
}
Expand Down Expand Up @@ -351,10 +351,14 @@ private List<DeployResourceEntity> getDeployResourceEntityList(
* Perform rollback when deployment fails and destroy the created resources.
*/
private void rollbackOnDeploymentFailure(Deployment deployment,
DeployTask destroyTask,
DeployTask deployTask,
DeployServiceEntity deployServiceEntity) {
log.info("Performing rollback of already provisioned resources.");
destroy(deployment, destroyTask, deployServiceEntity);
if (Objects.nonNull(deployServiceEntity.getDeployResourceList())
&& !deployServiceEntity.getDeployResourceList().isEmpty()) {
log.info("destroying created resources for service with ID: {}", deployTask.getId());
destroy(deployment, deployTask, deployServiceEntity);
}
}

/**
Expand All @@ -378,7 +382,7 @@ private void destroy(Deployment deployment, DeployTask destroyTask,
String stateFile = getStoredStateContent(deployServiceEntity);
destroyResult = deployment.destroy(destroyTask, stateFile);
} catch (RuntimeException e) {
log.info("Destroy service with id:{} failed. error:{}", destroyTask.getId(), e);
log.info("Destroy service with id:{} failed.", destroyTask.getId(), e);
destroyResult = new DeployResult();
destroyResult.setId(destroyTask.getId());
destroyResult.setState(TerraformExecState.DESTROY_FAILED);
Expand All @@ -393,7 +397,7 @@ private void destroy(Deployment deployment, DeployTask destroyTask,
deployment.deleteTaskWorkspace(destroyTask.getId().toString());
}
} catch (RuntimeException e) {
log.info("Destroy service with id:{} update database entity failed. error:{}",
log.info("Destroy service with id:{} update database entity failed.",
destroyTask.getId(), e);
}
}
Expand Down Expand Up @@ -458,7 +462,8 @@ private void purgeService(Deployment deployment, DeployTask deployTask,
try {
if (Objects.nonNull(deployServiceEntity.getDeployResourceList())
&& !deployServiceEntity.getDeployResourceList().isEmpty()) {
log.info("Purging created resources for service with ID: {}", deployTask.getId());
log.info("destroying created resources for service with ID: {}",
deployTask.getId());
destroy(deployment, deployTask, deployServiceEntity);
}
DeployServiceEntity updatedDeployServiceEntity =
Expand Down

0 comments on commit 28c6f53

Please sign in to comment.