modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataManager.java | 48 - modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataParser.java | 28 modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java | 463 +++++----- 3 files changed, 277 insertions(+), 262 deletions(-)
New commits: commit d1abc21a90e34fe2105289cba14cefd12d4edba7 Author: Heiko W. Rupp hwr@redhat.com Date: Wed Oct 20 17:38:08 2010 +0200
Be less verbose - it is expected that only a few types support the child type discovery facet
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java index 7567324..8e0347e 100644 --- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java +++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java @@ -1,230 +1,233 @@ -package org.rhq.core.pc.inventory; - -/* - * 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. - */ - -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.Callable; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.rhq.core.clientapi.agent.PluginContainerException; -import org.rhq.core.domain.measurement.AvailabilityType; -import org.rhq.core.domain.resource.Resource; -import org.rhq.core.domain.resource.ResourceCategory; -import org.rhq.core.domain.resource.ResourceType; -import org.rhq.core.pc.PluginContainer; -import org.rhq.core.pc.util.ComponentUtil; -import org.rhq.core.pc.util.FacetLockType; -import org.rhq.core.pluginapi.inventory.ChildResourceTypeDiscoveryFacet; -import org.rhq.core.util.exception.ThrowableUtil; - -public class ChildResourceTypeDiscoveryRunner implements Callable<Set<ResourceType>>, Runnable { - - private Log log = LogFactory.getLog(ChildResourceTypeDiscoveryRunner.class); - - //Default Ctor - public ChildResourceTypeDiscoveryRunner() { - - } - - public void run() { - try { - call(); - } catch (Exception e) { - log.error("Could not get measurement report.", e); - } - } - - public Set<ResourceType> call() { - - if (log.isDebugEnabled()) { - log.info("<ChildResourceTypeDiscoveryRunner>call() called"); - } - - //Set<ResourceTypes> for the ResourceTypes which shall be added later - Set<ResourceType> resourceTypes = null; - - long start = System.currentTimeMillis(); - - //get InventoryManager instance - InventoryManager im = PluginContainer.getInstance().getInventoryManager(); - - if (log.isDebugEnabled()) { - log.info("InventoryManager instance created"); - } - - //Get current plattform - Resource platform = im.getPlatform(); - if (log.isDebugEnabled()) { - log.info("Platform returned with name: " + platform.getName()); - } - - // Next discover all other services and non-top-level servers - Set<Resource> children = platform.getChildResources(); - if (log.isDebugEnabled()) { - log.info("Platform " + platform.getName() + " has " + children.size() + " ChildResources"); - } - - if (children != null) { - for (Resource child : children) { - if (log.isDebugEnabled()) { - log.debug("Name of server: " + child.getName()); - log.debug("Id of server: " + child.getId()); - log.debug("Category of server: " + child.getResourceType().getCategory().toString()); - } - - //Check if really is of Category SERVER because our Plugin has to be of that category - if (child.getResourceType().getCategory() == ResourceCategory.SERVER) { - - if (log.isDebugEnabled()) { - log.info("Server " + child.getName() + "has passed the Server Category test succesfull"); - } - - ResourceContainer container = im.getResourceContainer(child.getId()); - - if (log.isDebugEnabled()) { - log.info("Server " + child.getName() + " is running in ResourceContainer " - + container.toString()); - } - - if (container.getResourceComponentState() != ResourceContainer.ResourceComponentState.STARTED - || container.getAvailability() == null - || container.getAvailability().getAvailabilityType() == AvailabilityType.DOWN) { - // Don't collect metrics for resources that are down - if (log.isDebugEnabled()) { - log.info("ChildType not discoverd for inactive resource component: " - + container.getResource()); - } - } else { - - try { - - //Get Facet Component - ChildResourceTypeDiscoveryFacet discoveryComponent = ComponentUtil.getComponent(child - .getId(), ChildResourceTypeDiscoveryFacet.class, FacetLockType.READ, 30 * 1000, true, - true); - - //get Set<ResourceType> --> all the ChildResourceTypes which shall be added dynamically - resourceTypes = discoverChildResourceTypes(discoveryComponent); - - if (log.isDebugEnabled()) { - log.info("Container.getResource(): " + container.getResource().getName()); - log.info("Container.getResource().getResourceType(): " - + container.getResource().getResourceType().getName()); - - } - - //all the ChildResourceTypes which are already part of the plugin - Set<ResourceType> currentChildTypes = container.getResource().getResourceType() - .getChildResourceTypes(); - - if (log.isDebugEnabled()) { - log.info("Current existing types:"); - for (ResourceType type : currentChildTypes) { - log.info(type.getName()); - } - } - - Set<ResourceType> newTypesToAdd = new HashSet<ResourceType>(); - - if (log.isDebugEnabled()) { - log.info("Size of HashSet<ResourceType> after initialisation: " + newTypesToAdd.size()); - } - - //Check all types with were added by the plugin - for (ResourceType newTypetoAdd : resourceTypes) { - //Check all ChildResourceTypes that already exist - boolean childAllreadyExists = false; - - for (ResourceType alreadyExistingType : currentChildTypes) { - //Check if name and plugin of the types are equal - //Necessary because equal-named ChildResourceTypes can belong to different plugins - if (newTypetoAdd.getName().equals(alreadyExistingType.getName()) - && newTypetoAdd.getPlugin().equals(alreadyExistingType.getPlugin())) { - log.info("The ResourceType " + newTypetoAdd.getName() - + " already exists for the Plugin " + newTypetoAdd.getPlugin()); - - //if ResourceType already exists set boolean var to true - childAllreadyExists = true; - } - } - - //Check if type does not already exist, only add ResourceType to set if so - if (!childAllreadyExists) { - if (log.isDebugEnabled()) { - log.info("new ChildResourceType " + newTypetoAdd.getName() - + " added to Set<ResourceTypes>"); - } - newTypesToAdd.add(newTypetoAdd); - } - } - - //Create a new ResourceType in the DB for the selected type - //call InventoryManager method only if Set<ResourceType> contains at least one element - if (newTypesToAdd.size() > 0) { - - //pass the Set<Resourcetype> to the inventory manager - im.createNewResourceType(newTypesToAdd); - } - - } catch (PluginContainerException pce) { - // This is expected when the ResourceComponent does not implement the ChildResourceTypeDiscoveryFacet - log.warn("Error submitting service scan: " + pce.getMessage()); - } catch (Exception e) { - throw new RuntimeException("Error submitting service scan", e); - } - } - } - } - - } else { - log.info("Set<ResourceType> was returned with value null"); - } - - return null; - } - - /** - * - * @param discoveryComponent - * @return - */ - private Set<ResourceType> discoverChildResourceTypes(ChildResourceTypeDiscoveryFacet discoveryComponent) { - - Set<ResourceType> resourceTypes = null; - try { - long start = System.currentTimeMillis(); - resourceTypes = discoveryComponent.discoverChildResourceTypes(); - long duration = (System.currentTimeMillis() - start); - - if (duration > 2000) { - log.info("[PERF] Discovery of childResourceTypes for [" + discoveryComponent + "] took [" + duration - + "ms]"); - } - } catch (Throwable t) { - - log.warn("Failure to discover childResourceType data - cause: " + ThrowableUtil.getAllMessages(t)); - } - - return resourceTypes; - } -} +package org.rhq.core.pc.inventory; + +/* + * 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. + */ + +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.Callable; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.rhq.core.clientapi.agent.PluginContainerException; +import org.rhq.core.domain.measurement.AvailabilityType; +import org.rhq.core.domain.resource.Resource; +import org.rhq.core.domain.resource.ResourceCategory; +import org.rhq.core.domain.resource.ResourceType; +import org.rhq.core.pc.PluginContainer; +import org.rhq.core.pc.util.ComponentUtil; +import org.rhq.core.pc.util.FacetLockType; +import org.rhq.core.pluginapi.inventory.ChildResourceTypeDiscoveryFacet; +import org.rhq.core.util.exception.ThrowableUtil; + +public class ChildResourceTypeDiscoveryRunner implements Callable<Set<ResourceType>>, Runnable { + + private Log log = LogFactory.getLog(ChildResourceTypeDiscoveryRunner.class); + + //Default Ctor + public ChildResourceTypeDiscoveryRunner() { + + } + + public void run() { + try { + call(); + } catch (Exception e) { + log.error("Could not get measurement report.", e); + } + } + + public Set<ResourceType> call() { + + if (log.isDebugEnabled()) { + log.info("<ChildResourceTypeDiscoveryRunner>call() called"); + } + + //Set<ResourceTypes> for the ResourceTypes which shall be added later + Set<ResourceType> resourceTypes = null; + + long start = System.currentTimeMillis(); + + //get InventoryManager instance + InventoryManager im = PluginContainer.getInstance().getInventoryManager(); + + if (log.isDebugEnabled()) { + log.info("InventoryManager instance created"); + } + + //Get current plattform + Resource platform = im.getPlatform(); + if (log.isDebugEnabled()) { + log.info("Platform returned with name: " + platform.getName()); + } + + // Next discover all other services and non-top-level servers + Set<Resource> children = platform.getChildResources(); + if (log.isDebugEnabled()) { + log.info("Platform " + platform.getName() + " has " + children.size() + " ChildResources"); + } + + if (children != null) { + for (Resource child : children) { + if (log.isDebugEnabled()) { + log.debug("Name of server: " + child.getName()); + log.debug("Id of server: " + child.getId()); + log.debug("Category of server: " + child.getResourceType().getCategory().toString()); + } + + //Check if really is of Category SERVER because our Plugin has to be of that category + if (child.getResourceType().getCategory() == ResourceCategory.SERVER) { + + if (log.isDebugEnabled()) { + log.info("Server " + child.getName() + "has passed the Server Category test succesfull"); + } + + ResourceContainer container = im.getResourceContainer(child.getId()); + + if (log.isDebugEnabled()) { + log.info("Server " + child.getName() + " is running in ResourceContainer " + + container.toString()); + } + + if (container.getResourceComponentState() != ResourceContainer.ResourceComponentState.STARTED + || container.getAvailability() == null + || container.getAvailability().getAvailabilityType() == AvailabilityType.DOWN) { + // Don't collect metrics for resources that are down + if (log.isDebugEnabled()) { + log.info("ChildType not discoverd for inactive resource component: " + + container.getResource()); + } + } else { + + try { + + //Get Facet Component + ChildResourceTypeDiscoveryFacet discoveryComponent = ComponentUtil.getComponent(child + .getId(), ChildResourceTypeDiscoveryFacet.class, FacetLockType.READ, 30 * 1000, true, + true); + + //get Set<ResourceType> --> all the ChildResourceTypes which shall be added dynamically + resourceTypes = discoverChildResourceTypes(discoveryComponent); + + if (log.isDebugEnabled()) { + log.info("Container.getResource(): " + container.getResource().getName()); + log.info("Container.getResource().getResourceType(): " + + container.getResource().getResourceType().getName()); + + } + + //all the ChildResourceTypes which are already part of the plugin + Set<ResourceType> currentChildTypes = container.getResource().getResourceType() + .getChildResourceTypes(); + + if (log.isDebugEnabled()) { + log.info("Current existing types:"); + for (ResourceType type : currentChildTypes) { + log.info(type.getName()); + } + } + + Set<ResourceType> newTypesToAdd = new HashSet<ResourceType>(); + + if (log.isDebugEnabled()) { + log.info("Size of HashSet<ResourceType> after initialisation: " + newTypesToAdd.size()); + } + + //Check all types with were added by the plugin + for (ResourceType newTypetoAdd : resourceTypes) { + //Check all ChildResourceTypes that already exist + boolean childAllreadyExists = false; + + for (ResourceType alreadyExistingType : currentChildTypes) { + //Check if name and plugin of the types are equal + //Necessary because equal-named ChildResourceTypes can belong to different plugins + if (newTypetoAdd.getName().equals(alreadyExistingType.getName()) + && newTypetoAdd.getPlugin().equals(alreadyExistingType.getPlugin())) { + log.info("The ResourceType " + newTypetoAdd.getName() + + " already exists for the Plugin " + newTypetoAdd.getPlugin()); + + //if ResourceType already exists set boolean var to true + childAllreadyExists = true; + } + } + + //Check if type does not already exist, only add ResourceType to set if so + if (!childAllreadyExists) { + if (log.isDebugEnabled()) { + log.info("new ChildResourceType " + newTypetoAdd.getName() + + " added to Set<ResourceTypes>"); + } + newTypesToAdd.add(newTypetoAdd); + } + } + + //Create a new ResourceType in the DB for the selected type + //call InventoryManager method only if Set<ResourceType> contains at least one element + if (newTypesToAdd.size() > 0) { + + //pass the Set<Resourcetype> to the inventory manager + im.createNewResourceType(newTypesToAdd); + } + + } catch (PluginContainerException pce) { + // This is expected when the ResourceComponent does not implement the ChildResourceTypeDiscoveryFacet + if (pce.getMessage().contains("does not support") && pce.getMessage().contains("ChildResourceTypeDiscoveryFacet")) + log.debug("ChildResourceTypeDiscoveryFacet not supported"); + else + log.warn("Error submitting service scan: " + pce.getMessage()); + } catch (Exception e) { + throw new RuntimeException("Error submitting service scan", e); + } + } + } + } + + } else { + log.info("Set<ResourceType> was returned with value null"); + } + + return null; + } + + /** + * + * @param discoveryComponent + * @return + */ + private Set<ResourceType> discoverChildResourceTypes(ChildResourceTypeDiscoveryFacet discoveryComponent) { + + Set<ResourceType> resourceTypes = null; + try { + long start = System.currentTimeMillis(); + resourceTypes = discoveryComponent.discoverChildResourceTypes(); + long duration = (System.currentTimeMillis() - start); + + if (duration > 2000) { + log.info("[PERF] Discovery of childResourceTypes for [" + discoveryComponent + "] took [" + duration + + "ms]"); + } + } catch (Throwable t) { + + log.warn("Failure to discover childResourceType data - cause: " + ThrowableUtil.getAllMessages(t)); + } + + return resourceTypes; + } +}
commit 80b347e94018454644de33e4510a1ab49f125824 Author: Heiko W. Rupp hwr@redhat.com Date: Wed Oct 20 17:31:38 2010 +0200
Parse the plugin descriptor for childType(Discovery) attributes and use this on dynamic types to run discovery on the passed resource type.
diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataManager.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataManager.java index e0c0e25..0384a38 100644 --- a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataManager.java +++ b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataManager.java @@ -92,44 +92,54 @@ public class PluginMetadataManager {
PluginMetadataParser parser = this.parsersByPlugin.get(resourceType.getPlugin());
-// if (parser.getDescriptor().getName().equals("NagiosMonitor")) { -// return (parser != null) ? parser.getChildTypeDiscoveryComponentClass(resourceType) : null; -// } else { -// return (parser != null) ? parser.getDiscoveryComponentClass(resourceType) : null; -// } if (parser==null) return null;
+ + // Prefer hard coded types (= types from the plugin descriptor) + String discoveryComponentClass = parser.getDiscoveryComponentClass(resourceType); + if (discoveryComponentClass!=null) + return discoveryComponentClass; + + // Not in plugin descriptor? Check if the parent supports dynamic type discovery + // and use the discovery class from there if (resourceType.getParentResourceTypes()!=null && !resourceType.getParentResourceTypes().isEmpty()) { ResourceType parent = resourceType.getParentResourceTypes().iterator().next(); - if (parser.getChildTypeDiscoveryComponentClass(parent)!=null) - return parser.getChildTypeDiscoveryComponentClass(parent); - } + String childTypeDiscoveryComponentClass = parser.getChildTypeDiscoveryComponentClass(parent);
- return parser.getDiscoveryComponentClass(resourceType); + if (childTypeDiscoveryComponentClass !=null) + return childTypeDiscoveryComponentClass; + }
+ // No luck ... + log.warn("No discovery class for type " + resourceType + " found "); + return null; }
public String getComponentClass(ResourceType resourceType) { PluginMetadataParser parser = this.parsersByPlugin.get(resourceType.getPlugin());
-// if (parser.getDescriptor().getName().equals("NagiosMonitor")) { -// return (parser != null) ? parser.getChildTypeComponentClass(resourceType) : null; -// } else { -// return (parser != null) ? parser.getComponentClass(resourceType) : null; -// } if (parser==null) return null;
+ // Prefer hard coded types (= types from the plugin descriptor) + String componentClass = parser.getComponentClass(resourceType); + if (componentClass!=null) + return componentClass; + + // Not in plugin descriptor? Check if the parent supports dynamic type discovery + // and use the discovery class from there if (resourceType.getParentResourceTypes()!=null && !resourceType.getParentResourceTypes().isEmpty()) { ResourceType parent = resourceType.getParentResourceTypes().iterator().next(); - if (parser.getChildTypeComponentClass(parent)!=null) - return parser.getChildTypeComponentClass(parent); - } - - return parser.getComponentClass(resourceType); + String childTypeComponentClass = parser.getChildTypeComponentClass(parent);
+ if (childTypeComponentClass !=null) + return childTypeComponentClass; + }
+ // No luck ... + log.warn("No component class for type " + resourceType + " found "); + return null; }
/** diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataParser.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataParser.java index 95a8943..a494d0f 100644 --- a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataParser.java +++ b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataParser.java @@ -83,7 +83,7 @@ public class PluginMetadataParser { private String childTypeDiscoveryClass; private String childTypeComponentClass;
- //Hashmaps for ChildType discovery and component classes + //Hashmaps for ChildType discovery and component classes private Map<ResourceType, String> childTypeDiscoveryClasses = new HashMap<ResourceType, String>(); private Map<ResourceType, String> childTypeComponentClasses = new HashMap<ResourceType, String>();
@@ -206,16 +206,18 @@ public class PluginMetadataParser { //get childType discovery and component class names this.childTypeDiscoveryClass = serverDescriptor.getChildTypeDiscovery(); this.childTypeComponentClass = serverDescriptor.getChildTypeClass(); + childTypeDiscoveryClasses.put(serverResourceType,getFullyQualifiedComponentClassName(pluginDescriptor.getPackage(),childTypeDiscoveryClass)); + childTypeComponentClasses.put(serverResourceType,getFullyQualifiedComponentClassName(pluginDescriptor.getPackage(),childTypeComponentClass));
//Check if it is the Nagios plugin and if the serverResourceType is a child //Only nagios plugin decriptor has child type discovery and component class tags - if (this.childTypeDiscoveryClass != null && this.childTypeComponentClass != null - && parentServerType != null) { - parseResourceDescriptor(serverDescriptor, serverResourceType, this.childTypeDiscoveryClass, - this.childTypeComponentClass, null); - } else { +// if (this.childTypeDiscoveryClass != null && this.childTypeComponentClass != null +// && parentServerType != null) { +// parseResourceDescriptor(serverDescriptor, serverResourceType, this.childTypeDiscoveryClass, +// this.childTypeComponentClass, null); +// } else { parseResourceDescriptor(serverDescriptor, serverResourceType, null, null, null); - } +// }
LOG.debug("Parsed server Resource type: " + serverResourceType); } else if ((sourcePlugin.length() > 0) && (sourceServer.length() > 0)) { @@ -336,13 +338,13 @@ public class PluginMetadataParser {
//Check if it is the Nagios plugin and if the serviceResourceType is a child //Only nagios plugin decriptor has child type discovery and component class tags - if (this.childTypeDiscoveryClass != null && this.childTypeComponentClass != null && parentType != null) { - parseResourceDescriptor(serviceDescriptor, serviceResourceType, this.childTypeDiscoveryClass, - this.childTypeComponentClass, null); - } else { +// if (this.childTypeDiscoveryClass != null && this.childTypeComponentClass != null && parentType != null) { +// parseResourceDescriptor(serviceDescriptor, serviceResourceType, this.childTypeDiscoveryClass, +// this.childTypeComponentClass, null); +// } else { parseResourceDescriptor(serviceDescriptor, serviceResourceType, null, null, null);
- } +// }
LOG.debug("Parsed service Resource type: " + serviceResourceType);
@@ -657,7 +659,7 @@ public class PluginMetadataParser { String componentClass) { this.resourceTypes.add(resourceType);
- //if it is the child resource type of Nagios plugin + //if it is the child resource type of Nagios plugin if (discoveryClass.equals(this.childTypeDiscoveryClass) && componentClass.equals(this.childTypeComponentClass)) { //Put the childresource type and its discovery and component classes to the childtype map this.childTypeComponentClasses.put(resourceType, componentClass);