incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [2/3] git commit: Adding new controls to the blur shell.
Date Tue, 19 Jan 2016 21:05:47 GMT
Adding new controls to the blur shell.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/a6b2a667
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/a6b2a667
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/a6b2a667

Branch: refs/heads/master
Commit: a6b2a667b82b7ce6d9dfc9363dc94fdfc14afcac
Parents: 31d56a1
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Tue Jan 19 16:05:00 2016 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Tue Jan 19 16:05:00 2016 -0500

----------------------------------------------------------------------
 .../shell/CancelPlatformCommandCommand.java     |  55 +++++++
 .../ListRunningPlatformCommandsCommand.java     | 161 +++++++++++++++++++
 .../main/java/org/apache/blur/shell/Main.java   |   5 +-
 3 files changed, 220 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6b2a667/blur-shell/src/main/java/org/apache/blur/shell/CancelPlatformCommandCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/CancelPlatformCommandCommand.java
b/blur-shell/src/main/java/org/apache/blur/shell/CancelPlatformCommandCommand.java
new file mode 100644
index 0000000..7ea849a
--- /dev/null
+++ b/blur-shell/src/main/java/org/apache/blur/shell/CancelPlatformCommandCommand.java
@@ -0,0 +1,55 @@
+/**
+ * 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.blur.shell;
+
+import java.io.PrintWriter;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.apache.blur.thrift.generated.BlurException;
+
+public class CancelPlatformCommandCommand extends Command {
+
+  @Override
+  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+    if (args.length != 2) {
+      throw new CommandException("Invalid args: " + help());
+    }
+
+    String id = args[1];
+    client.commandCancel(id);
+    out.println("Cancel command issued for id [" + id + "]");
+  }
+
+  @Override
+  public String description() {
+    return "Cancel running command by id";
+  }
+
+  @Override
+  public String usage() {
+    return "<id>";
+  }
+
+  @Override
+  public String name() {
+    return "command-cancel";
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6b2a667/blur-shell/src/main/java/org/apache/blur/shell/ListRunningPlatformCommandsCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/ListRunningPlatformCommandsCommand.java
b/blur-shell/src/main/java/org/apache/blur/shell/ListRunningPlatformCommandsCommand.java
new file mode 100644
index 0000000..2b48374
--- /dev/null
+++ b/blur-shell/src/main/java/org/apache/blur/shell/ListRunningPlatformCommandsCommand.java
@@ -0,0 +1,161 @@
+/**
+ * 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.blur.shell;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.CommandStatus;
+import org.apache.blur.thrift.generated.CommandStatusState;
+import org.apache.blur.thrift.generated.User;
+
+public class ListRunningPlatformCommandsCommand extends Command {
+
+  @Override
+  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+    if (args.length != 1) {
+      throw new CommandException("Invalid args: " + help());
+    }
+
+    List<String> commandStatusList = client.commandStatusList(0, Short.MAX_VALUE);
+    RunningSummary runningSummary = new RunningSummary();
+    for (String id : commandStatusList) {
+      CommandStatus commandStatus = client.commandStatus(id);
+      Map<String, Map<CommandStatusState, Long>> serverStateMap = commandStatus.getServerStateMap();
+      out.println(serverStateMap);
+      Map<CommandStatusState, Long> summary = getSummary(serverStateMap);
+      if (summary.containsKey(CommandStatusState.RUNNING)) {
+        runningSummary.add(commandStatus, summary);
+      }
+    }
+
+    runningSummary.print(out);
+  }
+
+  private Map<CommandStatusState, Long> getSummary(Map<String, Map<CommandStatusState,
Long>> serverStateMap) {
+    Map<CommandStatusState, Long> map = new HashMap<CommandStatusState, Long>();
+    for (Map<CommandStatusState, Long> m : serverStateMap.values()) {
+      for (Entry<CommandStatusState, Long> e : m.entrySet()) {
+        Long c = map.get(e.getKey());
+        Long newCount = e.getValue();
+        if (c == null) {
+          map.put(e.getKey(), newCount);
+        } else {
+          map.put(e.getKey(), c + newCount);
+        }
+      }
+    }
+    return map;
+  }
+
+  @Override
+  public String description() {
+    return "List the running commands on the cluster";
+  }
+
+  @Override
+  public String usage() {
+    return "";
+  }
+
+  @Override
+  public String name() {
+    return "command-running";
+  }
+
+  static class RunningSummary {
+
+    private List<List<String>> _summary = new ArrayList<List<String>>();
+
+    public void add(CommandStatus commandStatus, Map<CommandStatusState, Long> summary)
{
+      String executionId = commandStatus.getExecutionId();
+      String commandName = commandStatus.getCommandName();
+      User user = commandStatus.getUser();
+      _summary.add(Arrays.asList(executionId, commandName, user.getUsername(), toString(summary)));
+    }
+
+    private String toString(Map<CommandStatusState, Long> summary) {
+      StringBuilder builder = new StringBuilder();
+      for (Entry<CommandStatusState, Long> e : summary.entrySet()) {
+        if (builder.length() != 0) {
+          builder.append(',');
+        }
+        builder.append(e.getKey().name()).append(":").append(e.getValue());
+      }
+      return builder.toString();
+    }
+
+    public void print(PrintWriter out) {
+      if (_summary == null || _summary.isEmpty()) {
+        out.println("No Commands Running");
+        return;
+      }
+      int[] maxLengths = getMaxLength();
+      for (List<String> line : _summary) {
+        print(out, line, maxLengths);
+      }
+    }
+
+    private void print(PrintWriter out, List<String> line, int[] maxLengths) {
+      for (int i = 0; i < line.size(); i++) {
+        int length = maxLengths[i];
+        print(out, line.get(i), length);
+      }
+      out.println();
+    }
+
+    private void print(PrintWriter out, String s, int length) {
+      out.print(buffer(s, length));
+    }
+
+    private String buffer(String s, int length) {
+      while (s.length() < length) {
+        s = s + " ";
+      }
+      return s;
+    }
+
+    private int[] getMaxLength() {
+      int[] len = null;
+      for (List<String> line : _summary) {
+        if (len == null) {
+          len = new int[line.size()];
+        }
+        for (int i = 0; i < line.size(); i++) {
+          if (line.get(i).length() > len[i]) {
+            len[i] = line.get(i).length();
+          }
+        }
+      }
+      // Add space between
+      for (int i = 0; i < len.length; i++) {
+        len[i]++;
+      }
+      return len;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6b2a667/blur-shell/src/main/java/org/apache/blur/shell/Main.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/Main.java b/blur-shell/src/main/java/org/apache/blur/shell/Main.java
index 1052c44..bf4b0b5 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/Main.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/Main.java
@@ -399,7 +399,8 @@ public class Main {
   public static String[] clusterCommands = { "controllers", "shards", "clusterlist", "cluster",
"safemodewait", "top" };
   public static String[] shellCommands = { "help", "debug", "timed", "quit", "reset", "user",
"whoami", "trace",
       "trace-remove", "trace-list" };
-  public static String[] platformCommands = { "command-list", "command-exec", "command-desc"
};
+  public static String[] platformCommands = { "command-list", "command-exec", "command-desc",
"command-running",
+      "command-cancel" };
   public static String[] serverCommands = { "logger", "logger-reset", "remove-shard" };
 
   private static class HelpCommand extends Command {
@@ -701,6 +702,8 @@ public class Main {
     register(builder, new DescribePlatformCommandCommand());
     register(builder, new ExecutePlatformCommandCommand());
     register(builder, new ImportDataCommand());
+    register(builder, new ListRunningPlatformCommandsCommand());
+    register(builder, new CancelPlatformCommandCommand());
     commands = builder.build();
   }
 


Mime
View raw message