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