diff --git a/backend/src/main/java/com/worlabel/domain/model/controller/AiModelController.java b/backend/src/main/java/com/worlabel/domain/model/controller/AiModelController.java index 634a2ff..17e79d5 100644 --- a/backend/src/main/java/com/worlabel/domain/model/controller/AiModelController.java +++ b/backend/src/main/java/com/worlabel/domain/model/controller/AiModelController.java @@ -2,10 +2,9 @@ package com.worlabel.domain.model.controller; import com.worlabel.domain.model.entity.dto.AiModelRequest; import com.worlabel.domain.model.entity.dto.AiModelResponse; +import com.worlabel.domain.model.entity.dto.MemoryResponse; import com.worlabel.domain.model.entity.dto.ModelTrainRequest; import com.worlabel.domain.model.service.AiModelService; -import com.worlabel.domain.progress.service.ProgressService; -import com.worlabel.domain.project.entity.dto.ProjectRequest; import com.worlabel.global.annotation.CurrentUser; import com.worlabel.global.config.swagger.SwaggerApiError; import com.worlabel.global.config.swagger.SwaggerApiSuccess; @@ -82,4 +81,12 @@ public class AiModelController { log.debug("다운로드 요청 projectId : {} modelId : {}", projectId, modelId); return aiModelService.modelDownload(projectId, modelId); } + + @Operation(summary = "GPU 서버 메모리 상태", description = "GPU 서버의 메모리 상태를 반환") + @SwaggerApiSuccess(description = "프로젝트 모델이 성공적으로 다운로드됩니다.") + @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) + @GetMapping("/gpu/memory") + public MemoryResponse getMemory() { + return aiModelService.getMemory(); + } } diff --git a/backend/src/main/java/com/worlabel/domain/model/entity/dto/MemoryResponse.java b/backend/src/main/java/com/worlabel/domain/model/entity/dto/MemoryResponse.java new file mode 100644 index 0000000..44f1805 --- /dev/null +++ b/backend/src/main/java/com/worlabel/domain/model/entity/dto/MemoryResponse.java @@ -0,0 +1,27 @@ +package com.worlabel.domain.model.entity.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +@Getter +@ToString +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class MemoryResponse { + + @JsonProperty("current_device") + @Schema(description = "사용중인 디바이스 ID", example = "1") + private int deviceId; + + @Schema(description = "전체 GPU 메모리(GB)", example = "1") + private double total; + + @Schema(description = "현재 사용중인 GPU 메모리(GB)", example = "1") + private double allocated; + + @Schema(description = "예약된 GPU 메모리(GB)", example = "1") + private double reserved; + + @Schema(description = "사용 가능한 GPU 메모리(GB)", example = "1") + private double free; +} \ No newline at end of file diff --git a/backend/src/main/java/com/worlabel/domain/model/service/AiModelService.java b/backend/src/main/java/com/worlabel/domain/model/service/AiModelService.java index 9270625..9540f54 100644 --- a/backend/src/main/java/com/worlabel/domain/model/service/AiModelService.java +++ b/backend/src/main/java/com/worlabel/domain/model/service/AiModelService.java @@ -191,4 +191,9 @@ public class AiModelService { } } + public MemoryResponse getMemory() { + String memoryResponse = aiRequestService.getRequest("/detection/memory", data -> data); + log.debug("memoryData {}", memoryResponse); + return gson.fromJson(memoryResponse, MemoryResponse.class); + } } diff --git a/backend/src/main/java/com/worlabel/domain/project/service/ProjectService.java b/backend/src/main/java/com/worlabel/domain/project/service/ProjectService.java index 5d0eeb4..8258b58 100644 --- a/backend/src/main/java/com/worlabel/domain/project/service/ProjectService.java +++ b/backend/src/main/java/com/worlabel/domain/project/service/ProjectService.java @@ -144,7 +144,7 @@ public class ProjectService { participantRepository.save(participant); } - @CheckPrivilege(PrivilegeType.ADMIN) + @CheckPrivilege(PrivilegeType.MANAGER) public void changeProjectMember(final Integer projectId, final ParticipantRequest participantRequest) { checkNotAdminParticipant(participantRequest.getMemberId(), projectId); @@ -191,10 +191,12 @@ public class ProjectService { AiModel aiModel = getAiModel(request); AutoLabelingRequest autoLabelingRequest = AutoLabelingRequest.of(projectId, aiModel.getModelKey(), labelMap, imageRequestList); - log.debug("요청 {}", autoLabelingRequest); + log.debug("요청 이미지 개수 :{}", imageRequestList.size()); List list = aiService.postRequest(endPoint, autoLabelingRequest, List.class, this::converter); + saveAutoLabelList(list); + log.debug("응답 이미지 개수 :{}", list.size()); alarmService.save(memberId, Alarm.AlarmType.PREDICT); } finally { @@ -207,7 +209,7 @@ public class ProjectService { public void saveAutoLabelList(final List resultList) { for (AutoLabelingResult result : resultList) { Image image = getImage(result.getImageId()); - if (image.getStatus() == LabelStatus.SAVE || image.getStatus() == LabelStatus.IN_PROGRESS) continue; + if (image.getStatus() == LabelStatus.SAVE || image.getStatus() == LabelStatus.REVIEW_REQUEST || image.getStatus() == LabelStatus.REVIEW_REJECT) continue; String dataPath = image.getDataPath(); s3UploadService.uploadJson(result.getData(), dataPath); image.updateStatus(LabelStatus.IN_PROGRESS); diff --git a/backend/src/main/java/com/worlabel/global/config/RestTemplateConfig.java b/backend/src/main/java/com/worlabel/global/config/RestTemplateConfig.java new file mode 100644 index 0000000..20a9e6d --- /dev/null +++ b/backend/src/main/java/com/worlabel/global/config/RestTemplateConfig.java @@ -0,0 +1,20 @@ +package com.worlabel.global.config; + +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +import java.time.Duration; + +@Configuration +public class RestTemplateConfig { + + @Bean + public RestTemplate restTemplate(RestTemplateBuilder builder) { + return builder + .setConnectTimeout(Duration.ZERO) + .setReadTimeout(Duration.ZERO) + .build(); + } +} diff --git a/backend/src/main/java/com/worlabel/global/config/WebConfig.java b/backend/src/main/java/com/worlabel/global/config/WebConfig.java index 7116fc6..ced073e 100644 --- a/backend/src/main/java/com/worlabel/global/config/WebConfig.java +++ b/backend/src/main/java/com/worlabel/global/config/WebConfig.java @@ -2,9 +2,8 @@ package com.worlabel.global.config; import com.worlabel.global.resolver.CurrentUserArgumentResolver; import lombok.RequiredArgsConstructor; -import org.springframework.context.annotation.Bean; + import org.springframework.context.annotation.Configuration; -import org.springframework.web.client.RestTemplate; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -20,9 +19,4 @@ public class WebConfig implements WebMvcConfigurer { public void addArgumentResolvers(List resolvers) { resolvers.add(currentUserArgumentResolver); } - - @Bean - public RestTemplate restTemplate() { - return new RestTemplate(); - } }