From 6fb28d0dc5757fd62c22f342553a2cd784479639 Mon Sep 17 00:00:00 2001 From: ikiler Date: Wed, 31 Jan 2024 19:37:16 +0800 Subject: [PATCH 1/4] optimize exception throw --- .../{Assert.java => DinkyAssert.java} | 22 +++++++++++++++++-- .../impl/ClusterConfigurationServiceImpl.java | 3 ++- .../impl/ClusterInstanceServiceImpl.java | 6 ++--- .../dinky/service/impl/LdapServiceImpl.java | 6 ++++- .../dinky/service/impl/TaskServiceImpl.java | 17 +++++++------- .../resource/impl/ResourceServiceImpl.java | 7 +++--- .../dinky/data/model/SystemConfiguration.java | 2 +- 7 files changed, 44 insertions(+), 19 deletions(-) rename dinky-admin/src/main/java/org/dinky/assertion/{Assert.java => DinkyAssert.java} (72%) 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..81ec24ed8a 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,25 @@ 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..8aba88fc3c 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; @@ -76,7 +77,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..3362864532 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,7 +19,7 @@ package org.dinky.service.impl; -import org.dinky.assertion.Assert; +import org.dinky.assertion.DinkyAssert; import org.dinky.assertion.Asserts; import org.dinky.cluster.FlinkCluster; import org.dinky.cluster.FlinkClusterInfo; @@ -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..e380b91a21 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 @@ -19,10 +19,12 @@ package org.dinky.service.impl; +import org.apache.http.util.TextUtils; 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; @@ -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.getMessage()); + } 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) From 1e530c2280ed59109b0ce5cf3b3441720895a243 Mon Sep 17 00:00:00 2001 From: gaoyan1998 Date: Wed, 31 Jan 2024 11:38:35 +0000 Subject: [PATCH 2/4] Spotless Apply --- .../src/main/java/org/dinky/assertion/DinkyAssert.java | 6 ++++-- .../dinky/service/impl/ClusterConfigurationServiceImpl.java | 2 -- .../org/dinky/service/impl/ClusterInstanceServiceImpl.java | 2 +- .../main/java/org/dinky/service/impl/LdapServiceImpl.java | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dinky-admin/src/main/java/org/dinky/assertion/DinkyAssert.java b/dinky-admin/src/main/java/org/dinky/assertion/DinkyAssert.java index 81ec24ed8a..b0a99e3bbf 100644 --- a/dinky-admin/src/main/java/org/dinky/assertion/DinkyAssert.java +++ b/dinky-admin/src/main/java/org/dinky/assertion/DinkyAssert.java @@ -43,18 +43,20 @@ static void check(TaskDTO task) { throw new BusException(Status.TASK_NOT_EXIST); } } + static void check(Task task) { if (task == null) { throw new BusException(Status.TASK_NOT_EXIST); } } - static void checkNull(Object o,Status status){ + static void checkNull(Object o, Status status) { if (o == null) { throw new BusException(status); } } - static void checkNull(Object o,String msg){ + + 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 8aba88fc3c..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 @@ -46,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 * 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 3362864532..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.DinkyAssert; 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; 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 e380b91a21..f00ee5d090 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 @@ -19,7 +19,6 @@ package org.dinky.service.impl; -import org.apache.http.util.TextUtils; import org.dinky.context.LdapContext; import org.dinky.data.dto.LoginDTO; import org.dinky.data.enums.Status; @@ -30,6 +29,8 @@ 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; @@ -41,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 From b590a0e6839287e638035628178bf7d333852f6e Mon Sep 17 00:00:00 2001 From: ikiler Date: Wed, 31 Jan 2024 19:39:47 +0800 Subject: [PATCH 3/4] optimize exception throw --- .../src/main/java/org/dinky/service/impl/LdapServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e380b91a21..c5dd9f055e 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 @@ -115,7 +115,7 @@ public User authenticate(LoginDTO loginDTO) throws AuthException { public List listUsers() { String filter = configuration.getLdapFilter().getValue(); if (TextUtils.isEmpty(filter)) { - throw new BusException(Status.LDAP_FILTER_INCORRECT.getMessage()); + throw new BusException(Status.LDAP_FILTER_INCORRECT); } LdapTemplate ldapTemplate = new LdapTemplate(LdapContext.getLdapContext()); From dd21043e47b8b624a066621d58869d9d96f87715 Mon Sep 17 00:00:00 2001 From: ikiler Date: Wed, 31 Jan 2024 20:05:29 +0800 Subject: [PATCH 4/4] fix sse err --- dinky-web/src/models/Sse.tsx | 1 + 1 file changed, 1 insertion(+) 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));