org.rhq.enterprise.server.drift
Class DriftManagerBean

java.lang.Object
  extended by org.rhq.enterprise.server.drift.DriftManagerBean
All Implemented Interfaces:
DriftManagerLocal, DriftManagerRemote

public class DriftManagerBean
extends Object
implements DriftManagerLocal, DriftManagerRemote

The SLSB supporting Drift management to clients. Wrappers are provided for the methods defined in DriftServerPluginFacet and the work is deferred to the plugin No assumption is made about the any back end implementation of a drift server plugin and therefore does not declare any transactioning (the NOT_SUPPORTED transaction attribute is used for all wrappers). For methods not deferred to the server plugin, the implementations are done here.

Author:
John Sanda, John Mazzitelli, Jay Shaughnessy

Constructor Summary
DriftManagerBean()
           
 
Method Summary
 void addChangeSet(org.rhq.core.domain.auth.Subject subject, int resourceId, long zipSize, InputStream zipStream)
          This method initiates an out-of-band (JMS-Based) server-side pull of the change-set file.
 void addFiles(org.rhq.core.domain.auth.Subject subject, int resourceId, String driftDefName, String token, long zipSize, InputStream zipStream)
          This method initiates an out-of-band (JMS-Based) server-side pull of the drift file zip.
 void deleteDriftDefinition(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.common.EntityContext entityContext, String driftDefName)
          Remove the provided driftDef (identified by name) on the specified entityContext.
 void deleteResourceDriftDefinition(org.rhq.core.domain.auth.Subject subject, int resourceId, int driftDefId)
          This is for internal use only - do not call it unless you know what you are doing.
 void detectDrift(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.common.EntityContext context, org.rhq.core.domain.drift.DriftDefinition driftDef)
          One time on-demand request to detect drift on the specified entities, using the supplied def.
 org.rhq.core.domain.util.PageList<? extends org.rhq.core.domain.drift.DriftChangeSet<?>> findDriftChangeSetsByCriteria(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.criteria.DriftChangeSetCriteria criteria)
          Standard criteria based fetch method
 org.rhq.core.domain.util.PageList<org.rhq.core.domain.drift.DriftComposite> findDriftCompositesByCriteria(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.criteria.DriftCriteria criteria)
           
 org.rhq.core.domain.util.PageList<org.rhq.core.domain.drift.DriftDefinitionComposite> findDriftDefinitionCompositesByCriteria(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.criteria.DriftDefinitionCriteria criteria)
           
 org.rhq.core.domain.util.PageList<org.rhq.core.domain.drift.DriftDefinition> findDriftDefinitionsByCriteria(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.criteria.DriftDefinitionCriteria criteria)
           
 org.rhq.core.domain.util.PageList<? extends org.rhq.core.domain.drift.Drift<?,?>> findDriftsByCriteria(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.criteria.DriftCriteria criteria)
          Standard criteria based fetch method
 org.rhq.core.domain.drift.FileDiffReport generateUnifiedDiff(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.drift.Drift<?,?> drift)
          Generates a unified diff of the two files references by drift.
 org.rhq.core.domain.drift.FileDiffReport generateUnifiedDiff(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.drift.Drift<?,?> drift1, org.rhq.core.domain.drift.Drift<?,?> drift2)
          Generates a unified diff of the two files referenced by drift1 and drift2.
 org.rhq.core.domain.drift.FileDiffReport generateUnifiedDiffByIds(org.rhq.core.domain.auth.Subject subject, String driftId1, String driftId2)
          Generates a unified diff of the two file versions referenced by drift ids.
 org.rhq.core.domain.drift.DriftDefinition getDriftDefinition(org.rhq.core.domain.auth.Subject subject, int driftDefId)
          Get the specified drift definition.
 org.rhq.core.domain.drift.DriftDetails getDriftDetails(org.rhq.core.domain.auth.Subject subject, String driftId)
          Returns an object that encapsulates the information needed for viewing drift details
 org.rhq.core.domain.drift.DriftFile getDriftFile(org.rhq.core.domain.auth.Subject subject, String hashId)
           
 byte[] getDriftFileAsByteArray(org.rhq.core.domain.auth.Subject subject, String hash)
           
 String getDriftFileBits(org.rhq.core.domain.auth.Subject subject, String hash)
          Returns the content associated with the specified hash as a string
 org.rhq.core.domain.drift.DriftSnapshot getSnapshot(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.drift.DriftSnapshotRequest request)
          Calculate and return requested Drift Snapshot.
 boolean isBinaryFile(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.drift.Drift<?,?> drift)
           
 String persistSnapshot(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.drift.DriftSnapshot snapshot, org.rhq.core.domain.drift.DriftChangeSet<? extends org.rhq.core.domain.drift.Drift<?,?>> changeSet)
           
 void pinSnapshot(org.rhq.core.domain.auth.Subject subject, int driftDefId, int snapshotVersion)
           
 void processRepeatChangeSet(int resourceId, String driftDefName, int version)
           
 void purgeByDriftDefinitionName(org.rhq.core.domain.auth.Subject subject, int resourceId, String driftDefName)
          This purges the persisted data related to drift definition, but it does NOT talk to the agent to tell the agent about this nor does it actually delete the drift def itself.
 int purgeOrphanedDriftFiles(org.rhq.core.domain.auth.Subject subject, long purgeMillis)
          This will remove all drift files that are no longer referenced by drift entries.
 DriftChangeSetSummary saveChangeSet(org.rhq.core.domain.auth.Subject subject, int resourceId, File changeSetZip)
           
 void saveChangeSetContent(org.rhq.core.domain.auth.Subject subject, int resourceId, String driftDefName, String token, File changeSetFilesZip)
           
 void saveChangeSetFiles(org.rhq.core.domain.auth.Subject subject, File changeSetFilesZip)
           
 void updateDriftDefinition(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.drift.DriftDefinition driftDefinition)
           
 void updateDriftDefinition(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.common.EntityContext entityContext, org.rhq.core.domain.drift.DriftDefinition driftDef)
           Saves or updates the provided drift definition.
