Unverified Commit 4eec3d59 authored by ZackYoung's avatar ZackYoung Committed by GitHub

[fix][git]Fix issues such as abnormal exit during git construction (#1997)

* Fix issues such as abnormal exit during git construction * Fix issues such as abnormal exit during git construction
parent 89a4606a
......@@ -17,36 +17,30 @@
*
*/
package org.dinky.sse;
package org.dinky.context;
import java.io.Serializable;
import org.dinky.function.constant.PathConstant;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
/**
* @author ZackYoung
* @since 0.8.0
*/
@Setter
@Getter
public class StepState implements Serializable {
private Integer currentStep;
// 1.log 2.data
private Integer type;
private Object content;
/** 2-success 1-process 0-failed */
private Integer status;
private Boolean history;
public static StepState genHistoryLog(Integer currentStep, Integer status, String log) {
StepState stepState = new StepState();
stepState.setHistory(true);
stepState.setContent(log);
stepState.setType(1);
stepState.setCurrentStep(currentStep);
stepState.setStatus(status);
return stepState;
import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONUtil;
public class GitBuildContextHolder {
private static final List<Integer> RUNNING_LIST = new ArrayList<>();
public static void addRun(Integer id) {
RUNNING_LIST.add(id);
FileUtil.writeUtf8String(
JSONUtil.toJsonStr(getAll()), PathConstant.TMP_PATH + "/build.list");
}
public static void remove(Integer id) {
RUNNING_LIST.remove(id);
}
public static List<Integer> getAll() {
return new ArrayList<>(RUNNING_LIST);
}
}
......@@ -30,4 +30,5 @@ import lombok.Setter;
public class GitAnalysisJarDTO {
private String jarPath;
private List<String> classList;
private Integer orderLine = 1;
}
......@@ -23,6 +23,7 @@ import org.dinky.assertion.Asserts;
import org.dinky.context.TenantContextHolder;
import org.dinky.daemon.task.DaemonFactory;
import org.dinky.daemon.task.DaemonTaskConfig;
import org.dinky.function.constant.PathConstant;
import org.dinky.function.pool.UdfCodePool;
import org.dinky.job.FlinkJobTask;
import org.dinky.model.JobInstance;
......@@ -36,6 +37,7 @@ import org.dinky.service.JobInstanceService;
import org.dinky.service.SysConfigService;
import org.dinky.service.TaskService;
import org.dinky.service.TenantService;
import org.dinky.utils.JSONUtil;
import org.dinky.utils.UDFUtils;
import java.util.ArrayList;
......@@ -49,6 +51,9 @@ import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import cn.hutool.core.io.FileUtil;
import lombok.RequiredArgsConstructor;
/**
......@@ -81,6 +86,7 @@ public class SystemInit implements ApplicationRunner {
initTaskMonitor();
initDolphinScheduler();
registerUDF();
updateGitBuildState();
}
/** init task monitor */
......@@ -130,4 +136,18 @@ public class SystemInit implements ApplicationRunner {
UdfCodePool.updateGitPool(gitProjectService.getGitPool());
TenantContextHolder.set(null);
}
public void updateGitBuildState() {
String path = PathConstant.TMP_PATH + "/build.list";
if (FileUtil.exist(path)) {
List<Integer> runningList =
JSONUtil.toList(FileUtil.readUtf8String(path), Integer.class);
gitProjectService.list().stream()
.filter(x -> x.getBuildState().equals(1))
.filter(x -> runningList.contains(x.getId()))
.peek(x -> x.setBuildState(2))
.forEach(Model::updateById);
FileUtil.del(path);
}
}
}
......@@ -19,6 +19,7 @@
package org.dinky.sse;
import org.dinky.context.GitBuildContextHolder;
import org.dinky.model.GitProject;
import java.io.File;
......@@ -212,6 +213,9 @@ public abstract class StepSse {
}
});
// Manual GC is required here to release file IO(此处需要手动GC,释放文件IO)
GitProject gitProject = (GitProject) params.get("gitProject");
GitBuildContextHolder.remove(gitProject.getId());
System.gc();
}
......@@ -236,6 +240,7 @@ public abstract class StepSse {
// "status":1 # 2完成 1进行中 0失败
//
// }
Object dataResult =
(data instanceof List) ? StrUtil.join("\n", data) : JSONUtil.toJsonStr(data);
return Dict.create()
......@@ -247,20 +252,6 @@ public abstract class StepSse {
.set("status", status);
}
protected Dict getLog(String data) {
return Dict.create()
.set("type", 1)
.set("currentStep", getStep())
.set("resultType", 1)
.set("data", data)
.set("currentStepName", name)
.set("status", status);
}
protected Dict getLogObj() {
return getLogObj(msgList);
}
protected Dict getEndLog() {
return Dict.create()
.set("type", 1)
......
......@@ -27,6 +27,7 @@ import org.dinky.sse.StepSse;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
......@@ -77,16 +78,21 @@ public class AnalysisUdfClassStepSse extends StepSse {
sendMsg(Dict.create().set(jar, udfClassByJar));
});
AtomicInteger index = new AtomicInteger(1);
udfMap.forEach(
(k, v) -> {
GitAnalysisJarDTO gitAnalysisJarDTO = new GitAnalysisJarDTO();
gitAnalysisJarDTO.setJarPath(k);
gitAnalysisJarDTO.setClassList(
v.stream().map(Class::getName).collect(Collectors.toList()));
gitAnalysisJarDTO.setOrderLine(index.get());
index.getAndIncrement();
dataList.add(gitAnalysisJarDTO);
});
dataList.sort(Comparator.comparing(GitAnalysisJarDTO::getOrderLine));
String data = JSONUtil.toJsonStr(dataList);
sendMsg(getList(null).set("data", data));
FileUtil.appendString(data, getLogFile(), StandardCharsets.UTF_8);
......
......@@ -20,6 +20,7 @@
package org.dinky.utils;
import org.dinky.common.result.StepResult;
import org.dinky.context.GitBuildContextHolder;
import org.dinky.model.GitProject;
import org.dinky.process.exception.DinkyException;
import org.dinky.sse.DoneStepSse;
......@@ -66,6 +67,7 @@ public final class GitProjectStepSseFactory {
gitProject.setBuildState(1);
gitProject.updateById();
GitBuildContextHolder.addRun(gitProject.getId());
sseEmitterMap.put(gitProject.getId(), emitterList);
}
......
......@@ -22,12 +22,14 @@ package org.dinky.utils;
import java.io.File;
import java.util.List;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* @author ZackYoung
* @since 0.8.0
*/
@Disabled
public class GitRepositoryTests {
// ssh-keygen -m PEM -t ecdsa
GitRepository sshRepository =
......
......@@ -29,6 +29,7 @@ import java.net.URLStreamHandlerFactory;
import java.util.Collection;
import java.util.List;
import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;
/** @since 0.7.0 */
......@@ -77,11 +78,25 @@ public class DinkyClassLoader extends URLClassLoader {
for (String path : paths) {
File file = new File(path);
try {
if (file.isDirectory()) {
FileUtil.walkFiles(
file,
f -> {
if (FileUtil.getSuffix(f).equals("jar")) {
try {
super.addURL(f.toURI().toURL());
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
});
continue;
}
if (!file.exists()) {
if (notExistsFiles != null && !notExistsFiles.isEmpty()) {
notExistsFiles.add(file.getAbsolutePath());
}
return;
continue;
}
super.addURL(file.toURI().toURL());
FlinkUdfPathContextHolder.addOtherPlugins(file);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment