Skip to content

Commit

Permalink
Add UUID to record the request (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
baixinsui authored May 22, 2024
1 parent 7ef1475 commit 32c3835
Show file tree
Hide file tree
Showing 17 changed files with 267 additions and 179 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<description>RESTful API Wrapper for OpenTofu</description>
<properties>
<java.version>21</java.version>
<spring.retry.version>2.0.5</spring.retry.version>
<springdoc.version>2.5.0</springdoc.version>
<checkstyle-maven-plugin.version>3.3.1</checkstyle-maven-plugin.version>
<logbook.version>3.8.0</logbook.version>
Expand Down Expand Up @@ -105,6 +106,11 @@
<artifactId>org.eclipse.jgit</artifactId>
<version>${jgit.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>${spring.retry.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableAsync;

/**
* Main entry class to tofu-maker. This class can be directly executed to start the server.
*/
@EnableRetry
@EnableAsync
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
public class OpenTofuMakerApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package org.eclipse.xpanse.tofu.maker.api.controllers;

import static org.eclipse.xpanse.tofu.maker.logging.CustomRequestIdGenerator.REQUEST_ID;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -34,7 +36,6 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -70,12 +71,9 @@ public OpenTofuMakerFromDirectoryApi(
public OpenTofuValidationResult validateFromDirectory(
@Parameter(name = "module_directory",
description = "directory name where the OpenTofu module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@RequestHeader(name = "X-Custom-RequestId", required = false) UUID uuid) {
if (Objects.isNull(uuid)) {
uuid = UUID.randomUUID();
}
MDC.put("TASK_ID", uuid.toString());
@PathVariable("module_directory") String moduleDirectory) {
UUID uuid = UUID.randomUUID();
MDC.put(REQUEST_ID, uuid.toString());
return openTofuDirectoryService.tfValidateFromDirectory(moduleDirectory);
}

Expand All @@ -93,13 +91,11 @@ public OpenTofuResult deployFromDirectory(
@Parameter(name = "module_directory",
description = "directory name where the OpenTofu module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody
OpenTofuDeployFromDirectoryRequest request,
@RequestHeader(name = "X-Custom-RequestId", required = false) UUID uuid) {
if (Objects.isNull(uuid)) {
uuid = UUID.randomUUID();
}
MDC.put("TASK_ID", uuid.toString());
@Valid @RequestBody OpenTofuDeployFromDirectoryRequest request) {
UUID uuid = Objects.nonNull(request.getRequestId())
? request.getRequestId() : UUID.randomUUID();
MDC.put(REQUEST_ID, uuid.toString());
request.setRequestId(uuid);
return openTofuDirectoryService.deployFromDirectory(request, moduleDirectory);
}

Expand All @@ -117,13 +113,11 @@ public OpenTofuResult modifyFromDirectory(
@Parameter(name = "module_directory",
description = "directory name where the OpenTofu module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody
OpenTofuModifyFromDirectoryRequest request,
@RequestHeader(name = "X-Custom-RequestId", required = false) UUID uuid) {
if (Objects.isNull(uuid)) {
uuid = UUID.randomUUID();
}
MDC.put("TASK_ID", uuid.toString());
@Valid @RequestBody OpenTofuModifyFromDirectoryRequest request) {
UUID uuid = Objects.nonNull(request.getRequestId())
? request.getRequestId() : UUID.randomUUID();
MDC.put(REQUEST_ID, uuid.toString());
request.setRequestId(uuid);
return openTofuDirectoryService.modifyFromDirectory(request, moduleDirectory);
}

Expand All @@ -143,12 +137,11 @@ public OpenTofuResult destroyFromDirectory(
description = "directory name where the OpenTofu module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody
OpenTofuDestroyFromDirectoryRequest request,
@RequestHeader(name = "X-Custom-RequestId", required = false) UUID uuid) {
if (Objects.isNull(uuid)) {
uuid = UUID.randomUUID();
}
MDC.put("TASK_ID", uuid.toString());
OpenTofuDestroyFromDirectoryRequest request) {
UUID uuid = Objects.nonNull(request.getRequestId())
? request.getRequestId() : UUID.randomUUID();
MDC.put(REQUEST_ID, uuid.toString());
request.setRequestId(uuid);
return openTofuDirectoryService.destroyFromDirectory(request, moduleDirectory);
}

Expand All @@ -167,12 +160,11 @@ public OpenTofuPlan plan(
@Parameter(name = "module_directory",
description = "directory name where the OpenTofu module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody OpenTofuPlanFromDirectoryRequest request,
@RequestHeader(name = "X-Custom-RequestId", required = false) UUID uuid) {
if (Objects.isNull(uuid)) {
uuid = UUID.randomUUID();
}
MDC.put("TASK_ID", uuid.toString());
@Valid @RequestBody OpenTofuPlanFromDirectoryRequest request) {
UUID uuid = Objects.nonNull(request.getRequestId())
? request.getRequestId() : UUID.randomUUID();
MDC.put(REQUEST_ID, uuid.toString());
request.setRequestId(uuid);
return openTofuDirectoryService.getOpenTofuPlanFromDirectory(request,
moduleDirectory);
}
Expand All @@ -190,13 +182,12 @@ public void asyncDeployFromDirectory(
@Parameter(name = "module_directory",
description = "directory name where the OpenTofu module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody OpenTofuAsyncDeployFromDirectoryRequest asyncDeployRequest,
@RequestHeader(name = "X-Custom-RequestId", required = false) UUID uuid) {
if (Objects.isNull(uuid)) {
uuid = UUID.randomUUID();
}
MDC.put("TASK_ID", uuid.toString());
openTofuDirectoryService.asyncDeployWithScripts(asyncDeployRequest, moduleDirectory);
@Valid @RequestBody OpenTofuAsyncDeployFromDirectoryRequest request) {
UUID uuid = Objects.nonNull(request.getRequestId())
? request.getRequestId() : UUID.randomUUID();
MDC.put(REQUEST_ID, uuid.toString());
request.setRequestId(uuid);
openTofuDirectoryService.asyncDeployWithScripts(request, moduleDirectory);
}

/**
Expand All @@ -212,13 +203,12 @@ public void asyncModifyFromDirectory(
@Parameter(name = "module_directory",
description = "directory name where the OpenTofu module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody OpenTofuAsyncModifyFromDirectoryRequest asyncModifyRequest,
@RequestHeader(name = "X-Custom-RequestId", required = false) UUID uuid) {
if (Objects.isNull(uuid)) {
uuid = UUID.randomUUID();
}
MDC.put("TASK_ID", uuid.toString());
openTofuDirectoryService.asyncModifyWithScripts(asyncModifyRequest, moduleDirectory);
@Valid @RequestBody OpenTofuAsyncModifyFromDirectoryRequest request) {
UUID uuid = Objects.nonNull(request.getRequestId())
? request.getRequestId() : UUID.randomUUID();
MDC.put(REQUEST_ID, uuid.toString());
request.setRequestId(uuid);
openTofuDirectoryService.asyncModifyWithScripts(request, moduleDirectory);
}

/**
Expand All @@ -234,12 +224,11 @@ public void asyncDestroyFromDirectory(
@Parameter(name = "module_directory",
description = "directory name where the OpenTofu module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody OpenTofuAsyncDestroyFromDirectoryRequest asyncDestroyRequest,
@RequestHeader(name = "X-Custom-RequestId", required = false) UUID uuid) {
if (Objects.isNull(uuid)) {
uuid = UUID.randomUUID();
}
MDC.put("TASK_ID", uuid.toString());
openTofuDirectoryService.asyncDestroyWithScripts(asyncDestroyRequest, moduleDirectory);
@Valid @RequestBody OpenTofuAsyncDestroyFromDirectoryRequest request) {
UUID uuid = Objects.nonNull(request.getRequestId())
? request.getRequestId() : UUID.randomUUID();
MDC.put(REQUEST_ID, uuid.toString());
request.setRequestId(uuid);
openTofuDirectoryService.asyncDestroyWithScripts(request, moduleDirectory);
}
}
Loading

0 comments on commit 32c3835

Please sign in to comment.