Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 53739 invoked from network); 31 Dec 2009 15:30:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 31 Dec 2009 15:30:17 -0000 Received: (qmail 46219 invoked by uid 500); 31 Dec 2009 15:30:17 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 46161 invoked by uid 500); 31 Dec 2009 15:30:17 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 46152 invoked by uid 99); 31 Dec 2009 15:30:17 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 Dec 2009 15:30:17 +0000 X-ASF-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,SUBJECT_FUZZY_TION X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 Dec 2009 15:30:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 052E823889BB; Thu, 31 Dec 2009 15:29:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r894867 - in /directory/apacheds/branches/apacheds-schema: ./ avl-partition/ jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/ jdbm-partition/src/test/java/org/apache/directory/server/core/schema/ ldap-api-test/s... Date: Thu, 31 Dec 2009 15:29:47 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091231152948.052E823889BB@eris.apache.org> Author: akarasulu Date: Thu Dec 31 15:29:47 2009 New Revision: 894867 URL: http://svn.apache.org/viewvc?rev=894867&view=rev Log: /directory/apacheds/trunk:806623-894866 Added: directory/apacheds/branches/apacheds-schema/syncrepl/src/main/java/org/apache/directory/server/syncrepl/EntryInjector.java - copied unchanged from r894866, directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/EntryInjector.java directory/apacheds/branches/apacheds-schema/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java - copied unchanged from r894866, directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java directory/apacheds/branches/apacheds-schema/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java - copied unchanged from r894866, directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java Modified: directory/apacheds/branches/apacheds-schema/ (props changed) directory/apacheds/branches/apacheds-schema/avl-partition/ (props changed) directory/apacheds/branches/apacheds-schema/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/ (props changed) directory/apacheds/branches/apacheds-schema/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java (props changed) directory/apacheds/branches/apacheds-schema/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/ (props changed) directory/apacheds/branches/apacheds-schema/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java (props changed) directory/apacheds/branches/apacheds-schema/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java (props changed) directory/apacheds/branches/apacheds-schema/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java Propchange: directory/apacheds/branches/apacheds-schema/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Dec 31 15:29:47 2009 @@ -1 +1,2 @@ /directory/apacheds/branches/apacheds-replication:749790-764110 +/directory/apacheds/trunk:806623-894866 Propchange: directory/apacheds/branches/apacheds-schema/avl-partition/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Dec 31 15:29:47 2009 @@ -0,0 +1 @@ +/directory/apacheds/trunk/avl-partition:806623-894866 Propchange: directory/apacheds/branches/apacheds-schema/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/ ------------------------------------------------------------------------------ --- svn:mergeinfo (added) +++ svn:mergeinfo Thu Dec 31 15:29:47 2009 @@ -0,0 +1,2 @@ +/directory/apacheds/branches/apacheds-replication/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:749790-764110 +/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:806623-894866* Propchange: directory/apacheds/branches/apacheds-schema/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java ------------------------------------------------------------------------------ --- svn:mergeinfo (added) +++ svn:mergeinfo Thu Dec 31 15:29:47 2009 @@ -0,0 +1,2 @@ +/directory/apacheds/branches/apacheds-replication/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:749790-764110 +/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:806623-894866 Propchange: directory/apacheds/branches/apacheds-schema/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/ ------------------------------------------------------------------------------ --- svn:mergeinfo (added) +++ svn:mergeinfo Thu Dec 31 15:29:47 2009 @@ -0,0 +1,2 @@ +/directory/apacheds/branches/apacheds-replication/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:749790-764110 +/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:806623-894866* Propchange: directory/apacheds/branches/apacheds-schema/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java ------------------------------------------------------------------------------ --- svn:mergeinfo (added) +++ svn:mergeinfo Thu Dec 31 15:29:47 2009 @@ -0,0 +1,2 @@ +/directory/apacheds/branches/apacheds-replication/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:749790-764110 +/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:806623-894866 Propchange: directory/apacheds/branches/apacheds-schema/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Dec 31 15:29:47 2009 @@ -0,0 +1 @@ +/directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java:806623-894866 Modified: directory/apacheds/branches/apacheds-schema/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java?rev=894867&r1=894866&r2=894867&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-schema/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java (original) +++ directory/apacheds/branches/apacheds-schema/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncReplConsumer.java Thu Dec 31 15:29:47 2009 @@ -27,7 +27,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.UUID; import javax.naming.ldap.Control; @@ -36,40 +35,37 @@ import org.apache.directory.server.core.DirectoryService; import org.apache.directory.server.core.entry.DefaultServerEntry; import org.apache.directory.server.core.entry.ServerModification; -import org.apache.directory.server.ldap.replication.SyncreplConfiguration; import org.apache.directory.shared.asn1.codec.DecoderException; import org.apache.directory.shared.ldap.client.api.LdapConnection; -import org.apache.directory.shared.ldap.client.api.LdapConnectionImpl; +import org.apache.directory.shared.ldap.client.api.exception.LdapException; +import org.apache.directory.shared.ldap.client.api.listeners.IntermediateResponseListener; import org.apache.directory.shared.ldap.client.api.listeners.SearchListener; -import org.apache.directory.shared.ldap.client.api.messages.AbstractControl; import org.apache.directory.shared.ldap.client.api.messages.BindResponse; -//import org.apache.directory.shared.ldap.client.api.messages.Control; +import org.apache.directory.shared.ldap.client.api.messages.IntermediateResponse; import org.apache.directory.shared.ldap.client.api.messages.LdapResult; import org.apache.directory.shared.ldap.client.api.messages.SearchRequest; -import org.apache.directory.shared.ldap.client.api.messages.SearchRequestImpl; import org.apache.directory.shared.ldap.client.api.messages.SearchResultDone; import org.apache.directory.shared.ldap.client.api.messages.SearchResultEntry; import org.apache.directory.shared.ldap.client.api.messages.SearchResultReference; -import org.apache.directory.shared.ldap.codec.LdapConstants; import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlCodec; +import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlDecoder; import org.apache.directory.shared.ldap.codec.controls.replication.syncInfoValue.SyncInfoValueControlCodec; import org.apache.directory.shared.ldap.codec.controls.replication.syncInfoValue.SyncInfoValueControlDecoder; import org.apache.directory.shared.ldap.codec.controls.replication.syncStateValue.SyncStateValueControlCodec; +import org.apache.directory.shared.ldap.codec.controls.replication.syncStateValue.SyncStateValueControlDecoder; import org.apache.directory.shared.ldap.constants.SchemaConstants; 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.filter.ExprNode; -import org.apache.directory.shared.ldap.filter.FilterParser; import org.apache.directory.shared.ldap.filter.SearchScope; import org.apache.directory.shared.ldap.message.AliasDerefMode; import org.apache.directory.shared.ldap.message.ResultCodeEnum; import org.apache.directory.shared.ldap.message.control.replication.SyncDoneValueControl; import org.apache.directory.shared.ldap.message.control.replication.SyncRequestValueControl; import org.apache.directory.shared.ldap.message.control.replication.SyncStateTypeEnum; +import org.apache.directory.shared.ldap.message.control.replication.SyncStateValueControl; import org.apache.directory.shared.ldap.message.control.replication.SynchronizationModeEnum; -import org.apache.directory.shared.ldap.name.LdapDN; import org.apache.directory.shared.ldap.util.StringTools; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -84,7 +80,7 @@ * @author Apache Directory Project * @version $Rev$, $Date$ */ -public class SyncreplConsumer implements SearchListener +public class SyncReplConsumer implements SearchListener, IntermediateResponseListener { /** the syncrepl configuration */ @@ -94,7 +90,7 @@ private byte[] syncCookie; /** the logger */ - private static final Logger LOG = LoggerFactory.getLogger( SyncreplConsumer.class ); + private static final Logger LOG = LoggerFactory.getLogger( SyncReplConsumer.class ); /** conection to the syncrepl provider */ private LdapConnection connection; @@ -105,7 +101,7 @@ /** the syncrequest control */ private SyncRequestValueControl syncReq; - /** a reference to the directoryservice */ + /** a reference to the directoryService */ private DirectoryService directoryService; /** the decoder for syncinfovalue control */ @@ -120,6 +116,9 @@ /** the core session */ private CoreSession session; + private SyncDoneValueControlDecoder syncDoneControlDecoder = new SyncDoneValueControlDecoder(); + + private SyncStateValueControlDecoder syncStateControlDecoder = new SyncStateValueControlDecoder(); /** * @return the config */ @@ -148,19 +147,6 @@ } - /** - * A helper method to check that we didn't get an error. - */ - private static void checkldapResult( LdapConnection connection, LdapResult ldapResult ) throws IOException - { - if ( ldapResult.getResultCode() != ResultCodeEnum.SUCCESS ) - { - LOG.debug( "failed to bind on the server : " + ldapResult ); - quit( connection ); - } - } - - public void init( DirectoryService directoryservice ) throws Exception { this.directoryService = directoryservice; @@ -174,43 +160,19 @@ } - public boolean connect() + public boolean bind() { - String providerHost = config.getProviderHost(); - int port = config.getPort(); - - // Create a connection - connection = new LdapConnection( providerHost, port ); - try { - // Connect to the server - boolean connected = connection.connect(); + String providerHost = config.getProviderHost(); + int port = config.getPort(); - if ( !connected ) + // Create a connection + if( connection == null ) { - LOG.error( "Failed to connect to the syncrepl provder host {} running at port {}", providerHost, port ); - return false; + connection = new LdapConnection( providerHost, port ); } - else - { - return connected; - } - } - catch ( Exception e ) - { - LOG.error( "Failed to connect to the syncrepl provder host {} running at port {}", providerHost, port ); - LOG.error( e.getMessage(), e ); - } - - return false; - } - - public boolean bind() - { - try - { // Do a bind BindResponse bindResponse = connection.bind( config.getBindDn(), config.getCredentials() ); @@ -251,7 +213,7 @@ { String baseDn = config.getBaseDn(); - searchRequest = new SearchRequestImpl(); + searchRequest = new SearchRequest(); searchRequest.setBaseDn( baseDn ); searchRequest.setFilter( config.getFilter() ); @@ -292,17 +254,32 @@ Control control = new SyncRequestValueControl(); ((SyncRequestValueControl)control).setCookie( syncReq.getEncodedValue() ); - searchRequest.add( control ); + try + { + searchRequest.add( control ); + } + catch( LdapException e ) + { + // shouldn't happen + LOG.error( "Failed to add constrol to the search request", e ); + } } public void handleSearchDone( SearchResultDone searchDone ) { LOG.debug( "///////////////// handleSearchDone //////////////////" ); - Map controls = searchDone.getControls(); - Control ctrl = controls.get( SyncDoneValueControl.CONTROL_OID ); - SyncDoneValueControlCodec syncDoneCtrl = ( SyncDoneValueControlCodec ) ctrl.getEncodedValue(); + Control ctrl = searchDone.getControl( SyncDoneValueControl.CONTROL_OID ); + SyncDoneValueControlCodec syncDoneCtrl = null; + try + { + syncDoneCtrl = ( SyncDoneValueControlCodec ) syncDoneControlDecoder.decode( ctrl.getEncodedValue() ); + } + catch( Exception e ) + { + LOG.error( "Failed to decode the syncDoneControlCodec", e ); + } if ( syncDoneCtrl.getCookie() != null ) { @@ -359,8 +336,17 @@ { Entry remoteEntry = syncResult.getEntry(); - Control ctrl = syncResult.getCurrentControl(); - SyncStateValueControlCodec syncStateCtrl = ( SyncStateValueControlCodec ) ctrl.getControlValue(); + Control ctrl = syncResult.getControl( SyncStateValueControl.CONTROL_OID ); + SyncStateValueControlCodec syncStateCtrl = null; + + try + { + syncStateCtrl = ( SyncStateValueControlCodec ) syncStateControlDecoder.decode( ctrl.getEncodedValue() ); + } + catch( Exception e ) + { + LOG.error( "Failed to decode syncStateControl", e ); + } if ( syncStateCtrl.getCookie() != null ) { @@ -372,7 +358,9 @@ SyncStateTypeEnum state = syncStateCtrl.getSyncStateType(); LOG.debug( "state name {}", state.name() ); - LOG.debug( "entryUUID = {}", UUID.nameUUIDFromBytes( syncStateCtrl.getEntryUUID() ) ); + + EntryAttribute entryUUID = remoteEntry.get( "entryUUID" ); + LOG.debug( "entryUUID = {}", ( entryUUID == null ? null : entryUUID.getString() ) ); switch ( state ) { @@ -484,10 +472,9 @@ } LOG.debug( "Trying to reconnect" ); - connected = connect(); + connected = bind(); } - bind(); startSync(); } @@ -549,14 +536,55 @@ } + //====================== SearchListener methods ==================================== + + + /* (non-Javadoc) + * @see org.apache.directory.shared.ldap.client.api.listeners.SearchListener#entryFound(org.apache.directory.shared.ldap.client.api.LdapConnection, org.apache.directory.shared.ldap.client.api.messages.SearchResultEntry) + */ + public void entryFound( LdapConnection connection, SearchResultEntry searchResultEntry ) throws LdapException + { + handleSearchResult( searchResultEntry ); + } + + + /* (non-Javadoc) + * @see org.apache.directory.shared.ldap.client.api.listeners.SearchListener#referralFound(org.apache.directory.shared.ldap.client.api.LdapConnection, org.apache.directory.shared.ldap.client.api.messages.SearchResultReference) + */ + public void referralFound( LdapConnection connection, SearchResultReference searchResultReference ) + throws LdapException + { + handleSearchReference( searchResultReference ); + } + + + /* (non-Javadoc) + * @see org.apache.directory.shared.ldap.client.api.listeners.SearchListener#searchDone(org.apache.directory.shared.ldap.client.api.LdapConnection, org.apache.directory.shared.ldap.client.api.messages.SearchResultDone) + */ + public void searchDone( LdapConnection connection, SearchResultDone searchResultDone ) throws LdapException + { + handleSearchDone( searchResultDone ); + } + + + /* (non-Javadoc) + * @see org.apache.directory.shared.ldap.client.api.listeners.IntermediateResponseListener#responseReceived(org.apache.directory.shared.ldap.client.api.LdapConnection, org.apache.directory.shared.ldap.client.api.messages.IntermediateResponse) + */ + public void responseReceived( LdapConnection connection, IntermediateResponse intermediateResponse ) + { + handleSyncInfo( intermediateResponse.getResponseValue() ); + } + + /** - * - * performs a search on connection with updated syncrequest control. + * performs a search on connection with updated syncRequest control. * * @throws Exception in case of any problems encountered while searching */ private void doSyncSearch() throws Exception { + SyncRequestValueControl syncReq = new SyncRequestValueControl(); + if( config.isRefreshPersist() ) { syncReq.setMode( SynchronizationModeEnum.REFRESH_AND_PERSIST ); @@ -567,9 +595,14 @@ syncReq.setCookie( syncCookie ); } - searchRequest.getCurrentControl().setControlValue( syncReq.getEncodedValue() ); + SyncRequestValueControl syncReqControl = ( SyncRequestValueControl ) searchRequest.getControl( SyncRequestValueControl.CONTROL_OID ); + + searchRequest.remove( syncReqControl ); - connection.search( searchRequest ); + searchRequest.add( syncReq ); + + // Do the search + connection.search( searchRequest, this ); } @@ -585,6 +618,7 @@ connection.close(); LOG.info( "Connection closed for the server {}", config.getProviderHost() ); + connection = null; // persist the cookie storeCookie(); } @@ -629,12 +663,13 @@ { try { - if( cookieFile.exists() && cookieFile.length() > 0 ) + if( cookieFile.exists() && ( cookieFile.length() > 0 ) ) { FileInputStream fin = new FileInputStream( cookieFile ); syncCookie = new byte[ fin.read() ]; fin.read( syncCookie ); fin.close(); + LOG.debug( "read the cookie from file: " + StringTools.utf8ToString( syncCookie ) ); } }