sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1518228 - in /sis/branches/JDK7: application/sis-console/src/main/java/org/apache/sis/console/ application/sis-console/src/test/java/org/apache/sis/console/ core/sis-utility/src/main/java/org/apache/sis/internal/system/ core/sis-utility/sr...
Date Wed, 28 Aug 2013 14:52:22 GMT
Author: desruisseaux
Date: Wed Aug 28 14:52:22 2013
New Revision: 1518228

URL: http://svn.apache.org/r1518228
Log:
Added capability to provide information about a SIS installation on a remote machine
(only if explicitely enabled at remote JVM startup time).

Modified:
    sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/AboutSC.java
    sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java
    sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/package-info.java
    sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/AboutSCTest.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties

Modified: sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/AboutSC.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/AboutSC.java?rev=1518228&r1=1518227&r2=1518228&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/AboutSC.java
[UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/AboutSC.java
[UTF-8] Wed Aug 28 14:52:22 2013
@@ -17,9 +17,20 @@
 package org.apache.sis.console;
 
 import java.util.EnumSet;
+import java.io.IOException;
+import java.rmi.registry.Registry;
+import javax.management.JMX;
+import javax.management.ObjectName;
+import javax.management.MBeanServerConnection;
+import javax.management.remote.JMXServiceURL;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
 import org.apache.sis.setup.About;
 import org.apache.sis.util.Version;
+import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.resources.Vocabulary;
+import org.apache.sis.internal.system.Supervisor;
+import org.apache.sis.internal.system.SupervisorMBean;
 
 
 /**
@@ -32,9 +43,14 @@ import org.apache.sis.util.resources.Voc
  *   <li>{@code --verbose}: prints all information including the libraries.</li>
  * </ul>
  *
+ * {@section About SIS installation on a remote machine}
+ * This sub-command can provide information about SIS installation on a remote machine,
+ * provided that remote access has been enabled at the Java Virtual Machine startup time.
+ * See {@link org.apache.sis.console} package javadoc for more information.
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.4
  * @module
  */
 final class AboutSC extends SubCommand {
@@ -50,23 +66,67 @@ final class AboutSC extends SubCommand {
      * Prints the information to the output stream.
      */
     @Override
-    public int run() {
-        if (hasUnexpectedFileCount(0, 0)) {
+    public int run() throws Exception {
+        /*
+         * Check the number of arguments, which can be 0 or 1. If present,
+         * the argument is the name and port number of a remote machine.
+         *
+         * In the current implementation, the --brief option is supported only on the local
machine.
+         */
+        final boolean brief = options.containsKey(Option.BRIEF);
+        if (hasUnexpectedFileCount(0, brief ? 0 : 1)) {
             return Command.INVALID_ARGUMENT_EXIT_CODE;
         }
         final String configuration;
-        if (options.containsKey(Option.BRIEF)) {
+        if (brief) {
             configuration = Vocabulary.getResources(locale).getString(
                     Vocabulary.Keys.Version_2, "Apache SIS", Version.SIS);
         } else {
-            final EnumSet<About> sections = EnumSet.allOf(About.class);
-            if (!options.containsKey(Option.VERBOSE)) {
-                sections.remove(About.LIBRARIES);
+            if (files.isEmpty()) {
+                /*
+                 * Provide information about the local SIS installation.
+                 */
+                final EnumSet<About> sections = EnumSet.allOf(About.class);
+                if (!options.containsKey(Option.VERBOSE)) {
+                    sections.remove(About.LIBRARIES);
+                }
+                configuration = About.configuration(sections, locale, timezone).toString();
+            } else {
+                /*
+                 * Provide information about a remote SIS installation. Those information
are accessible
+                 * only if explicitely enabled at JVM startup time.
+                 *
+                 * Tutorial: http://docs.oracle.com/javase/tutorial/jmx/remote/custom.html
+                 */
+                final String path = toRemoveURL(files.get(0));
+                try {
+                    final JMXServiceURL url = new JMXServiceURL(path);
+                    try (JMXConnector jmxc = JMXConnectorFactory.connect(url)) {
+                        final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
+                        final SupervisorMBean bean = JMX.newMBeanProxy(mbsc, new ObjectName(Supervisor.NAME),
SupervisorMBean.class);
+                        configuration = bean.configuration().toString();
+                    }
+                } catch (IOException e) {
+                    error(Errors.format(Errors.Keys.CanNotConnectTo_1, path), e);
+                    return Command.IO_EXCEPTION_EXIT_CODE;
+                }
             }
-            configuration = About.configuration(sections, locale, timezone).toString();
         }
         out.println(configuration);
         out.flush();
         return 0;
     }
+
+    /**
+     * Creates a {@code "service:jmx:rmi:///jndi/rmi://host:port/jmxrmi"} URL for the given
host name.
+     * The host name can optionally be followed by a port number.
+     */
+    static String toRemoveURL(final String host) {
+        final StringBuilder buffer = new StringBuilder(60).append("service:jmx:rmi:///jndi/rmi://")
+                .append(host, host.regionMatches(true, 0, "localhost", 0, 9) ? 9 : 0, host.length());
+        if (host.lastIndexOf(':') < 0) {
+            buffer.append(':').append(Registry.REGISTRY_PORT);
+        }
+        return buffer.append("/jmxrmi").toString();
+    }
 }

Modified: sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java?rev=1518228&r1=1518227&r2=1518228&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java
[UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java
[UTF-8] Wed Aug 28 14:52:22 2013
@@ -56,9 +56,13 @@ import org.apache.sis.util.logging.Monol
  * to the {@linkplain System#err standard error stream}. The reason is that command output
may be targeted to
  * a client, while the error messages are usually for the operator.
  *
+ * {@section SIS installation on remote machines}
+ * Some sub-commands can operate on SIS installation on remote machines, provided that remote
access has been enabled
+ * at the Java Virtual Machine startup time. See {@link org.apache.sis.console} package javadoc
for more information.
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.4
  * @module
  */
 public final class Command {

Modified: sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/package-info.java?rev=1518228&r1=1518227&r2=1518228&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/package-info.java
[UTF-8] Wed Aug 28 14:52:22 2013
@@ -17,10 +17,37 @@
 
 /**
  * Command line interface for Apache SIS.
+ * See {@link org.apache.sis.console.Command} for the list of supported commands.
+ *
+ * {@section SIS installation on remote machines}
+ * Some sub-commands can operate on SIS installation on remote machines, provided
+ * that the remote Java Virtual Machine has been started with the following options:
+ *
+ * {@preformat shell
+ *   java -Dcom.sun.management.jmxremote.port=1099 \
+ *        -Dcom.sun.management.jmxremote.authenticate=false \
+ *        -Dcom.sun.management.jmxremote.ssl=false \
+ *        -Dcom.sun.management.jmxremote.local.only=true \
+ *        <other options>
+ * }
+ *
+ * If the port number is different than {@value java.rmi.registry.Registry#REGISTRY_PORT},
then it must be specified
+ * to the {@code sis} subcommand after the host name. For example if the port number has
been set to 9999, then the
+ * {@code about} sub-command shall be invoked as below:
+ *
+ * {@preformat shell
+ *   java org.apache.sis.console.Command about localhost:9999
+ * }
+ *
+ * The {@code com.sun.management.jmxremote.local.only} property is recommended if the remote
JVM is an other
+ * JVM instance running on the local machine. Otherwise this property can be omitted for
debugging purpose.
+ * For production environment, see the security settings documented on the
+ * <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/management/agent.html">Monitoring
+ * and Management Using JMX Technology</a> page.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.4
  * @module
  */
 package org.apache.sis.console;

Modified: sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/AboutSCTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/AboutSCTest.java?rev=1518228&r1=1518227&r2=1518228&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/AboutSCTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/AboutSCTest.java
[UTF-8] Wed Aug 28 14:52:22 2013
@@ -31,7 +31,7 @@ import static org.apache.sis.test.TestUt
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.4
  * @module
  */
 @DependsOn(SubCommandTest.class)
@@ -39,10 +39,10 @@ public final strictfp class AboutSCTest 
     /**
      * Tests the sub-command without option.
      *
-     * @throws InvalidOptionException Should never happen.
+     * @throws Exception Should never happen.
      */
     @Test
-    public void testDefault() throws InvalidOptionException {
+    public void testDefault() throws Exception {
         final AboutSC test = new AboutSC(0, SubCommand.TEST);
         test.run();
         verify(test.outputBuffer.toString());
@@ -68,10 +68,10 @@ public final strictfp class AboutSCTest 
     /**
      * Tests the sub-command with the {@code --brief} option.
      *
-     * @throws InvalidOptionException Should never happen.
+     * @throws Exception Should never happen.
      */
     @Test
-    public void testBrief() throws InvalidOptionException {
+    public void testBrief() throws Exception {
         final AboutSC test = new AboutSC(0, SubCommand.TEST, "--brief");
         test.run();
         final String result = getSingleton(CharSequences.splitOnEOL(test.outputBuffer.toString().trim())).toString();
@@ -81,10 +81,10 @@ public final strictfp class AboutSCTest 
     /**
      * Tests the sub-command with the {@code --verbose} option.
      *
-     * @throws InvalidOptionException Should never happen.
+     * @throws Exception Should never happen.
      */
     @Test
-    public void testVerbose() throws InvalidOptionException {
+    public void testVerbose() throws Exception {
         final AboutSC test = new AboutSC(0, SubCommand.TEST, "--verbose");
         test.run();
         final String result = test.outputBuffer.toString();
@@ -93,4 +93,17 @@ public final strictfp class AboutSCTest 
         // Check for a dependency which should be present.
         assertTrue("geoapi", result.contains("geoapi"));
     }
+
+    /**
+     * Tests the {@link AboutSC#toRemoveURL(String)} method.
+     */
+    @Test
+    public void testToRemoveURL() {
+        assertEquals("service:jmx:rmi:///jndi/rmi://myhost:9999/jmxrmi",    AboutSC.toRemoveURL("myhost:9999"));
+        assertEquals("service:jmx:rmi:///jndi/rmi://myhost:1099/jmxrmi",    AboutSC.toRemoveURL("myhost"));
+        assertEquals("service:jmx:rmi:///jndi/rmi://:9999/jmxrmi",          AboutSC.toRemoveURL("localhost:9999"));
+        assertEquals("service:jmx:rmi:///jndi/rmi://:1099/jmxrmi",          AboutSC.toRemoveURL("localhost"));
+        assertEquals("service:jmx:rmi:///jndi/rmi://:9999/jmxrmi",          AboutSC.toRemoveURL(":9999"));
+        assertEquals("service:jmx:rmi:///jndi/rmi://localhosx:1099/jmxrmi", AboutSC.toRemoveURL("localhosx"));
+    }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java?rev=1518228&r1=1518227&r2=1518228&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java
[UTF-8] Wed Aug 28 14:52:22 2013
@@ -49,7 +49,7 @@ import org.apache.sis.util.collection.Tr
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.4
  * @module
  */
 public final class Supervisor extends StandardMBean implements SupervisorMBean, Localized
{
@@ -60,6 +60,11 @@ public final class Supervisor extends St
     static final boolean ENABLED = true;
 
     /**
+     * The JMX object name for the {@code Supervisor} service.
+     */
+    public static final String NAME = "org.apache.sis:type=Supervisor";
+
+    /**
      * The JMX object name, created when the {@link #register()} is first invoked.
      * {@link ObjectName#WILDCARD} is used as a sentinel value if the registration failed.
      */
@@ -79,7 +84,7 @@ public final class Supervisor extends St
             name = ObjectName.WILDCARD; // In case of failure.
             final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
             try {
-                final ObjectName n = new ObjectName("org.apache.sis:type=Supervisor");
+                final ObjectName n = new ObjectName(NAME);
                 server.registerMBean(new Supervisor(null, null), n);
                 name = n; // Store only on success.
             } catch (SecurityException | JMException e) {

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1518228&r1=1518227&r2=1518228&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Wed Aug 28 14:52:22 2013
@@ -74,6 +74,11 @@ public final class Errors extends Indexe
         public static final int CanNotComputeDerivative = 44;
 
         /**
+         * Can not connect to “{0}”.
+         */
+        public static final int CanNotConnectTo_1 = 114;
+
+        /**
          * Can not convert from type ‘{0}’ to type ‘{1}’.
          */
         public static final int CanNotConvertFromType_2 = 72;

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1518228&r1=1518227&r2=1518228&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Wed Aug 28 14:52:22 2013
@@ -25,6 +25,7 @@
 # can reorder the parameters as they want.
 #
 CanNotAddToExclusiveSet_2       = No element can be added to this set because properties
\u2018{0}\u2019 and \u2018{1}\u2019 are mutually exclusive.
+CanNotConnectTo_1               = Can not connect to \u201c{0}\u201d.
 CanNotConvertFromType_2         = Can not convert from type \u2018{0}\u2019 to type \u2018{1}\u2019.
 CanNotConvertValue_2            = Can not convert value \u201c{0}\u201d to type \u2018{1}\u2019.
 CanNotComputeDerivative         = Can not compute the derivative.

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1518228&r1=1518227&r2=1518228&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Wed Aug 28 14:52:22 2013
@@ -15,6 +15,7 @@
 # limitations under the License.
 #
 CanNotAddToExclusiveSet_2       = Aucun \u00e9l\u00e9ment ne peut \u00eatre ajout\u00e9 \u00e0
cet ensemble car les propri\u00e9t\u00e9s \u2018{0}\u2019 et \u2018{1}\u2019 sont mutuellement
exclusives.
+CanNotConnectTo_1               = Ne peut pas se connecter \u00e0 \u201c{0}\u201d.
 CanNotConvertFromType_2         = Ne peut pas convertir du type \u2018{0}\u2019 vers le type
\u2018{1}\u2019.
 CanNotConvertValue_2            = La valeur \u201c{0}\u201d ne peut pas \u00eatre convertie
vers le type \u2018{1}\u2019.
 CanNotComputeDerivative         = La d\u00e9riv\u00e9 ne peut pas \u00eatre calcul\u00e9e.



Mime
View raw message