static void validateDriftDefinition(org.rhq.core.domain.drift.DriftDefinition driftDef)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DriftManagerBean

public DriftManagerBean()
Method Detail

addChangeSet

public void addChangeSet(org.rhq.core.domain.auth.Subject subject,
                         int resourceId,
                         long zipSize,
                         InputStream zipStream)
                  throws Exception
Description copied from interface: DriftManagerLocal
This method initiates an out-of-band (JMS-Based) server-side pull of the change-set file. Upon successful upload of the change-set, it is processed. This may in turn generated requests for drift files to be persisted.

Specified by:
addChangeSet in interface DriftManagerLocal
resourceId - The resource for which the change-set is being reported.
zipSize - The size of the zip waiting to be streamed.
zipStream - The change-set zip file stream
Throws:
Exception

addFiles

public void addFiles(org.rhq.core.domain.auth.Subject subject,
                     int resourceId,
                     String driftDefName,
                     String token,
                     long zipSize,
                     InputStream zipStream)
              throws Exception
Description copied from interface: DriftManagerLocal
This method initiates an out-of-band (JMS-Based) server-side pull of the drift file zip. Upon successful upload of the zip, the files are stored.

Specified by:
addFiles in interface DriftManagerLocal
resourceId - The resource from which the drift file is being supplied.
zipSize - The size of the zip waiting to be streamed.
zipStream - The drift files zip file stream
Throws:
Exception

saveChangeSetContent

public void saveChangeSetContent(org.rhq.core.domain.auth.Subject subject,
                                 int resourceId,
                                 String driftDefName,
                                 String token,
                                 File changeSetFilesZip)
                          throws Exception
