cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1054137 - in /cassandra/branches/cassandra-0.7: CHANGES.txt src/java/org/apache/cassandra/tools/NodeCmd.java src/java/org/apache/cassandra/tools/NodeProbe.java
Date Fri, 31 Dec 2010 17:22:04 GMT
Author: jbellis
Date: Fri Dec 31 17:22:04 2010
New Revision: 1054137

URL: http://svn.apache.org/viewvc?rev=1054137&view=rev
Log:
add RMI authentication options to nodetool
patch by mck; reviewed by jbellis for CASSANDRA-1921

Modified:
    cassandra/branches/cassandra-0.7/CHANGES.txt
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/tools/NodeCmd.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/tools/NodeProbe.java

Modified: cassandra/branches/cassandra-0.7/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/CHANGES.txt?rev=1054137&r1=1054136&r2=1054137&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.7/CHANGES.txt Fri Dec 31 17:22:04 2010
@@ -4,6 +4,7 @@ dev
  * upgrade to TFastFramedTransport (CASSANDRA-1743)
  * avoid polluting page cache with commitlog or sstable writes
    and seq scan operations (CASSANDRA-1470)
+ * add RMI authentication options to nodetool (CASSANDRA-1921)
 
 
 0.7.0-rc4

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/tools/NodeCmd.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/tools/NodeCmd.java?rev=1054137&r1=1054136&r2=1054137&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/tools/NodeCmd.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/tools/NodeCmd.java Fri
Dec 31 17:22:04 2010
@@ -45,6 +45,10 @@ public class NodeCmd {
     private static final String HOST_OPT_SHORT = "h";
     private static final String PORT_OPT_LONG = "port";
     private static final String PORT_OPT_SHORT = "p";
+    private static final String USERNAME_OPT_LONG = "username";
+    private static final String USERNAME_OPT_SHORT = "u";
+    private static final String PASSWORD_OPT_LONG = "password";
+    private static final String PASSWORD_OPT_SHORT = "pw";
     private static final int defaultPort = 8080;
     private static Options options = null;
     
@@ -57,6 +61,8 @@ public class NodeCmd {
         optHost.setRequired(true);
         options.addOption(optHost);
         options.addOption(PORT_OPT_SHORT, PORT_OPT_LONG, true, "remote jmx agent port number");
+        options.addOption(USERNAME_OPT_SHORT, USERNAME_OPT_LONG, true, "remote jmx agent
username");
+        options.addOption(PASSWORD_OPT_SHORT, PASSWORD_OPT_LONG, true, "remote jmx agent
password");
     }
     
     public NodeCmd(NodeProbe probe)
@@ -469,11 +475,13 @@ public class NodeCmd {
                 throw new ParseException("Port must be a number");
             }
         }
+        String username = cmd.getOptionValue(USERNAME_OPT_LONG);
+        String password = cmd.getOptionValue(PASSWORD_OPT_LONG);
         
         NodeProbe probe = null;
         try
         {
-            probe = new NodeProbe(host, port);
+            probe = username == null ? new NodeProbe(host, port) : new NodeProbe(host, port,
username, password);
         }
         catch (IOException ioe)
         {

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/tools/NodeProbe.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/tools/NodeProbe.java?rev=1054137&r1=1054136&r2=1054137&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/tools/NodeProbe.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/tools/NodeProbe.java Fri
Dec 31 17:22:04 2010
@@ -63,6 +63,8 @@ public class NodeProbe
     private static final int defaultPort = 8080;
     final String host;
     final int port;
+    private String username;
+    private String password;
 
     private JMXConnector jmxc;
     private MBeanServerConnection mbeanServerConn;
@@ -73,6 +75,25 @@ public class NodeProbe
     private StreamingServiceMBean streamProxy;
     
     /**
+     * Creates a NodeProbe using the specified JMX host, port, username, and password.
+     *
+     * @param host hostname or IP address of the JMX agent
+     * @param port TCP port of the remote JMX agent
+     * @throws IOException on connection failures
+     */
+    public NodeProbe(String host, int port, String username, String password) throws IOException,
InterruptedException
+    {
+        assert username != null && !username.isEmpty() && null != password
&& !password.isEmpty()
+               : "neither username nor password can be blank";
+
+        this.host = host;
+        this.port = port;
+        this.username = username;
+        this.password = password;
+        connect();
+    }
+
+    /**
      * Creates a NodeProbe using the specified JMX host and port.
      * 
      * @param host hostname or IP address of the JMX agent
@@ -107,7 +128,13 @@ public class NodeProbe
     private void connect() throws IOException
     {
         JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port));
-        jmxc = JMXConnectorFactory.connect(jmxUrl, null);
+        Map<String,Object> env = new HashMap<String,Object>();
+        if (username != null)
+        {
+            String[] creds = { username, password };
+            env.put(JMXConnector.CREDENTIALS, creds);
+        }
+        jmxc = JMXConnectorFactory.connect(jmxUrl, env);
         mbeanServerConn = jmxc.getMBeanServerConnection();
         
         try



Mime
View raw message