From d51b5e270978b603f5c0b111b2350e709994cd9b Mon Sep 17 00:00:00 2001 From: bjkim Date: Wed, 15 Oct 2025 17:08:43 +0900 Subject: [PATCH] =?UTF-8?q?[ADD]=20=EC=99=B8=EB=B6=80=20Edge=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EB=93=B1=EB=A1=9D=20API=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=ED=8C=8C=EC=9D=BC=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=20=EC=A7=80=EC=9B=90,=20=EA=B4=80=EB=A0=A8=20Controll?= =?UTF-8?q?er=20=EB=B0=8F=20Service=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ExternalAuthController.java | 19 ++++++++++ .../autoflow/service/ExternalAuthService.java | 36 +++++++++++++++++++ src/main/resources/application.properties | 4 ++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/main/java/kr/re/etri/autoflow/controllers/ExternalAuthController.java b/src/main/java/kr/re/etri/autoflow/controllers/ExternalAuthController.java index ef3fec8..71e2995 100644 --- a/src/main/java/kr/re/etri/autoflow/controllers/ExternalAuthController.java +++ b/src/main/java/kr/re/etri/autoflow/controllers/ExternalAuthController.java @@ -1,11 +1,13 @@ package kr.re.etri.autoflow.controllers; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import kr.re.etri.autoflow.service.ExternalAuthService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; 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: 요청 public static record SigninRequest(String id, String password) { } diff --git a/src/main/java/kr/re/etri/autoflow/service/ExternalAuthService.java b/src/main/java/kr/re/etri/autoflow/service/ExternalAuthService.java index a8e891f..58624db 100644 --- a/src/main/java/kr/re/etri/autoflow/service/ExternalAuthService.java +++ b/src/main/java/kr/re/etri/autoflow/service/ExternalAuthService.java @@ -4,10 +4,14 @@ import jakarta.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.*; import org.springframework.stereotype.Service; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.web.multipart.MultipartFile; import javax.net.ssl.*; +import java.io.IOException; import java.security.cert.X509Certificate; import java.util.HashMap; import java.util.Map; @@ -23,6 +27,9 @@ public class ExternalAuthService { @Value("${external.auth.edge-search-url}") private String edgeSearchUrl; + @Value("${external.edge.add-url:https://cuuva.com:24443/api/datamanager/edge-pkg/add}") + private String edgeAddUrl; + @PostConstruct public void init() { this.restTemplate = createUnsafeRestTemplate(); @@ -102,4 +109,33 @@ public class ExternalAuthService { 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 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> request = new HttpEntity<>(body, headers); + + ResponseEntity response = restTemplate.exchange( + edgeAddUrl, + HttpMethod.POST, + request, + Object.class + ); + + return response.getBody(); + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2f7804c..3b05bfb 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -46,6 +46,8 @@ springdoc.swagger-ui.url=/autoflow-server-mgmt/v3/api-docs springdoc.swagger-ui.doc-expansion=none 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 @@ -58,7 +60,7 @@ minio.bucket=mlpipeline # Kubeflow kubeflow.url=http://192.168.10.135:32473/ -# MLflow +# MLflowz mlflow.url=http://192.168.10.135:30128/ mlflow.user=user mlflow.password=LImQa2Me37nu