[ADD] 외부 Edge 패키지 등록 API 추가 및 파일 업로드 지원, 관련 Controller 및 Service 로직 구현

main
bjkim 8 months ago
parent 7785fc220b
commit d51b5e2709

@ -1,11 +1,13 @@
package kr.re.etri.autoflow.controllers; package kr.re.etri.autoflow.controllers;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import kr.re.etri.autoflow.service.ExternalAuthService; import kr.re.etri.autoflow.service.ExternalAuthService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.Map; import java.util.Map;
@ -43,6 +45,23 @@ public class ExternalAuthController {
} }
} }
@Operation(summary = "외부 Edge 패키지 등록", description = "외부 서버로 Edge 패키지 정보를 파일과 함께 전송하여 등록합니다.")
@PostMapping(value = "/add", consumes = {"multipart/form-data"})
public ResponseEntity<?> addEdgePackage(
@Parameter(description = "로그인 시 발급받은 Bearer 토큰") @RequestHeader("Authorization") String bearerToken,
@Parameter(description = "Edge 패키지 등록 요청 JSON 데이터") @RequestPart("edgePkgInfoVO") String edgePkgInfoJson,
@Parameter(description = "업로드할 패키지 파일") @RequestPart(value = "file", required = false) MultipartFile file
) {
try {
Object response = externalAuthService.uploadEdgePackage(bearerToken, edgePkgInfoJson, file);
return ResponseEntity.ok(response);
} catch (Exception e) {
return ResponseEntity.internalServerError().body(
String.format("파일 업로드 실패: %s", e.getMessage())
);
}
}
// DTO: 요청 // DTO: 요청
public static record SigninRequest(String id, String password) { } public static record SigninRequest(String id, String password) { }

@ -4,10 +4,14 @@ import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*; import org.springframework.http.*;
import org.springframework.stereotype.Service; 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.client.RestTemplate;
import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.multipart.MultipartFile;
import javax.net.ssl.*; import javax.net.ssl.*;
import java.io.IOException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -23,6 +27,9 @@ public class ExternalAuthService {
@Value("${external.auth.edge-search-url}") @Value("${external.auth.edge-search-url}")
private String edgeSearchUrl; private String edgeSearchUrl;
@Value("${external.edge.add-url:https://cuuva.com:24443/api/datamanager/edge-pkg/add}")
private String edgeAddUrl;
@PostConstruct @PostConstruct
public void init() { public void init() {
this.restTemplate = createUnsafeRestTemplate(); this.restTemplate = createUnsafeRestTemplate();
@ -102,4 +109,33 @@ public class ExternalAuthService {
throw new RuntimeException("Failed to fetch edge package list"); throw new RuntimeException("Failed to fetch edge package list");
} }
public Object uploadEdgePackage(String bearerToken, String edgePkgInfoJson, MultipartFile file) throws IOException {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.set("Authorization", bearerToken.startsWith("Bearer ") ? bearerToken : "Bearer " + bearerToken);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("edgePkgInfoVO", edgePkgInfoJson);
if (file != null && !file.isEmpty()) {
body.add("file", new org.springframework.core.io.ByteArrayResource(file.getBytes()) {
@Override
public String getFilename() {
return file.getOriginalFilename();
}
});
}
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(body, headers);
ResponseEntity<Object> response = restTemplate.exchange(
edgeAddUrl,
HttpMethod.POST,
request,
Object.class
);
return response.getBody();
}
} }

@ -46,6 +46,8 @@ springdoc.swagger-ui.url=/autoflow-server-mgmt/v3/api-docs
springdoc.swagger-ui.doc-expansion=none springdoc.swagger-ui.doc-expansion=none
springdoc.swagger-ui.disable-swagger-default-url=true springdoc.swagger-ui.disable-swagger-default-url=true
spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=500MB
springdoc.swagger-ui.tags-sorter=alpha springdoc.swagger-ui.tags-sorter=alpha
@ -58,7 +60,7 @@ minio.bucket=mlpipeline
# Kubeflow # Kubeflow
kubeflow.url=http://192.168.10.135:32473/ kubeflow.url=http://192.168.10.135:32473/
# MLflow # MLflowz
mlflow.url=http://192.168.10.135:30128/ mlflow.url=http://192.168.10.135:30128/
mlflow.user=user mlflow.user=user
mlflow.password=LImQa2Me37nu mlflow.password=LImQa2Me37nu

Loading…
Cancel
Save