chukwa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asrab...@apache.org
Subject svn commit: r759379 - in /hadoop/chukwa/trunk: ./ src/java/org/apache/hadoop/chukwa/inputtools/log4j/ src/test/org/apache/hadoop/chukwa/inputtools/log4j/
Date Fri, 27 Mar 2009 22:39:45 GMT
Author: asrabkin
Date: Fri Mar 27 22:39:45 2009
New Revision: 759379

URL: http://svn.apache.org/viewvc?rev=759379&view=rev
Log:
CHUKWA-28.  Late initialization of log4j appender.  (contributed by Jerome Boulon)

Added:
    hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/inputtools/log4j/TestChukwaDailyRollingFileAppender.java
    hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/inputtools/log4j/late-log4j.properties
Modified:
    hadoop/chukwa/trunk/CHANGES.txt
    hadoop/chukwa/trunk/build.xml
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/ChukwaDailyRollingFileAppender.java

Modified: hadoop/chukwa/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/CHANGES.txt?rev=759379&r1=759378&r2=759379&view=diff
==============================================================================
--- hadoop/chukwa/trunk/CHANGES.txt (original)
+++ hadoop/chukwa/trunk/CHANGES.txt Fri Mar 27 22:39:45 2009
@@ -35,6 +35,8 @@
 
   BUG FIXES
 
+    CHUKWA-28.  Late initalization of log4j adaptor.  (Jerome Boulon via asrabkin)
+
     CHUKWA-48.  Cleanup code to resolve compiler warnings.  (asrabkin)
 
     CHUKWA-9.  MetricDataLoader should close JDBC connection.  (Jerome Boulon via asrabkin)

Modified: hadoop/chukwa/trunk/build.xml
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/build.xml?rev=759379&r1=759378&r2=759379&view=diff
==============================================================================
--- hadoop/chukwa/trunk/build.xml (original)
+++ hadoop/chukwa/trunk/build.xml Fri Mar 27 22:39:45 2009
@@ -272,7 +272,7 @@
                 <property name="test.build.testjar" value="${test.build.dir}/testjar"/>
                 <property name="test.include" value="Test*"/>
                 <property name="test.classpath.id" value="test.classpath"/>
-                <property name="test.output" value="yes"/>
+                <property name="test.output" value="no"/>
                 <property name="test.timeout" value="900000"/>
                 <property name="test.junit.output.format" value="plain"/>
                 <property name="test.junit.fork.mode" value="perTest" />
@@ -360,13 +360,20 @@
                  <classpath refid="testClasspath" />
                  <classpath refid="testDemuxClasspath" />
             </javac>
+
+            <copy todir="${test.build.dir}/classes/org/apache/hadoop/chukwa/inputtools/log4j/">
+                  <fileset dir="${basedir}/src/test/org/apache/hadoop/chukwa/inputtools/log4j/">
+                     <include name="late-log4j.properties" />
+                  </fileset>
+            </copy>
+
         </target>
 
             <!--printsummary="${test.junit.printsummary}" -->
 
 	<target name="test-chukwa" depends="compile,compile-test" description="Run Chukwa unit
tests">
           <mkdir dir="${basedir}/var"/>
