From 06ec8c88556b02782c7b91a233de91eaf4a1439d Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 09 Jun 2009 12:28:05 +0000
Subject: [PATCH] Fix for issue 3550 (Consider making the control panel able to manage remote servers)

---
 opends/src/guitools/org/opends/guitools/controlpanel/util/ConfigFromDirContext.java |  105 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 96 insertions(+), 9 deletions(-)

diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/util/ConfigFromDirContext.java b/opends/src/guitools/org/opends/guitools/controlpanel/util/ConfigFromDirContext.java
index 86f1513..7f6e720 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/util/ConfigFromDirContext.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/util/ConfigFromDirContext.java
@@ -67,6 +67,7 @@
 import org.opends.server.admin.client.ldap.LDAPManagementContext;
 import org.opends.server.admin.std.client.*;
 import org.opends.server.admin.std.meta.LocalDBIndexCfgDefn.IndexType;
+import org.opends.server.core.DirectoryServer;
 import org.opends.server.types.DN;
 import org.opends.server.types.OpenDsException;
 import org.opends.server.util.ServerConstants;
@@ -88,6 +89,9 @@
   private CustomSearchResult systemInformation;
   private CustomSearchResult entryCaches;
   private CustomSearchResult workQueue;
+  private CustomSearchResult versionMonitor;
+
+  private boolean isLocal = true;
 
   private Map<String, CustomSearchResult> hmConnectionHandlersMonitor =
     new HashMap<String, CustomSearchResult>();
@@ -112,6 +116,10 @@
    * The work queue monitoring entry DN.
    */
   protected DN workQueueDN = DN.nullDN();
+  /**
+   * The version monitoring entry DN.
+   */
+  protected DN versionDN = DN.nullDN();
 
   {
     try
@@ -121,6 +129,7 @@
       systemInformationDN = DN.decode("cn=System Information,cn=monitor");
       entryCachesDN = DN.decode("cn=Entry Caches,cn=monitor");
       workQueueDN = DN.decode("cn=Work Queue,cn=monitor");
+      versionDN = DN.decode("cn=Version,cn=monitor");
     }
     catch (Throwable t)
     {
@@ -169,6 +178,15 @@
   }
 
   /**
+   * Returns the version entry of the monitoring tree.
+   * @return the version entry of the monitoring tree.
+   */
+  public CustomSearchResult getVersionMonitor()
+  {
+    return versionMonitor;
+  }
+
+  /**
    * Returns the monitoring entry for the system information.
    * @return the monitoring entry for the system information.
    */
@@ -187,6 +205,28 @@
   }
 
   /**
+   * Sets whether this server represents the local instance or a remote server.
+   * @param isLocal whether this server represents the local instance or a
+   * remote server (in another machine or in another installation on the same
+   * machine).
+   */
+  public void setIsLocal(boolean isLocal)
+  {
+    this.isLocal = isLocal;
+  }
+
+  /**
+   * Returns <CODE>true</CODE> if we are trying to manage the local host and
+   * <CODE>false</CODE> otherwise.
+   * @return <CODE>true</CODE> if we are trying to manage the local host and
+   * <CODE>false</CODE> otherwise.
+   */
+  public boolean isLocal()
+  {
+    return isLocal;
+  }
+
+  /**
    * Reads configuration and monitoring information using the provided
    * connection.
    * @param ctx the connection to be used to read the information.
@@ -204,9 +244,28 @@
     systemInformation = null;
     entryCaches = null;
     workQueue = null;
+    versionMonitor = null;
 
     hmConnectionHandlersMonitor.clear();
 
+    if (mustReadSchema())
+    {
+      try
+      {
+        readSchema(ctx);
+        if (getSchema() != null)
+        {
+          // Update the schema: so that when we call the server code the
+          // latest schema read on the server we are managing is used.
+          DirectoryServer.setSchema(getSchema());
+        }
+      }
+      catch (OpenDsException oe)
+      {
+        ex.add(oe);
+      }
+    }
+
     try
     {
       // Get the Directory Server configuration handler and use it.
@@ -449,15 +508,6 @@
       {
         ex.add(oe);
       }
-
-      try
-      {
-        readSchema();
-      }
-      catch (OpenDsException oe)
-      {
-        ex.add(oe);
-      }
     }
     catch (final Throwable t)
     {
@@ -506,6 +556,33 @@
   }
 
   /**
+   * Reads the schema from the files.
+   * @param ctx the connection to be used to load the schema.
+   * @throws OpenDsException if an error occurs reading the schema.
+   */
+  private void readSchema(InitialLdapContext ctx) throws OpenDsException
+  {
+    if (isLocal)
+    {
+      super.readSchema();
+    }
+    else
+    {
+      RemoteSchemaLoader loader = new RemoteSchemaLoader();
+      try
+      {
+        loader.readSchema(ctx);
+      }
+      catch (NamingException ne)
+      {
+        throw new OnlineUpdateException(
+            ERR_READING_SCHEMA_LDAP.get(ne.toString()), ne);
+      }
+      schema = loader.getSchema();
+    }
+  }
+
+  /**
    * Takes the provided search result and updates the monitoring information
    * accordingly.
    * @param sr the search result.
@@ -662,6 +739,10 @@
         {
           systemInformation = csr;
         }
+        else if ((versionMonitor == null) && isVersionMonitor(csr))
+        {
+          versionMonitor = csr;
+        }
         else if (isConnectionHandler(csr))
         {
           String statistics = " Statistics";
@@ -829,6 +910,12 @@
     return monitorDN.equals(DN.decode(csr.getDN()));
   }
 
+  private boolean isVersionMonitor(CustomSearchResult csr)
+  throws OpenDsException
+  {
+    return versionDN.equals(DN.decode(csr.getDN()));
+  }
+
   private boolean isSystemInformation(CustomSearchResult csr)
   throws OpenDsException
   {

--
Gitblit v1.10.0