From 3c40ef909b40639c8e5219234285b906f19a8af2 Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Mon, 31 May 2010 13:06:56 +0000
Subject: [PATCH] Add support for displaying replication CSNs in the Access Logs. The default is disabled, but the log of replication CSNs can be activated by setting the log-changenumber property in the Replication domain configuration.

---
 opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java                 |   11 +++++
 opendj-sdk/opends/src/server/org/opends/server/types/AbstractOperation.java                                  |    5 +-
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/OperationTestCase.java           |   15 -------
 opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationDomainConfiguration.xml              |   22 +++++++++++
 opendj-sdk/opends/src/admin/messages/ReplicationDomainCfgDefn.properties                                     |    2 +
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/DomainFakeCfg.java |   24 +++++++----
 opendj-sdk/opends/resource/schema/02-config.ldif                                                             |    6 +++
 7 files changed, 60 insertions(+), 25 deletions(-)

diff --git a/opendj-sdk/opends/resource/schema/02-config.ldif b/opendj-sdk/opends/resource/schema/02-config.ldif
index e2b0d79..2259683 100644
--- a/opendj-sdk/opends/resource/schema/02-config.ldif
+++ b/opendj-sdk/opends/resource/schema/02-config.ldif
@@ -2458,6 +2458,11 @@
   SYNTAX 1.3.6.1.4.1.1466.115.121.1.27
   SINGLE-VALUE
   X-ORIGIN 'OpenDS Directory Server' )
+attributeTypes: ( 1.3.6.1.4.1.26027.1.1.608
+  NAME 'ds-cfg-log-changenumber'
+  SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
+  SINGLE-VALUE
+  X-ORIGIN 'OpenDS Directory Server' )
 objectClasses: ( 1.3.6.1.4.1.26027.1.2.1
   NAME 'ds-cfg-access-control-handler'
   SUP top
@@ -3022,6 +3027,7 @@
         ds-cfg-fractional-include $
         ds-cfg-solve-conflicts $
         ds-cfg-changetime-heartbeat-interval $
+        ds-cfg-log-changenumber $
         ds-cfg-initialization-window-size )
   X-ORIGIN 'OpenDS Directory Server' )
 objectClasses: ( 1.3.6.1.4.1.26027.1.2.58
diff --git a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationDomainConfiguration.xml b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationDomainConfiguration.xml
index 32046e8..1bc7968 100644
--- a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationDomainConfiguration.xml
+++ b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationDomainConfiguration.xml
@@ -495,6 +495,28 @@
       </ldap:attribute>
     </adm:profile>
   </adm:property>
+    <adm:property name="log-changenumber" advanced="false">
+    <adm:synopsis>
+      Indicates if this server logs the ChangeNumber in access log.
+    </adm:synopsis>
+    <adm:description>
+      This boolean indicates if the domain should log the ChangeNumber 
+      of replicated operations in the access log.
+    </adm:description>
+    <adm:default-behavior>
+      <adm:defined>
+        <adm:value>false</adm:value>
+      </adm:defined>
+    </adm:default-behavior>
+    <adm:syntax>
+      <adm:boolean />
+    </adm:syntax>
+    <adm:profile name="ldap">
+      <ldap:attribute>
+        <ldap:name>ds-cfg-log-changenumber</ldap:name>
+      </ldap:attribute>
+    </adm:profile>
+  </adm:property>
   <adm:property name="initialization-window-size">
     <adm:synopsis>
       Specifies the window size that this Directory Server may use when
diff --git a/opendj-sdk/opends/src/admin/messages/ReplicationDomainCfgDefn.properties b/opendj-sdk/opends/src/admin/messages/ReplicationDomainCfgDefn.properties
index e7c93bf..26959a8 100644
--- a/opendj-sdk/opends/src/admin/messages/ReplicationDomainCfgDefn.properties
+++ b/opendj-sdk/opends/src/admin/messages/ReplicationDomainCfgDefn.properties
@@ -27,6 +27,8 @@
 property.isolation-policy.synopsis=Specifies the behavior of the Directory Server if a write operation is attempted on the data within the Replication Domain when none of the configured Replication Servers are available.
 property.isolation-policy.syntax.enumeration.value.accept-all-updates.synopsis=Indicates that updates should be accepted even though it is not possible to send them to any Replication Server. Best effort is made to re-send those updates to a Replication Servers when one of them is available, however those changes are at risk because they are only available from the historical information. This mode can also introduce high replication latency.
 property.isolation-policy.syntax.enumeration.value.reject-all-updates.synopsis=Indicates that all updates attempted on this Replication Domain are rejected when no Replication Server is available.
+property.log-changenumber.synopsis=Indicates if this server logs the ChangeNumber in access log.
+property.log-changenumber.description=This boolean indicates if the domain should log the ChangeNumber of replicated operations in the access log.
 property.referrals-url.synopsis=The URLs other LDAP servers should use to refer to the local server.
 property.referrals-url.description=URLs used by peer servers in the topology to refer to the local server through LDAP referrals. If this attribute is not defined, every URLs available to access this server will be used. If defined, only URLs specified here will be used.
 property.referrals-url.syntax.string.pattern.synopsis=A LDAP URL compliant with RFC 2255.
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
index 9af9669..04094a0 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
@@ -405,6 +405,9 @@
   // The operation should become a no-op
   private static final int FRACTIONAL_BECOME_NO_OP = 3;
 
+  // This configuration boolean indicates if this ReplicationDomain should log
+  // ChangeNumbers.
+  private boolean logChangeNumber = false;
 
   /**
    * The thread that periodically saves the ServerState of this
@@ -551,6 +554,7 @@
     heartbeatInterval = configuration.getHeartbeatInterval();
     isolationpolicy = configuration.getIsolationPolicy();
     configDn = configuration.dn();
+    logChangeNumber = configuration.isLogChangenumber();
     this.updateToReplayQueue = updateToReplayQueue;
 
     // Get assured configuration
@@ -2297,6 +2301,12 @@
     // Note that a failed non-replication operation might not have a change
     // number.
     ChangeNumber curChangeNumber = OperationContext.getChangeNumber(op);
+    if ((curChangeNumber != null) && (logChangeNumber))
+    {
+      Message message =
+        Message.raw("replicationCN:%s", curChangeNumber.toString());
+      op.appendAdditionalLogMessage(message);
+    }
 
     if ((result == ResultCode.SUCCESS) && (!op.isSynchronizationOperation()))
     {
@@ -4234,6 +4244,7 @@
          ReplicationDomainCfg configuration)
   {
     isolationpolicy = configuration.getIsolationPolicy();
+    logChangeNumber = configuration.isLogChangenumber();
 
     changeConfig(
         configuration.getReplicationServer(),
diff --git a/opendj-sdk/opends/src/server/org/opends/server/types/AbstractOperation.java b/opendj-sdk/opends/src/server/org/opends/server/types/AbstractOperation.java
index db10ccb..aa8446f 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/types/AbstractOperation.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/types/AbstractOperation.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2009 Sun Microsystems, Inc.
+ *      Copyright 2006-2010 Sun Microsystems, Inc.
  */
 package org.opends.server.types;
 import org.opends.messages.Message;
@@ -206,7 +206,7 @@
     }
 
     resultCode                 = ResultCode.UNDEFINED;
