[KC-108] ai api batch 작업중
This commit is contained in:
@@ -221,17 +221,17 @@ public class InferenceResultApiController {
|
||||
|
||||
@Operation(summary = "추론관리 추론진행 서버 현황", description = "추론관리 추론진행 서버 현황")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "검색 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = Page.class))),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 검색 조건", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "검색 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = Page.class))),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 검색 조건", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@GetMapping("/serverStatus")
|
||||
public ApiResponseDto<List<InferenceServerStatusDto>> getInferenceServerStatusList() {
|
||||
|
||||
|
||||
@@ -129,10 +129,7 @@ public class InferenceResultDto {
|
||||
}
|
||||
|
||||
public static Status fromCode(String code) {
|
||||
return Arrays.stream(values())
|
||||
.filter(v -> v.name().equals(code))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalArgumentException("알 수 없는 상태 코드: " + code));
|
||||
return Arrays.stream(values()).filter(v -> v.name().equals(code)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static String getDescByCode(String code) {
|
||||
@@ -205,81 +202,81 @@ public class InferenceResultDto {
|
||||
public static class InferenceServerStatusDto {
|
||||
|
||||
private String serverName;
|
||||
@JsonIgnore
|
||||
private float cpu_user;
|
||||
@JsonIgnore private float cpu_user;
|
||||
@JsonIgnore private float cpu_system;
|
||||
@JsonIgnore private float memused;
|
||||
private Long kbmemused;
|
||||
private float gpuUtil;
|
||||
//private String cpuStatusName;
|
||||
//private String memStatusName;
|
||||
//private String gpuStatusName;
|
||||
//private float cpu_use_rate;
|
||||
//private float gpu_use_rate;
|
||||
//private float mem_use_rate;
|
||||
|
||||
public float getCpuUseRate()
|
||||
{
|
||||
return this.cpu_user+this.cpu_system;
|
||||
// private String cpuStatusName;
|
||||
// private String memStatusName;
|
||||
// private String gpuStatusName;
|
||||
// private float cpu_use_rate;
|
||||
// private float gpu_use_rate;
|
||||
// private float mem_use_rate;
|
||||
|
||||
public float getCpuUseRate() {
|
||||
return this.cpu_user + this.cpu_system;
|
||||
}
|
||||
|
||||
public String getServerStatus()
|
||||
{
|
||||
public String getServerStatus() {
|
||||
String enumId = "SAFETY";
|
||||
//if( this.cpu_user+this.cpu_system >= 80 )enumId = "CAUTION";
|
||||
// if( this.cpu_user+this.cpu_system >= 80 )enumId = "CAUTION";
|
||||
return enumId;
|
||||
}
|
||||
|
||||
public String getServerStatusName()
|
||||
{
|
||||
//String enumId = "SAFETY";
|
||||
//if( this.cpu_user+this.cpu_system >= 80 )enumId = "CAUTION";
|
||||
public String getServerStatusName() {
|
||||
// String enumId = "SAFETY";
|
||||
// if( this.cpu_user+this.cpu_system >= 80 )enumId = "CAUTION";
|
||||
return ServerStatus.SAFETY.getText();
|
||||
}
|
||||
|
||||
public String getCpuStatus()
|
||||
{
|
||||
public String getCpuStatus() {
|
||||
String enumId = "SAFETY";
|
||||
if( this.cpu_user+this.cpu_system >= 80 )enumId = "CAUTION";
|
||||
if (this.cpu_user + this.cpu_system >= 80) {
|
||||
enumId = "CAUTION";
|
||||
}
|
||||
return enumId;
|
||||
}
|
||||
|
||||
public String getGpuStatus()
|
||||
{
|
||||
public String getGpuStatus() {
|
||||
String enumId = "SAFETY";
|
||||
if( this.gpuUtil >= 80 )enumId = "CAUTION";
|
||||
if (this.gpuUtil >= 80) {
|
||||
enumId = "CAUTION";
|
||||
}
|
||||
return enumId;
|
||||
}
|
||||
|
||||
public String getMemStatus()
|
||||
{
|
||||
public String getMemStatus() {
|
||||
String enumId = "SAFETY";
|
||||
if( this.memused >= 80 )enumId = "CAUTION";
|
||||
if (this.memused >= 80) {
|
||||
enumId = "CAUTION";
|
||||
}
|
||||
return enumId;
|
||||
}
|
||||
|
||||
public String getCpuStatusName()
|
||||
{
|
||||
if( this.cpu_user+this.cpu_system >= 80 )return ServerStatus.CAUTION.getText();
|
||||
public String getCpuStatusName() {
|
||||
if (this.cpu_user + this.cpu_system >= 80) {
|
||||
return ServerStatus.CAUTION.getText();
|
||||
}
|
||||
return ServerStatus.SAFETY.getText();
|
||||
}
|
||||
|
||||
public String getGpuStatusName()
|
||||
{
|
||||
if( this.gpuUtil >= 80 )return ServerStatus.CAUTION.getText();
|
||||
public String getGpuStatusName() {
|
||||
if (this.gpuUtil >= 80) {
|
||||
return ServerStatus.CAUTION.getText();
|
||||
}
|
||||
return ServerStatus.SAFETY.getText();
|
||||
}
|
||||
|
||||
public String getMemStatusName()
|
||||
{
|
||||
if( this.memused >= 80 )return ServerStatus.CAUTION.getText();
|
||||
public String getMemStatusName() {
|
||||
if (this.memused >= 80) {
|
||||
return ServerStatus.CAUTION.getText();
|
||||
}
|
||||
return ServerStatus.SAFETY.getText();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ServerStatus implements EnumType {
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.InferenceServerSt
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.MapSheetNumDto;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.MapSheetScope;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.ResultList;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.Status;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceSendDto;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceSendDto.pred_requests_areas;
|
||||
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto.MngListCompareDto;
|
||||
@@ -199,7 +200,7 @@ public class InferenceResultService {
|
||||
m3.setPred_requests_areas(predRequestsAreas);
|
||||
|
||||
Long batchId = this.ensureAccepted(m1);
|
||||
inferenceResultCoreService.update(uuid, batchId, "IN_PROGRESS");
|
||||
inferenceResultCoreService.update(uuid, batchId, Status.IN_PROGRESS.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -228,6 +228,15 @@ public class InferenceResultCoreService {
|
||||
entity.setStatus(status);
|
||||
}
|
||||
|
||||
public List<InferenceServerStatusDto> getInferenceServerStatusList(){return mapSheetLearnRepository.getInferenceServerStatusList();
|
||||
public List<InferenceServerStatusDto> getInferenceServerStatusList() {
|
||||
return mapSheetLearnRepository.getInferenceServerStatusList();
|
||||
}
|
||||
|
||||
public Long getInferenceResultByStatus(String status) {
|
||||
MapSheetLearnEntity entity =
|
||||
mapSheetLearnRepository
|
||||
.getInferenceResultByStatus(status)
|
||||
.orElseThrow(() -> new EntityNotFoundException(status));
|
||||
return entity.getBatchId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,5 +44,4 @@ public class GpuMetricEntity {
|
||||
|
||||
@Column(name = "gpu_mem_total")
|
||||
private Float gpuMemTotal;
|
||||
|
||||
}
|
||||
|
||||
@@ -55,5 +55,4 @@ public class SystemMetricEntity {
|
||||
|
||||
@Column(name = "memused")
|
||||
private Float memused;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package com.kamco.cd.kamcoback.postgres.repository.Inference;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.InferenceServerStatusDto;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MapSheetLearnEntity;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.List;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
public interface MapSheetLearnRepositoryCustom {
|
||||
@@ -15,4 +15,6 @@ public interface MapSheetLearnRepositoryCustom {
|
||||
Optional<MapSheetLearnEntity> getInferenceResultByUuid(UUID uuid);
|
||||
|
||||
List<InferenceServerStatusDto> getInferenceServerStatusList();
|
||||
|
||||
Optional<MapSheetLearnEntity> getInferenceResultByStatus(String status);
|
||||
}
|
||||
|
||||
@@ -94,35 +94,49 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
|
||||
|
||||
BooleanBuilder builder = new BooleanBuilder();
|
||||
|
||||
List<Integer> latestIds = queryFactory
|
||||
.select(systemMetricEntity.id1.max())
|
||||
.from(systemMetricEntity)
|
||||
.groupBy(systemMetricEntity.serverName)
|
||||
.fetch();
|
||||
List<Integer> latestIds =
|
||||
queryFactory
|
||||
.select(systemMetricEntity.id1.max())
|
||||
.from(systemMetricEntity)
|
||||
.groupBy(systemMetricEntity.serverName)
|
||||
.fetch();
|
||||
|
||||
List<Integer> latestGpuIds = queryFactory
|
||||
.select(gpuMetricEntity.id1.max())
|
||||
.from(gpuMetricEntity)
|
||||
.groupBy(gpuMetricEntity.serverName)
|
||||
.fetch();
|
||||
List<Integer> latestGpuIds =
|
||||
queryFactory
|
||||
.select(gpuMetricEntity.id1.max())
|
||||
.from(gpuMetricEntity)
|
||||
.groupBy(gpuMetricEntity.serverName)
|
||||
.fetch();
|
||||
|
||||
List<InferenceServerStatusDto> foundContent = queryFactory
|
||||
.select(Projections.constructor(
|
||||
InferenceServerStatusDto.class,
|
||||
systemMetricEntity.serverName,
|
||||
systemMetricEntity.cpuUser,
|
||||
systemMetricEntity.cpuSystem,
|
||||
systemMetricEntity.memused,
|
||||
systemMetricEntity.kbmemused,
|
||||
gpuMetricEntity.gpuUtil
|
||||
))
|
||||
.from(systemMetricEntity)
|
||||
.leftJoin(gpuMetricEntity).on(gpuMetricEntity.serverName.eq(systemMetricEntity.serverName))
|
||||
.where(systemMetricEntity.id1.in(latestIds)) // In 절 사용
|
||||
.orderBy(systemMetricEntity.serverName.asc())
|
||||
.limit(4)
|
||||
.fetch();
|
||||
List<InferenceServerStatusDto> foundContent =
|
||||
queryFactory
|
||||
.select(
|
||||
Projections.constructor(
|
||||
InferenceServerStatusDto.class,
|
||||
systemMetricEntity.serverName,
|
||||
systemMetricEntity.cpuUser,
|
||||
systemMetricEntity.cpuSystem,
|
||||
systemMetricEntity.memused,
|
||||
systemMetricEntity.kbmemused,
|
||||
gpuMetricEntity.gpuUtil))
|
||||
.from(systemMetricEntity)
|
||||
.leftJoin(gpuMetricEntity)
|
||||
.on(gpuMetricEntity.serverName.eq(systemMetricEntity.serverName))
|
||||
.where(systemMetricEntity.id1.in(latestIds)) // In 절 사용
|
||||
.orderBy(systemMetricEntity.serverName.asc())
|
||||
.limit(4)
|
||||
.fetch();
|
||||
|
||||
return foundContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<MapSheetLearnEntity> getInferenceResultByStatus(String status) {
|
||||
return Optional.ofNullable(
|
||||
queryFactory
|
||||
.selectFrom(mapSheetLearnEntity)
|
||||
.where(mapSheetLearnEntity.status.eq(status))
|
||||
.limit(1)
|
||||
.fetchOne());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.kamco.cd.kamcoback.scheduler.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class JobStatusDto {
|
||||
|
||||
private Long id;
|
||||
|
||||
@JsonProperty("created_at")
|
||||
private ZonedDateTime createdAt;
|
||||
|
||||
@JsonProperty("input1_year")
|
||||
private Integer input1Year;
|
||||
|
||||
@JsonProperty("input2_year")
|
||||
private Integer input2Year;
|
||||
|
||||
@JsonProperty("total_jobs")
|
||||
private Integer totalJobs;
|
||||
|
||||
@JsonProperty("pending_jobs")
|
||||
private Integer pendingJobs;
|
||||
|
||||
@JsonProperty("running_jobs")
|
||||
private Integer runningJobs;
|
||||
|
||||
@JsonProperty("completed_jobs")
|
||||
private Integer completedJobs;
|
||||
|
||||
@JsonProperty("failed_jobs")
|
||||
private Integer failedJobs;
|
||||
|
||||
private String status;
|
||||
|
||||
private List<Object> jobs;
|
||||
|
||||
@JsonProperty("completed_ids")
|
||||
private List<String> completedIds;
|
||||
|
||||
@JsonProperty("processing_ids")
|
||||
private List<String> processingIds;
|
||||
|
||||
@JsonProperty("queued_ids")
|
||||
private List<String> queuedIds;
|
||||
|
||||
@JsonProperty("failed_ids")
|
||||
private List<String> failedIds;
|
||||
}
|
||||
@@ -1,8 +1,19 @@
|
||||
package com.kamco.cd.kamcoback.scheduler.service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient;
|
||||
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient.ExternalCallResult;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.Status;
|
||||
import com.kamco.cd.kamcoback.postgres.core.InferenceResultCoreService;
|
||||
import com.kamco.cd.kamcoback.scheduler.dto.JobStatusDto;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -12,6 +23,12 @@ import org.springframework.stereotype.Service;
|
||||
public class MapSheetInferenceJobService {
|
||||
|
||||
private final InferenceResultCoreService inferenceResultCoreService;
|
||||
private final ExternalHttpClient externalHttpClient;
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Value("${inference.batch-url}")
|
||||
private String batchUrl;
|
||||
|
||||
@Scheduled(fixedDelay = 60_000)
|
||||
public void runBatch() {
|
||||
@@ -19,8 +36,36 @@ public class MapSheetInferenceJobService {
|
||||
|
||||
try {
|
||||
// TODO: 배치 로직 작성
|
||||
|
||||
Long batchId =
|
||||
inferenceResultCoreService.getInferenceResultByStatus(Status.IN_PROGRESS.getId());
|
||||
|
||||
if (batchId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
|
||||
|
||||
String url = batchUrl + "/" + batchId;
|
||||
|
||||
ExternalCallResult<String> result =
|
||||
externalHttpClient.call(url, HttpMethod.GET, null, headers, String.class);
|
||||
|
||||
int status = result.statusCode();
|
||||
if (status < 200 || status >= 300) {
|
||||
return;
|
||||
}
|
||||
|
||||
String json = result.body();
|
||||
JobStatusDto dto = objectMapper.readValue(json, JobStatusDto.class);
|
||||
|
||||
System.out.println(dto);
|
||||
|
||||
Thread.sleep(3000); // 예시: 처리 시간 3초
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
} catch (InterruptedException | JsonProcessingException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.error("배치 중 인터럽트 발생", e);
|
||||
}
|
||||
|
||||
@@ -97,4 +97,5 @@ file:
|
||||
|
||||
inference:
|
||||
url: http://10.100.0.11:8000/jobs
|
||||
batch-url: http://10.100.0.11:8000/batches
|
||||
geojson-dir: /kamco-nfs/requests/
|
||||
|
||||
@@ -83,4 +83,5 @@ file:
|
||||
|
||||
inference:
|
||||
url: http://10.100.0.11:8000/jobs
|
||||
batch-url: http://10.100.0.11:8000/batches
|
||||
geojson-dir: /kamco-nfs/requests/
|
||||
|
||||
@@ -58,5 +58,6 @@ file:
|
||||
|
||||
inference:
|
||||
url: http://10.100.0.11:8000/jobs
|
||||
batch-url: http://10.100.0.11:8000/batches
|
||||
geojson-dir: /kamco-nfs/requests/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user