From 5515540a55fec581af09610837d99aa5d2794dc3 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 20 Nov 2007 13:02:16 +0000
Subject: [PATCH] Simplify the interface of InstallerHelper.configureReplication and add some checks to avoid problems with DN comparison in the code of the QuickSetup.

---
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java |    7 ++-----
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java       |   46 ++++++++++++++++++++++++++++++++++++----------
 2 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
index dc7bf31..38a226d 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -1438,7 +1438,6 @@
        is a degenerate case. Also, collect a set of all observed replication
        servers as the set of ADS suffix replicas (all instances hosting the
        replication server also replicate ADS). */
-    Set<String> dns = new HashSet<String>();
     Map<String, Set<String>> replicationServers
             = new HashMap<String, Set<String>>();
     HashSet<String> adsServers = new HashSet<String>();
@@ -1448,13 +1447,12 @@
     {
       LinkedList<String> baseDns =
         getUserData().getNewSuffixOptions().getBaseDns();
-      dns.addAll(baseDns);
       HashSet<String> h = new HashSet<String>();
       h.add(getLocalReplicationServer());
       adsServers.add(getLocalReplicationServer());
       for (String dn : baseDns)
       {
-        replicationServers.put(dn, h);
+        replicationServers.put(dn, new HashSet<String>(h));
       }
     }
     else
@@ -1463,7 +1461,6 @@
         getUserData().getSuffixesToReplicateOptions().getSuffixes();
       for (SuffixDescriptor suffix : suffixes)
       {
-        dns.add(suffix.getDN());
         HashSet<String> h = new HashSet<String>();
         h.addAll(suffix.getReplicationServers());
         adsServers.addAll(suffix.getReplicationServers());
@@ -1483,10 +1480,9 @@
         replicationServers.put(suffix.getDN(), h);
       }
     }
-    dns.add(ADSContext.getAdministrationSuffixDN());
     replicationServers.put(ADSContext.getAdministrationSuffixDN(), adsServers);
-    dns.add(Constants.SCHEMA_DN);
-    replicationServers.put(Constants.SCHEMA_DN, adsServers);
+    replicationServers.put(Constants.SCHEMA_DN,
+        new HashSet<String>(adsServers));
 
     InitialLdapContext ctx = null;
     long localTime = -1;
@@ -1495,7 +1491,7 @@
     try
     {
       ctx = createLocalContext();
-      helper.configureReplication(ctx, dns, replicationServers,
+      helper.configureReplication(ctx, replicationServers,
           getUserData().getReplicationOptions().getReplicationPort(),
           getUserData().getReplicationOptions().useSecureReplication(),
           getLocalHostPort(),
@@ -1582,16 +1578,46 @@
                 server.getHostPort(true));
           }
         }
-        dns = new HashSet<String>();
+        HashSet<String> dns = new HashSet<String>();
         for (ReplicaDescriptor replica : hm.get(server))
         {
           dns.add(replica.getSuffix().getDN());
         }
         dns.add(ADSContext.getAdministrationSuffixDN());
         dns.add(Constants.SCHEMA_DN);
+        Map<String, Set<String>> remoteReplicationServers
+        = new HashMap<String, Set<String>>();
+        for (String dn : dns)
+        {
+          Set<String> repServer = replicationServers.get(dn);
+          if (repServer == null)
+          {
+            // Do the comparison manually
+            for (String dn1 : replicationServers.keySet())
+            {
+              if (Utils.areDnsEqual(dn, dn1))
+              {
+                repServer = replicationServers.get(dn1);
+                dn = dn1;
+                break;
+              }
+            }
+          }
+          if (repServer != null)
+          {
+            remoteReplicationServers.put(dn, repServer);
+          }
+          else
+          {
+            LOG.log(Level.WARNING, "Could not find replication server for: "+
+                dn);
+          }
+        }
+
+
         ctx = getRemoteConnection(server, getTrustManager());
         ConfiguredReplication repl =
-          helper.configureReplication(ctx, dns, replicationServers,
+          helper.configureReplication(ctx, remoteReplicationServers,
               replicationPort, enableSecureReplication,
               server.getHostPort(true), knownReplicationServerIds,
               knownServerIds);
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java
index c8ca3c7..83a2e5d 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java
@@ -212,8 +212,6 @@
    * Configures the replication on a given server.
    * @param remoteCtx the conection to the server where we want to configure
    * the replication.
-   * @param dns the suffix base dns for which we want to configure the
-   * replication.
    * @param replicationServers a Map where the key value is the base dn and
    * the value is the list of replication servers for that base dn (or domain).
    * @param replicationPort the replicationPort of the server that is being
@@ -229,8 +227,7 @@
    * @return a ConfiguredReplication object describing what has been configured.
    */
   public ConfiguredReplication configureReplication(
-      InitialLdapContext remoteCtx, Set<String> dns,
-      Map<String,Set<String>> replicationServers,
+      InitialLdapContext remoteCtx, Map<String,Set<String>> replicationServers,
       int replicationPort, boolean useSecureReplication, String serverDisplay,
       Set<Integer> usedReplicationServerIds, Set<Integer> usedServerIds)
   throws ApplicationException
@@ -365,7 +362,7 @@
       {
         domains[i] = sync.getReplicationDomain(domainNames[i]);
       }
-      for (String dn : dns)
+      for (String dn : replicationServers.keySet())
       {
         ReplicationDomainCfgClient domain = null;
         boolean isCreated;

--
Gitblit v1.10.0