From 7886f35b46cac515f73de8c6af33b8d8df3e2a3b Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 08 Jun 2007 12:00:22 +0000
Subject: [PATCH] Commit quite a lot of bug fixes to the ADS.

---
 opends/src/ads/org/opends/admin/ads/ServerDescriptor.java |   91 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 79 insertions(+), 12 deletions(-)

diff --git a/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java b/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
index 0676984..c396951 100644
--- a/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
+++ b/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
@@ -223,12 +223,15 @@
           ServerProperty.LDAP_ENABLED);
       ArrayList p = (ArrayList)serverProperties.get(
           ServerProperty.LDAP_PORT);
-      for (int i=0; i<s.size(); i++)
+      if (s != null)
       {
-        if (Boolean.TRUE.equals(s.get(i)))
+        for (int i=0; i<s.size(); i++)
         {
-          port = (Integer)p.get(i);
-          break;
+          if (Boolean.TRUE.equals(s.get(i)))
+          {
+            port = (Integer)p.get(i);
+            break;
+          }
         }
       }
       if (securePreferred)
@@ -236,12 +239,15 @@
         s = (ArrayList)serverProperties.get(
             ServerProperty.LDAPS_ENABLED);
         p = (ArrayList)serverProperties.get(ServerProperty.LDAPS_PORT);
-        for (int i=0; i<s.size(); i++)
+        if (s != null)
         {
-          if (Boolean.TRUE.equals(s.get(i)))
+          for (int i=0; i<s.size(); i++)
           {
-            port = (Integer)p.get(i);
-            break;
+            if (Boolean.TRUE.equals(s.get(i)))
+            {
+              port = (Integer)p.get(i);
+              break;
+            }
           }
         }
       }
@@ -269,7 +275,7 @@
       {
       }
     }
-    return host + "." + port;
+    return host + ":" + port;
   }
 
   /**
@@ -343,6 +349,65 @@
   }
 
   /**
+   * This methods updates the ADS properties (the ones that were read from
+   * the ADS) with the contents of the server properties (the ones that were
+   * read directly from the server).
+   */
+  public void updateAdsPropertiesWithServerProperties()
+  {
+    adsProperties.put(ADSContext.ServerProperty.HOST_NAME, getHostName());
+    ServerProperty[][] sProps =
+    {
+        {ServerProperty.LDAP_ENABLED, ServerProperty.LDAP_PORT},
+        {ServerProperty.LDAPS_ENABLED, ServerProperty.LDAPS_PORT},
+        {ServerProperty.JMX_ENABLED, ServerProperty.JMX_PORT},
+        {ServerProperty.JMXS_ENABLED, ServerProperty.JMXS_PORT}
+    };
+    ADSContext.ServerProperty[][] adsProps =
+    {
+        {ADSContext.ServerProperty.LDAP_ENABLED,
+          ADSContext.ServerProperty.LDAP_PORT},
+        {ADSContext.ServerProperty.LDAPS_ENABLED,
+          ADSContext.ServerProperty.LDAPS_PORT},
+        {ADSContext.ServerProperty.JMX_ENABLED,
+          ADSContext.ServerProperty.JMX_PORT},
+        {ADSContext.ServerProperty.JMXS_ENABLED,
+          ADSContext.ServerProperty.JMXS_PORT}
+    };
+
+    for (int i=0; i<sProps.length; i++)
+    {
+      ArrayList s = (ArrayList)serverProperties.get(sProps[i][0]);
+      ArrayList p = (ArrayList)serverProperties.get(sProps[i][1]);
+      if (s != null)
+      {
+        int port = -1;
+        for (int j=0; j<s.size(); i++)
+        {
+          if (Boolean.TRUE.equals(s.get(j)))
+          {
+            port = (Integer)p.get(j);
+            break;
+          }
+        }
+        if (port == -1)
+        {
+          adsProperties.put(adsProps[i][0], "false");
+          if (p.size() > 0)
+          {
+            port = (Integer)p.iterator().next();
+          }
+        }
+        else
+        {
+          adsProperties.put(adsProps[i][0], "true");
+        }
+        adsProperties.put(adsProps[i][1], String.valueOf(port));
+      }
+    }
+  }
+
+  /**
    * Creates a ServerDescriptor object based on some ADS properties provided.
    * @param adsProperties the ADS properties of the server.
    * @return a ServerDescriptor object that corresponds to the provided ADS
@@ -522,17 +587,18 @@
 
         int nEntries = getEntryCount(ctx, id);
 
+        Set<ReplicaDescriptor> replicas = desc.getReplicas();
         for (String baseDn : baseDns)
         {
           SuffixDescriptor suffix = new SuffixDescriptor();
           suffix.setDN(baseDn);
           ReplicaDescriptor replica = new ReplicaDescriptor();
           replica.setServer(desc);
-          Set<ReplicaDescriptor> replicas = new HashSet<ReplicaDescriptor>();
           replicas.add(replica);
-          suffix.setReplicas(replicas);
+          HashSet<ReplicaDescriptor> r = new HashSet<ReplicaDescriptor>();
+          r.add(replica);
+          suffix.setReplicas(r);
           replica.setSuffix(suffix);
-          desc.setReplicas(replicas);
           if (baseDns.size() == 1)
           {
             replica.setEntries(nEntries);
@@ -543,6 +609,7 @@
             replica.setEntries(-1);
           }
         }
+        desc.setReplicas(replicas);
       }
     }
   }

--
Gitblit v1.10.0