추론관리 목록 조회 수정, 추론 종료 추가
This commit is contained in:
@@ -1,30 +1,72 @@
|
||||
package com.kamco.cd.kamcoback.config.resttemplate;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.HttpServerErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
@RequiredArgsConstructor
|
||||
public class ExternalHttpClient {
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
public <T> ResponseEntity<T> exchange(
|
||||
String url, HttpMethod method, Object body, HttpHeaders headers, Class<T> responseType) {
|
||||
HttpEntity<Object> entity = new HttpEntity<>(body, headers);
|
||||
return restTemplate.exchange(url, method, entity, responseType);
|
||||
}
|
||||
|
||||
public <T> ExternalCallResult<T> call(
|
||||
String url, HttpMethod method, Object body, HttpHeaders headers, Class<T> responseType) {
|
||||
ResponseEntity<T> res = exchange(url, method, body, headers, responseType);
|
||||
int code = res.getStatusCodeValue();
|
||||
return new ExternalCallResult<>(code, code >= 200 && code < 300, res.getBody());
|
||||
|
||||
HttpEntity<Object> entity = new HttpEntity<>(body, headers);
|
||||
|
||||
// 요청 로그
|
||||
log.info("[HTTP-REQ] {} {}", method, url);
|
||||
if (body != null) {
|
||||
log.debug("[HTTP-REQ-BODY] {}", body);
|
||||
}
|
||||
|
||||
try {
|
||||
ResponseEntity<T> res = restTemplate.exchange(url, method, entity, responseType);
|
||||
|
||||
int code = res.getStatusCodeValue();
|
||||
|
||||
// 응답 로그
|
||||
log.info("[HTTP-RES] {} {} -> {}", method, url, code);
|
||||
log.debug("[HTTP-RES-BODY] {}", res.getBody());
|
||||
|
||||
return new ExternalCallResult<>(code, code >= 200 && code < 300, res.getBody());
|
||||
|
||||
} catch (HttpClientErrorException.NotFound e) {
|
||||
// ⭐ 핵심: 404를 예외가 아닌 결과로 처리
|
||||
log.info("[HTTP-RES] {} {} -> 404 (Not Found)", method, url);
|
||||
log.debug("[HTTP-RES-BODY] {}", e.getResponseBodyAsString());
|
||||
|
||||
return new ExternalCallResult<>(404, false, null);
|
||||
|
||||
} catch (HttpClientErrorException e) {
|
||||
// 기타 4xx
|
||||
log.warn(
|
||||
"[HTTP-ERR] {} {} -> {} body={}",
|
||||
method,
|
||||
url,
|
||||
e.getStatusCode().value(),
|
||||
e.getResponseBodyAsString());
|
||||
throw e;
|
||||
|
||||
} catch (HttpServerErrorException e) {
|
||||
// 5xx
|
||||
log.error(
|
||||
"[HTTP-ERR] {} {} -> {} body={}",
|
||||
method,
|
||||
url,
|
||||
e.getStatusCode().value(),
|
||||
e.getResponseBodyAsString());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public record ExternalCallResult<T>(int statusCode, boolean success, T body) {}
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -139,6 +140,25 @@ public class InferenceResultApiController {
|
||||
return ApiResponseDto.ok(uuid);
|
||||
}
|
||||
|
||||
@Operation(summary = "추론 종료", description = "추론 종료")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "201",
|
||||
description = "종료 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = Page.class))),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 검색 조건", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@DeleteMapping("/end")
|
||||
public ApiResponseDto<Void> getInferenceGeomList() {
|
||||
inferenceResultService.deleteInferenceEnd();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Operation(summary = "분석 모델 선택 조회", description = "변화탐지 실행 정보 입력 모델선택 팝업 ")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
|
||||
@@ -84,7 +84,11 @@ public class InferenceResultService {
|
||||
* @return
|
||||
*/
|
||||
public UUID getProcessing() {
|
||||
return inferenceResultCoreService.getProcessing();
|
||||
SaveInferenceAiDto dto = inferenceResultCoreService.getProcessing();
|
||||
if (dto == null) {
|
||||
return null;
|
||||
}
|
||||
return dto.getUuid();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,7 +188,7 @@ public class InferenceResultService {
|
||||
m1.setPred_requests_areas(predRequestsAreas);
|
||||
|
||||
// ai 추론 실행 api 호출
|
||||
Long batchId = 0L; // ensureAccepted(m1);
|
||||
Long batchId = ensureAccepted(m1);
|
||||
|
||||
// ai 추론 실행후 응답값 update
|
||||
SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto();
|
||||
@@ -487,4 +491,27 @@ public class InferenceResultService {
|
||||
public Page<Geom> getInferenceGeomList(String uuid, SearchGeoReq searchGeoReq) {
|
||||
return inferenceResultCoreService.getInferenceGeomList(uuid, searchGeoReq);
|
||||
}
|
||||
|
||||
public void deleteInferenceEnd() {
|
||||
SaveInferenceAiDto dto = inferenceResultCoreService.getProcessing();
|
||||
if (dto == null) {
|
||||
throw new CustomApiException("NOT_FOUND", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
Long batchId = dto.getBatchId();
|
||||
String url = inferenceUrl + "/" + batchId;
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
|
||||
|
||||
ExternalCallResult<String> result =
|
||||
externalHttpClient.call(url, HttpMethod.DELETE, dto, headers, String.class);
|
||||
|
||||
System.out.println(result);
|
||||
|
||||
SaveInferenceAiDto request = new SaveInferenceAiDto();
|
||||
request.setStatus(Status.END.getId());
|
||||
request.setUuid(dto.getUuid());
|
||||
inferenceResultCoreService.update(request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,8 +379,26 @@ public class InferenceResultCoreService {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public UUID getProcessing() {
|
||||
return mapSheetLearnRepository.getProcessing();
|
||||
public SaveInferenceAiDto getProcessing() {
|
||||
MapSheetLearnEntity entity = mapSheetLearnRepository.getProcessing();
|
||||
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SaveInferenceAiDto dto = new SaveInferenceAiDto();
|
||||
dto.setUuid(entity.getUuid());
|
||||
|
||||
if (entity.getM3ModelBatchId() != null) {
|
||||
dto.setBatchId(entity.getM3ModelBatchId());
|
||||
}
|
||||
if (entity.getM2ModelBatchId() != null) {
|
||||
dto.setBatchId(entity.getM2ModelBatchId());
|
||||
}
|
||||
if (entity.getM1ModelBatchId() != null) {
|
||||
dto.setBatchId(entity.getM1ModelBatchId());
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,7 +28,7 @@ public interface MapSheetLearnRepositoryCustom {
|
||||
|
||||
InferenceStatusDetailDto getInferenceStatus(UUID uuid);
|
||||
|
||||
UUID getProcessing();
|
||||
MapSheetLearnEntity getProcessing();
|
||||
|
||||
Integer getLearnStage(Integer compareYear, Integer targetYear);
|
||||
|
||||
|
||||
@@ -259,9 +259,9 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public UUID getProcessing() {
|
||||
public MapSheetLearnEntity getProcessing() {
|
||||
return queryFactory
|
||||
.select(mapSheetLearnEntity.uuid)
|
||||
.select(mapSheetLearnEntity)
|
||||
.from(mapSheetLearnEntity)
|
||||
.where(mapSheetLearnEntity.status.eq("IN_PROGRESS"))
|
||||
.fetchOne();
|
||||
|
||||
@@ -52,7 +52,7 @@ public class MapSheetInferenceJobService {
|
||||
@Transactional
|
||||
public void runBatch() {
|
||||
if (isLocalProfile()) {
|
||||
return;
|
||||
// return;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -133,6 +133,10 @@ public class MapSheetInferenceJobService {
|
||||
externalHttpClient.call(url, HttpMethod.GET, null, jsonHeaders(), String.class);
|
||||
|
||||
int status = result.statusCode();
|
||||
if (status == 404) {
|
||||
log.info("Batch not found. batchId={}", batchId);
|
||||
return null;
|
||||
}
|
||||
if (status < 200 || status >= 300) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user