Skip to content

Commit

Permalink
remove 'DeploymentScenario' from terraform-boot
Browse files Browse the repository at this point in the history
  • Loading branch information
baixinsui committed Apr 16, 2024
1 parent 80d5dba commit a185a1e
Show file tree
Hide file tree
Showing 69 changed files with 868 additions and 2,614 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public List<DeployedService> listDeployedServices(
@RequestParam(name = "serviceVersion", required = false) String serviceVersion,
@Parameter(name = "serviceState", description = "deployment state of the service")
@RequestParam(name = "serviceState", required = false)
ServiceDeploymentState serviceState) {
ServiceDeploymentState serviceState) {
return this.serviceDetailsViewManager.listDeployedServices(
category, csp, serviceName, serviceVersion, serviceState);
}
Expand All @@ -162,7 +162,7 @@ public List<DeployedService> listDeployedServicesDetails(
@RequestParam(name = "serviceVersion", required = false) String serviceVersion,
@Parameter(name = "serviceState", description = "deployment state of the service")
@RequestParam(name = "serviceState", required = false)
ServiceDeploymentState serviceState) {
ServiceDeploymentState serviceState) {
// return type is DeployedService but actually returns one of the child types
// VendorHostedDeployedServiceDetails or DeployedServiceDetails
return this.serviceDetailsViewManager.listDeployedServicesDetails(
Expand Down Expand Up @@ -209,10 +209,10 @@ public UUID deploy(@Valid @RequestBody DeployRequest deployRequest) {
@Operation(description = "Start a task to modify service using registered service template.")
@PutMapping(value = "/services/modify/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.ACCEPTED)
public UUID modify(@Valid @RequestBody
ModifyRequest modifyRequest, @Parameter(name = "id", description =
"The id of modify service")
@PathVariable("id") String id) {
public UUID modify(@Parameter(name = "id", description = "The id of modify service")
@PathVariable("id") String id,
@Valid @RequestBody
ModifyRequest modifyRequest) {
log.info("Modifying service with id {}", id);
DeployServiceEntity deployServiceEntity =
this.deployServiceEntityHandler.getDeployServiceEntity(UUID.fromString(id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import lombok.extern.slf4j.Slf4j;
import org.eclipse.xpanse.modules.deployment.deployers.terraform.callbacks.TerraformDeploymentResultCallbackManager;
import org.eclipse.xpanse.modules.deployment.deployers.terraform.terraformboot.generated.model.TerraformResult;
import org.eclipse.xpanse.modules.orchestrator.deployment.DeploymentScenario;
import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -79,7 +80,7 @@ public void modifyCallback(
*/
@Tag(name = "Webhook", description = "Webhook APIs")
@Operation(description = "Process the execution result after terraform executes the command "
+ "line.")
+ "line to destroy service.")
@PostMapping(value = "${webhook.terraform-boot.destroyCallbackUri}/{task_id}", produces =
MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
Expand All @@ -88,7 +89,44 @@ public void destroyCallback(
@PathVariable("task_id") String taskId,
@Valid @RequestBody TerraformResult result) {

terraformDeploymentResultCallbackManager.destroyCallback(UUID.fromString(taskId), result);
terraformDeploymentResultCallbackManager.destroyCallback(UUID.fromString(taskId), result,
DeploymentScenario.DESTROY);
}


/**
* Webhook methods to receive terraform execution result.
*/
@Tag(name = "Webhook", description = "Webhook APIs")
@Operation(description = "Process the execution result after terraform executes the command "
+ "line to rollback service deployment.")
@PostMapping(value = "${webhook.terraform-boot.rollbackCallbackUri}/{task_id}", produces =
MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public void rollbackCallback(
@Parameter(name = "task_id", description = "task id")
@PathVariable("task_id") String taskId,
@Valid @RequestBody TerraformResult result) {
terraformDeploymentResultCallbackManager.destroyCallback(UUID.fromString(taskId), result,
DeploymentScenario.ROLLBACK);
}


/**
* Webhook methods to receive terraform execution result.
*/
@Tag(name = "Webhook", description = "Webhook APIs")
@Operation(description = "Process the execution result after terraform executes the command "
+ "line to purge service.")
@PostMapping(value = "${webhook.terraform-boot.purgeCallbackUri}/{task_id}", produces =
MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public void purgeCallback(
@Parameter(name = "task_id", description = "task id")
@PathVariable("task_id") String taskId,
@Valid @RequestBody TerraformResult result) {
terraformDeploymentResultCallbackManager.destroyCallback(UUID.fromString(taskId), result,
DeploymentScenario.PURGE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ private ServiceDeploymentState getServiceDeploymentState(
case DESTROY_SUCCESS, PURGE_SUCCESS -> ServiceDeploymentState.DESTROY_SUCCESS;
case DESTROY_FAILED -> ServiceDeploymentState.DESTROY_FAILED;
case ROLLBACK_FAILED -> ServiceDeploymentState.ROLLBACK_FAILED;
case MODIFYING -> ServiceDeploymentState.MODIFYING;
case MODIFYING_FAILED -> ServiceDeploymentState.MODIFYING_FAILED;
case MODIFICATION_SUCCESSFUL -> ServiceDeploymentState.MODIFICATION_SUCCESSFUL;
case MODIFICATION_FAILED -> ServiceDeploymentState.MODIFICATION_FAILED;
case INIT, PURGE_FAILED -> ServiceDeploymentState.MANUAL_CLEANUP_REQUIRED;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private void deploy(DeployTask deployTask) {
log.info("Deploy service with id:{} failed.", deployTask.getId(), e);
deployResult = new DeployResult();
deployResult.setId(deployTask.getId());
deployResult.setState(getDeploymentTaskState(deployTask.getDeploymentScenario()));
deployResult.setState(getDeployerTaskFailedState(deployTask.getDeploymentScenario()));
deployResult.setMessage(e.getMessage());
}
try {
Expand Down Expand Up @@ -258,7 +258,7 @@ public DeployTask getModifyTask(ModifyRequest modifyRequest,
if (!deployServiceEntity.getServiceDeploymentState()
.equals(ServiceDeploymentState.DEPLOY_SUCCESS)
&& !deployServiceEntity.getServiceDeploymentState()
.equals(ServiceDeploymentState.MODIFYING_FAILED)
.equals(ServiceDeploymentState.MODIFICATION_FAILED)
&& !deployServiceEntity.getServiceDeploymentState()
.equals(ServiceDeploymentState.MODIFICATION_SUCCESSFUL)) {
throw new InvalidServiceStateException(
Expand Down Expand Up @@ -302,7 +302,7 @@ public void modifyService(DeployTask modifyTask, DeployServiceEntity deployServi
log.info("Modify service with id:{} failed.", modifyTask.getId(), e);
modifyResult = new DeployResult();
modifyResult.setId(modifyTask.getId());
modifyResult.setState(getDeploymentTaskState(modifyTask.getDeploymentScenario()));
modifyResult.setState(getDeployerTaskFailedState(modifyTask.getDeploymentScenario()));
modifyResult.setMessage(e.getMessage());
}
try {
Expand Down Expand Up @@ -340,7 +340,7 @@ private void destroy(DeployTask destroyTask, DeployServiceEntity deployServiceEn
log.info("Destroy service with id:{} failed.", destroyTask.getId(), e);
destroyResult = new DeployResult();
destroyResult.setId(destroyTask.getId());
destroyResult.setState(getDeploymentTaskState(destroyTask.getDeploymentScenario()));
destroyResult.setState(getDeployerTaskFailedState(destroyTask.getDeploymentScenario()));
destroyResult.setMessage(e.getMessage());
}
try {
Expand All @@ -357,13 +357,13 @@ private void destroy(DeployTask destroyTask, DeployServiceEntity deployServiceEn
}
}

private DeployerTaskStatus getDeploymentTaskState(DeploymentScenario deploymentScenario) {
private DeployerTaskStatus getDeployerTaskFailedState(DeploymentScenario deploymentScenario) {
return switch (deploymentScenario) {
case DEPLOY -> DeployerTaskStatus.DEPLOY_FAILED;
case DESTROY -> DeployerTaskStatus.DESTROY_FAILED;
case ROLLBACK -> DeployerTaskStatus.ROLLBACK_FAILED;
case PURGE -> DeployerTaskStatus.PURGE_FAILED;
case MODIFY -> DeployerTaskStatus.MODIFYING_FAILED;
case MODIFY -> DeployerTaskStatus.MODIFICATION_FAILED;
};
}

Expand Down Expand Up @@ -454,7 +454,6 @@ public DeployTask getPurgeTask(DeployServiceEntity deployServiceEntity) {
// Get state of service.
ServiceDeploymentState state = deployServiceEntity.getServiceDeploymentState();
if (!(state == ServiceDeploymentState.DEPLOY_FAILED
|| state == ServiceDeploymentState.MODIFYING_FAILED
|| state == ServiceDeploymentState.DESTROY_SUCCESS
|| state == ServiceDeploymentState.DESTROY_FAILED
|| state == ServiceDeploymentState.ROLLBACK_FAILED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private DeployerTaskStatus getDeployerTaskStatus(
case DEPLOY -> isCommandSuccessful ? DeployerTaskStatus.DEPLOY_SUCCESS
: DeployerTaskStatus.DEPLOY_FAILED;
case MODIFY -> isCommandSuccessful ? DeployerTaskStatus.MODIFICATION_SUCCESSFUL
: DeployerTaskStatus.MODIFYING_FAILED;
: DeployerTaskStatus.MODIFICATION_FAILED;
case DESTROY -> isCommandSuccessful ? DeployerTaskStatus.DESTROY_SUCCESS
: DeployerTaskStatus.DESTROY_FAILED;
case ROLLBACK -> isCommandSuccessful ? DeployerTaskStatus.ROLLBACK_SUCCESS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ private OpenTofuAsyncDeployFromScriptsRequest getDeployFromScriptsRequest(Deploy
request.setVariables(tofuMakerHelper.getInputVariables(task, true));
request.setEnvVariables(tofuMakerHelper.getEnvironmentVariables(task));
request.setWebhookConfig(tofuMakerHelper.getWebhookConfig(task, false));
request.setDeploymentScenario(
OpenTofuAsyncDeployFromScriptsRequest.DeploymentScenarioEnum.fromValue(
task.getDeploymentScenario().toValue()));
return request;
}

Expand All @@ -99,9 +96,6 @@ private OpenTofuAsyncDeployFromGitRepoRequest getDeployFromGitRepoRequest(Deploy
tofuMakerHelper.convertOpenTofuScriptGitRepoDetailsFromDeployFromGitRepo(
task.getOcl().getDeployment().getScriptsRepo())
);
request.setDeploymentScenario(
OpenTofuAsyncDeployFromGitRepoRequest.DeploymentScenarioEnum.fromValue(
task.getDeploymentScenario().toValue()));
return request;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ private OpenTofuAsyncModifyFromScriptsRequest getModifyFromScriptsRequest(Deploy
request.setVariables(tofuMakerHelper.getInputVariables(task, false));
request.setEnvVariables(tofuMakerHelper.getEnvironmentVariables(task));
request.setWebhookConfig(tofuMakerHelper.getModifyWebhookConfig(task));
request.setDeploymentScenario(
OpenTofuAsyncModifyFromScriptsRequest.DeploymentScenarioEnum.fromValue(
task.getDeploymentScenario().toValue()));
return request;
}

Expand All @@ -112,9 +109,6 @@ private OpenTofuAsyncModifyFromGitRepoRequest getModifyFromGitRepoRequest(Deploy
request.setVariables(tofuMakerHelper.getInputVariables(task, false));
request.setEnvVariables(tofuMakerHelper.getEnvironmentVariables(task));
request.setWebhookConfig(tofuMakerHelper.getModifyWebhookConfig(task));
request.setDeploymentScenario(
OpenTofuAsyncModifyFromGitRepoRequest.DeploymentScenarioEnum.fromValue(
task.getDeploymentScenario().toValue()));
request.setGitRepoDetails(
tofuMakerHelper.convertOpenTofuScriptGitRepoDetailsFromDeployFromGitRepo(
task.getOcl().getDeployment().getScriptsRepo()));
Expand Down

0 comments on commit a185a1e

Please sign in to comment.