[infinispan-commits] Infinispan SVN: r370 - in trunk: jopr-plugin and 14 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Tue Jun 2 08:21:30 EDT 2009
Author: manik.surtani at jboss.com
Date: 2009-06-02 08:21:29 -0400 (Tue, 02 Jun 2009)
New Revision: 370
Added:
trunk/jopr-plugin/
trunk/jopr-plugin/pom.xml
trunk/jopr-plugin/src/
trunk/jopr-plugin/src/main/
trunk/jopr-plugin/src/main/java/
trunk/jopr-plugin/src/main/java/org/
trunk/jopr-plugin/src/main/java/org/infinispan/
trunk/jopr-plugin/src/main/java/org/infinispan/jopr/
trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/
trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/CacheComponent.java
trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/CacheDiscovery.java
trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/ConnectionHelper.java
trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/InfinispanComponent.java
trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/InfinispanDiscovery.java
trunk/jopr-plugin/src/main/resources/
trunk/jopr-plugin/src/main/resources/META-INF/
trunk/jopr-plugin/src/main/resources/META-INF/rhq-plugin.xml
trunk/jopr-plugin/src/test/
trunk/jopr-plugin/src/test/java/
trunk/jopr-plugin/src/test/java/org/
trunk/jopr-plugin/src/test/java/org/infinispan/
trunk/jopr-plugin/src/test/java/org/infinispan/jopr/
trunk/jopr-plugin/src/test/java/org/infinispan/jopr/InfinispanJoprTest.java
Modified:
trunk/pom.xml
Log:
Added JOPR plugin
Added: trunk/jopr-plugin/pom.xml
===================================================================
--- trunk/jopr-plugin/pom.xml (rev 0)
+++ trunk/jopr-plugin/pom.xml 2009-06-02 12:21:29 UTC (rev 370)
@@ -0,0 +1,217 @@
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+ >
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.rhq</groupId>
+ <artifactId>rhq-plugins-parent</artifactId>
+ <version>1.2.0.GA</version>
+ <!-- TODO adjust RHQ version in the future -->
+ </parent>
+
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-jopr-plugin</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Infinispan JOPR Plugin</name>
+ <description>The Infinispan JOPR Plugin</description>
+
+ <properties>
+ <scm.module.path>plugin/infinispan</scm.module.path>
+ <rhq.defaultDevContainerPath>/jon/dev-container</rhq.defaultDevContainerPath>
+ </properties>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ <mainClass>org.infinispan.Version</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ <executions>
+ <execution>
+ <id>build-test-jar</id>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ <configuration>
+ <archive>
+ <manifest>
+ <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ </manifest>
+ </archive>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>dev</id>
+
+ <properties>
+ <rhq.rootDir>../../..</rhq.rootDir>
+ <rhq.containerDir>${rhq.rootDir}/${rhq.defaultDevContainerPath}</rhq.containerDir>
+ <rhq.deploymentDir>
+ ${rhq.containerDir}/jbossas/server/default/deploy/${rhq.earName}/rhq-downloads/rhq-plugins
+ </rhq.deploymentDir>
+ </properties>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+
+ <execution>
+ <id>deploy</id>
+ <phase>compile</phase>
+ <configuration>
+ <tasks>
+ <mkdir dir="${rhq.deploymentDir}"/>
+ <property name="deployment.file"
+ location="${rhq.deploymentDir}/${project.build.finalName}.jar"/>
+ <echo>*** Updating ${deployment.file}...</echo>
+ <jar destfile="${deployment.file}" basedir="${project.build.outputDirectory}"/>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+
+ <execution>
+ <id>deploy-jar-meta-inf</id>
+ <phase>package</phase>
+ <configuration>
+ <tasks>
+ <property name="deployment.file"
+ location="${rhq.deploymentDir}/${project.build.finalName}.jar"/>
+ <echo>*** Updating META-INF dir in ${deployment.file}...</echo>
+ <unjar src="${project.build.directory}/${project.build.finalName}.jar"
+ dest="${project.build.outputDirectory}">
+ <patternset>
+ <include name="META-INF/**"/>
+ </patternset>
+ </unjar>
+ <jar destfile="${deployment.file}"
+ manifest="${project.build.outputDirectory}/META-INF/MANIFEST.MF"
+ update="true">
+ </jar>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+
+ <execution>
+ <id>undeploy</id>
+ <phase>clean</phase>
+ <configuration>
+ <tasks>
+ <property name="deployment.file"
+ location="${rhq.deploymentDir}/${project.build.finalName}.jar"/>
+ <echo>*** Deleting ${deployment.file}...</echo>
+ <delete file="${deployment.file}"/>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ </profile>
+ </profiles>
+
+
+ <repositories>
+ <repository>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <id>jboss</id>
+ <name>JBoss Repository</name>
+ <url>http://repository.jboss.org/maven2/</url>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <id>jboss</id>
+ <name>JBoss Plugin Repository</name>
+ <url>http://repository.jboss.org/maven2/</url>
+ </pluginRepository>
+ </pluginRepositories>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.rhq</groupId>
+ <artifactId>rhq-core-domain</artifactId>
+ <version>1.2.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.rhq</groupId>
+ <artifactId>rhq-core-plugin-api</artifactId>
+ <version>1.2.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.rhq</groupId>
+ <artifactId>rhq-core-native-system</artifactId>
+ <version>1.2.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.rhq</groupId>
+ <artifactId>rhq-jmx-plugin</artifactId>
+ <version>1.2.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-core</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Property changes on: trunk/jopr-plugin/pom.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/CacheComponent.java
===================================================================
--- trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/CacheComponent.java (rev 0)
+++ trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/CacheComponent.java 2009-06-02 12:21:29 UTC (rev 370)
@@ -0,0 +1,181 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * 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.infinispan.jopr.infinispan;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mc4j.ems.connection.EmsConnection;
+import org.mc4j.ems.connection.bean.EmsBean;
+import org.mc4j.ems.connection.bean.attribute.EmsAttribute;
+import org.mc4j.ems.connection.bean.operation.EmsOperation;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.measurement.MeasurementDataNumeric;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.core.pluginapi.measurement.MeasurementFacet;
+import org.rhq.core.pluginapi.operation.OperationFacet;
+import org.rhq.core.pluginapi.operation.OperationResult;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Component class for Caches within Infinispan
+ *
+ * @author Heiko W. Rupp
+ */
+public class CacheComponent implements ResourceComponent<InfinispanComponent>, MeasurementFacet, OperationFacet {
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ /**
+ * Map to match an abbreviation for the MBean to the full MBean name
+ */
+ private static final Map<String, String> abbrevToMBean = new HashMap<String, String>();
+
+ static {
+ abbrevToMBean.put("Mgmt", "CacheMgmtInterceptor");
+ abbrevToMBean.put("Mvcc", "MvccLockManager");
+ abbrevToMBean.put("Tx", "TxInterceptor");
+ }
+
+
+ private ResourceContext<InfinispanComponent> context;
+ /**
+ * The naming pattern of the current bean without the actual bean name
+ */
+ private String myNamePattern;
+
+ /**
+ * Return availability of this resource
+ *
+ * @see org.rhq.core.pluginapi.inventory.ResourceComponent#getAvailability()
+ */
+ public AvailabilityType getAvailability() {
+ // TODO does a cache have a lifecycle of its own?
+ return context.getParentResourceComponent().getAvailability();
+ }
+
+
+ /**
+ * Start the resource connection
+ *
+ * @see org.rhq.core.pluginapi.inventory.ResourceComponent#start(org.rhq.core.pluginapi.inventory.ResourceContext)
+ */
+ public void start(ResourceContext<InfinispanComponent> context) throws Exception {
+
+ this.context = context;
+ //
+ myNamePattern = context.getResourceKey();
+ myNamePattern = myNamePattern.substring(0, myNamePattern.indexOf("jmx-resource=") + 13);
+
+ }
+
+
+ /**
+ * Tear down the rescource connection
+ *
+ * @see org.rhq.core.pluginapi.inventory.ResourceComponent#stop()
+ */
+ public void stop() {
+
+
+ }
+
+
+ /**
+ * Gather measurement data
+ *
+ * @see org.rhq.core.pluginapi.measurement.MeasurementFacet#getValues(org.rhq.core.domain.measurement.MeasurementReport,
+ * java.util.Set)
+ */
+ public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception {
+
+ EmsConnection conn = getConnection();
+ for (MeasurementScheduleRequest req : metrics) {
+ String metric = req.getName();
+ try {
+ String abbrev = metric.substring(0, metric.indexOf("."));
+ String mbean = abbrevToMBean.get(abbrev);
+ mbean = myNamePattern + mbean;
+ EmsBean bean = conn.getBean(mbean);
+ bean.refreshAttributes();
+ String attName = metric.substring(metric.indexOf(".") + 1);
+ EmsAttribute att = bean.getAttribute(attName);
+
+ // Attribute values are of various data types ...
+ Object o = att.getValue();
+ Class type = att.getTypeClass();
+ if (type.equals(Long.class) || type.equals(long.class)) {
+ Long tmp = (Long) o;
+ MeasurementDataNumeric res = new MeasurementDataNumeric(req, Double.valueOf(tmp));
+ report.addData(res);
+ } else if (type.equals(Double.class) || type.equals(double.class)) {
+ Double tmp = (Double) o;
+ MeasurementDataNumeric res = new MeasurementDataNumeric(req, tmp);
+ report.addData(res);
+ } else if (type.equals(Integer.class) || type.equals(int.class)) {
+ Integer tmp = (Integer) o;
+ MeasurementDataNumeric res = new MeasurementDataNumeric(req, Double.valueOf(tmp));
+ report.addData(res);
+ }
+ }
+ catch (Exception e) {
+ log.warn("getValues failed for " + metric + " : ", e);
+ }
+ }
+ }
+
+ /**
+ * Invoke operations on the Cache MBean instance
+ *
+ * @param name Name of the operation
+ * @param parameters Parameters of the Operation
+ * @return OperationResult object if successful
+ * @throws Exception If operation was not successful
+ */
+ public OperationResult invokeOperation(String name,
+ Configuration parameters) throws Exception {
+ EmsConnection conn = getConnection();
+ String abbrev = name.substring(0, name.indexOf("."));
+ String mbean = abbrevToMBean.get(abbrev);
+ mbean = myNamePattern + mbean;
+ EmsBean bean = conn.getBean(mbean);
+ String opName = name.substring(name.indexOf(".") + 1);
+ EmsOperation ops = bean.getOperation(opName);
+ if (ops != null)
+ ops.invoke(new Object[]{});
+ else
+ throw new Exception("Operation " + name + " can't be found");
+
+
+ return new OperationResult();
+ }
+
+ private EmsConnection getConnection() {
+ return context.getParentResourceComponent().getConnection();
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/CacheComponent.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/CacheDiscovery.java
===================================================================
--- trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/CacheDiscovery.java (rev 0)
+++ trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/CacheDiscovery.java 2009-06-02 12:21:29 UTC (rev 370)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * 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.infinispan.jopr.infinispan;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mc4j.ems.connection.EmsConnection;
+import org.mc4j.ems.connection.bean.EmsBean;
+import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+import org.rhq.plugins.jmx.ObjectNameQueryUtility;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Discovery class for individual cache instances
+ *
+ * @author Heiko W. Rupp
+ */
+public class CacheDiscovery implements ResourceDiscoveryComponent<InfinispanComponent> {
+
+
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ /**
+ * Naming pattern of the cache MgmtInterceptor
+ */
+ private static final String CACHE_QUERY = "*:cache-name=%name%,jmx-resource=CacheMgmtInterceptor";
+
+
+ /**
+ * Run the discovery
+ */
+ public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<InfinispanComponent> discoveryContext) throws Exception {
+
+ Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>();
+
+ EmsConnection conn = discoveryContext.getParentResourceComponent().getConnection();
+ ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(CACHE_QUERY);
+ List<EmsBean> beans = conn.queryBeans(queryUtility.getTranslatedQuery());
+
+ for (EmsBean bean : beans) {
+
+ /**
+ * A discovered resource must have a unique key, that must
+ * stay the same when the resource is discovered the next
+ * time
+ */
+ String name = bean.getBeanName().getCanonicalName();
+ name = name.substring(name.indexOf("jmx-resource=") + 13);
+ DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
+ discoveryContext.getResourceType(), // Resource Type
+ bean.getBeanName().getCanonicalName(), // Resource Key
+ name, // Resource name
+ null, // Version
+ "One cache within Infinispan", // ResourceDescription
+ discoveryContext.getDefaultPluginConfiguration(), // Plugin Config
+ null // ProcessInfo
+ );
+
+
+ // Add to return values
+ discoveredResources.add(detail);
+ log.info("Discovered new ... " + bean.getBeanName().getCanonicalName());
+ }
+ return discoveredResources;
+ }
+}
\ No newline at end of file
Property changes on: trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/CacheDiscovery.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/ConnectionHelper.java
===================================================================
--- trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/ConnectionHelper.java (rev 0)
+++ trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/ConnectionHelper.java 2009-06-02 12:21:29 UTC (rev 370)
@@ -0,0 +1,166 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.infinispan.jopr.infinispan;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mc4j.ems.connection.ConnectionFactory;
+import org.mc4j.ems.connection.EmsConnection;
+import org.mc4j.ems.connection.settings.ConnectionSettings;
+import org.mc4j.ems.connection.support.ConnectionProvider;
+import org.mc4j.ems.connection.support.metadata.ConnectionTypeDescriptor;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.plugins.jmx.JMXDiscoveryComponent;
+
+import java.util.Properties;
+
+/**
+ * Shared helper class to connect to a remote server
+ *
+ * @author Jay Shaughnessy
+ * @author Heiko W. Rupp
+ */
+public class ConnectionHelper {
+
+ private final Log log = LogFactory.getLog(ConnectionHelper.class);
+
+ private EmsConnection connection;
+ /**
+ * Controls the dampening of connection error stack traces in an attempt to control spam to the log file. Each time a
+ * connection error is encountered, this will be incremented. When the connection is finally established, this will
+ * be reset to zero.
+ */
+ private int consecutiveConnectionErrors;
+
+
+ public EmsConnection getEmsConnection(Configuration config) {
+ EmsConnection emsConnection = null;
+
+ try {
+ emsConnection = loadConnection(config);
+ } catch (Exception e) {
+ log.error("Component attempting to access a connection that could not be loaded");
+ }
+
+ return emsConnection;
+ }
+
+ /**
+ * This is the preferred way to use a connection from within this class; methods should not access the connection
+ * property directly as it may not have been instantiated if the connection could not be made. <p/> <p>If the
+ * connection has already been established, return the object reference to it. If not, attempt to make a live
+ * connection to the JMX server.</p> <p/> <p>If the connection could not be made in the
+ * start(org.rhq.core.pluginapi.inventory.ResourceContext) method, this method will effectively try to load the
+ * connection on each attempt to use it. As such, multiple threads may attempt to access the connection through this
+ * means at a time. Therefore, the method has been made synchronized on instances of the class.</p> <p/> <p>If any
+ * errors are encountered, this method will log the error, taking into account logic to prevent spamming the log
+ * file. Calling methods should take care to not redundantly log the exception thrown by this method.</p>
+ *
+ * @param pluginConfig
+ * @return live connection to the JMX server; this will not be <code>null</code>
+ * @throws Exception if there are any issues at all connecting to the server
+ */
+ private synchronized EmsConnection loadConnection(Configuration pluginConfig) throws Exception {
+ if (this.connection == null) {
+ try {
+ //Configuration pluginConfig = this.resourceContext.getPluginConfiguration();
+
+ ConnectionSettings connectionSettings = new ConnectionSettings();
+
+ String connectionTypeDescriptorClass = pluginConfig.getSimple(JMXDiscoveryComponent.CONNECTION_TYPE)
+ .getStringValue();
+ PropertySimple serverUrl = pluginConfig
+ .getSimple(JMXDiscoveryComponent.CONNECTOR_ADDRESS_CONFIG_PROPERTY);
+
+ connectionSettings.initializeConnectionType((ConnectionTypeDescriptor) Class.forName(
+ connectionTypeDescriptorClass).newInstance());
+ // if not provided use the default serverUrl
+ if (null != serverUrl) {
+ connectionSettings.setServerUrl(serverUrl.getStringValue());
+ }
+
+// connectionSettings.setPrincipal(pluginConfig.getSimpleValue(PRINCIPAL_CONFIG_PROP, null));
+// connectionSettings.setCredentials(pluginConfig.getSimpleValue(CREDENTIALS_CONFIG_PROP, null));
+
+ if (connectionSettings.getAdvancedProperties() == null) {
+ connectionSettings.setAdvancedProperties(new Properties());
+ }
+
+ ConnectionFactory connectionFactory = new ConnectionFactory();
+
+
+ ConnectionProvider connectionProvider = connectionFactory.getConnectionProvider(connectionSettings);
+ this.connection = connectionProvider.connect();
+
+ this.connection.loadSynchronous(false); // this loads all the MBeans
+
+ this.consecutiveConnectionErrors = 0;
+
+ if (log.isDebugEnabled())
+ log.debug("Successfully made connection to the remote server instance");
+ } catch (Exception e) {
+
+ // The connection will be established even in the case that the principal cannot be authenticated,
+ // but the connection will not work. That failure seems to come from the call to loadSynchronous after
+ // the connection is established. If we get to this point that an exception was thrown, close any
+ // connection that was made and null it out so we can try to establish it again.
+ if (connection != null) {
+ if (log.isDebugEnabled())
+ log.debug("Connection created but an exception was thrown. Closing the connection.", e);
+ connection.close();
+ connection = null;
+ }
+
+ // Since the connection is attempted each time it's used, failure to connect could result in log
+ // file spamming. Log it once for every 10 consecutive times it's encountered.
+ if (consecutiveConnectionErrors % 10 == 0) {
+ log.warn("Could not establish connection to the Infinispan instance ["
+ + (consecutiveConnectionErrors + 1) + "] times.", e);
+ }
+
+ if (log.isDebugEnabled())
+ log.debug("Could not connect to the Infinispan instance for resource ", e);
+
+ consecutiveConnectionErrors++;
+
+ throw e;
+ }
+ }
+
+ return connection;
+ }
+
+
+ /**
+ * If necessary attempt to close the EMS connection, then set this.connection null. Synchronized ensure we play well
+ * with loadConnection.
+ */
+ public synchronized void closeConnection() {
+ if (this.connection != null) {
+ try {
+ this.connection.close();
+ } catch (Exception e) {
+ log.error("Error closing Infinispan EMS connection: " + e);
+ }
+ this.connection = null;
+ }
+ }
+
+}
Property changes on: trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/ConnectionHelper.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/InfinispanComponent.java
===================================================================
--- trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/InfinispanComponent.java (rev 0)
+++ trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/InfinispanComponent.java 2009-06-02 12:21:29 UTC (rev 370)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * 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.infinispan.jopr.infinispan;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mc4j.ems.connection.EmsConnection;
+import org.mc4j.ems.connection.bean.EmsBean;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.measurement.MeasurementDataNumeric;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.core.pluginapi.measurement.MeasurementFacet;
+
+import java.util.Set;
+
+/**
+ * The component class for the Infinispan manager
+ *
+ * @author Heiko W. Rupp
+ */
+public class InfinispanComponent implements ResourceComponent, MeasurementFacet {
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ private ResourceContext context;
+ private ConnectionHelper helper;
+
+
+ /**
+ * Return availability of this resource. We do this by checking the connection to it. If the Manager would expose
+ * some "run state" we could check for that too.
+ *
+ * @see org.rhq.core.pluginapi.inventory.ResourceComponent#getAvailability()
+ */
+ public AvailabilityType getAvailability() {
+ EmsConnection conn = getConnection();
+ try {
+ conn.refresh();
+ EmsBean bean = conn.getBean(context.getResourceKey());
+ if (bean != null)
+ bean.refreshAttributes();
+ return AvailabilityType.UP;
+ } catch (Exception e) {
+ return AvailabilityType.DOWN;
+ }
+ }
+
+ /**
+ * Start the resource connection
+ *
+ * @see org.rhq.core.pluginapi.inventory.ResourceComponent#start(org.rhq.core.pluginapi.inventory.ResourceContext)
+ */
+ public void start(ResourceContext context) throws InvalidPluginConfigurationException, Exception {
+
+ this.context = context;
+ helper = new ConnectionHelper();
+ getConnection();
+ }
+
+ /**
+ * Tear down the rescource connection
+ *
+ * @see org.rhq.core.pluginapi.inventory.ResourceComponent#stop()
+ */
+ public void stop() {
+ helper.closeConnection();
+
+ }
+
+ /**
+ * Gather measurement data
+ *
+ * @see org.rhq.core.pluginapi.measurement.MeasurementFacet#getValues(org.rhq.core.domain.measurement.MeasurementReport,
+ * java.util.Set)
+ */
+ public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception {
+
+ EmsConnection conn = getConnection();
+ EmsBean bean = conn.getBean(context.getPluginConfiguration().getSimpleValue("objectName", null));
+ bean.refreshAttributes();
+
+ for (MeasurementScheduleRequest req : metrics) {
+ // TODO check with Traits in the future - also why are the values Strings?
+ String tmp = (String) bean.getAttribute(req.getName()).getValue();
+ Double val = Double.valueOf(tmp);
+ MeasurementDataNumeric res = new MeasurementDataNumeric(req, val);
+ report.addData(res);
+ }
+ }
+
+ /**
+ * Helper to obtain a connection
+ *
+ * @return EmsConnection object
+ */
+ protected EmsConnection getConnection() {
+ EmsConnection conn = helper.getEmsConnection(context.getPluginConfiguration());
+ return conn;
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/InfinispanComponent.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/InfinispanDiscovery.java
===================================================================
--- trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/InfinispanDiscovery.java (rev 0)
+++ trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/InfinispanDiscovery.java 2009-06-02 12:21:29 UTC (rev 370)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * 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.infinispan.jopr.infinispan;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mc4j.ems.connection.EmsConnection;
+import org.mc4j.ems.connection.bean.EmsBean;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+import org.rhq.plugins.jmx.JMXDiscoveryComponent;
+import org.rhq.plugins.jmx.ObjectNameQueryUtility;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Discovery class for Infinispan engines
+ *
+ * @author Heiko W. Rupp
+ */
+public class InfinispanDiscovery implements ResourceDiscoveryComponent<InfinispanComponent> {
+
+
+ // Assume a java5 jmx-remote connector on port 6996
+ public static String REMOTE = "service:jmx:rmi://127.0.0.1/jndi/rmi://127.0.0.1:6996/jmxrmi";
+
+ public static String MANAGER_OBJECT = "*:cache-name=[global],jmx-resource=CacheManager";
+
+ String connector = "org.mc4j.ems.connection.support.metadata.J2SE5ConnectionTypeDescriptor";
+ private final Log log = LogFactory.getLog(this.getClass());
+
+
+ /**
+ * Run the discovery
+ */
+ public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<InfinispanComponent> discoveryContext) throws Exception {
+
+ Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>();
+
+ /*
+ * Currently this uses a hardcoded remote address for access to the MBean server
+ * This needs to be switched to check if we e.g. run inside a JBossAS to which we
+ * have a connection already that we can reuse.
+ */
+ Configuration c = new Configuration(); // TODO get from defaultPluginConfig
+ c.put(new PropertySimple(JMXDiscoveryComponent.CONNECTOR_ADDRESS_CONFIG_PROPERTY, REMOTE));
+ c.put(new PropertySimple(JMXDiscoveryComponent.CONNECTION_TYPE, connector));
+ c.put(new PropertySimple("objectName", MANAGER_OBJECT));
+
+ ConnectionHelper helper = new ConnectionHelper();
+ EmsConnection conn = helper.getEmsConnection(c);
+
+ // Run query for manager_object
+ ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(MANAGER_OBJECT);
+ List<EmsBean> beans = conn.queryBeans(queryUtility.getTranslatedQuery());
+
+ for (EmsBean bean : beans) {
+
+ String managerName = bean.getBeanName().getCanonicalName();
+ c.put(new PropertySimple("objectName", managerName));
+ /**
+ *
+ * A discovered resource must have a unique key, that must
+ * stay the same when the resource is discovered the next
+ * time
+ */
+ DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
+ discoveryContext.getResourceType(), // ResourceType
+ managerName, // Resource Key
+ "Infinispan Cache Manager", // Resource Name
+ null, // Version TODO can we get that from discovery ?
+ "The Infinispan Manager", // Description
+ c, // Plugin Config
+ null // Process info from a process scan
+ );
+
+
+ // Add to return values
+ discoveredResources.add(detail);
+ log.info("Discovered Infinispan instance: " + managerName);
+ }
+ return discoveredResources;
+
+ }
+}
\ No newline at end of file
Property changes on: trunk/jopr-plugin/src/main/java/org/infinispan/jopr/infinispan/InfinispanDiscovery.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/jopr-plugin/src/main/resources/META-INF/rhq-plugin.xml
===================================================================
--- trunk/jopr-plugin/src/main/resources/META-INF/rhq-plugin.xml (rev 0)
+++ trunk/jopr-plugin/src/main/resources/META-INF/rhq-plugin.xml 2009-06-02 12:21:29 UTC (rev 370)
@@ -0,0 +1,90 @@
+<?xml version="1.0"?>
+<plugin name="infinispan"
+ displayName="infinispanPlugin"
+ package="org.infinispan.jopr.infinispan"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="JMX" useClasses="true"/>
+
+ <server
+ name="infinispan"
+ discovery="InfinispanDiscovery"
+ class="InfinispanComponent"
+ singleton="true"
+
+ >
+
+ <plugin-configuration>
+ <c:simple-property name="connectorAddress" description="JMX Remoting address of the remote JBossOSGi Server"/>
+ <c:simple-property name="objectName" description="ObjectName of the Manager" type="string" readOnly="true"/>
+ <c:template name="default" description="The default setup for JBossOSGi">
+ <c:simple-property name="connectorAddress" displayName="URL of the remote server"
+ defaultValue="service:jmx:rmi://127.0.0.1/jndi/rmi://127.0.0.1:6996/jmxrmi"/>
+ </c:template>
+ </plugin-configuration>
+
+ <!-- TODO process scans -->
+
+ <metric property="createdCacheCount" displayName="Number of Caches created." displayType="summary" units="none"/>
+ <metric property="definedCacheCount" displayName="Number of Caches defined." displayType="summary" units="none"/>
+
+
+ <service
+ name="Cache"
+ discovery="CacheDiscovery"
+ class="CacheComponent"
+ description="One individual cache in Infinispan"
+ >
+
+ <operation name="Mgmt.resetStatistics" displayName="Reset Statistics (Mgmt)"
+ description="Reset statistics on the CacheManagement Interceptor"/>
+ <operation name="Tx.resetStatistics" displayName="Reset Statistics (Tx)"
+ description="Reset statistics on the Transaction Interceptor"/>
+
+ <metric property="Mgmt.averageReadTime" displayName="Average Read Time"
+ description="Average time to read an entry from the cache"
+ units="milliseconds" measurementType="dynamic"/>
+ <metric property="Mgmt.averageWriteTime" displayName="Average Write Time"
+ description="Average time to write an entry to the cache"
+ units="milliseconds" measurementType="dynamic"/>
+ <metric property="Mgmt.evictions" displayName="Evictions" measurementType="trendsup"
+ description="How many items got evicted from the cache" displayType="summary"/>
+ <metric property="Mgmt.hitRatio" displayName="Hit Ratio"
+ description="Hit ratio of this cache" displayType="summary"
+ units="percentage"/>
+ <metric property="Mgmt.hits" displayName="Hits" description="Number of cache hits"
+ measurementType="trendsup"/>
+ <metric property="Mgmt.misses" displayName="Misses" description="Number of cache misses"
+ measurementType="trendsup"/>
+ <metric property="Mgmt.numberOfEntries" displayName="Number of Entries"
+ description="The number of entries in this cache"/>
+ <metric property="Mgmt.readWriteRatio" displayName="Read write ratio"
+ description="The ratio between reads and writes of this cache"
+ units="percentage"/>
+ <metric property="Mgmt.stores" displayName="Stores" description="Number of stores in the cache"
+ measurementType="trendsup"/>
+
+ <metric property="Mvcc.numerOfLocksAvailable" displayName="Number of Locks availabe"
+ description="How many locks are still available in this Cache"
+ units="none" measurementType="dynamic"/>
+ <metric property="Mvcc.concurrencyLevel" displayName="Concurrency Level"/>
+ <!-- TODO description -->
+ <metric property="Mvcc.numberOfLocksHeld" displayName="Number of Locks held"/>
+
+ <metric property="Tx.commits" displayName="Commits"
+ description="Number of transaction commits performed since last reset"
+ units="none" measurementType="trendsup" displayType="summary"/>
+ <metric property="Tx.prepares" displayName="Prepares"
+ description="Number of transaction prepares performed since last reset"
+ units="none" measurementType="trendsup"/>
+ <metric property="Tx.rollbacks" displayName="Rollbacks"
+ description="Number of transaction rollbacks performed since last reset"
+ units="none" measurementType="trendsup" displayType="summary"/>
+ </service>
+
+ </server>
+
+
+</plugin>
\ No newline at end of file
Property changes on: trunk/jopr-plugin/src/main/resources/META-INF/rhq-plugin.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/jopr-plugin/src/test/java/org/infinispan/jopr/InfinispanJoprTest.java
===================================================================
--- trunk/jopr-plugin/src/test/java/org/infinispan/jopr/InfinispanJoprTest.java (rev 0)
+++ trunk/jopr-plugin/src/test/java/org/infinispan/jopr/InfinispanJoprTest.java 2009-06-02 12:21:29 UTC (rev 370)
@@ -0,0 +1,70 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package de.bsd.Infinitest;
+
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.config.GlobalConfiguration;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.manager.DefaultCacheManager;
+
+/**
+ * Standalone cache for infinispan testing
+ *
+ * @author Heiko W. Rupp
+ */
+public class InfinispanJoprTest {
+
+ private static final String MY_CUSTOM_CACHE = "myCustomCache";
+
+ public static void main(String[] args) throws InterruptedException {
+
+ GlobalConfiguration myGlobalConfig = new GlobalConfiguration();
+ // org.infinispan:cache-name=[global],jmx-resource=CacheManager
+ myGlobalConfig.setJmxDomain("org.infinispan");
+ myGlobalConfig.setExposeGlobalJmxStatistics(true);
+ CacheManager manager = new DefaultCacheManager(myGlobalConfig);
+
+ // org.infinispan:cache-name=myCustomcache(local),jmx-resource=CacheMgmgtInterceptor
+ // org.infinispan:cache-name=myCustomcache(local),jmx-resource=MvccLockManager
+ // org.infinispan:cache-name=myCustomcache(local),jmx-resource=TxInterceptor
+
+ Configuration config = new Configuration();
+ config.setExposeJmxStatistics(true);
+ config.setEvictionMaxEntries(123);
+ config.setExpirationMaxIdle(180000);
+
+ manager.defineCache(MY_CUSTOM_CACHE, config);
+ Cache<String,String> cache = manager.getCache(MY_CUSTOM_CACHE);
+
+ cache.put("myKey", "myValue");
+
+ int i = 0;
+ while (i < Integer.MAX_VALUE) {
+ Thread.sleep(12000);
+ cache.put("key" + i, String.valueOf(i));
+ cache.get("key" + ((int)(10000 * Math.random())));
+ i++;
+ if (i%10 == 0) {
+ System.out.print(".");
+ System.out.flush();
+ }
+ }
+ }
+}
Property changes on: trunk/jopr-plugin/src/test/java/org/infinispan/jopr/InfinispanJoprTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-06-02 11:00:50 UTC (rev 369)
+++ trunk/pom.xml 2009-06-02 12:21:29 UTC (rev 370)
@@ -27,6 +27,7 @@
<module>cachestore/s3</module>
<module>cachestore/jdbc</module>
<module>cachestore/jdbm</module>
+ <module>jopr-plugin</module>
<module>gui-demo</module>
</modules>
@@ -93,7 +94,7 @@
<fileset dir="core/target/classes"/>
<fileset dir="tree/target/classes"/>
<manifest>
- <attribute name="Main-Class" value="org.infinispan.Version" />
+ <attribute name="Main-Class" value="org.infinispan.Version"/>
</manifest>
</jar>
</tasks>
More information about the infinispan-commits
mailing list