You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2016/10/13 12:43:28 UTC

[16/20] ambari git commit: AMBARI-18543. Option to enable request/access logs in Ambari. (Amarnath reddy pappu via swagle)

AMBARI-18543. Option to enable request/access logs in Ambari. (Amarnath reddy pappu via swagle)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/60dc2402
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/60dc2402
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/60dc2402

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 60dc240216bf54f35dfb5d3fea823ccceee2c9a4
Parents: 5d007e2
Author: Siddharth Wagle <sw...@hortonworks.com>
Authored: Wed Oct 12 11:04:54 2016 -0700
Committer: Siddharth Wagle <sw...@hortonworks.com>
Committed: Wed Oct 12 11:04:54 2016 -0700

----------------------------------------------------------------------
 ambari-server/conf/windows/ambari.properties    |  1 +
 .../server/configuration/Configuration.java     | 23 +++++++++
 .../ambari/server/controller/AmbariServer.java  | 50 ++++++++++++++++++++
 3 files changed, 74 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/60dc2402/ambari-server/conf/windows/ambari.properties
----------------------------------------------------------------------
diff --git a/ambari-server/conf/windows/ambari.properties b/ambari-server/conf/windows/ambari.properties
index c1c0a99..e47319e 100644
--- a/ambari-server/conf/windows/ambari.properties
+++ b/ambari-server/conf/windows/ambari.properties
@@ -51,6 +51,7 @@ server.execution.scheduler.maxThreads=5
 server.execution.scheduler.maxDbConnections=5
 server.execution.scheduler.misfire.toleration.minutes=480
 
+
 # Kerberos settings
 kerberos.keytab.cache.dir = data\\cache
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/60dc2402/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index e976f45..378db18 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -1680,6 +1680,27 @@ public class Configuration {
       "server.tmp.dir", AmbariPath.getPath("/var/lib/ambari-server/tmp"));
 
   /**
+   * Request logs path .
+   */
+  @Markdown(description = "The location on the Ambari Server where request logs can be created.")
+  public static final ConfigurationProperty<String> REQUEST_LOGPATH = new ConfigurationProperty<>(
+      "server.requestlogs.path", null);
+
+  /**
+   * The pattern of request  logs .
+   */
+  @Markdown(description = "The pattern of request log file name")
+  public static final ConfigurationProperty<String> REQUEST_LOGNAMEPATTERN = new ConfigurationProperty<>(
+          "server.requestlogs.namepattern", "ambari-access-yyyy_mm_dd.log");
+
+  /**
+   * The number of days request logs can be retained.
+   */
+  @Markdown(description = "The number of days that request log would be retained.")
+  public static final ConfigurationProperty<Integer> REQUEST_LOG_RETAINDAYS = new ConfigurationProperty<>(
+          "server.requestlogs.retaindays", 15);
+
+  /**
    * The time, in {@link TimeUnit#MILLISECONDS}, until an external script is killed.
    */
   @Markdown(description = "The time, in milliseconds, until an external script is killed.")
