You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
autoflow-server-mgmt/src/main/java/kr/re/etri/autoflow/controllers/PipelineUploadController.java

93 lines
3.8 KiB

package kr.re.etri.autoflow.controllers;
import io.swagger.v3.oas.annotations.tags.Tag;
import kr.re.etri.autoflow.entity.WorkflowEntity;
import kr.re.etri.autoflow.service.PipelineUploadService;
import kr.re.etri.autoflow.service.WorkFlowService;
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.time.LocalDateTime;
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;
private final WorkFlowService workFlowService;
@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(
@RequestParam("uploadfile") MultipartFile file,
@RequestParam(value = "name", required = true) String name,
@RequestParam(value = "display_name", required = true) String displayName,
@RequestParam(value = "description", required = false) String description,
@RequestParam(value = "namespace", required = false) String namespace,
@RequestParam(value = "regUserId") String regUserId,
@RequestParam(value = "projectId") Long projectId
) {
try {
// Kubeflow 업로드
Map<String, Object> result = pipelineUploadService.uploadPipeline(file, name, displayName, description, namespace);
// WorkflowEntity 매핑 후 DB 저장
WorkflowEntity workflow = WorkflowEntity.builder()
.pipelineId((String) result.get("pipeline_id"))
.displayName((String) result.get("display_name"))
.name((String) result.get("name"))
.description((String) result.get("description"))
.namespace((String) result.get("namespace"))
.regUserId(regUserId)
.projectId(projectId)
.kubeflowStatus("Created")
.version(1)
.build();
// 저장
workFlowService.save(workflow);
return ResponseEntity.ok(result);
} catch (Exception e) {
log.error("Pipeline upload failed", e);
Map<String, Object> error = Map.of(
"status", 500,
"error", "Internal Server Error",
"message", e.getMessage()
);
return ResponseEntity.status(500).body(error);
}
}
}