From b7fe300600e848ffe5fd028afb3100dae03625c3 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 11 Dec 2009 16:55:17 +0000
Subject: [PATCH] Fix for issue 4398 (status can be very slow: include a refresh mode)

---
 opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCliArgumentParser.java |   39 +++++++++++++++++++
 opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCli.java               |   67 +++++++++++++++++++++++++--------
 opendj-sdk/opends/src/messages/messages/admin_tool.properties                            |   11 ++++-
 3 files changed, 99 insertions(+), 18 deletions(-)

diff --git a/opendj-sdk/opends/src/messages/messages/admin_tool.properties b/opendj-sdk/opends/src/messages/messages/admin_tool.properties
index cb52c5f..eb26bc8 100644
--- a/opendj-sdk/opends/src/messages/messages/admin_tool.properties
+++ b/opendj-sdk/opends/src/messages/messages/admin_tool.properties
@@ -1627,6 +1627,9 @@
 MILD_ERR_CANNOT_DELETE_ATTRIBUTE_WITH_DEPENDENCIES=Attribute '%s' is optional \
  or required by the following objectClasses: %s.  You must redefine these \
  classes so that they do not depend on attribute '%s' before deleting it.
+MILD_ERR_CANNOT_MODIFY_PARENT_ATTRIBUTE=Attribute '%s' is superior of the \
+ following attributes: %s.  You must redefine these attributes so that they do \
+ not inherit from attribute '%s' before modifying it.
 INFO_CTRL_PANEL_MANAGE_SCHEMA_TITLE=Manage Schema
 INFO_CTRL_PANEL_DELETE_OBJECTCLASSES_TITLE=Delete Objectclasses
 INFO_CTRL_PANEL_DELETE_ATTRIBUTES_TITLE=Delete Attributes
@@ -1969,8 +1972,12 @@
 
 INFO_CTRL_PANEL_UNSAVED_CHANGES_DIALOG_TITLE=Unsaved Changes
 INFO_CTRL_PANEL_UNSAVED_CHANGES_SUMMARY=Unsaved Changes
-INFO_CTRL_PANEL_UNSAVED_INDEX_CHANGES_DETAILS=Save Changes to: '%s'?
-INFO_CTRL_PANEL_UNSAVED_ENTRY_CHANGES_DETAILS=Save Changes to: '%s'?
+INFO_CTRL_PANEL_UNSAVED_INDEX_CHANGES_DETAILS=Save Changes to index: '%s'?
+INFO_CTRL_PANEL_UNSAVED_ENTRY_CHANGES_DETAILS=Save Changes to entry: '%s'?
+INFO_CTRL_PANEL_UNSAVED_ATTRIBUTE_CHANGES_DETAILS=Save Changes to attribute: \
+ '%s'?
+INFO_CTRL_PANEL_UNSAVED_OBJECTCLASS_CHANGES_DETAILS=Save Changes to object \
+ class: '%s'?
 INFO_CTRL_PANEL_DELETING_ENTRY_TITLE=Delete Entry
 INFO_CTRL_PANEL_DELETING_SUBTREE_TITLE=Delete Subtree
 INFO_CTRL_PANEL_DELETE_ENTRY_CONFIRMATION_DETAILS=Do you want to delete entry \
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCli.java b/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCli.java
index af6c62d..6ba52cc 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCli.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCli.java
@@ -62,7 +62,6 @@
 import org.opends.server.admin.client.cli.DsFrameworkCliReturnCode;
 import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
 import org.opends.server.config.ConfigException;
-import org.opends.server.core.DirectoryServer;
 
 import org.opends.messages.Message;
 import org.opends.messages.MessageBuilder;
