Merge branch 'be/develop' into 'be/refactor/image'

# Conflicts:
#   backend/src/main/java/com/worlabel/domain/image/controller/ImageController.java
#   backend/src/main/java/com/worlabel/domain/image/service/ImageService.java
This commit is contained in:
김용수 2024-10-08 15:43:48 +09:00
commit e290e0cf8a
6 changed files with 67 additions and 12 deletions

View File

@ -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.AiModelRequest;
import com.worlabel.domain.model.entity.dto.AiModelResponse; 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.entity.dto.ModelTrainRequest;
import com.worlabel.domain.model.service.AiModelService; 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.annotation.CurrentUser;
import com.worlabel.global.config.swagger.SwaggerApiError; import com.worlabel.global.config.swagger.SwaggerApiError;
import com.worlabel.global.config.swagger.SwaggerApiSuccess; import com.worlabel.global.config.swagger.SwaggerApiSuccess;
@ -82,4 +81,12 @@ public class AiModelController {
log.debug("다운로드 요청 projectId : {} modelId : {}", projectId, modelId); log.debug("다운로드 요청 projectId : {} modelId : {}", projectId, modelId);
return aiModelService.modelDownload(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();
}
} }

View File

@ -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;
}

View File

@ -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);
}
} }

View File

@ -144,7 +144,7 @@ public class ProjectService {
participantRepository.save(participant); participantRepository.save(participant);
} }
@CheckPrivilege(PrivilegeType.ADMIN) @CheckPrivilege(PrivilegeType.MANAGER)
public void changeProjectMember(final Integer projectId, final ParticipantRequest participantRequest) { public void changeProjectMember(final Integer projectId, final ParticipantRequest participantRequest) {
checkNotAdminParticipant(participantRequest.getMemberId(), projectId); checkNotAdminParticipant(participantRequest.getMemberId(), projectId);
@ -191,10 +191,12 @@ public class ProjectService {
AiModel aiModel = getAiModel(request); AiModel aiModel = getAiModel(request);
AutoLabelingRequest autoLabelingRequest = AutoLabelingRequest.of(projectId, aiModel.getModelKey(), labelMap, imageRequestList); AutoLabelingRequest autoLabelingRequest = AutoLabelingRequest.of(projectId, aiModel.getModelKey(), labelMap, imageRequestList);
log.debug("요청 {}", autoLabelingRequest); log.debug("요청 이미지 개수 :{}", imageRequestList.size());
List<AutoLabelingResult> list = aiService.postRequest(endPoint, autoLabelingRequest, List.class, this::converter); List<AutoLabelingResult> list = aiService.postRequest(endPoint, autoLabelingRequest, List.class, this::converter);
saveAutoLabelList(list); saveAutoLabelList(list);
log.debug("응답 이미지 개수 :{}", list.size());
alarmService.save(memberId, Alarm.AlarmType.PREDICT); alarmService.save(memberId, Alarm.AlarmType.PREDICT);
} finally { } finally {
@ -207,7 +209,7 @@ public class ProjectService {
public void saveAutoLabelList(final List<AutoLabelingResult> resultList) { public void saveAutoLabelList(final List<AutoLabelingResult> resultList) {
for (AutoLabelingResult result : resultList) { for (AutoLabelingResult result : resultList) {
Image image = getImage(result.getImageId()); 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(); String dataPath = image.getDataPath();
s3UploadService.uploadJson(result.getData(), dataPath); s3UploadService.uploadJson(result.getData(), dataPath);
image.updateStatus(LabelStatus.IN_PROGRESS); image.updateStatus(LabelStatus.IN_PROGRESS);

View File

@ -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();
}
}

View File

@ -2,9 +2,8 @@ package com.worlabel.global.config;
import com.worlabel.global.resolver.CurrentUserArgumentResolver; import com.worlabel.global.resolver.CurrentUserArgumentResolver;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@ -20,9 +19,4 @@ public class WebConfig implements WebMvcConfigurer {
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) { public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(currentUserArgumentResolver); resolvers.add(currentUserArgumentResolver);
} }
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
} }