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.
64 lines
2.6 KiB
64 lines
2.6 KiB
package kr.re.etri.autoflow.controllers;
|
|
|
|
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.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
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
|
|
public class PipelineUploadController {
|
|
|
|
private final PipelineUploadService pipelineUploadService;
|
|
|
|
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
public ResponseEntity<Map<String, Object>> uploadPipeline(
|
|
@RequestParam("uploadfile") MultipartFile file,
|
|
@RequestParam(value = "name", required = false) String name,
|
|
@RequestParam(value = "display_name", required = false) String displayName,
|
|
@RequestParam(value = "description", required = false) String description,
|
|
@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);
|
|
}
|
|
}
|
|
}
|
|
|