-          <junit showoutput="yes"
+          <junit showoutput="${test.output}"
             fork="yes"
             printsummary="withOutAndErr"
             forkmode="${test.junit.fork.mode}"

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/ChukwaDailyRollingFileAppender.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/ChukwaDailyRollingFileAppender.java?rev=759379&r1=759378&r2=759379&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/ChukwaDailyRollingFileAppender.java
(original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/ChukwaDailyRollingFileAppender.java
Fri Mar 27 22:39:45 2009
@@ -183,6 +183,9 @@
    */
   private int maxBackupIndex = 10;
 
+  private ClientFinalizer clientFinalizer = null;
+  
+  boolean hasBeenActivated = false;
   Date now = new Date();
 
   SimpleDateFormat sdf;
@@ -225,7 +228,6 @@
         .println("Daily Rolling File Appender successfully registered file with agent: "
             + filename);
     this.datePattern = datePattern;
-    activateOptions();
   }
 
   /**
@@ -253,6 +255,11 @@
   }
 
   public void activateOptions() {
+    
+    // Prevent early initialisation
+    if (!hasBeenActivated)
+    { return;}
+    
     super.activateOptions();
     if (datePattern != null && fileName != null) {
       now.setTime(System.currentTimeMillis());
@@ -478,7 +485,22 @@
     }
   }
 
-  private ClientFinalizer clientFinalizer = null;
+  
+  /**
+   * Fix for late-initialisation
+   */
+  @Override
+  protected boolean checkEntryConditions() {
+    if (!hasBeenActivated) {
+      synchronized(chukwaLock) {
+        if (!hasBeenActivated) {
+          hasBeenActivated = true;
+          activateOptions();
+        }
+      }
+    }
+    return super.checkEntryConditions();
+  }
 
   /**
    * This method differentiates DailyRollingFileAppender from its super class.
@@ -514,6 +536,11 @@
 
             chukwaClientIsNull = false;
 
+            // FIXME: Hack to make the log file readable by chukwa user. 
+            if(System.getProperty("os.name").intern()=="Linux".intern()) {
+              Runtime.getRuntime().exec("chmod 640 "+getFile());
+            }
+            
             // Watchdog is watching for ChukwaAgent only once every 5 minutes,
             // so there's no point in retrying more than once every 5 mins.
             // In practice, if the watchdog is not able to automatically restart

Added: hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/inputtools/log4j/TestChukwaDailyRollingFileAppender.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/inputtools/log4j/TestChukwaDailyRollingFileAppender.java?rev=759379&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/inputtools/log4j/TestChukwaDailyRollingFileAppender.java
(added)
+++ hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/inputtools/log4j/TestChukwaDailyRollingFileAppender.java
Fri Mar 27 22:39:45 2009
@@ -0,0 +1,64 @@
+package org.apache.hadoop.chukwa.inputtools.log4j;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Date;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.hadoop.chukwa.datacollection.agent.ChukwaAgent;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.log4j.helpers.LogLog;
+import org.apache.log4j.helpers.OptionConverter;
+
+public class TestChukwaDailyRollingFileAppender extends TestCase {
+
+  @SuppressWarnings("deprecation")
+  public void testlateInit4ChukwaDailyRollingFileAppender() {
+
+    String folder = System.getProperty("test.build.data", "/tmp");
+    File tempDir = new File(folder);
+    if (!tempDir.exists()) {
+      tempDir.mkdirs();
+    }
+    // load new log4j
+    String configuratorClassName = OptionConverter.getSystemProperty(
+        LogManager.CONFIGURATOR_CLASS_KEY, null);
+
+    URL url = TestChukwaDailyRollingFileAppender.class
+        .getResource("late-log4j.properties");
+
+    System.getProperties().setProperty("CHUKWA_TEST_LOG_LATE_INIT", folder);
+
+    if (url != null) {
+      LogLog
+          .debug("Using URL [" + url + "] for automatic log4j configuration.");
+      try {
+        OptionConverter.selectAndConfigure(url, configuratorClassName,
+            LogManager.getLoggerRepository());
+      } catch (NoClassDefFoundError e) {
+        LogLog.warn("Error during default initialization", e);
+      }
+    } else {
+      Assert.fail("URL should not be null");
+    }
+    File logFile = new File(folder + "/chukwaTestLateLogInit.log");
+    if (logFile.exists()) {
+      logFile.delete();
+    }
+    Assert.assertTrue("Log file should not be there", logFile.exists() == false);
+    Logger log = Logger.getLogger(ChukwaAgent.class);
+    try {
+      Thread.sleep(2000);
+    }catch (Exception e) {
+      // do nothing
+    }
+    Assert.assertTrue("Log file should not be there", logFile.exists() == false);
+    log.warn("test 123 " + new Date());
+    Assert.assertTrue("Log file should not be there", logFile.exists() == true);
+    logFile.delete();
+  }
+
+}

Added: hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/inputtools/log4j/late-log4j.properties
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/inputtools/log4j/late-log4j.properties?rev=759379&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/inputtools/log4j/late-log4j.properties
(added)
+++ hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/inputtools/log4j/late-log4j.properties
Fri Mar 27 22:39:45 2009
@@ -0,0 +1,12 @@
+log4j.rootLogger=INFO, R
+#log4j.appender.R=org.apache.log4j.RollingFileAppender
+log4j.appender.R=org.apache.hadoop.chukwa.inputtools.log4j.ChukwaDailyRollingFileAppender
+log4j.appender.R.File=${CHUKWA_TEST_LOG_LATE_INIT}/chukwaTestLateLogInit.log
+log4j.appender.R.DatePattern=.yyyy-MM-dd
+log4j.appender.R.MaxBackupIndex=10
+log4j.appender.R.layout=org.apache.log4j.PatternLayout
+log4j.appender.R.layout.ConversionPattern=%d{ISO8601} %p %t %c{1} - %m%n
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %p %t %c{1} - %m%n



Mime
View raw message