directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1153045 - in /directory/apacheds/trunk: core-annotations/src/main/java/org/apache/directory/server/core/factory/ protocol-ldap/src/main/java/org/apache/directory/server/ldap/ server-annotations/src/main/java/org/apache/directory/server/fac...
Date Tue, 02 Aug 2011 06:32:40 GMT
Author: elecharny
Date: Tue Aug  2 06:32:39 2011
New Revision: 1153045

URL: http://svn.apache.org/viewvc?rev=1153045&view=rev
Log:
o Added some javadoc
o Exposed the startProducer/Consumer methods in LdapServer
o Added the creation of the replication consumer in ServerAnnotation
o Fixed tests accordingly

Modified:
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
    directory/apacheds/trunk/server-annotations/src/main/java/org/apache/directory/server/factory/ServerAnnotationProcessor.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientInitialRefreshIT.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientServerReplicationIT.java

Modified: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java?rev=1153045&r1=1153044&r2=1153045&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
(original)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
Tue Aug  2 06:32:39 2011
@@ -232,6 +232,15 @@ public class DSAnnotationProcessor
         }
     }
     
+    
+    /**
+     * Get an instance of a class extracted from the @nnotation found in the method
+     * or the class.
+     * 
+     * @param clazz The Annotation we want to get an instance for
+     * @return The instance or null if no annotation is found
+     * @throws ClassNotFoundException If we can't find a class
+     */
     public static Object getInstance( Class<? extends Annotation> clazz ) throws ClassNotFoundException
     {
         Object instance = null;

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=1153045&r1=1153044&r2=1153045&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
Tue Aug  2 06:32:39 2011
@@ -485,19 +485,28 @@ public class LdapServer extends Director
         nexus.registerSupportedSaslMechanisms( saslMechanismHandlers.keySet() );
 
         // Install the replication handler if we have one
-        if ( replicationReqHandler != null )
-        {
-            replicationReqHandler.init( this );
-            ( ( SearchHandler ) getSearchHandler() ).setReplicationReqHandler( replicationReqHandler
);
-        }
+        startReplicationProducer();
 
         // And start the replication consumers on this server
-        startConsumers();
+        startReplicationConsumers();
 
         started = true;
 
         LOG.info( "Ldap service started." );
     }
+    
+
+    /**
+     * Install the replication handler if we have one
+     */
+    public void startReplicationProducer()
+    {
+        if ( replicationReqHandler != null )
+        {
+            replicationReqHandler.init( this );
+            ( ( SearchHandler ) getSearchHandler() ).setReplicationReqHandler( replicationReqHandler
);
+        }
+    }
 
 
     /**
@@ -633,7 +642,7 @@ public class LdapServer extends Director
     /**
      * starts the replication consumers
      */
