Author: ningjiang
Date: Thu May 31 03:04:17 2007
New Revision: 543103
URL: http://svn.apache.org/viewvc?view=rev&rev=543103
Log:
Added the ManagementConsole for starting and stopping the endpoints, also
updated the management unit test to JUnit4 style
Added:
incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/
incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java
(with props)
incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties
(with props)
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/utils/
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java
(with props)
Modified:
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/MBServerConnectorTest.java
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/export/ModelMBeanAssemblerTest.java
Added:
incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java?view=auto&rev=543103
==============================================================================
---
incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java
(added)
+++
incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java
Thu May 31 03:04:17 2007
@@ -0,0 +1,206 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.management.utils;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.management.ManagementConstants;
+
+
+public final class ManagementConsole {
+ private static MBeanServerConnection mbsc;
+ private static final String DEFAULT_JMXSERVICE_URL =
+ "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
+ private static final Logger LOG =
LogUtils.getL7dLogger(ManagementConsole.class);
+
+ String jmxServerURL;
+ String portName;
+ String serviceName;
+ String operationName;
+
+ ManagementConsole() {
+
+ }
+
+ public void getManagedObjectAttributes(ObjectName name) throws Exception {
+
+ if (mbsc == null) {
+ LOG.log(Level.SEVERE , "NO_MBEAN_SERVER");
+ return;
+ }
+ MBeanInfo info = mbsc.getMBeanInfo(name);
+ MBeanAttributeInfo[] attrs = info.getAttributes();
+ if (attrs == null) {
+ return;
+ }
+ for (int i = 0; i < attrs.length; i++) {
+ if (attrs[i].isReadable()) {
+ try {
+ Object o = mbsc.getAttribute(name, attrs[i].getName());
+ System.out.println("\t\t" + attrs[i].getName() + " = " +
o);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+
+ void connectToMBserver() throws IOException {
+ jmxServerURL = jmxServerURL == null ? DEFAULT_JMXSERVICE_URL :
jmxServerURL;
+ JMXServiceURL url = new JMXServiceURL(jmxServerURL);
+ JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
+ mbsc = jmxc.getMBeanServerConnection();
+ }
+
+ @SuppressWarnings("unchecked")
+ void listAllManagedEndpoint() {
+ try {
+ ObjectName queryEndpointName = new
ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME
+ +
":type=Bus.Service.Endpoint,*");
+ Set<ObjectName> endpointNames = mbsc.queryNames(queryEndpointName,
null);
+ System.out.println("The endpoints are : ");
+ for (ObjectName oName : endpointNames) {
+ System.out.println(oName);
+ getManagedObjectAttributes(oName);
+ }
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "FAIL_TO_LIST_ENDPOINTS", new Object[]{e});
+ }
+ }
+
+ ObjectName getEndpointObjectName()
+ throws MalformedObjectNameException, NullPointerException {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(ManagementConstants.DEFAULT_DOMAIN_NAME +
":type=Bus.Service.Endpoint,");
+ buffer.append(ManagementConstants.SERVICE_NAME_PROP + "='" +
serviceName + "',");
+ buffer.append(ManagementConstants.PORT_NAME_PROP + "='" + portName +
"',*");
+ return new ObjectName(buffer.toString());
+ }
+
+ @SuppressWarnings("unchecked")
+ private void invokeEndpoint(String operation) {
+ ObjectName endpointName = null;
+ ObjectName queryEndpointName;
+ try {
+ queryEndpointName = getEndpointObjectName();
+ Set<ObjectName> endpointNames = mbsc.queryNames(queryEndpointName,
null);
+ // now get the ObjectName with the busId
+ Iterator it = endpointNames.iterator();
+
+ if (it.hasNext()) {
+ // only deal with the first endpoint object which retrun from
the list.
+ endpointName = (ObjectName)it.next();
+ mbsc.invoke(endpointName, operation, new Object[0], new
String[0]);
+ }
+
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "FAIL_TO_LIST_ENDPOINTS", new
Object[]{endpointName, operation, e});
+ }
+ }
+
+ void startEndpoint() {
+ invokeEndpoint("start");
+ }
+
+ void stopEndpoint() {
+ invokeEndpoint("stop");
+ }
+
+ void restartEndpoint() {
+ invokeEndpoint("stop");
+ invokeEndpoint("start");
+ }
+
+
+ void parserArguments(String[] args) {
+ portName = "";
+ serviceName = "";
+ jmxServerURL = "";
+
+ int i;
+ String arg;
+ for (i = 0; i < args.length; i++) {
+ arg = args[i];
+ if ("-port".equals(arg)) {
+ portName = args[++i];
+ continue;
+ }
+ if ("-service".equals(arg)) {
+ serviceName = args[++i];
+ continue;
+ }
+ if ("-jmx".equals(arg)) {
+ jmxServerURL = args[++i];
+ continue;
+ }
+ if ("-operation".equals(arg)) {
+ operationName = args[++i];
+ continue;
+ }
+ }
+ }
+
+ public void doManagement() {
+ try {
+ connectToMBserver();
+ if ("listall".equalsIgnoreCase(operationName)) {
+ listAllManagedEndpoint();
+ }
+ if ("start".equalsIgnoreCase(operationName)) {
+ startEndpoint();
+ }
+ if ("stop".equalsIgnoreCase(operationName)) {
+ stopEndpoint();
+ }
+ if ("restart".equalsIgnoreCase(operationName)) {
+ restartEndpoint();
+ }
+ } catch (IOException e) {
+ LOG.log(Level.SEVERE, "FAIL_TO_CONNECT_TO_MBEAN_SERVER", new
Object[]{jmxServerURL});
+ }
+
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ ManagementConsole mc = new ManagementConsole();
+ mc.parserArguments(args);
+ mc.doManagement();
+ }
+
+
+}
Propchange:
incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/ManagementConsole.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties?view=auto&rev=543103
==============================================================================
---
incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties
(added)
+++
incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties
Thu May 31 03:04:17 2007
@@ -0,0 +1,24 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+NO_MBEAN_SERVER = Can't find the MBeanServer, please Connect the MBeanServer
first.
+FAIL_TO_CONNECT_TO_MBEAN_SERVER = Failed to connect to the MBeanServer with is
url {0};
+FAIL_TO_LIST_ENDPOINTS = Failed to list the endpoints, the exception is {0}.
+FAIL_TO_INVOKE_MANAGED_OBJECT_OPERTION = Failed to invoke the managed object
{0}'s operation {1}, the exception is {2}.
\ No newline at end of file
Propchange:
incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/utils/Messages.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java?view=diff&rev=543103&r1=543102&r2=543103
==============================================================================
---
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java
(original)
+++
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java
Thu May 31 03:04:17 2007
@@ -24,24 +24,30 @@
import javax.management.MBeanServer;
import javax.management.ObjectName;
-import junit.framework.TestCase;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.workqueue.WorkQueueManagerImpl;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-public class InstrumentationManagerTest extends TestCase {
+public class InstrumentationManagerTest extends Assert {
InstrumentationManager im;
Bus bus;
+ @Before
public void setUp() throws Exception {
}
+ @After
public void tearDown() throws Exception {
//test case had done the bus.shutdown
bus.shutdown(true);
}
+ @Test
public void testInstrumentationNotEnabled() {
SpringBusFactory factory = new SpringBusFactory();
bus = factory.createBus();
@@ -51,6 +57,7 @@
assertNull("MBeanServer should not be available.", mbs);
}
+ @Test
// try to get WorkQueue information
public void testWorkQueueInstrumentation() throws Exception {
SpringBusFactory factory = new SpringBusFactory();
Modified:
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java?view=diff&rev=543103&r1=543102&r2=543103
==============================================================================
---
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
(original)
+++
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
Thu May 31 03:04:17 2007
@@ -22,15 +22,18 @@
import javax.management.JMException;
import javax.management.ObjectName;
-import junit.framework.TestCase;
-
import org.apache.cxf.management.jmx.export.AnnotationTestInstrumentation;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-public class JMXManagedComponentManagerTest extends TestCase {
+public class JMXManagedComponentManagerTest extends Assert {
private static final String NAME_ATTRIBUTE = "Name";
private InstrumentationManagerImpl manager;
+ @Before
public void setUp() throws Exception {
manager = new InstrumentationManagerImpl();
manager.setDaemon(false);
@@ -41,11 +44,13 @@
//Wait for MBeanServer connector to be initialized on separate thread.
Thread.sleep(2000);
}
-
+
+ @After
public void tearDown() throws Exception {
manager.shutdown();
}
+ @Test
public void testRegisterInstrumentation() throws Exception {
//manager.setDaemon(false);
//manager.setThreaded(false);
@@ -94,6 +99,7 @@
manager.unregister(im);
}
+ @Test
public void testRegisterStandardMBean() throws Exception {
HelloWorld hw = new HelloWorld();
ObjectName name = new ObjectName("org.apache.cxf:type=foo,name=bar");
Modified:
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/MBServerConnectorTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/MBServerConnectorTest.java?view=diff&rev=543103&r1=543102&r2=543103
==============================================================================
---
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/MBServerConnectorTest.java
(original)
+++
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/MBServerConnectorTest.java
Thu May 31 03:04:17 2007
@@ -24,11 +24,14 @@
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
-public class MBServerConnectorTest extends TestCase {
+public class MBServerConnectorTest extends Assert {
+
+ @Test
public void testMBServerConnector() {
MBServerConnectorFactory mcf;
MBeanServer mbs;
Modified:
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/export/ModelMBeanAssemblerTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/export/ModelMBeanAssemblerTest.java?view=diff&rev=543103&r1=543102&r2=543103
==============================================================================
---
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/export/ModelMBeanAssemblerTest.java
(original)
+++
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/export/ModelMBeanAssemblerTest.java
Thu May 31 03:04:17 2007
@@ -32,13 +32,16 @@
import javax.management.modelmbean.ModelMBeanOperationInfo;
import javax.management.modelmbean.RequiredModelMBean;
-import junit.framework.TestCase;
import org.apache.cxf.management.jmx.export.runtime.ModelMBeanAssembler;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-public class ModelMBeanAssemblerTest extends TestCase {
+public class ModelMBeanAssemblerTest extends Assert {
protected static final String AGE_ATTRIBUTE = "Age";
@@ -50,6 +53,7 @@
protected ObjectName ton;
+ @Before
public final void setUp() throws Exception {
this.server = MBeanServerFactory.createMBeanServer();
try {
@@ -59,8 +63,9 @@
throw e;
}
}
-
- protected void tearDown() throws Exception {
+
+ @After
+ public void tearDown() throws Exception {
releaseServer();
onTearDown();
}
@@ -105,18 +110,20 @@
}
//the client get and set the ModelObject and setup the ManagerBean
-
+ @Test
public void testRegisterOperations() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
assertEquals("Incorrect number of operations registered",
10, info.getOperations().length);
}
-
+
+ @Test
public void testGetMBeanInfo() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
assertNotNull("MBeanInfo should not be null", info);
}
+ @Test
public void testGetMBeanAttributeInfo() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
MBeanAttributeInfo[] inf = info.getAttributes();
@@ -130,6 +137,7 @@
}
}
+ @Test
public void testGetMBeanOperationInfo() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
MBeanOperationInfo[] inf = info.getOperations();
@@ -143,13 +151,14 @@
}
}
+ @Test
public void testDescriptionNotNull() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
assertNotNull("The MBean description should not be null",
info.getDescription());
}
-
+ @Test
public void testSetAttribute() throws Exception {
getServer().setAttribute(ton, new Attribute(AGE_ATTRIBUTE, 12));
assertEquals("The Age should be ", 12, ati.getAge());
@@ -157,18 +166,21 @@
assertEquals("The name should be ", "Rob Harrop", ati.getName());
}
+ @Test
public void testGetAttribute() throws Exception {
ati.setName("John Smith");
Object val = getServer().getAttribute(ton, NAME_ATTRIBUTE);
assertEquals("Incorrect result", "John Smith", val);
}
+ @Test
public void testOperationInvocation() throws Exception {
Object result = getServer().invoke(ton, "add",
new Object[] {new Integer(20), new
Integer(30)}, new String[] {"int", "int"});
assertEquals("Incorrect result", new Integer(50), result);
}
+ @Test
public void testAttributeHasCorrespondingOperations() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
@@ -182,6 +194,7 @@
}
+ @Test
public void testNotificationMetadata() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
MBeanNotificationInfo[] notifications = info.getNotifications();
@@ -195,6 +208,7 @@
assertEquals("Notification type.bar not found", "type.bar",
notifTypes[1]);
}
+
protected ModelMBeanInfo getMBeanInfoFromAssembler() {
ModelMBeanAssembler assembler = new ModelMBeanAssembler();
return
assembler.getModelMbeanInfo(AnnotationTestInstrumentation.class);
Added:
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java?view=auto&rev=543103
==============================================================================
---
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java
(added)
+++
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java
Thu May 31 03:04:17 2007
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.management.utils;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ManagementConsoleTest extends Assert {
+ private ManagementConsole mc = new ManagementConsole();
+
+ @Test
+ public void paraserCommandTest() {
+ String[] listArgs = new String[] {"-operation", "listall"};
+ mc.parserArguments(listArgs);
+ assertEquals("It is not right operation name", "listall",
mc.operationName);
+ assertEquals("The portName should be cleared", "", mc.portName);
+ String[] startArgs = new String[] {"-operation", "start", "-jmx",
+
"service:jmx:rmi:///jndi/rmi://localhost:1234/jmxrmi",
+ "-port",
+
"\"{http://apache.org/hello_world_soap_http}SoapPort\"",
+ "-service",
+
"\"{http://apache.org/hello_world_soap_http}SOAPService\""};
+ mc.parserArguments(startArgs);
+ assertEquals("It is not right operation name", "start",
mc.operationName);
+ assertEquals("It is not right port name",
+ "\"{http://apache.org/hello_world_soap_http}SoapPort\"",
mc.portName);
+ assertEquals("It is not right service name",
+
"\"{http://apache.org/hello_world_soap_http}SOAPService\"", mc.serviceName);
+ assertEquals("It is not a jmx url",
+ "service:jmx:rmi:///jndi/rmi://localhost:1234/jmxrmi",
+ mc.jmxServerURL);
+ }
+
+
+
+}
Propchange:
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/utils/ManagementConsoleTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date