From 682435e39a4dcc19ec81583cffe6adc0897107df Mon Sep 17 00:00:00 2001 From: littlezhou Date: Mon, 15 Jan 2018 17:11:45 +0800 Subject: [PATCH] Solve #1536, Define interface to query node info of SSM cluster (#1537) --- .../main/java/org/smartdata/server/SmartEngine.java | 11 +++++++++++ .../server/engine/cmdlet/CmdletDispatcher.java | 4 ++-- .../org/smartdata/server/rest/ClusterRestApi.java | 12 ++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/smart-engine/src/main/java/org/smartdata/server/SmartEngine.java b/smart-engine/src/main/java/org/smartdata/server/SmartEngine.java index 000960b2aa8..2b92c5bd1b2 100644 --- a/smart-engine/src/main/java/org/smartdata/server/SmartEngine.java +++ b/smart-engine/src/main/java/org/smartdata/server/SmartEngine.java @@ -23,6 +23,8 @@ import org.smartdata.conf.SmartConf; import org.smartdata.model.StorageCapacity; import org.smartdata.model.Utilization; +import org.smartdata.server.cluster.NodeInfo; +import org.smartdata.server.engine.ActiveServerInfo; import org.smartdata.server.engine.CmdletManager; import org.smartdata.server.engine.ConfManager; import org.smartdata.server.engine.RuleManager; @@ -36,6 +38,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.LinkedList; import java.util.List; import java.util.Random; @@ -176,4 +179,12 @@ private List getFackData(String resourceName, long granularity, } return utils; } + + public List getSsmNodesInfo() { + List ret = new LinkedList<>(); + ret.addAll(Arrays.asList(ActiveServerInfo.getInstance())); + ret.addAll(getStandbyServers()); + ret.addAll(getAgents()); + return ret; + } } diff --git a/smart-engine/src/main/java/org/smartdata/server/engine/cmdlet/CmdletDispatcher.java b/smart-engine/src/main/java/org/smartdata/server/engine/cmdlet/CmdletDispatcher.java index 0ba7f6d17ca..8f63c6a3245 100644 --- a/smart-engine/src/main/java/org/smartdata/server/engine/cmdlet/CmdletDispatcher.java +++ b/smart-engine/src/main/java/org/smartdata/server/engine/cmdlet/CmdletDispatcher.java @@ -95,9 +95,9 @@ public CmdletDispatcher(SmartContext smartContext, CmdletManager cmdletManager, boolean disableLocal = smartContext.getConf().getBoolean( SmartConfKeys.SMART_ACTION_LOCAL_EXECUTION_DISABLED_KEY, SmartConfKeys.SMART_ACTION_LOCAL_EXECUTION_DISABLED_DEFAULT); + CmdletExecutorService exe = + new LocalCmdletExecutorService(smartContext.getConf(), cmdletManager); if (!disableLocal) { - CmdletExecutorService exe = - new LocalCmdletExecutorService(smartContext.getConf(), cmdletManager); registerExecutorService(exe); } this.index = 0; diff --git a/smart-zeppelin/zeppelin-server/src/main/java/org/smartdata/server/rest/ClusterRestApi.java b/smart-zeppelin/zeppelin-server/src/main/java/org/smartdata/server/rest/ClusterRestApi.java index b3d44b54ea3..3fe37d46e5a 100644 --- a/smart-zeppelin/zeppelin-server/src/main/java/org/smartdata/server/rest/ClusterRestApi.java +++ b/smart-zeppelin/zeppelin-server/src/main/java/org/smartdata/server/rest/ClusterRestApi.java @@ -162,6 +162,18 @@ public Response fileInfo(String path) { } } + @GET + @Path("/primary/ssmnodesinfo") + public Response ssmNodesInfo() { + try { + return new JsonResponse<>(Response.Status.OK, smartEngine.getSsmNodesInfo()).build(); + } catch (Exception e) { + logger.error("Exception in ClusterRestApi while listing SSM nodes", e); + return new JsonResponse<>(Response.Status.INTERNAL_SERVER_ERROR, + e.getMessage(), ExceptionUtils.getStackTrace(e)).build(); + } + } + // @GET // @Path("/alluxio/{clusterName}") // public void alluxio() {