-    private void startConsumers() throws Exception
+    public void startReplicationConsumers() throws Exception
     {
         if ( replConsumers != null )
         {

Modified: directory/apacheds/trunk/server-annotations/src/main/java/org/apache/directory/server/factory/ServerAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-annotations/src/main/java/org/apache/directory/server/factory/ServerAnnotationProcessor.java?rev=1153045&r1=1153044&r2=1153045&view=diff
==============================================================================
--- directory/apacheds/trunk/server-annotations/src/main/java/org/apache/directory/server/factory/ServerAnnotationProcessor.java
(original)
+++ directory/apacheds/trunk/server-annotations/src/main/java/org/apache/directory/server/factory/ServerAnnotationProcessor.java
Tue Aug  2 06:32:39 2011
@@ -23,6 +23,7 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.net.ServerSocket;
 
+import org.apache.directory.server.annotations.CreateConsumer;
 import org.apache.directory.server.annotations.CreateKdcServer;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
@@ -36,6 +37,9 @@ import org.apache.directory.server.ldap.
 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.handlers.bind.ntlm.NtlmProvider;
+import org.apache.directory.server.ldap.replication.ReplicationConsumer;
+import org.apache.directory.server.ldap.replication.SyncReplConsumer;
+import org.apache.directory.server.ldap.replication.SyncreplConfiguration;
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 import org.apache.directory.server.protocol.shared.transport.Transport;
 import org.apache.directory.server.protocol.shared.transport.UdpTransport;
@@ -214,6 +218,47 @@ public class ServerAnnotationProcessor
 
         return ldapServer;
     }
+    
+    
+    private static ReplicationConsumer createConsumer( CreateConsumer createConsumer )
+    {
+        ReplicationConsumer consumer = new SyncReplConsumer();
+        
+        SyncreplConfiguration config = new SyncreplConfiguration();
+        config.setRemoteHost( createConsumer.remoteHost() );
+        config.setRemotePort( createConsumer.remotePort() );
+        config.setReplUserDn( createConsumer.replUserDn() );
+        config.setReplUserPassword( Strings.getBytesUtf8( createConsumer.replUserPassword()
) );
+        config.setUseTls( createConsumer.useTls() );
+        config.setBaseDn( createConsumer.baseDn() );
+        config.setRefreshInterval( createConsumer.refreshInterval() );
+        
+        consumer.setConfig( config );
+
+        return consumer;
+    }
+    
+    
+    /**
+     * creates an LdapServer and starts before returning the instance, infering
+     * the configuration from the Stack trace
+     *  
+     * @return a running LdapServer instance
+     */
+    public static ReplicationConsumer createConsumer() throws ClassNotFoundException
+    {
+        Object instance = DSAnnotationProcessor.getInstance( CreateConsumer.class );
+        ReplicationConsumer consumer = null;
+        
+        if ( instance != null )
+        {
+            CreateConsumer createConsumer = (CreateConsumer)instance;
+            
+            consumer = createConsumer( createConsumer );
+        }
+
+        return consumer;
+    }
 
     
     /**
@@ -223,7 +268,7 @@ public class ServerAnnotationProcessor
      * @param directoryService the directory service
      * @return a running LdapServer instance
      */
-    public static LdapServer createLdapServer( CreateLdapServer createLdapServer, DirectoryService
directoryService )
+    private static LdapServer createLdapServer( CreateLdapServer createLdapServer, DirectoryService
directoryService )
     {
         LdapServer ldapServer = instantiateLdapServer( createLdapServer, directoryService
);
         
@@ -249,23 +294,6 @@ public class ServerAnnotationProcessor
     /**
      * Create a new instance of LdapServer
      *
-     * @param directoryService The associated DirectoryService
-     * @param startPort The port used by the server
-     * @return An LdapServer instance 
-     * @throws Exception If the server cannot be started
-     *
-    public static LdapServer createLdapServer( DirectoryService directoryService ) throws
Exception
-    {
-        CreateLdapServer createLdapServer = ( CreateLdapServer ) getAnnotation( CreateLdapServer.class
);
-        
-        // Ok, we have found a CreateLdapServer annotation. Process it now.
-        return createLdapServer( createLdapServer, directoryService );
-    }
-
-
-    /**
-     * Create a new instance of LdapServer
-     *
      * @param description A description for the created LdapServer
      * @param directoryService The associated DirectoryService
      * @param startPort The port used by the server

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientInitialRefreshIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientInitialRefreshIT.java?rev=1153045&r1=1153044&r2=1153045&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientInitialRefreshIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientInitialRefreshIT.java
Tue Aug  2 06:32:39 2011
@@ -23,7 +23,6 @@ package org.apache.directory.server.repl
 
 import static org.junit.Assert.assertTrue;
 
-import java.lang.reflect.Method;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.directory.server.annotations.CreateLdapServer;
@@ -157,17 +156,14 @@ public class ClientInitialRefreshIT
              })
     @CreateLdapServer(transports =
         { @CreateTransport( port=16000, protocol = "LDAP") })
-    private static void startProvider() throws Exception
+    public static void startProvider() throws Exception
     {
-        Method createProviderMethod = ClientInitialRefreshIT.class.getDeclaredMethod( "startProvider"
);
-        CreateDS dsAnnotation = createProviderMethod.getAnnotation( CreateDS.class );
-        DirectoryService provDirService = DSAnnotationProcessor.createDS( dsAnnotation );
+        DirectoryService provDirService = DSAnnotationProcessor.getDirectoryService();
 
-        CreateLdapServer serverAnnotation = createProviderMethod.getAnnotation( CreateLdapServer.class
);
-
-        providerServer = ServerAnnotationProcessor.instantiateLdapServer( serverAnnotation,
provDirService );
+        providerServer = ServerAnnotationProcessor.createLdapServer( provDirService );
         
         providerServer.setReplicationReqHandler( new SyncReplRequestHandler() );
+        providerServer.startReplicationProducer();
         
         Runnable r = new Runnable()
         {
@@ -175,7 +171,6 @@ public class ClientInitialRefreshIT
             {
                 try
                 {
-                    providerServer.start();
                     schemaManager = providerServer.getDirectoryService().getSchemaManager();
                     providerSession = providerServer.getDirectoryService().getAdminSession();
                 }

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientServerReplicationIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientServerReplicationIT.java?rev=1153045&r1=1153044&r2=1153045&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientServerReplicationIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/replication/ClientServerReplicationIT.java
Tue Aug  2 06:32:39 2011
@@ -25,7 +25,6 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -46,7 +45,6 @@ import org.apache.directory.server.ldap.
 import org.apache.directory.server.ldap.replication.ReplicationConsumer;
 import org.apache.directory.server.ldap.replication.SyncReplConsumer;
 import org.apache.directory.server.ldap.replication.SyncReplRequestHandler;
-import org.apache.directory.server.ldap.replication.SyncreplConfiguration;
 import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.message.ModifyRequest;
@@ -152,6 +150,8 @@ public class ClientServerReplicationIT
         
         providerSession.add( provUser );
         
+        assertTrue( providerSession.exists( provUser.getDn() ) );
+        
         ModifyRequest modReq = new ModifyRequestImpl();
         modReq.setName( provUser.getDn() );
         modReq.add( "userPassword", "secret" );
@@ -338,17 +338,13 @@ public class ClientServerReplicationIT
              })
     @CreateLdapServer(transports =
         { @CreateTransport( port=16000, protocol = "LDAP") })
-    private static void startProvider() throws Exception
+    public static void startProvider() throws Exception
     {
-        Method createProviderMethod = ClientServerReplicationIT.class.getDeclaredMethod(
"startProvider" );
-        CreateDS dsAnnotation = createProviderMethod.getAnnotation( CreateDS.class );
-        DirectoryService provDirService = DSAnnotationProcessor.createDS( dsAnnotation );
-
-        CreateLdapServer serverAnnotation = createProviderMethod.getAnnotation( CreateLdapServer.class
);
+        DirectoryService provDirService = DSAnnotationProcessor.getDirectoryService();
 
-        providerServer = ServerAnnotationProcessor.instantiateLdapServer( serverAnnotation,
provDirService );
-        
+        providerServer = ServerAnnotationProcessor.createLdapServer( provDirService );
         providerServer.setReplicationReqHandler( new SyncReplRequestHandler() );
+        providerServer.startReplicationProducer();
         
         Runnable r = new Runnable()
         {
@@ -357,7 +353,6 @@ public class ClientServerReplicationIT
             {
                 try
                 {
-                    providerServer.start();
                     schemaManager = providerServer.getDirectoryService().getSchemaManager();
                     providerSession = providerServer.getDirectoryService().getAdminSession();
                 }
@@ -406,29 +401,16 @@ public class ClientServerReplicationIT
         )
     public static void startConsumer() throws Exception
     {
-        Method createProviderMethod = ClientServerReplicationIT.class.getDeclaredMethod(
"startConsumer" );
         DirectoryService provDirService = DSAnnotationProcessor.getDirectoryService();
-
-        CreateLdapServer serverAnnotation = createProviderMethod.getAnnotation( CreateLdapServer.class
);
-
-        consumerServer = ServerAnnotationProcessor.instantiateLdapServer( serverAnnotation,
provDirService );
+        consumerServer = ServerAnnotationProcessor.createLdapServer( provDirService );
         
-        SyncReplConsumer syncreplClient = new SyncReplConsumer();
-        final SyncreplConfiguration config = new SyncreplConfiguration();
-        config.setRemoteHost( "localhost" );
-        config.setRemotePort( 16000 );
-        config.setReplUserDn( "uid=admin,ou=system" );
-        config.setReplUserPassword( "secret".getBytes() );
-        config.setUseTls( false );
-        config.setBaseDn( "dc=example,dc=com" );
-        config.setRefreshInterval( 1000 );
-        
-        syncreplClient.setConfig( config );
+        final SyncReplConsumer consumer = (SyncReplConsumer)ServerAnnotationProcessor.createConsumer();
         
         List<ReplicationConsumer> replConsumers = new ArrayList<ReplicationConsumer>();
-        replConsumers.add( syncreplClient );
+        replConsumers.add( consumer );
         
         consumerServer.setReplConsumers( replConsumers );
+        consumerServer.startReplicationConsumers();
         
         Runnable r = new Runnable()
         {
@@ -436,30 +418,28 @@ public class ClientServerReplicationIT
             {
                 try
                 {
-                    consumerServer.start();
-                    
                     DirectoryService ds = consumerServer.getDirectoryService();
                     
                     Dn configDn = new Dn( ds.getSchemaManager(), "ads-replConsumerId=localhost,ou=system"
);
-                    config.setConfigEntryDn( configDn );
+                    consumer.getConfig().setConfigEntryDn( configDn );
                     
                     Entry provConfigEntry = new DefaultEntry( ds.getSchemaManager(), configDn,
                         "objectClass: ads-replConsumer",
                         "ads-replConsumerId: localhost",
-                        "ads-searchBaseDN", config.getBaseDn(),
-                        "ads-replProvHostName", config.getRemoteHost(),
-                        "ads-replProvPort", String.valueOf( config.getRemotePort() ),
-                        "ads-replRefreshInterval", String.valueOf( config.getRefreshInterval()
),
-                        "ads-replRefreshNPersist", String.valueOf( config.isRefreshNPersist()
),
-                        "ads-replSearchScope", config.getSearchScope().getLdapUrlValue(),
-                        "ads-replSearchFilter", config.getFilter(),
-                        "ads-replSearchSizeLimit", String.valueOf( config.getSearchSizeLimit()
),
-                        "ads-replSearchTimeOut", String.valueOf( config.getSearchTimeout()
),
-                        "ads-replUserDn", config.getReplUserDn(),
-                        "ads-replUserPassword", config.getReplUserPassword() );
+                        "ads-searchBaseDN", consumer.getConfig().getBaseDn(),
+                        "ads-replProvHostName", consumer.getConfig().getRemoteHost(),
+                        "ads-replProvPort", String.valueOf( consumer.getConfig().getRemotePort()
),
+                        "ads-replRefreshInterval", String.valueOf( consumer.getConfig().getRefreshInterval()
),
+                        "ads-replRefreshNPersist", String.valueOf( consumer.getConfig().isRefreshNPersist()
),
+                        "ads-replSearchScope", consumer.getConfig().getSearchScope().getLdapUrlValue(),
+                        "ads-replSearchFilter", consumer.getConfig().getFilter(),
+                        "ads-replSearchSizeLimit", String.valueOf( consumer.getConfig().getSearchSizeLimit()
),
+                        "ads-replSearchTimeOut", String.valueOf( consumer.getConfig().getSearchTimeout()
),
+                        "ads-replUserDn", consumer.getConfig().getReplUserDn(),
+                        "ads-replUserPassword", consumer.getConfig().getReplUserPassword()
);
                     
-                    provConfigEntry.put( "ads-replAliasDerefMode", config.getAliasDerefMode().getJndiValue()
);
-                    provConfigEntry.put( "ads-replAttributes", config.getAttributes() );
+                    provConfigEntry.put( "ads-replAliasDerefMode", consumer.getConfig().getAliasDerefMode().getJndiValue()
);
+                    provConfigEntry.put( "ads-replAttributes", consumer.getConfig().getAttributes()
);
 
                     
                     consumerSession = consumerServer.getDirectoryService().getAdminSession();



Mime
View raw message