incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [5/5] git commit: Adding logger level changer plus shell commands.
Date Tue, 25 Feb 2014 13:07:11 GMT
Adding logger level changer plus shell commands.


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

Branch: refs/heads/apache-blur-0.2
Commit: b726909c4857618a5a2cc7a9119afdae72fbdb94
Parents: f3c7791
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Tue Feb 25 08:06:59 2014 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Tue Feb 25 08:06:59 2014 -0500

----------------------------------------------------------------------
 .../apache/blur/server/FilteredBlurServer.java  |   11 +
 .../java/org/apache/blur/thrift/TableAdmin.java |   86 +
 blur-shell/generate_docs.sh                     |    2 +-
 .../java/org/apache/blur/shell/Command.java     |    6 +-
 .../java/org/apache/blur/shell/LogCommand.java  |   69 +
 .../org/apache/blur/shell/LogResetCommand.java  |   64 +
 .../main/java/org/apache/blur/shell/Main.java   |   27 +-
 .../org/apache/blur/thrift/generated/Blur.java  | 3366 +++++++++++++-----
 .../org/apache/blur/thrift/generated/Level.java |   85 +
 .../main/java/org/apache/blur/log/LogImpl.java  |   24 +-
 .../src/main/scripts/interface/Blur.thrift      |   29 +
 .../main/scripts/interface/gen-html/Blur.html   |   29 +
 .../main/scripts/interface/gen-html/index.html  |    3 +
 .../org/apache/blur/thrift/generated/Blur.java  | 3366 +++++++++++++-----
 .../org/apache/blur/thrift/generated/Level.java |   85 +
 .../src/main/scripts/interface/gen-js/Blur.js   |  278 ++
 .../main/scripts/interface/gen-js/Blur_types.js |   10 +
 .../scripts/interface/gen-perl/Blur/Blur.pm     |  403 +++
 .../scripts/interface/gen-perl/Blur/Types.pm    |    9 +
 .../src/main/scripts/interface/gen-rb/blur.rb   |  122 +
 .../main/scripts/interface/gen-rb/blur_types.rb |   13 +
 docs/Blur.html                                  |   29 +
 22 files changed, 6354 insertions(+), 1762 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b726909c/blur-core/src/main/java/org/apache/blur/server/FilteredBlurServer.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/server/FilteredBlurServer.java b/blur-core/src/main/java/org/apache/blur/server/FilteredBlurServer.java
index 67d0ad3..472a2a9 100644
--- a/blur-core/src/main/java/org/apache/blur/server/FilteredBlurServer.java
+++ b/blur-core/src/main/java/org/apache/blur/server/FilteredBlurServer.java
@@ -29,6 +29,7 @@ import org.apache.blur.thrift.generated.BlurQueryStatus;
 import org.apache.blur.thrift.generated.BlurResults;
 import org.apache.blur.thrift.generated.ColumnDefinition;
 import org.apache.blur.thrift.generated.FetchResult;
+import org.apache.blur.thrift.generated.Level;
 import org.apache.blur.thrift.generated.Metric;
 import org.apache.blur.thrift.generated.Query;
 import org.apache.blur.thrift.generated.RowMutation;
@@ -223,4 +224,14 @@ public class FilteredBlurServer implements Iface {
     _iface.ping();
   }
 
