Unverified Commit 90c8b61d authored by gaoyan's avatar gaoyan Committed by GitHub

Fix some npe (#2705)

* fix log error * Fix some Npe, and optimize some code logic * add some null check * add some null check
parent 95c544b5
......@@ -26,7 +26,6 @@ import org.dinky.data.enums.ProcessType;
import org.dinky.data.enums.SseTopic;
import org.dinky.data.enums.Status;
import org.dinky.data.exception.BusException;
import org.dinky.data.exception.DinkyException;
import org.dinky.data.model.ProcessEntity;
import org.dinky.data.model.ProcessStepEntity;
import org.dinky.utils.LogUtil;
......@@ -94,7 +93,7 @@ public class ConsoleContextHolder {
*
* @param processName process name
* @param stepPid process step type
* @param logLine messages
* @param logLine messages
* @throws BusException Throws an exception if the process does not exist
*/
public void appendLog(String processName, String stepPid, String logLine, boolean recordGlobal) {
......@@ -108,7 +107,12 @@ public class ConsoleContextHolder {
}
if (stepPid != null) {
ProcessStepEntity stepNode = getStepNode(stepPid, getStepsMap(processName));
stepNode.appendLog(logLine);
if (stepNode != null) {
stepNode.appendLog(logLine);
process.setLastUpdateStep(stepNode);
} else {
log.error("process step not found {},{}", processName, stepPid);
}
process.setLastUpdateStep(stepNode);
}
// /TOPIC/PROCESS_CONSOLE/FlinkSubmit/12
......@@ -172,7 +176,11 @@ public class ConsoleContextHolder {
process.getChildren().add(processStepEntity);
} else {
ProcessStepEntity stepNode = getStepNode(parentStepPid, process.getChildren());
stepNode.getChildren().add(processStepEntity);
if (stepNode == null) {
log.error("registerProcessStep {} failed in {}", type.getDesc(), processName);
} else {
stepNode.getChildren().add(processStepEntity);
}
}
return processStepEntity;
}
......@@ -241,7 +249,8 @@ public class ConsoleContextHolder {
JSONObject.toJSONString(logPross),
stepPid,
MDC.get(ProcessAspect.PROCESS_NAME));
throw new DinkyException(errorStr);
log.debug(errorStr);
return null;
}
/**
......
......@@ -159,7 +159,7 @@ public class SseSessionContextHolder {
SseDataVo data = new SseDataVo(sessionKey, topic, content);
sendSse(sessionKey, data);
} catch (Exception e) {
log.error("Error sending sse data", e);
log.error("Error sending sse data:{}", e.getMessage());
onError(sessionKey, e);
}
}
......
......@@ -151,9 +151,10 @@ public class JobInstanceServiceImpl extends SuperServiceImpl<JobInstanceMapper,
@Override
public JobInfoDetail getJobInfoDetailInfo(JobInstance jobInstance) {
Asserts.checkNull(jobInstance, Status.JOB_INSTANCE_NOT_EXIST.getMessage());
JobInfoDetail jobInfoDetail = new JobInfoDetail(jobInstance.getId());
Asserts.checkNull(jobInstance, Status.JOB_INSTANCE_NOT_EXIST.getMessage());
jobInfoDetail.setInstance(jobInstance);
ClusterInstance clusterInstance = clusterInstanceService.getById(jobInstance.getClusterId());
......
......@@ -19,7 +19,7 @@
package org.dinky.assertion;
import org.dinky.data.exception.RunTimeException;
import org.dinky.data.exception.BusException;
import java.util.Arrays;
import java.util.Collection;
......@@ -89,31 +89,31 @@ public class Asserts {
public static void checkNull(Object key, String msg) {
if (key == null) {
throw new RunTimeException(msg);
throw new BusException(msg);
}
}
public static void checkNotNull(Object object, String msg) {
if (isNull(object)) {
throw new RunTimeException(msg);
throw new BusException(msg);
}
}
public static void checkNullString(String key, String msg) {
if (isNull(key) || isEquals("", key)) {
throw new RunTimeException(msg);
throw new BusException(msg);
}
}
public static void checkNullCollection(Collection<?> collection, String msg) {
if (isNullCollection(collection)) {
throw new RunTimeException(msg);
throw new BusException(msg);
}
}
public static void checkNullMap(Map<?, ?> map, String msg) {
if (isNullMap(map)) {
throw new RunTimeException(msg);
throw new BusException(msg);
}
}
}
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