directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1515755 - in /directory/apacheds/trunk: server-config/src/main/java/org/apache/directory/server/config/beans/ service-builder/ service-builder/src/main/java/org/apache/directory/server/config/builder/
Date Tue, 20 Aug 2013 09:54:31 GMT
Author: kayyagari
Date: Tue Aug 20 09:54:30 2013
New Revision: 1515755

URL: http://svn.apache.org/r1515755
Log:
o configuration beans for mavibot partition
o initialize mavbot partition from the configuration (DIRSERVER-1886)

Added:
    directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/MavibotIndexBean.java
    directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/MavibotPartitionBean.java
Modified:
    directory/apacheds/trunk/service-builder/pom.xml
    directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/builder/ServiceBuilder.java

Added: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/MavibotIndexBean.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/MavibotIndexBean.java?rev=1515755&view=auto
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/MavibotIndexBean.java
(added)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/MavibotIndexBean.java
Tue Aug 20 09:54:30 2013
@@ -0,0 +1,61 @@
+/*
+ *   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.
+ *
+ */
+package org.apache.directory.server.config.beans;
+
+
+
+
+/**
+ * A class used to store the MavibotIndex configuration.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class MavibotIndexBean<K, E> extends IndexBean
+{
+    /**
+     * Create a new MavibotIndexBean instance
+     */
+    public MavibotIndexBean()
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString( String tabs )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append( tabs ).append( "MavibotIndexBean :\n" );
+        sb.append( super.toString( tabs ) );
+
+        return sb.toString();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString()
+    {
+        return toString( "" );
+    }
+}

Added: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/MavibotPartitionBean.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/MavibotPartitionBean.java?rev=1515755&view=auto
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/MavibotPartitionBean.java
(added)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/MavibotPartitionBean.java
Tue Aug 20 09:54:30 2013
@@ -0,0 +1,61 @@
+/*
+ *   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.
+ *
+ */
+package org.apache.directory.server.config.beans;
+
+
+
+
+/**
+ * A class used to store the MavibotPartition configuration.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class MavibotPartitionBean extends PartitionBean
+{
+    /**
+     * Create a new JdbmPartitionBean instance
+     */
+    public MavibotPartitionBean()
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString( String tabs )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append( tabs ).append( "JdbmPartitionBean :\n" );
+        sb.append( super.toString( tabs ) );
+
+        return sb.toString();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString()
+    {
+        return toString( "" );
+    }
+}

Modified: directory/apacheds/trunk/service-builder/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/service-builder/pom.xml?rev=1515755&r1=1515754&r2=1515755&view=diff
==============================================================================
--- directory/apacheds/trunk/service-builder/pom.xml (original)
+++ directory/apacheds/trunk/service-builder/pom.xml Tue Aug 20 09:54:30 2013
@@ -116,6 +116,11 @@
     </dependency>
     
     <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>apacheds-mavibot-partition</artifactId>
+    </dependency>
+
+    <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <scope>test</scope>

Modified: directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/builder/ServiceBuilder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/builder/ServiceBuilder.java?rev=1515755&r1=1515754&r2=1515755&view=diff
==============================================================================
--- directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/builder/ServiceBuilder.java
(original)
+++ directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/builder/ServiceBuilder.java
Tue Aug 20 09:54:30 2013
@@ -62,6 +62,8 @@ import org.apache.directory.server.confi
 import org.apache.directory.server.config.beans.JournalBean;
 import org.apache.directory.server.config.beans.KdcServerBean;
 import org.apache.directory.server.config.beans.LdapServerBean;
+import org.apache.directory.server.config.beans.MavibotIndexBean;
+import org.apache.directory.server.config.beans.MavibotPartitionBean;
 import org.apache.directory.server.config.beans.NtpServerBean;
 import org.apache.directory.server.config.beans.PartitionBean;
 import org.apache.directory.server.config.beans.PasswordPolicyBean;
@@ -81,6 +83,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.api.interceptor.Interceptor;
 import org.apache.directory.server.core.api.journal.Journal;
 import org.apache.directory.server.core.api.journal.JournalStore;
