[jboss-svn-commits] JBL Code SVN: r17960 - in labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator: scripts and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jan 18 12:43:19 EST 2008


Author: tcunning
Date: 2008-01-18 12:43:18 -0500 (Fri, 18 Jan 2008)
New Revision: 17960

Added:
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/src/org/jboss/soa/esb/samples/quickstart/jmx/
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/src/org/jboss/soa/esb/samples/quickstart/jmx/JMXAttributeFinder.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/src/org/jboss/soa/esb/samples/quickstart/jmx/LGCallbackHandler.java
Modified:
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/build.xml
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/readme.txt
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/scripts/LoadReport.groovy
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/scripts/LoadUtil.groovy
Log:
bug:JBESB-1473
Add a "runtest-secure" option, which will login before querying MBeans.


Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/build.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/build.xml	2008-01-18 17:08:45 UTC (rev 17959)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/build.xml	2008-01-18 17:43:18 UTC (rev 17960)
@@ -8,8 +8,13 @@
 	<!-- Import the base Ant build script... -->
 	<import file="../conf/base-build.xml" />
 
+	<target name="quickstart-specific-clean">
+		<delete dir="load_generator_classes"/>
+	</target>
+
 	<target name="init-groovy" depends="dependencies">
 		<path id="groovy.classpath">
+			<pathelement path="build/classes"/>
 			<fileset dir="${org.jboss.esb.server.home}/server/${org.jboss.esb.server.config}/deploy">
 				<include name="jboss-aop-jdk50**/*.jar"/>
 			</fileset>
@@ -43,15 +48,30 @@
 	</target>
 
 	<target name="load-report" depends="compile-churn" description="Test the report agent script/settings">
-		<java classname="LoadReport">
-			<classpath refid="groovy.classpath" />
-			<classpath location="load_generator_classes" />
-			<arg value="load_generator_classes/load.xml" />
+		<java classname="LoadReport" fork="true">
+			<classpath location="${org.jboss.esb.server.home}/client"/>
+			<classpath location="build/classes"/>
+			<classpath refid="groovy.classpath"/>
+			<classpath location="load_generator_classes"/>
+			<arg value="load_generator_classes/load.xml"/>
 		</java>
 	</target>
 
+        <target name="load-report-secure" depends="compile-churn" description="Test the report agent script/settings">
+                <java classname="LoadReport" fork="true">
+                        <classpath location="${org.jboss.esb.server.home}/client"/>
+                        <classpath location="build/classes"/>
+                        <classpath refid="groovy.classpath"/>
+                        <classpath location="load_generator_classes"/>
+                        <arg line="load_generator_classes/load.xml admin admin"/>
+                </java>
+        </target>
+
 	<target name="runtest" depends="compile-churn,load-agent,load-report" description="Run the agent in background thread and report script in console">
 		
 	</target>
 
+	<target name="runtest-secure" depends="compile-churn,load-agent,load-report-secure" description="Run the agent in background thread and report script in console">
+	</target>
+
 </project>

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/readme.txt
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/readme.txt	2008-01-18 17:08:45 UTC (rev 17959)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/readme.txt	2008-01-18 17:43:18 UTC (rev 17960)
@@ -9,13 +9,18 @@
   Please refer to 'ant help-quickstarts' for prerequisites about the quickstarts
   and a more detailed descripton of the different ways to run the quickstarts.
 
+Protected JMX 
+=======================
+  If access to JMX is secured on your server, run the "ant runtest-secure" target, 
+  which takes a username and a password.
+
 To Run standalone mode:
 =======================
   1. In a command terminal window in the quickstart folder type
      'ant deploy-jms-dests'.
   2. In a command terminal window in this folder ("Window1"), type 'ant run'.
   3. Open another command terminal window in this folder ("Window2"), type
-     'ant runtest'.
+     'ant runtest' or 'ant runtest-secure'.
   4. Switch back to "Window1" to see the output from the ESB
   5. When finished, interrupt the ESB using Ctrl-C and, in this folder
      ("Window1"), type 'ant undeploy-jms-dests'.
@@ -24,13 +29,14 @@
 ===========================
   1. In a command terminal window in this folder ("Window1"), type 'ant deploy-jms-dests' and then 'ant deploy'.
   2. Open another command terminal window in this folder ("Window2"), type
