From ce69bacb01d7466a2f08e2f288573593266a41f1 Mon Sep 17 00:00:00 2001 From: teddy Date: Wed, 4 Feb 2026 19:15:10 +0900 Subject: [PATCH] =?UTF-8?q?=EB=AA=A8=EB=8D=B8=ED=95=99=EC=8A=B5=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=93=B1=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../training/config/api/ApiResponseDto.java | 1 + .../hyperparam/HyperParamApiController.java | 3 +- .../model/ModelTrainMngApiController.java | 3 +- .../model/service/ModelTrainMngService.java | 1 + .../postgres/core/HyperParamCoreService.java | 5 +++- .../core/ModelTrainMngCoreService.java | 28 +++++++++++++++---- .../postgres/entity/ModelMasterEntity.java | 4 +-- .../hyperparam/HyperParamRepository.java | 5 +++- 8 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/kamco/cd/training/config/api/ApiResponseDto.java b/src/main/java/com/kamco/cd/training/config/api/ApiResponseDto.java index 886031c..5beef94 100644 --- a/src/main/java/com/kamco/cd/training/config/api/ApiResponseDto.java +++ b/src/main/java/com/kamco/cd/training/config/api/ApiResponseDto.java @@ -164,6 +164,7 @@ public class ApiResponseDto { NOT_FOUND_USER_FOR_EMAIL("이메일로 유저를 찾을 수 없습니다."), NOT_FOUND_USER("사용자를 찾을 수 없습니다."), UNPROCESSABLE_ENTITY("이 데이터는 삭제할 수 없습니다."), + UNPROCESSABLE_ENTITY_UPDATE("이 데이터는 수정할 수 없습니다."), LOGIN_ID_NOT_FOUND("아이디를 잘못 입력하셨습니다."), LOGIN_PASSWORD_MISMATCH("비밀번호를 잘못 입력하셨습니다."), LOGIN_PASSWORD_EXCEEDED("비밀번호 오류 횟수를 초과하여 이용하실 수 없습니다.\n로그인 오류에 대해 관리자에게 문의하시기 바랍니다."), diff --git a/src/main/java/com/kamco/cd/training/hyperparam/HyperParamApiController.java b/src/main/java/com/kamco/cd/training/hyperparam/HyperParamApiController.java index 60ff8d2..964ba74 100644 --- a/src/main/java/com/kamco/cd/training/hyperparam/HyperParamApiController.java +++ b/src/main/java/com/kamco/cd/training/hyperparam/HyperParamApiController.java @@ -65,6 +65,7 @@ public class HyperParamApiController { mediaType = "application/json", schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "400", description = "잘못된 요청", content = @Content), + @ApiResponse(responseCode = "422", description = "HPs_0001 수정 불가", content = @Content), @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) }) @PutMapping("/{uuid}") @@ -132,7 +133,7 @@ public class HyperParamApiController { @ApiResponses( value = { @ApiResponse(responseCode = "200", description = "삭제 성공", content = @Content), - @ApiResponse(responseCode = "409", description = "HPs_0001 삭제 불가", content = @Content), + @ApiResponse(responseCode = "422", description = "HPs_0001 삭제 불가", content = @Content), @ApiResponse(responseCode = "404", description = "하이퍼파라미터를 찾을 수 없음", content = @Content), }) @DeleteMapping("/{uuid}") diff --git a/src/main/java/com/kamco/cd/training/model/ModelTrainMngApiController.java b/src/main/java/com/kamco/cd/training/model/ModelTrainMngApiController.java index ad73849..c306895 100644 --- a/src/main/java/com/kamco/cd/training/model/ModelTrainMngApiController.java +++ b/src/main/java/com/kamco/cd/training/model/ModelTrainMngApiController.java @@ -11,6 +11,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -86,7 +87,7 @@ public class ModelTrainMngApiController { @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) }) @PostMapping - public ApiResponseDto createModelTrain(@RequestBody ModelTrainMngDto.AddReq req) { + public ApiResponseDto createModelTrain(@Valid @RequestBody ModelTrainMngDto.AddReq req) { modelTrainMngService.createModelTrain(req); return ApiResponseDto.ok("ok"); } diff --git a/src/main/java/com/kamco/cd/training/model/service/ModelTrainMngService.java b/src/main/java/com/kamco/cd/training/model/service/ModelTrainMngService.java index c408a08..2c19c4d 100644 --- a/src/main/java/com/kamco/cd/training/model/service/ModelTrainMngService.java +++ b/src/main/java/com/kamco/cd/training/model/service/ModelTrainMngService.java @@ -53,6 +53,7 @@ public class ModelTrainMngService { HyperParam hyperParam = req.getHyperParam(); HyperParamDto.Basic hyper = new HyperParamDto.Basic(); + // 하이파라미터 신규저장 if (HyperParamSelectType.NEW.getId().equals(req.getHyperParamType())) { // 하이퍼파라미터 등록 hyper = hyperParamCoreService.createHyperParam(hyperParam); diff --git a/src/main/java/com/kamco/cd/training/postgres/core/HyperParamCoreService.java b/src/main/java/com/kamco/cd/training/postgres/core/HyperParamCoreService.java index d3b1f4b..853eec7 100644 --- a/src/main/java/com/kamco/cd/training/postgres/core/HyperParamCoreService.java +++ b/src/main/java/com/kamco/cd/training/postgres/core/HyperParamCoreService.java @@ -57,6 +57,9 @@ public class HyperParamCoreService { .findHyperParamByUuid(uuid) .orElseThrow(() -> new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND)); + if (entity.getHyperVer().equals("HPs_0001")) { + throw new CustomApiException("UNPROCESSABLE_ENTITY_UPDATE", HttpStatus.UNPROCESSABLE_ENTITY); + } applyHyperParam(entity, createReq); // user @@ -120,7 +123,7 @@ public class HyperParamCoreService { .orElseThrow(() -> new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND)); if (entity.getHyperVer().equals("HPs_0001")) { - throw new CustomApiException("CONFLICT", HttpStatus.CONFLICT, "HPs_0001 버전은 삭제할수 없습니다."); + throw new CustomApiException("UNPROCESSABLE_ENTITY", HttpStatus.UNPROCESSABLE_ENTITY); } entity.setDelYn(true); diff --git a/src/main/java/com/kamco/cd/training/postgres/core/ModelTrainMngCoreService.java b/src/main/java/com/kamco/cd/training/postgres/core/ModelTrainMngCoreService.java index 45d0e3b..7bab856 100644 --- a/src/main/java/com/kamco/cd/training/postgres/core/ModelTrainMngCoreService.java +++ b/src/main/java/com/kamco/cd/training/postgres/core/ModelTrainMngCoreService.java @@ -1,5 +1,6 @@ package com.kamco.cd.training.postgres.core; +import com.kamco.cd.training.common.enums.HyperParamSelectType; import com.kamco.cd.training.common.enums.ModelType; import com.kamco.cd.training.common.enums.TrainStatusType; import com.kamco.cd.training.common.exception.BadRequestException; @@ -71,22 +72,37 @@ public class ModelTrainMngCoreService { */ public Long saveModel(ModelTrainMngDto.AddReq addReq) { ModelMasterEntity entity = new ModelMasterEntity(); - ModelHyperParamEntity hyperParamEntity = - hyperParamRepository.findHyperParamByUuid(addReq.getHyperUuid()).orElse(null); + ModelHyperParamEntity hyperParamEntity = new ModelHyperParamEntity(); - entity.setModelNo(addReq.getModelNo()); - entity.setTrainType(addReq.getTrainType()); + // 최적화 파라미터는 HPs_0001 사용 + if (HyperParamSelectType.OPTIMIZED.getId().equals(addReq.getHyperParamType())) { + hyperParamEntity = hyperParamRepository.findByHyperVer("HPs_0001").orElse(null); - if (hyperParamEntity != null) { - entity.setHyperParamId(hyperParamEntity.getId()); + } else { + hyperParamEntity = + hyperParamRepository.findHyperParamByUuid(addReq.getHyperUuid()).orElse(null); } + if (hyperParamEntity == null || hyperParamEntity.getHyperVer() == null) { + throw new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND); + } + + String modelVer = + String.join( + ".", addReq.getModelNo(), hyperParamEntity.getHyperVer(), entity.getUuid().toString()); + entity.setModelVer(modelVer); + entity.setHyperParamId(hyperParamEntity.getId()); + entity.setModelNo(addReq.getModelNo()); + entity.setTrainType(addReq.getTrainType()); // 일반, 전이 + if (addReq.getIsStart()) { entity.setModelStep((short) 1); entity.setStatusCd(TrainStatusType.IN_PROGRESS.getId()); entity.setStrtDttm(ZonedDateTime.now()); entity.setStep1StrtDttm(ZonedDateTime.now()); entity.setStep1State(TrainStatusType.IN_PROGRESS.getId()); + } else { + entity.setStatusCd(TrainStatusType.READY.getId()); } entity.setCreatedUid(userUtil.getId()); diff --git a/src/main/java/com/kamco/cd/training/postgres/entity/ModelMasterEntity.java b/src/main/java/com/kamco/cd/training/postgres/entity/ModelMasterEntity.java index 1e9dee4..9497cce 100644 --- a/src/main/java/com/kamco/cd/training/postgres/entity/ModelMasterEntity.java +++ b/src/main/java/com/kamco/cd/training/postgres/entity/ModelMasterEntity.java @@ -32,8 +32,8 @@ public class ModelMasterEntity { @Column(name = "model_no", length = 10) private String modelNo; - @Size(max = 50) - @Column(name = "model_ver", length = 50) + @Size(max = 200) + @Column(name = "model_ver", length = 200) private String modelVer; @Column(name = "model_step") diff --git a/src/main/java/com/kamco/cd/training/postgres/repository/hyperparam/HyperParamRepository.java b/src/main/java/com/kamco/cd/training/postgres/repository/hyperparam/HyperParamRepository.java index 529bc81..6e1d5e1 100644 --- a/src/main/java/com/kamco/cd/training/postgres/repository/hyperparam/HyperParamRepository.java +++ b/src/main/java/com/kamco/cd/training/postgres/repository/hyperparam/HyperParamRepository.java @@ -1,9 +1,12 @@ package com.kamco.cd.training.postgres.repository.hyperparam; import com.kamco.cd.training.postgres.entity.ModelHyperParamEntity; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface HyperParamRepository - extends JpaRepository, HyperParamRepositoryCustom {} + extends JpaRepository, HyperParamRepositoryCustom { + Optional findByHyperVer(String hyperVer); +}