+import org.apache.directory.server.core.api.partition.AbstractPartition;
 import org.apache.directory.server.core.api.partition.Partition;
 import org.apache.directory.server.core.authn.AuthenticationInterceptor;
 import org.apache.directory.server.core.authn.Authenticator;
@@ -93,6 +96,10 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmRdnIndex;
+import org.apache.directory.server.core.partition.impl.btree.mavibot.MavibotDnIndex;
+import org.apache.directory.server.core.partition.impl.btree.mavibot.MavibotIndex;
+import org.apache.directory.server.core.partition.impl.btree.mavibot.MavibotPartition;
+import org.apache.directory.server.core.partition.impl.btree.mavibot.MavibotRdnIndex;
 import org.apache.directory.server.integration.http.HttpServer;
 import org.apache.directory.server.integration.http.WebApp;
 import org.apache.directory.server.kerberos.ChangePasswordConfig;
@@ -1292,42 +1299,7 @@ public class ServiceBuilder
         jdbmPartition.setIndexedAttributes( createJdbmIndexes( jdbmPartition, jdbmPartitionBean.getIndexes(),
             directoryService ) );
 
-        String contextEntry = jdbmPartitionBean.getContextEntry();
-
-        if ( contextEntry != null )
-        {
-            try
-            {
-                // Replace '\n' to real LF
-                String entryStr = contextEntry.replaceAll( "\\\\n", "\n" );
-
-                LdifReader ldifReader = new LdifReader();
-
-                List<LdifEntry> entries = ldifReader.parseLdif( entryStr );
-
-                if ( ( entries != null ) && ( entries.size() > 0 ) )
-                {
-                    LdifEntry entry = entries.get( 0 );
-                    jdbmPartition.setContextEntry( entry.getEntry() );
-                }
-
-                try
-                {
-                    ldifReader.close();
-                }
-                catch ( IOException ioe )
-                {
-                    LOG.error( "Cannot close the ldif reader" );
-                }
-
-            }
-            catch ( LdapLdifException lle )
-            {
-                String message = "Cannot parse the context entry : " + contextEntry + ",
" + lle.getMessage();
-                LOG.error( message );
-                throw new ConfigurationException( message );
-            }
-        }
+        setContextEntry( jdbmPartitionBean, jdbmPartition );
 
         return jdbmPartition;
     }
@@ -1352,6 +1324,10 @@ public class ServiceBuilder
         {
             return createJdbmPartition( directoryService, ( JdbmPartitionBean ) partitionBean
);
         }
+        else if ( partitionBean instanceof MavibotPartitionBean )
+        {
+            return createMavibotPartition( directoryService, ( MavibotPartitionBean ) partitionBean
);
+        }
         else
         {
             return null;
@@ -1484,4 +1460,150 @@ public class ServiceBuilder
 
         return directoryService;
     }
