|
|
|
|
package kr.re.etri.autoflow.controllers;
|
|
|
|
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
import kr.re.etri.autoflow.service.PipelineUploadService;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.client.HttpClientErrorException;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/pipelines")
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@CrossOrigin(origins = "*") // 모든 도메인 허용
|
|
|
|
|
@io.swagger.v3.oas.annotations.tags.Tag(name = "Kubeflow Pipeline", description = "Kubeflow 파이프라인 업로드 API")
|
|
|
|
|
public class PipelineUploadController {
|
|
|
|
|
|
|
|
|
|
private final PipelineUploadService pipelineUploadService;
|
|
|
|
|
|
|
|
|
|
@io.swagger.v3.oas.annotations.Operation(
|
|
|
|
|
summary = "파이프라인 업로드",
|
|
|
|
|
description = "Kubeflow에 파이프라인 파일(Multipart)을 업로드하고, 업로드 결과를 반환합니다."
|
|
|
|
|
)
|
|
|
|
|
@io.swagger.v3.oas.annotations.responses.ApiResponses({
|
|
|
|
|
@io.swagger.v3.oas.annotations.responses.ApiResponse(
|
|
|
|
|
responseCode = "200",
|
|
|
|
|
description = "파이프라인 업로드 성공"
|
|
|
|
|
),
|
|
|
|
|
@io.swagger.v3.oas.annotations.responses.ApiResponse(
|
|
|
|
|
responseCode = "400",
|
|
|
|
|
description = "잘못된 요청"
|
|
|
|
|
),
|
|
|
|
|
@io.swagger.v3.oas.annotations.responses.ApiResponse(
|
|
|
|
|
responseCode = "500",
|
|
|
|
|
description = "서버 내부 오류"
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
|
|
public ResponseEntity<Map<String, Object>> uploadPipeline(
|
|
|
|
|
@io.swagger.v3.oas.annotations.Parameter(description = "업로드할 파이프라인 파일", required = true)
|
|
|
|
|
@RequestParam("uploadfile") MultipartFile file,
|
|
|
|
|
|
|
|
|
|
@io.swagger.v3.oas.annotations.Parameter(description = "파이프라인 이름", required = true)
|
|
|
|
|
@RequestParam(value = "name", required = false) String name,
|
|
|
|
|
|
|
|
|
|
@io.swagger.v3.oas.annotations.Parameter(description = "표시 이름", required = true)
|
|
|
|
|
@RequestParam(value = "display_name", required = false) String displayName,
|
|
|
|
|
|
|
|
|
|
@io.swagger.v3.oas.annotations.Parameter(description = "파이프라인 설명", required = false)
|
|
|
|
|
@RequestParam(value = "description", required = false) String description,
|
|
|
|
|
|
|
|
|
|
@io.swagger.v3.oas.annotations.Parameter(description = "Kubeflow 네임스페이스", required = false)
|
|
|
|
|
@RequestParam(value = "namespace", required = false) String namespace
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
Map<String, Object> result = pipelineUploadService.uploadPipeline(file, name, displayName, description, namespace);
|
|
|
|
|
return ResponseEntity.ok(result);
|
|
|
|
|
|
|
|
|
|
} catch (HttpClientErrorException e) {
|
|
|
|
|
log.error("Kubeflow API Error: status={}, response={}", e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
|
|
|
|
|
Map<String, Object> error = new HashMap<>();
|
|
|
|
|
error.put("status", e.getStatusCode().value());
|
|
|
|
|
error.put("error", e.getStatusText());
|
|
|
|
|
error.put("message", e.getResponseBodyAsString());
|
|
|
|
|
return ResponseEntity.status(e.getStatusCode()).body(error);
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("Pipeline upload failed", e);
|
|
|
|
|
|
|
|
|
|
Map<String, Object> error = new HashMap<>();
|
|
|
|
|
error.put("status", 500);
|
|
|
|
|
error.put("error", "Internal Server Error");
|
|
|
|
|
error.put("message", e.getMessage());
|
|
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|