directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r943298 - in /directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl: SyncReplConsumer.java SyncreplConfiguration.java
Date Tue, 11 May 2010 21:24:13 GMT
Author: kayyagari
Date: Tue May 11 21:24:13 2010
New Revision: 943298

URL: http://svn.apache.org/viewvc?rev=943298&view=rev
Log:
o refactored the configuration parameter names and methods
o added support for ApacheDS specific MODDN operation control

Modified:
    directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java
    directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java

Modified: directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java?rev=943298&r1=943297&r2=943298&view=diff
==============================================================================
--- directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java
(original)
+++ directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java
Tue May 11 21:24:13 2010
@@ -51,13 +51,15 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.controls.replication.syncRequestValue.SyncRequestValueControl;
 import org.apache.directory.shared.ldap.codec.controls.replication.syncStateValue.SyncStateValueControl;
 import org.apache.directory.shared.ldap.codec.controls.replication.syncStateValue.SyncStateValueControlDecoder;
+import org.apache.directory.shared.ldap.codec.controls.replication.syncmodifydn.SyncModifyDnControl;
+import org.apache.directory.shared.ldap.codec.controls.replication.syncmodifydn.SyncModifyDnControlDecoder;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
-import org.apache.directory.shared.ldap.entry.DefaultServerEntry;
+import org.apache.directory.shared.ldap.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.entry.DefaultModification;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
-import org.apache.directory.shared.ldap.entry.ServerModification;
 import org.apache.directory.shared.ldap.filter.EqualityNode;
 import org.apache.directory.shared.ldap.filter.ExprNode;
 import org.apache.directory.shared.ldap.filter.OrNode;
@@ -65,9 +67,11 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.message.control.replication.SyncModifyDnType;
 import org.apache.directory.shared.ldap.message.control.replication.SyncStateTypeEnum;
 import org.apache.directory.shared.ldap.message.control.replication.SynchronizationModeEnum;
 import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.name.RDN;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
@@ -122,10 +126,12 @@ public class SyncReplConsumer
     private SyncDoneValueControlDecoder syncDoneControlDecoder = new SyncDoneValueControlDecoder();
 
     private SyncStateValueControlDecoder syncStateControlDecoder = new SyncStateValueControlDecoder();
+    
+    private SyncModifyDnControlDecoder syncModifyDnControlDecoder = new SyncModifyDnControlDecoder();
 
     /** attributes on which modification should be ignored */
     private static final String[] MOD_IGNORE_AT = new String[]
-        { SchemaConstants.ENTRY_UUID_AT, SchemaConstants.ENTRY_CSN_AT }; //{ "1.3.6.1.1.16.4",
"1.3.6.1.4.1.4203.666.1.7" };
+        { SchemaConstants.ENTRY_UUID_AT, SchemaConstants.ENTRY_CSN_AT, SchemaConstants.MODIFIERS_NAME_AT,
SchemaConstants.MODIFY_TIMESTAMP_AT, SchemaConstants.CREATE_TIMESTAMP_AT, SchemaConstants.CREATORS_NAME_AT
};
 
     /** flag to indicate whether the current phase is for deleting entries */
     private boolean refreshDeletes;
@@ -183,7 +189,7 @@ public class SyncReplConsumer
             }
 
             // Do a bind
-            BindResponse bindResponse = connection.bind( config.getBindDn(), config.getCredentials()
);
+            BindResponse bindResponse = connection.bind( config.getReplUserDn(), config.getReplUserPassword()
);
 
             // Check that it' not null and valid
             if ( bindResponse == null )
@@ -231,7 +237,7 @@ public class SyncReplConsumer
 
         // the only valid values are NEVER_DEREF_ALIASES and DEREF_FINDING_BASE_OBJ
         searchRequest.setDerefAliases( AliasDerefMode.NEVER_DEREF_ALIASES );
-        searchRequest.setScope( SearchScope.getSearchScope( config.getSearchScope() ) );
+        searchRequest.setScope( config.getSearchScope() );
         searchRequest.setTypesOnly( false );
 
         searchRequest.addAttributes( config.getAttributes() );