+    
+    
+    public static MavibotPartition createMavibotPartition( DirectoryService directoryService,
+        MavibotPartitionBean mvbtPartitionBean ) throws ConfigurationException
+    {
+        if ( ( mvbtPartitionBean == null ) || mvbtPartitionBean.isDisabled() )
+        {
+            return null;
+        }
+
+        MavibotPartition mvbtPartition = new MavibotPartition( directoryService.getSchemaManager()
);
+
+        mvbtPartition.setId( mvbtPartitionBean.getPartitionId() );
+        //mvbtPartition.setOptimizerEnabled( mvbtPartitionBean.isJdbmPartitionOptimizerEnabled()
);
+        File partitionPath = new File( directoryService.getInstanceLayout().getPartitionsDirectory(),
+            mvbtPartitionBean.getPartitionId() );
+        mvbtPartition.setPartitionPath( partitionPath.toURI() );
+
+        try
+        {
+            mvbtPartition.setSuffixDn( mvbtPartitionBean.getPartitionSuffix() );
+        }
+        catch ( LdapInvalidDnException lide )
+        {
+            String message = "Cannot set the Dn " + mvbtPartitionBean.getPartitionSuffix()
+ ", " + lide.getMessage();
+            LOG.error( message );
+            throw new ConfigurationException( message );
+        }
+
+        mvbtPartition.setSyncOnWrite( mvbtPartitionBean.isPartitionSyncOnWrite() );
+        mvbtPartition.setIndexedAttributes( createMavibotIndexes( mvbtPartition, mvbtPartitionBean.getIndexes(),
+            directoryService ) );
+
+        setContextEntry( mvbtPartitionBean, mvbtPartition );
+
+        return mvbtPartition;
+    }
+ 
+    
+    /**
+     * Create the list of MavibotIndex from the configuration
+     */
+    private static Set<Index<?, ?, String>> createMavibotIndexes( MavibotPartition
partition,
+        List<IndexBean> indexesBeans,
+        DirectoryService directoryService ) //throws Exception
+    {
+        Set<Index<?, ?, String>> indexes = new HashSet<Index<?, ?, String>>();
+
+        for ( IndexBean indexBean : indexesBeans )
+        {
+            if ( indexBean.isEnabled() && ( indexBean instanceof MavibotIndexBean
) )
+            {
+                indexes.add( createMavibotIndex( partition, ( MavibotIndexBean ) indexBean,
directoryService ) );
+            }
+        }
+
+        return indexes;
+    }
+
+    
+    /**
+     * Create a new instance of a MavibotIndex from an instance of MavibotIndexBean
+     * 
+     * @param MavibotIndexBean The MavibotIndexBean to convert
+     * @return An MavibotIndex instance
+     * @throws Exception If the instance cannot be created
+     */
+    public static MavibotIndex<?, ?> createMavibotIndex( MavibotPartition partition,
+        MavibotIndexBean<String, Entry> mavobotIndexBean, DirectoryService directoryService
)
+    {
+        if ( ( mavobotIndexBean == null ) || mavobotIndexBean.isDisabled() )
+        {
+            return null;
+        }
+
+        MavibotIndex<?, ?> index = null;
+
+        boolean hasReverse = mavobotIndexBean.getIndexHasReverse();
+
+        if ( mavobotIndexBean.getIndexAttributeId().equalsIgnoreCase( ApacheSchemaConstants.APACHE_RDN_AT
) ||
+            mavobotIndexBean.getIndexAttributeId().equalsIgnoreCase( ApacheSchemaConstants.APACHE_RDN_AT_OID
) )
+        {
+            index = new MavibotRdnIndex();
+        }
+        else if ( mavobotIndexBean.getIndexAttributeId().equalsIgnoreCase( ApacheSchemaConstants.APACHE_ALIAS_AT
) ||
+            mavobotIndexBean.getIndexAttributeId().equalsIgnoreCase( ApacheSchemaConstants.APACHE_ALIAS_AT_OID
) )
+        {
+            index = new MavibotDnIndex( ApacheSchemaConstants.APACHE_ALIAS_AT_OID );
+        }
+        else
+        {
+            index = new MavibotIndex<String, Entry>( mavobotIndexBean.getIndexAttributeId(),
hasReverse );
+        }
+
+        index.setWkDirPath( partition.getPartitionPath() );
+        
+        return index;
+    }
+
+
+    /**
+     * Sets the configured context entry if present in the given partition bean 
+     *
+     * @param bean the partition configuration bean
+     * @param partition the partition instance
+     * @throws ConfigurationException
+     */
+    private static void setContextEntry(PartitionBean bean, AbstractPartition partition)
throws ConfigurationException
+    {
+        String contextEntry = bean.getContextEntry();
+
+        if ( contextEntry != null )
+        {
+            try
+            {
+                // Replace '\n' to real LF
+                String entryStr = contextEntry.replaceAll( "\\\\n", "\n" );
+
+                LdifReader ldifReader = new LdifReader();
+
+                List<LdifEntry> entries = ldifReader.parseLdif( entryStr );
+
+                if ( ( entries != null ) && ( entries.size() > 0 ) )
+                {
+                    LdifEntry entry = entries.get( 0 );
+                    partition.setContextEntry( entry.getEntry() );
+                }
+
+                try
+                {
+                    ldifReader.close();
+                }
+                catch ( IOException ioe )
+                {
+                    LOG.error( "Cannot close the ldif reader" );
+                }
+
+            }
+            catch ( LdapLdifException lle )
+            {
+                String message = "Cannot parse the context entry : " + contextEntry + ",
" + lle.getMessage();
+                LOG.error( message );
+                throw new ConfigurationException( message );
+            }
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message