org.rhq.core.pc.inventory
Class InventoryManager

java.lang.Object
  extended by org.rhq.core.pc.agent.AgentService
      extended by org.rhq.core.pc.inventory.InventoryManager
All Implemented Interfaces:
DiscoveryAgentService, ContainerService

public class InventoryManager
extends AgentService
implements ContainerService, DiscoveryAgentService

Manages the process of both auto-detection of servers and runtime detection of services across all plugins. Manages their scheduling and result sending as well as the general inventory model.

This is an Agent service; its DiscoveryAgentService interface is made remotely accessible if it is deployed within the Agent.

Author:
Greg Hinkle, Ian Springer, Jay Shaughnessy

Nested Class Summary
 
Nested classes/interfaces inherited from class org.rhq.core.pc.agent.AgentService
AgentService.LifecycleState
 
Constructor Summary
InventoryManager()
           
 
Method Summary
 void activateResource(org.rhq.core.domain.resource.Resource resource, ResourceContainer container, boolean updatedPluginConfig)
          This will start the resource's plugin component, creating it first if it has not yet been created.
 void addInventoryEventListener(InventoryEventListener listener)
          Instructs the inventory manager to notify the specified listener of inventory change events.
<T extends ResourceComponent<?>>
ResourceUpgradeContext<T>
createResourceUpgradeContext(org.rhq.core.domain.resource.Resource resource, ResourceContext<?> parentResourceContext, T parentComponent, ResourceDiscoveryComponent<T> discoveryComponent)
           
 void deactivateResource(org.rhq.core.domain.resource.Resource resource)
          Shutdown the ResourceComponents from the bottom up.
 void disableServiceScans(int serverResourceId)
           
 void enableServiceScans(int serverResourceId, org.rhq.core.domain.configuration.Configuration config)
           
 org.rhq.core.domain.discovery.AvailabilityReport executeAvailabilityScanImmediately(boolean changedOnlyReport)
           
 InventoryReport executeServerScanImmediately()
           
 void executeServiceScanDeferred()
           
 InventoryReport executeServiceScanImmediately()
           
 org.rhq.core.domain.resource.Agent getAgent()
           
 org.rhq.core.domain.measurement.Availability getAvailabilityIfKnown(org.rhq.core.domain.resource.Resource resource)
          Returns the known availability for the resource.
 org.rhq.core.domain.measurement.Availability getCurrentAvailability(org.rhq.core.domain.resource.Resource resource)
           
 DiscoveryComponentProxyFactory getDiscoveryComponentProxyFactory()
           
 org.rhq.core.domain.resource.Resource getPlatform()
           
 ResourceComponent<?> getResourceComponent(org.rhq.core.domain.resource.Resource resource)
           
 ResourceContainer getResourceContainer(CanonicalResourceKey canonicalId)
           
 ResourceContainer getResourceContainer(Integer resourceId)
           
 ResourceContainer getResourceContainer(org.rhq.core.domain.resource.Resource resource)
           
 ResourceContainer getResourceContainer(String uuid)
           
 Set<org.rhq.core.domain.resource.Resource> getResourcesWithType(org.rhq.core.domain.resource.ResourceType serverType)
          Lookup all the servers with a particular server type
 boolean handleInvalidPluginConfigurationResourceError(org.rhq.core.domain.resource.Resource resource, Throwable t)
          This will send a resource error to the server (if applicable) to indicate that the given resource could not be connected to due to an invalid plugin configuration.
 void handleReport(org.rhq.core.domain.discovery.AvailabilityReport report)
           
 boolean handleReport(InventoryReport report)
          Send an inventory report to the Server.
 boolean hasUpgradeMergeFailed()
           
 void initialize()
          Initializes the container service which will effectively tell the service to start doing its work.
 Set<DiscoveredResourceDetails> invokeDiscoveryComponent(ResourceContainer parentResourceContainer, ResourceDiscoveryComponent component, ResourceDiscoveryContext context)
          Invokes the given discovery component in order to discover resources.
 List<URL> invokeDiscoveryComponentClassLoaderFacet(org.rhq.core.domain.resource.Resource resource, ResourceDiscoveryComponent component, ResourceContainer parentContainer)
          Invokes the given discovery component's ClassLoaderFacet in order to obtain additional jars for the resource's classloader.