@@ -292,7 +298,7 @@ public class SyncReplConsumer
 
     public void handleSearchReference( SearchResultReference searchRef )
     {
-        // this method won't be called cause the provider will server the referrals as
+        // this method won't be called cause the provider will serve the referrals as
         // normal entry objects due to the usage of ManageDsaITControl in the search request
     }
 
@@ -311,8 +317,7 @@ public class SyncReplConsumer
 
             try
             {
-                syncStateCtrl = ( SyncStateValueControl ) syncStateControlDecoder.decode(
ctrl.getValue(),
-                    syncStateCtrl );
+                syncStateCtrl = ( SyncStateValueControl ) syncStateControlDecoder.decode(
ctrl.getValue(), syncStateCtrl );
             }
             catch ( Exception e )
             {
@@ -343,7 +348,7 @@ public class SyncReplConsumer
                     {
                         LOG.debug( "adding entry with dn {}", remoteEntry.getDn().getName()
);
                         LOG.debug( remoteEntry.toString() );
-                        session.add( new DefaultServerEntry( schemaManager, remoteEntry )
);
+                        session.add( new DefaultEntry( schemaManager, remoteEntry ) );
                     }
                     // in refreshOnly mode the modified entry will be sent with state ADD
                     else if ( !config.isRefreshPersist() )
@@ -358,6 +363,25 @@ public class SyncReplConsumer
                     LOG.debug( "modifying entry with dn {}", remoteEntry.getDn().getName()
);
                     modify( remoteEntry );
                     break;
+                    
+                case MODDN:
+                    Control adsModDnControl = syncResult.getControl( SyncModifyDnControl.CONTROL_OID
);
+                    //Apache Directory Server's special control
+                    SyncModifyDnControl syncModDnControl = new SyncModifyDnControl();
+                    
+                    try
+                    {
+                        LOG.debug( "decoding the SyncModifyDnControl.." );
+                        syncModDnControl = ( SyncModifyDnControl ) syncModifyDnControlDecoder.decode(
adsModDnControl.getValue(), syncModDnControl );
+                    }
+                    catch( Exception e )
+                    {
+                        syncModDnControl = null;
+                        LOG.error( "Failed to decode the SyncModifyDnControl", e );
+                    }
+                    
+                    applyModDnOperation( syncModDnControl );
+                    break;
 
                 case DELETE:
                     LOG.debug( "deleting entry with dn {}", remoteEntry.getDn().getName()
);
@@ -381,12 +405,13 @@ public class SyncReplConsumer
     /**
      * {@inheritDoc}
      */
-    public void handleSyncInfo( byte[] syncinfo )
+    public void handleSyncInfo( SearchIntermediateResponse syncInfoResp )
     {
         try
         {
             LOG.debug( "............... inside handleSyncInfo ..............." );
 
+            byte[] syncinfo = syncInfoResp.getResponseValue();
             SyncInfoValueControl syncInfoValue = ( SyncInfoValueControl ) decoder.decode(
syncinfo, null );
 
             byte[] cookie = syncInfoValue.getCookie();
@@ -438,7 +463,7 @@ public class SyncReplConsumer
         {
             try
             {
-                Thread.sleep( config.getConsumerInterval() );
+                Thread.sleep( config.getRefreshInterval() );
             }
             catch ( InterruptedException e )
             {
@@ -516,7 +541,7 @@ public class SyncReplConsumer
             }
             else if ( resp instanceof SearchIntermediateResponse )
             {
-                handleSyncInfo( ( ( SearchIntermediateResponse ) resp ).getResponseValue()
);
+                handleSyncInfo( ( SearchIntermediateResponse ) resp );
             }
             
             resp = sf.get();
@@ -639,7 +664,44 @@ public class SyncReplConsumer
         }
     }
 
+    
+    private void applyModDnOperation( SyncModifyDnControl modDnControl ) throws Exception
+    {
+        SyncModifyDnType modDnType = modDnControl.getModDnType();
+        
+        DN entryDn = new DN( modDnControl.getEntryDn() );
+        switch( modDnType )
+        {
+            case MOVE:
+                LOG.debug( "moving {} to the new parent {}", entryDn, modDnControl.getNewSuperiorDn()
);
+                
+                session.move( entryDn, new DN( modDnControl.getNewSuperiorDn() ) );
+                break;
+            
+            case RENAME:
+                
+                RDN newRdn = new RDN( modDnControl.getNewRdn() );
+                boolean deleteOldRdn =  modDnControl.isDeleteOldRdn();
+                LOG.debug( "renaming the DN {} with new RDN {} and deleteOldRdn flag set
to {}", 
+                    new String[]{ entryDn.getName(), newRdn.getName(), String.valueOf( deleteOldRdn
) } );
+                
+                session.rename( entryDn, newRdn, deleteOldRdn );
+                break;
+            
+            case MOVEANDRENAME:
+                
+                DN newParentDn = new DN( modDnControl.getNewSuperiorDn() );
+                newRdn = new RDN( modDnControl.getNewRdn() );
+                deleteOldRdn =  modDnControl.isDeleteOldRdn();
+                
+                LOG.debug( "moveAndRename on the DN {} with new newParent DN {}, new RDN
{} and deleteOldRdn flag set to {}", 
+                    new String[]{ entryDn.getName(), newParentDn.getName(), newRdn.getName(),
String.valueOf( deleteOldRdn ) } );
+                
+                session.moveAndRename( entryDn, newParentDn, newRdn, deleteOldRdn );
+        }
+    }
 
+    
     private void modify( Entry remoteEntry ) throws Exception
     {
         Entry localEntry = session.lookup( remoteEntry.getDn() );
@@ -658,12 +720,12 @@ public class SyncReplConsumer
 
             if ( remoteAttr != null ) // would be better if we compare the values also? or
will it consume more time?
             {
-                mod = new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE, remoteAttr
);
+                mod = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, remoteAttr
);
                 remoteEntry.remove( remoteAttr );
             }
             else
             {
-                mod = new ServerModification( ModificationOperation.REMOVE_ATTRIBUTE, localAttr
);
+                mod = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, localAttr
);
             }
 
             mods.add( mod );
