modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java | 13 + modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java | 89 +++++++--- 2 files changed, 78 insertions(+), 24 deletions(-)
New commits: commit 6b76f043e59b6ec695f1f5d30f65fe621a657dc5 Author: alexander.kiefer79@googlemail.com <di34475@.dh-com.continental.steel> Date: Tue Jul 27 14:11:37 2010 +0200
Put the code to create new ChildResourceTypes to method initialize()
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 8a53169..72e0c45 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 @@ -17,16 +17,23 @@ import org.rhq.core.util.exception.ThrowableUtil; public class ChildResourceTypeDiscoveryRunner implements Callable<Set<ResourceType>>, Runnable {
private Log log = LogFactory.getLog(ChildResourceTypeDiscoveryRunner.class); + + //TODO: Maybe will be needed for later purpose //private MeasurementManager measurementManager; - private int resourceId; + //private int resourceId;
//TODO: maybe to be implemented for later usage // public ChildResourceTypeDiscoveryRunner(MeasurementManager measurementManager) { // // }
- public ChildResourceTypeDiscoveryRunner(int resourceId) { - this.resourceId = resourceId; + // public ChildResourceTypeDiscoveryRunner(int resourceId) { + // this.resourceId = resourceId; + // } + + //Default Ctor + public ChildResourceTypeDiscoveryRunner() { + }
public void run() { diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java index d1e103a..8f1ec92 100644 --- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java +++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java @@ -95,6 +95,7 @@ import org.rhq.core.pluginapi.availability.AvailabilityFacet; import org.rhq.core.pluginapi.content.ContentContext; import org.rhq.core.pluginapi.content.ContentServices; import org.rhq.core.pluginapi.event.EventContext; +import org.rhq.core.pluginapi.inventory.ChildResourceTypeDiscoveryFacet; import org.rhq.core.pluginapi.inventory.ClassLoaderFacet; import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails; import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException; @@ -143,6 +144,9 @@ public class InventoryManager extends AgentService implements ContainerService, private RuntimeDiscoveryExecutor serviceScanExecutor; private AvailabilityExecutor availabilityExecutor;
+ //Own Executor to add new ResourceTypes + private ChildResourceTypeDiscoveryRunner childDiscoveryRunner; + private Agent agent;
/** @@ -222,6 +226,49 @@ public class InventoryManager extends AgentService implements ContainerService, serverScanExecutor = new AutoDiscoveryExecutor(null, this, configuration); serviceScanExecutor = new RuntimeDiscoveryExecutor(this, configuration);
+ //Code for discovering new ResourceTypes + childDiscoveryRunner = new ChildResourceTypeDiscoveryRunner(); + + //TODO: Do testing and make write this to another method if it works well + // Run a full scan for all resources in the inventory + Resource platform = this.getPlatform(); + // Next discover all other services and non-top-level servers + Set<Resource> servers = platform.getChildResources(); + + for (Resource server : servers) { + //check if child resource implements the interface ChildResourceTypeDiscoveryFacet + if (server instanceof ChildResourceTypeDiscoveryFacet) { + + log.info("ChildResourceTypeDiscoveryRunner instance created with values " + + childDiscoveryRunner.toString()); + try { + //get Set<ResourceType> --> all the Services which are running under the specific server + Set<ResourceType> resourceTypes = inventoryThreadPoolExecutor.submit( + (Callable<Set<ResourceType>>) childDiscoveryRunner).get(); + log.info("Set<ResourceType> was returned with values: "); + + for (ResourceType type : resourceTypes) { + log.info("ResourceType instance: " + type.getName()); + } + + //Iterate over all the ResourceTypes contained in the Set + for (ResourceType type : resourceTypes) { + //Create a new ResourceType in the DB for the selected type + this.createNewResourceType(type.getName(), type.getName() + "Metric"); + } + + } catch (Exception e) { + throw new RuntimeException("Error submitting service scan", e); + } + + } + } + + // } else { + // // Run a single scan for just a resource and its descendants + // discoverForResource(resource, report, false); + // } + // Only schedule periodic discovery scans and avail checks if we are running inside the RHQ Agent (versus // inside EmbJopr). if (configuration.isInsideAgent()) { @@ -1004,27 +1051,27 @@ public class InventoryManager extends AgentService implements ContainerService, /** * Usage of new implemented ChildResourceTypeDiscoveryRunner */ - ChildResourceTypeDiscoveryRunner childDiscoveryRunner = new ChildResourceTypeDiscoveryRunner(resourceId); - log.info("ChildResourceTypeDiscoveryRunner instance created with values " + childDiscoveryRunner.toString()); - try { - //get Set<ResourceType> - Set<ResourceType> resourceTypes = inventoryThreadPoolExecutor.submit( - (Callable<Set<ResourceType>>) childDiscoveryRunner).get(); - log.info("Set<ResourceType> was returned with values: "); - - for (ResourceType type : resourceTypes) { - log.info("ResourceType instance: " + type.getName()); - } - - //Iterate over all the ResourceTypes contained in the Set - for (ResourceType type : resourceTypes) { - //Create a new ResourceType in the DB for the selected type - this.createNewResourceType(type.getName(), type.getName() + "Metric"); - } - - } catch (Exception e) { - throw new RuntimeException("Error submitting service scan", e); - } + // ChildResourceTypeDiscoveryRunner childDiscoveryRunner = new ChildResourceTypeDiscoveryRunner(resourceId); + // log.info("ChildResourceTypeDiscoveryRunner instance created with values " + childDiscoveryRunner.toString()); + // try { + // //get Set<ResourceType> + // Set<ResourceType> resourceTypes = inventoryThreadPoolExecutor.submit( + // (Callable<Set<ResourceType>>) childDiscoveryRunner).get(); + // log.info("Set<ResourceType> was returned with values: "); + // + // for (ResourceType type : resourceTypes) { + // log.info("ResourceType instance: " + type.getName()); + // } + // + // //Iterate over all the ResourceTypes contained in the Set + // for (ResourceType type : resourceTypes) { + // //Create a new ResourceType in the DB for the selected type + // this.createNewResourceType(type.getName(), type.getName() + "Metric"); + // } + // + // } catch (Exception e) { + // throw new RuntimeException("Error submitting service scan", e); + // } }
@Nullable
rhq-commits@lists.fedorahosted.org