<T extends ResourceComponent<?>>
org.rhq.core.domain.resource.ResourceUpgradeReport
invokeDiscoveryComponentResourceUpgradeFacet(org.rhq.core.domain.resource.ResourceType resourceType, ResourceDiscoveryComponent<T> component, ResourceUpgradeContext<T> inventoriedResource, ResourceContainer parentResourceContainer)
           
 org.rhq.core.domain.discovery.MergeResourceResponse manuallyAddResource(org.rhq.core.domain.resource.ResourceType resourceType, int parentResourceId, org.rhq.core.domain.configuration.Configuration pluginConfiguration, int ownerSubjectId)
           
 org.rhq.core.domain.resource.Resource mergeResourceFromDiscovery(org.rhq.core.domain.resource.Resource resource, org.rhq.core.domain.resource.Resource parent)
           
 void mergeResourcesFromUpgrade(Set<ResourceUpgradeRequest> upgradeRequests)
           
 void notifyForAllActivatedResources(InventoryEventListener listener)
          During initialization time, the inventory manager will active resources after loading them from disk.
 void performServiceScan(int resourceId)
          Performs a service scan on the specified Resource.
 void removeInventoryEventListener(InventoryEventListener listener)
          Removes the specified listener from notification of inventory change events.
 void setConfiguration(PluginContainerConfiguration configuration)
          Informs the container service how it should be configured by providing the full plugin container configuration.
 void shutdown()
          Stops the container service which effectively releases all runtime resources such as running threads.
 void synchronizeInventory(org.rhq.core.domain.discovery.ResourceSyncInfo syncInfo)
           
 void uninventoryResource(int resourceId)
           
 org.rhq.core.domain.measurement.Availability updateAvailability(org.rhq.core.domain.resource.Resource resource, org.rhq.core.domain.measurement.AvailabilityType availabilityType)
          Inject a new availability
 void updatePluginConfiguration(int resourceId, org.rhq.core.domain.configuration.Configuration newPluginConfiguration)
           
 
Methods inherited from class org.rhq.core.pc.agent.AgentService
addLifecycleListener, getClientInterface, notifyLifecycleListenersOfNewState, remoteInputStream, remoteOutputStream, removeLifecycleListener, setAgentServiceStreamRemoter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InventoryManager

public InventoryManager()
Method Detail

initialize

public void initialize()
Description copied from interface: ContainerService
Initializes the container service which will effectively tell the service to start doing its work. Implementations of this interface can be assured that prior to this method being called, a non-null configuration will be set via a call to ContainerService.setConfiguration(PluginContainerConfiguration).

Specified by:
initialize in interface ContainerService
See Also:
ContainerService.initialize()

shutdown

public void shutdown()
Description copied from interface: ContainerService
Stops the container service which effectively releases all runtime resources such as running threads.

Specified by:
shutdown in interface ContainerService
See Also:
ContainerService.shutdown()

invokeDiscoveryComponent

public Set<DiscoveredResourceDetails> invokeDiscoveryComponent(ResourceContainer parentResourceContainer,
                                                               ResourceDiscoveryComponent component,
                                                               ResourceDiscoveryContext context)
                                                        throws DiscoverySuspendedException,
                                                               Exception
Invokes the given discovery component in order to discover resources. This will return the discovered resources' details as returned by the discovery component. This may return an empty set if nothing is discovered. This may return null if for some reason we could not invoke the discovery component.

Parameters:
parentResourceContainer - the container of the resource under which we are going to execute the discovery
component - the discovery component that will actually go out and discover resources
context - the context for use by the discovery component
Returns:
the details of all discovered resources, may be empty or null
Throws:
DiscoverySuspendedException - if the discovery is suspended due to a resource upgrade failure
Exception - if the discovery component threw an exception

invokeDiscoveryComponentClassLoaderFacet

public List<URL> invokeDiscoveryComponentClassLoaderFacet(org.rhq.core.domain.resource.Resource resource,
                                                          ResourceDiscoveryComponent component,
                                                          ResourceContainer parentContainer)
                                                   throws Throwable
Invokes the given discovery component's ClassLoaderFacet in order to obtain additional jars for the resource's classloader. This will return the discovered resources' details as returned.

Parameters:
resource - the resource whose component is to be invoked
component - the discovery component that will actually go out and discover resources
parentContainer - the activated parent container
Returns:
the additional jars for the resource's classloader
Throws:
Throwable - if the discovery component threw an exception

invokeDiscoveryComponentResourceUpgradeFacet