@@ -674,7 +736,7 @@ public class SyncReplConsumer
             itr = remoteEntry.iterator();
             while ( itr.hasNext() )
             {
-                mods.add( new ServerModification( ModificationOperation.ADD_ATTRIBUTE, itr.next()
) );
+                mods.add( new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, itr.next()
) );
             }
         }
 
@@ -792,7 +854,7 @@ public class SyncReplConsumer
                     doSyncSearch( SynchronizationModeEnum.REFRESH_ONLY );
 
                     LOG.info( "--------------------- Sleep for a little while ------------------"
);
-                    Thread.sleep( config.getConsumerInterval() );
+                    Thread.sleep( config.getRefreshInterval() );
                     LOG.debug( "--------------------- syncing again ------------------" );
 
                 }

Modified: directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java?rev=943298&r1=943297&r2=943298&view=diff
==============================================================================
--- directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java
(original)
+++ directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java
Tue May 11 21:24:13 2010
@@ -19,10 +19,13 @@
  */
 package org.apache.directory.server.syncrepl;
 
+
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.filter.SearchScope;
+import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.util.StringTools;
 
+
 /**
  * 
  * A class for holding the syncrepl consumer's configuration.
@@ -35,36 +38,34 @@ import org.apache.directory.shared.ldap.
  */
 public class SyncreplConfiguration
 {
-    /** host name of the syncrepl provider server */
-    private String providerHost;
+    /** host name of the syncrepl provider server, default value is localhost */
+    private String providerHost = "localhost";
 
-    /** port number of the syncrepl provider server */
-    private int port;
+    /** port number of the syncrepl provider server, default is 389 */
+    private int port = 389;
 
-    /** bind dn */
-    private String bindDn;
+    /** replication user's DN */
+    private String replUserDn;
 
-    /** password for binding with bind dn */
-    private String credentials;
+    /** password for binding with replication user dn */
+    private byte[] replUserPassword;
 
-    /** flag to represent refresh and persist or refreh only mode */
+    /** flag to represent refresh and persist or refresh only mode, defaults to true */
     private boolean refreshPersist = true;
 
-    /** time interval for successive sync requests */
-    private long consumerInterval = 5 * 1000;
+    /** time interval for successive sync requests, default is 5 seconds */
+    private long refreshInterval = 5 * 1000;
 
-    /** the base DN whose content will be searched for syncing */
+    /** the base DN whose content will be searched for replicating */
     private String baseDn;
 
-    /** the ldap filter for fetching the entries */
-    private String filter;
+    /** the ldap filter for fetching the entries, default value is (objectClass=*) */
+    private String filter = "(objectClass=*)";
 
-    /** a comma separated string of attribute names */
-    private String attributesString;
+    /** names of attributes to be replicated, default value is all user attributes */
+    private String[] attributes = new String[]{ SchemaConstants.ALL_USER_ATTRIBUTES };
 
-    private String[] attrs;
-    
-    /** the numer for setting the limit on numer of search results to be fteched
+    /** the numer for setting the limit on number of search results to be fetched
      * default value is 0 (i.e no limit) */
     private int searchSizeLimit = 0;
 
@@ -72,12 +73,19 @@ public class SyncreplConfiguration
      * default value is 0 (i.e no limit)*/
     private int searchTimeout = 0;
 
-    /** the search scope */
-    private int searchScope = SearchScope.ONELEVEL.getScope();
+    /** the search scope, default is sub tree level */
+    private SearchScope searchScope = SearchScope.SUBTREE;
+    
+    /** alias dereferencing mode, default is set to 'never deref aliases' */
+    private AliasDerefMode aliasDerefMode = AliasDerefMode.NEVER_DEREF_ALIASES;
 
+    /** the cookie received from server */
+    private byte[] cookie;
+    
     /** the replica's id */
     private int replicaId;
-    
+
+
     /**
      * @return the providerHost
      */
@@ -86,6 +94,7 @@ public class SyncreplConfiguration
         return providerHost;
     }
 
