[ADD] projectId 필드 추가 및 Kubeflow 업로드 API 활성화 (Service, Controller)

main
bjkim 9 months ago
parent e94a85571f
commit 48746a113c

@ -14,7 +14,10 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.InputStreamResource;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.http.*; import org.springframework.http.*;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream; import java.io.InputStream;
@ -83,11 +86,13 @@ public class MinioAttachmentController {
@RequestParam(value = "title", required = false) String title, @RequestParam(value = "title", required = false) String title,
@RequestParam(value = "description", required = false) String description, @RequestParam(value = "description", required = false) String description,
@RequestParam(value = "version", required = false, defaultValue = "1") Integer version, @RequestParam(value = "version", required = false, defaultValue = "1") Integer version,
@RequestParam(value = "regUserId") String regUserId @RequestParam(value = "regUserId") String regUserId,
@RequestParam(value = "projectId") Long projectId
) { ) {
try { try {
MinioAttachmentEntity saved = minioAttachmentService.uploadFile( MinioAttachmentEntity saved = minioAttachmentService.uploadFile(
file, path, refId, refType, title, description, version, regUserId file, path, refId, refType, title, description, version, regUserId, projectId
); );
Map<String, Object> response = new HashMap<>(); Map<String, Object> response = new HashMap<>();
@ -102,51 +107,52 @@ public class MinioAttachmentController {
} }
} }
// @Operation(summary = "파일 업로드 및 Kubeflow 업로드", @Operation(summary = "파일 업로드 및 Kubeflow 업로드",
// description = "MinIO와 DB에 저장하고 Kubeflow REST API에도 업로드합니다. Kubeflow API 경로는 요청 시 지정 가능") description = "MinIO와 DB에 저장하고 Kubeflow REST API에도 업로드합니다. Kubeflow API 경로는 요청 시 지정 가능")
// @PostMapping(value = "/upload-and-kubeflow", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping(value = "/upload-and-kubeflow", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
// public ResponseEntity<Map<String, Object>> uploadFileAndKubeflow( public ResponseEntity<Map<String, Object>> uploadFileAndKubeflow(
// @Parameter(description = "업로드할 파일") @RequestPart("file") MultipartFile file, @Parameter(description = "업로드할 파일") @RequestPart("file") MultipartFile file,
// @RequestPart(value = "path", required = false) String path, @RequestPart(value = "path", required = false) String path,
// @RequestParam(value = "refId", required = false) Long refId, @RequestParam(value = "refId", required = false) Long refId,
// @RequestParam(value = "refType", required = false, defaultValue = "TRAINING_SCRIPT") String refType, @RequestParam(value = "refType", required = false, defaultValue = "TRAINING_SCRIPT") String refType,
// @RequestParam(value = "title", required = false) String title, @RequestParam(value = "title", required = false) String title,
// @RequestParam(value = "description", required = false) String description, @RequestParam(value = "description", required = false) String description,
// @RequestParam(value = "version", required = false, defaultValue = "1") Integer version, @RequestParam(value = "version", required = false, defaultValue = "1") Integer version,
// @RequestParam(value = "regUserId") String regUserId, @RequestParam(value = "regUserId") String regUserId,
// @RequestParam(value = "kubeflowApi") String kubeflowApi @RequestParam(value = "projectId") Long projectId,
// ) { @RequestParam(value = "kubeflowApi") String kubeflowApi
// Map<String, Object> response = new HashMap<>(); ) {
// try { Map<String, Object> response = new HashMap<>();
// MinioAttachmentEntity saved = minioAttachmentService.uploadFile( try {
// file, path, refId, refType, title, description, version, regUserId MinioAttachmentEntity saved = minioAttachmentService.uploadFile(
// ); file, path, refId, refType, title, description, version, regUserId, projectId
// String minioUrl = minioAttachmentService.getFileUrl(saved.getStoragePath()); );
// response.put("attachment", saved); String minioUrl = minioAttachmentService.getFileUrl(saved.getStoragePath());
// response.put("minioUrl", minioUrl); response.put("attachment", saved);
// response.put("minioUrl", minioUrl);
// RestTemplate restTemplate = new RestTemplate();
// MultiValueMap<String, Object> body = new LinkedMultiValueMap<>(); RestTemplate restTemplate = new RestTemplate();
// body.add("uploadfile", new MultipartInputStreamFileResource(file.getInputStream(), file.getOriginalFilename())); MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
// body.add("uploadfile", new MultipartInputStreamFileResource(file.getInputStream(), file.getOriginalFilename()));
// HttpHeaders headers = new HttpHeaders();
// headers.setContentType(MediaType.MULTIPART_FORM_DATA); HttpHeaders headers = new HttpHeaders();
// headers.setContentType(MediaType.MULTIPART_FORM_DATA);
// HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
// HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
// String fullUrl = kubeflowBaseUrl + kubeflowApi;
// ResponseEntity<String> kubeflowResponse = restTemplate.postForEntity(fullUrl, requestEntity, String.class); String fullUrl = kubeflowBaseUrl + kubeflowApi;
// ResponseEntity<String> kubeflowResponse = restTemplate.postForEntity(fullUrl, requestEntity, String.class);
// response.put("kubeflowResponse", kubeflowResponse.getBody());
// response.put("kubeflowResponse", kubeflowResponse.getBody());
// return ResponseEntity.ok(response);
// return ResponseEntity.ok(response);
// } catch (Exception e) {
// log.error("파일 업로드 실패", e); } catch (Exception e) {
// response.put("error", e.getMessage()); log.error("파일 업로드 실패", e);
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); response.put("error", e.getMessage());
// } return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
// } }
}
// 파일 업로드용 InputStreamResource // 파일 업로드용 InputStreamResource
private static class MultipartInputStreamFileResource extends InputStreamResource { private static class MultipartInputStreamFileResource extends InputStreamResource {

@ -53,7 +53,10 @@ public class MinioAttachmentService {
String title, String title,
String description, String description,
Integer version, Integer version,
String regUserId) throws Exception { String regUserId,
Long projectId
) throws Exception {
try (InputStream is = file.getInputStream()) { try (InputStream is = file.getInputStream()) {
String storedName = UUID.randomUUID() + "-" + file.getOriginalFilename(); String storedName = UUID.randomUUID() + "-" + file.getOriginalFilename();
String objectName = (path == null || path.isEmpty()) String objectName = (path == null || path.isEmpty())
@ -83,6 +86,7 @@ public class MinioAttachmentService {
.version(version) .version(version)
.description(description) .description(description)
.regUserId(regUserId) .regUserId(regUserId)
.projectId(projectId)
.build(); .build();
return minioAttachmentRepository.save(attachment); return minioAttachmentRepository.save(attachment);

Loading…
Cancel
Save