-     'ant runtest'.
+     'ant runtest' or 'ant runtest-secure'.
   3. Switch back to Application Server console to see the output from the ESB
   4. In this folder ("Window1"), type 'ant undeploy' and then 'ant undeploy-jms-dests'.
 
 Load Test Targets
 ===========================
 runtest - Runs the load agent to simulate load and the load reporter to report on load
+runtest-secure - Runs the load agent to simulate load, and the load reporter authenticates to secure http
 load-agent - Simulates load only
 load-report - Report on load only
 

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/scripts/LoadReport.groovy
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/scripts/LoadReport.groovy	2008-01-18 17:08:45 UTC (rev 17959)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/scripts/LoadReport.groovy	2008-01-18 17:43:18 UTC (rev 17960)
@@ -43,7 +43,7 @@
 
 class LoadReport
 {
-	LoadUtil util = new LoadUtil()
+	LoadUtil util
 	def loadConfigFile
 	InitialContext ctx
 	MBeanServerConnection server
@@ -52,11 +52,13 @@
 	def svcReportLog
 	def queueReportLog
 		
-	LoadReport(aLoadConfigFile)
+	LoadReport(aLoadConfigFile, user, password)
 	{
 		loadConfigFile = aLoadConfigFile
 		ctx = new InitialContext(); // From jndi.properties
 		server = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor")
+		util = new LoadUtil(user, password)
+		println "USER=$user PASSWORD=$password"
 	}
 
    public generateMetrics()
@@ -169,7 +171,12 @@
 
 	static void main(args)
 	{
-		LoadReport reporter = new LoadReport(args[0])
+		LoadReport reporter = null
+		if (args.size() == 3) {
+			 reporter = new LoadReport(args[0], args[1], args[2])
+		} else {
+			 reporter = new LoadReport(args[0], null, null)
+		}
 		reporter.generateMetrics()	
 	}
 

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/scripts/LoadUtil.groovy
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/scripts/LoadUtil.groovy	2008-01-18 17:08:45 UTC (rev 17959)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/scripts/LoadUtil.groovy	2008-01-18 17:43:18 UTC (rev 17960)
@@ -3,6 +3,8 @@
 import javax.naming.InitialContext
 import javax.naming.NamingException
 
+import org.jboss.soa.esb.samples.quickstart.jmx.*;
+
 /**
  * Simple Groovy load script that will provide TPS statistics for a ESB service call and JMS Queues.
  *
@@ -13,22 +15,38 @@
 {
    InitialContext ctx
    MBeanServerConnection server	
+   String user
+   String password
    
    public LoadUtil()
    {
-   		initContext()
+	user = null
+	password = null
    }
-	
-   private initContext()
+
+   public LoadUtil(f_user, f_password)
    {
-   		ctx = new InitialContext(); // From jndi.properties
-		server = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor")
-   }   
+	user = f_user
+	password = f_password
+   }
 
+   public Long getLongAttribute (ObjectName on, String an) {
+        Long val = null
+		JMXAttributeFinder jf = new JMXAttributeFinder(user, password)
+		val = (Long) jf.query(on, an)
+		return val
+   }
+
+   public Integer getIntegerAttribute (ObjectName on, String an) {
+		Integer val = null
+		JMXAttributeFinder jf = new JMXAttributeFinder(user, password)
+		val = (Integer) jf.query(on, an)
+   }
+
    public float getEsbServiceTps(serviceReportBean)
    {
    		def serviceMessageCount = {
-   			server.getAttribute(new ObjectName("jboss.esb:service-name=$serviceReportBean.serviceName,deployment=$serviceReportBean.esbArchiveName,category=MessageCounter"), "overall service message count").toLong()
+			getLongAttribute(new ObjectName("jboss.esb:service-name=$serviceReportBean.serviceName,deployment=$serviceReportBean.esbArchiveName,category=MessageCounter"), "overall service message count")
    		}
    		
    		def processedMsgsBefore = serviceMessageCount()
@@ -55,9 +73,9 @@
    		def queueDepthCount = {
 			def temp = 0
 			try {
-				temp = server.getAttribute(new ObjectName("$queue"), "QueueDepth").toLong()
+				temp = getLongAttribute(new ObjectName("$queue"), "QueueDepth")
 			} catch (javax.management.AttributeNotFoundException e) {
-				temp = server.getAttribute(new ObjectName("$queue"), "MessageCount").toInteger()
+				temp = getIntegerAttribute(new ObjectName("$queue"), "MessageCount")
 			}
 			if (temp == null) {
 				return 0

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/src/org/jboss/soa/esb/samples/quickstart/jmx/JMXAttributeFinder.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/src/org/jboss/soa/esb/samples/quickstart/jmx/JMXAttributeFinder.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/src/org/jboss/soa/esb/samples/quickstart/jmx/JMXAttributeFinder.java	2008-01-18 17:43:18 UTC (rev 17960)
@@ -0,0 +1,127 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.samples.quickstart.jmx;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
+
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+
+/**
+ * Facade for querying JMX.     If user and password have a value other than null,
+ * try to authenticate to secure HTTP before querying JMX.     
+ *
+ * @author <a href="tcunning at redhat.com">Tom Cunningham</a>
+ */
+public class JMXAttributeFinder {
+
+	LoginContext loginContext = null;
+	String user;
+	String password;
+
+	public JMXAttributeFinder() {
+		user = null;
+		password = null;
+	}
+
+	public JMXAttributeFinder(String f_user, String f_password) {
+		user = f_user;
+		password = f_password;
+	}
+
+	public String getResourceURL(String resource) throws MalformedURLException {
+		ClassLoader loader = Thread.currentThread().getContextClassLoader();
+		URL resURL = loader.getResource(resource);
+		return resURL != null ? resURL.toString() : null;
+	}
+
+	public void login() {
+		if ((user != null) && (password != null)) {
+			try {
+				CallbackHandler handler = new LGCallbackHandler(user,password);
+				String authConf = getResourceURL("auth.conf");
+				System.setProperty("java.security.auth.login.config", authConf);			
+				LoginContext loginContext = new LoginContext("jboss_jaas",  handler);
+				loginContext.login();
+			} catch (Exception e) {
+			}
+		}
+	}
+
+	public Object query(ObjectName oname, String attname) throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException {
+		Object att = null;
+		login();
+		Properties env = new Properties();
+		String url = new String("http://localhost:8080/invoker/JNDIFactory");
+		env.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.HttpNamingContextFactory");
+		env.setProperty(Context.PROVIDER_URL,url);
+		env.setProperty("java.naming.factory.url.pkgs","org.jboss.naming.client");
+		Context ctx;
+		MBeanServerConnection server = null;
+		try {
+			ctx = new InitialContext(env);
+			server = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor");
+		} catch (NamingException e1) {
+			e1.printStackTrace();
+		}
+	
+		att = server.getAttribute(oname, attname);
+	
+		try {
+			logout();
+		} catch (LoginException e) {
+			e.printStackTrace();
+		}
+		return att;
+	}
+
+	public void logout() throws LoginException {
+		if (loginContext != null) {
+			loginContext.logout();
+		}
+	}
+
+	public static void main (String args[]) {
+		try {
+			JMXAttributeFinder t = new JMXAttributeFinder();
+			Object val = t.query(new ObjectName("jboss.esb:gateway-name=JMS-Gateway"), "LifeCycleState");	
+			System.out.println(val);
+			t.logout();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+}
+

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/src/org/jboss/soa/esb/samples/quickstart/jmx/LGCallbackHandler.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/src/org/jboss/soa/esb/samples/quickstart/jmx/LGCallbackHandler.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/load_generator/src/org/jboss/soa/esb/samples/quickstart/jmx/LGCallbackHandler.java	2008-01-18 17:43:18 UTC (rev 17960)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.samples.quickstart.jmx; 
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+/**
+ * Simple callback class for load_generator.      
+ *
+ * @author <a href="tcunning at redhat.com">Tom Cunningham</a>
+ */
+public class LGCallbackHandler implements CallbackHandler {
+	String username;
+	String password;
+
+	public LGCallbackHandler (String username, String password) {
+		this.username = username;
+		this.password = password;
+	}
+
+	public void handle(Callback[] callbacks) throws java.io.IOException, UnsupportedCallbackException {
+		for (int i = 0; i < callbacks.length; i++) {
+			Callback callback = callbacks[i];
+			if (callback instanceof NameCallback) {
+				((NameCallback) callback).setName(username);
+			} else if (callback instanceof PasswordCallback) {
+				((PasswordCallback) callback).setPassword(password.toCharArray());
+			} else {
+				throw new UnsupportedCallbackException(callback, "Unsupported Callback");
+			}
+		}
+	}
+}




More information about the jboss-svn-commits mailing list