RaigorJiang commented on a change in pull request #13032:
URL: https://github.com/apache/shardingsphere/pull/13032#discussion_r728710828



##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowInstancesExecutor.java
##########
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.show.executor;
+
+import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.ClusterInstance;
+import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.ComputeNodeStatus;
+import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.node.ComputeStatusNode;
+import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import 
org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryHeader;
+import 
org.apache.shardingsphere.sharding.merge.dal.common.MultipleLocalDataMergedResult;
+
+import java.sql.Types;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * Show instance executor.
+ */
+public final class ShowInstancesExecutor extends AbstractShowExecutor {
+    
+    private static final String DELIMITER = "@";
+    
+    private static final String IP = "ip";
+    
+    private static final String PORT = "port";
+    
+    private static final String STATUS = "status";
+    
+    private static final String DISABLE = "disable";
+    
+    private static final String ENABLE = "enable";
+    
+    @Override
+    protected List<QueryHeader> createQueryHeaders() {
+        return Arrays.asList(
+                new QueryHeader("", "", IP, IP, 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)
+        );
+    }
+    
+    @Override
+    protected MergedResult createMergedResult() {
+        MetaDataPersistService persistService = 
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataPersistService().orElse(null);
+        if (null == persistService || null == persistService.getRepository()) {
+            return new MultipleLocalDataMergedResult(buildInstanceRows());
+        }
+        Collection<List<Object>> rows = buildInstanceRows(persistService, 
ENABLE);
+        Collection<List<Object>> disableInstanceIds = 
buildInstanceRows(persistService, DISABLE);
+        if (!disableInstanceIds.isEmpty()) {
+            rows.addAll(disableInstanceIds);
+        }
+        return new MultipleLocalDataMergedResult(rows);
+    }
+    
+    private Collection<List<Object>> buildInstanceRows() {
+        LinkedList<Object> row = new LinkedList<>();
+        row.add(buildRow(ClusterInstance.getInstance().getId(), ENABLE));
+        return Collections.singletonList(row);
+    }
+    
+    private Collection<List<Object>> buildInstanceRows(final 
MetaDataPersistService persist, final String status) {

Review comment:
       persistService may be better.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to