-    additionalLogMessage       = new MessageBuilder();
+    additionalLogMessage       = null;
     errorMessage               = new MessageBuilder();
     attachments                = new HashMap<String,Object>();
     matchedDN                  = null;
@@ -619,6 +619,7 @@
     }
     else
     {
+      additionalLogMessage.append(" ");
       additionalLogMessage.append(message);
     }
   }
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/OperationTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/OperationTestCase.java
index a711a14..2f6a6ee 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/OperationTestCase.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/OperationTestCase.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Copyright 2006-2010 Sun Microsystems, Inc.
  */
 package org.opends.server.core;
 
@@ -306,19 +306,6 @@
 
 
 
-  /**
-   * Tests the <CODE>getAdditionalLogMessage</CODE> method for the provided
-   * operation.
-   *
-   * @param  operation  The operation to test.
-   */
-  @Test(dataProvider = "testOperations")
-  public void testGetAdditionalLogMessage(Operation operation)
-  {
-    assertNotNull(operation.getAdditionalLogMessage());
-  }
-
-
 
   /**
    * Tests the <CODE>getMatchedDN</CODE> method for the provided operation.
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/DomainFakeCfg.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/DomainFakeCfg.java
index 92721ea..9b4fd91 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/DomainFakeCfg.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/DomainFakeCfg.java
@@ -79,9 +79,9 @@
   private SortedSet<String> fractionalIncludes = new TreeSet<String>();
 
   private SortedSet<String> eclIncludes = new TreeSet<String>();
-  private ExternalChangelogDomainCfg eclCfg = 
+  private ExternalChangelogDomainCfg eclCfg =
     new ExternalChangelogDomainFakeCfg(true, new TreeSet<AttributeType>());
-  
+
   /**
    * Creates a new Domain with the provided information
    * (assured mode disabled, default group id)
@@ -379,12 +379,12 @@
   {
     return true;
   }
-  
+
   public void setEclIncludes(SortedSet<String> attrs)
   {
     this.eclIncludes = attrs;
   }
- 
+
   public SortedSet<String> getECLInclude()
   {
     return this.eclIncludes;
@@ -394,7 +394,7 @@
   {
     return 180;
   }
-  
+
 
   public int getInitializationWindowSize()
   {
@@ -414,7 +414,7 @@
    *           be successfully decoded.
    */
   public ExternalChangelogDomainCfg getExternalChangelogDomain()
-  throws ConfigException 
+  throws ConfigException
   { return eclCfg; }
 
 
@@ -427,7 +427,7 @@
    *           be successfully decoded.
    */
   public void  setExternalChangelogDomain(ExternalChangelogDomainCfg eclCfg)
-  throws ConfigException 
+  throws ConfigException
   { this.eclCfg=eclCfg;}
 
 
@@ -469,7 +469,7 @@
    * @throws ConfigException
    *          If the delete listener could not be registered.
    */
-  public void 
+  public void
   addECLDomainDeleteListener(
       ConfigurationDeleteListener<ExternalChangelogDomainCfg> listener)
   throws ConfigException
@@ -483,8 +483,14 @@
    * @param listener
    *          The ECL Domain configuration delete listener.
    */
-  public void 
+  public void
   removeECLDomainDeleteListener(
       ConfigurationDeleteListener<ExternalChangelogDomainCfg> listener)
   {}
+
+  @Override
+  public boolean isLogChangenumber()
+  {
+    return true;
+  }
 }

--
Gitblit v1.10.0