From eeb11eedfb831cd5b503732265de979add78c9de Mon Sep 17 00:00:00 2001 From: Kerwin <37063904+zhuangchong@users.noreply.github.com> Date: Fri, 21 Oct 2022 13:54:28 +0800 Subject: [PATCH] cherry-pick [Bug-12410] [API]Fix the worker list result in workflow definition only has default --- .../ResourcePermissionCheckServiceImpl.java | 22 ++++++------------- .../service/impl/K8SNamespaceServiceImpl.java | 2 +- .../dao/mapper/K8sNamespaceMapper.java | 13 +++-------- .../dao/mapper/K8sNamespaceMapper.xml | 10 --------- 4 files changed, 11 insertions(+), 36 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceImpl.java index e013603bd2..9362e68c20 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceImpl.java @@ -42,6 +42,7 @@ import org.apache.dolphinscheduler.dao.entity.AccessToken; import org.apache.dolphinscheduler.dao.entity.AlertGroup; import org.apache.dolphinscheduler.dao.entity.DataSource; import org.apache.dolphinscheduler.dao.entity.Environment; +import org.apache.dolphinscheduler.dao.entity.K8sNamespace; import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Queue; import org.apache.dolphinscheduler.dao.entity.Resource; @@ -49,6 +50,7 @@ import org.apache.dolphinscheduler.dao.entity.TaskGroup; import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.UdfFunc; import org.apache.dolphinscheduler.dao.entity.User; +import org.apache.dolphinscheduler.dao.entity.WorkerGroup; import org.apache.dolphinscheduler.dao.mapper.AccessTokenMapper; import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper; import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper; @@ -172,7 +174,7 @@ public class ResourcePermissionCheckServiceImpl implements ResourcePermissionChe return Collections.emptySet(); } List queues = queueMapper.selectList(null); - return queues.isEmpty() ? Collections.emptySet() : queues.stream().map(Queue::getId).collect(toSet()); + return queues.stream().map(Queue::getId).collect(toSet()); } } @@ -257,9 +259,6 @@ public class ResourcePermissionCheckServiceImpl implements ResourcePermissionChe @Override public Set listAuthorizedResource(int userId, Logger logger) { List udfFuncList = udfFuncMapper.listAuthorizedUdfByUserId(userId); - if (udfFuncList.isEmpty()){ - return Collections.emptySet(); - } return udfFuncList.stream().map(UdfFunc::getId).collect(toSet()); } @@ -286,9 +285,6 @@ public class ResourcePermissionCheckServiceImpl implements ResourcePermissionChe @Override public Set listAuthorizedResource(int userId, Logger logger) { List taskGroupList = taskGroupMapper.listAuthorizedResource(userId); - if (taskGroupList.isEmpty()) { - return Collections.emptySet(); - } return taskGroupList.stream().map(TaskGroup::getId).collect(Collectors.toSet()); } @@ -319,7 +315,8 @@ public class ResourcePermissionCheckServiceImpl implements ResourcePermissionChe @Override public Set listAuthorizedResource(int userId, Logger logger) { - return Collections.emptySet(); + List k8sNamespaces = k8sNamespaceMapper.queryAuthedNamespaceListByUserId(userId); + return k8sNamespaces.stream().map(K8sNamespace::getId).collect(Collectors.toSet()); } } @@ -346,9 +343,6 @@ public class ResourcePermissionCheckServiceImpl implements ResourcePermissionChe @Override public Set listAuthorizedResource(int userId, Logger logger) { List environments = environmentMapper.queryAllEnvironmentList(); - if (environments.isEmpty()) { - return Collections.emptySet(); - } return environments.stream().map(Environment::getId).collect(Collectors.toSet()); } } @@ -375,7 +369,8 @@ public class ResourcePermissionCheckServiceImpl implements ResourcePermissionChe @Override public Set listAuthorizedResource(int userId, Logger logger) { - return Collections.emptySet(); + List workerGroups = workerGroupMapper.queryAllWorkerGroup(); + return workerGroups.stream().map(WorkerGroup::getId).collect(Collectors.toSet()); } } @@ -463,9 +458,6 @@ public class ResourcePermissionCheckServiceImpl implements ResourcePermissionChe @Override public Set listAuthorizedResource(int userId, Logger logger) { - if (userId != 0) { - return Collections.emptySet(); - } List tenantList = tenantMapper.queryAll(); return tenantList.stream().map(Tenant::getId).collect(Collectors.toSet()); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/K8SNamespaceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/K8SNamespaceServiceImpl.java index 6365abfe88..53edac0493 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/K8SNamespaceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/K8SNamespaceServiceImpl.java @@ -424,7 +424,7 @@ public class K8SNamespaceServiceImpl extends BaseServiceImpl implements K8sNames if (isAdmin(loginUser)) { k8sNamespaces = k8sNamespaceMapper.selectList(null); } else { - k8sNamespaces = k8sNamespaceMapper.queryNamespaceAvailable(loginUser.getId()); + k8sNamespaces = k8sNamespaceMapper.queryAuthedNamespaceListByUserId(loginUser.getId()); } setClusterName(k8sNamespaces); return k8sNamespaces; diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/K8sNamespaceMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/K8sNamespaceMapper.java index f89e7579e4..d748d7ed80 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/K8sNamespaceMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/K8sNamespaceMapper.java @@ -30,6 +30,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; * namespace interface */ public interface K8sNamespaceMapper extends BaseMapper { + /** * k8s namespace page * @@ -63,15 +64,7 @@ public interface K8sNamespaceMapper extends BaseMapper { * @param userId userId * @return namespace list */ - List queryAuthedNamespaceListByUserId(@Param("userId") int userId); - - /** - * query namespace can use - * - * @param userId userId - * @return namespace list - */ - List queryNamespaceAvailable(@Param("userId") Integer userId); + List queryAuthedNamespaceListByUserId(@Param("userId") Integer userId); /** * check the target namespace @@ -80,4 +73,4 @@ public interface K8sNamespaceMapper extends BaseMapper { * @return true if exist else return null */ K8sNamespace queryByNamespaceCode(@Param("clusterCode") Long namespaceCode); -} \ No newline at end of file +} diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/K8sNamespaceMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/K8sNamespaceMapper.xml index 4acea799df..acac0023b4 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/K8sNamespaceMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/K8sNamespaceMapper.xml @@ -70,16 +70,6 @@ where p.id = rel.namespace_id and rel.user_id= #{userId} -