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

[Optimize ]optimize exception throw (#3116)

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