From kalumet-commits-return-136-apmail-incubator-kalumet-commits-archive=incubator.apache.org@incubator.apache.org Fri Jun 8 14:18:57 2012 Return-Path: X-Original-To: apmail-incubator-kalumet-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-kalumet-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BB256C518 for ; Fri, 8 Jun 2012 14:18:57 +0000 (UTC) Received: (qmail 25298 invoked by uid 500); 8 Jun 2012 14:18:57 -0000 Delivered-To: apmail-incubator-kalumet-commits-archive@incubator.apache.org Received: (qmail 25251 invoked by uid 500); 8 Jun 2012 14:18:57 -0000 Mailing-List: contact kalumet-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: kalumet-dev@incubator.apache.org Delivered-To: mailing list kalumet-commits@incubator.apache.org Received: (qmail 25236 invoked by uid 99); 8 Jun 2012 14:18:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jun 2012 14:18:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jun 2012 14:18:54 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7271E2388962; Fri, 8 Jun 2012 14:18:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: kalumet-commits@incubator.apache.org From: jbonofre@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120608141832.7271E2388962@eris.apache.org> 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 Environment 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 Environment 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 @@ - - + +