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

jvergara
02.04.2007 cd7ddcc30ed1b2cedf327e3c45185f815bf7ca29
Allow the user to specify the JMX port using *j* option during the cli installation and using configure script.
In the QuickSetup I added some code to *temporarily* select a port that is not being used for JMX. Today we do not inform the user of the existence of this port so this approach does not make things much worse and reduces the changes of port conflicts in general. Even in the case where we are not installing multiple instances of OpenDS the port 1689 might be in use by another process.
7 files modified
226 ■■■■■ changed files
opends/src/quicksetup/org/opends/quicksetup/QuickSetup.java 29 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java 2 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/installer/UserInstallData.java 20 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/messages/ToolMessages.java 39 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/ConfigureDS.java 41 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/InstallDS.java 86 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/SetupUtils.java 9 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/QuickSetup.java
@@ -64,6 +64,7 @@
import org.opends.quicksetup.util.BackgroundTask;
import org.opends.quicksetup.util.ProgressMessageFormatter;
import org.opends.quicksetup.util.Utils;
import org.opends.server.util.SetupUtils;
/**
 * This class is responsible for doing the following:
@@ -873,6 +874,12 @@
      displayFieldInvalid(FieldName.DIRECTORY_MANAGER_PWD_CONFIRM, false);
    }
    int defaultJMXPort = getDefaultJMXPort();
    if (defaultJMXPort != -1)
    {
      getUserInstallData().setServerJMXPort(defaultJMXPort);
    }
    if (errorMsgs.size() > 0)
    {
      throw new UserInstallDataException(Step.SERVER_SETTINGS,
@@ -1168,6 +1175,7 @@
    {
      defaultUserData.setServerPort(defaultPort);
    }
    defaultUserData.setDirectoryManagerDn("cn=Directory Manager");
    defaultUserData.setDataOptions(defaultDataOptions);
@@ -1471,6 +1479,27 @@
  }
  /**
   * Provides the port that will be used by default for JMX.
   *
   * @return the port X689 if it is available and we can use and -1 if not.
   */
  private int getDefaultJMXPort()
  {
    int defaultJMXPort = -1;
    for (int i=0;i<65000 && (defaultJMXPort == -1);i+=1000)
    {
      int port = i + SetupUtils.getDefaultJMXPort();
      if (Utils.canUseAsPort(port))
      {
        defaultJMXPort = port;
      }
    }
    return defaultJMXPort;
  }
  /**
   * Returns the number of free disk space in bytes required to install Open DS
   *
   * For the moment we just return 15 Megabytes. TODO we might want to have
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -677,6 +677,8 @@
    argList.add(getConfigFilePath());
    argList.add("-p");
    argList.add(String.valueOf(getUserData().getServerPort()));
    argList.add("-j");
    argList.add(String.valueOf(getUserData().getServerJMXPort()));
    argList.add("-D");
    argList.add(getUserData().getDirectoryManagerDn());
opends/src/quicksetup/org/opends/quicksetup/installer/UserInstallData.java
@@ -40,6 +40,8 @@
  private int serverPort;
  private int serverJMXPort;
  private String directoryManagerDn;
  private String directoryManagerPwd;
@@ -85,6 +87,24 @@
  }
  /**
   * Sets the server JMX port.
   * @param serverJMXPort the new server JMX port.
   */
  public void setServerJMXPort(int serverJMXPort)
  {
    this.serverJMXPort = serverJMXPort;
  }
  /**
   * Returns the server JMX port.
   * @return the server JMX port.
   */
  public int getServerJMXPort()
  {
    return serverJMXPort;
  }
  /**
   * Returns the Directory Manager DN.
   * @return the Directory Manager DN.
   */
