modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractManagedDeploymentComponent.java | 10
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerComponent.java | 100 +++---
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/Ejb2BeanComponent.java | 14
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java | 153 ++++++----
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/TxConnectionFactoryComponent.java | 42 +-
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/ManagedComponentUtils.java | 99 ++----
6 files changed, 231 insertions(+), 187 deletions(-)
New commits:
commit f8f501532d2658d814048ecf3879685ddfdff984
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Thu Oct 28 13:07:04 2010 -0500
Perf Work on the AS-5 Plugin to try and reduce avail and metric gathering
times. In general trying to reduce interaction with Profile Service.
1) Cache ManagedComponent in ManagedComponentComponent
This is the base class for resources managed by a profile service
ManagedComponent. It seems that for "runtime" properties gettingthe prop
value returns the live value, so we dont have to get the re-fetch the
ManagedComponent object from the ManagementView. This greatly helps avail checking
Since RunState is a runtime value. It also helps metric collection if all
of the requested metrics are runtime values.
2) Cache whether metrics are runtime or not runtime
Instead of figuring out every time whether requested metrics are runtime
properties, cache this info to save time. This is a static cache so all
instances of the type can share the info.
3) Remove use of ManagedComponentUtils.getManagedComponent()
The PS API added ManagementView.getComponent(name, type), which is more
efficient.
4) Avoid load() when checking avail for ManagedDeployment components (EAR/WAR)
Although it is necessary to re-fetch the ManagedDeployment to get an
updated deployment state, a load of the management view is not necessary.
Conflicts:
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerComponent.java
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java
diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractManagedDeploymentComponent.java b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractManagedDeploymentComponent.java
index bd78958..e925148 100644
--- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractManagedDeploymentComponent.java
+++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractManagedDeploymentComponent.java
@@ -106,7 +106,7 @@ public abstract class AbstractManagedDeploymentComponent extends AbstractManaged
public AvailabilityType getAvailability() {
DeploymentState deploymentState = null;
try {
- deploymentState = getManagedDeployment().getDeploymentState();
+ deploymentState = getManagedDeployment(false).getDeploymentState();
} catch (NoSuchDeploymentException e) {
log.warn(this.deploymentType + " deployment '" + this.deploymentName + "' not found. Cause: "
+ e.getLocalizedMessage());
@@ -186,8 +186,14 @@ public abstract class AbstractManagedDeploymentComponent extends AbstractManaged
}
protected ManagedDeployment getManagedDeployment() throws NoSuchDeploymentException {
+ return getManagedDeployment(true);
+ }
+
+ protected ManagedDeployment getManagedDeployment(boolean forceLoad) throws NoSuchDeploymentException {
ManagementView managementView = getConnection().getManagementView();
- managementView.load();
+ if (forceLoad) {
+ managementView.load();
+ }
return managementView.getDeployment(this.deploymentName);
}
diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerComponent.java b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerComponent.java
index 855791a..5bacccb 100644
--- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerComponent.java
+++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerComponent.java
@@ -35,9 +35,15 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import com.jboss.jbossnetwork.product.jbpm.handlers.ControlActionFacade;
+
+import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.commons.lang.exception.ExceptionUtils;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.mc4j.ems.connection.EmsConnection;
+import org.mc4j.ems.connection.support.metadata.InternalVMTypeDescriptor;
import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.deployers.spi.management.deploy.ProgressEvent;
@@ -49,17 +55,12 @@ import org.jboss.on.common.jbossas.JBPMWorkflowManager;
import org.jboss.on.common.jbossas.JBossASPaths;
import org.jboss.on.common.jbossas.JmxConnectionHelper;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.mc4j.ems.connection.EmsConnection;
-import org.mc4j.ems.connection.support.metadata.InternalVMTypeDescriptor;
-
-import org.rhq.core.domain.content.transfer.DeployPackagesResponse;
-import org.rhq.core.domain.content.transfer.RemovePackagesResponse;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.content.PackageType;
import org.rhq.core.domain.content.transfer.DeployPackageStep;
+import org.rhq.core.domain.content.transfer.DeployPackagesResponse;
+import org.rhq.core.domain.content.transfer.RemovePackagesResponse;
import org.rhq.core.domain.content.transfer.ResourcePackageDetails;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.measurement.DataType;
@@ -88,12 +89,10 @@ import org.rhq.plugins.jbossas5.connection.ProfileServiceConnection;
import org.rhq.plugins.jbossas5.connection.ProfileServiceConnectionProvider;
import org.rhq.plugins.jbossas5.connection.RemoteProfileServiceConnectionProvider;
import org.rhq.plugins.jbossas5.helper.CreateChildResourceFacetDelegate;
-import org.rhq.plugins.jbossas5.helper.JBossAS5ConnectionTypeDescriptor;
import org.rhq.plugins.jbossas5.helper.InPluginControlActionFacade;
+import org.rhq.plugins.jbossas5.helper.JBossAS5ConnectionTypeDescriptor;
import org.rhq.plugins.jbossas5.util.ManagedComponentUtils;
-import com.jboss.jbossnetwork.product.jbpm.handlers.ControlActionFacade;
-
/**
* ResourceComponent for a JBoss AS, 5.1.0.CR1 or later, Server.
*
@@ -144,25 +143,26 @@ public class ApplicationServerComponent implements ResourceComponent, ProfileSer
try {
ManagementView managementView = this.connection.getManagementView();
managementView.load();
-
+
//let's see if the connection corresponds to the server
//this component represents. This is to prevent 2 servers
//with the same JNP URL to be reported as UP when just one
//of them can be up at a time.
- ManagedComponent serverConfig = managementView.getComponentsForType(new ComponentType("MCBean", "ServerConfig")).iterator().next();
-
- String reportedServerHomeDirPath = (String)((SimpleValue)serverConfig.getProperty("serverHomeDir").getValue()).getValue();
-
- String configuredServerHomeDirPath = resourceContext.getPluginConfiguration()
- .getSimpleValue(ApplicationServerPluginConfigurationProperties.SERVER_HOME_DIR, null);
-
+ ManagedComponent serverConfig = managementView.getComponentsForType(
+ new ComponentType("MCBean", "ServerConfig")).iterator().next();
+
+ String reportedServerHomeDirPath = (String) ((SimpleValue) serverConfig.getProperty("serverHomeDir")
+ .getValue()).getValue();
+
+ String configuredServerHomeDirPath = resourceContext.getPluginConfiguration().getSimpleValue(
+ ApplicationServerPluginConfigurationProperties.SERVER_HOME_DIR, null);
+
//the paths might be symlinked
File reportedServerHomeDir = new File(reportedServerHomeDirPath);
File configuredServerHomeDir = new File(configuredServerHomeDirPath);
-
- availability = reportedServerHomeDir.getCanonicalPath().equals(configuredServerHomeDir.getCanonicalPath())
- ? AvailabilityType.UP
- : AvailabilityType.DOWN;
+
+ availability = reportedServerHomeDir.getCanonicalPath().equals(
+ configuredServerHomeDir.getCanonicalPath()) ? AvailabilityType.UP : AvailabilityType.DOWN;
} catch (Exception e) {
availability = AvailabilityType.DOWN;
}
@@ -193,7 +193,8 @@ public class ApplicationServerComponent implements ResourceComponent, ProfileSer
// prepare to perform async avail checking
Configuration pc = resourceContext.getPluginConfiguration();
- String availCheckPeriodProp = pc.getSimpleValue(ApplicationServerPluginConfigurationProperties.AVAIL_CHECK_PERIOD_CONFIG_PROP, null);
+ String availCheckPeriodProp = pc.getSimpleValue(
+ ApplicationServerPluginConfigurationProperties.AVAIL_CHECK_PERIOD_CONFIG_PROP, null);
if (availCheckPeriodProp != null) {
try {
long availCheckMillis = Integer.parseInt(availCheckPeriodProp) * 1000L;
@@ -260,7 +261,7 @@ public class ApplicationServerComponent implements ResourceComponent, ProfileSer
propertyNames.add(ALTERNATE_METRIC_NAMES.get(requestName));
}
throw new IllegalStateException("A property was not found with any of the following names: "
- + propertyNames);
+ + propertyNames);
}
if (value != null) {
@@ -350,10 +351,13 @@ public class ApplicationServerComponent implements ResourceComponent, ProfileSer
connectionProvider = new LocalProfileServiceConnectionProvider();
} else {
Configuration pluginConfig = this.resourceContext.getPluginConfiguration();
- String namingURL = pluginConfig.getSimpleValue(ApplicationServerPluginConfigurationProperties.NAMING_URL, null);
+ String namingURL = pluginConfig.getSimpleValue(ApplicationServerPluginConfigurationProperties.NAMING_URL,
+ null);
validateNamingURL(namingURL);
- String principal = pluginConfig.getSimpleValue(ApplicationServerPluginConfigurationProperties.PRINCIPAL, null);
- String credentials = pluginConfig.getSimpleValue(ApplicationServerPluginConfigurationProperties.CREDENTIALS, null);
+ String principal = pluginConfig.getSimpleValue(ApplicationServerPluginConfigurationProperties.PRINCIPAL,
+ null);
+ String credentials = pluginConfig.getSimpleValue(
+ ApplicationServerPluginConfigurationProperties.CREDENTIALS, null);
connectionProvider = new RemoteProfileServiceConnectionProvider(namingURL, principal, credentials);
}
if (Thread.interrupted()) {
@@ -373,7 +377,7 @@ public class ApplicationServerComponent implements ResourceComponent, ProfileSer
log.warn("Failed to connect to Profile Service - cause: " + rootCause);
}
throw new InvalidPluginConfigurationException(
- "Values of 'principal' and/or 'credentials' connection properties are invalid.", rootCause);
+ "Values of 'principal' and/or 'credentials' connection properties are invalid.", rootCause);
}
log.debug("Failed to connect to Profile Service.", e);
}
@@ -395,15 +399,18 @@ public class ApplicationServerComponent implements ResourceComponent, ProfileSer
private JBossASPaths getJBossASPaths() {
Configuration pluginConfiguration = this.resourceContext.getPluginConfiguration();
- String homeDir = pluginConfiguration.getSimpleValue(ApplicationServerPluginConfigurationProperties.HOME_DIR, null);
- String serverHomeDir = pluginConfiguration.getSimpleValue(ApplicationServerPluginConfigurationProperties.SERVER_HOME_DIR, null);
+ String homeDir = pluginConfiguration.getSimpleValue(ApplicationServerPluginConfigurationProperties.HOME_DIR,
+ null);
+ String serverHomeDir = pluginConfiguration.getSimpleValue(
+ ApplicationServerPluginConfigurationProperties.SERVER_HOME_DIR, null);
return new JBossASPaths(homeDir, serverHomeDir);
}
private boolean runningEmbedded() {
Configuration pluginConfiguration = this.resourceContext.getPluginConfiguration();
- String namingUrl = pluginConfiguration.getSimpleValue(ApplicationServerPluginConfigurationProperties.NAMING_URL, null);
+ String namingUrl = pluginConfiguration.getSimpleValue(
+ ApplicationServerPluginConfigurationProperties.NAMING_URL, null);
return namingUrl == null;
}
@@ -412,7 +419,8 @@ public class ApplicationServerComponent implements ResourceComponent, ProfileSer
File configDir = new File(path);
if (!configDir.isAbsolute()) {
Configuration pluginConfig = this.resourceContext.getPluginConfiguration();
- String homeDir = pluginConfig.getSimple(ApplicationServerPluginConfigurationProperties.HOME_DIR).getStringValue();
+ String homeDir = pluginConfig.getSimple(ApplicationServerPluginConfigurationProperties.HOME_DIR)
+ .getStringValue();
configDir = new File(homeDir, path);
}
return configDir;
@@ -455,7 +463,7 @@ public class ApplicationServerComponent implements ResourceComponent, ProfileSer
public OperationResult invokeOperation(String name, Configuration parameters) throws InterruptedException,
Exception {
-
+
ApplicationServerSupportedOperations operation = Enum.valueOf(ApplicationServerSupportedOperations.class, name
.toUpperCase());
return this.operationDelegate.invoke(operation, parameters);
@@ -466,16 +474,20 @@ public class ApplicationServerComponent implements ResourceComponent, ProfileSer
Configuration jmxConfig = new Configuration();
- String jbossHomeDir = pluginConfiguration.getSimpleValue(ApplicationServerPluginConfigurationProperties.HOME_DIR, null);
+ String jbossHomeDir = pluginConfiguration.getSimpleValue(
+ ApplicationServerPluginConfigurationProperties.HOME_DIR, null);
String connectorDescriptorType;
boolean runningEmbedded = runningEmbedded();
if (runningEmbedded) {
connectorDescriptorType = InternalVMTypeDescriptor.class.getName();
} else {
- String connectorAddress = pluginConfiguration.getSimpleValue(ApplicationServerPluginConfigurationProperties.NAMING_URL, null);
- String connectorPrincipal = pluginConfiguration.getSimpleValue(ApplicationServerPluginConfigurationProperties.PRINCIPAL, null);
- String connectorCredentials = pluginConfiguration.getSimpleValue(ApplicationServerPluginConfigurationProperties.CREDENTIALS, null);
+ String connectorAddress = pluginConfiguration.getSimpleValue(
+ ApplicationServerPluginConfigurationProperties.NAMING_URL, null);
+ String connectorPrincipal = pluginConfiguration.getSimpleValue(
+ ApplicationServerPluginConfigurationProperties.PRINCIPAL, null);
+ String connectorCredentials = pluginConfiguration.getSimpleValue(
+ ApplicationServerPluginConfigurationProperties.CREDENTIALS, null);
connectorDescriptorType = JBossAS5ConnectionTypeDescriptor.class.getName();
@@ -512,7 +524,7 @@ public class ApplicationServerComponent implements ResourceComponent, ProfileSer
private File getConfigurationPath() {
Configuration pluginConfig = this.resourceContext.getPluginConfiguration();
String serverHomeDir = getRequiredPropertyValue(pluginConfig,
- ApplicationServerPluginConfigurationProperties.SERVER_HOME_DIR);
+ ApplicationServerPluginConfigurationProperties.SERVER_HOME_DIR);
File configPath = resolvePathRelativeToHomeDir(serverHomeDir);
if (!configPath.isDirectory()) {
throw new InvalidPluginConfigurationException("Configuration path '" + configPath + "' does not exist.");
@@ -527,7 +539,7 @@ public class ApplicationServerComponent implements ResourceComponent, ProfileSer
Matcher matcher = METRIC_NAME_PATTERN.matcher(metricName);
if (!matcher.matches()) {
throw new IllegalStateException("Metric name '" + metricName + "' does not match pattern '"
- + METRIC_NAME_PATTERN + "'.");
+ + METRIC_NAME_PATTERN + "'.");
}
String componentCategory = matcher.group(1);
String componentSubType = matcher.group(2);
@@ -538,7 +550,13 @@ public class ApplicationServerComponent implements ResourceComponent, ProfileSer
if (componentName.equals("*")) {
component = ManagedComponentUtils.getSingletonManagedComponent(managementView, componentType);
} else {
- component = ManagedComponentUtils.getManagedComponent(managementView, componentType, componentName);
+ //component = ManagedComponentUtils.getManagedComponent(managementView, componentType, componentName);
+ try {
+ component = managementView.getComponent(componentName, componentType);
+ } catch (Exception e) {
+ throw new IllegalStateException("Error fetching component " + componentName + "of type "
+ + componentType);
+ }
}
return ManagedComponentUtils.getSimplePropertyValue(component, propertyName);
diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/Ejb2BeanComponent.java b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/Ejb2BeanComponent.java
index 1eb2219..15ffea3 100644
--- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/Ejb2BeanComponent.java
+++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/Ejb2BeanComponent.java
@@ -24,8 +24,9 @@ package org.rhq.plugins.jbossas5;
import java.util.Set;
-import org.jboss.managed.api.ManagedComponent;
+import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedComponent;
import org.rhq.plugins.jbossas5.util.Ejb2BeanUtils;
@@ -38,26 +39,27 @@ public class Ejb2BeanComponent extends AbstractEjbBeanComponent {
private static final ComponentType MDB_COMPONENT_TYPE = new ComponentType("EJB", "MDB");
@Override
- protected ManagedComponent getManagedComponent() {
+ protected ManagedComponent getManagedComponent(boolean forceRefresh) {
if (MDB_COMPONENT_TYPE.equals(getComponentType())) {
try {
//we need to reload the management view here, because the MDBs might have changed since
//the last call, because the @object-id is part of their names.
- getConnection().getManagementView().load();
+ ManagementView mv = getConnection().getManagementView();
+ mv.load();
- Set<ManagedComponent> mdbs = getConnection().getManagementView().getComponentsForType(
- MDB_COMPONENT_TYPE);
+ Set<ManagedComponent> mdbs = mv.getComponentsForType(MDB_COMPONENT_TYPE);
for (ManagedComponent mdb : mdbs) {
if (getComponentName().equals(Ejb2BeanUtils.getUniqueBeanIdentificator(mdb))) {
return mdb;
}
}
+
} catch (Exception e) {
throw new IllegalStateException(e);
}
} else {
- return super.getManagedComponent();
+ return super.getManagedComponent(forceRefresh);
}
return null;
diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java
index 7c70bc7..6d564ee 100644
--- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java
+++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java
@@ -24,12 +24,16 @@ package org.rhq.plugins.jbossas5;
import java.lang.reflect.Array;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.deployers.spi.management.deploy.DeploymentManager;
import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
@@ -40,20 +44,17 @@ import org.jboss.managed.api.ManagedDeployment;
import org.jboss.managed.api.ManagedOperation;
import org.jboss.managed.api.ManagedProperty;
import org.jboss.managed.api.RunState;
+import org.jboss.managed.api.annotation.ViewUse;
import org.jboss.metatype.api.values.ArrayValue;
import org.jboss.metatype.api.values.CollectionValue;
import org.jboss.metatype.api.values.CompositeValue;
import org.jboss.metatype.api.values.EnumValue;
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.metatype.api.values.SimpleValue;
-import org.jboss.remoting.CannotConnectException;
-
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
+import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.measurement.DataType;
@@ -72,11 +73,10 @@ import org.rhq.core.pluginapi.operation.OperationFacet;
import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.core.util.exception.ThrowableUtil;
import org.rhq.plugins.jbossas5.util.ConversionUtils;
+import org.rhq.plugins.jbossas5.util.DebugUtils;
import org.rhq.plugins.jbossas5.util.DeploymentUtils;
-import org.rhq.plugins.jbossas5.util.ManagedComponentUtils;
-import org.rhq.plugins.jbossas5.util.ResourceTypeUtils;
import org.rhq.plugins.jbossas5.util.ResourceComponentUtils;
-import org.rhq.plugins.jbossas5.util.DebugUtils;
+import org.rhq.plugins.jbossas5.util.ResourceTypeUtils;
/**
* Service ResourceComponent for all {@link ManagedComponent}s in a Profile.
@@ -93,12 +93,19 @@ public class ManagedComponentComponent extends AbstractManagedComponent implemen
String COMPONENT_NAME = "componentName";
String TEMPLATE_NAME = "templateName";
String COMPONENT_NAME_PROPERTY = "componentNameProperty";
- }
+ }
protected static final char PREFIX_DELIMITER = '|';
+ // Map the managedComponentComponent class name to a map of metricName to "isRuntimeProp". So, for a given
+ // component we can quickly determine whether requested metrics need to refresh the managedComponent, or not.
+ private static final Map<String, Map<String, Boolean>> runtimeMetricMaps = new HashMap<String, Map<String, Boolean>>();
+
private final Log log = LogFactory.getLog(this.getClass());
+ // Cache the ManagedComponent since it can be re-used to request any ViewUse.RUNTIME property values
+ private ManagedComponent managedComponent = null;
+
private String componentName;
private ComponentType componentType;
@@ -109,15 +116,15 @@ public class ManagedComponentComponent extends AbstractManagedComponent implemen
try {
runState = getManagedComponent().getRunState();
} catch (Throwable t) {
- log.debug("Could not get component state for " + this.componentType + " component '"
- + this.componentName + "', cause: ", t);
+ log.debug("Could not get component state for " + this.componentType + " component '" + this.componentName
+ + "', cause: ", t);
return AvailabilityType.DOWN;
}
if (runState == RunState.RUNNING) {
return AvailabilityType.UP;
} else {
- log.debug(this.componentType + " component '" + this.componentName + "' was not running, state" +
- " was: " + runState);
+ log.debug(this.componentType + " component '" + this.componentName + "' was not running, state" + " was: "
+ + runState);
return AvailabilityType.DOWN;
}
}
@@ -132,58 +139,51 @@ public class ManagedComponentComponent extends AbstractManagedComponent implemen
}
public void stop() {
- return;
+ managedComponent = null;
+ super.stop();
}
// ConfigurationComponent Implementation --------------------------------------------
- public Configuration loadResourceConfiguration()
- {
+ public Configuration loadResourceConfiguration() {
Configuration resourceConfig;
- try
- {
+ try {
Map<String, ManagedProperty> managedProperties = getManagedComponent().getProperties();
- Map<String, PropertySimple> customProps =
- ResourceComponentUtils.getCustomProperties(getResourceContext().getPluginConfiguration());
- if (this.log.isDebugEnabled()) this.log.debug("*** AFTER LOAD:\n"
- + DebugUtils.convertPropertiesToString(managedProperties));
- resourceConfig = ConversionUtils.convertManagedObjectToConfiguration(managedProperties,
- customProps, getResourceContext().getResourceType());
- }
- catch (Exception e)
- {
+ Map<String, PropertySimple> customProps = ResourceComponentUtils.getCustomProperties(getResourceContext()
+ .getPluginConfiguration());
+ if (this.log.isDebugEnabled())
+ this.log.debug("*** AFTER LOAD:\n" + DebugUtils.convertPropertiesToString(managedProperties));
+ resourceConfig = ConversionUtils.convertManagedObjectToConfiguration(managedProperties, customProps,
+ getResourceContext().getResourceType());
+ } catch (Exception e) {
RunState runState = getManagedComponent().getRunState();
if (runState == RunState.RUNNING) {
- this.log.error("Failed to load configuration for " + getResourceDescription() + ".", e);
+ this.log.error("Failed to load configuration for " + getResourceDescription() + ".", e);
} else {
- this.log.debug("Failed to load configuration for " + getResourceDescription()
- + ", but managed component is not in the RUNNING state.", e);
+ this.log.debug("Failed to load configuration for " + getResourceDescription()
+ + ", but managed component is not in the RUNNING state.", e);
}
throw new RuntimeException(ThrowableUtil.getAllMessages(e));
}
return resourceConfig;
}
- public void updateResourceConfiguration(ConfigurationUpdateReport configurationUpdateReport)
- {
+ public void updateResourceConfiguration(ConfigurationUpdateReport configurationUpdateReport) {
Configuration resourceConfig = configurationUpdateReport.getConfiguration();
Configuration pluginConfig = getResourceContext().getPluginConfiguration();
- try
- {
+ try {
ManagedComponent managedComponent = getManagedComponent();
Map<String, ManagedProperty> managedProperties = managedComponent.getProperties();
Map<String, PropertySimple> customProps = ResourceComponentUtils.getCustomProperties(pluginConfig);
- if (this.log.isDebugEnabled()) this.log.debug("*** BEFORE UPDATE:\n"
- + DebugUtils.convertPropertiesToString(managedProperties));
+ if (this.log.isDebugEnabled())
+ this.log.debug("*** BEFORE UPDATE:\n" + DebugUtils.convertPropertiesToString(managedProperties));
ConversionUtils.convertConfigurationToManagedProperties(managedProperties, resourceConfig,
- getResourceContext().getResourceType(), customProps);
- if (this.log.isDebugEnabled()) this.log.debug("*** AFTER UPDATE:\n"
- + DebugUtils.convertPropertiesToString(managedProperties));
+ getResourceContext().getResourceType(), customProps);
+ if (this.log.isDebugEnabled())
+ this.log.debug("*** AFTER UPDATE:\n" + DebugUtils.convertPropertiesToString(managedProperties));
updateComponent(managedComponent);
configurationUpdateReport.setStatus(ConfigurationUpdateStatus.SUCCESS);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
this.log.error("Failed to update configuration for " + getResourceDescription() + ".", e);
configurationUpdateReport.setStatus(ConfigurationUpdateStatus.FAILURE);
configurationUpdateReport.setErrorMessage(ThrowableUtil.getAllMessages(e));
@@ -234,7 +234,36 @@ public class ManagedComponentComponent extends AbstractManagedComponent implemen
// MeasurementFacet Implementation --------------------------------------------
public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception {
- ManagedComponent managedComponent = getManagedComponent();
+ // this bit could be synchronized but I don't think it really hurts to perhaps go through this logic more
+ // than once, it will settle down near immediately
+ Map<String, Boolean> runtimeMetricMap = runtimeMetricMaps.get(this.getClass().getName());
+ if (null == runtimeMetricMap) {
+ //log.info("\nADDING MAP FOR CLASS=" + this.getClass().getName());
+ runtimeMetricMap = new HashMap<String, Boolean>();
+ runtimeMetricMaps.put(this.getClass().getName(), runtimeMetricMap);
+ }
+
+ // determine whether we can use the cachedComponent or if we need to force a component fetch to
+ // gather the requested metrics.
+ boolean forceRefresh = false;
+ for (MeasurementScheduleRequest request : metrics) {
+ Boolean isRuntimeMetric = runtimeMetricMap.get(request.getName());
+ // if this is the first time we've seen this metric find out if it's a runtime prop
+ if (null == isRuntimeMetric) {
+ //log.info("\nADDING MAP ENTRY FOR METRIC=" + request.getName());
+ ManagedProperty managedProp = getManagedProperty(managedComponent, request);
+ runtimeMetricMap.put(request.getName(), Boolean.valueOf((null == managedProp || managedProp
+ .hasViewUse(ViewUse.RUNTIME))));
+ }
+
+ if (Boolean.FALSE.equals(runtimeMetricMap.get(request.getName()))) {
+ //log.info("\nFORCING COMPONENT REFRESH DUE TO NON-RUNTIME PROP: " + request.getName());
+ forceRefresh = true;
+ break;
+ }
+ }
+
+ ManagedComponent managedComponent = getManagedComponent(forceRefresh);
RunState runState = managedComponent.getRunState();
for (MeasurementScheduleRequest request : metrics) {
try {
@@ -249,7 +278,7 @@ public class ManagedComponentComponent extends AbstractManagedComponent implemen
log.error("Failed to collect metric for " + request, e);
} else {
log.debug("Failed to collect metric for " + request
- + ", but managed component is not in the RUNNING state.", e);
+ + ", but managed component is not in the RUNNING state.", e);
}
}
}
@@ -297,6 +326,29 @@ public class ManagedComponentComponent extends AbstractManagedComponent implemen
return getInnerValue(metaValue);
}
+ /**
+ * The name of the measurement schedule request (i.e. the metric name) can be in one of two forms:
+ * <p/>
+ * [prefix'|']simplePropertyName (e.g. "maxTime" or "ThreadPool|currentThreadCount")
+ * [prefix'|']compositePropertyName'.'key (e.g. "consumerCount" or "messageStatistics.count")
+ *
+ * @param managedComponent a managed component
+ * @param request a measurement schedule request
+ * @return the metric value
+ */
+ @Nullable
+ protected ManagedProperty getManagedProperty(ManagedComponent managedComponent, MeasurementScheduleRequest request) {
+ String metricName = request.getName();
+ int pipeIndex = metricName.indexOf(PREFIX_DELIMITER);
+ // Remove the prefix if there is one (e.g. "ThreadPool|currentThreadCount" -> "currentThreadCount").
+ String compositePropName = (pipeIndex == -1) ? metricName : metricName.substring(pipeIndex + 1);
+ int dotIndex = compositePropName.indexOf('.');
+ String metricPropName = (dotIndex == -1) ? compositePropName : compositePropName.substring(0, dotIndex);
+ ManagedProperty metricProp = managedComponent.getProperty(metricPropName);
+
+ return metricProp;
+ }
+
// TODO: Move this to a utility class.
@Nullable
private static Object getInnerValue(MetaValue metaValue) {
@@ -362,11 +414,18 @@ public class ManagedComponentComponent extends AbstractManagedComponent implemen
}
protected ManagedComponent getManagedComponent() {
- ManagedComponent managedComponent;
+ return getManagedComponent(false);
+ }
+
+ protected ManagedComponent getManagedComponent(boolean forceRefresh) {
+
+ if (!forceRefresh && null != this.managedComponent) {
+ return this.managedComponent;
+ }
+
try {
ManagementView managementView = getConnection().getManagementView();
- managedComponent = ManagedComponentUtils.getManagedComponent(managementView, this.componentType,
- this.componentName);
+ managedComponent = managementView.getComponent(this.componentName, this.componentType);
} catch (Exception e) {
throw new RuntimeException("Failed to load [" + this.componentType + "] ManagedComponent ["
+ this.componentName + "].", e);
diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/TxConnectionFactoryComponent.java b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/TxConnectionFactoryComponent.java
index 07f4462..cdfa98b 100644
--- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/TxConnectionFactoryComponent.java
+++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/TxConnectionFactoryComponent.java
@@ -27,47 +27,41 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.rhq.core.domain.measurement.MeasurementDataTrait;
-import org.rhq.core.domain.measurement.MeasurementReport;
-import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedProperty;
import org.jboss.metatype.api.values.SimpleValue;
+import org.rhq.core.domain.measurement.MeasurementDataTrait;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+
/**
* A Resource component for JBoss AS 5 Tx Connection Factories.
*
* @author Ian Springer
*/
-public class TxConnectionFactoryComponent extends ManagedComponentComponent
-{
+public class TxConnectionFactoryComponent extends ManagedComponentComponent {
private final Log log = LogFactory.getLog(this.getClass());
@Override
- public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception
- {
- Set<MeasurementScheduleRequest> uncollectedMetrics = new HashSet();
- for (MeasurementScheduleRequest request : metrics)
- {
- try
- {
- if (request.getName().equals("custom.transactionType"))
- {
- ManagedProperty xaTransactionProp = getManagedComponent().getProperty("xa-transaction");
- SimpleValue xaTransactionMetaValue = (SimpleValue)xaTransactionProp.getValue();
- Boolean xaTransactionValue = (xaTransactionMetaValue != null)
- ? (Boolean)xaTransactionMetaValue.getValue() : null;
+ public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception {
+ ManagedComponent mc = getManagedComponent(true);
+ Set<MeasurementScheduleRequest> uncollectedMetrics = new HashSet<MeasurementScheduleRequest>();
+ for (MeasurementScheduleRequest request : metrics) {
+ try {
+ if (request.getName().equals("custom.transactionType")) {
+ ManagedProperty xaTransactionProp = mc.getProperty("xa-transaction");
+ SimpleValue xaTransactionMetaValue = (SimpleValue) xaTransactionProp.getValue();
+ Boolean xaTransactionValue = (xaTransactionMetaValue != null) ? (Boolean) xaTransactionMetaValue
+ .getValue() : null;
boolean isXa = (xaTransactionValue != null && xaTransactionValue);
String transactionType = (isXa) ? "XA" : "Local";
report.addData(new MeasurementDataTrait(request, transactionType));
- }
- else
- {
+ } else {
uncollectedMetrics.add(request);
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
log.error("Failed to collect metric for " + request, e);
}
}
diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/ManagedComponentUtils.java b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/ManagedComponentUtils.java
index b928584..a08a043 100644
--- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/ManagedComponentUtils.java
+++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/ManagedComponentUtils.java
@@ -23,12 +23,13 @@
package org.rhq.plugins.jbossas5.util;
import java.io.Serializable;
+import java.util.Comparator;
import java.util.EnumSet;
-import java.util.Set;
import java.util.HashSet;
-import java.util.Comparator;
+import java.util.Set;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.deployers.spi.management.NameMatcher;
@@ -39,78 +40,53 @@ import org.jboss.managed.api.annotation.ViewUse;
import org.jboss.metatype.api.types.MetaType;
import org.jboss.metatype.api.values.EnumValue;
import org.jboss.metatype.api.values.SimpleValue;
-import org.jetbrains.annotations.Nullable;
/**
* A collection of utility methods for working with Profile Service {@link ManagedComponent}s.
*
* @author Ian Springer
*/
-public class ManagedComponentUtils
-{
+public class ManagedComponentUtils {
private static final Comparator<ComponentType> COMPONENT_TYPE_COMPARATOR = new ComponentTypeComparator();
@Nullable
- public static ManagedComponent getManagedComponent(ManagementView managementView, ComponentType componentType,
- String componentName)
- {
- Set<ManagedComponent> components = getManagedComponents(managementView, componentType);
- for (ManagedComponent component : components)
- {
- if (component.getName().equals(componentName))
- return component;
- }
- return null;
- }
-
- @Nullable
public static ManagedComponent getSingletonManagedComponent(ManagementView managementView,
- ComponentType componentType)
- {
+ ComponentType componentType) {
Set<ManagedComponent> components = getManagedComponents(managementView, componentType);
- if (components.size() > 1)
- {
+ if (components.size() > 1) {
throw new IllegalStateException("Found more than one component of type " + componentType + ": "
- + components);
+ + components);
}
- @SuppressWarnings({"UnnecessaryLocalVariable"})
+ @SuppressWarnings( { "UnnecessaryLocalVariable" })
ManagedComponent component = (components.size() == 1) ? components.iterator().next() : null;
return component;
}
public static Serializable getSimplePropertyValue(ManagedComponent component, String propertyName)
- throws PropertyNotFoundException {
+ throws PropertyNotFoundException {
ManagedProperty property = component.getProperty(propertyName);
- if (property == null)
- {
- throw new PropertyNotFoundException("Property named '" + propertyName + "' not found for ManagedComponent ["
- + component + "].");
+ if (property == null) {
+ throw new PropertyNotFoundException("Property named '" + propertyName
+ + "' not found for ManagedComponent [" + component + "].");
}
MetaType metaType = property.getMetaType();
Serializable value;
- if (metaType.isSimple())
- {
- SimpleValue simpleValue = (SimpleValue)property.getValue();
+ if (metaType.isSimple()) {
+ SimpleValue simpleValue = (SimpleValue) property.getValue();
value = (simpleValue != null) ? simpleValue.getValue() : null;
- }
- else if (metaType.isEnum())
- {
- EnumValue enumValue = (EnumValue)property.getValue();
+ } else if (metaType.isEnum()) {
+ EnumValue enumValue = (EnumValue) property.getValue();
value = (enumValue != null) ? enumValue.getValue() : null;
- }
- else
- {
+ } else {
throw new IllegalStateException("Type of [" + property + "] is not simple or enum.");
}
return value;
}
@NotNull
- public static EnumSet<ViewUse> getViewUses(ManagedProperty managedProperty)
- {
+ public static EnumSet<ViewUse> getViewUses(ManagedProperty managedProperty) {
EnumSet<ViewUse> viewUses = EnumSet.noneOf(ViewUse.class);
- for (ViewUse viewUse : ViewUse.values())
- {
+ for (ViewUse viewUse : ViewUse.values()) {
if (managedProperty.hasViewUse(viewUse))
viewUses.add(viewUse);
}
@@ -120,19 +96,15 @@ public class ManagedComponentUtils
/**
* TODO
*/
- public static boolean isManagedComponent(ManagementView managementView, String name, ComponentType componentType)
- {
+ public static boolean isManagedComponent(ManagementView managementView, String name, ComponentType componentType) {
boolean isDeployed = false;
- if (name != null)
- {
- try
- {
- ManagedComponent component = getManagedComponent(managementView, componentType, name);
+ if (name != null) {
+ try {
+ //ManagedComponent component = getManagedComponent(managementView, componentType, name);
+ ManagedComponent component = managementView.getComponent(name, componentType);
if (component != null)
isDeployed = true;
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
// Setting it to true to be safe than sorry, since there might be a component
// already deployed in the AS. TODO (ips): I don't think I like this.
isDeployed = true;
@@ -142,9 +114,8 @@ public class ManagedComponentUtils
}
@NotNull
- public static Set<ManagedComponent> getManagedComponents(ManagementView managementView, ComponentType componentType,
- String name, NameMatcher<ManagedComponent> nameMatcher)
- {
+ public static Set<ManagedComponent> getManagedComponents(ManagementView managementView,
+ ComponentType componentType, String name, NameMatcher<ManagedComponent> nameMatcher) {
Set<ManagedComponent> matchingComponents = new HashSet<ManagedComponent>();
Set<ManagedComponent> allComponents = getManagedComponents(managementView, componentType);
for (ManagedComponent component : allComponents) {
@@ -160,24 +131,18 @@ public class ManagedComponentUtils
}
@NotNull
- private static Set<ManagedComponent> getManagedComponents(ManagementView managementView, ComponentType componentType)
- {
+ private static Set<ManagedComponent> getManagedComponents(ManagementView managementView, ComponentType componentType) {
Set<ManagedComponent> components;
- try
- {
+ try {
components = managementView.getComponentsForType(componentType);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
throw new IllegalStateException(e);
}
return components;
}
- private static class ComponentTypeComparator implements Comparator<ComponentType>
- {
- public int compare(ComponentType type1, ComponentType type2)
- {
+ private static class ComponentTypeComparator implements Comparator<ComponentType> {
+ public int compare(ComponentType type1, ComponentType type2) {
int value = type1.getType().compareTo(type2.getType());
// If the categories (e.g. JMSDestination) were equal, do a secondary sort by subtype (e.g. Queue).
return (value != 0) ? value : type1.getSubtype().compareTo(type2.getSubtype());