+
     /**
      * @param providerHost the providerHost to set
      */
@@ -94,6 +103,7 @@ public class SyncreplConfiguration
         this.providerHost = providerHost;
     }
 
+
     /**
      * @return the port
      */
@@ -102,6 +112,7 @@ public class SyncreplConfiguration
         return port;
     }
 
+
     /**
      * @param port the port to set
      */
@@ -110,38 +121,52 @@ public class SyncreplConfiguration
         this.port = port;
     }
 
+
     /**
-     * @return the bindDn
+     * @return the replication user's DN
      */
-    public String getBindDn()
+    public String getReplUserDn()
     {
-        return bindDn;
+        return replUserDn;
     }
 
+
     /**
-     * @param bindDn the bindDn to set
+     * @param replUserdDn the DN of the replication user
      */
-    public void setBindDn( String bindDn )
+    public void setReplUserDn( String replUserdDn )
     {
-        this.bindDn = bindDn;
+        this.replUserDn = replUserdDn;
     }
 
+
     /**
-     * @return the credentials
+     * @return the replication user's password
      */
-    public String getCredentials()
+    public String getReplUserPassword()
     {
-        return credentials;
+        return StringTools.utf8ToString( replUserPassword );
     }
 
+
     /**
-     * @param credentials the credentials to set
+     * @param replUserPassword the replication user's password
      */
-    public void setCredentials( String credentials )
+    public void setReplUserPassword( String replUserPassword )
     {
-        this.credentials = credentials;
+        setReplUserPassword( replUserPassword.getBytes() );
     }
 
+
+    /**
+     * @param replUserPassword the replication user's password
+     */
+    public void setReplUserPassword( byte[] replUserPassword )
+    {
+        this.replUserPassword = replUserPassword;
+    }
+
+    
     /**
      * @return the refreshPersist
      */
@@ -150,6 +175,7 @@ public class SyncreplConfiguration
         return refreshPersist;
     }
 
+
     /**
      * @param refreshPersist the refreshPersist to set
      */
@@ -158,22 +184,25 @@ public class SyncreplConfiguration
         this.refreshPersist = refreshPersist;
     }
 
+
     /**
-     * @return the consumerInterval
+     * @return the refresh interval
      */