@@ -276,10 +275,6 @@
    * @return the return code (SUCCESSFUL, USER_DATA_ERROR or BUG.
    */
   public int execute(String[] args, boolean initializeServer) {
-    if (initializeServer) {
-      DirectoryServer.bootstrapClient();
-    }
-
     argParser = new StatusCliArgumentParser(StatusCli.class.getName());
     try {
       argParser.initializeGlobalArguments(getOutputStream());
@@ -378,9 +373,7 @@
             return ErrorReturnCode.USER_CANCELLED_OR_DATA_ERROR.getReturnCode();
           } catch (ClientException e) {
             println(e.getMessageObject());
-            // Display the information in the config file
-            ServerDescriptor desc = controlInfo.getServerDescriptor();
-            writeStatus(desc);
+            writeStatus(controlInfo);
             return ErrorReturnCode.USER_CANCELLED_OR_DATA_ERROR.getReturnCode();
           } finally {
             if (ctx != null) {
@@ -410,10 +403,9 @@
             ctx = Utilities.getAdminDirContext(controlInfo, bindDn, bindPwd);
             controlInfo.setDirContext(ctx);
             controlInfo.regenerateDescriptor();
-            ServerDescriptor desc = controlInfo.getServerDescriptor();
-            writeStatus(desc);
+            writeStatus(controlInfo);
 
-            if (!desc.getExceptions().isEmpty()) {
+            if (!controlInfo.getServerDescriptor().getExceptions().isEmpty()) {
               return ErrorReturnCode.ERROR_READING_CONFIGURATION_WITH_LDAP.
                 getReturnCode();
             }
@@ -443,18 +435,56 @@
         } else {
           // The user did not provide authentication: just display the
           // information we can get reading the config file.
-          ServerDescriptor desc = controlInfo.getServerDescriptor();
-          writeStatus(desc);
+          writeStatus(controlInfo);
         }
       } else {
-        ServerDescriptor desc = controlInfo.getServerDescriptor();
-        writeStatus(desc);
+        writeStatus(controlInfo);
       }
     }
 
     return ErrorReturnCode.SUCCESSFUL.getReturnCode();
   }
 
+  private void writeStatus(ControlPanelInfo controlInfo)
+  {
+    if (controlInfo.getServerDescriptor() == null)
+    {
+      controlInfo.regenerateDescriptor();
+    }
+    writeStatus(controlInfo.getServerDescriptor());
+    int period = argParser.getRefreshPeriod();
+    boolean first = true;
+    while (period > 0)
+    {
+      long timeToSleep = period * 1000;
+      if (!first)
+      {
+        long t1 = System.currentTimeMillis();
+        controlInfo.regenerateDescriptor();
+        long t2 = System.currentTimeMillis();
+
+        timeToSleep = timeToSleep - t2 + t1;
+      }
+
+      if (timeToSleep > 0)
+      {
+        try
+        {
+          Thread.sleep(timeToSleep);
+        }
+        catch (Throwable t)
+        {
+        }
+      }
+      getOutputStream().println();
+      getOutputStream().println(
+      "          ---------------------");
+      getOutputStream().println();
+      writeStatus(controlInfo.getServerDescriptor());
+      first = false;
+    }
+  }
+
   private void writeStatus(ServerDescriptor desc)
   {
     Message[] labels =
@@ -1294,7 +1324,7 @@
 
 
   /**
-   * Wraps a message accoring to client tool console width.
+   * Wraps a message according to client tool console width.
    * @param text to wrap
    * @return raw message representing wrapped string
    */
@@ -1303,4 +1333,9 @@
     return Message.raw(
         StaticUtils.wrapText(text, getCommandLineMaxLineWidth()));
   }
+
+  private static void printTimeSince(String msg, long initTime)
+  {
+    System.out.println(msg+" : "+(System.currentTimeMillis() - initTime));
+  }
 }
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCliArgumentParser.java b/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCliArgumentParser.java
index f19eca6..98f3b54 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCliArgumentParser.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCliArgumentParser.java
@@ -41,6 +41,7 @@
 import org.opends.server.util.args.Argument;
 import org.opends.server.util.args.ArgumentException;
 import org.opends.server.util.args.BooleanArgument;
+import org.opends.server.util.args.IntegerArgument;
 import org.opends.server.util.args.StringArgument;
 
 /**
@@ -55,6 +56,11 @@
   // This CLI is always using the administration connector with SSL
   private final boolean alwaysSSL = true;
 
+
+  /**
+   * The 'refresh' argument.
+   */
+  private IntegerArgument refreshArg;
   /**
    * The 'scriptFriendly' argument.
    */
@@ -120,6 +126,12 @@
     setNoPropertiesFileArgument(noPropertiesFileArgument);
 
     initializeGlobalArguments(defaultArgs);
+
+    refreshArg = new IntegerArgument("refresh", 'r',
+        "refresh", false, true, INFO_PERIOD_PLACEHOLDER.get(),
+        true, 1, false, Integer.MAX_VALUE,
+        INFO_DESCRIPTION_REFRESH_PERIOD.get());
+    addGlobalArgument(refreshArg, ioArgGroup);
   }
 
   /**
@@ -155,6 +167,33 @@
   }
 
   /**
+   * Returns the refresh period (in seconds) specified in the command-line.
+   * If no refresh period was specified, returns -1.
+   * The code assumes that the attributes have been successfully parsed.
+   * @return the specified refresh period in the command-line.
+   */
+  public int getRefreshPeriod()
+  {
+    if (refreshArg.isPresent())
+    {
+      try
+      {
+        return refreshArg.getIntValue();
+      }
+      catch (ArgumentException ae)
+      {
+        // Bug
+        throw new IllegalStateException("Error getting value, this method "+
+            "should be called after parsing the attributes: "+ae, ae);
+      }
+    }
+    else
+    {
+      return -1;
+    }
+  }
+
+  /**
    * Returns the bind DN explicitly provided in the command-line.
    * @return the bind DN explicitly provided in the command-line.
    * Returns <CODE>null</CODE> if no bind DN was explicitly provided.

--
Gitblit v1.10.0