Skip to content

Commit

Permalink
introduce option to modify specifications of a service.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alice1319 committed Apr 2, 2024
1 parent 41c6989 commit a84a076
Show file tree
Hide file tree
Showing 16 changed files with 487 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import org.eclipse.xpanse.terraform.boot.models.plan.TerraformPlanFromDirectoryRequest;
import org.eclipse.xpanse.terraform.boot.models.request.directory.TerraformAsyncDeployFromDirectoryRequest;
import org.eclipse.xpanse.terraform.boot.models.request.directory.TerraformAsyncDestroyFromDirectoryRequest;
import org.eclipse.xpanse.terraform.boot.models.request.directory.TerraformAsyncModifyFromDirectoryRequest;
import org.eclipse.xpanse.terraform.boot.models.request.directory.TerraformDeployFromDirectoryRequest;
import org.eclipse.xpanse.terraform.boot.models.request.directory.TerraformDestroyFromDirectoryRequest;
import org.eclipse.xpanse.terraform.boot.models.request.directory.TerraformModifyFromDirectoryRequest;
import org.eclipse.xpanse.terraform.boot.models.response.TerraformResult;
import org.eclipse.xpanse.terraform.boot.models.validation.TerraformValidationResult;
import org.eclipse.xpanse.terraform.boot.terraform.service.TerraformDirectoryService;
Expand Down Expand Up @@ -101,6 +103,30 @@ public TerraformResult deployFromDirectory(
return terraformDirectoryService.deployFromDirectory(request, moduleDirectory);
}

