Compare commits
2 Commits
5d417d85ff
...
e69eccc82b
| Author | SHA1 | Date | |
|---|---|---|---|
| e69eccc82b | |||
| 828a4c5dca |
@@ -1,23 +1,47 @@
|
|||||||
package com.kamco.cd.kamcoback.common.service;
|
package com.kamco.cd.kamcoback.common.service;
|
||||||
|
|
||||||
|
import com.kamco.cd.kamcoback.config.InferenceProperties;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Log4j2
|
@Log4j2
|
||||||
|
//0312
|
||||||
|
@RequiredArgsConstructor
|
||||||
@Component
|
@Component
|
||||||
|
|
||||||
public class ExternalJarRunner {
|
public class ExternalJarRunner {
|
||||||
@Value("${spring.profiles.active}")
|
@Value("${spring.profiles.active}")
|
||||||
private String profile;
|
private String profile;
|
||||||
|
//0312
|
||||||
|
private final InferenceProperties inferenceProperties;
|
||||||
|
|
||||||
private static final long TIMEOUT_MINUTES = TimeUnit.DAYS.toMinutes(3);
|
private static final long TIMEOUT_MINUTES = TimeUnit.DAYS.toMinutes(3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// java -jar build/libs/shp-exporter.jar --batch --geoserver.enabled=true --converter.inference-id=qq99999 --converter.batch-ids[0]=111
|
||||||
|
//0312 shp 파일 배치를 통해 생성
|
||||||
|
public void run(String inferenceLearningId, List<Long> batchIds){
|
||||||
|
//JAR 경로 (shape파일 생성용)
|
||||||
|
String jarPathV2 = inferenceProperties.getJarPathV2();
|
||||||
|
List<String> args = new ArrayList<>();
|
||||||
|
args.add(" --spring.profiles.active="+profile);
|
||||||
|
args.add(" --batch");
|
||||||
|
args.add(" --geoserver.enabled=true");
|
||||||
|
args.add(" --converter.inference-id="+inferenceLearningId);
|
||||||
|
batchIds.forEach(batchId -> args.add(" --converter.batch-ids["+args.size()+"]="+batchId));
|
||||||
|
execJar(jarPathV2, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shp 파일 생성
|
* shp 파일 생성
|
||||||
*
|
*
|
||||||
@@ -74,7 +98,8 @@ public class ExternalJarRunner {
|
|||||||
cmd.add("-jar");
|
cmd.add("-jar");
|
||||||
cmd.add(jarPath);
|
cmd.add(jarPath);
|
||||||
cmd.addAll(args);
|
cmd.addAll(args);
|
||||||
|
//0312
|
||||||
|
log.info("exec jar command: {}", cmd);
|
||||||
ProcessBuilder pb = new ProcessBuilder(cmd);
|
ProcessBuilder pb = new ProcessBuilder(cmd);
|
||||||
pb.redirectErrorStream(true);
|
pb.redirectErrorStream(true);
|
||||||
|
|
||||||
@@ -135,3 +160,4 @@ public class ExternalJarRunner {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,5 +16,7 @@ public class InferenceProperties {
|
|||||||
private String batchUrl;
|
private String batchUrl;
|
||||||
private String geojsonDir;
|
private String geojsonDir;
|
||||||
private String jarPath;
|
private String jarPath;
|
||||||
|
//0312
|
||||||
|
private String jarPathV2;
|
||||||
private String inferenceServerName;
|
private String inferenceServerName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,9 @@ public class SecurityConfig {
|
|||||||
auth
|
auth
|
||||||
|
|
||||||
// .requestMatchers("/chunk_upload_test.html").authenticated()
|
// .requestMatchers("/chunk_upload_test.html").authenticated()
|
||||||
.requestMatchers("/monitor/health", "/monitor/health/**")
|
.requestMatchers("/monitor/health"
|
||||||
|
, "/monitor/health/**"
|
||||||
|
)
|
||||||
.permitAll()
|
.permitAll()
|
||||||
|
|
||||||
// 맵시트 영역 전체 허용 (우선순위 최상단)
|
// 맵시트 영역 전체 허용 (우선순위 최상단)
|
||||||
@@ -71,6 +73,10 @@ public class SecurityConfig {
|
|||||||
.requestMatchers("/api/test/review")
|
.requestMatchers("/api/test/review")
|
||||||
.hasAnyRole("ADMIN", "REVIEWER")
|
.hasAnyRole("ADMIN", "REVIEWER")
|
||||||
|
|
||||||
|
// shapefile 생성 테스트 API - 인증 없이 접근 가능
|
||||||
|
.requestMatchers("/api/test/make-shapefile")
|
||||||
|
.permitAll()
|
||||||
|
|
||||||
// ASYNC/ERROR 재디스패치는 막지 않기 (다운로드/스트리밍에서 필수)
|
// ASYNC/ERROR 재디스패치는 막지 않기 (다운로드/스트리밍에서 필수)
|
||||||
.dispatcherTypeMatchers(DispatcherType.ASYNC, DispatcherType.ERROR)
|
.dispatcherTypeMatchers(DispatcherType.ASYNC, DispatcherType.ERROR)
|
||||||
.permitAll()
|
.permitAll()
|
||||||
@@ -113,7 +119,8 @@ public class SecurityConfig {
|
|||||||
"/api/user/**",
|
"/api/user/**",
|
||||||
"/api/my/menus",
|
"/api/my/menus",
|
||||||
"/api/training-data/label/**",
|
"/api/training-data/label/**",
|
||||||
"/api/training-data/review/**")
|
"/api/training-data/review/**"
|
||||||
|
)
|
||||||
.authenticated()
|
.authenticated()
|
||||||
|
|
||||||
// 나머지는 메뉴권한
|
// 나머지는 메뉴권한
|
||||||
|
|||||||
@@ -255,8 +255,9 @@ public class MapSheetInferenceJobService {
|
|||||||
// 추론 종료일때 shp 파일 생성
|
// 추론 종료일때 shp 파일 생성
|
||||||
String batchIdStr = batchIds.stream().map(String::valueOf).collect(Collectors.joining(","));
|
String batchIdStr = batchIds.stream().map(String::valueOf).collect(Collectors.joining(","));
|
||||||
|
|
||||||
// shp 파일 비동기 생성
|
//0312 shp 파일 비동기 생성 (바꿔주세요)
|
||||||
shpPipelineService.runPipeline(jarPath, datasetDir, batchIdStr, sheet.getUid());
|
shpPipelineService.makeShapeFile(sheet.getUid(),batchIds);
|
||||||
|
//shpPipelineService.runPipeline(jarPath, datasetDir, batchIdStr, sheet.getUid());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.kamco.cd.kamcoback.common.service.ExternalJarRunner;
|
|||||||
import com.kamco.cd.kamcoback.postgres.core.InferenceResultCoreService;
|
import com.kamco.cd.kamcoback.postgres.core.InferenceResultCoreService;
|
||||||
import com.kamco.cd.kamcoback.scheduler.config.ShpKeyLock;
|
import com.kamco.cd.kamcoback.scheduler.config.ShpKeyLock;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
@@ -18,6 +19,32 @@ public class ShpPipelineService {
|
|||||||
private final ExternalJarRunner externalJarRunner;
|
private final ExternalJarRunner externalJarRunner;
|
||||||
private final ShpKeyLock shpKeyLock;
|
private final ShpKeyLock shpKeyLock;
|
||||||
|
|
||||||
|
|
||||||
|
//0312 shp 파일 비동기 생성
|
||||||
|
@Async("makeShapeFile")
|
||||||
|
public void makeShapeFile(String inferenceId, List<Long> batchIds) {
|
||||||
|
if (!shpKeyLock.tryLock(inferenceId)) {
|
||||||
|
log.info("");
|
||||||
|
log.info("============================================================");
|
||||||
|
log.info("SHP pipeline already running. inferenceId={}", inferenceId);
|
||||||
|
log.info("============================================================");
|
||||||
|
try {
|
||||||
|
log.info("SHP pipeline already start. inferenceId={}", inferenceId);
|
||||||
|
externalJarRunner.run(inferenceId, batchIds);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("SHP pipeline failed. inferenceId={}", inferenceId, e);
|
||||||
|
// TODO 실패 상태 업데이트 로직 추가
|
||||||
|
} finally {
|
||||||
|
log.info("============================================================");
|
||||||
|
log.info("SHP pipeline DONE. inferenceId={}", inferenceId);
|
||||||
|
log.info("============================================================");
|
||||||
|
log.info("");
|
||||||
|
shpKeyLock.unlock(inferenceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shp 파일 생성 1. merge 생성 2. 생성된 merge shp 파일로 geoserver 등록, 3.도엽별로 shp 생성
|
* shp 파일 생성 1. merge 생성 2. 생성된 merge shp 파일로 geoserver 등록, 3.도엽별로 shp 생성
|
||||||
*
|
*
|
||||||
@@ -36,24 +63,33 @@ public class ShpPipelineService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
log.info("");
|
||||||
|
log.info("============================================================");
|
||||||
|
log.info("SHP pipeline started. inferenceId={}", inferenceId);
|
||||||
|
log.info("============================================================");
|
||||||
|
|
||||||
// uid 기준 merge shp, geojson 파일 생성
|
// uid 기준 merge shp, geojson 파일 생성
|
||||||
externalJarRunner.run(jarPath, batchIds, inferenceId, "", "MERGED");
|
externalJarRunner.run(jarPath, batchIds, inferenceId, "", "MERGED");
|
||||||
|
|
||||||
// uid 기준 shp 파일 geoserver 등록
|
// uid 기준 shp 파일 geoserver 등록
|
||||||
String register =
|
// String register =
|
||||||
Paths.get(datasetDir, inferenceId, "merge", inferenceId + ".shp").toString();
|
// Paths.get(datasetDir, inferenceId, "merge", inferenceId + ".shp").toString();
|
||||||
log.info("register={}", register);
|
// log.info("register={}", register);
|
||||||
externalJarRunner.run(jarPath, register, inferenceId);
|
// externalJarRunner.run(jarPath, register, inferenceId);
|
||||||
|
//
|
||||||
// uid 기준 도엽별 shp, geojson 파일 생성
|
// // uid 기준 도엽별 shp, geojson 파일 생성
|
||||||
externalJarRunner.run(jarPath, batchIds, inferenceId, "", "RESOLVE");
|
// externalJarRunner.run(jarPath, batchIds, inferenceId, "", "RESOLVE");
|
||||||
|
//
|
||||||
log.info("SHP pipeline finished. inferenceId={}", inferenceId);
|
// log.info("SHP pipeline finished. inferenceId={}", inferenceId);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("SHP pipeline failed. inferenceId={}", inferenceId, e);
|
log.error("SHP pipeline failed. inferenceId={}", inferenceId, e);
|
||||||
// TODO 실패 상태 업데이트 로직 추가
|
// TODO 실패 상태 업데이트 로직 추가
|
||||||
} finally {
|
} finally {
|
||||||
|
log.info("============================================================");
|
||||||
|
log.info("SHP pipeline DONE. inferenceId={}", inferenceId);
|
||||||
|
log.info("============================================================");
|
||||||
shpKeyLock.unlock(inferenceId);
|
shpKeyLock.unlock(inferenceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package com.kamco.cd.kamcoback.test;
|
||||||
|
|
||||||
|
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||||
|
import com.kamco.cd.kamcoback.scheduler.service.ShpPipelineService;
|
||||||
|
import io.swagger.v3.oas.annotations.Hidden;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.ErrorResponse;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Hidden
|
||||||
|
@Tag(name = "test shape api", description = "test shape api")
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
|
||||||
|
@RequestMapping("/api/test")
|
||||||
|
public class TestShapeApiController {
|
||||||
|
|
||||||
|
private final ShpPipelineService shpPipelineService;
|
||||||
|
|
||||||
|
@Operation(summary = "shapefile 생성 테스트", description = "지정된 inference ID와 batch ID 목록으로 shapefile을 생성합니다.")
|
||||||
|
@ApiResponses({
|
||||||
|
@ApiResponse(
|
||||||
|
responseCode = "200",
|
||||||
|
description = "shapefile 생성 요청 성공",
|
||||||
|
content = @Content(schema = @Schema(implementation = String.class))),
|
||||||
|
@ApiResponse(
|
||||||
|
responseCode = "400",
|
||||||
|
description = "잘못된 요청 데이터",
|
||||||
|
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
|
||||||
|
@ApiResponse(
|
||||||
|
responseCode = "500",
|
||||||
|
description = "서버 오류",
|
||||||
|
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
|
||||||
|
})
|
||||||
|
@GetMapping("/make-shapefile")
|
||||||
|
public ApiResponseDto<String> makeShapeFile(
|
||||||
|
@RequestParam String inferenceId,
|
||||||
|
@RequestParam List<Long> batchIds) {
|
||||||
|
shpPipelineService.makeShapeFile(inferenceId, batchIds);
|
||||||
|
return ApiResponseDto.ok("Shapefile 생성이 시작되었습니다. inferenceId: " + inferenceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -100,6 +100,7 @@ inference:
|
|||||||
url: http://192.168.2.183:8000/jobs
|
url: http://192.168.2.183:8000/jobs
|
||||||
batch-url: http://192.168.2.183:8000/batches
|
batch-url: http://192.168.2.183:8000/batches
|
||||||
jar-path: ${inference.nfs}/repo/jar/shp-exporter.jar
|
jar-path: ${inference.nfs}/repo/jar/shp-exporter.jar
|
||||||
|
jar-path-v2: ${inference.nfs}/repo/jar/shp-exporter-v2.jar
|
||||||
inference-server-name: server1,server2,server3,server4
|
inference-server-name: server1,server2,server3,server4
|
||||||
output-dir: ${inference.nfs}/model_output/export
|
output-dir: ${inference.nfs}/model_output/export
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ inference:
|
|||||||
url: http://10.100.0.11:8000/jobs
|
url: http://10.100.0.11:8000/jobs
|
||||||
batch-url: http://10.100.0.11:8000/batches
|
batch-url: http://10.100.0.11:8000/batches
|
||||||
jar-path: jar/shp-exporter.jar
|
jar-path: jar/shp-exporter.jar
|
||||||
|
jar-path-v2: jar/shp-exporter-v2.jar
|
||||||
inference-server-name: server1,server2,server3,server4
|
inference-server-name: server1,server2,server3,server4
|
||||||
output-dir: ${inference.nfs}/model_output/export
|
output-dir: ${inference.nfs}/model_output/export
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,8 @@ inference:
|
|||||||
url: http://172.16.4.56:8000/jobs
|
url: http://172.16.4.56:8000/jobs
|
||||||
batch-url: http://172.16.4.56:8000/batches
|
batch-url: http://172.16.4.56:8000/batches
|
||||||
jar-path: ${inference.nfs}/repo/jar/shp-exporter.jar
|
jar-path: ${inference.nfs}/repo/jar/shp-exporter.jar
|
||||||
|
# //0312
|
||||||
|
jar-path-v2: ${inference.nfs}/repo/jar/shp-exporter-v2.jar
|
||||||
inference-server-name: server1,server2,server3,server4
|
inference-server-name: server1,server2,server3,server4
|
||||||
output-dir: ${inference.nfs}/model_output/export
|
output-dir: ${inference.nfs}/model_output/export
|
||||||
|
|
||||||
|
|||||||
@@ -88,3 +88,6 @@ inference:
|
|||||||
nfs: /kamco-nfs
|
nfs: /kamco-nfs
|
||||||
geojson-dir: ${inference.nfs}/requests/ # 추론실행을 위한 파일생성경로
|
geojson-dir: ${inference.nfs}/requests/ # 추론실행을 위한 파일생성경로
|
||||||
jar-path: ${inference.nfs}/repo/jar/shp-exporter.jar
|
jar-path: ${inference.nfs}/repo/jar/shp-exporter.jar
|
||||||
|
# //0312
|
||||||
|
jar-path-v2: ${inference.nfs}/repo/jar/shp-exporter-v2.jar
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user