Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 66649 invoked from network); 28 Oct 2010 23:32:25 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 28 Oct 2010 23:32:25 -0000 Received: (qmail 90122 invoked by uid 500); 28 Oct 2010 23:25:45 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 90088 invoked by uid 500); 28 Oct 2010 23:25:45 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 90081 invoked by uid 99); 28 Oct 2010 23:25:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Oct 2010 23:25:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Thu, 28 Oct 2010 23:25:42 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9B50B2388A1C; Thu, 28 Oct 2010 23:24:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1028541 - in /directory/apacheds/branches/apacheds-config/core-api/src/main/java/org/apache/directory/server/core: AbstractLayout.java InstanceLayout.java Date: Thu, 28 Oct 2010 23:24:44 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101028232444.9B50B2388A1C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Thu Oct 28 23:24:44 2010 New Revision: 1028541 URL: http://svn.apache.org/viewvc?rev=1028541&view=rev Log: Added the Layout classes in core-api Added: directory/apacheds/branches/apacheds-config/core-api/src/main/java/org/apache/directory/server/core/AbstractLayout.java directory/apacheds/branches/apacheds-config/core-api/src/main/java/org/apache/directory/server/core/InstanceLayout.java Added: directory/apacheds/branches/apacheds-config/core-api/src/main/java/org/apache/directory/server/core/AbstractLayout.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-config/core-api/src/main/java/org/apache/directory/server/core/AbstractLayout.java?rev=1028541&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-config/core-api/src/main/java/org/apache/directory/server/core/AbstractLayout.java (added) +++ directory/apacheds/branches/apacheds-config/core-api/src/main/java/org/apache/directory/server/core/AbstractLayout.java Thu Oct 28 23:24:44 2010 @@ -0,0 +1,222 @@ +package org.apache.directory.server.core; + + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +import java.io.File; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Convenience class to encapsulate paths to various directories and files within + * an layout. + * + * @author Apache Directory Project + */ +public abstract class AbstractLayout +{ + /** The logger*/ + private final static Logger log = LoggerFactory.getLogger( AbstractLayout.class ); + + /** The required directories */ + private File[] requiredDirectories = new File[0]; + + /** The required files */ + private File[] requiredFiles = new File[0]; + + /** The directory */ + private File directory; + + + /** + * Creates a new instance of AbstractLayout. + * + * @param directory + * the directory + */ + protected AbstractLayout( File directory ) + { + this.directory = directory; + } + + + /** + * Creates a new instance of AbstractLayout. + * + * @param directoryPath + * the path to the directory + */ + protected AbstractLayout( String directoryPath ) + { + this.directory = new File( directoryPath ); + } + + + /** + * Gets the installation directory. + * + * @return + * the installation directory + */ + protected File getDirectory() + { + return directory; + } + + + /** + * Gets the required directories. + * + * @return + * the required directories + */ + public File[] getRequiredDirectories() + { + return requiredDirectories; + } + + + /** + * Gets the required files. + * + * @return + * the required files + */ + public File[] getRequiredFiles() + { + return requiredFiles; + } + + + /** + * Creates the required directories (if they don't already exist). + */ + public void mkdirs() + { + for ( File requiredDirectory : requiredDirectories ) + { + if ( !requiredDirectory.exists() ) + { + requiredDirectory.mkdirs(); + } + } + } + + + /** + * Sets the required directories. + * + * @param requiredDirectories + * an array of required directories + */ + protected void setRequiredDirectories( File[] requiredDirectories ) + { + this.requiredDirectories = requiredDirectories; + } + + + /** + * Sets the required files. + * + * @param requiredFiles + * an array of required files + */ + protected void setRequiredFiles( File[] requiredFiles ) + { + this.requiredFiles = requiredFiles; + } + + + /** + * Verifies the installation by checking required directories and files. + */ + public void verifyInstallation() + { + log.debug( "Verifying required directories" ); + + // Verifying required directories + for ( File requiredDirectory : requiredDirectories ) + { + // Exists? + if ( !requiredDirectory.exists() ) + { + String message = "The required '" + requiredDirectory + " directory does not exist!"; + log.error( message ); + throw new IllegalStateException( message ); + } + + // Directory? + if ( requiredDirectory.isFile() ) + { + String message = "'" + requiredDirectory + "' is a file when it should be a directory."; + log.error( message ); + throw new IllegalStateException( message ); + } + + // Writable? + if ( !requiredDirectory.canWrite() ) + { + String message = "'" + requiredDirectory + + "' is write protected from the current user '" + + System.getProperty( "user.name" ) + "'"; + log.error( message ); + throw new IllegalStateException( message ); + } + } + + log.debug( "Required directories verification finished successfully." ); + + log.debug( "Verifying required files" ); + + // Verifying required files + for ( File requiredFile : requiredFiles ) + { + // Exists? + if ( !requiredFile.exists() ) + { + String message = "The required'" + requiredFile + "' file does not exist!"; + log.error( message ); + throw new IllegalStateException( message ); + } + + // File? + if ( requiredFile.isDirectory() ) + { + String message = "'" + requiredFile + "' is a directory when it should be a file."; + log.error( message ); + throw new IllegalStateException( message ); + } + + // Writable? + if ( !requiredFile.canRead() ) + { + String message = "'" + requiredFile + "' is not readable by the current user '" + + System.getProperty( "user.name" ) + "'."; + log.error( message ); + throw new IllegalStateException( message ); + } + } + + log.debug( "Required files verification finished successfully." ); + } +} Added: directory/apacheds/branches/apacheds-config/core-api/src/main/java/org/apache/directory/server/core/InstanceLayout.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-config/core-api/src/main/java/org/apache/directory/server/core/InstanceLayout.java?rev=1028541&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-config/core-api/src/main/java/org/apache/directory/server/core/InstanceLayout.java (added) +++ directory/apacheds/branches/apacheds-config/core-api/src/main/java/org/apache/directory/server/core/InstanceLayout.java Thu Oct 28 23:24:44 2010 @@ -0,0 +1,325 @@ +package org.apache.directory.server.core; + + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +import java.io.File; + + +/** + * Convenience class to encapsulate paths to various directories and files within + * an instance. + *
+ * The default layout is : + *
+ *  <instance directory>
+ *    |
+ *    +-- conf/
+ *    |    |
+ *    |    +-- config.ldif
+ *    |    |
+ *    |    +-- wrapper.conf
+ *    |    |
+ *    |    +-- log4j.properties
+ *    |
+ *    +-- partitions/
+ *    |    |
+ *    |    +-- system/
+ *    |    |    |
+ *    |    |    +-- master.db
+ *    |    |    |
+ *    |    |    +-- objectclass.db
+ *    |    |    |
+ *    |    |    +-- objectclass.lg
+ *    |    |    |
+ *    |    |    +-- <index XXX lg and db files>
+ *    |    |
+ *    |    +-- schema/
+ *    |    |    |
+ *    |    |    :
+ *    |    |
+ *    |    +-- <partition XXX>/
+ *    |    |    |
+ *    |    :    :
+ *    |
+ *    +-- log
+ *    |    |
+ *    |   [+-- journal.ldif]
+ *    |    |
+ *    |    +-- <log file>
+ *    |
+ *    +-- run
+ * 
+ * @author Apache Directory Project + */ +public class InstanceLayout extends AbstractLayout +{ + // Static final fields for system property names + private static final String LOG_DIR = "apacheds.log.dir"; + private static final String RUN_DIR = "apacheds.run.dir"; + + /** Static directory names */ + private static final String LOG_NAME = "log"; + private static final String RUN_NAME = "run"; + private static final String CONF_NAME = "conf"; + private static final String PARTITIONS_NAME = "partitions"; + + /** Static file names */ + private static final String LOG4J_PROPERTIES = "log4j.properties"; + private static final String WRAPPER_CONF = "wrapper.conf"; + private static final String CONFIG_LDIF = "config.ldif"; + + /** The Log directory */ + private File logDir; + + /** The Partitions directory */ + private File partitionsDir; + + /** The Run directory */ + private File runDir; + + /** The Conf directory */ + private File confDir; + + + /** + * Creates a new instance of InstanceLayout. + * + * @param instanceDirectory the instance directory + */ + public InstanceLayout( File instanceDirectory ) + { + super( instanceDirectory ); + init(); + } + + + /** + * Creates a new instance of InstanceLayout. + * + * @param instanceDirectoryPath the path to the instance directory + */ + public InstanceLayout( String instanceDirectoryPath ) + { + super( instanceDirectoryPath ); + init(); + } + + + /** + * Initializes the InstanceLayout. + */ + private void init() + { + // The required directories + File[] requiredDirectories = new File[] + { + getInstanceDirectory(), + getConfDirectory(), + getLogDirectory(), + getPartitionsDirectory(), + getRunDirectory() + }; + setRequiredDirectories( requiredDirectories ); + + // The required files + File[] requiredFiles = new File[] + { + getWrapperConfigurationFile(), + getLogConfigurationFile() /*, + getApacheDsConfigurationLdifFile() */// TODO re-activate this when possible. + }; + setRequiredFiles( requiredFiles ); + } + + + /** + * Gets the 'conf' directory. + * + * @return the 'conf' directory + */ + public File getConfDirectory() + { + if ( confDir == null ) + { + confDir = new File( getInstanceDirectory(), CONF_NAME ); + } + + return confDir; + } + + + /** + * @param confDir the confDir to set + */ + public void setConfDir( File confDir ) + { + this.confDir = confDir; + } + + + /** + * Gets the 'log' directory. + * + * @return the 'log' directory + */ + public File getLogDirectory() + { + if ( logDir == null ) + { + String systemLogDir = System.getProperty( LOG_DIR ); + + if ( systemLogDir != null ) + { + logDir = new File( systemLogDir ); + } + else + { + logDir = new File( getInstanceDirectory(), LOG_NAME ); + } + } + + return logDir; + } + + + /** + * @param logDir the logDir to set + */ + public void setLogDir( File logDir ) + { + this.logDir = logDir; + } + + + /** + * Gets the 'partitions' directory. + * + * @return the 'partitions' directory + */ + public File getPartitionsDirectory() + { + if ( partitionsDir == null ) + { + partitionsDir = new File( getInstanceDirectory(), PARTITIONS_NAME ); + } + + return partitionsDir; + } + + + /** + * @param partitionsDir the partitionsDir to set + */ + public void setPartitionsDir( File partitionsDir ) + { + this.partitionsDir = partitionsDir; + } + + + /** + * Gets the 'run' directory in the installation directory. + * + * @return the 'run' directory + */ + public File getRunDirectory() + { + if ( runDir == null ) + { + String systemRunDir = System.getProperty( RUN_DIR ); + + if ( systemRunDir != null ) + { + runDir = new File( systemRunDir ); + } + else + { + runDir = new File( getInstanceDirectory(), RUN_NAME ); + } + } + + return runDir; + } + + + /** + * @param runDir the runDir to set + */ + public void setRunDir( File runDir ) + { + this.runDir = runDir; + } + + + /** + * Gets the instance directory. + * + * @return the instance directory + */ + public File getInstanceDirectory() + { + return getDirectory(); + } + + + /** + * Gets the log configuration file ('/conf/log4j.properties'). + * + * @return the log configuration file + */ + public File getLogConfigurationFile() + { + return new File( getConfDirectory(), LOG4J_PROPERTIES ); + } + + + /** + * Gets the wrapper configuration file ('/conf/wrapper.conf'). + * + * @return the wrapper configuration file + */ + public File getWrapperConfigurationFile() + { + return new File( getConfDirectory(), WRAPPER_CONF ); + } + + + /** + * Gets the apacheds configuration ldif file ('/conf/wrapper.conf'). + * + * @return the apacheds configuration ldif file + */ + public File getApacheDsConfigurationLdifFile() + { + return new File( getConfDirectory(), CONFIG_LDIF ); + } + + + public String toString() + { + return "Instance Layout: \n" + + " Instance dir : " + getInstanceDirectory() + "\n" + + " Instance conf dir : " + getConfDirectory() + "\n" + + " Instance log dir : " + getLogDirectory() + "\n" + + " Instance run dir : " + getRunDirectory() + "\n" + + " Instance partitions dir : " + getPartitionsDirectory() + "\n"; + } +}