추론실행 shp파일 생성 jar
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package com.kamco.cd.kamcoback.common.service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Log4j2
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ExternalJarRunner {
|
||||
|
||||
public void run(String jarPath, String batchIds, String inferenceId, String mapIds) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
|
||||
try {
|
||||
List<String> cmd = new ArrayList<>();
|
||||
cmd.add("java");
|
||||
cmd.add("-jar");
|
||||
cmd.add(jarPath);
|
||||
|
||||
if (inferenceId != null && !inferenceId.isBlank()) {
|
||||
cmd.add("--converter.inference-id=" + inferenceId);
|
||||
}
|
||||
if (mapIds != null && !mapIds.isBlank()) {
|
||||
cmd.add("--converter.map-ids=" + mapIds);
|
||||
}
|
||||
if (batchIds != null && !batchIds.isBlank()) {
|
||||
cmd.add("--converter.batch-ids=" + batchIds);
|
||||
}
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(cmd);
|
||||
pb.redirectErrorStream(true);
|
||||
|
||||
Process p = pb.start();
|
||||
|
||||
try (BufferedReader br =
|
||||
new BufferedReader(new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
out.append(line).append('\n');
|
||||
log.info("[jar] {}", line);
|
||||
}
|
||||
}
|
||||
|
||||
boolean finished = p.waitFor(30, TimeUnit.MINUTES);
|
||||
if (!finished) {
|
||||
p.destroyForcibly();
|
||||
throw new RuntimeException("jar timeout\n" + out);
|
||||
}
|
||||
|
||||
int exit = p.exitValue();
|
||||
if (exit != 0) {
|
||||
throw new RuntimeException("jar failed. exitCode=" + exit + "\n" + out);
|
||||
}
|
||||
|
||||
log.info("jar finished successfully");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("jar execution error. output=\n{}", out, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user