From 882aedfbfee45fd3b3f7c60089de3c037ba8b1ee 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.

---
 opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java |   86 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 86 insertions(+), 0 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java b/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java
index 6efc4df..5357c97 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java
+++ b/opendj-sdk/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)
     {

--
Gitblit v1.10.0