/**
* Method to modify resources requested in a workspace.
*
* @return Returns the status of the deployment.
*/
@Tag(name = "TerraformFromDirectory", description =
"APIs for running Terraform commands inside a provided directory.")
@Operation(description = "Modify resources via Terraform from the given directory.")
@PostMapping(value = "/modify/{module_directory}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public TerraformResult modifyFromDirectory(
@Parameter(name = "module_directory",
description = "directory name where the Terraform module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody
TerraformModifyFromDirectoryRequest request,
@RequestHeader(name = "X-Custom-RequestId", required = false) UUID uuid) {
if (Objects.isNull(uuid)) {
uuid = UUID.randomUUID();
}
MDC.put("TASK_ID", uuid.toString());
return terraformDirectoryService.modifyFromDirectory(request, moduleDirectory);
}

/**
* Method to destroy resources requested in a workspace.
*
Expand Down Expand Up @@ -173,6 +199,28 @@ public void asyncDeployFromDirectory(
terraformDirectoryService.asyncDeployWithScripts(asyncDeployRequest, moduleDirectory);
}

/**
* Method to async modify resources from the given directory.
*/
@Tag(name = "TerraformFromDirectory", description =
"APIs for running Terraform commands inside a provided directory.")
@Operation(description = "async modify resources via Terraform from the given directory.")
@PostMapping(value = "/modify/async/{module_directory}", produces =
MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.ACCEPTED)
public void asyncModifyFromDirectory(
@Parameter(name = "module_directory",
description = "directory name where the Terraform module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody TerraformAsyncModifyFromDirectoryRequest asyncModifyRequest,
@RequestHeader(name = "X-Custom-RequestId", required = false) UUID uuid) {
if (Objects.isNull(uuid)) {
uuid = UUID.randomUUID();
}
MDC.put("TASK_ID", uuid.toString());
terraformDirectoryService.asyncModifyWithScripts(asyncModifyRequest, moduleDirectory);
}

/**
* Method to async destroy resources from the given directory.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import org.eclipse.xpanse.terraform.boot.models.plan.TerraformPlanFromGitRepoRequest;
import org.eclipse.xpanse.terraform.boot.models.request.git.TerraformAsyncDeployFromGitRepoRequest;
import org.eclipse.xpanse.terraform.boot.models.request.git.TerraformAsyncDestroyFromGitRepoRequest;
import org.eclipse.xpanse.terraform.boot.models.request.git.TerraformAsyncModifyFromGitRepoRequest;
import org.eclipse.xpanse.terraform.boot.models.request.git.TerraformDeployFromGitRepoRequest;
import org.eclipse.xpanse.terraform.boot.models.request.git.TerraformDestroyFromGitRepoRequest;
import org.eclipse.xpanse.terraform.boot.models.request.git.TerraformModifyFromGitRepoRequest;
import org.eclipse.xpanse.terraform.boot.models.response.TerraformResult;
import org.eclipse.xpanse.terraform.boot.models.validation.TerraformValidationResult;
import org.eclipse.xpanse.terraform.boot.terraform.service.TerraformGitRepoService;
Expand Down Expand Up @@ -110,6 +112,27 @@ public TerraformResult deployFromGitRepo(
return terraformGitRepoService.deployFromGitRepo(request, uuid);
}

/**
* Method to modify resources using scripts from the GIT Repo provided.
*
* @return Returns the status of the deployment.
*/
@Tag(name = "TerraformFromGitRepo", description =
"APIs for running Terraform commands using Terraform scripts from a GIT Repo.")
@Operation(description = "Modify resources via Terraform")
@PostMapping(value = "/modify", produces =
MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public TerraformResult modifyFromGitRepo(
@Valid @RequestBody TerraformModifyFromGitRepoRequest request,
@RequestHeader(name = "X-Custom-RequestId", required = false) UUID uuid) {
if (Objects.isNull(uuid)) {
uuid = UUID.randomUUID();
}
MDC.put("TASK_ID", uuid.toString());
return terraformGitRepoService.modifyFromGitRepo(request, uuid);
}

/**
* MMethod to deploy resources using scripts from the GIT Repo provided.
*
Expand Down Expand Up @@ -150,6 +173,25 @@ public void asyncDeployFromGitRepo(
terraformGitRepoService.asyncDeployFromGitRepo(asyncDeployRequest, uuid);
}

/**
* Method to async modify resources from the provided GIT Repo.
*/
@Tag(name = "TerraformFromGitRepo", description =
"APIs for running Terraform commands using Terraform scripts from a GIT Repo.")
@Operation(description = "async deploy resources via Terraform")
@PostMapping(value = "/modify/async", produces =
MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.ACCEPTED)
public void asyncModifyFromGitRepo(
@Valid @RequestBody TerraformAsyncModifyFromGitRepoRequest asyncModifyRequest,
@RequestHeader(name = "X-Custom-RequestId", required = false) UUID uuid) {
if (Objects.isNull(uuid)) {
uuid = UUID.randomUUID();
}
MDC.put("TASK_ID", uuid.toString());
terraformGitRepoService.asyncModifyFromGitRepo(asyncModifyRequest, uuid);
}

/**
* Method to async destroy resources by scripts.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import org.eclipse.xpanse.terraform.boot.models.plan.TerraformPlanWithScriptsRequest;
import org.eclipse.xpanse.terraform.boot.models.request.scripts.TerraformAsyncDeployFromScriptsRequest;
import org.eclipse.xpanse.terraform.boot.models.request.scripts.TerraformAsyncDestroyFromScriptsRequest;
import org.eclipse.xpanse.terraform.boot.models.request.scripts.TerraformAsyncModifyFromScriptsRequest;
import org.eclipse.xpanse.terraform.boot.models.request.scripts.TerraformDeployWithScriptsRequest;
import org.eclipse.xpanse.terraform.boot.models.request.scripts.TerraformDestroyWithScriptsRequest;
import org.eclipse.xpanse.terraform.boot.models.request.scripts.TerraformModifyWithScriptsRequest;
import org.eclipse.xpanse.terraform.boot.models.response.TerraformResult;
import org.eclipse.xpanse.terraform.boot.models.validation.TerraformValidationResult;
import org.eclipse.xpanse.terraform.boot.terraform.service.TerraformScriptsService;
Expand Down Expand Up @@ -89,6 +91,27 @@ public TerraformResult deployWithScripts(
return terraformScriptsService.deployWithScripts(request, uuid);
}

/**
* Method to modify resources by scripts.
*
* @return Returns the status of the deployment.
*/
@Tag(name = "TerraformFromScripts", description =
"APIs for running Terraform commands on the scripts sent via request body.")
@Operation(description = "Modify resources via Terraform")
@PostMapping(value = "/modify", produces =
MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public TerraformResult modifyWithScripts(
@Valid @RequestBody TerraformModifyWithScriptsRequest request,
@RequestHeader(name = "X-Custom-RequestId", required = false) UUID uuid) {
if (Objects.isNull(uuid)) {
uuid = UUID.randomUUID();
}
MDC.put("TASK_ID", uuid.toString());
return terraformScriptsService.modifyWithScripts(request, uuid);
}

/**
* Method to destroy resources by scripts.
*
Expand Down Expand Up @@ -129,6 +152,25 @@ public void asyncDeployWithScripts(
terraformScriptsService.asyncDeployWithScripts(asyncDeployRequest, uuid);
}

/**
* Method to async modify resources by scripts.
*/
@Tag(name = "TerraformFromScripts", description =
"APIs for running Terraform commands on the scripts sent via request body.")
@Operation(description = "async modify resources via Terraform")
@PostMapping(value = "/modify/async", produces =
MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.ACCEPTED)
public void asyncModifyWithScripts(
@Valid @RequestBody TerraformAsyncModifyFromScriptsRequest asyncModifyRequest,
@RequestHeader(name = "X-Custom-RequestId", required = false) UUID uuid) {
if (Objects.isNull(uuid)) {
uuid = UUID.randomUUID();
}
MDC.put("TASK_ID", uuid.toString());
terraformScriptsService.asyncModifyWithScripts(asyncModifyRequest, uuid);
}

/**
* Method to async destroy resources by scripts.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,37 @@
import org.eclipse.xpanse.terraform.boot.models.exceptions.UnsupportedEnumValueException;

/**
* Destroy Scenario. The destroy scenario is used to set into TerraformResult and sent back to the
* client which sent the destroy request in what scenario.
* The deployment scenario is used to set into TerraformResult and sent back to the
* client which sent the deployment request in what scenario.
*/
public enum DestroyScenario {
public enum DeploymentScenario {
DEPLOY("deploy"),
MODIFY("modify"),
DESTROY("destroy"),
ROLLBACK("rollback"),
PURGE("purge");
private final String scenario;

DestroyScenario(String scenario) {
DeploymentScenario(String scenario) {
this.scenario = scenario;
}

/**
* For DestroyScenario deserialize.
* For DeploymentScenario deserialize.
*/
@JsonCreator
public static DestroyScenario getByValue(String scenario) {
for (DestroyScenario destroyScenario : values()) {
if (StringUtils.equalsIgnoreCase(destroyScenario.scenario, scenario)) {
return destroyScenario;
public static DeploymentScenario getByValue(String scenario) {
for (DeploymentScenario deploymentScenario : values()) {
if (StringUtils.equalsIgnoreCase(deploymentScenario.scenario, scenario)) {
return deploymentScenario;
}
}
throw new UnsupportedEnumValueException(
String.format("DestroyScenario value %s is not supported.", scenario));
String.format("DeploymentScenario value %s is not supported.", scenario));
}

/**
* For DestroyScenario serialize.
* For DeploymentScenario serialize.
*/
@JsonValue
public String toValue() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*/

package org.eclipse.xpanse.terraform.boot.models.request.directory;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.eclipse.xpanse.terraform.boot.models.request.webhook.WebhookConfig;

/**
* Data model for the terraform async modify requests.
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class TerraformAsyncModifyFromDirectoryRequest extends TerraformModifyFromDirectoryRequest {

@NotNull
@Schema(description = "Configuration information of webhook.")
private WebhookConfig webhookConfig;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.HashMap;
import java.util.Map;
import lombok.Data;
import org.eclipse.xpanse.terraform.boot.models.enums.DeploymentScenario;

/**
* Data model for the terraform deploy requests.
Expand All @@ -19,9 +20,16 @@ public class TerraformDeployFromDirectoryRequest {

@NotNull
@Schema(description = "Flag to control if the deployment must only generate the terraform "
+ "or it must also apply the changes.")
+ "or it must also apply the changes.")
Boolean isPlanOnly;

@Schema(description = "This value can be set by the client if they wish to know the type of"
+ "request for which the callback response is generated from terraform-boot. There will"
+ "be no difference in the way request is executed. This information is only set in"
+ "the callback response again for the client to handle the callback response"
+ "accordingly.")
DeploymentScenario deploymentScenario;

@NotNull
@Schema(description = "Key-value pairs of variables that must be used to execute the "
+ "Terraform request.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
import java.util.HashMap;
import java.util.Map;
import lombok.Data;
import org.eclipse.xpanse.terraform.boot.models.enums.DestroyScenario;
import org.eclipse.xpanse.terraform.boot.models.enums.DeploymentScenario;

/**
* Data model for the terraform destroy requests.
*/
@Data
public class TerraformDestroyFromDirectoryRequest {

@Schema(description = "The destroy scenario when the Xpanse client send the destroy request. "
+ "Valid values: destroy,rollback,purge.")
DestroyScenario destroyScenario;
@Schema(description = "This value can be set by the client if they wish to know the type of"
+ "request for which the callback response is generated from terraform-boot. There will"
+ "be no difference in the way request is executed. This information is only set in"
+ "the callback response again for the client to handle the callback response"
+ "accordingly.")
DeploymentScenario deploymentScenario;

@NotNull
@Schema(description = "Key-value pairs of regular variables that must be used to execute the "
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*/

package org.eclipse.xpanse.terraform.boot.models.request.directory;

import static io.swagger.v3.oas.annotations.media.Schema.AdditionalPropertiesValue.TRUE;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.Map;
import lombok.Data;
import org.eclipse.xpanse.terraform.boot.models.enums.DeploymentScenario;

/**
* Data model for the terraform modify requests.
*/
@Data
public class TerraformModifyFromDirectoryRequest {
@NotNull
@Schema(description = "Flag to control if the deployment must only generate the terraform "
+ "or it must also apply the changes.")
Boolean isPlanOnly;

@Schema(description = "This value can be set by the client if they wish to know the type of"
+ "request for which the callback response is generated from terraform-boot. There will"
+ "be no difference in the way request is executed. This information is only set in"
+ "the callback response again for the client to handle the callback response"
+ "accordingly.")
DeploymentScenario deploymentScenario;

@NotNull
@Schema(description = "Key-value pairs of regular variables that must be used to execute the "
+ "Terraform request.", additionalProperties = TRUE)
Map<String, Object> variables;

@Schema(description = "Key-value pairs of variables that must be injected as environment "
+ "variables to terraform process.", additionalProperties = TRUE)
Map<String, String> envVariables = new HashMap<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*/

package org.eclipse.xpanse.terraform.boot.models.request.git;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.eclipse.xpanse.terraform.boot.models.request.webhook.WebhookConfig;

/**
* Data model for terraform async modify requests using scripts from a GIT Repo.
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class TerraformAsyncModifyFromGitRepoRequest extends TerraformModifyFromGitRepoRequest {

@NotNull
@Schema(description = "Configuration information of webhook.")
private WebhookConfig webhookConfig;
}
Loading

0 comments on commit a84a076

Please sign in to comment.