Skip to content
This repository was archived by the owner on Sep 21, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private ScxExceptionBundle(ResourceBundle bundle) {
/**
* <p>
* Get the localized message for the given Exception Code.
* </p
* </p>
*
* @param key
* A key to look-up in the resource file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ public Statistic getAppServerName()
{
ServerName = getJMXAttribute(ijmx, "WebSphere:j2eeType=J2EEServer,*", "platformName");
}
else
if(storename.compareTo(JmxConstant.KARAF_MBEAN_STORE_NAME)==0)
{
ServerName = "JBoss A-MQ (on Karaf)";
}
}
}

Expand Down Expand Up @@ -225,6 +230,11 @@ public Statistic getVersion()
{
ServerVersion = getJMXAttribute(ijmx, "WebSphere:j2eeType=J2EEServer,*", "platformVersion");
}
else
if(storename.compareTo(JmxConstant.KARAF_MBEAN_STORE_NAME)==0)
{
ServerVersion = getJMXAttribute(ijmx, "org.apache.activemq:brokerName=*,type=Broker", "BrokerVersion");
}
}
}
return ServerVersion!=null ? new Statistic(AppServerVersion, String.class, ServerVersion) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public static void connectToJmxStores()
addStoreToJmxStores(JmxConstant.TOMCAT_MBEAN_STORE_NAME,null);
addStoreToJmxStores(JmxConstant.WEBSPHERE_MBEAN_STORE_NAME,null);
addStoreToJmxStores(JmxConstant.WEBLOGIC_MBEAN_STORE_NAME,null);
addStoreToJmxStores(JmxConstant.KARAF_MBEAN_STORE_NAME,null);
/*
* The JdkJMXAbstraction needs to be the last entry in the list to avoid the
* version information being processed from the JdkJMXAbstraction MBean store.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
/**
* Copyright (c) Microsoft Corporation
*
* Licensed 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.
*
* THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
* OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
* ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
* MERCHANTABLITY OR NON-INFRINGEMENT.
*
* See the Apache Version 2.0 License for specific language governing
* permissions and limitations under the License.
*/

package com.interopbridges.scx.jmx;

import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.Set;

import javax.management.AttributeNotFoundException;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.QueryExp;
import javax.management.ReflectionException;
import javax.naming.NamingException;

import com.interopbridges.scx.ScxException;


/**
* <p>
* Karaf 2.2.3 for the Runtime JMX Store
* </p>
*
* @author Geoff Erasmus
*/
public class KarafJMXAbstraction implements IJMX {

/**
* <p>
* Connection to the MBeanServer
* </p>
*/
private MBeanServerConnection _server;

/**
* <p>
* Constructor. The constructor sets the MBeanServer to be used by this class.
* </p>
*
* @param server
* An instance of a MBeanServer to be used by this class.
*
*/
public KarafJMXAbstraction(MBeanServer server) throws
NamingException
{
_server = server;
}

/**
* <p>
* Default Constructor. The constructor attempts to locate a reference to the Weblogic runtime JMX MBean Store
* it does not use specific API calls but rather does a JNDI lookup to retrieve the reference to the
* MBeanServer.
* </p>
*
* @throws ScxException
* The JNDI lookup could not return an instance of a MBeanServer.
*/
public KarafJMXAbstraction() throws
NamingException,
ScxException
{
/*
try
{
//JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root");
HashMap env = new HashMap();
String[] credentials = new String[] {"admin","admin"};
env.put(JMXConnector.CREDENTIALS, credentials);

JMXConnector connector = JMXConnectorFactory.connect(url, env);
//JMXConnector connector = JMXConnectorFactory.connect(url, null);
_server = connector.getMBeanServerConnection();

}
catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
*/
_server = ManagementFactory.getPlatformMBeanServer();

}

/*
* (non-Javadoc)
*
* @see com.interopbridges.scx.jmx.IJMX#getAttribute(javax.management.ObjectName,
* java.lang.String)
*/
public Object getAttribute(ObjectName name, String attribute)
throws MBeanException, AttributeNotFoundException,
InstanceNotFoundException, ReflectionException, IOException {
return this._server.getAttribute(name, attribute);
}

/*
* (non-Javadoc)
*
* @see com.interopbridges.scx.jmx.IJMX#getMBeanServerID()
*/
public int getMBeanServerID()
{
return this._server.hashCode();
}

/*
* (non-Javadoc)
*
* @see com.interopbridges.scx.jmx.IJMX#getMBeanCount()
*/
public Integer getMBeanCount()
throws IOException
{
return this._server.getMBeanCount();
}

/*
* (non-Javadoc)
*
* @see com.interopbridges.scx.jmx.IJMX#getMBeanInfo(javax.management.ObjectName)
*/
public MBeanInfo getMBeanInfo(ObjectName name)
throws InstanceNotFoundException, IntrospectionException,
ReflectionException, IOException {
return this._server.getMBeanInfo(name);
}

/*
* (non-Javadoc)
*
* @see com.interopbridges.scx.jmx.IJMX#isStandAloneJmxStore()
*/
public boolean isStandAloneJmxStore()
{
return true;
}

/*
* (non-Javadoc)
*
* @see com.interopbridges.scx.jmx.IJMX#queryMBeans(javax.management.ObjectName,
* javax.management.QueryExp)
*/
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query)
throws IOException
{
return this._server.queryMBeans(name, query);
}

/*
* (non-Javadoc)
*
* @see com.interopbridges.scx.jmx.IJMX#queryNames(javax.management.ObjectName,
* javax.management.QueryExp)
*/
public Set<ObjectName> queryNames(ObjectName name, QueryExp query)
throws IOException
{
return this._server.queryNames(name, query);
}

/*
* (non-Javadoc)
*
* @see com.interopbridges.scx.jmx.IJMX#registerMbean(java.lang.Object,
* javax.management.ObjectName)
*/
public void registerMBean(Object bean, ObjectName keys)
throws InstanceAlreadyExistsException, MBeanRegistrationException,
NotCompliantMBeanException, IOException {
/* do nothing */
}

/*
* (non-Javadoc)
*
* @see com.interopbridges.scx.jmx.IJMX#verifyStoreConnection()
*/
public boolean verifyStoreConnection()
{
// No additional checks are needed for this platform to
// verify the JMX store connection
return true;
}

/*
* (non-Javadoc)
*
* @see com.interopbridges.scx.jmx.IJMX#invoke(ObjectName, String, Object[], String[])
*/
public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature)
throws InstanceNotFoundException, ReflectionException, MBeanException, IOException
{
return this._server.invoke(name, operationName, params, signature);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,5 @@ public class JmxConstant {
public static final String WEBSPHERE_MBEAN_STORE_NAME = "com.interopbridges.scx.jmx.WebSphereJMXAbstraction";
public static final String WEBLOGIC_MBEAN_STORE_NAME = "com.interopbridges.scx.jmx.WeblogicRuntimeJMXAbstraction";
public static final String JDK_MBEAN_STORE_NAME = "com.interopbridges.scx.jmx.JdkJMXAbstraction";
public static final String KARAF_MBEAN_STORE_NAME = "com.interopbridges.scx.jmx.KarafJMXAbstraction";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.interopbridges.scx.beanspy;

import java.io.IOException;
import java.util.HashMap;

import com.interopbridges.scx.ScxException;
import com.interopbridges.scx.jmx.JmxStores;
import com.interopbridges.scx.log.ILogger;
import com.interopbridges.scx.log.LoggingFactory;
import com.interopbridges.scx.mbeans.MBeanGetter;
import com.interopbridges.scx.util.JmxURLCheck;
import com.interopbridges.scx.util.MsVersion;

public class BeanSpyMainTest {

/**
* <p>
* Logger for the class.
* </p>
*/
private static ILogger _logger = LoggingFactory.getLogger();


/**
* <p>
* Interface to getting the desired MBeans from the JMX Store (as XML).
* </p>
*/
protected MBeanGetter _mbeanAccessor;

public BeanSpyMainTest(){

//this._logger = LoggingFactory.getLogger();
_mbeanAccessor = new MBeanGetter(JmxStores.getListOfJmxStoreAbstractions());


String JMXQuery = "org.apache.activemq:type=Broker,*";
HashMap<String, String[]> Params = null;
try {
String xml = _mbeanAccessor.getMBeansAsXml(JMXQuery, Params)
.toString();
System.out.println(xml);
} catch (ScxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}






JmxStores.clearListOfJmxStores();

}


public static void main(String[] args) {
_logger.info(new StringBuffer("Initializing BeanSpy (Build: ")
.append(MsVersion.VERSION).append(", Label: ").append(
MsVersion.LABEL_NAME).append(", BuildDate: ").append(
MsVersion.BUILD_DATE).append(")").toString());
_logger.info("contextInitialized: connecting to JMX Stores");
JmxStores.connectToJmxStores();
new BeanSpyMainTest();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.interopbridges.scx.beanspy;

import java.util.HashMap;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

public class DummyKarafTest {

public static void main(String[] args) throws Exception {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root");
HashMap env = new HashMap();
String[] credentials = new String[] {"admin","admin"};
env.put(JMXConnector.CREDENTIALS, credentials);

JMXConnector connector = JMXConnectorFactory.connect(url, env);

MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
ObjectName systemMBean = new ObjectName("org.apache.activemq:brokerName=amq,type=Broker,*");
// systemMBean.
connector.close();

System.out.println("Done");

}

}