Specified by:
saveChangeSetContent in interface DriftManagerLocal
Throws:
Exception

processRepeatChangeSet

public void processRepeatChangeSet(int resourceId,
                                   String driftDefName,
                                   int version)
Specified by:
processRepeatChangeSet in interface DriftManagerLocal

getSnapshot

public org.rhq.core.domain.drift.DriftSnapshot getSnapshot(org.rhq.core.domain.auth.Subject subject,
                                                           org.rhq.core.domain.drift.DriftSnapshotRequest request)
Description copied from interface: DriftManagerRemote
Calculate and return requested Drift Snapshot.

Specified by:
getSnapshot in interface DriftManagerRemote
Returns:
The DriftSnapshot Not null but version is set to -1 if the drift definition does not yet have any snapshots or there are no snapshots that meet the requested snapshot version constraints.

detectDrift

public void detectDrift(org.rhq.core.domain.auth.Subject subject,
                        org.rhq.core.domain.common.EntityContext context,
                        org.rhq.core.domain.drift.DriftDefinition driftDef)
Description copied from interface: DriftManagerLocal
One time on-demand request to detect drift on the specified entities, using the supplied def.

Specified by:
detectDrift in interface DriftManagerLocal

deleteDriftDefinition

public void deleteDriftDefinition(org.rhq.core.domain.auth.Subject subject,
                                  org.rhq.core.domain.common.EntityContext entityContext,
                                  String driftDefName)
Description copied from interface: DriftManagerRemote
Remove the provided driftDef (identified by name) on the specified entityContext. Agents, if available, will be notified of the change.

Specified by:
deleteDriftDefinition in interface DriftManagerRemote

deleteResourceDriftDefinition

public void deleteResourceDriftDefinition(org.rhq.core.domain.auth.Subject subject,
                                          int resourceId,
                                          int driftDefId)
Description copied from interface: DriftManagerLocal
This is for internal use only - do not call it unless you know what you are doing.

Specified by:
deleteResourceDriftDefinition in interface DriftManagerLocal

findDriftChangeSetsByCriteria

public org.rhq.core.domain.util.PageList<? extends org.rhq.core.domain.drift.DriftChangeSet<?>> findDriftChangeSetsByCriteria(org.rhq.core.domain.auth.Subject subject,
                                                                                                                              org.rhq.core.domain.criteria.DriftChangeSetCriteria criteria)
Description copied from interface: DriftManagerRemote
Standard criteria based fetch method

Specified by:
findDriftChangeSetsByCriteria in interface DriftManagerRemote
Returns:
The DriftChangeSets matching the criteria

findDriftCompositesByCriteria

public org.rhq.core.domain.util.PageList<org.rhq.core.domain.drift.DriftComposite> findDriftCompositesByCriteria(org.rhq.core.domain.auth.Subject subject,
                                                                                                                 org.rhq.core.domain.criteria.DriftCriteria criteria)
Specified by:
findDriftCompositesByCriteria in interface DriftManagerLocal

findDriftDefinitionsByCriteria

public org.rhq.core.domain.util.PageList<org.rhq.core.domain.drift.DriftDefinition> findDriftDefinitionsByCriteria(org.rhq.core.domain.auth.Subject subject,
                                                                                                                   org.rhq.core.domain.criteria.DriftDefinitionCriteria criteria)
Specified by:
findDriftDefinitionsByCriteria in interface DriftManagerRemote

findDriftDefinitionCompositesByCriteria

public org.rhq.core.domain.util.PageList<org.rhq.core.domain.drift.DriftDefinitionComposite> findDriftDefinitionCompositesByCriteria(org.rhq.core.domain.auth.Subject subject,
                                                                                                                                     org.rhq.core.domain.criteria.DriftDefinitionCriteria criteria)
Specified by:
findDriftDefinitionCompositesByCriteria in interface DriftManagerLocal

findDriftsByCriteria

