5
5
6
6
package org .eclipse .xpanse .terraform .boot .api .controllers ;
7
7
8
+ import static org .eclipse .xpanse .terraform .boot .logging .CustomRequestIdGenerator .REQUEST_ID ;
9
+
8
10
import io .swagger .v3 .oas .annotations .Operation ;
9
11
import io .swagger .v3 .oas .annotations .tags .Tag ;
10
12
import jakarta .validation .Valid ;
29
31
import org .springframework .web .bind .annotation .DeleteMapping ;
30
32
import org .springframework .web .bind .annotation .PostMapping ;
31
33
import org .springframework .web .bind .annotation .RequestBody ;
32
- import org .springframework .web .bind .annotation .RequestHeader ;
33
34
import org .springframework .web .bind .annotation .RequestMapping ;
34
35
import org .springframework .web .bind .annotation .ResponseStatus ;
35
36
import org .springframework .web .bind .annotation .RestController ;
@@ -61,12 +62,11 @@ public TerraformBootFromGitRepoApi(TerraformGitRepoService terraformGitRepoServi
61
62
MediaType .APPLICATION_JSON_VALUE )
62
63
@ ResponseStatus (HttpStatus .OK )
63
64
public TerraformValidationResult validateScriptsFromGitRepo (
64
- @ Valid @ RequestBody TerraformDeployFromGitRepoRequest request ,
65
- @ RequestHeader (name = "X-Custom-RequestId" , required = false ) UUID uuid ) {
66
- if (Objects .isNull (uuid )) {
67
- uuid = UUID .randomUUID ();
68
- }
69
- MDC .put ("TASK_ID" , uuid .toString ());
65
+ @ Valid @ RequestBody TerraformDeployFromGitRepoRequest request ) {
66
+ UUID uuid = Objects .nonNull (request .getRequestId ())
67
+ ? request .getRequestId () : UUID .randomUUID ();
68
+ MDC .put (REQUEST_ID , uuid .toString ());
69
+ request .setRequestId (uuid );
70
70
return terraformGitRepoService .validateWithScripts (request );
71
71
}
72
72
@@ -82,12 +82,11 @@ public TerraformValidationResult validateScriptsFromGitRepo(
82
82
@ PostMapping (value = "/plan" , produces = MediaType .APPLICATION_JSON_VALUE )
83
83
@ ResponseStatus (HttpStatus .OK )
84
84
public TerraformPlan planFromGitRepo (
85
- @ Valid @ RequestBody TerraformPlanFromGitRepoRequest request ,
86
- @ RequestHeader (name = "X-Custom-RequestId" , required = false ) UUID uuid ) {
87
- if (Objects .isNull (uuid )) {
88
- uuid = UUID .randomUUID ();
89
- }
90
- MDC .put ("TASK_ID" , uuid .toString ());
85
+ @ Valid @ RequestBody TerraformPlanFromGitRepoRequest request ) {
86
+ UUID uuid = Objects .nonNull (request .getRequestId ())
87
+ ? request .getRequestId () : UUID .randomUUID ();
88
+ MDC .put (REQUEST_ID , uuid .toString ());
89
+ request .setRequestId (uuid );
91
90
return terraformGitRepoService .getTerraformPlanFromGitRepo (request , uuid );
92
91
}
93
92
@@ -103,12 +102,11 @@ public TerraformPlan planFromGitRepo(
103
102
MediaType .APPLICATION_JSON_VALUE )
104
103
@ ResponseStatus (HttpStatus .OK )
105
104
public TerraformResult deployFromGitRepo (
106
- @ Valid @ RequestBody TerraformDeployFromGitRepoRequest request ,
107
- @ RequestHeader (name = "X-Custom-RequestId" , required = false ) UUID uuid ) {
108
- if (Objects .isNull (uuid )) {
109
- uuid = UUID .randomUUID ();
110
- }
111
- MDC .put ("TASK_ID" , uuid .toString ());
105
+ @ Valid @ RequestBody TerraformDeployFromGitRepoRequest request ) {
106
+ UUID uuid = Objects .nonNull (request .getRequestId ())
107
+ ? request .getRequestId () : UUID .randomUUID ();
108
+ MDC .put (REQUEST_ID , uuid .toString ());
109
+ request .setRequestId (uuid );
112
110
return terraformGitRepoService .deployFromGitRepo (request , uuid );
113
111
}
114
112
@@ -124,12 +122,11 @@ public TerraformResult deployFromGitRepo(
124
122
MediaType .APPLICATION_JSON_VALUE )
125
123
@ ResponseStatus (HttpStatus .OK )
126
124
public TerraformResult modifyFromGitRepo (
127
- @ Valid @ RequestBody TerraformModifyFromGitRepoRequest request ,
128
- @ RequestHeader (name = "X-Custom-RequestId" , required = false ) UUID uuid ) {
129
- if (Objects .isNull (uuid )) {
130
- uuid = UUID .randomUUID ();
131
- }
132
- MDC .put ("TASK_ID" , uuid .toString ());
125
+ @ Valid @ RequestBody TerraformModifyFromGitRepoRequest request ) {
126
+ UUID uuid = Objects .nonNull (request .getRequestId ())
127
+ ? request .getRequestId () : UUID .randomUUID ();
128
+ MDC .put (REQUEST_ID , uuid .toString ());
129
+ request .setRequestId (uuid );
133
130
return terraformGitRepoService .modifyFromGitRepo (request , uuid );
134
131
}
135
132
@@ -145,12 +142,11 @@ public TerraformResult modifyFromGitRepo(
145
142
MediaType .APPLICATION_JSON_VALUE )
146
143
@ ResponseStatus (HttpStatus .OK )
147
144
public TerraformResult destroyFromGitRepo (
148
- @ Valid @ RequestBody TerraformDestroyFromGitRepoRequest request ,
149
- @ RequestHeader (name = "X-Custom-RequestId" , required = false ) UUID uuid ) {
150
- if (Objects .isNull (uuid )) {
151
- uuid = UUID .randomUUID ();
152
- }
153
- MDC .put ("TASK_ID" , uuid .toString ());
145
+ @ Valid @ RequestBody TerraformDestroyFromGitRepoRequest request ) {
146
+ UUID uuid = Objects .nonNull (request .getRequestId ())
147
+ ? request .getRequestId () : UUID .randomUUID ();
148
+ MDC .put (REQUEST_ID , uuid .toString ());
149
+ request .setRequestId (uuid );
154
150
return terraformGitRepoService .destroyFromGitRepo (request , uuid );
155
151
}
156
152
@@ -164,13 +160,12 @@ public TerraformResult destroyFromGitRepo(
164
160
MediaType .APPLICATION_JSON_VALUE )
165
161
@ ResponseStatus (HttpStatus .ACCEPTED )
166
162
public void asyncDeployFromGitRepo (
167
- @ Valid @ RequestBody TerraformAsyncDeployFromGitRepoRequest asyncDeployRequest ,
168
- @ RequestHeader (name = "X-Custom-RequestId" , required = false ) UUID uuid ) {
169
- if (Objects .isNull (uuid )) {
170
- uuid = UUID .randomUUID ();
171
- }
172
- MDC .put ("TASK_ID" , uuid .toString ());
173
- terraformGitRepoService .asyncDeployFromGitRepo (asyncDeployRequest , uuid );
163
+ @ Valid @ RequestBody TerraformAsyncDeployFromGitRepoRequest request ) {
164
+ UUID uuid = Objects .nonNull (request .getRequestId ())
165
+ ? request .getRequestId () : UUID .randomUUID ();
166
+ MDC .put (REQUEST_ID , uuid .toString ());
167
+ request .setRequestId (uuid );
168
+ terraformGitRepoService .asyncDeployFromGitRepo (request , uuid );
174
169
}
175
170
176
171
/**
@@ -183,13 +178,12 @@ public void asyncDeployFromGitRepo(
183
178
MediaType .APPLICATION_JSON_VALUE )
184
179
@ ResponseStatus (HttpStatus .ACCEPTED )
185
180
public void asyncModifyFromGitRepo (
186
- @ Valid @ RequestBody TerraformAsyncModifyFromGitRepoRequest asyncModifyRequest ,
187
- @ RequestHeader (name = "X-Custom-RequestId" , required = false ) UUID uuid ) {
188
- if (Objects .isNull (uuid )) {
189
- uuid = UUID .randomUUID ();
190
- }
191
- MDC .put ("TASK_ID" , uuid .toString ());
192
- terraformGitRepoService .asyncModifyFromGitRepo (asyncModifyRequest , uuid );
181
+ @ Valid @ RequestBody TerraformAsyncModifyFromGitRepoRequest request ) {
182
+ UUID uuid = Objects .nonNull (request .getRequestId ())
183
+ ? request .getRequestId () : UUID .randomUUID ();
184
+ MDC .put (REQUEST_ID , uuid .toString ());
185
+ request .setRequestId (uuid );
186
+ terraformGitRepoService .asyncModifyFromGitRepo (request , uuid );
193
187
}
194
188
195
189
/**
@@ -202,12 +196,11 @@ public void asyncModifyFromGitRepo(
202
196
produces = MediaType .APPLICATION_JSON_VALUE )
203
197
@ ResponseStatus (HttpStatus .ACCEPTED )
204
198
public void asyncDestroyFromGitRepo (
205
- @ Valid @ RequestBody TerraformAsyncDestroyFromGitRepoRequest asyncDestroyRequest ,
206
- @ RequestHeader (name = "X-Custom-RequestId" , required = false ) UUID uuid ) {
207
- if (Objects .isNull (uuid )) {
208
- uuid = UUID .randomUUID ();
209
- }
210
- MDC .put ("TASK_ID" , uuid .toString ());
211
- terraformGitRepoService .asyncDestroyFromGitRepo (asyncDestroyRequest , uuid );
199
+ @ Valid @ RequestBody TerraformAsyncDestroyFromGitRepoRequest request ) {
200
+ UUID uuid = Objects .nonNull (request .getRequestId ())
201
+ ? request .getRequestId () : UUID .randomUUID ();
202
+ MDC .put (REQUEST_ID , uuid .toString ());
203
+ request .setRequestId (uuid );
204
+ terraformGitRepoService .asyncDestroyFromGitRepo (request , uuid );
212
205
}
213
206
}
0 commit comments