From 3abf557a605041e265d0e2a18b729b65c2bd2690 Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Thu, 27 May 2010 14:37:37 +0000
Subject: [PATCH] Fix issue #4537, naming changelog entries with changeNumber instead of cn. Improve ECL and tests as well

---
 opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java                  |   38 ++++++++----
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java |   28 ++++----
 opendj-sdk/opends/src/server/org/opends/server/replication/plugin/ExternalChangelogDomain.java                |    6 +-
 opendj-sdk/opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java      |    9 +-
 opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java                     |   41 +++++++++++++
 5 files changed, 86 insertions(+), 36 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/ExternalChangelogDomain.java b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/ExternalChangelogDomain.java
index e50a690..b8a0d94 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/ExternalChangelogDomain.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/ExternalChangelogDomain.java
@@ -66,8 +66,8 @@
     if (configuration.getECLInclude() != null)
     {
       HashSet<String> attrNames = new HashSet<String>(0);
-      for (AttributeType eclInclude : configuration.getECLInclude())
-        attrNames.add(eclInclude.getNormalizedPrimaryName());
+      for (AttributeType eclIncludeAttribute : configuration.getECLInclude())
+        attrNames.add(eclIncludeAttribute.getNormalizedPrimaryName());
       domain.setEclInclude(domain.getServerId(), attrNames);
     }
   }
@@ -129,7 +129,7 @@
       HashSet<String> attrNames = new HashSet<String>(0);
       for (AttributeType eclInclude : configuration.getECLInclude())
         attrNames.add(eclInclude.getNormalizedPrimaryName());
-      domain.setEclInclude(domain.getServerId(), attrNames);
+      domain.changeConfig(attrNames);
       return new ConfigChangeResult(ResultCode.SUCCESS, false);
     }
     catch (Exception e)
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 c0d20e4..f597000 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
@@ -563,7 +563,7 @@
     setGroupId((byte)configuration.getGroupId());
     setURLs(configuration.getReferralsUrl());
 
-    createECLDomainCfg(configuration);
+    storeECLConfiguration(configuration);
 
     /*
      * Modify conflicts are solved for all suffixes but the schema suffix
@@ -4235,7 +4235,7 @@
 
     try
     {
-      createECLDomainCfg(configuration);
+      storeECLConfiguration(configuration);
     }
     catch(Exception e)
     {
@@ -4341,29 +4341,34 @@
   }
 
   /**
-   * Create the ECl configuration.
-   * @param  configuration The provided configuration.
-   * @throws ConfigException a.
+   * Store the provided ECL configuration for the domain.
+   * @param  domCfg       The provided configuration.
+   * @throws ConfigException When an error occured.
    */
