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

jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 1cbbf9f  [DistSQL]`show instance list` syntax add the display of 
labels. (#15036)
1cbbf9f is described below

commit 1cbbf9f792e7fc889a495283b6464cfc81e98f85
Author: lanchengx <[email protected]>
AuthorDate: Tue Jan 25 13:24:31 2022 +0800

    [DistSQL]`show instance list` syntax add the display of labels. (#15036)
    
    * show instance list syntax add the display of labels.
    
    * Rename field.
---
 .../ral/common/show/executor/ShowInstanceExecutor.java   | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowInstanceExecutor.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowInstanceExecutor.java
index ff04bcf..87c090c 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowInstanceExecutor.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowInstanceExecutor.java
@@ -35,7 +35,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 /**
  * Show instance executor.
@@ -54,6 +53,8 @@ public final class ShowInstanceExecutor extends 
AbstractShowExecutor {
     
     private static final String DISABLE = "disable";
     
+    private static final String LABELS = "labels";
+    
     private static final String ENABLE = "enable";
     
     @Override
@@ -62,7 +63,8 @@ public final class ShowInstanceExecutor extends 
AbstractShowExecutor {
                 new QueryHeader("", "", ID, ID, Types.VARCHAR, "VARCHAR", 64, 
0, false, false, false, false),
                 new QueryHeader("", "", HOST, HOST, Types.VARCHAR, "VARCHAR", 
64, 0, false, false, false, false),
                 new QueryHeader("", "", PORT, PORT, Types.VARCHAR, "VARCHAR", 
64, 0, false, false, false, false),
-                new QueryHeader("", "", STATUS, STATUS, Types.VARCHAR, 
"VARCHAR", 64, 0, false, false, false, false)
+                new QueryHeader("", "", STATUS, STATUS, Types.VARCHAR, 
"VARCHAR", 64, 0, false, false, false, false),
+                new QueryHeader("", "", LABELS, LABELS, Types.VARCHAR, 
"VARCHAR", 64, 0, false, false, false, false)
         );
     }
     
@@ -78,24 +80,26 @@ public final class ShowInstanceExecutor extends 
AbstractShowExecutor {
     private Collection<List<Object>> buildInstanceRows() {
         List<List<Object>> result = new LinkedList<>();
         InstanceId instanceId = 
ProxyContext.getInstance().getContextManager().getInstanceContext().getInstance().getInstanceDefinition().getInstanceId();
-        result.add(buildRow(instanceId.getId(), ENABLE));
+        result.add(buildRow(instanceId.getId(), ENABLE, 
Collections.emptyList()));
         return result;
     }
     
     private Collection<List<Object>> buildInstanceRows(final 
MetaDataPersistService persistService) {
         Collection<ComputeNodeInstance> instances = 
persistService.getComputeNodePersistService().loadAllComputeNodeInstances();
         if (!instances.isEmpty()) {
-            return instances.stream().filter(Objects::nonNull).map(each -> 
buildRow(each.getInstanceDefinition().getInstanceId().getId(), 
getStatus(each.getStatus())))
+            return instances.stream().filter(Objects::nonNull)
+                    .map(each -> 
buildRow(each.getInstanceDefinition().getInstanceId().getId(), 
getStatus(each.getStatus()), each.getLabels()))
                     .collect(Collectors.toCollection(LinkedList::new));
         }
         return Collections.emptyList();
     }
     
-    private List<Object> buildRow(final String instanceId, final String 
status) {
+    private List<Object> buildRow(final String instanceId, final String 
status, final Collection<String> instanceLabels) {
         String[] splitInstanceId = instanceId.split(DELIMITER);
         String host = splitInstanceId[0];
         String port = splitInstanceId.length < 2 ? "" : splitInstanceId[1];
-        return Stream.of(instanceId, host, port, status).map(each -> (Object) 
each).collect(Collectors.toCollection(LinkedList::new));
+        String labels = null == instanceLabels ? "" : String.join(",", 
instanceLabels);
+        return new LinkedList<>(Arrays.asList(instanceId, host, port, status, 
labels));
     }
     
     private String getStatus(final Collection<String> computeNodeStatus) {

Reply via email to