|
|
|
|
@ -9,6 +9,7 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
import jakarta.annotation.PostConstruct;
|
|
|
|
|
import kr.re.etri.autoflow.payload.request.EdgeSWVO;
|
|
|
|
|
import kr.re.etri.autoflow.service.DynamicMinioAttachmentService;
|
|
|
|
|
import kr.re.etri.autoflow.service.EdgeSWUploadService;
|
|
|
|
|
import kr.re.etri.autoflow.service.ExternalAuthService;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
@ -44,6 +45,8 @@ public class ExternalAuthController {
|
|
|
|
|
|
|
|
|
|
private final ExternalAuthService externalAuthService;
|
|
|
|
|
private final EdgeSWUploadService edgeSWUploadService;
|
|
|
|
|
private final DynamicMinioAttachmentService minioService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
@PostConstruct
|
|
|
|
|
@ -163,7 +166,7 @@ public class ExternalAuthController {
|
|
|
|
|
@PostMapping(value = "/register-with-file", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
|
|
public ResponseEntity<String> registerWithFile(
|
|
|
|
|
@RequestParam("sw_id") String swId,
|
|
|
|
|
@RequestParam("sw_version") int swVersion,
|
|
|
|
|
@RequestParam("sw_version") float swVersion,
|
|
|
|
|
@RequestParam("sw_name") String swName,
|
|
|
|
|
@RequestParam("auth_id") String authId,
|
|
|
|
|
|
|
|
|
|
@ -239,6 +242,103 @@ public class ExternalAuthController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/register-with-minio-file")
|
|
|
|
|
@Operation(
|
|
|
|
|
summary = "외부 DB 등록 + MinIO 다운로드 파일 S3 업로드",
|
|
|
|
|
description = "MinIO에서 파일을 다운로드하고, S3 업로드 후 외부 DB에 등록합니다.",
|
|
|
|
|
security = @SecurityRequirement(name = "bearerAuth")
|
|
|
|
|
)
|
|
|
|
|
public ResponseEntity<String> registerWithMinioFile(
|
|
|
|
|
@RequestParam("sw_id") String swId,
|
|
|
|
|
@RequestParam("sw_version") float swVersion,
|
|
|
|
|
@RequestParam("sw_name") String swName,
|
|
|
|
|
|
|
|
|
|
@RequestParam
|
|
|
|
|
@Schema(description = "auth token", example = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTc2NDIxOTA5MSwiaWF0IjoxNzYxNjI3MDkxfQ.OGDxMSEOsS36IEDEKTXTgACMS5r0nW3ylVskCmqbQYY", required = true)
|
|
|
|
|
String authId,
|
|
|
|
|
|
|
|
|
|
@RequestParam
|
|
|
|
|
@Schema(description = "SW/엣지 패키지 정보", example = "14", required = true)
|
|
|
|
|
Integer pkg_serial,
|
|
|
|
|
|
|
|
|
|
@RequestParam
|
|
|
|
|
@Schema(description = "압축여부(0:단일,1:묶음)", example = "1", required = true)
|
|
|
|
|
Integer archiveType,
|
|
|
|
|
|
|
|
|
|
@RequestParam
|
|
|
|
|
@Schema(description = "실행여부 (0:실행하지않음,1:실행)", example = "1", required = true)
|
|
|
|
|
String execYn,
|
|
|
|
|
|
|
|
|
|
@RequestParam
|
|
|
|
|
@Schema(description = "비밀글 여부 (true/false)", example = "false", required = true)
|
|
|
|
|
String secretAt,
|
|
|
|
|
|
|
|
|
|
@RequestParam
|
|
|
|
|
@Schema(description = "설치 위치", example = "/etc/test/", required = true)
|
|
|
|
|
String downloadLocation,
|
|
|
|
|
|
|
|
|
|
@RequestParam("user_id")
|
|
|
|
|
@Schema(description = "사용자 ID", example = "admin", required = true)
|
|
|
|
|
String userId,
|
|
|
|
|
|
|
|
|
|
@RequestParam("sw_type")
|
|
|
|
|
@Schema(description = "0 = sw, 1 = edge로 DB 전송", example = "1", required = true)
|
|
|
|
|
int sw_type,
|
|
|
|
|
|
|
|
|
|
@RequestParam("creation_datetime")
|
|
|
|
|
@Schema(description = "생성 일시 (ISO-8601 형식, UTC)", example = "2025-10-20T11:46:49.848Z", required = true)
|
|
|
|
|
String creationDatetime,
|
|
|
|
|
|
|
|
|
|
@Parameter(description = "다운로드할 MinIO 객체 이름", example="4/9d08fa7973cf4c39a0979bb4d70c640b/artifacts/sklearn-model/model.pkl", required = true)
|
|
|
|
|
@RequestParam String objectName,
|
|
|
|
|
|
|
|
|
|
@Parameter(description = "MINIO 서버 타입 (type1[kubeflow],type2[mlflow])", example="type2", required = true)
|
|
|
|
|
@RequestParam String type,
|
|
|
|
|
|
|
|
|
|
@Parameter(description = "서버에 저장할 로컬 경로", example="downloads/temp", required = true)
|
|
|
|
|
@RequestParam String localPath
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
// objectName에서 파일명 추출
|
|
|
|
|
String fileName = objectName.substring(objectName.lastIndexOf("/") + 1);
|
|
|
|
|
// localPath가 디렉토리라면 파일명 붙이기
|
|
|
|
|
String fullLocalPath = localPath.endsWith("/") ? localPath + fileName : localPath + "/" + fileName;
|
|
|
|
|
|
|
|
|
|
// 1. MinIO에서 서버로 다운로드
|
|
|
|
|
minioService.downloadFileToServer(objectName, type, localPath);
|
|
|
|
|
|
|
|
|
|
// 2. VO 생성
|
|
|
|
|
EdgeSWVO edgeSWVO = new EdgeSWVO();
|
|
|
|
|
edgeSWVO.setSw_id(swId);
|
|
|
|
|
edgeSWVO.setSw_version(swVersion);
|
|
|
|
|
edgeSWVO.setSw_name(swName);
|
|
|
|
|
edgeSWVO.setAuth_id(authId);
|
|
|
|
|
edgeSWVO.setUser_id(userId);
|
|
|
|
|
edgeSWVO.setCreation_datetime(creationDatetime);
|
|
|
|
|
edgeSWVO.setPkg_serial(pkg_serial);
|
|
|
|
|
edgeSWVO.setArchive_type(archiveType);
|
|
|
|
|
edgeSWVO.setDownload_location(downloadLocation);
|
|
|
|
|
edgeSWVO.setExec_yn(execYn);
|
|
|
|
|
edgeSWVO.setSecret_at(secretAt);
|
|
|
|
|
|
|
|
|
|
// 3. 다운로드한 파일을 S3로 업로드
|
|
|
|
|
edgeSWUploadService.uploadFileToS3Only(edgeSWVO, fullLocalPath);
|
|
|
|
|
|
|
|
|
|
// 4. DB 등록
|
|
|
|
|
String result = edgeSWUploadService.registerMetadata(edgeSWVO, sw_type);
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(result);
|
|
|
|
|
|
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
|
log.error("S3 파일 업로드 실패", ioe);
|
|
|
|
|
return ResponseEntity.internalServerError().body("파일 업로드 실패: " + ioe.getMessage());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("DB 등록 실패", e);
|
|
|
|
|
return ResponseEntity.internalServerError().body("DB 등록 실패: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DTO: 요청
|
|
|
|
|
public static record SigninRequest(String id, String password) { }
|
|
|
|
|
|
|
|
|
|
|