-  public void createECLDomainCfg(ReplicationDomainCfg configuration)
+  public void storeECLConfiguration(ReplicationDomainCfg domCfg)
   throws ConfigException
   {
+    ExternalChangelogDomainCfg eclDomCfg = null;
     // create the ecl config if it does not exist
     // There may ot be any config entry related to this domain in some
     // unit test cases
     try
     {
-      ExternalChangelogDomainCfg eclDomCfg = null;
       if (DirectoryServer.getConfigHandler().entryExists(configDn))
       {
         try
-        { eclDomCfg = configuration.getExternalChangelogDomain();
-        }catch(Exception e) {}
-        if (eclDomCfg==null)
+        { eclDomCfg = domCfg.getExternalChangelogDomain();
+        } catch(Exception e) {}
+        // domain with no config entry only when running unit tests
+        if (eclDomCfg == null)
         {
+          // no ECL config provided hence create a default one
+          // create the default one
           DN eclConfigEntryDN = DN.decode("cn=external changelog," + configDn);
           if (!DirectoryServer.getConfigHandler().entryExists(eclConfigEntryDN))
           {
+            // no entry exist yet for the ECL config for this domain
+            // create it
             String ldif = makeLdif(
                 "dn: cn=external changelog," + configDn,
                 "objectClass: top",
@@ -4379,8 +4384,17 @@
           }
         }
       }
-      eclDomCfg = configuration.getExternalChangelogDomain();
-      eclDomain = new ExternalChangelogDomain(this, eclDomCfg);
+      eclDomCfg = domCfg.getExternalChangelogDomain();
+      if (eclDomain != null)
+      {
+        eclDomain.applyConfigurationChange(eclDomCfg);
+      }
+      else
+      {
+        // Create the ECL domain object
+        eclDomain = new ExternalChangelogDomain(this, eclDomCfg);
+      }
+
     }
     catch(Exception de)
     {
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java b/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java
index 57f1223..7729aa3 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java
@@ -2445,7 +2445,7 @@
   }
 
   /**
-   * Change the ReplicationDomain parameters.
+   * Change some ReplicationDomain parameters.
    *
    * @param replicationServers  The new list of Replication Servers that this
    *                           domain should now use.
@@ -2473,6 +2473,44 @@
     }
   }
 
+  /**
+   * Change some ReplicationDomain parameters : the ECL include attribute.
+   *
+   * @param newECLInclude The new ECL attribute.
+   */
+  public void changeConfig(Set<String> newECLInclude)
+  {
+    boolean configECLIncludeChanged = false;
+    Set<String>  currentECLInclude = this.getEclInclude(serverID);
+
+    if (newECLInclude.size() != currentECLInclude.size())
+    {
+      configECLIncludeChanged = true;
+    }
+    else
+    {
+      // compare current config and new config
+      for (String attr : currentECLInclude)
+      {
+        if (!newECLInclude.contains(attr))
+        {
+          configECLIncludeChanged = true;
+          break;
+        }
+      }
+    }
+
+    if (configECLIncludeChanged)
+    {
+      // set new config
+      this.setEclInclude(this.serverID, newECLInclude);
+      if (broker != null)
+      {
+        disableService();
+        enableService();
+      }
+    }
+  }
 
   /**
    * This method should trigger an export of the replicated data.
@@ -2918,7 +2956,6 @@
    */
   public Set<String> getEclInclude()
   {
-    System.out.println("cdECLIn=" + crossServersECLIncludes);
     return crossServersECLIncludes;
   }
 
diff --git a/opendj-sdk/opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java b/opendj-sdk/opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java
index 755d66f..4ac2932 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2008-2009 Sun Microsystems, Inc.
+ *      Copyright 2008-2010 Sun Microsystems, Inc.
  */
 package org.opends.server.workflowelement.externalchangelog;
 
@@ -36,7 +36,6 @@
 import static org.opends.server.util.ServerConstants.*;
 import static org.opends.server.util.StaticUtils.getExceptionMessage;
 import static org.opends.server.util.StaticUtils.needsBase64Encoding;
-import static org.opends.server.util.StaticUtils.*;
 
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -909,13 +908,13 @@
     if (draftChangenumber == 0)
     {
       // Draft uncompat mode
-      dnString = "cn="+ changeNumber +"," + serviceID + "," +
-        ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT;
+      dnString = "replicationcsn="+ changeNumber +"," + serviceID
+        + "," + ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT;
     }
     else
     {
       // Draft compat mode
-      dnString = "cn="+ draftChangenumber + "," +
+      dnString = "changenumber="+ draftChangenumber + "," +
       ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT;
     }
     HashMap<ObjectClass,String> oClasses =
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java
index b15b2ba..6e0dfc4 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java
@@ -1575,7 +1575,7 @@
           {
             // check the DEL entry has the right content
             assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
-                "cn=" + cn1 + "," + TEST_ROOT_DN_STRING + ",cn=changelog"));
+                "replicationcsn=" + cn1 + "," + TEST_ROOT_DN_STRING + ",cn=changelog"));
             checkValue(resultEntry,"replicationcsn",cn1.toString());
             checkValue(resultEntry,"replicaidentifier","1201");
             checkValue(resultEntry,"targetdn","uid="+tn+"1," + TEST_ROOT_DN_STRING);
@@ -1587,7 +1587,7 @@
           {
             // check the ADD entry has the right content
             assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
-                "cn=" + cn2 + "," + TEST_ROOT_DN_STRING + ",cn=changelog"));
+                "replicationcsn=" + cn2 + "," + TEST_ROOT_DN_STRING + ",cn=changelog"));
             String expectedValue1 = "objectClass: domain\nobjectClass: top\n" +
             "entryUUID: 11111111-1111-1111-1111-111111111111\n\n";
             String expectedValue2 = "entryUUID: 11111111-1111-1111-1111-111111111111\n" +
@@ -1604,7 +1604,7 @@
           {
             // check the MOD entry has the right content
             assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
-                "cn=" + cn3 + "," + TEST_ROOT_DN_STRING + ",cn=changelog"));
+                "replicationcsn=" + cn3 + "," + TEST_ROOT_DN_STRING + ",cn=changelog"));
             String expectedValue = "replace: description\n" +
             "description: new value\n-\n";
             checkValue(resultEntry,"changes",expectedValue);
@@ -1619,7 +1619,7 @@
           {
             // check the MODDN entry has the right content
             assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
-                "cn=" + cn4 + "," + TEST_ROOT_DN_STRING + ",cn=changelog"));
+                "replicationcsn=" + cn4 + "," + TEST_ROOT_DN_STRING + ",cn=changelog"));
             checkValue(resultEntry,"replicationcsn",cn4.toString());
             checkValue(resultEntry,"replicaidentifier","1201");
             checkValue(resultEntry,"targetdn","uid="+tn+"4," + TEST_ROOT_DN_STRING);
