You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ca...@apache.org on 2022/09/21 02:20:47 UTC

[dolphinscheduler] branch 3.1.0-prepare updated (c286c5567a -> 280b7c8545)

This is an automated email from the ASF dual-hosted git repository.

caishunfeng pushed a change to branch 3.1.0-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


    from c286c5567a Script cannot contains ''' in params (#12068)
     new cda3110409 [improvement]Add Set cluster name (#12058)
     new 280b7c8545 [Improvement] Add Set cluster name (#12074)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../api/service/impl/K8SNamespaceServiceImpl.java  | 27 ++++++++++++++++++++--
 .../api/service/K8SNamespaceServiceTest.java       | 19 +++++++++++++++
 .../task/components/node/fields/use-namespace.ts   |  6 ++---
 3 files changed, 47 insertions(+), 5 deletions(-)


[dolphinscheduler] 01/02: [improvement]Add Set cluster name (#12058)

Posted by ca...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

caishunfeng pushed a commit to branch 3.1.0-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git

commit cda31104098cca05c972576004422592bb45accb
Author: jackfanwan <61...@users.noreply.github.com>
AuthorDate: Tue Sep 20 21:26:05 2022 +0800

    [improvement]Add Set cluster name (#12058)
    
    * Add Set cluster name
    
    * add unit test
    
    Co-authored-by: fanwanlong <fa...@kezaihui.com>
---
 .../api/service/impl/K8SNamespaceServiceImpl.java  | 27 ++++++++++++++++++++--
 .../api/service/K8SNamespaceServiceTest.java       | 19 +++++++++++++++
 2 files changed, 44 insertions(+), 2 deletions(-)

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 760fbf8f5f..6365abfe88 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
@@ -32,6 +32,7 @@ import org.apache.dolphinscheduler.remote.exceptions.RemotingException;
 import org.apache.dolphinscheduler.api.k8s.K8sClientService;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.collections.CollectionUtils;
 
 import java.util.ArrayList;
 import java.util.Date;
@@ -40,6 +41,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -418,10 +420,31 @@ public class K8SNamespaceServiceImpl extends BaseServiceImpl implements K8sNames
      */
     @Override
     public List<K8sNamespace> queryNamespaceAvailable(User loginUser) {
+        List<K8sNamespace> k8sNamespaces;
         if (isAdmin(loginUser)) {
-            return k8sNamespaceMapper.selectList(null);
+            k8sNamespaces = k8sNamespaceMapper.selectList(null);
         } else {
-            return k8sNamespaceMapper.queryNamespaceAvailable(loginUser.getId());
+             k8sNamespaces = k8sNamespaceMapper.queryNamespaceAvailable(loginUser.getId());
+        }
+        setClusterName(k8sNamespaces);
+        return k8sNamespaces;
+    }
+
+    /**
+     * set cluster_name
+     * @param k8sNamespaces source data
+     */
+    private void setClusterName(List<K8sNamespace> k8sNamespaces) {
+        if (CollectionUtils.isNotEmpty(k8sNamespaces)) {
+            List<Cluster> clusters = clusterMapper.queryAllClusterList();
+            if (CollectionUtils.isNotEmpty(clusters)) {
+                Map<Long, String> codeNameMap = clusters.stream()
+                        .collect(Collectors.toMap(Cluster::getCode, Cluster::getName, (a, b) -> a));
+                for (K8sNamespace k8sNamespace : k8sNamespaces) {
+                    String clusterName = codeNameMap.get(k8sNamespace.getClusterCode());
+                    k8sNamespace.setClusterName(clusterName);
+                }
+            }
         }
     }
 
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/K8SNamespaceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/K8SNamespaceServiceTest.java
index ed684ea914..390153aa3d 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/K8SNamespaceServiceTest.java
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/K8SNamespaceServiceTest.java
@@ -221,6 +221,25 @@ public class K8SNamespaceServiceTest {
         Assert.assertTrue(CollectionUtils.isEmpty(namespaces));
     }
 
+    @Test
+    public void testQueryNamespaceAvailable() {
+        List<K8sNamespace> k8sNamespaces = new ArrayList<>();
+        K8sNamespace k8sNamespace = new K8sNamespace();
+        k8sNamespace.setClusterCode(1L);
+        k8sNamespaces.add(k8sNamespace);
+
+        List<Cluster> clusters = new ArrayList<>();
+        Cluster cluster = new Cluster();
+        cluster.setCode(1L);
+        cluster.setName("test");
+        clusters.add(cluster);
+
+        Mockito.when(k8sNamespaceMapper.selectList(Mockito.any())).thenReturn(k8sNamespaces);
+        Mockito.when(clusterMapper.queryAllClusterList()).thenReturn(clusters);
+        List<K8sNamespace> result = k8sNamespaceService.queryNamespaceAvailable(getLoginUser());
+        Assert.assertEquals(result.get(0).getClusterName(), cluster.getName());
+    }
+
     private User getLoginUser() {
 
         User loginUser = new User();


[dolphinscheduler] 02/02: [Improvement] Add Set cluster name (#12074)

Posted by ca...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

caishunfeng pushed a commit to branch 3.1.0-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git

commit 280b7c85457e371e74ab7e5f757b3235f2fe436a
Author: jackfanwan <61...@users.noreply.github.com>
AuthorDate: Wed Sep 21 10:05:15 2022 +0800

    [Improvement] Add Set cluster name (#12074)
---
 .../src/views/projects/task/components/node/fields/use-namespace.ts | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-namespace.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-namespace.ts
index 983fd6506a..fc4a8925f1 100644
--- a/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-namespace.ts
+++ b/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-namespace.ts
@@ -31,11 +31,11 @@ export function useNamespace(): IJsonItem {
     loading.value = true
     const totalList = await getAllNamespaces()
     options.value = (totalList || []).map(
-      (item: { id: string; namespace: string; k8s: string }) => ({
-        label: `${item.namespace}(${item.k8s})`,
+      (item: { id: string; namespace: string; clusterName: string }) => ({
+        label: `${item.namespace}(${item.clusterName})`,
         value: JSON.stringify({
           name: item.namespace,
-          cluster: item.k8s
+          cluster: item.clusterName
         })
       })
     )