public org.rhq.core.domain.util.PageList<? extends org.rhq.core.domain.drift.Drift<?,?>> findDriftsByCriteria(org.rhq.core.domain.auth.Subject subject,
                                                                                                              org.rhq.core.domain.criteria.DriftCriteria criteria)
Description copied from interface: DriftManagerRemote
Standard criteria based fetch method

Specified by:
findDriftsByCriteria in interface DriftManagerRemote
Returns:
The Drifts matching the criteria

getDriftDefinition

public org.rhq.core.domain.drift.DriftDefinition getDriftDefinition(org.rhq.core.domain.auth.Subject subject,
                                                                    int driftDefId)
Description copied from interface: DriftManagerLocal
Get the specified drift definition. Note, the full Configuration is fetched.

Specified by:
getDriftDefinition in interface DriftManagerLocal
Returns:
The drift definition

getDriftFile

public org.rhq.core.domain.drift.DriftFile getDriftFile(org.rhq.core.domain.auth.Subject subject,
                                                        String hashId)
                                                 throws Exception
Specified by:
getDriftFile in interface DriftManagerLocal
Throws:
Exception

saveChangeSet

public DriftChangeSetSummary saveChangeSet(org.rhq.core.domain.auth.Subject subject,
                                           int resourceId,
                                           File changeSetZip)
                                    throws Exception
Specified by:
saveChangeSet in interface DriftManagerLocal
Throws:
Exception

saveChangeSetFiles

public void saveChangeSetFiles(org.rhq.core.domain.auth.Subject subject,
                               File changeSetFilesZip)
                        throws Exception
Specified by:
saveChangeSetFiles in interface DriftManagerLocal
Throws:
Exception

purgeByDriftDefinitionName

public void purgeByDriftDefinitionName(org.rhq.core.domain.auth.Subject subject,
                                       int resourceId,
                                       String driftDefName)
                                throws Exception
This purges the persisted data related to drift definition, but it does NOT talk to the agent to tell the agent about this nor does it actually delete the drift def itself. If you want to delete a drift definition and all that that entails, you must use deleteDriftDefinition(Subject, EntityContext, String) instead. This method is really for internal use only.

Specified by:
purgeByDriftDefinitionName in interface DriftManagerLocal
resourceId - the resource whose drift definition is being purged
driftDefName - identifies the data that is to be purged
Throws:
Exception

purgeOrphanedDriftFiles

public int purgeOrphanedDriftFiles(org.rhq.core.domain.auth.Subject subject,
                                   long purgeMillis)
Description copied from interface: DriftManagerLocal
This will remove all drift files that are no longer referenced by drift entries. This is a maintenance method to help reclaim space on the backend.

Specified by:
purgeOrphanedDriftFiles in interface DriftManagerLocal
purgeMillis - only those unused drift files that are older than this (in epoch millis) will be purged.
Returns:
number of orphaned drife files that were removed

pinSnapshot

public void pinSnapshot(org.rhq.core.domain.auth.Subject subject,
                        int driftDefId,
                        int snapshotVersion)
Specified by:
pinSnapshot in interface DriftManagerRemote

persistSnapshot

public String persistSnapshot(org.rhq.core.domain.auth.Subject subject,
                              org.rhq.core.domain.drift.DriftSnapshot snapshot,
                              org.rhq.core.domain.drift.DriftChangeSet<? extends org.rhq.core.domain.drift.Drift<?,?>> changeSet)
Specified by:
persistSnapshot in interface DriftManagerLocal

getDriftFileBits

public String getDriftFileBits(org.rhq.core.domain.auth.Subject subject,
                               String hash)
Description copied from interface: DriftManagerLocal
Returns the content associated with the specified hash as a string

Specified by:
getDriftFileBits in interface DriftManagerLocal
Specified by:
getDriftFileBits in interface DriftManagerRemote
hash - The hash the uniquely identifies the requested content
Returns:
The content as a string