opends/src/server/org/opends/server/messages/ToolMessages.java
@@ -7664,7 +7664,34 @@
  public static final int MSGID_DESCRIPTION_CERT_NICKNAME =
       CATEGORY_MASK_TOOLS | SEVERITY_MASK_INFORMATIONAL | 805;
  /**
   * The message ID for the message that will be used as the description of the
   * jmxPort argument.  This does not take any arguments.
   */
  public static final int MSGID_CONFIGDS_DESCRIPTION_JMX_PORT =
       CATEGORY_MASK_TOOLS | SEVERITY_MASK_INFORMATIONAL | 806;
  /**
   * The message ID for the message that will be used if an error occurs while
   * attempting to update the JMX port.  This takes a single argument, which is
   * a message explaining the problem that occurred.
   */
  public static final int MSGID_CONFIGDS_CANNOT_UPDATE_JMX_PORT =
       CATEGORY_MASK_TOOLS | SEVERITY_MASK_SEVERE_ERROR | 807;
  /**
   * The message ID for the message that will be used as the description for the
   * jmxPort argument.  This does not take any arguments.
   */
  public static final int MSGID_INSTALLDS_DESCRIPTION_JMXPORT =
       CATEGORY_MASK_TOOLS | SEVERITY_MASK_INFORMATIONAL | 808;
  /**
   * The message ID for the message that will be used as the prompt to determine
   * the JMX port number to use.  It does not take any arguments.
   */
  public static final int MSGID_INSTALLDS_PROMPT_JMXPORT =
       CATEGORY_MASK_TOOLS | SEVERITY_MASK_INFORMATIONAL | 809;
  /**
   * Associates a set of generic messages with the message IDs defined in this
@@ -9125,6 +9152,9 @@
    registerMessage(MSGID_CONFIGDS_DESCRIPTION_LDAP_PORT,
                    "Specifies the port on which the Directory Server should " +
                    "listen for LDAP communication.");
    registerMessage(MSGID_CONFIGDS_DESCRIPTION_JMX_PORT,
                    "Specifies the port on which the Directory Server should " +
                    "listen for JMX communication.");
    registerMessage(MSGID_CONFIGDS_DESCRIPTION_BASE_DN,
                    "Specifies the base DN for user information in the " +
                    "Directory Server.  Multiple base DNs may be provided " +
@@ -9178,6 +9208,9 @@
    registerMessage(MSGID_CONFIGDS_CANNOT_UPDATE_LDAP_PORT,
                    "An error occurred while attempting to update the port " +
                    "on which to listen for LDAP communication:  %s.");
    registerMessage(MSGID_CONFIGDS_CANNOT_UPDATE_JMX_PORT,
                    "An error occurred while attempting to update the port " +
                    "on which to listen for JMX communication:  %s.");
    registerMessage(MSGID_CONFIGDS_CANNOT_UPDATE_ROOT_USER,
                    "An error occurred while attempting to update the entry " +
                    "for the initial Directory Server root user:  %s.");
@@ -9224,6 +9257,9 @@
    registerMessage(MSGID_INSTALLDS_DESCRIPTION_LDAPPORT,
                    "Specifies the port on which the Directory Server should " +
                    "listen for LDAP communication.");
    registerMessage(MSGID_INSTALLDS_DESCRIPTION_JMXPORT,
                    "Specifies the port on which the Directory Server should " +
                    "listen for JMX communication.");
    registerMessage(MSGID_INSTALLDS_DESCRIPTION_SKIPPORT,
                    "Skip the check to determine whether the specified LDAP " +
                    "port is usable.");
@@ -9275,6 +9311,9 @@
    registerMessage(MSGID_INSTALLDS_PROMPT_LDAPPORT,
                    "On which port would you like the Directory Server to " +
                    "accept connections from LDAP clients?");
    registerMessage(MSGID_INSTALLDS_PROMPT_JMXPORT,
                    "On which port would you like the Directory Server to " +
                    "accept connections from JMX clients?");
    registerMessage(MSGID_INSTALLDS_CANNOT_BIND_TO_PRIVILEGED_PORT,
                    "ERROR:  Unable to bind to port %d.  This port may " +
                    "already be in use, or you may not have permission to " +
opends/src/server/org/opends/server/tools/ConfigureDS.java
@@ -42,6 +42,7 @@
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.DN;
import org.opends.server.util.SetupUtils;
import org.opends.server.util.args.ArgumentException;
import org.opends.server.util.args.ArgumentParser;
import org.opends.server.util.args.BooleanArgument;
@@ -99,6 +100,12 @@
       "cn=LDAP Connection Handler," + DN_CONNHANDLER_BASE;
  /**
   * The DN of the configuration entry defining the JMX connection handler.
   */
  private static final String DN_JMX_CONNECTION_HANDLER =
       "cn=JMX Connection Handler," + DN_CONNHANDLER_BASE;
  /**
   * The DN of the configuration entry defining the initial root user.
@@ -140,6 +147,7 @@
    BooleanArgument   showUsage;
    FileBasedArgument rootPasswordFile;
    IntegerArgument   ldapPort;
    IntegerArgument   jmxPort;
    StringArgument    baseDNString;
    StringArgument    configClass;
    StringArgument    configFile;
@@ -171,6 +179,12 @@
                                     MSGID_CONFIGDS_DESCRIPTION_LDAP_PORT);
      argParser.addArgument(ldapPort);
      jmxPort = new IntegerArgument("jmxport", 'j', "jmxPort", false, false,
          true, "{jmxPort}", SetupUtils.getDefaultJMXPort(), null, true, 1,
          true, 65535,
          MSGID_CONFIGDS_DESCRIPTION_JMX_PORT);
      argParser.addArgument(jmxPort);
      baseDNString = new StringArgument("basedn", 'b', "baseDN", false, true,
                                        true, "{baseDN}", "dc=example,dc=com",
                                        null,
@@ -233,7 +247,7 @@
    // Make sure that the user actually tried to configure something.
    if (! (baseDNString.isPresent() || ldapPort.isPresent() ||
           rootDNString.isPresent()))
        jmxPort.isPresent() || rootDNString.isPresent()))
    {
      int    msgID   = MSGID_CONFIGDS_NO_CONFIG_CHANGES;
      String message = getMessage(msgID);
@@ -426,6 +440,31 @@
        }
      }
//    If an JMX port was specified, then update the config accordingly.
      if (jmxPort.isPresent())
      {
        try
        {
          DN jmxListenerDN = DN.decode(DN_JMX_CONNECTION_HANDLER);
          ConfigEntry configEntry =
               configHandler.getConfigEntry(jmxListenerDN);
          int msgID = MSGID_JMX_CONNHANDLER_DESCRIPTION_LISTEN_PORT;
          IntegerConfigAttribute portAttr =
               new IntegerConfigAttribute(ATTR_LISTEN_PORT, getMessage(msgID),
                                          true, false, true, true, 1, true,
                                          65535, jmxPort.getIntValue());
          configEntry.putConfigAttribute(portAttr);
        }
        catch (Exception e)
        {
          int    msgID   = MSGID_CONFIGDS_CANNOT_UPDATE_JMX_PORT;
          String message = getMessage(msgID, String.valueOf(e));
          System.err.println(wrapText(message, MAX_LINE_WIDTH));
          return 1;
        }
      }
      // If a root user DN and password were specified, then update the config
      // accordingly.
opends/src/server/org/opends/server/tools/InstallDS.java
@@ -179,6 +179,7 @@
    BooleanArgument   skipPortCheck;
    FileBasedArgument rootPWFile;
    IntegerArgument   ldapPort;
    IntegerArgument   jmxPort;
    IntegerArgument   sampleData;
    StringArgument    baseDN;
    StringArgument    configClass;
@@ -250,6 +251,13 @@
                                     MSGID_INSTALLDS_DESCRIPTION_LDAPPORT);
      argParser.addArgument(ldapPort);
      jmxPort = new IntegerArgument("jmxport", 'j', "jmxPort", false, false,
                                    true, "{port}",
                                    SetupUtils.getDefaultJMXPort(), null, true,
                                    1, true, 65535,
                                    MSGID_INSTALLDS_DESCRIPTION_JMXPORT);
      argParser.addArgument(jmxPort);
      skipPortCheck = new BooleanArgument("skipportcheck", 'S', "skipPortCheck",
                                          MSGID_INSTALLDS_DESCRIPTION_SKIPPORT);
      argParser.addArgument(skipPortCheck);
@@ -489,6 +497,82 @@
      }
    }
//  Determine the JMX port number.
    int jmxPortNumber;
    if (silentInstall.isPresent() || jmxPort.isPresent())
    {
      try
      {
        jmxPortNumber = jmxPort.getIntValue();
        if (! skipPortCheck.isPresent())
        {
          // Check if the port can be used.
          if (!SetupUtils.canUseAsPort(jmxPortNumber))
          {
            int msgID;
            String message;
            if (SetupUtils.isPriviledgedPort(jmxPortNumber))
            {
              msgID   = MSGID_INSTALLDS_CANNOT_BIND_TO_PRIVILEGED_PORT;
              message = getMessage(msgID, jmxPortNumber);
              System.err.println(wrapText(message, MAX_LINE_WIDTH));
            }
            else
            {
              msgID   = MSGID_INSTALLDS_CANNOT_BIND_TO_PORT;
              message = getMessage(msgID, jmxPortNumber);
              System.err.println(wrapText(message, MAX_LINE_WIDTH));
            }
            return 1;
          }
        }
      }
      catch (ArgumentException ae)
      {
        System.err.println(wrapText(ae.getMessage(), MAX_LINE_WIDTH));
        return 1;
      }
    }
    else
    {
      while (true)
      {
        int    msgID   = MSGID_INSTALLDS_PROMPT_JMXPORT;
        String message = getMessage(msgID);
        jmxPortNumber = promptForInteger(message,
            SetupUtils.getDefaultJMXPort(), 1, 65535);
        if (skipPortCheck.isPresent())
        {
            break;
        }
        else
        {
          // Check if the port can be used.
          if (SetupUtils.canUseAsPort(jmxPortNumber))
          {
              break;
          }
          else
          {
            if (SetupUtils.isPriviledgedPort(jmxPortNumber))
            {
              msgID   = MSGID_INSTALLDS_CANNOT_BIND_TO_PRIVILEGED_PORT;
              message = getMessage(msgID, jmxPortNumber);
              System.err.println(wrapText(message, MAX_LINE_WIDTH));
            }
            else
            {
              msgID   = MSGID_INSTALLDS_CANNOT_BIND_TO_PORT;
              message = getMessage(msgID, jmxPortNumber);
              System.err.println(wrapText(message, MAX_LINE_WIDTH));
            }
          }
        }
      }
    }
    // Determine the initial root user DN.
    LinkedList<DN> rootDNs;
@@ -716,6 +800,8 @@
    argList.add(configFileName);
    argList.add("-p");
    argList.add(String.valueOf(ldapPortNumber));
    argList.add("-j");
    argList.add(String.valueOf(jmxPortNumber));
    for (DN dn : baseDNs)
    {
opends/src/server/org/opends/server/util/SetupUtils.java
@@ -301,5 +301,14 @@
  {
    return (port <= 1024) && !isWindows();
  }
  /**
   * Returns the default value for the JMX Port.
   * @return the default value for the JMX Port.
   */
  public static int getDefaultJMXPort()
  {
    return 1689;
  }
}