incubator-kalumet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject svn commit: r1348084 [2/2] - in /incubator/kalumet/trunk: common/src/main/java/org/apache/kalumet/model/ console/ console/src/main/java/org/apache/kalumet/console/configuration/ console/src/main/resources/
Date Fri, 08 Jun 2012 14:18:32 GMT
Modified: incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/ConfigurationManager.java?rev=1348084&r1=1348083&r2=1348084&view=diff
==============================================================================
--- incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/ConfigurationManager.java
(original)
+++ incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/configuration/ConfigurationManager.java
Fri Jun  8 14:18:31 2012
@@ -33,127 +33,171 @@ import org.slf4j.LoggerFactory;
 /**
  * Load and manipulate the Kalumet configuration store.
  */
-public class ConfigurationManager {
+public class ConfigurationManager
+{
 
-    private final static transient Logger LOGGER = LoggerFactory.getLogger(ConfigurationManager.class);
+  private final static transient Logger LOGGER = LoggerFactory.getLogger( ConfigurationManager.class
);
 
-    private final static String KALUMET_CONSOLE_CONFIGURATION_FILE = "/kalumet-console-config.xml";
-    private final static String ENVIRONMENT_JOURNAL_FILE_EXTENSION = ".log";
+  private final static String KALUMET_CONSOLE_CONFIGURATION_FILE = "/kalumet-console-config.xml";
 
-    private static KalumetConsole KALUMET_CONSOLE_CACHE = null;
+  private final static String ENVIRONMENT_JOURNAL_FILE_EXTENSION = ".log";
 
-    private static Kalumet KALUMET_CACHE = null;
-    private static int KALUMET_CACHE_TIMEOUT_MINUTES = 5;
-    private static Date KALUMET_CACHE_DEPRECATION_DATE = null;
-
-    /**
-     * Load the Kalumet Console configuration.
-     *
-     * @return the Kalumet configuration object.
-     */
-    public final static KalumetConsole loadConfiguration() throws Exception {
-        if (KALUMET_CONSOLE_CACHE == null) {
-            LOGGER.debug("Loading Apache Kalumet console configuration from {}", KALUMET_CONSOLE_CONFIGURATION_FILE);
-            String configurationFile = null;
-            try {
-                configurationFile = ConfigurationManager.class.getResource(ConfigurationManager.KALUMET_CONSOLE_CONFIGURATION_FILE).toString();
-            } catch (NullPointerException nullPointerException) {
-                LOGGER.error("Apache Kalumet configuration file is not found in the server
classpath");
-                throw new IllegalStateException("Apache Kalumet configuration file is not
found in the server classpath");
-            }
-            KALUMET_CONSOLE_CACHE = KalumetConsole.digeste(configurationFile);
-        }
-        return KALUMET_CONSOLE_CACHE;
-    }
-
-    /**
-     * Get the Kalumet XML configuration location.
-     *
-     * @return the Kalumet XML configuration location.
-     */
-    private final static String getStoreFile() throws Exception {
-        KalumetConsole kalumetConsole = ConfigurationManager.loadConfiguration();
-        Property kalumetConsoleProperty = kalumetConsole.getProperty("ConfigurationLocation");
-        if (kalumetConsoleProperty == null) {
-            throw new IllegalStateException("The property ConfigurationLocation is not found
in the Apache Kalumet Console configuration. This property is required to use Apache Kalumet
Console and must contains the location (file: or http:) to the Kalumet configuration store");
-        }
-        return kalumetConsoleProperty.getValue();
-    }
-
-    /**
-     * Load the Kalumet configuration.
-     *
-     * @return the Kalumet configuration.
-     */
-    public final static Kalumet loadStore() throws Exception {
-        if (KALUMET_CACHE == null || KALUMET_CACHE_DEPRECATION_DATE.after(Calendar.getInstance().getTime()))
{
-            String kalumetConfigurationFile = ConfigurationManager.getStoreFile();
-            KALUMET_CACHE = Kalumet.digeste(kalumetConfigurationFile);
-            // update the deprecation date
-            Calendar timeout = Calendar.getInstance();
-            timeout.set(Calendar.MINUTE, timeout.get(Calendar.MINUTE) + KALUMET_CACHE_TIMEOUT_MINUTES);
-            KALUMET_CACHE_DEPRECATION_DATE = timeout.getTime();
-        }
-        return KALUMET_CACHE;
-    }
-
-    /**
-     * Read the Kalumet configuration store and return the XML raw content.
-     *
-     * @return the Kalumet XML raw content.
-     */
-    public final static String readStore() throws Exception {
-        String content = null;
-        return FileUtils.readFileToString(new File(ConfigurationManager.getStoreFile()),
"ISO-8859-1");
-    }
-
-    /**
-     * Write the Kalumet configuration.
-     *
-     * @param kalumet the Kalumet configuration object to store.
-     */
-    public final static void writeStore(Kalumet kalumet) throws Exception {
-        // get the kalumet configuration store location
-        String kalumetConfigurationLocation = ConfigurationManager.getStoreFile();
-        // write the file
-        kalumet.writeXMLFile(kalumetConfigurationLocation);
-        // update the cache
-        KALUMET_CACHE = kalumet;
-        // update the deprecation date
-        Calendar timeout = Calendar.getInstance();
-        timeout.set(Calendar.MINUTE, timeout.get(Calendar.MINUTE) + KALUMET_CACHE_TIMEOUT_MINUTES);
-        KALUMET_CACHE_DEPRECATION_DATE = timeout.getTime();
-    }
-
-    /**
-     * Get the Environment Journal location.
-     *
-     * @param environment the Environment name.
-     * @return the Environment Journal location.
-     */
-    public final static String getEnvironmentJournalFile(String environment) throws Exception
{
-        KalumetConsole kalumetConsole = ConfigurationManager.loadConfiguration();
-        Property kalumetConsoleProperty = kalumetConsole.getProperty("JournalsLocation");
-        if (kalumetConsoleProperty == null) {
-            throw new IllegalArgumentException("The property JournalsLocation is not found
in the Apache Kalumet Console configuration. This property is required to store the environment
journals and must contain the directory path for the journal files.");
-        }
-        return kalumetConsoleProperty.getValue() + "/" + environment + ConfigurationManager.ENVIRONMENT_JOURNAL_FILE_EXTENSION;
-    }
-
-    /**
-     * Read the environment journal.
-     *
-     * @param environment the <code>Environment</code> name.
-     * @return the environment journal object.
-     */
-    public final static Journal loadEnvironmentJournal(String environment) throws Exception
{
-        KalumetConsole kalumetConsole = ConfigurationManager.loadConfiguration();
-        Property kalumetJournalLocation = kalumetConsole.getProperty("JournalsLocation");
-        if (kalumetJournalLocation == null) {
-            throw new IllegalArgumentException("The property JournalsLocation is not found
in the Apache Kalumet Console configuration. This property is required to store the environment
journals and must contain the directory path for the journal files.");
-        }
-        Journal journal = null;
-        return Journal.digeste(kalumetJournalLocation.getValue() + "/" + environment + ConfigurationManager.ENVIRONMENT_JOURNAL_FILE_EXTENSION);
-    }
+  private static KalumetConsole KALUMET_CONSOLE_CACHE = null;
+
+  private static Kalumet KALUMET_CACHE = null;
+
+  private static int KALUMET_CACHE_TIMEOUT_MINUTES = 5;
+
+  private static Date KALUMET_CACHE_DEPRECATION_DATE = null;
+
+  /**
+   * Load the Kalumet Console configuration.
+   *
+   * @return the Kalumet configuration object.
+   */
+  public final static KalumetConsole loadConfiguration()
+    throws Exception
+  {
+    if ( KALUMET_CONSOLE_CACHE == null )
+    {
+      LOGGER.debug( "Loading Apache Kalumet console configuration from {}", KALUMET_CONSOLE_CONFIGURATION_FILE
);
+      String configurationFile = null;
+      try
+      {
+        configurationFile =
+          ConfigurationManager.class.getResource( ConfigurationManager.KALUMET_CONSOLE_CONFIGURATION_FILE
).toString();
+      }
+      catch ( NullPointerException nullPointerException )
+      {
+        LOGGER.error( "Apache Kalumet configuration file is not found in the server classpath"
);
+        throw new IllegalStateException( "Apache Kalumet configuration file is not found
in the server classpath" );
+      }
+      KALUMET_CONSOLE_CACHE = KalumetConsole.digeste( configurationFile );
+    }
+    return KALUMET_CONSOLE_CACHE;
+  }
+
+  /**
+   * Get the Kalumet XML configuration location.
+   *
+   * @return the Kalumet XML configuration location.
+   */
+  private final static String getStoreFile()
+    throws Exception
+  {
+    KalumetConsole kalumetConsole = ConfigurationManager.loadConfiguration();
+    Property kalumetConsoleProperty = kalumetConsole.getProperty( "ConfigurationLocation"
);
+    if ( kalumetConsoleProperty == null )
+    {
+      throw new IllegalStateException(
+        "The property ConfigurationLocation is not found in the Apache Kalumet Console configuration.
This property is required to use Apache Kalumet Console and must contains the location (file:
or http:) to the Kalumet configuration store" );
+    }
+    if ( System.getProperty( "kalumet.home" ) != null )
+    {
+      return System.getProperty( "kalumet.home" ) + "/" + kalumetConsoleProperty.getValue();
+    }
+    return kalumetConsoleProperty.getValue();
+  }
+
+  /**
+   * Load the Kalumet configuration.
+   *
+   * @return the Kalumet configuration.
+   */
+  public final static Kalumet loadStore()
+    throws Exception
+  {
+    if ( KALUMET_CACHE == null || KALUMET_CACHE_DEPRECATION_DATE.after( Calendar.getInstance().getTime()
) )
+    {
+      String kalumetConfigurationPath = ConfigurationManager.getStoreFile();
+      File kalumetConfigurationFile = new File( kalumetConfigurationPath );
+      if ( !kalumetConfigurationFile.exists() )
+      {
+        kalumetConfigurationFile.createNewFile();
+        // init with a default file
+        Kalumet.writeDefault( kalumetConfigurationPath );
+      }
+      KALUMET_CACHE = Kalumet.digeste( kalumetConfigurationPath );
+      // update the deprecation date
+      Calendar timeout = Calendar.getInstance();
+      timeout.set( Calendar.MINUTE, timeout.get( Calendar.MINUTE ) + KALUMET_CACHE_TIMEOUT_MINUTES
);
+      KALUMET_CACHE_DEPRECATION_DATE = timeout.getTime();
+    }
+    return KALUMET_CACHE;
+  }
+
+  /**
+   * Read the Kalumet configuration store and return the XML raw content.
+   *
+   * @return the Kalumet XML raw content.
+   */
+  public final static String readStore()
+    throws Exception
+  {
+    String content = null;
+    return FileUtils.readFileToString( new File( ConfigurationManager.getStoreFile() ), "ISO-8859-1"
);
+  }
+
+  /**
+   * Write the Kalumet configuration.
+   *
+   * @param kalumet the Kalumet configuration object to store.
+   */
+  public final static void writeStore( Kalumet kalumet )
+    throws Exception
+  {
+    // get the kalumet configuration store location
+    String kalumetConfigurationLocation = ConfigurationManager.getStoreFile();
+    // write the file
+    kalumet.writeXMLFile( kalumetConfigurationLocation );
+    // update the cache
+    KALUMET_CACHE = kalumet;
+    // update the deprecation date
+    Calendar timeout = Calendar.getInstance();
+    timeout.set( Calendar.MINUTE, timeout.get( Calendar.MINUTE ) + KALUMET_CACHE_TIMEOUT_MINUTES
);
+    KALUMET_CACHE_DEPRECATION_DATE = timeout.getTime();
+  }
+
+  /**
+   * Get the Environment Journal location.
+   *
+   * @param environment the Environment name.
+   * @return the Environment Journal location.
+   */
+  public final static String getEnvironmentJournalFile( String environment )
+    throws Exception
+  {
+    KalumetConsole kalumetConsole = ConfigurationManager.loadConfiguration();
+    Property kalumetConsoleProperty = kalumetConsole.getProperty( "JournalsLocation" );
+    if ( kalumetConsoleProperty == null )
+    {
+      throw new IllegalArgumentException(
+        "The property JournalsLocation is not found in the Apache Kalumet Console configuration.
This property is required to store the environment journals and must contain the directory
path for the journal files." );
+    }
+    File journalDir = new File( kalumetConsoleProperty.getValue() );
+    journalDir.mkdirs();
+    if ( System.getProperty( "kalumet.home" ) != null )
+    {
+      return System.getProperty( "kalumet.home" ) + "/" + kalumetConsoleProperty.getValue()
+ "/" + environment
+        + ConfigurationManager.ENVIRONMENT_JOURNAL_FILE_EXTENSION;
+    }
+    return kalumetConsoleProperty.getValue() + "/" + environment
+      + ConfigurationManager.ENVIRONMENT_JOURNAL_FILE_EXTENSION;
+  }
+
+  /**
+   * Read the environment journal.
+   *
+   * @param environment the <code>Environment</code> name.
+   * @return the environment journal object.
+   */
+  public final static Journal loadEnvironmentJournal( String environment )
+    throws Exception
+  {
+    KalumetConsole kalumetConsole = ConfigurationManager.loadConfiguration();
+    String journalPath = ConfigurationManager.getEnvironmentJournalFile( environment );
+    Journal journal = null;
+    return Journal.digeste( journalPath );
+  }
 
 }

Modified: incubator/kalumet/trunk/console/src/main/resources/kalumet-console-config.xml
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/console/src/main/resources/kalumet-console-config.xml?rev=1348084&r1=1348083&r2=1348084&view=diff
==============================================================================
--- incubator/kalumet/trunk/console/src/main/resources/kalumet-console-config.xml (original)
+++ incubator/kalumet/trunk/console/src/main/resources/kalumet-console-config.xml Fri Jun
 8 14:18:31 2012
@@ -2,7 +2,7 @@
 
 <kalumet-console>
 
-  <property name="ConfigurationLocation" value="/var/lib/apache-kalumet/db/kalumet.xml"/>
-  <property name="JournalsLocation" value="/var/lib/apache-kalumet/journals"/>
+  <property name="ConfigurationLocation" value="kalumet.xml"/>
+  <property name="JournalsLocation" value="journals"/>
 
 </kalumet-console>



Mime
View raw message