Merge pull request '[KC-108] ai api 실행' (#200) from feat/infer_dev_260107 into develop
Reviewed-on: https://kamco.gitea.gs.dabeeo.com/dabeeo/kamco-dabeeo-backoffice/pulls/200
This commit is contained in:
@@ -14,17 +14,18 @@ public class ExternalHttpClient {
|
|||||||
|
|
||||||
private final RestTemplate restTemplate;
|
private final RestTemplate restTemplate;
|
||||||
|
|
||||||
public ResponseEntity<String> exchange(
|
public <T> ResponseEntity<T> exchange(
|
||||||
String url, HttpMethod method, Object body, HttpHeaders headers) {
|
String url, HttpMethod method, Object body, HttpHeaders headers, Class<T> responseType) {
|
||||||
HttpEntity<Object> entity = new HttpEntity<>(body, headers);
|
HttpEntity<Object> entity = new HttpEntity<>(body, headers);
|
||||||
return restTemplate.exchange(url, method, entity, String.class);
|
return restTemplate.exchange(url, method, entity, responseType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExternalCallResult call(String url, HttpMethod method, Object body, HttpHeaders headers) {
|
public <T> ExternalCallResult<T> call(
|
||||||
ResponseEntity<String> res = exchange(url, method, body, headers);
|
String url, HttpMethod method, Object body, HttpHeaders headers, Class<T> responseType) {
|
||||||
|
ResponseEntity<T> res = exchange(url, method, body, headers, responseType);
|
||||||
int code = res.getStatusCodeValue();
|
int code = res.getStatusCodeValue();
|
||||||
return new ExternalCallResult(code, code >= 200 && code < 300, res.getBody());
|
return new ExternalCallResult<>(code, code >= 200 && code < 300, res.getBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
public record ExternalCallResult(int statusCode, boolean success, String body) {}
|
public record ExternalCallResult<T>(int statusCode, boolean success, T body) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.kamco.cd.kamcoback.inference.service;
|
package com.kamco.cd.kamcoback.inference.service;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.kamco.cd.kamcoback.common.exception.CustomApiException;
|
|
||||||
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient;
|
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient;
|
||||||
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient.ExternalCallResult;
|
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient.ExternalCallResult;
|
||||||
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto;
|
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto;
|
||||||
@@ -34,7 +33,6 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -53,6 +51,9 @@ public class InferenceResultService {
|
|||||||
@Value("${inference.url}")
|
@Value("${inference.url}")
|
||||||
private String inferenceUrl;
|
private String inferenceUrl;
|
||||||
|
|
||||||
|
@Value("${spring.profiles.active}")
|
||||||
|
private String profile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 추론관리 목록
|
* 추론관리 목록
|
||||||
*
|
*
|
||||||
@@ -205,9 +206,7 @@ public class InferenceResultService {
|
|||||||
private void ensureAccepted(InferenceSendDto dto) {
|
private void ensureAccepted(InferenceSendDto dto) {
|
||||||
log.info("dto null? {}", dto == null);
|
log.info("dto null? {}", dto == null);
|
||||||
ObjectMapper om = new ObjectMapper();
|
ObjectMapper om = new ObjectMapper();
|
||||||
String json = "";
|
|
||||||
try {
|
try {
|
||||||
json = om.writeValueAsString(dto);
|
|
||||||
log.info("dto json={}", om.writeValueAsString(dto));
|
log.info("dto json={}", om.writeValueAsString(dto));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
@@ -217,12 +216,17 @@ public class InferenceResultService {
|
|||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
|
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
|
||||||
|
|
||||||
ExternalCallResult result =
|
// TODO 추후 삭제
|
||||||
externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers);
|
if ("local".equals(profile)) {
|
||||||
|
dto.getPred_requests_areas().setInput1_scene_path("/kamco-nfs/requests/2023_local.geojson");
|
||||||
if (!result.success()) {
|
dto.getPred_requests_areas().setInput2_scene_path("/kamco-nfs/requests/2024_local.geojson");
|
||||||
throw new CustomApiException("BAD_GATEWAY", HttpStatus.BAD_GATEWAY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExternalCallResult<String> result =
|
||||||
|
externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers, String.class);
|
||||||
|
|
||||||
|
int status = result.statusCode();
|
||||||
|
String body = result.body();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -110,9 +110,12 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
|
|||||||
queryFactory
|
queryFactory
|
||||||
.select(modelMngEntity.modelUid.count())
|
.select(modelMngEntity.modelUid.count())
|
||||||
.from(modelMngEntity)
|
.from(modelMngEntity)
|
||||||
|
.innerJoin(modelResultMetricEntity)
|
||||||
|
.on(modelMngEntity.modelUid.eq(modelResultMetricEntity.modelUid))
|
||||||
.where(
|
.where(
|
||||||
eventEndedAtBetween(startDate, endDate, property),
|
eventEndedAtBetween(startDate, endDate, property),
|
||||||
searchModelVersion(modelType, searchVal))
|
searchModelVersion(modelType, searchVal),
|
||||||
|
modelMngEntity.deleted.isFalse().or(modelMngEntity.deleted.isNull()))
|
||||||
.fetchOne();
|
.fetchOne();
|
||||||
|
|
||||||
return new PageImpl<>(foundContent, pageable, countQuery);
|
return new PageImpl<>(foundContent, pageable, countQuery);
|
||||||
|
|||||||
Reference in New Issue
Block a user