From cd7ddcc30ed1b2cedf327e3c45185f815bf7ca29 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 02 Mar 2007 17:04:03 +0000
Subject: [PATCH] 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.

---
 opends/src/server/org/opends/server/tools/ConfigureDS.java |   41 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/ConfigureDS.java b/opends/src/server/org/opends/server/tools/ConfigureDS.java
index b262629..00f6122 100644
--- a/opends/src/server/org/opends/server/tools/ConfigureDS.java
+++ b/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.

--
Gitblit v1.10.0