parent
48746a113c
commit
6edcea695c
@ -0,0 +1,34 @@
|
|||||||
|
package kr.re.etri.autoflow.controllers;
|
||||||
|
|
||||||
|
import kr.re.etri.autoflow.service.PipelineUploadService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
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.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@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) {
|
||||||
|
|
||||||
|
Map<String, Object> result = pipelineUploadService.uploadPipeline(file, name, displayName, description, namespace);
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package kr.re.etri.autoflow.service;
|
||||||
|
|
||||||
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class MultipartInputStreamFileResource extends InputStreamResource {
|
||||||
|
|
||||||
|
private final String filename;
|
||||||
|
|
||||||
|
public MultipartInputStreamFileResource(InputStream inputStream, String filename) {
|
||||||
|
super(inputStream);
|
||||||
|
this.filename = filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFilename() {
|
||||||
|
return this.filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long contentLength() {
|
||||||
|
return -1; // 파일 크기를 알 수 없으면 -1로 설정
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
package kr.re.etri.autoflow.service;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
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.util.UriComponentsBuilder;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class PipelineUploadService {
|
||||||
|
|
||||||
|
private final RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@Value("${kubeflow.pipeline.upload-url}")
|
||||||
|
private String kubeflowUploadUrl;
|
||||||
|
|
||||||
|
public Map<String, Object> uploadPipeline(MultipartFile file,
|
||||||
|
String name,
|
||||||
|
String displayName,
|
||||||
|
String description,
|
||||||
|
String namespace) {
|
||||||
|
try {
|
||||||
|
// 파일 form-data
|
||||||
|
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);
|
||||||
|
|
||||||
|
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
||||||
|
|
||||||
|
// URL 조립 (쿼리 파라미터 방식)
|
||||||
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(kubeflowUploadUrl);
|
||||||
|
|
||||||
|
if (name != null && !name.isBlank()) builder.queryParam("name", name);
|
||||||
|
if (displayName != null && !displayName.isBlank()) builder.queryParam("display_name", displayName);
|
||||||
|
if (description != null && !description.isBlank()) builder.queryParam("description", description);
|
||||||
|
if (namespace != null && !namespace.isBlank()) builder.queryParam("namespace", namespace);
|
||||||
|
|
||||||
|
String url = builder.toUriString();
|
||||||
|
|
||||||
|
ResponseEntity<Map> response = restTemplate.postForEntity(url, requestEntity, Map.class);
|
||||||
|
return response.getBody();
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Pipeline upload failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue