org.rhq.plugins.byteman
Class BytemanAgentComponent

java.lang.Object
  extended by org.rhq.plugins.byteman.BytemanAgentComponent
All Implemented Interfaces:
AvailabilityFacet, ConfigurationFacet, ConfigurationFacetSupport, ContentFacet, CreateChildResourceFacet, ResourceComponent<BytemanAgentComponent>, MeasurementFacet, OperationFacet

public class BytemanAgentComponent
extends Object
implements ResourceComponent<BytemanAgentComponent>, MeasurementFacet, OperationFacet, ContentFacet, CreateChildResourceFacet, ConfigurationFacet

Component that represents the remote Byteman agent listening for requests. A note about adding boot/system classpath jars and the content this component supports related to that feature. There are operations this component supports to add jars to the byteman classpath. Those operations tell the byteman agent to add jars, but those jars must already exist and be accessible for the byteman agent to do so. This component will not manage the jars added via the operations. If, however, a user pushes jar content from the RHQ server to this plugin via the content facet, those jars will be managed by this component as they are added to the byteman agent.

Author:
John Mazzitelli

Constructor Summary
BytemanAgentComponent()
           
 
Method Summary
protected  void addDeployedClasspathJars()
          Goes through all jars that were deployed via RHQ and ensures they are still deployed, adding them if need be.
 CreateResourceReport createResource(CreateResourceReport report)
          Creates a new script by deploying the script file to the Byteman agent.
 DeployPackagesResponse deployPackages(Set<ResourcePackageDetails> packages, ContentServices contentServices)
          Deploys boot and system classpath jars to the Byteman agent.
 Set<ResourcePackageDetails> discoverDeployedPackages(PackageType type)
          Detects the different content for the Byteman agent.
 List<DeployPackageStep> generateInstallationSteps(ResourcePackageDetails packageDetails)
          Essentially a no-op - there are no installation steps associated with Byteman content.
 Map<String,String> getAllKnownScripts()
          Returns a cached copy of all known scripts since the last availability check was made.
 AvailabilityType getAvailability()
          Determines if the Byteman agent is up by asking it for the current list of all scripts and their rules.
 File getBootJarsDataDirectory()
           
 org.jboss.byteman.agent.submit.Submit getBytemanClient()
          Returns a client that can be used to talk to the remote Byteman agent.
 File getPackageFile(ResourcePackageDetails packageDetails)
          Given a package details, this will attempt to find that package's file.
 File getResourceDataDirectory(String suffix)
          Returns the component's data directory that is used to persist managed content.
 File getScriptsDataDirectory()
           
 File getSystemJarsDataDirectory()
           
 void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> requests)
          The plugin container will call this method when metrics are to be collected.
 OperationResult invokeOperation(String name, Configuration configuration)
          The plugin container will call this method when it wants to invoke an operation on the Byteman agent.
 Configuration loadResourceConfiguration()
           
 RemovePackagesResponse removePackages(Set<ResourcePackageDetails> packages)
          Removes the packages, if they are managed by this component.
 InputStream retrievePackageBits(ResourcePackageDetails packageDetails)
          When a remote client wants to see the actual data content for an installed package, this method will be called.
 void start(ResourceContext<BytemanAgentComponent> context)
          Start the management component.
 void stop()
          Called when the resource component will no longer manage the remote Byteman agent.
 void updateResourceConfiguration(ConfigurationUpdateReport report)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BytemanAgentComponent

public BytemanAgentComponent()
Method Detail

start

public void start(ResourceContext<BytemanAgentComponent> context)
Start the management component. This will immediately attempt to add previously deployed classpath jars, if it is found that the remote Byteman agent no longer has those jars in its classpath.

Specified by:
start in interface ResourceComponent<BytemanAgentComponent>
See Also:
ResourceComponent.start(ResourceContext)

stop

public void stop()
Called when the resource component will no longer manage the remote Byteman agent. This method will clean up the resource component.

Specified by:
stop in interface ResourceComponent<BytemanAgentComponent>
See Also:
ResourceComponent.stop()

getAvailability

public AvailabilityType getAvailability()
Determines if the Byteman agent is up by asking it for the current list of all scripts and their rules.

Specified by:
getAvailability in interface AvailabilityFacet
See Also:
AvailabilityFacet.getAvailability()

getValues

public void getValues(MeasurementReport report,
                      Set<MeasurementScheduleRequest> requests)
The plugin container will call this method when metrics are to be collected.

Specified by:
getValues in interface MeasurementFacet
See Also:
MeasurementFacet.getValues(MeasurementReport, Set)

loadResourceConfiguration

public Configuration loadResourceConfiguration()
                                        throws Exception
