directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1088546 - in /directory/apacheds/trunk: protocol-ldap/src/main/java/org/apache/directory/server/ldap/ server-config/src/main/java/org/apache/directory/server/config/beans/ server-config/src/main/resources/ service-builder/src/main/java/org...
Date Mon, 04 Apr 2011 10:35:24 GMT
Author: kayyagari
Date: Mon Apr  4 10:35:24 2011
New Revision: 1088546

URL: http://svn.apache.org/viewvc?rev=1088546&view=rev
Log:
o added support for reading replication configuration and starting the replication consumers
o added a new entry in config.ldif for holding the replication consumer configuration


Modified:
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
    directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/LdapServerBean.java
    directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/ReplConsumerBean.java
    directory/apacheds/trunk/server-config/src/main/resources/config.ldif
    directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/ServiceBuilder.java

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java?rev=1088546&r1=1088545&r2=1088546&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
Mon Apr  4 10:35:24 2011
@@ -53,9 +53,8 @@ import org.apache.directory.server.ldap.
 import org.apache.directory.server.ldap.handlers.bind.MechanismHandler;
 import org.apache.directory.server.ldap.handlers.extended.StartTlsHandler;
 import org.apache.directory.server.ldap.handlers.ssl.LdapsInitializer;
+import org.apache.directory.server.ldap.replication.ReplicationConsumer;
 import org.apache.directory.server.ldap.replication.ReplicationRequestHandler;
-import org.apache.directory.server.ldap.replication.SyncReplConsumer;
-import org.apache.directory.server.ldap.replication.SyncreplConfiguration;
 import org.apache.directory.server.protocol.shared.DirectoryBackedService;
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 import org.apache.directory.server.protocol.shared.transport.Transport;
@@ -65,7 +64,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.extras.controls.SyncInfoValue;
 import org.apache.directory.shared.ldap.extras.controls.SyncRequestValue;
 import org.apache.directory.shared.ldap.extras.controls.SyncStateValue;
-import org.apache.directory.shared.ldap.model.message.extended.NoticeOfDisconnect;
 import org.apache.directory.shared.ldap.model.constants.SaslQoP;
 import org.apache.directory.shared.ldap.model.exception.LdapConfigurationException;
 import org.apache.directory.shared.ldap.model.message.AbandonRequest;
@@ -85,6 +83,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.controls.PagedResults;
 import org.apache.directory.shared.ldap.model.message.controls.PersistentSearch;
 import org.apache.directory.shared.ldap.model.message.controls.Subentries;
+import org.apache.directory.shared.ldap.model.message.extended.NoticeOfDisconnect;
 import org.apache.directory.shared.util.Strings;
 import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
 import org.apache.mina.core.filterchain.IoFilterChainBuilder;
@@ -213,9 +212,7 @@ public class LdapServer extends Director
 
     private ReplicationRequestHandler replicationReqHandler;
 
