directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
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 GMT
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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+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.
+ * <br>
+ * The default layout is :
+ * <pre>
+ *  &lt;instance directory&gt;
+ *    |
+ *    +-- conf/
+ *    |    |
+ *    |    +-- config.ldif
+ *    |    |
+ *    |    +-- wrapper.conf
+ *    |    |
+ *    |    +-- log4j.properties
+ *    |
+ *    +-- partitions/
+ *    |    |
+ *    |    +-- system/
+ *    |    |    |
+ *    |    |    +-- master.db
+ *    |    |    |
+ *    |    |    +-- objectclass.db
+ *    |    |    |
+ *    |    |    +-- objectclass.lg
+ *    |    |    |
+ *    |    |    +-- &lt;index XXX lg and db files&gt;
+ *    |    |
+ *    |    +-- schema/
+ *    |    |    |
+ *    |    |    :
+ *    |    |
+ *    |    +-- &lt;partition XXX&gt;/
+ *    |    |    |
+ *    |    :    :
+ *    |
+ *    +-- log
+ *    |    |
+ *    |   [+-- journal.ldif]
+ *    |    |
+ *    |    +-- &lt;log file&gt;
+ *    |
+ *    +-- run
+ * </pre>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+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 (<em>'/conf/log4j.properties'</em>).
+     *
+     * @return the log configuration file
+     */
+    public File getLogConfigurationFile()
+    {
+        return new File( getConfDirectory(), LOG4J_PROPERTIES );
+    }
+
+
+    /**
+     * Gets the wrapper configuration file (<em>'/conf/wrapper.conf'</em>).
+     *
+     * @return the wrapper configuration file
+     */
+    public File getWrapperConfigurationFile()
+    {
+        return new File( getConfDirectory(), WRAPPER_CONF );
+    }
+
+
+    /**
+     * Gets the apacheds configuration ldif file (<em>'/conf/wrapper.conf'</em>).
+     *
+     * @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";
+    }
+}



Mime
View raw message