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/service/PipelineUploadService.java

61 lines
2.5 KiB

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);
}
}
}