mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
07.00.2009 3d95b1667808dc87d7536e69f2e5b93cb2dbd6f9
Fix for issue 4091 (]  extend behaviour of dsconfig's --commandFilePath, to keep history accross sessions)
4 files modified
108 ■■■■■ changed files
opendj-sdk/opends/src/messages/messages/admin_tool.properties 1 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/messages/messages/dsconfig.properties 4 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java 57 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java 46 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/messages/messages/admin_tool.properties
@@ -2800,3 +2800,4 @@
INFO_CTRL_PANEL_NO_TASK_SELECTED=-No Task Selected-
INFO_CTRL_PANEL_MULTIPLE_TASKS_SELECTED=-Multiple Tasks Selected-
INFO_CTRL_PANEL_NO_TASK_SPECIFIC_DETAILS=-No Task Specific Details-
INFO_OPERATION_START_TIME_MESSAGE=Operation date: %s
opendj-sdk/opends/src/messages/messages/dsconfig.properties
@@ -480,3 +480,7 @@
 Are you sure that this is the correct one?
MILD_ERR_DSCFG_ERROR_READING_BATCH_FILE_162=An error occurred \
 while attempting to read the batch file : %s
INFO_DSCFG_SESSION_START_TIME_MESSAGE_163=%s session start date: %s
INFO_DSCFG_EQUIVALENT_COMMAND_LINE_SESSION_OPERATION_NUMBER_164=Session \
 operation number: %d
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java
@@ -34,6 +34,7 @@
import static org.opends.server.loggers.debug.DebugLogger.*;
import static org.opends.server.tools.ToolConstants.*;
import static org.opends.server.tools.dsconfig.ArgumentExceptionFactory.*;
import static org.opends.server.util.ServerConstants.PROPERTY_SCRIPT_NAME;
import static org.opends.server.util.StaticUtils.*;
import java.io.BufferedWriter;
@@ -46,6 +47,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -72,6 +74,7 @@
import org.opends.server.types.InitializationException;
import org.opends.server.util.EmbeddedUtils;
import org.opends.server.util.ServerConstants;
import org.opends.server.util.SetupUtils;
import org.opends.server.util.StaticUtils;
import org.opends.server.util.args.ArgumentException;
import org.opends.server.util.args.BooleanArgument;
@@ -293,6 +296,9 @@
  // This CLI is always using the administration connector with SSL
  private static final boolean alwaysSSL = true;
  private long sessionStartTime;
  private boolean sessionStartTimePrinted = false;
  private int sessionEquivalentOperationNumber = 0;
  /**
   * Provides the command-line arguments to the main application for
@@ -333,6 +339,7 @@
      OutputStream outStream, OutputStream errStream) {
    DSConfig app = new DSConfig(System.in, outStream, errStream,
        new LDAPManagementContextFactory(alwaysSSL));
    app.sessionStartTime = System.currentTimeMillis();
    // Only initialize the client environment when run as a standalone
    // application.
    if (initializeServer) {
@@ -412,10 +419,6 @@
  // properties file.
  private BooleanArgument noPropertiesFileArgument;
  // The boolean that is used to know if data must be appended to the file
  // containing equivalent non-interactive commands.
  private boolean alreadyWroteEquivalentCommand;
  /**
   * Creates a new dsconfig application instance.
   *
@@ -1137,15 +1140,32 @@
    }
    if (equivalentCommandFileArgument.isPresent())
    {
      // Write to the file.
      boolean append = alreadyWroteEquivalentCommand;
      String file = equivalentCommandFileArgument.getValue();
      try
      {
        BufferedWriter writer =
          new BufferedWriter(new FileWriter(file, append));
          new BufferedWriter(new FileWriter(file, true));
        if (!sessionStartTimePrinted)
        {
          writer.write(SHELL_COMMENT_SEPARATOR+getSessionStartTimeMessage());
          writer.newLine();
          sessionStartTimePrinted = true;
        }
        sessionEquivalentOperationNumber++;
        writer.newLine();
        writer.write(SHELL_COMMENT_SEPARATOR+
            INFO_DSCFG_EQUIVALENT_COMMAND_LINE_SESSION_OPERATION_NUMBER.get(
                sessionEquivalentOperationNumber));
        writer.newLine();
        writer.write(SHELL_COMMENT_SEPARATOR+getCurrentOperationDateMessage());
        writer.newLine();
        writer.write(commandBuilder.toString());
        writer.newLine();
        writer.newLine();
        writer.flush();
        writer.close();
@@ -1155,12 +1175,30 @@
        println(ERR_DSCFG_ERROR_WRITING_EQUIVALENT_COMMAND_LINE.get(file,
            ioe.toString()));
      }
      alreadyWroteEquivalentCommand = true;
    }
  }
  private void handleBatchFile(String[] args) {
  /**
   * Returns the message to be displayed in the file with the equivalent
   * command-line with information about when the session started.
   * @return  the message to be displayed in the file with the equivalent
   * command-line with information about when the session started.
   */
  private String getSessionStartTimeMessage()
  {
    String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME);
    if ((scriptName == null) || (scriptName.length() == 0))
    {
      scriptName = "dsconfig";
    }
    String date = formatDateTimeStringForEquivalentCommand(
        new Date(sessionStartTime));
    return INFO_DSCFG_SESSION_START_TIME_MESSAGE.get(scriptName, date).
    toString();
  }
  private void handleBatchFile(String[] args)
  {
      BufferedReader reader = null;
      try {
        // Build a list of initial arguments,
@@ -1226,5 +1264,4 @@
        println(ERR_DSCFG_ERROR_READING_BATCH_FILE.get(ex.toString()));
      }
  }
}
opendj-sdk/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
@@ -43,6 +43,9 @@
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.Reader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -63,6 +66,7 @@
import org.opends.server.tools.ClientException;
import org.opends.server.types.NullOutputStream;
import org.opends.server.util.PasswordReader;
import org.opends.server.util.SetupUtils;
/**
@@ -109,6 +113,16 @@
   */
  protected final static int CONFIRMATION_MAX_TRIES = 5;
  private static final String COMMENT_SHELL_UNIX = "# ";
  private static final String COMMENT_BATCH_WINDOWS = "rem ";
  /**
   * The String used to write comments in a shell (or batch) script.
   */
  protected static final String SHELL_COMMENT_SEPARATOR =
    SetupUtils.isWindows() ?
      COMMENT_BATCH_WINDOWS : COMMENT_SHELL_UNIX;
  /**
   * Creates a new console application instance.
   *
@@ -1011,4 +1025,36 @@
    }
    return ctx;
  }
  /**
   * Returns the message to be displayed in the file with the equivalent
   * command-line with information about the current time.
   * @return  the message to be displayed in the file with the equivalent
   * command-line with information about the current time.
   */
  protected String getCurrentOperationDateMessage()
  {
    String date = formatDateTimeStringForEquivalentCommand(new Date());
    return INFO_OPERATION_START_TIME_MESSAGE.get(date).
    toString();
  }
  /**
   * Formats a Date to String representation in "dd/MMM/yyyy:HH:mm:ss Z".
   *
   * @param date to format; null if <code>date</code> is null
   * @return string representation of the date
   */
  protected String formatDateTimeStringForEquivalentCommand(Date date)
  {
    String timeStr = null;
    if (date != null)
    {
      SimpleDateFormat dateFormat =
        new SimpleDateFormat(DATE_FORMAT_LOCAL_TIME);
      dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
      timeStr = dateFormat.format(date);
    }
    return timeStr;
  }
}