[infinispan-commits] Infinispan SVN: r1156 - trunk/jopr-plugin/src/main/java/org/infinispan/jopr.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Thu Nov 12 12:38:49 EST 2009
Author: galder.zamarreno at jboss.com
Date: 2009-11-12 12:38:49 -0500 (Thu, 12 Nov 2009)
New Revision: 1156
Modified:
trunk/jopr-plugin/src/main/java/org/infinispan/jopr/CacheComponent.java
trunk/jopr-plugin/src/main/java/org/infinispan/jopr/CacheManagerComponent.java
trunk/jopr-plugin/src/main/java/org/infinispan/jopr/CacheManagerDiscovery.java
Log:
[ISPN-268] (Enhance the plugin so that Infinispan instances can be added manually) Fix messed up cache manager discovery and attribute retrieval.
Modified: trunk/jopr-plugin/src/main/java/org/infinispan/jopr/CacheComponent.java
===================================================================
--- trunk/jopr-plugin/src/main/java/org/infinispan/jopr/CacheComponent.java 2009-11-12 17:13:35 UTC (rev 1155)
+++ trunk/jopr-plugin/src/main/java/org/infinispan/jopr/CacheComponent.java 2009-11-12 17:38:49 UTC (rev 1156)
@@ -70,8 +70,8 @@
EmsBean bean = conn.getBean(context.getResourceKey());
EmsAttribute attribute = bean.getAttribute("CacheStatus");
if (attribute.getValue().equals(ComponentStatus.RUNNING.toString())) {
- if (trace) log.trace("Cache status is running, so it's up.");
bean.refreshAttributes();
+ if (trace) log.trace("Cache status is running and attributes could be refreshed, so it's up.");
return AvailabilityType.UP;
}
if (trace) log.trace("Cache status is anything other than running, so it's down.");
@@ -126,21 +126,25 @@
String attName = metric.substring(metric.indexOf(".") + 1);
EmsAttribute att = bean.getAttribute(attName);
// Attribute values are of various data types
- Object o = att.getValue();
- Class attrType = att.getTypeClass();
- DataType type = req.getDataType();
- if (type == DataType.MEASUREMENT) {
- if (o != null) {
- MeasurementDataNumeric res = constructMeasurementDataNumeric(attrType, o, req);
- if (res != null) report.addData(res);
- } else {
- if (log.isDebugEnabled()) log.debug("Metric ({0}) has null value, do not add to report", req.getName());
+ if (att != null) {
+ Object o = att.getValue();
+ Class attrType = att.getTypeClass();
+ DataType type = req.getDataType();
+ if (type == DataType.MEASUREMENT) {
+ if (o != null) {
+ MeasurementDataNumeric res = constructMeasurementDataNumeric(attrType, o, req);
+ if (res != null) report.addData(res);
+ } else {
+ if (log.isDebugEnabled()) log.debug("Metric ({0}) has null value, do not add to report", req.getName());
+ }
+ } else if (type == DataType.TRAIT) {
+ String value = (String) o;
+ if (trace) log.trace("Metric ({0}) is trait with value {1}", req.getName(), value);
+ MeasurementDataTrait res = new MeasurementDataTrait(req, value);
+ report.addData(res);
}
- } else if (type == DataType.TRAIT) {
- String value = (String) o;
- if (trace) log.trace("Metric ({0}) is trait with value {1}", req.getName(), value);
- MeasurementDataTrait res = new MeasurementDataTrait(req, value);
- report.addData(res);
+ } else {
+ log.warn("Attribute {0} not found", attName);
}
} else {
if (trace) log.trace("No mbean found with name {0}", mbean);
Modified: trunk/jopr-plugin/src/main/java/org/infinispan/jopr/CacheManagerComponent.java
===================================================================
--- trunk/jopr-plugin/src/main/java/org/infinispan/jopr/CacheManagerComponent.java 2009-11-12 17:13:35 UTC (rev 1155)
+++ trunk/jopr-plugin/src/main/java/org/infinispan/jopr/CacheManagerComponent.java 2009-11-12 17:38:49 UTC (rev 1156)
@@ -35,6 +35,7 @@
import org.rhq.core.pluginapi.inventory.ResourceComponent;
import org.rhq.core.pluginapi.inventory.ResourceContext;
import org.rhq.core.pluginapi.measurement.MeasurementFacet;
+import org.rhq.plugins.jmx.ObjectNameQueryUtility;
import java.util.Set;
@@ -48,7 +49,6 @@
private static final Log log = LogFactory.getLog(CacheManagerComponent.class);
private ResourceContext context;
private ConnectionHelper helper;
- private String objectName;
/**
* Return availability of this resource. We do this by checking the connection to it. If the Manager would expose
@@ -57,14 +57,20 @@
* @see org.rhq.core.pluginapi.inventory.ResourceComponent#getAvailability()
*/
public AvailabilityType getAvailability() {
+ boolean trace = log.isTraceEnabled();
EmsConnection conn = getConnection();
try {
conn.refresh();
- EmsBean bean = conn.getBean(objectName);
- if (bean != null)
+ EmsBean bean = queryCacheManagerBean(conn);
+ if (bean != null) {
bean.refreshAttributes();
- return AvailabilityType.UP;
+ if (trace) log.trace("Cache manager could be found and attributes where refreshed, so it's up.", bean);
+ return AvailabilityType.UP;
+ }
+ if (trace) log.trace("Cache manager could not be found, so cache manager is down");
+ return AvailabilityType.DOWN;
} catch (Exception e) {
+ if (trace) log.trace("There was an exception checking availability, so cache manager is down");
return AvailabilityType.DOWN;
}
}
@@ -76,7 +82,6 @@
*/
public void start(ResourceContext context) throws InvalidPluginConfigurationException, Exception {
this.context = context;
- this.objectName = context.getPluginConfiguration().getSimpleValue("objectName", null);
this.helper = new ConnectionHelper();
getConnection();
}
@@ -101,8 +106,10 @@
boolean trace = log.isTraceEnabled();
if (trace) log.trace("Get values for these metrics: {0}", metrics);
EmsConnection conn = getConnection();
- EmsBean bean = conn.getBean(objectName);
+ if (trace) log.trace("Connection to ems server stablished: {0}", conn);
+ EmsBean bean = queryCacheManagerBean(conn);
bean.refreshAttributes();
+ if (trace) log.trace("Querying returned bean: {0}", bean);
for (MeasurementScheduleRequest req : metrics) {
DataType type = req.getDataType();
if (type == DataType.MEASUREMENT) {
@@ -130,4 +137,10 @@
return conn;
}
+ private EmsBean queryCacheManagerBean(EmsConnection conn) {
+ String pattern = context.getPluginConfiguration().getSimpleValue("objectName", null);
+ if (log.isTraceEnabled()) log.trace("Pattern to query is {0}", pattern);
+ ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(pattern);
+ return conn.queryBeans(queryUtility.getTranslatedQuery()).get(0);
+ }
}
\ No newline at end of file
Modified: trunk/jopr-plugin/src/main/java/org/infinispan/jopr/CacheManagerDiscovery.java
===================================================================
--- trunk/jopr-plugin/src/main/java/org/infinispan/jopr/CacheManagerDiscovery.java 2009-11-12 17:13:35 UTC (rev 1155)
+++ trunk/jopr-plugin/src/main/java/org/infinispan/jopr/CacheManagerDiscovery.java 2009-11-12 17:38:49 UTC (rev 1156)
@@ -93,29 +93,34 @@
ConnectionHelper helper = new ConnectionHelper();
EmsConnection conn = helper.getEmsConnection(c);
- if (trace) log.trace("Connection to ems server stablished: {0}", conn);
+ if (conn != null) {
+ if (trace) log.trace("Connection to ems server stablished: {0}", conn);
- // Run query for manager_object
- ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(objectName);
- List<EmsBean> beans = conn.queryBeans(queryUtility.getTranslatedQuery());
- if (trace) log.trace("Querying [{0}] returned beans: {1}", queryUtility.getTranslatedQuery(), beans);
+ // Run query for manager_object
+ ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(objectName);
+ List<EmsBean> beans = conn.queryBeans(queryUtility.getTranslatedQuery());
+ if (trace) log.trace("Querying [{0}] returned beans: {1}", queryUtility.getTranslatedQuery(), beans);
- EmsBean bean = beans.get(0);
- String managerName = bean.getBeanName().getCanonicalName();
- String resourceName = bean.getAttribute("Name").getValue().toString();
- String version = bean.getAttribute("Version").getValue().toString();
- /* A discovered resource must have a unique key, that must stay the same when the resource is discovered the next time */
- if (trace) log.trace("Add resource with version '{1}' and type {2}", version, ctx.getResourceType());
- DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
- ctx.getResourceType(), // Resource type
- resourceName, // Resource key
- resourceName, // Resource name
- version, // Resource version
- "A cache manager within Infinispan", // Description
- c, // Plugin config
- null // Process info from a process scan
- );
- log.info("Discovered Infinispan instance with key {0} and name {1}", resourceName, managerName);
- return detail;
+ EmsBean bean = beans.get(0);
+ String managerName = bean.getBeanName().getCanonicalName();
+ String resourceName = bean.getAttribute("Name").getValue().toString();
+ String version = bean.getAttribute("Version").getValue().toString();
+ /* A discovered resource must have a unique key, that must stay the same when the resource is discovered the next time */
+ if (trace) log.trace("Add resource with version '{1}' and type {2}", version, ctx.getResourceType());
+ DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
+ ctx.getResourceType(), // Resource type
+ resourceName, // Resource key
+ resourceName, // Resource name
+ version, // Resource version
+ "A cache manager within Infinispan", // Description
+ c, // Plugin config
+ null // Process info from a process scan
+ );
+ log.info("Discovered Infinispan instance with key {0} and name {1}", resourceName, managerName);
+ return detail;
+ } else {
+ log.debug("Unable to establish connection");
+ return null;
+ }
}
}
\ No newline at end of file
More information about the infinispan-commits
mailing list