public <T extends ResourceComponent<?>> org.rhq.core.domain.resource.ResourceUpgradeReport invokeDiscoveryComponentResourceUpgradeFacet(org.rhq.core.domain.resource.ResourceType resourceType,
                                                                                                                                        ResourceDiscoveryComponent<T> component,
                                                                                                                                        ResourceUpgradeContext<T> inventoriedResource,
                                                                                                                                        ResourceContainer parentResourceContainer)
                                                                                                throws Throwable
Throws:
Throwable

getDiscoveryComponentProxyFactory

public DiscoveryComponentProxyFactory getDiscoveryComponentProxyFactory()

getResourceContainer

@Nullable
public ResourceContainer getResourceContainer(String uuid)

getResourceContainer

@Nullable
public ResourceContainer getResourceContainer(CanonicalResourceKey canonicalId)

getResourceContainer

@Nullable
public ResourceContainer getResourceContainer(org.rhq.core.domain.resource.Resource resource)

getResourceContainer

@Nullable
public ResourceContainer getResourceContainer(Integer resourceId)

setConfiguration

public void setConfiguration(PluginContainerConfiguration configuration)
Description copied from interface: ContainerService
Informs the container service how it should be configured by providing the full plugin container configuration. The plugin container will ensure it passes in a non-null configuration object so implementations of this interface should never have to worry about a null configuration parameter value.

Specified by:
setConfiguration in interface ContainerService

updatePluginConfiguration

public void updatePluginConfiguration(int resourceId,
                                      org.rhq.core.domain.configuration.Configuration newPluginConfiguration)
                               throws InvalidPluginConfigurationClientException,
                                      PluginContainerException
Specified by:
updatePluginConfiguration in interface DiscoveryAgentService
Throws:
InvalidPluginConfigurationClientException
PluginContainerException

executeServerScanImmediately

public InventoryReport executeServerScanImmediately()
Specified by:
executeServerScanImmediately in interface DiscoveryAgentService

executeServiceScanImmediately

public InventoryReport executeServiceScanImmediately()
Specified by:
executeServiceScanImmediately in interface DiscoveryAgentService

executeServiceScanDeferred

public void executeServiceScanDeferred()
Specified by:
executeServiceScanDeferred in interface DiscoveryAgentService

executeAvailabilityScanImmediately

public org.rhq.core.domain.discovery.AvailabilityReport executeAvailabilityScanImmediately(boolean changedOnlyReport)
Specified by:
executeAvailabilityScanImmediately in interface DiscoveryAgentService

getCurrentAvailability

@NotNull
public org.rhq.core.domain.measurement.Availability getCurrentAvailability(org.rhq.core.domain.resource.Resource resource)
Specified by:
getCurrentAvailability in interface DiscoveryAgentService

manuallyAddResource

public org.rhq.core.domain.discovery.MergeResourceResponse manuallyAddResource(org.rhq.core.domain.resource.ResourceType resourceType,
                                                                               int parentResourceId,
                                                                               org.rhq.core.domain.configuration.Configuration pluginConfiguration,
                                                                               int ownerSubjectId)
                                                                        throws InvalidPluginConfigurationClientException,
                                                                               PluginContainerException
Specified by:
manuallyAddResource in interface DiscoveryAgentService
Throws:
InvalidPluginConfigurationClientException
PluginContainerException

getAvailabilityIfKnown

@Nullable
public org.rhq.core.domain.measurement.Availability getAvailabilityIfKnown(org.rhq.core.domain.resource.Resource resource)
Returns the known availability for the resource. If the availability is not known, null is returned.

Parameters:
resource - the resource whose availability should be returned
Returns:
resource availability or null if not known

handleReport

public void handleReport(org.rhq.core.domain.discovery.AvailabilityReport report)

handleReport

public boolean handleReport(InventoryReport report)
Send an inventory report to the Server.

Parameters:
report - the inventory report to be sent
Returns:
true if sending the report to the Server succeeded, or false otherwise

performServiceScan

public void performServiceScan(int resourceId)
Performs a service scan on the specified Resource. NOTE: This method will block until the scan completes.

Parameters:
resourceId - the id of the Resource on which to discover services

getResourceComponent

@Nullable
public ResourceComponent<?> getResourceComponent(org.rhq.core.domain.resource.Resource resource)

uninventoryResource

public void uninventoryResource(int resourceId)
Specified by:
uninventoryResource in interface DiscoveryAgentService

getPlatform

public org.rhq.core.domain.resource.Resource getPlatform()
Specified by:
getPlatform in interface DiscoveryAgentService