+  @Override
+  public void logging(String classNameOrLoggerName, Level level) throws BlurException, TException
{
+    _iface.logging(classNameOrLoggerName, level);
+  }
+
+  @Override
+  public void resetLogging() throws BlurException, TException {
+    _iface.resetLogging();
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b726909c/blur-core/src/main/java/org/apache/blur/thrift/TableAdmin.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/thrift/TableAdmin.java b/blur-core/src/main/java/org/apache/blur/thrift/TableAdmin.java
index 4165013..95afda7 100644
--- a/blur-core/src/main/java/org/apache/blur/thrift/TableAdmin.java
+++ b/blur-core/src/main/java/org/apache/blur/thrift/TableAdmin.java
@@ -16,13 +16,18 @@ package org.apache.blur.thrift;
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+import java.io.File;
 import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 
+import javax.xml.parsers.FactoryConfigurationError;
+
 import org.apache.blur.BlurConfiguration;
 import org.apache.blur.analysis.FieldManager;
 import org.apache.blur.analysis.FieldTypeDefinition;
@@ -34,6 +39,7 @@ 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.ColumnDefinition;
+import org.apache.blur.thrift.generated.Level;
 import org.apache.blur.thrift.generated.Metric;
 import org.apache.blur.thrift.generated.Schema;
 import org.apache.blur.thrift.generated.Selector;
@@ -43,6 +49,9 @@ import org.apache.blur.trace.Trace;
 import org.apache.blur.trace.TraceStorage;
 import org.apache.blur.utils.BlurUtil;
 import org.apache.blur.utils.MemoryReporter;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.log4j.xml.DOMConfigurator;
 import org.apache.zookeeper.ZooKeeper;
 
 public abstract class TableAdmin implements Iface {
@@ -577,4 +586,81 @@ public abstract class TableAdmin implements Iface {
   public void ping() throws TException {
 
   }
+
+  @Override
+  public void logging(String classNameOrLoggerName, Level level) throws BlurException, TException
{
+    Logger logger;
+    if (classNameOrLoggerName == null) {
+      logger = LogManager.getRootLogger();
+    } else {
+      logger = LogManager.getLogger(classNameOrLoggerName);
+    }
+
+    if (logger == null) {
+      throw new BException("Logger [{0}] not found.", classNameOrLoggerName);
+    }
+    org.apache.log4j.Level current = logger.getLevel();
+    org.apache.log4j.Level newLevel = getLevel(level);
+    LOG.info("Changing Logger [{0}] from logging level [{1}] to [{2}]", logger, current,
newLevel);
+    logger.setLevel(newLevel);
+  }
+
+  @Override
+  public void resetLogging() throws BlurException, TException {
+    try {
+      reloadConfig();
+    } catch (MalformedURLException e) {
+      throw new BException("Unknown error while trying to reload log4j config.");
+    } catch (FactoryConfigurationError e) {
+      throw new BException("Unknown error while trying to reload log4j config.");
+    }
+  }
+
+  private void reloadConfig() throws MalformedURLException, FactoryConfigurationError, BException
{
+    String blurHome = System.getenv("BLUR_HOME");
+    if (blurHome != null) {
+      File blurHomeFile = new File(blurHome);
+      if (blurHomeFile.exists()) {
+        File log4jFile = new File(new File(blurHomeFile, "conf"), "log4j.xml");
+        if (log4jFile.exists()) {
+          LOG.info("Reseting log4j config from [{0}]", log4jFile);
+          LogManager.resetConfiguration();
+          DOMConfigurator.configure(log4jFile.toURI().toURL());
+          return;
+        }
+      }
+    }
+    URL url = TableAdmin.class.getResource("/log4j.xml");
+    if (url != null) {
+      LOG.info("Reseting log4j config from classpath resource [{0}]", url);
+      LogManager.resetConfiguration();
+      DOMConfigurator.configure(url);
+      return;
+    }
+    throw new BException("Could not locate log4j file to reload, doing nothing.");
+  }
+
+  private org.apache.log4j.Level getLevel(Level level) throws BlurException {
+    switch (level) {
+    case ALL:
+      return org.apache.log4j.Level.ALL;
+    case DEBUG:
+      return org.apache.log4j.Level.DEBUG;
+    case ERROR:
+      return org.apache.log4j.Level.ERROR;
+    case FATAL:
+      return org.apache.log4j.Level.FATAL;
+    case INFO:
+      return org.apache.log4j.Level.INFO;
+    case TRACE:
+      return org.apache.log4j.Level.TRACE;
+    case OFF:
+      return org.apache.log4j.Level.OFF;
+    case WARN:
+      return org.apache.log4j.Level.WARN;
+    default:
+      throw new BException("Level [{0}] not found.", level);
+    }
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b726909c/blur-shell/generate_docs.sh
----------------------------------------------------------------------
diff --git a/blur-shell/generate_docs.sh b/blur-shell/generate_docs.sh
index 89a6153..c5c8c41 100755
--- a/blur-shell/generate_docs.sh
+++ b/blur-shell/generate_docs.sh
@@ -16,4 +16,4 @@
 # limitations under the License.
 
 
-mvn exec:java -Dexec.mainClass="org.apache.blur.shell.GenerateDoc" -Dexec.args="../docs/using-blur.base.html
../docs/using-blur.html"
+mvn exec:java -Dhadoop1 -Dexec.mainClass="org.apache.blur.shell.GenerateDoc" -Dexec.args="../docs/using-blur.base.html
../docs/using-blur.html"

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b726909c/blur-shell/src/main/java/org/apache/blur/shell/Command.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/Command.java b/blur-shell/src/main/java/org/apache/blur/shell/Command.java
index 70d3419..193c432 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/Command.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/Command.java
@@ -40,7 +40,11 @@ public abstract class Command {
       BlurException;
 
   public final String help() {
-    return description() + " " + "Usage: " + name() + " " + usage();
+    return "Usage: " + name() + " " + usage();
+  }
+
+  public final String helpWithDescription() {
+    return description() + "\n\n" + "Usage: " + name() + " " + usage();
   }
 
   abstract public String description();

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b726909c/blur-shell/src/main/java/org/apache/blur/shell/LogCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/LogCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/LogCommand.java
new file mode 100644
index 0000000..5364a26
--- /dev/null
+++ b/blur-shell/src/main/java/org/apache/blur/shell/LogCommand.java
@@ -0,0 +1,69 @@
+/**
+ * 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.BlurClient;
+import org.apache.blur.thrift.generated.Blur;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.Level;
+
+public class LogCommand extends Command {
+  @Override
+  public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
+      BlurException {
+    if (args.length != 4) {
+      throw new CommandException("Invalid args: " + help());
+    }
+
+    Iface clientToNode = BlurClient.getClient(args[1]);
+    Level level = Level.valueOf(args[2].toUpperCase().trim());
+    String classNameOrLoggerName = args[3].trim();
+    if (classNameOrLoggerName.equals("ROOT")) {
+      clientToNode.logging(null, level);
+    } else {
+      clientToNode.logging(classNameOrLoggerName, level);
+    }
+  }
+
+  @Override
+  public String description() {
+    StringBuilder builder = new StringBuilder();
+    for (Level level : Level.values()) {
+      if (builder.length() != 0) {
+        builder.append(", ");
+      }
+      builder.append(level.toString());
+    }
+    return "Change log levels of a server.  Levels are: " + builder.toString();
+  }
+
+  @Override
+  public String usage() {
+    return "<node:port> <log level> <logger name or class name>";
+  }
+
+  @Override
+  public String name() {
+    return "logger";
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b726909c/blur-shell/src/main/java/org/apache/blur/shell/LogResetCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/LogResetCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/LogResetCommand.java
new file mode 100644
index 0000000..66e57c7
--- /dev/null
+++ b/blur-shell/src/main/java/org/apache/blur/shell/LogResetCommand.java
@@ -0,0 +1,64 @@
+/**
+ * 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.BlurClient;
+import org.apache.blur.thrift.generated.Blur;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.Level;
+
+public class LogResetCommand extends Command {
+
+  @Override
+  public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
+      BlurException {
+    if (args.length != 2) {
+      throw new CommandException("Invalid args: " + help());
+    }
+
+    Iface clientToNode = BlurClient.getClient(args[1]);
+    clientToNode.resetLogging();
+  }
+
+  @Override
+  public String description() {
+    StringBuilder builder = new StringBuilder();
+    for (Level level : Level.values()) {
+      if (builder.length() != 0) {
+        builder.append(", ");
+      }
+      builder.append(level.toString());
+    }
+    return "Reset/reload log configuration of a server.";
+  }
+
+  @Override
+  public String usage() {
+    return "<node:port>";
+  }
+
+  @Override
+  public String name() {
+    return "logger-reset";
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b726909c/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 2f1613c..6735689 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
@@ -405,23 +405,36 @@ 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[] serverCommands = { "logger", "logger-reset" };
 
   private static class HelpCommand extends Command {
     @Override
     public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
         BlurException {
-      out.println("Available commands:");
 
       Map<String, Command> cmds = new TreeMap<String, Command>(commands);
+      if (args.length == 2) {
+        String commandStr = args[1];
+        out.println(" - " + commandStr + " help -");
+        out.println();
+        Command command = cmds.get(commandStr);
+        if (command == null) {
+          out.println("Command " + commandStr + " not found.");
+          return;
+        }
+        out.println(command.helpWithDescription());
+        out.println();
+        return;
+      }
+
+      out.println("Available commands:");
 
       int bufferLength = getMaxCommandLength(cmds.keySet()) + 2;
       out.println(" - Table commands - ");
-
       printCommandAndHelp(out, cmds, tableCommands, bufferLength);
 
       out.println();
       out.println(" - Data commands - ");
-
       printCommandAndHelp(out, cmds, dataCommands, bufferLength);
 
       out.println();
@@ -429,6 +442,10 @@ public class Main {
       printCommandAndHelp(out, cmds, clusterCommands, bufferLength);
 
       out.println();
+      out.println(" - Server commands - ");
+      printCommandAndHelp(out, cmds, serverCommands, bufferLength);
+
+      out.println();
       out.println(" - Shell commands - ");
 
       printCommandAndHelp(out, cmds, shellCommands, bufferLength);
@@ -520,7 +537,7 @@ public class Main {
   }
 
   public static void main(String[] args) throws Throwable {
-    
+
     Trace.setStorage(new LogTraceStorage(new BlurConfiguration()));
 
     args = removeLeadingShellFromScript(args);
@@ -675,6 +692,8 @@ public class Main {
     register(builder, new TraceCommand());
     register(builder, new TraceList());
     register(builder, new TraceRemove());
+    register(builder, new LogCommand());
+    register(builder, new LogResetCommand());
     commands = builder.build();
   }
 


Mime
View raw message