@@ -2987,9 +2987,9 @@
           {
             // check the DEL entry has the right content
             assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
-                "cn="+String.valueOf(firstDraftChangeNumber+0)+",cn=changelog"),
+                "changenumber="+String.valueOf(firstDraftChangeNumber+0)+",cn=changelog"),
                 "Result entry DN : actual=" + resultEntry.getDN().toNormalizedString() +
-                " expected=" + "cn="+String.valueOf(firstDraftChangeNumber+0)+",cn=changelog");
+                " expected=" + "changenumber="+String.valueOf(firstDraftChangeNumber+0)+",cn=changelog");
             checkValue(resultEntry,"replicationcsn",cn1.toString());
             checkValue(resultEntry,"replicaidentifier","1201");
             checkValue(resultEntry,"targetdn","uid="+tn+"1," + TEST_ROOT_DN_STRING);
@@ -3002,7 +3002,7 @@
           {
             // check the ADD entry has the right content
             assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
-                "cn="+String.valueOf(firstDraftChangeNumber+1)+",cn=changelog"));
+                "changenumber="+String.valueOf(firstDraftChangeNumber+1)+",cn=changelog"));
             String expectedValue1 = "objectClass: domain\nobjectClass: top\n" +
             "entryUUID: "+user1entryUUID+"\n\n";
             String expectedValue2 = "entryUUID: "+user1entryUUID+"\n" +
@@ -3019,7 +3019,7 @@
           {
             // check the MOD entry has the right content
             assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
-                "cn="+String.valueOf(firstDraftChangeNumber+2)+",cn=changelog"));
+                "changenumber="+String.valueOf(firstDraftChangeNumber+2)+",cn=changelog"));
             String expectedValue = "replace: description\n" +
             "description: new value\n-\n";
             checkValue(resultEntry,"changes",expectedValue);
@@ -3034,7 +3034,7 @@
           {
             // check the MODDN entry has the right content
             assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
-                "cn="+String.valueOf(firstDraftChangeNumber+3)+",cn=changelog"));
+                "changenumber="+String.valueOf(firstDraftChangeNumber+3)+",cn=changelog"));
             checkValue(resultEntry,"replicationcsn",cn4.toString());
             checkValue(resultEntry,"replicaidentifier","1201");
             checkValue(resultEntry,"targetdn","uid="+tn+"4," + TEST_ROOT_DN_STRING);
@@ -3082,7 +3082,7 @@
           {
             // check the DEL entry has the right content
             assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
-                "cn="+String.valueOf(firstDraftChangeNumber+0)+",cn=changelog"));
+                "changenumber="+String.valueOf(firstDraftChangeNumber+0)+",cn=changelog"));
             checkValue(resultEntry,"replicationcsn",cn1.toString());
             checkValue(resultEntry,"replicaidentifier","1201");
             checkValue(resultEntry,"targetdn","uid="+tn+"1," + TEST_ROOT_DN_STRING);
@@ -3095,7 +3095,7 @@
           {
             // check the ADD entry has the right content
             assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
-                "cn="+String.valueOf(firstDraftChangeNumber+1)+",cn=changelog"));
+                "changenumber="+String.valueOf(firstDraftChangeNumber+1)+",cn=changelog"));
             String expectedValue1 = "objectClass: domain\nobjectClass: top\n" +
             "entryUUID: "+user1entryUUID+"\n\n";
             String expectedValue2 = "entryUUID: "+user1entryUUID+"\n" +
@@ -3112,7 +3112,7 @@
           {
             // check the MOD entry has the right content
             assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
-                "cn="+String.valueOf(firstDraftChangeNumber+2)+",cn=changelog"));
+                "changenumber="+String.valueOf(firstDraftChangeNumber+2)+",cn=changelog"));
             String expectedValue = "replace: description\n" +
             "description: new value\n-\n";
             checkValue(resultEntry,"changes",expectedValue);
@@ -3127,7 +3127,7 @@
           {
             // check the MODDN entry has the right content
             assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
-                "cn="+String.valueOf(firstDraftChangeNumber+3)+",cn=changelog"));
+                "changenumber="+String.valueOf(firstDraftChangeNumber+3)+",cn=changelog"));
             checkValue(resultEntry,"replicationcsn",cn4.toString());
             checkValue(resultEntry,"replicaidentifier","1201");
             checkValue(resultEntry,"targetdn","uid="+tn+"4," + TEST_ROOT_DN_STRING);
@@ -3201,7 +3201,7 @@
           ldifWriter.writeEntry(resultEntry);
           // check the entry has the right content
           assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
-              "cn=6,cn=changelog"));
+              "changenumber=6,cn=changelog"));
           checkValue(resultEntry,"replicationcsn",gblCN.toString());
           checkValue(resultEntry,"replicaidentifier","1201");
           checkValue(resultEntry,"changetype","add");

--
Gitblit v1.10.0