accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject accumulo git commit: ACCUMULO-3735 add "listbulk" to the shell
Date Wed, 26 Aug 2015 17:58:14 GMT
Repository: accumulo
Updated Branches:
  refs/heads/master 9368641c1 -> 3f7b72e69


ACCUMULO-3735 add "listbulk" to the shell


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/3f7b72e6
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/3f7b72e6
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/3f7b72e6

Branch: refs/heads/master
Commit: 3f7b72e691c4d9efcb5d294a236b1d6b95fe55d6
Parents: 9368641
Author: Eric C. Newton <eric.newton@gmail.com>
Authored: Wed Aug 26 13:57:55 2015 -0400
Committer: Eric C. Newton <eric.newton@gmail.com>
Committed: Wed Aug 26 13:57:55 2015 -0400

----------------------------------------------------------------------
 .../shell/commands/BulkImportListIterator.java  | 70 +++++++++++++++
 .../shell/commands/ListBulkCommand.java         | 92 ++++++++++++++++++++
 2 files changed, 162 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/3f7b72e6/shell/src/main/java/org/apache/accumulo/shell/commands/BulkImportListIterator.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/BulkImportListIterator.java
b/shell/src/main/java/org/apache/accumulo/shell/commands/BulkImportListIterator.java
new file mode 100644
index 0000000..b1cc72d
--- /dev/null
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/BulkImportListIterator.java
@@ -0,0 +1,70 @@
+/*
+ * 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.accumulo.shell.commands;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.accumulo.core.master.thrift.BulkImportStatus;
+import org.apache.accumulo.core.master.thrift.MasterMonitorInfo;
+import org.apache.accumulo.core.master.thrift.TabletServerStatus;
+import org.apache.accumulo.core.util.Duration;
+
+public class BulkImportListIterator implements Iterator<String> {
+
+  private final Iterator<String> iter;
+
+  public BulkImportListIterator(List<String> tservers, MasterMonitorInfo stats) {
+    List<String> result = new ArrayList<>();
+    for (BulkImportStatus status : stats.bulkImports) {
+      result.add(format(status));
+    }
+    if (!tservers.isEmpty()) {
+      for (TabletServerStatus tserver : stats.tServerInfo) {
+        if (tservers.contains(tserver.name)) {
+          result.add(tserver.name + ":");
+          for (BulkImportStatus status : tserver.bulkImports) {
+            result.add(format(status));
+          }
+        }
+      }
+    }
+    iter = result.iterator();
+  }
+
+  private String format(BulkImportStatus status) {
+    long diff = System.currentTimeMillis() - status.startTime;
+    return String.format("%25s | %4s | %s", status.filename, Duration.format(diff, " ", "-"),
status.state);
+  }
+
+  @Override
+  public boolean hasNext() {
+    return iter.hasNext();
+  }
+
+  @Override
+  public String next() {
+    return iter.next();
+  }
+
+  @Override
+  public void remove() {
+    iter.remove();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/3f7b72e6/shell/src/main/java/org/apache/accumulo/shell/commands/ListBulkCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/ListBulkCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/ListBulkCommand.java
new file mode 100644
index 0000000..6db9327
--- /dev/null
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/ListBulkCommand.java
@@ -0,0 +1,92 @@
+/*
+ * 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.accumulo.shell.commands;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.accumulo.core.client.impl.MasterClient;
+import org.apache.accumulo.core.master.thrift.MasterClientService;
+import org.apache.accumulo.core.master.thrift.MasterMonitorInfo;
+import org.apache.accumulo.core.trace.Tracer;
+import org.apache.accumulo.server.AccumuloServerContext;
+import org.apache.accumulo.server.conf.ServerConfigurationFactory;
+import org.apache.accumulo.shell.Shell;
+import org.apache.accumulo.shell.Shell.Command;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+
+public class ListBulkCommand extends Command {
+
+  private Option tserverOption, disablePaginationOpt;
+
+  @Override
+  public String description() {
+    return "lists what bulk imports are currently running in accumulo.";
+  }
+
+  @Override
+  public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
throws Exception {
+
+    List<String> tservers;
+
+    MasterMonitorInfo stats;
+    MasterClientService.Iface client = null;
+    try {
+      AccumuloServerContext context = new AccumuloServerContext(new ServerConfigurationFactory(shellState.getInstance()));
+      client = MasterClient.getConnectionWithRetry(context);
+      stats = client.getMasterStats(Tracer.traceInfo(), context.rpcCreds());
+    } finally {
+      if (client != null)
+        MasterClient.close(client);
+    }
+
+    final boolean paginate = !cl.hasOption(disablePaginationOpt.getOpt());
+
+    if (cl.hasOption(tserverOption.getOpt())) {
+      tservers = new ArrayList<String>();
+      tservers.add(cl.getOptionValue(tserverOption.getOpt()));
+    } else {
+      tservers = Collections.emptyList();
+    }
+
+    shellState.printLines(new BulkImportListIterator(tservers, stats), paginate);
+    return 0;
+  }
+
+  @Override
+  public int numArgs() {
+    return 0;
+  }
+
+  @Override
+  public Options getOptions() {
+    final Options opts = new Options();
+
+    tserverOption = new Option("ts", "tabletServer", true, "tablet server to list bulk imports");
+    tserverOption.setArgName("tablet server");
+    opts.addOption(tserverOption);
+
+    disablePaginationOpt = new Option("np", "no-pagination", false, "disable pagination of
output");
+    opts.addOption(disablePaginationOpt);
+
+    return opts;
+  }
+
+}


Mime
View raw message