Unverified Commit 26b10ca7 authored by gaoyan's avatar gaoyan Committed by GitHub

[Optimize ]optimize exception throw (#3116)

parent 9063fe8e
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package org.dinky.assertion; package org.dinky.assertion;
import org.dinky.data.dto.TaskDTO;
import org.dinky.data.enums.Status;
import org.dinky.data.exception.BusException; import org.dinky.data.exception.BusException;
import org.dinky.data.model.ClusterInstance; import org.dinky.data.model.ClusterInstance;
import org.dinky.data.model.Task; import org.dinky.data.model.Task;
...@@ -28,7 +30,7 @@ import org.dinky.data.model.Task; ...@@ -28,7 +30,7 @@ import org.dinky.data.model.Task;
* *
* @since 2021/5/30 11:13 * @since 2021/5/30 11:13
*/ */
public interface Assert { public interface DinkyAssert {
static void check(ClusterInstance clusterInstance) { static void check(ClusterInstance clusterInstance) {
if (clusterInstance.getId() == null) { if (clusterInstance.getId() == null) {
...@@ -36,9 +38,27 @@ public interface Assert { ...@@ -36,9 +38,27 @@ public interface Assert {
} }
} }
static void check(TaskDTO task) {
if (task == null) {
throw new BusException(Status.TASK_NOT_EXIST);
}
}
static void check(Task task) { static void check(Task task) {
if (task == null) { if (task == null) {
throw new BusException("作业不存在"); throw new BusException(Status.TASK_NOT_EXIST);
}
}
static void checkNull(Object o, Status status) {
if (o == null) {
throw new BusException(status);
}
}
static void checkNull(Object o, String msg) {
if (o == null) {
throw new BusException(msg);
} }
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.dinky.service.impl; package org.dinky.service.impl;
import org.dinky.assertion.DinkyAssert;
import org.dinky.data.dto.ClusterConfigurationDTO; import org.dinky.data.dto.ClusterConfigurationDTO;
import org.dinky.data.enums.Status; import org.dinky.data.enums.Status;
import org.dinky.data.exception.BusException; import org.dinky.data.exception.BusException;
...@@ -45,8 +46,6 @@ import org.springframework.stereotype.Service; ...@@ -45,8 +46,6 @@ import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.hutool.core.lang.Assert;
/** /**
* ClusterConfigServiceImpl * ClusterConfigServiceImpl
* *
...@@ -76,7 +75,7 @@ public class ClusterConfigurationServiceImpl extends SuperServiceImpl<ClusterCon ...@@ -76,7 +75,7 @@ public class ClusterConfigurationServiceImpl extends SuperServiceImpl<ClusterCon
@Override @Override
public FlinkClusterConfig getFlinkClusterCfg(Integer id) { public FlinkClusterConfig getFlinkClusterCfg(Integer id) {
ClusterConfiguration cfg = this.getClusterConfigById(id); ClusterConfiguration cfg = this.getClusterConfigById(id);
Assert.notNull(cfg, "The clusterConfiguration not exists!"); DinkyAssert.checkNull(cfg, "The clusterConfiguration not exists!");
return FlinkClusterConfig.create(cfg.getType(), cfg.getConfigJson()); return FlinkClusterConfig.create(cfg.getType(), cfg.getConfigJson());
} }
......
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
package org.dinky.service.impl; package org.dinky.service.impl;
import org.dinky.assertion.Assert;
import org.dinky.assertion.Asserts; import org.dinky.assertion.Asserts;
import org.dinky.assertion.DinkyAssert;
import org.dinky.cluster.FlinkCluster; import org.dinky.cluster.FlinkCluster;
import org.dinky.cluster.FlinkClusterInfo; import org.dinky.cluster.FlinkClusterInfo;
import org.dinky.data.dto.ClusterInstanceDTO; import org.dinky.data.dto.ClusterInstanceDTO;
...@@ -84,14 +84,14 @@ public class ClusterInstanceServiceImpl extends SuperServiceImpl<ClusterInstance ...@@ -84,14 +84,14 @@ public class ClusterInstanceServiceImpl extends SuperServiceImpl<ClusterInstance
@Override @Override
public String getJobManagerAddress(ClusterInstance clusterInstance) { public String getJobManagerAddress(ClusterInstance clusterInstance) {
// TODO 这里判空逻辑有问题,clusterInstance有可能为null // TODO 这里判空逻辑有问题,clusterInstance有可能为null
Assert.check(clusterInstance); DinkyAssert.check(clusterInstance);
FlinkClusterInfo info = FlinkClusterInfo info =
FlinkCluster.testFlinkJobManagerIP(clusterInstance.getHosts(), clusterInstance.getJobManagerHost()); FlinkCluster.testFlinkJobManagerIP(clusterInstance.getHosts(), clusterInstance.getJobManagerHost());
String host = null; String host = null;
if (info.isEffective()) { if (info.isEffective()) {
host = info.getJobManagerAddress(); host = info.getJobManagerAddress();
} }
Assert.checkHost(host); DinkyAssert.checkHost(host);
if (!host.equals(clusterInstance.getJobManagerHost())) { if (!host.equals(clusterInstance.getJobManagerHost())) {
clusterInstance.setJobManagerHost(host); clusterInstance.setJobManagerHost(host);
updateById(clusterInstance); updateById(clusterInstance);
......
...@@ -23,11 +23,14 @@ import org.dinky.context.LdapContext; ...@@ -23,11 +23,14 @@ import org.dinky.context.LdapContext;
import org.dinky.data.dto.LoginDTO; import org.dinky.data.dto.LoginDTO;
import org.dinky.data.enums.Status; import org.dinky.data.enums.Status;
import org.dinky.data.exception.AuthException; import org.dinky.data.exception.AuthException;
import org.dinky.data.exception.BusException;
import org.dinky.data.model.LdapUserIdentification; import org.dinky.data.model.LdapUserIdentification;
import org.dinky.data.model.SystemConfiguration; import org.dinky.data.model.SystemConfiguration;
import org.dinky.data.model.rbac.User; import org.dinky.data.model.rbac.User;
import org.dinky.service.LdapService; import org.dinky.service.LdapService;
import org.apache.http.util.TextUtils;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
...@@ -39,7 +42,6 @@ import org.springframework.ldap.AuthenticationException; ...@@ -39,7 +42,6 @@ import org.springframework.ldap.AuthenticationException;
import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.core.LdapTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import cn.hutool.core.lang.Assert;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Service @Service
...@@ -112,7 +114,9 @@ public class LdapServiceImpl implements LdapService { ...@@ -112,7 +114,9 @@ public class LdapServiceImpl implements LdapService {
@Override @Override
public List<User> listUsers() { public List<User> listUsers() {
String filter = configuration.getLdapFilter().getValue(); String filter = configuration.getLdapFilter().getValue();
Assert.notBlank(filter, Status.LDAP_FILTER_INCORRECT.getMessage()); if (TextUtils.isEmpty(filter)) {
throw new BusException(Status.LDAP_FILTER_INCORRECT);
}
LdapTemplate ldapTemplate = new LdapTemplate(LdapContext.getLdapContext()); LdapTemplate ldapTemplate = new LdapTemplate(LdapContext.getLdapContext());
List<User> result = ldapTemplate.search( List<User> result = ldapTemplate.search(
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
package org.dinky.service.impl; package org.dinky.service.impl;
import org.dinky.assertion.Asserts; import org.dinky.assertion.Asserts;
import org.dinky.assertion.DinkyAssert;
import org.dinky.config.Dialect; import org.dinky.config.Dialect;
import org.dinky.context.TenantContextHolder; import org.dinky.context.TenantContextHolder;
import org.dinky.data.annotations.ProcessStep; import org.dinky.data.annotations.ProcessStep;
...@@ -174,7 +175,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -174,7 +175,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
log.info("Start check and config task, task:{}", task.getName()); log.info("Start check and config task, task:{}", task.getName());
Assert.notNull(task, Status.TASK_NOT_EXIST.getMessage()); DinkyAssert.check(task);
if (StringUtils.isNotBlank(submitDto.getSavePointPath())) { if (StringUtils.isNotBlank(submitDto.getSavePointPath())) {
task.setSavePointStrategy(SavePointStrategy.CUSTOM.getValue()); task.setSavePointStrategy(SavePointStrategy.CUSTOM.getValue());
...@@ -359,10 +360,10 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -359,10 +360,10 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
TaskDTO task = this.getTaskInfoById(id); TaskDTO task = this.getTaskInfoById(id);
boolean useSavepoint = !TextUtils.isEmpty(savePointPath); boolean useSavepoint = !TextUtils.isEmpty(savePointPath);
Asserts.checkNull(task, Status.TASK_NOT_EXIST.getMessage()); DinkyAssert.check(task);
if (!Dialect.isCommonSql(task.getDialect()) && Asserts.isNotNull(task.getJobInstanceId())) { if (!Dialect.isCommonSql(task.getDialect()) && Asserts.isNotNull(task.getJobInstanceId())) {
JobInstance jobInstance = jobInstanceService.getById(task.getJobInstanceId()); JobInstance jobInstance = jobInstanceService.getById(task.getJobInstanceId());
Assert.notNull(jobInstance, Status.JOB_INSTANCE_NOT_EXIST.getMessage()); DinkyAssert.checkNull(jobInstance, Status.JOB_INSTANCE_NOT_EXIST);
String status = jobInstance.getStatus(); String status = jobInstance.getStatus();
if (!JobStatus.isDone(status)) { if (!JobStatus.isDone(status)) {
log.info("JobInstance [{}] status is [{}], stop it now", jobInstance.getName(), status); log.info("JobInstance [{}] status is [{}], stop it now", jobInstance.getName(), status);
...@@ -409,9 +410,9 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -409,9 +410,9 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
return true; return true;
} }
JobInstance jobInstance = jobInstanceService.getById(task.getJobInstanceId()); JobInstance jobInstance = jobInstanceService.getById(task.getJobInstanceId());
Assert.notNull(jobInstance, Status.JOB_INSTANCE_NOT_EXIST.getMessage()); DinkyAssert.checkNull(jobInstance, Status.JOB_INSTANCE_NOT_EXIST.getMessage());
ClusterInstance clusterInstance = clusterInstanceService.getById(jobInstance.getClusterId()); ClusterInstance clusterInstance = clusterInstanceService.getById(jobInstance.getClusterId());
Assert.notNull(clusterInstance, Status.CLUSTER_NOT_EXIST.getMessage()); DinkyAssert.checkNull(clusterInstance, Status.CLUSTER_NOT_EXIST.getMessage());
JobManager jobManager; JobManager jobManager;
try { try {
...@@ -446,7 +447,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -446,7 +447,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
@Override @Override
public SavePointResult savepointTaskJob(TaskDTO task, SavePointType savePointType) { public SavePointResult savepointTaskJob(TaskDTO task, SavePointType savePointType) {
JobInstance jobInstance = jobInstanceService.getById(task.getJobInstanceId()); JobInstance jobInstance = jobInstanceService.getById(task.getJobInstanceId());
Assert.notNull(jobInstance, Status.JOB_INSTANCE_NOT_EXIST.getMessage()); DinkyAssert.checkNull(jobInstance, Status.JOB_INSTANCE_NOT_EXIST.getMessage());
JobManager jobManager = JobManager.build(buildJobConfig(task)); JobManager jobManager = JobManager.build(buildJobConfig(task));
String jobId = jobInstance.getJid(); String jobId = jobInstance.getJid();
...@@ -490,7 +491,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -490,7 +491,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
@Override @Override
public String exportSql(Integer id) { public String exportSql(Integer id) {
TaskDTO task = this.getTaskInfoById(id); TaskDTO task = this.getTaskInfoById(id);
Asserts.checkNull(task, Status.TASK_NOT_EXIST.getMessage()); DinkyAssert.check(task);
if (Dialect.isCommonSql(task.getDialect())) { if (Dialect.isCommonSql(task.getDialect())) {
return task.getStatement(); return task.getStatement();
} }
...@@ -514,7 +515,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -514,7 +515,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
@Override @Override
public TaskDTO getTaskInfoById(Integer id) { public TaskDTO getTaskInfoById(Integer id) {
Task mTask = this.getById(id); Task mTask = this.getById(id);
Assert.notNull(mTask, Status.TASK_NOT_EXIST.getMessage()); DinkyAssert.check(mTask);
TaskDTO taskDTO = new TaskDTO(); TaskDTO taskDTO = new TaskDTO();
BeanUtil.copyProperties(mTask, taskDTO); BeanUtil.copyProperties(mTask, taskDTO);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.dinky.service.resource.impl; package org.dinky.service.resource.impl;
import org.dinky.assertion.DinkyAssert;
import org.dinky.data.dto.TreeNodeDTO; import org.dinky.data.dto.TreeNodeDTO;
import org.dinky.data.enums.Status; import org.dinky.data.enums.Status;
import org.dinky.data.exception.BusException; import org.dinky.data.exception.BusException;
...@@ -137,7 +138,7 @@ public class ResourceServiceImpl extends ServiceImpl<ResourcesMapper, Resources> ...@@ -137,7 +138,7 @@ public class ResourceServiceImpl extends ServiceImpl<ResourcesMapper, Resources>
public void rename(Integer id, String fileName, String desc) { public void rename(Integer id, String fileName, String desc) {
Resources byId = getById(id); Resources byId = getById(id);
String sourceFullName = byId.getFullName(); String sourceFullName = byId.getFullName();
Assert.notNull(byId, () -> new BusException("resource is not exists!")); DinkyAssert.checkNull(byId, Status.RESOURCE_DIR_OR_FILE_NOT_EXIST);
long count = count(new LambdaQueryWrapper<Resources>() long count = count(new LambdaQueryWrapper<Resources>()
.eq(Resources::getPid, byId.getPid()) .eq(Resources::getPid, byId.getPid())
.eq(Resources::getFileName, fileName) .eq(Resources::getFileName, fileName)
...@@ -216,7 +217,7 @@ public class ResourceServiceImpl extends ServiceImpl<ResourcesMapper, Resources> ...@@ -216,7 +217,7 @@ public class ResourceServiceImpl extends ServiceImpl<ResourcesMapper, Resources>
@Override @Override
public String getContentByResourceId(Integer id) { public String getContentByResourceId(Integer id) {
Resources resources = getById(id); Resources resources = getById(id);
Assert.notNull(resources, () -> new BusException(Status.RESOURCE_DIR_OR_FILE_NOT_EXIST)); DinkyAssert.checkNull(resources, Status.RESOURCE_DIR_OR_FILE_NOT_EXIST);
Assert.isFalse(resources.getSize() > ALLOW_MAX_CAT_CONTENT_SIZE, () -> new BusException("file is too large!")); Assert.isFalse(resources.getSize() > ALLOW_MAX_CAT_CONTENT_SIZE, () -> new BusException("file is too large!"));
return getBaseResourceManager().getFileContent(resources.getFullName()); return getBaseResourceManager().getFileContent(resources.getFullName());
} }
...@@ -224,7 +225,7 @@ public class ResourceServiceImpl extends ServiceImpl<ResourcesMapper, Resources> ...@@ -224,7 +225,7 @@ public class ResourceServiceImpl extends ServiceImpl<ResourcesMapper, Resources>
@Override @Override
public File getFile(Integer id) { public File getFile(Integer id) {
Resources resources = getById(id); Resources resources = getById(id);
Assert.notNull(resources, () -> new BusException(Status.RESOURCE_DIR_OR_FILE_NOT_EXIST)); DinkyAssert.checkNull(resources, Status.RESOURCE_DIR_OR_FILE_NOT_EXIST);
Assert.isFalse(resources.getSize() > ALLOW_MAX_CAT_CONTENT_SIZE, () -> new BusException("file is too large!")); Assert.isFalse(resources.getSize() > ALLOW_MAX_CAT_CONTENT_SIZE, () -> new BusException("file is too large!"));
return URLUtils.toFile("rs://" + resources.getFullName()); return URLUtils.toFile("rs://" + resources.getFullName());
} }
......
...@@ -181,7 +181,7 @@ public class SystemConfiguration { ...@@ -181,7 +181,7 @@ public class SystemConfiguration {
private final Configuration<String> ldapFilter = key(Status.SYS_LDAP_SETTINGS_FILTER) private final Configuration<String> ldapFilter = key(Status.SYS_LDAP_SETTINGS_FILTER)
.stringType() .stringType()
.defaultValue("") .defaultValue("(&(objectClass=inetOrgPerson))")
.note(Status.SYS_LDAP_SETTINGS_FILTER_NOTE); .note(Status.SYS_LDAP_SETTINGS_FILTER_NOTE);
private final Configuration<Boolean> ldapAutoload = key(Status.SYS_LDAP_SETTINGS_AUTOLOAD) private final Configuration<Boolean> ldapAutoload = key(Status.SYS_LDAP_SETTINGS_AUTOLOAD)
......
...@@ -50,6 +50,7 @@ export default () => { ...@@ -50,6 +50,7 @@ export default () => {
.catch((e) => ErrorMessage(e)); .catch((e) => ErrorMessage(e));
}; };
const reconnectSse = () => { const reconnectSse = () => {
uuidRef.current = uuidv4();
const sseUrl = '/api/sse/connect?sessionKey=' + uuidRef.current; const sseUrl = '/api/sse/connect?sessionKey=' + uuidRef.current;
eventSource?.close(); eventSource?.close();
setEventSource(new EventSource(sseUrl)); setEventSource(new EventSource(sseUrl));
......
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