Specified by:
loadResourceConfiguration in interface ConfigurationFacet
Throws:
Exception

updateResourceConfiguration

public void updateResourceConfiguration(ConfigurationUpdateReport report)
Specified by:
updateResourceConfiguration in interface ConfigurationFacet

invokeOperation

public OperationResult invokeOperation(String name,
                                       Configuration configuration)
The plugin container will call this method when it wants to invoke an operation on the Byteman agent.

Specified by:
invokeOperation in interface OperationFacet
See Also:
OperationFacet.invokeOperation(String, Configuration)

discoverDeployedPackages

public Set<ResourcePackageDetails> discoverDeployedPackages(PackageType type)
Detects the different content for the Byteman agent. This will only discover content that was previously deployed by the RHQ content facet mechanism. In other words, content already deployed in the Byteman agent, or deployed by some other non-RHQ means, will not be detected.

Specified by:
discoverDeployedPackages in interface ContentFacet
See Also:
ContentFacet.discoverDeployedPackages(PackageType)

deployPackages

public DeployPackagesResponse deployPackages(Set<ResourcePackageDetails> packages,
                                             ContentServices contentServices)
Deploys boot and system classpath jars to the Byteman agent.

Specified by:
deployPackages in interface ContentFacet
See Also:
ContentFacet.deployPackages(Set, ContentServices)

retrievePackageBits

public InputStream retrievePackageBits(ResourcePackageDetails packageDetails)
When a remote client wants to see the actual data content for an installed package, this method will be called. This method must return a stream of data containing the full content of the package.

Specified by:
retrievePackageBits in interface ContentFacet
See Also:
ContentFacet.retrievePackageBits(ResourcePackageDetails)

generateInstallationSteps

public List<DeployPackageStep> generateInstallationSteps(ResourcePackageDetails packageDetails)
Essentially a no-op - there are no installation steps associated with Byteman content.

Specified by:
generateInstallationSteps in interface ContentFacet

removePackages

public RemovePackagesResponse removePackages(Set<ResourcePackageDetails> packages)
Removes the packages, if they are managed by this component. Note that the Byteman agent does not support runtime removal of jars from its classpaths, so the Byteman agent will retain classpath jars in its memory until the VM is restarted, even if this component was asked to remove classpath jars.

Specified by:
removePackages in interface ContentFacet
See Also:
ContentFacet.removePackages(Set)

createResource

public CreateResourceReport createResource(CreateResourceReport report)
Creates a new script by deploying the script file to the Byteman agent.

Specified by:
createResource in interface CreateChildResourceFacet
See Also:
CreateChildResourceFacet.createResource(CreateResourceReport)

getBytemanClient

public org.jboss.byteman.agent.submit.Submit getBytemanClient()
Returns a client that can be used to talk to the remote Byteman agent.

Returns:
client object

getAllKnownScripts

public Map<String,String> getAllKnownScripts()
Returns a cached copy of all known scripts since the last availability check was made. Use this if you do not need the most up-to-date list, which helps avoid making unnecessary calls to the remote Byteman agent. If you need the most up-to-date data, call the agent using the client.

Returns:
the last known set of scripts that were loaded in the remote Byteman agent. null if a problem occurred attempting to get the scripts

getPackageFile

public File getPackageFile(ResourcePackageDetails packageDetails)
                    throws Exception
Given a package details, this will attempt to find that package's file. The details "file name" is examined first to figure out where the file is supposed to be. Only if that isn't set will the details general "name" be used as the file name. If the "file name" (or "name") is not absolute, it will be assumed to be in one of the subdirectories under this component's data directory, based on the package type name.

Parameters:
packageDetails - details describing the file
Returns:
the file that corresponds to the details object - this file may or may not exist; existence is not a requirement for this method to return a valid File object
Throws:
Exception - if the file could not be determined

getBootJarsDataDirectory

public File getBootJarsDataDirectory()
Returns:
directory where managed boot classpath jars are persisted

getSystemJarsDataDirectory

public File getSystemJarsDataDirectory()
Returns:
directory where managed system classpath jars are persisted

getScriptsDataDirectory

public File getScriptsDataDirectory()
Returns:
directory where managed scripts are persisted. Scripts are files that contain rules.

getResourceDataDirectory

public File getResourceDataDirectory(String suffix)
Returns the component's data directory that is used to persist managed content. suffix is the last part of the file path, essentially providing a specific location for different kinds of content for the component.

Parameters:
suffix - identifies a specific location under a general data directory for this component.
Returns:
data directory that can be used to persist data for this component

addDeployedClasspathJars

protected void addDeployedClasspathJars()
                                 throws Exception
Goes through all jars that were deployed via RHQ and ensures they are still deployed, adding them if need be.

Throws:
Exception


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