-    private List<SyncreplConfiguration> providerConfigs;
-
-    private List<SyncReplConsumer> replConsumers;
+    private List<ReplicationConsumer> replConsumers;
 
 
     /**
@@ -636,11 +633,9 @@ public class LdapServer extends Director
      */
     private void startConsumers() throws Exception
     {
-        if ( providerConfigs != null )
+        if ( replConsumers != null )
         {
-            replConsumers = new ArrayList<SyncReplConsumer>( providerConfigs.size()
);
-
-            for ( final SyncreplConfiguration config : providerConfigs )
+            for ( final ReplicationConsumer consumer : replConsumers )
             {
                 Runnable consumerTask = new Runnable()
                 {
@@ -648,16 +643,14 @@ public class LdapServer extends Director
                     {
                         try
                         {
-                            SyncReplConsumer consumer = new SyncReplConsumer();
-                            LOG.info( "starting the replication consumer with config {}",
config );
-                            consumer.init( getDirectoryService(), config );
-                            consumer.connect();
+                            LOG.info( "starting the replication consumer with config {}",
consumer );
+                            consumer.init( getDirectoryService() );
                             replConsumers.add( consumer );
-                            consumer.startSync();
+                            consumer.start();
                         }
                         catch ( Exception e )
                         {
-                            LOG.error( "Failed to start the consumer with config {}", config
);
+                            LOG.error( "Failed to start the consumer with config {}", consumer
);
                             throw new RuntimeException( e );
                         }
                     }
@@ -678,10 +671,10 @@ public class LdapServer extends Director
     {
         if ( replConsumers != null )
         {
-            for ( SyncReplConsumer consumer : replConsumers )
+            for ( ReplicationConsumer consumer : replConsumers )
             {
-                LOG.info( "stopping the consumer with id {}", consumer.getConfig().getReplicaId()
);
-                consumer.disconnet();
+                LOG.info( "stopping the consumer with id {}", consumer.getId() );
+                consumer.stop();
             }
         }
     }
@@ -1331,9 +1324,9 @@ public class LdapServer extends Director
     }
 
 
-    public void setReplProviderConfigs( List<SyncreplConfiguration> providerConfigs
)
+    public void setReplConsumers( List<ReplicationConsumer> replConsumers )
     {
-        this.providerConfigs = providerConfigs;
+        this.replConsumers = replConsumers;
     }
 
 

Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/LdapServerBean.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/LdapServerBean.java?rev=1088546&r1=1088545&r2=1088546&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/LdapServerBean.java
(original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/LdapServerBean.java
Mon Apr  4 10:35:24 2011
@@ -65,13 +65,13 @@ public class LdapServerBean extends DSBa
     @ConfigurationElement(attributeType = "ads-certificatePassword")
     private String certificatePassword;
 
-    /** tells if the replication is enabled */
-    @ConfigurationElement(attributeType = "ads-enableReplProvider")
-    private boolean enableReplProvider;
+    /** the replication request handler, server will be in replication provider/master mode
if a valid FQCN is given */
+    @ConfigurationElement(attributeType = "ads-replReqHandler")
+    private String replReqHandler;
 
     /** The replication consumer Bean */
-    @ConfigurationElement
-    private ReplConsumerBean replConsumer;
+    @ConfigurationElement(attributeType = "ads-replConsumers", container = "replConsumers")
+    private List<ReplConsumerBean> replConsumers;
 
     /** The replication producer Bean */
     @ConfigurationElement
@@ -255,38 +255,20 @@ public class LdapServerBean extends DSBa
 
 
     /**
-     * @return the replProviderImpl
-     *
-    public ReplicationProviderBean getReplProviderImpl()
-    {
-        return replProviderImpl;
-    }
-
-    
-    /**
-     * @param replProviderImpl the replProviderImpl to set
-     *
-    public void setReplProviderImpl( ReplicationProviderBean replProviderImpl )
-    {
-        this.replProviderImpl = replProviderImpl;
-    }
-
-    
-    /**
-     * @return the enableReplProvider
+     * @return the replReqHandler
      */
-    public boolean isEnableReplProvider()
+    public String getReplReqHandler()
     {
-        return enableReplProvider;
+        return replReqHandler;
     }
 
 
     /**
-     * @param enableReplProvider the enableReplProvider to set
+     * @param replReqHandler the replReqHandler to set
      */
-    public void setEnableReplProvider( boolean enableReplProvider )
+    public void setReplReqHandler( String replReqHandler )
     {
-        this.enableReplProvider = enableReplProvider;
+        this.replReqHandler = replReqHandler;
     }
 
 
@@ -354,22 +336,34 @@ public class LdapServerBean extends DSBa
     /**
      * @return the Replication Consumer Bean
      */
-    public ReplConsumerBean getReplConsumer()
+    public List<ReplConsumerBean> getReplConsumers()
     {
-        return replConsumer;
+        return replConsumers;
     }
 
 
     /**
-     * @param replConsumer the Replication Consumer Bean to set
+     * @param replConsumers the Replication Consumer Bean to set
      */
-    public void setReplConsumer( ReplConsumerBean replConsumer )
+    public void setReplConsumer( List<ReplConsumerBean> replConsumers )
     {
-        this.replConsumer = replConsumer;
+        this.replConsumers = replConsumers;
     }
 
 
     /**
+     * @param replConsumers the Replication Consumer Bean to set
+     */
+    public void addReplConsumers( ReplConsumerBean... replConsumers )
+    {
+        for( ReplConsumerBean bean : replConsumers )
+        {
+            this.replConsumers.add( bean );
+        }
+    }
+
+    
+    /**
      * @return the replProvider
      */
     public ReplProviderBean getReplProvider()
@@ -403,7 +397,7 @@ public class LdapServerBean extends DSBa
         sb.append( toString( tabs, "  sasl principal", saslPrincipal ) );
         sb.append( tabs ).append( "  sasl host : " ).append( saslHost ).append( '\n' );
         sb.append( toString( tabs, "  confidentiality required", confidentialityRequired
) );
-        sb.append( toString( tabs, "  enable replication provider", enableReplProvider )
);
+        sb.append( toString( tabs, "  enable replication provider", replReqHandler ) );
 
         if ( ( extendedOpHandlers != null ) && ( extendedOpHandlers.size() > 0
) )
         {
@@ -435,11 +429,16 @@ public class LdapServerBean extends DSBa
             }
         }
 
-        if ( replConsumer != null )
+        if ( ( replConsumers != null ) && ( replConsumers.size() > 0 ) )
         {
-            sb.append( tabs ).append( replConsumer.toString( tabs + "  " ) );
-        }
+            sb.append( tabs ).append( "  replication consumers :\n" );
 
+            for ( ReplConsumerBean replConsumer : replConsumers )
+            {
+                sb.append( replConsumer.toString( tabs + "    " ) );
+            }
+        }
+        
         if ( replProvider != null )
         {
             sb.append( tabs ).append( replProvider.toString( tabs + "  " ) );

Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/ReplConsumerBean.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/ReplConsumerBean.java?rev=1088546&r1=1088545&r2=1088546&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/ReplConsumerBean.java
(original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/ReplConsumerBean.java
Mon Apr  4 10:35:24 2011
@@ -75,6 +75,9 @@ public class ReplConsumerBean extends Ad
     @ConfigurationElement(attributeType = "ads-replPeerCertificate")
     private String replPeerCertificate;
 
+    /** The FQCN of replication client implementation */
+    @ConfigurationElement(attributeType = "ads-replConsumerImpl")
+    private String replConsumerImpl;
 
     /**
      * Create a new Replication Consumer instance
@@ -287,6 +290,24 @@ public class ReplConsumerBean extends Ad
 
 
     /**
+     * @return the replConsumerImpl
+     */
+    public String getReplConsumerImpl()
+    {
+        return replConsumerImpl;
+    }
+
+
+    /**
+     * @param replConsumerImpl the replConsumerImpl to set
+     */
+    public void setReplConsumerImpl( String replConsumerImpl )
+    {
+        this.replConsumerImpl = replConsumerImpl;
+    }
+
+
+    /**
      * {@inheritDoc}
      */
     public String toString( String tabs )
@@ -296,6 +317,7 @@ public class ReplConsumerBean extends Ad
         sb.append( tabs ).append( "Replication consumer :\n" );
         sb.append( super.toString( tabs + "  " ) );
 
+        sb.append( tabs ).append( "  consumer implementation's FQCN : " ).append( replConsumerImpl
).append( '\n' );
         sb.append( tabs ).append( "  consumer ID : " ).append( replConsumerId ).append( '\n'
);
         sb.append( tabs ).append( "  replica ID : " ).append( dsReplicaId ).append( '\n'
);
         sb.append( tabs ).append( "  last sent CSN : " ).append( replLastSentCsn ).append(
'\n' );

Modified: directory/apacheds/trunk/server-config/src/main/resources/config.ldif
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/resources/config.ldif?rev=1088546&r1=1088545&r2=1088546&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/resources/config.ldif (original)
+++ directory/apacheds/trunk/server-config/src/main/resources/config.ldif Mon Apr  4 10:35:24
2011
@@ -700,7 +700,6 @@ ads-saslRealms: example.com
 ads-saslRealms: apache.org
 ads-searchBaseDN: ou=users,ou=system
 ads-enabled: TRUE
-ads-enableReplProvider: FALSE
 ads-transports: ldap
 ads-transports: ldaps
 ads-saslmechhandlers: CRAM-MD5
@@ -713,6 +712,11 @@ ads-extendedophandlers: gracefulShutdown
 ads-extendedophandlers: starttlshandler
 ads-extendedophandlers: storedprochandler
 
+dn: ou=replConsumers,ads-serverId=ldapServer,ou=servers,ads-directoryServiceId=default,ou=config
+objectClass: organizationalUnit
+objectClass: top
+ou: replConsumers
+
 dn: ou=transports,ads-serverId=ldapServer,ou=servers,ads-directoryServiceId=default,ou=config
 ou: transports
 objectclass: organizationalUnit

Modified: directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/ServiceBuilder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/ServiceBuilder.java?rev=1088546&r1=1088545&r2=1088546&view=diff
==============================================================================
--- directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/ServiceBuilder.java
(original)
+++ directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/ServiceBuilder.java
Mon Apr  4 10:35:24 2011
@@ -51,6 +51,7 @@ import org.apache.directory.server.confi
 import org.apache.directory.server.config.beans.NtpServerBean;
 import org.apache.directory.server.config.beans.PartitionBean;
 import org.apache.directory.server.config.beans.PasswordPolicyBean;
+import org.apache.directory.server.config.beans.ReplConsumerBean;
 import org.apache.directory.server.config.beans.SaslMechHandlerBean;
 import org.apache.directory.server.config.beans.SimpleAuthenticatorBean;
 import org.apache.directory.server.config.beans.StrongAuthenticatorBean;
@@ -85,8 +86,10 @@ import org.apache.directory.server.ldap.
 import org.apache.directory.server.ldap.LdapServer;
 import org.apache.directory.server.ldap.handlers.bind.MechanismHandler;
 import org.apache.directory.server.ldap.handlers.bind.ntlm.NtlmMechanismHandler;
+import org.apache.directory.server.ldap.replication.ReplicationConsumer;
 import org.apache.directory.server.ldap.replication.ReplicationRequestHandler;
-import org.apache.directory.server.ldap.replication.SyncReplRequestHandler;
+import org.apache.directory.server.ldap.replication.SyncReplConsumer;
+import org.apache.directory.server.ldap.replication.SyncreplConfiguration;
 import org.apache.directory.server.ntp.NtpServer;
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 import org.apache.directory.server.protocol.shared.transport.Transport;
@@ -99,6 +102,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.ldif.LdapLdifException;
 import org.apache.directory.shared.ldap.model.ldif.LdifEntry;
 import org.apache.directory.shared.ldap.model.ldif.LdifReader;
+import org.apache.directory.shared.ldap.model.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.model.message.SearchScope;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.slf4j.Logger;
@@ -910,22 +915,11 @@ public class ServiceBuilder
             }
         }
 
-        // PasswordPolicy
-        // TODO
+        // ReplReqHandler
+        String fqcn = ldapServerBean.getReplReqHandler();
         
-        // ReplProvider
-        if ( ldapServerBean.isEnableReplProvider() )
+        if ( fqcn != null )
         {
-            //EntryAttribute replProvImplAttr = ldapServerEntry.get( ConfigSchemaConstants.ADS_REPL_PROVIDER_IMPL
);
-            
-            String fqcn = ldapServerBean.getReplProvider().getReplAttribute();
-            
-            if ( fqcn == null )
-            {
-                // default replication provider
-                fqcn = SyncReplRequestHandler.class.getName();
-            }
-            
             try
             {
                 Class<?> replProvImplClz = Class.forName( fqcn );
@@ -934,24 +928,87 @@ public class ServiceBuilder
             }
             catch( Exception e )
             {
-                String message = "Failed to load and instantiate ReplicationRequestHandler
implementation : " + e.getMessage();
+                String message = "Failed to load and instantiate ReplicationRequestHandler
implementation : " + fqcn;
                 LOG.error( message );
                 throw new ConfigurationException( message );
             }
             
-            // TODO
-            // ldapServer.setReplProviderConfigs( createReplProviderConfigs() );
         }
         
-        // ReplConsumer
-        // TODO 
+        ldapServer.setReplConsumers( createReplConsumers( ldapServerBean.getReplConsumers()
) );
         
-
         return ldapServer;
     }
     
     
     /**
+     * instantiate the ReplicationConsumers based on the configuration present in ReplConsumerBeans
+     * 
+     * @param replConsumerBeans the list of consumers configured
+     * @return a list of ReplicationConsumer instances
+     * @throws ConfigurationException
+     */
+    public static List<ReplicationConsumer> createReplConsumers( List<ReplConsumerBean>
replConsumerBeans ) throws ConfigurationException
+    {
+        List<ReplicationConsumer> lst = new ArrayList<ReplicationConsumer>();
+
+        if( replConsumerBeans == null )
+        {
+            return lst;
+        }
+        
+        for ( ReplConsumerBean replBean : replConsumerBeans )
+        {
+            String className = replBean.getReplConsumerImpl();
+            
+            
+            ReplicationConsumer consumer = null;
+            Class<?> consumerClass = null;
+            SyncreplConfiguration config = null;
+            
+            try
+            {
+                if( className == null )
+                {
+                    consumerClass = SyncReplConsumer.class; 
+                }
+                else
+                {
+                    consumerClass = Class.forName( className );
+                }
+                
+                consumer = ( ReplicationConsumer ) consumerClass.newInstance();
+                
+                // we don't support any other configuration impls atm, but this configuration
should suffice for many needs
+                config = new SyncreplConfiguration();
+                
+                config.setReplicaId( Integer.parseInt( replBean.getDsreplicaid() ) );
+                config.setAliasDerefMode( AliasDerefMode.getDerefMode( replBean.getReplAliasDerefMode()
) );
+                config.setBaseDn( replBean.getSearchBaseDn().getName() );
+                
+                int scope = SearchScope.getSearchScope( replBean.getReplSearchScope() );
+                config.setSearchScope( SearchScope.getSearchScope( scope ) );
+                
+                config.setFilter( replBean.getReplSearchFilter() );
+                config.setRefreshNPersist( replBean.isReplRefreshNPersist() );
+                config.setUseTls( replBean.isReplUseTls() );
+                config.setStrictCertVerification( replBean.isReplStrictCertValidation() );
+                
+                consumer.setConfig( config );
+                
+                lst.add( consumer );
+            }
+            catch( Exception e )
+            {
+                throw new ConfigurationException( "cannot configure the replication consumer
with FQCN " + className, e );
+            }
+        }
+        
+        return lst;
+    }
+    
+    
+    /**
      * Create a new instance of a JdbmIndex from an instance of JdbmIndexBean
      * 
      * @param JdbmIndexBean The JdbmIndexBean to convert



Mime
View raw message