modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java
| 78 +++++++---
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
| 73 ---------
2 files changed, 61 insertions(+), 90 deletions(-)
New commits:
commit 51cdf2ed77e178186a9426dcac048d9c4599eda5
Author: alexander.kiefer79(a)googlemail.com <di34475@.dh-com.continental.steel>
Date: Tue Jul 27 15:18:08 2010 +0200
Put code from InventoryManager.initialize() to
ChildResourceTypeDiscoveryRunner.call()
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 72e0c45..a2eca92 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
@@ -7,6 +7,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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;
@@ -49,34 +51,68 @@ public class ChildResourceTypeDiscoveryRunner implements
Callable<Set<ResourceTy
log.info("<ChildResourceTypeDiscoveryRunner>call() called");
Set<ResourceType> resourceTypes = null;
- try {
+ long start = System.currentTimeMillis();
- long start = System.currentTimeMillis();
+ InventoryManager im = PluginContainer.getInstance().getInventoryManager();
+ log.info("InventoryManager instance created");
- InventoryManager im = PluginContainer.getInstance().getInventoryManager();
- log.info("InventoryManager instance created");
+ //TODO: Do testing and split code to more than one method if it works well
+ // Run a full scan for all resources in the inventory
- ResourceContainer container = im.getResourceContainer(this.resourceId);
- log.info("InventoryManager instance created");
+ Resource platform = im.getPlatform();
+ log.info("Platform returned with name: " + platform.getName());
- 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.debug("ChildType not discoverd for inactive resource
component: " + container.getResource());
- }
- } else {
- ChildResourceTypeDiscoveryFacet discoveryComponent =
ComponentUtil.getComponent(resourceId,
- ChildResourceTypeDiscoveryFacet.class, FacetLockType.READ, 30 * 1000,
true, true);
+ // Next discover all other services and non-top-level servers
+ Set<Resource> servers = platform.getChildResources();
- resourceTypes = discoverChildResourceTypes(discoveryComponent);
- }
+ for (Resource server : servers) {
- } catch (Throwable t) {
- log.error("Failed to run ChildType discovery", t);
+ //Check if really is of Category SERVER
+ if (server.getResourceType().getCategory() == ResourceCategory.SERVER) {
+ //check if child resource implements the interface
ChildResourceTypeDiscoveryFacet
+ if (server instanceof ChildResourceTypeDiscoveryFacet) {
+
+ log.info("Server " + server.getName() + " is
instanceof ChildResourceTypeDiscoveryFacet");
+ //Get ResourceContainer for each server instance
+
+ ResourceContainer container =
im.getResourceContainer(server.getId());
+
+ log.info("Server " + server.getName() + " is runnig 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.debug("ChildType not discoverd for inactive resource
component: "
+ + container.getResource());
+ }
+ } else {
+
+ try {
+
+ ChildResourceTypeDiscoveryFacet discoveryComponent =
ComponentUtil.getComponent(server
+ .getId(), ChildResourceTypeDiscoveryFacet.class,
FacetLockType.READ, 30 * 1000, true,
+ true);
+
+ //get Set<ResourceType> --> all the Services which
are running under the specific server
+ resourceTypes =
discoverChildResourceTypes(discoveryComponent);
+
+ //Iterate over all the ResourceTypes contained in the Set
+ for (ResourceType type : resourceTypes) {
+
+ //Create a new ResourceType in the DB for the selected
type
+ im.createNewResourceType(type.getName(), type.getName() +
"Metric");
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Error submitting service
scan", e);
+ }
+ }
+ }
+ }
}
- return resourceTypes;
+
+ return null;
}
/**
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 8f1ec92..64f6f10 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,7 +95,6 @@ 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;
@@ -226,49 +225,9 @@ public class InventoryManager extends AgentService implements
ContainerService,
serverScanExecutor = new AutoDiscoveryExecutor(null, this, configuration);
serviceScanExecutor = new RuntimeDiscoveryExecutor(this, configuration);
- //Code for discovering new ResourceTypes
+ //Object for discovering new ChildResourceTypes
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()) {
@@ -280,9 +239,9 @@ public class InventoryManager extends AgentService implements
ContainerService,
inventoryThreadPoolExecutor.scheduleWithFixedDelay(serverScanExecutor,
configuration
.getServerDiscoveryInitialDelay(),
configuration.getServerDiscoveryPeriod(), TimeUnit.SECONDS);
- // After an initial delay (20s by default), periodically run a service
discovery scan (every 1d by default).
- inventoryThreadPoolExecutor.scheduleWithFixedDelay(serviceScanExecutor,
configuration
- .getServiceDiscoveryInitialDelay(),
configuration.getServiceDiscoveryPeriod(), TimeUnit.SECONDS);
+ //Call ScheduledThreadPoolExecutor for type
ChildResourceTypeDiscoveryRunner
+ // After an initial delay (20s by default), periodically run a service
discovery scan (every 1minute).
+ inventoryThreadPoolExecutor.scheduleWithFixedDelay(childDiscoveryRunner,
20L, 60L, TimeUnit.SECONDS);
}
} finally {
inventoryLock.writeLock().unlock();
@@ -1048,30 +1007,6 @@ public class InventoryManager extends AgentService implements
ContainerService,
throw new RuntimeException("Error submitting service scan", e);
}
- /**
- * 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);
- // }
}
@Nullable