getDriftFileAsByteArray

public byte[] getDriftFileAsByteArray(org.rhq.core.domain.auth.Subject subject,
                                      String hash)
Specified by:
getDriftFileAsByteArray in interface DriftManagerRemote

generateUnifiedDiff

public org.rhq.core.domain.drift.FileDiffReport generateUnifiedDiff(org.rhq.core.domain.auth.Subject subject,
                                                                    org.rhq.core.domain.drift.Drift<?,?> drift)
Description copied from interface: DriftManagerRemote
Generates a unified diff of the two files references by drift. In the case of a modified file, a Drift object references the current and previous versions of the file. This method generates a diff of the two versions.

Specified by:
generateUnifiedDiff in interface DriftManagerRemote
drift - Specifies the two files that will be compared
Returns:
A report containing a unified diff of the two versions of the file referenced by drift

generateUnifiedDiffByIds

public org.rhq.core.domain.drift.FileDiffReport generateUnifiedDiffByIds(org.rhq.core.domain.auth.Subject subject,
                                                                         String driftId1,
                                                                         String driftId2)
Description copied from interface: DriftManagerRemote
Generates a unified diff of the two file versions referenced by drift ids.

Specified by:
generateUnifiedDiffByIds in interface DriftManagerRemote
Returns:
A report containing a unified diff of the two versions of the file referenced by drift

generateUnifiedDiff

public org.rhq.core.domain.drift.FileDiffReport generateUnifiedDiff(org.rhq.core.domain.auth.Subject subject,
                                                                    org.rhq.core.domain.drift.Drift<?,?> drift1,
                                                                    org.rhq.core.domain.drift.Drift<?,?> drift2)
Description copied from interface: DriftManagerRemote
Generates a unified diff of the two files referenced by drift1 and drift2. More specifically, the files referenced by Drift.getNewDriftFile() are compared.

Specified by:
generateUnifiedDiff in interface DriftManagerRemote
drift1 - References the first file to be compared
drift2 - References the second file to be compared
Returns:
A report containing a unified diff of the two files compared

updateDriftDefinition

public void updateDriftDefinition(org.rhq.core.domain.auth.Subject subject,
                                  org.rhq.core.domain.drift.DriftDefinition driftDefinition)
Specified by:
updateDriftDefinition in interface DriftManagerLocal

updateDriftDefinition

public void updateDriftDefinition(org.rhq.core.domain.auth.Subject subject,
                                  org.rhq.core.domain.common.EntityContext entityContext,
                                  org.rhq.core.domain.drift.DriftDefinition driftDef)
Description copied from interface: DriftManagerLocal

Saves or updates the provided drift definition. If the definition, identified by name, already exists, an update is performed; otherwise, a new drift definition is saved. Agents if available will be notified of the change. If agents are unreachable, the definition will still be saved/updated. Changes will then propagate to agents the next time they do an inventory sync.

Several validation checks are performed before the definition is persisted. If it is a new definition, the following checks are performed:

For new and existing definitions these additional checks are performed:

Specified by:
updateDriftDefinition in interface DriftManagerLocal
Specified by:
updateDriftDefinition in interface DriftManagerRemote

validateDriftDefinition

public static void validateDriftDefinition(org.rhq.core.domain.drift.DriftDefinition driftDef)

isBinaryFile

public boolean isBinaryFile(org.rhq.core.domain.auth.Subject subject,
                            org.rhq.core.domain.drift.Drift<?,?> drift)
Specified by:
isBinaryFile in interface DriftManagerLocal

getDriftDetails

public org.rhq.core.domain.drift.DriftDetails getDriftDetails(org.rhq.core.domain.auth.Subject subject,
                                                              String driftId)
Description copied from interface: DriftManagerLocal
Returns an object that encapsulates the information needed for viewing drift details

Specified by:
getDriftDetails in interface DriftManagerLocal
Returns:


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