@@ -2566,6 +2587,8 @@ public class Configuration {
     configsMap.put(JAVA_HOME.getKey(), getProperty(JAVA_HOME));
     configsMap.put(PARALLEL_STAGE_EXECUTION.getKey(), getProperty(PARALLEL_STAGE_EXECUTION));
     configsMap.put(SERVER_TMP_DIR.getKey(), getProperty(SERVER_TMP_DIR));
+    configsMap.put(REQUEST_LOGPATH.getKey(), getProperty(REQUEST_LOGPATH));
+    configsMap.put(REQUEST_LOG_RETAINDAYS.getKey(), getProperty(REQUEST_LOG_RETAINDAYS));
     configsMap.put(EXTERNAL_SCRIPT_TIMEOUT.getKey(), getProperty(EXTERNAL_SCRIPT_TIMEOUT));
     configsMap.put(SHARED_RESOURCES_DIR.getKey(), getProperty(SHARED_RESOURCES_DIR));
     configsMap.put(KDC_PORT.getKey(), getProperty(KDC_PORT));

http://git-wip-us.apache.org/repos/asf/ambari/blob/60dc2402/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
index 5e498f0..c05840e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
@@ -124,12 +124,17 @@ import org.apache.ambari.server.view.AmbariViewsMDCLoggingFilter;
 import org.apache.ambari.server.view.ViewDirectoryWatcher;
 import org.apache.ambari.server.view.ViewRegistry;
 import org.apache.ambari.server.view.ViewThrottleFilter;
+import org.apache.commons.lang.StringUtils;
 import org.apache.velocity.app.Velocity;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.SessionIdManager;
 import org.eclipse.jetty.server.SessionManager;
 import org.eclipse.jetty.server.nio.SelectChannelConnector;
 import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
+import org.eclipse.jetty.server.NCSARequestLog;
+import org.eclipse.jetty.server.handler.HandlerCollection;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.handler.RequestLogHandler;
 import org.eclipse.jetty.servlet.DefaultServlet;
 import org.eclipse.jetty.servlet.FilterHolder;
 import org.eclipse.jetty.servlet.ServletContextHandler;
@@ -497,6 +502,9 @@ public class AmbariServer {
       viewRegistry.readViewArchives();
       viewDirectoryWatcher.start();
 
+      //Check and load requestlog handler.
+      loadRequestlogHandler(handlerList, serverForAgent, configsMap);
+
       handlerList.addHandler(root);
       server.setHandler(handlerList);
 
@@ -933,6 +941,48 @@ public class AmbariServer {
     LOG.info(Joiner.on("\n" + linePrefix).join(rawMessages));
   }
 
+  /**
+   * For loading requestlog handlers
+   */
+  private static void loadRequestlogHandler(AmbariHandlerList handlerList, Server serverForAgent , Map<String, String> configsMap) {
+
+    //Example:  /var/log/ambari-server/ambari-server-access-yyyy_mm_dd.log
+    String requestlogpath =  configsMap.get(Configuration.REQUEST_LOGPATH.getKey());
+
+    //Request logs can be disable by removing the property from ambari.properties file
+    if(!StringUtils.isBlank(requestlogpath)) {
+      String logfullpath = requestlogpath + "//" + Configuration.REQUEST_LOGNAMEPATTERN.getDefaultValue();
+      LOG.info("********* Initializing request access log: " + logfullpath);
+      RequestLogHandler requestLogHandler = new RequestLogHandler();
+
+      NCSARequestLog requestLog = new NCSARequestLog(requestlogpath);
+
+      String retaindays = configsMap.get(Configuration.REQUEST_LOG_RETAINDAYS.getKey());
+      int retaindaysInt = Configuration.REQUEST_LOG_RETAINDAYS.getDefaultValue();
+      if(retaindays != null && !StringUtils.isBlank(retaindays)) {
+        retaindaysInt = Integer.parseInt(retaindays.trim());
+      }
+
+      requestLog.setRetainDays(retaindaysInt);
+      requestLog.setAppend(true);
+      requestLog.setLogLatency(true);
+      requestLog.setExtended(true);
+      requestLogHandler.setRequestLog(requestLog);
+      //Add requestloghandler to existing handlerlist.
+      handlerList.addHandler(requestLogHandler);
+
+      //For agent communication.
+      HandlerCollection handlers = new HandlerCollection();
+      Handler[] handler = serverForAgent.getHandlers();
+      if(handler != null ) {
+        handlers.setHandlers((Handler[])handler);
+        handlers.addHandler(requestLogHandler);
+        serverForAgent.setHandler(handlers);
+      }
+
+    }
+  }
+
   public static void main(String[] args) throws Exception {
     logStartup();
     Injector injector = Guice.createInjector(new ControllerModule(), new AuditLoggerModule());