[UPDATE] CreateRunRequest DTO와 PipelineUploadService 리팩토링 및 WebClient로 Run 생성 로직 변경

main
bjkim 9 months ago
parent eb2e430669
commit 2cf4c84860

@ -76,18 +76,22 @@ public class PipelineUploadController {
}
@PostMapping("/runs")
@Operation(summary = "Kubeflow Run 생성", description = "Kubeflow에 Run을 생성합니다.")
@Operation(
summary = "Kubeflow Run 생성",
description = "Kubeflow에 Run을 생성합니다."
)
@ApiResponses({
@ApiResponse(responseCode = "200", description = "Run 생성 성공"),
@ApiResponse(responseCode = "400", description = "display_name 필수"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
public ResponseEntity<Map<String, Object>> createRun(
@Parameter @RequestBody CreateRunRequest runRequest
@RequestBody CreateRunRequest runRequest
) {
try {
Map<String, Object> result = pipelineUploadService.createRun(runRequest);
return ResponseEntity.ok(result);
} catch (IllegalArgumentException e) {
log.error("Invalid run request", e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
@ -96,6 +100,7 @@ public class PipelineUploadController {
"error", "Bad Request",
"message", e.getMessage()
));
} catch (Exception e) {
log.error("Run creation failed", e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)

@ -1,41 +1,54 @@
package kr.re.etri.autoflow.payload.request;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import lombok.*;
import java.util.Map;
@Data
@Schema(description = "Kubeflow Run 생성 요청 DTO")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Schema(description = "Kubeflow Run 생성 요청")
public class CreateRunRequest {
@Schema(description = "Run 이름 (필수)", required = true, example = "Run of 435345 (5c7b9)")
@Schema(description = "Run 이름 (필수)", example = "Run of 435345 (5c7b9)")
private String display_name;
@Schema(description = "Run 설명", example = "테스트 Run")
private String description;
@Schema(description = "파이프라인 버전 참조", required = true)
@Schema(description = "Pipeline Version Reference")
private PipelineVersionReference pipeline_version_reference;
@Schema(description = "런 타임 구성")
@Schema(description = "Run Runtime Config")
private RuntimeConfig runtime_config;
@Schema(description = "서비스 계정", example = "pipeline-runner")
private String service_account;
@Data
@Schema(description = "Pipeline Version Reference")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Schema(description = "Pipeline 버전 참조")
public static class PipelineVersionReference {
@Schema(description = "파이프라인 ID", required = true)
@Schema(description = "Pipeline ID", example = "e701e230-9bc2-4104-819a-a59ff7501d69")
private String pipeline_id;
@Schema(description = "파이프라인 버전 ID", required = true)
@Schema(description = "Pipeline Version ID", example = "cab9f077-7acd-4f68-a844-5aa9bb5635df")
private String pipeline_version_id;
}
@Data
@Schema(description = "Runtime Config")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Schema(description = "Run Runtime Config")
public static class RuntimeConfig {
@Schema(description = "파라미터", example = "{}")
private Map<String, Object> parameters;

@ -14,7 +14,10 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Mono;
import java.io.IOException;
import java.util.Map;
@ -29,6 +32,9 @@ public class PipelineUploadService {
@Value("${kubeflow.url}")
private String kubeflowBaseUrl; // 예: http://192.168.10.135:32473/
private final WebClient webClient;
/**
* Pipeline
*/
@ -65,26 +71,21 @@ public class PipelineUploadService {
* Run
* runRequest display_name, pipeline_version_reference, runtime_config
*/
// PipelineUploadService.java
public Map<String, Object> createRun(CreateRunRequest runRequest) {
try {
// URL 조립
String url = kubeflowBaseUrl + "apis/v2beta1/runs";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
// DTO를 Map으로 변환해서 전송
ObjectMapper objectMapper = new ObjectMapper();
Map body = objectMapper.convertValue(runRequest, Map.class);
HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(body, headers);
ResponseEntity<Map> response = restTemplate.postForEntity(url, requestEntity, Map.class);
if (runRequest.getDisplay_name() == null || runRequest.getDisplay_name().isBlank()) {
throw new IllegalArgumentException("Run display_name cannot be empty");
}
return response.getBody();
try {
Mono<Map> responseMono = webClient.post()
.uri(kubeflowBaseUrl + "/apis/v2beta1/runs")
.contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromValue(runRequest))
.retrieve()
.bodyToMono(Map.class);
return responseMono.block(); // 동기 호출
} catch (Exception e) {
if (e instanceof IllegalArgumentException) throw e;
throw new RuntimeException("Kubeflow Run creation failed", e);
}
}

Loading…
Cancel
Save