diff --git a/dinky-admin/src/main/java/org/dinky/assertion/Assert.java b/dinky-admin/src/main/java/org/dinky/assertion/DinkyAssert.java similarity index 72% rename from dinky-admin/src/main/java/org/dinky/assertion/Assert.java rename to dinky-admin/src/main/java/org/dinky/assertion/DinkyAssert.java index 7f2d102b56..b0a99e3bbf 100644 --- a/dinky-admin/src/main/java/org/dinky/assertion/Assert.java +++ b/dinky-admin/src/main/java/org/dinky/assertion/DinkyAssert.java @@ -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 @@ * * @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 @@ static void check(ClusterInstance clusterInstance) { } } + 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); } } diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/ClusterConfigurationServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/ClusterConfigurationServiceImpl.java index a59dfd0a65..cf73eb1b07 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/ClusterConfigurationServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/ClusterConfigurationServiceImpl.java @@ -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 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 List listEnabledAllClusterConfig() { @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()); } diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/ClusterInstanceServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/ClusterInstanceServiceImpl.java index 4c56bae45f..65df48a011 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/ClusterInstanceServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/ClusterInstanceServiceImpl.java @@ -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 FlinkClusterInfo checkHeartBeat(String hosts, String host) { @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); diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java index 0175b3d37c..2a6c587304 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java @@ -23,11 +23,14 @@ 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.core.LdapTemplate; import org.springframework.stereotype.Service; -import cn.hutool.core.lang.Assert; import lombok.extern.slf4j.Slf4j; @Service @@ -112,7 +114,9 @@ public User authenticate(LoginDTO loginDTO) throws AuthException { @Override public List 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 result = ldapTemplate.search( diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/TaskServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/TaskServiceImpl.java index fbd4b48212..9f7e0e0c09 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/TaskServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/TaskServiceImpl.java @@ -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 TaskDTO prepareTask(TaskSubmitDto submitDto) { 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 JobResult restartTask(Integer id, String savePointPath) throws Exception 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 boolean cancelTaskJob(TaskDTO task, boolean withSavePoint, boolean forceC 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 boolean cancelTaskJob(TaskDTO task, boolean withSavePoint, boolean forceC @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 ObjectNode getStreamGraph(TaskDTO taskDTO) { @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 String exportSql(Integer id) { @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); diff --git a/dinky-admin/src/main/java/org/dinky/service/resource/impl/ResourceServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/resource/impl/ResourceServiceImpl.java index baec839a0b..cc4c2f67a6 100644 --- a/dinky-admin/src/main/java/org/dinky/service/resource/impl/ResourceServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/resource/impl/ResourceServiceImpl.java @@ -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 TreeNodeDTO createFolderOrGet(Integer pid, String fileName, String desc) 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() .eq(Resources::getPid, byId.getPid()) .eq(Resources::getFileName, fileName) @@ -216,7 +217,7 @@ private static TreeNodeDTO convertTree(Resources 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 String getContentByResourceId(Integer id) { @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()); } diff --git a/dinky-common/src/main/java/org/dinky/data/model/SystemConfiguration.java b/dinky-common/src/main/java/org/dinky/data/model/SystemConfiguration.java index f0474872b8..83eaa1e730 100644 --- a/dinky-common/src/main/java/org/dinky/data/model/SystemConfiguration.java +++ b/dinky-common/src/main/java/org/dinky/data/model/SystemConfiguration.java @@ -181,7 +181,7 @@ public static Configuration.OptionBuilder key(Status status) { private final Configuration ldapFilter = key(Status.SYS_LDAP_SETTINGS_FILTER) .stringType() - .defaultValue("") + .defaultValue("(&(objectClass=inetOrgPerson))") .note(Status.SYS_LDAP_SETTINGS_FILTER_NOTE); private final Configuration ldapAutoload = key(Status.SYS_LDAP_SETTINGS_AUTOLOAD) diff --git a/dinky-web/src/models/Sse.tsx b/dinky-web/src/models/Sse.tsx index aea7a75108..e2372ef42c 100644 --- a/dinky-web/src/models/Sse.tsx +++ b/dinky-web/src/models/Sse.tsx @@ -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));