-    public long getConsumerInterval()
+    public long getRefreshInterval()
     {
-        return consumerInterval;
+        return refreshInterval;
     }
 
+
     /**
-     * @param consumerInterval the consumerInterval to set
+     * @param refreshInterval the consumerInterval to set
      */
-    public void setConsumerInterval( long consumerInterval )
+    public void setRefreshInterval( long refreshInterval )
     {
-        this.consumerInterval = consumerInterval;
+        this.refreshInterval = refreshInterval;
     }
 
+
     /**
      * @return the baseDn
      */
@@ -182,6 +211,7 @@ public class SyncreplConfiguration
         return baseDn;
     }
 
+
     /**
      * @param baseDn the baseDn to set
      */
@@ -190,6 +220,7 @@ public class SyncreplConfiguration
         this.baseDn = baseDn;
     }
 
+
     /**
      * @return the filter
      */
@@ -198,6 +229,7 @@ public class SyncreplConfiguration
         return filter;
     }
 
+
     /**
      * @param filter the filter to set
      */
@@ -206,32 +238,25 @@ public class SyncreplConfiguration
         this.filter = filter;
     }
 
+
     /**
      * @return the attributes
      */
     public String[] getAttributes()
     {
-        if( attrs == null )
-        {
-            if ( StringTools.isEmpty( attributesString ) )
-            {
-                attributesString = SchemaConstants.ALL_USER_ATTRIBUTES;
-            }
-
-            attrs = attributesString.trim().split( "," );
-        }
-
-        return attrs;
+        return attributes;
     }
 
+
     /**
      * @param attributes the attributes to set
      */
-    public void setAttributes( String attributes )
+    public void setAttributes( String[] attributes )
     {
-        this.attributesString = attributes;
+        this.attributes = attributes;
     }
 
+
     /**
      * @return the searchSizeLimit
      */
@@ -240,6 +265,7 @@ public class SyncreplConfiguration
         return searchSizeLimit;
     }
 
+
     /**
      * @param searchSizeLimit the searchSizeLimit to set
      */
@@ -248,6 +274,7 @@ public class SyncreplConfiguration
         this.searchSizeLimit = searchSizeLimit;
     }
 
+
     /**
      * @return the searchTimeout
      */
@@ -256,6 +283,7 @@ public class SyncreplConfiguration
         return searchTimeout;
     }
 
+
     /**
      * @param searchTimeout the searchTimeout to set
      */
@@ -264,22 +292,25 @@ public class SyncreplConfiguration
         this.searchTimeout = searchTimeout;
     }
 
+
     /**
      * @return the searchScope
      */
-    public int getSearchScope()
+    public SearchScope getSearchScope()
     {
         return searchScope;
     }
 
+
     /**
      * @param searchScope the searchScope to set
      */
-    public void setSearchScope( int searchScope )
+    public void setSearchScope( SearchScope searchScope )
     {
         this.searchScope = searchScope;
     }
 
+
     /**
      * @return the replicaId
      */
@@ -288,6 +319,7 @@ public class SyncreplConfiguration
         return replicaId;
     }
 
+
     /**
      * @param replicaId the replicaId to set
      */
@@ -296,6 +328,33 @@ public class SyncreplConfiguration
         this.replicaId = replicaId;
     }
 
-    
+
+    public AliasDerefMode getAliasDerefMode()
+    {
+        return aliasDerefMode;
+    }
+
+
+    public void setAliasDerefMode( AliasDerefMode aliasDerefMode )
+    {
+        if( aliasDerefMode != AliasDerefMode.NEVER_DEREF_ALIASES || aliasDerefMode != AliasDerefMode.DEREF_FINDING_BASE_OBJ
)
+        {
+            throw new IllegalArgumentException( "alias deref mode should only be set to either
'NEVER_DEREF_ALIASES' or 'DEREF_FINDING_BASE_OBJ'" );
+        }
+        
+        this.aliasDerefMode = aliasDerefMode;
+    }
+
+
+    public byte[] getCookie()
+    {
+        return cookie;
+    }
+
+
+    public void setCookie( byte[] cookie )
+    {
+        this.cookie = cookie;
+    }
     
 }



Mime
View raw message