org.rhq.core.util.updater
Class DeploymentsMetadata

java.lang.Object
  extended by org.rhq.core.util.updater.DeploymentsMetadata

public class DeploymentsMetadata
extends Object

This loads and stores metadata about installs of a particular bundle deployment.

Author:
John Mazzitelli

Field Summary
static String BACKUP_DIR
           
static String CURRENT_DEPLOYMENT_FILE
           
static String DEPLOYMENT_FILE
           
static String EXT_BACKUP_DIR
           
static String HASHCODES_FILE
           
static String METADATA_DIR
           
static String PREVIOUS_DEPLOYMENT_FILE
           
 
Constructor Summary
DeploymentsMetadata(File rootDirectory)
          Creates the metadata object given the root directory where the bundle deployment is installed.
 
Method Summary
 FileHashcodeMap getCurrentDeploymentFileHashcodes()
          Returns the files and their hashcodes for the current deployment.
 DeploymentProperties getCurrentDeploymentProperties()
          Returns information about the current deployment.
 File getDeploymentBackupDirectory(int deploymentId)
          Returns a metadata directory that is appropriate to place backup files for the deployment.
 Map<String,File> getDeploymentExternalBackupDirectoriesForWindows(int deploymentId)
          Returns all the metadata directories that contain backup files for external directories (i.e.
 File getDeploymentExternalBackupDirectory(int deploymentId)
          Returns a metadata directory that is appropriate to place backup files for the deployment.
 FileHashcodeMap getDeploymentFileHashcodes(int deploymentId)
          Returns the files and their hashcodes for the given deployment.
 DeploymentProperties getDeploymentProperties(int deploymentId)
          Returns information about the deployment with the given ID.
 String getExternalBackupDirectoryNameForWindows(String driveLetter)
          Given a Windows drive letter, this will return the name of the external backup directory where all backups for external files should be copied to.
 File getMetadataDirectory()
           
 File getMetadataDirectoryOnlyIfExists()
          Same as getMetadataDirectory(), however, if the directory doesn't exist, an exception is thrown.
 DeploymentProperties getPreviousDeploymentProperties(int deploymentId)
          Returns information about the previous deployment given a specific deployment ID.
 File getRootDirectory()
           
 boolean isManaged()
          If this object's getRootDirectory() refers to a directory containing managed deployments, this returns true.
 void setCurrentDeployment(DeploymentProperties deploymentProps, FileHashcodeMap fileHashcodeMap, boolean rememberPrevious)
          Call this when you already know the properties, and files/hashcodes for the current live deployment.
 FileHashcodeMap snapshotLiveDeployment(DeploymentProperties deploymentProps, Pattern ignoreRegex, Set<String> ignored)
          Looks at the live deployment and takes a snapshot of it and stores its metadata in its appropriate deployment metadata directory.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

METADATA_DIR

public static final String METADATA_DIR
See Also:
Constant Field Values

CURRENT_DEPLOYMENT_FILE

public static final String CURRENT_DEPLOYMENT_FILE
See Also:
Constant Field Values

PREVIOUS_DEPLOYMENT_FILE

public static final String PREVIOUS_DEPLOYMENT_FILE
See Also:
Constant Field Values

DEPLOYMENT_FILE

public static final String DEPLOYMENT_FILE
See Also:
Constant Field Values

HASHCODES_FILE

public static final String HASHCODES_FILE
See Also:
Constant Field Values

BACKUP_DIR

public static final String BACKUP_DIR
See Also:
Constant Field Values

EXT_BACKUP_DIR

public static final String EXT_BACKUP_DIR
See Also:
Constant Field Values
Constructor Detail

DeploymentsMetadata

public DeploymentsMetadata(File rootDirectory)
Creates the metadata object given the root directory where the bundle deployment is installed.

Parameters:
rootDirectory - the location where the bundle deployments will go and where the metadata directory is located
Method Detail

toString

public String toString()
Overrides:
toString in class Object

getRootDirectory

public File getRootDirectory()
Returns:
the root directory where the bundle deployments are and where the metadata directory is located. The returned File will have an absolute path.

isManaged

public boolean isManaged()
If this object's getRootDirectory() refers to a directory containing managed deployments, this returns true. If that root location is not managed, false is returned.

Returns:
indication if the root directory has deployments that are managed

getMetadataDirectory

public File getMetadataDirectory()
Returns:
the directory where the metadata does or should exist

getMetadataDirectoryOnlyIfExists

public File getMetadataDirectoryOnlyIfExists()
                                      throws Exception
Same as getMetadataDirectory(), however, if the directory doesn't exist, an exception is thrown.

Returns:
the directory where the metadata exists
Throws:
Exception - if the directory does not exist

getCurrentDeploymentProperties

public DeploymentProperties getCurrentDeploymentProperties()
                                                    throws Exception
Returns information about the current deployment.

Returns:
props with current deployment information
Throws:
Exception - if could not determine the current deployment

getDeploymentProperties

public DeploymentProperties getDeploymentProperties(int deploymentId)
                                             throws Exception
Returns information about the deployment with the given ID.

Parameters:
id - identifies which deployment the caller wants information on
Returns:
props with deployment information
Throws:
Exception - if could not find the deployment information

getPreviousDeploymentProperties

public DeploymentProperties getPreviousDeploymentProperties(int deploymentId)
                                                     throws Exception
Returns information about the previous deployment given a specific deployment ID.

Parameters:
id - identifies which deployment whose previous deployment props are to be returned
Returns:
props with previous deployment information, or null if there was no previous deployment
Throws:
Exception - if could not load the previous deployment information or the given deployment ID is invalid

getCurrentDeploymentFileHashcodes

public FileHashcodeMap getCurrentDeploymentFileHashcodes()
                                                  throws Exception
Returns the files and their hashcodes for the current deployment. This does not perform live computations of the file hashcodes, instead it reads the data out of the metadata file from a previous computation when the files were initially deployed. In other words, if someone has recently changed a file after it was initially deployed, the returned map will not know about it.

Returns:
map of files/hashcodes when the current deployment was initially deployed
Throws:
Exception

getDeploymentFileHashcodes

public FileHashcodeMap getDeploymentFileHashcodes(int deploymentId)
                                           throws Exception
Returns the files and their hashcodes for the given deployment. This does not perform live computations of the file hashcodes, instead it reads the data out of the metadata file for the given deployment.

Parameters:
deploymentId - the ID of the deployment whose files/hashcodes are to be returned
Returns:
map of files/hashcodes when the current deployment was initially deployed
Throws:
Exception

getDeploymentBackupDirectory

public File getDeploymentBackupDirectory(int deploymentId)
                                  throws Exception
Returns a metadata directory that is appropriate to place backup files for the deployment. Files placed here are files found in the deployment directory that needed to be backed up before being overwritten or deleted.

Parameters:
deploymentId - the ID of the deployment whose backup directory is to be returned
Returns:
backup directory for the deployment
Throws:
Exception

getDeploymentExternalBackupDirectory

public File getDeploymentExternalBackupDirectory(int deploymentId)
                                          throws Exception
Returns a metadata directory that is appropriate to place backup files for the deployment. Files placed here are files found in external directories (i.e. outside the deployment directory) that needed to be backed up before being overwritten or deleted.

Parameters:
deploymentId - the ID of the deployment whose backup directory is to be returned
Returns:
backup directory for the deployment's external files
Throws:
Exception

getDeploymentExternalBackupDirectoriesForWindows

public Map<String,File> getDeploymentExternalBackupDirectoriesForWindows(int deploymentId)
                                                                  throws Exception
Returns all the metadata directories that contain backup files for external directories (i.e. outside the deployment directory). The returned map has driver letter root directories as their keys (e.g. "C:\"); the values are the backup directories that contain files that were stored on their associated drive. Obviously, this method is only appropriate to be called on Windows platforms. If this method is called while the Java VM is running in a non-Windows environment, null is returned.

Parameters:
deploymentId - the ID of the deployment whose backup directories are to be returned
Returns:
backup directories for the deployment's external files, keyed on the drive letter root directory
Throws:
Exception

getExternalBackupDirectoryNameForWindows

public String getExternalBackupDirectoryNameForWindows(String driveLetter)
Given a Windows drive letter, this will return the name of the external backup directory where all backups for external files should be copied to. This method involves no relative or absolute paths, this only returns the short name of the directory. The returned name should be appended to the end of a external backup directory to obtain the full path.

Parameters:
driveLetter -
Returns:
the name of the directory that should be used when storing external files for backup.

setCurrentDeployment

public void setCurrentDeployment(DeploymentProperties deploymentProps,
                                 FileHashcodeMap fileHashcodeMap,
                                 boolean rememberPrevious)
                          throws Exception
Call this when you already know the properties, and files/hashcodes for the current live deployment. This method will also mark this initialized, live deployment as the "current" deployment. In addition, if rememberPrevious is true, this will take the previous deployment information and backup that data - pass false if you merely want to update the current deployment properties without affecting anything else, specifically the backed up previous deployment data.

Parameters:
deploymentProps - identifies the deployment information for the live deployment
fileHashcodeMap - the files and their hashcodes of the current live deployment
rememberPrevious - if true, this will create a backup of the previous deployment data
Throws:
Exception - if failed to write out the necessary metadata about the given live data information

snapshotLiveDeployment

public FileHashcodeMap snapshotLiveDeployment(DeploymentProperties deploymentProps,
                                              Pattern ignoreRegex,
                                              Set<String> ignored)
                                       throws Exception
Looks at the live deployment and takes a snapshot of it and stores its metadata in its appropriate deployment metadata directory. The "live deployment" means the actual files in the root directory. This method will also mark the live deployment as the "current" deployment.

Parameters:
deploymentProps - identifies the deployment information for the live data
ignoreRegex - the live files/directories to ignore
ignored - a set that will contain those files/directories that were ignored while scanning the deployment
Returns:
the map of the files/hashcodes
Throws:
Exception - if failed to calculate and store the metadata


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