getAgent

public org.rhq.core.domain.resource.Agent getAgent()

updateAvailability

public org.rhq.core.domain.measurement.Availability updateAvailability(org.rhq.core.domain.resource.Resource resource,
                                                                       org.rhq.core.domain.measurement.AvailabilityType availabilityType)
Inject a new availability

Parameters:
resource -
availabilityType -
Returns:

mergeResourcesFromUpgrade

public void mergeResourcesFromUpgrade(Set<ResourceUpgradeRequest> upgradeRequests)
                               throws Exception
Throws:
Exception

mergeResourceFromDiscovery

public org.rhq.core.domain.resource.Resource mergeResourceFromDiscovery(org.rhq.core.domain.resource.Resource resource,
                                                                        org.rhq.core.domain.resource.Resource parent)
                                                                 throws PluginContainerException
Throws:
PluginContainerException

notifyForAllActivatedResources

public void notifyForAllActivatedResources(InventoryEventListener listener)
During initialization time, the inventory manager will active resources after loading them from disk. Any other manager that starts up and is initialized after the Inventory Manager is initialized will miss the activation notifications. This method is here so those managers can be notified during their initialization phase by simply passing in their listener which will be called for every resource currently activated in inventory.

Parameters:
listener - the listener that will be notified for every resource currently active

activateResource

public void activateResource(org.rhq.core.domain.resource.Resource resource,
                             @NotNull
                             ResourceContainer container,
                             boolean updatedPluginConfig)
                      throws InvalidPluginConfigurationException,
                             PluginContainerException
This will start the resource's plugin component, creating it first if it has not yet been created. If the component is already created and started, this method is a no-op.

Parameters:
resource - the resource that the component will manage
container - the wrapper around the resource and its component
updatedPluginConfig - if true, this will indicate that the resource's plugin configuration is known to have changed since the last time the resource component was started
Throws:
InvalidPluginConfigurationException - when connecting to the managed resource fails due to an invalid plugin configuration
PluginContainerException - for all other errors

createResourceUpgradeContext

public <T extends ResourceComponent<?>> ResourceUpgradeContext<T> createResourceUpgradeContext(org.rhq.core.domain.resource.Resource resource,
                                                                                               ResourceContext<?> parentResourceContext,
                                                                                               T parentComponent,
                                                                                               ResourceDiscoveryComponent<T> discoveryComponent)

handleInvalidPluginConfigurationResourceError

public boolean handleInvalidPluginConfigurationResourceError(org.rhq.core.domain.resource.Resource resource,
                                                             Throwable t)
This will send a resource error to the server (if applicable) to indicate that the given resource could not be connected to due to an invalid plugin configuration.

Parameters:
resource - the resource that could not be connected to
t - the exception that indicates the problem with the plugin configuration
Returns:
true if the error was sent successfully, or false otherwise

getResourcesWithType

public Set<org.rhq.core.domain.resource.Resource> getResourcesWithType(org.rhq.core.domain.resource.ResourceType serverType)
Lookup all the servers with a particular server type

Parameters:
serverType - the server type to match against
Returns:
the set of servers matching the provided type

deactivateResource

public void deactivateResource(org.rhq.core.domain.resource.Resource resource)
Shutdown the ResourceComponents from the bottom up.

Parameters:
resource - The resource to deactivate

synchronizeInventory

public void synchronizeInventory(org.rhq.core.domain.discovery.ResourceSyncInfo syncInfo)
Specified by:
synchronizeInventory in interface DiscoveryAgentService

addInventoryEventListener

public void addInventoryEventListener(InventoryEventListener listener)
Instructs the inventory manager to notify the specified listener of inventory change events.

Parameters:
listener - instance to notify of change events

removeInventoryEventListener

public void removeInventoryEventListener(InventoryEventListener listener)
Removes the specified listener from notification of inventory change events.

Parameters:
listener - instance to remove from event notification

hasUpgradeMergeFailed

public boolean hasUpgradeMergeFailed()
Returns:
true if the inventory manager failed to merge the upgrade requests with the server during startup.

enableServiceScans

public void enableServiceScans(int serverResourceId,
                               org.rhq.core.domain.configuration.Configuration config)
Specified by:
enableServiceScans in interface DiscoveryAgentService

disableServiceScans

public void disableServiceScans(int serverResourceId)
Specified by:
disableServiceScans in interface DiscoveryAgentService


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.