From 391c56175d771b919d1b2db3e88cec42ed5e75c0 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 16 Jan 2009 14:25:56 +0000
Subject: [PATCH] Add some monitoring information to the backend descriptor objects.

---
 opends/src/guitools/org/opends/guitools/controlpanel/datamodel/BackendDescriptor.java |   32 ++++++++++++++++++++++++++++++++
 opends/src/guitools/org/opends/guitools/controlpanel/util/ConfigFromDirContext.java   |   22 ++++++++++++++++++++++
 2 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/BackendDescriptor.java b/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/BackendDescriptor.java
index 25aa7da..8ffc94d 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/BackendDescriptor.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/BackendDescriptor.java
@@ -45,6 +45,7 @@
   private int entries;
   private boolean isConfigBackend;
   private boolean isEnabled;
+  private CustomSearchResult monitoringEntry;
   private Type type;
   private int hashCode;
 
@@ -186,6 +187,19 @@
         {
           equals = desc.getVLVIndexes().equals(getVLVIndexes());
         }
+
+        if (equals)
+        {
+          // Compare monitoring entries
+          if (getMonitoringEntry() == null)
+          {
+            equals = desc.getMonitoringEntry() == null;
+          }
+          else
+          {
+            equals = getMonitoringEntry().equals(desc.getMonitoringEntry());
+          }
+        }
       }
     }
     else
@@ -196,6 +210,15 @@
   }
 
   /**
+   * Returns the monitoring entry information.
+   * @return the monitoring entry information.
+   */
+  public CustomSearchResult getMonitoringEntry()
+  {
+    return monitoringEntry;
+  }
+
+  /**
    * {@inheritDoc}
    */
   public int hashCode()
@@ -290,6 +313,15 @@
   }
 
   /**
+   * Sets the monitoring entry corresponding to this backend.
+   * @param monitoringEntry the monitoring entry corresponding to this backend.
+   */
+  public void setMonitoringEntry(CustomSearchResult monitoringEntry)
+  {
+    this.monitoringEntry = monitoringEntry;
+  }
+
+  /**
    * Returns the type of the backend.
    * @return the type of the backend.
    */
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 a34eaa9..c881d57 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/util/ConfigFromDirContext.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/util/ConfigFromDirContext.java
@@ -52,6 +52,7 @@
 import org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
 import org.opends.guitools.controlpanel.datamodel.BaseDNDescriptor;
 import org.opends.guitools.controlpanel.datamodel.ConnectionHandlerDescriptor;
+import org.opends.guitools.controlpanel.datamodel.CustomSearchResult;
 import org.opends.guitools.controlpanel.datamodel.IndexDescriptor;
 import org.opends.guitools.controlpanel.datamodel.VLVIndexDescriptor;
 import org.opends.guitools.controlpanel.datamodel.VLVSortOrder;
@@ -71,6 +72,8 @@
  */
 public class ConfigFromDirContext extends ConfigReader
 {
+  private static final String DATABASE_ENVIRONMENT_SUFFIX =
+    "Database Environment";
   private static final Logger LOG =
     Logger.getLogger(ConfigFromDirContext.class.getName());
 
@@ -356,6 +359,7 @@
     }
     catch (Throwable t)
     {
+      LOG.log(Level.WARNING, "Error reading configuration: "+t, t);
       OnlineUpdateException oupe = new OnlineUpdateException(
           ERR_READING_CONFIG_LDAP.get(t.toString()), t);
       ex.add(oupe);
@@ -487,6 +491,24 @@
           }
         }
       }
+      else
+      {
+        // Check if it is the DB monitor entry
+        String cn = ConnectionUtils.getFirstValue(sr, "cn");
+        if ((cn != null) && cn.endsWith(DATABASE_ENVIRONMENT_SUFFIX))
+        {
+          String monitorBackendID = cn.substring(0, cn.length() -
+              DATABASE_ENVIRONMENT_SUFFIX.length());
+          for (BackendDescriptor backend : backends)
+          {
+            if (backend.getBackendID().equalsIgnoreCase(monitorBackendID))
+            {
+              CustomSearchResult csr = new CustomSearchResult(sr, searchBaseDN);
+              backend.setMonitoringEntry(csr);
+            }
+          }
+        }
+      }
     }
   }
 

--
Gitblit v1.10.0