Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D752F200BAE for ; Thu, 13 Oct 2016 14:31:54 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D0689160AF8; Thu, 13 Oct 2016 12:31:54 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 03CA6160AE4 for ; Thu, 13 Oct 2016 14:31:53 +0200 (CEST) Received: (qmail 98599 invoked by uid 500); 13 Oct 2016 12:31:53 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 98524 invoked by uid 99); 13 Oct 2016 12:31:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Oct 2016 12:31:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 909B3E95B8; Thu, 13 Oct 2016 12:31:52 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jonathanhurley@apache.org To: commits@ambari.apache.org Date: Thu, 13 Oct 2016 12:31:54 -0000 Message-Id: <3427ed8e3ef5419e824ef03de4add296@git.apache.org> In-Reply-To: <81e95d5f95a645afac54f84a501460d2@git.apache.org> References: <81e95d5f95a645afac54f84a501460d2@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/7] ambari git commit: AMBARI-18543. Option to enable request/access logs in Ambari. (Amarnath reddy pappu via swagle) archived-at: Thu, 13 Oct 2016 12:31:55 -0000 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-feature-AMBARI-18456 Commit: 60dc240216bf54f35dfb5d3fea823ccceee2c9a4 Parents: 5d007e2 Author: Siddharth Wagle Authored: Wed Oct 12 11:04:54 2016 -0700 Committer: Siddharth Wagle 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 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 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 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 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());