dk.netarkivet.deploy
Class Machine

java.lang.Object
  extended by dk.netarkivet.deploy.Machine
Direct Known Subclasses:
LinuxMachine, WindowsMachine

public abstract class Machine
extends java.lang.Object

Machine defines an abstract representation of a physical computer at a physical location. The actual instances are depending on the operation system: LinuxMachine and WindowsMachine. All non-OS specific methods are implemented this machine class.


Field Summary
protected  java.util.List<Application> applications
          The list of the application on this machine.
protected  java.io.File arcDatabaseFile
          The inherited archive database file name.
protected  java.io.File databaseFile
          The inherited database file name.
protected  java.io.File inheritedLogPropFile
          The inherited log.prop file.
protected  java.io.File inheritedSecurityPolicyFile
          The inherited security.policy file.
protected  java.io.File jarFolder
          The folder containing the external jar library files.
protected  org.apache.commons.logging.Log log
          the log, for logging stuff instead of displaying them directly.
protected  java.io.File machineDirectory
          The directory for this machine.
protected  Parameters machineParameters
          The machine parameters.
protected  org.dom4j.Element machineRoot
          The root-branch for this machine in the XML tree.
protected  java.lang.String name
          The name of this machine.
protected  java.lang.String netarchiveSuiteFileName
          The name of the NetarchiveSuite.zip file.
protected  java.lang.String operatingSystem
          The operating system on this machine: 'windows' or 'linux'.
protected  boolean resetTempDir
          Whether the temp dir should be cleaned.
protected  java.lang.String scriptExtension
          The extension on the scipt files (specified by operating system).
protected  XmlStructure settings
          The settings, inherited from parent and overwritten.
 
Constructor Summary
Machine(org.dom4j.Element subTreeRoot, XmlStructure parentSettings, Parameters param, java.lang.String netarchiveSuiteSource, java.io.File logProp, java.io.File securityPolicy, java.io.File dbFileName, java.io.File archiveDbFileName, boolean resetDir, java.io.File externalJarFolder)
          A machine is referring to an actual computer at a physical location, which can have independent applications from the other machines at the same location.
 
Method Summary
protected abstract  java.lang.String changeFileDirPathForSecurity(java.lang.String path)
          Changes the file directory path to the format used in the security policy.
protected abstract  void createApplicationKillScripts(java.io.File directory)
          Creates the kill scripts for all the applications.
protected abstract  void createApplicationStartScripts(java.io.File directory)
          Creates the start scripts for all the applications.
protected abstract  void createArchiveDatabaseKillScript(java.io.File dir)
          Creates a script for killing the archive database on a given machine.
protected abstract  void createArchiveDatabaseStartScript(java.io.File dir)
          Creates a script for starting the archive database on a given machine.
protected abstract  void createHarvestDatabaseKillScript(java.io.File dir)
          Creates a script for killing the harvest database on a given machine.
protected abstract  void createHarvestDatabaseStartScript(java.io.File dir)
          Creates a script for starting the harvest database on a given machine.
protected abstract  void createInstallDirScript(java.io.File dir)
          Function to create the script which installs the new directories.
protected  void createJmxRemoteAccessFile(java.io.File directory)
          Creates the jmxremote.password file, based on the settings.
protected  void createJmxRemotePasswordFile(java.io.File directory)
          Creates the jmxremote.password file, based on the settings.
protected  void createLogPropertyFiles(java.io.File directory)
          Creates a the log property file for every application.
protected abstract  void createOSLocalKillAllScript(java.io.File directory)
          This function creates the script to kill all applications on this machine.
protected abstract  void createOSLocalStartAllScript(java.io.File directory)
          This function creates the script to start all applications on this machine.
protected abstract  void createRestartScript(java.io.File dir)
          Creates a script for restating all the applications on a given machine.
protected  void createSecurityPolicyFile(java.io.File directory)
          Copy inherited securityPolicyFile to local directory.
protected abstract  java.lang.String getAppDirectories()
          Creates the script for creating the application specified directories.
protected abstract  java.lang.String getConfDirPath()
          The operation system specific path to the conf directory.
protected  java.lang.String getEnvironmentName()
          For retrieving the environment name variable.
protected  java.lang.String getHeritrixLogin()
          For finding the jmxUsernames and jmxPasswords under the harvest.harvesting.heritrix branch under in the settings.
protected  java.lang.String getHeritrixUsername()
          For retrieving the Heritrix username for the jmxremote.access file.
protected abstract  java.lang.String getInstallDirPath()
          The operation system specific path to the installation directory.
protected abstract  java.lang.String getJMXremoteFilesCommand()
          This method does the following: Retrieves the path to the jmxremote.access and jmxremote.password files.
protected  java.lang.String getMonitorLogin()
          For finding the jmxUsernames and jmxPasswords under the monitor branch in the settings.
protected  java.lang.String getMonitorUsername()
          For retrieving the monitor username for the jmxremote.access file.
protected  java.lang.String machineUserLogin()
          The string for accessing this machine through SSH.
protected abstract  java.lang.String osGetClassPath(Application app)
          Makes all the class paths into the operation system specific syntax, and puts them into a string where they are separated by the operation system specific separator (':' for linux, ';' for windows).
protected abstract  java.lang.String osInstallArchiveDatabase()
          Checks if a specific directory for the archive database is given in the settings, and thus if the archive database should be installed on this machine.
protected abstract  java.lang.String osInstallDatabase()
          Checks if a specific directory for the database is given in the settings, and thus if the database should be installed on this machine.
protected abstract  java.lang.String osInstallExternalJarFiles()
          This function makes the part of the install script for installing the external jar files from within the jarFolder.
protected abstract  java.lang.String osInstallScript()
          Creates the operation system specific installation script for this machine.
protected abstract  java.lang.String osInstallScriptCreateDir()
          Creates the specified directories in the deploy-configuration file.
protected abstract  java.lang.String osKillScript()
          Creates the operation system specific killing script for this machine.
protected abstract  java.lang.String osStartScript()
          Creates the operation system specific starting script for this machine.
protected abstract  java.lang.String scriptCreateDir(java.lang.String dir, boolean clean)
          This functions makes the script for creating the new directories.
 void write(java.io.File parentDirectory)
          Create the directory for the specific configurations of this machine and call the functions for creating all the scripts in this directory.
 java.lang.String writeToGlobalInstallScript()
          Make the script for installing this machine.
 java.lang.String writeToGlobalKillScript()
          Make the script for killing this machine.
 java.lang.String writeToGlobalStartScript()
          Make the script for starting this machine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.commons.logging.Log log
the log, for logging stuff instead of displaying them directly.


machineRoot

protected org.dom4j.Element machineRoot
The root-branch for this machine in the XML tree.


settings

protected XmlStructure settings
The settings, inherited from parent and overwritten.


machineParameters

protected Parameters machineParameters
The machine parameters.


applications

protected java.util.List<Application> applications
The list of the application on this machine.


name

protected java.lang.String name
The name of this machine.


operatingSystem

protected java.lang.String operatingSystem
The operating system on this machine: 'windows' or 'linux'.


scriptExtension

protected java.lang.String scriptExtension
The extension on the scipt files (specified by operating system).


netarchiveSuiteFileName

protected java.lang.String netarchiveSuiteFileName
The name of the NetarchiveSuite.zip file.


inheritedLogPropFile

protected java.io.File inheritedLogPropFile
The inherited log.prop file.


inheritedSecurityPolicyFile

protected java.io.File inheritedSecurityPolicyFile
The inherited security.policy file.


databaseFile

protected java.io.File databaseFile
The inherited database file name.


arcDatabaseFile

protected java.io.File arcDatabaseFile
The inherited archive database file name.


machineDirectory

protected java.io.File machineDirectory
The directory for this machine.


resetTempDir

protected boolean resetTempDir
Whether the temp dir should be cleaned.


jarFolder

protected java.io.File jarFolder
The folder containing the external jar library files.

Constructor Detail

Machine

public Machine(org.dom4j.Element subTreeRoot,
               XmlStructure parentSettings,
               Parameters param,
               java.lang.String netarchiveSuiteSource,
               java.io.File logProp,
               java.io.File securityPolicy,
               java.io.File dbFileName,
               java.io.File archiveDbFileName,
               boolean resetDir,
               java.io.File externalJarFolder)
        throws ArgumentNotValid
A machine is referring to an actual computer at a physical location, which can have independent applications from the other machines at the same location.

Parameters:
subTreeRoot - The root of this instance in the XML document.
parentSettings - The setting inherited by the parent.
param - The machine parameters inherited by the parent.
netarchiveSuiteSource - The name of the NetarchiveSuite package file.
logProp - The logging property file.
securityPolicy - The security policy file.
dbFileName - The name of the database file.
archiveDbFileName - The name of the archive database file.
resetDir - Whether the temporary directory should be reset.
externalJarFolder - The folder containing the external jar library files.
Throws:
ArgumentNotValid - If one of the following arguments are null: subTreeRoot, parentSettings, param, netarchiveSuiteSource, logProp, securityPolicy.
Method Detail

write

public void write(java.io.File parentDirectory)
           throws ArgumentNotValid
Create the directory for the specific configurations of this machine and call the functions for creating all the scripts in this directory.

Parameters:
parentDirectory - The directory where to write the files.
Throws:
ArgumentNotValid - If the parenteDirectory is null.

writeToGlobalKillScript

public java.lang.String writeToGlobalKillScript()
Make the script for killing this machine. This is put into the entire kill all script for the physical location.

Returns:
The script to kill this machine.

writeToGlobalInstallScript

public java.lang.String writeToGlobalInstallScript()
Make the script for installing this machine. This is put into the entire install script for the physical location.

Returns:
The script to make the installation on this machine

writeToGlobalStartScript

public java.lang.String writeToGlobalStartScript()
Make the script for starting this machine. This is put into the entire startall script for the physical location.

Returns:
The script to start this machine.

createSecurityPolicyFile

protected void createSecurityPolicyFile(java.io.File directory)
                                 throws IOFailure
Copy inherited securityPolicyFile to local directory.

Parameters:
directory - The local directory for this machine.
Throws:
IOFailure - If an error occurred during the creation of the security policy file.

createLogPropertyFiles

protected void createLogPropertyFiles(java.io.File directory)
                               throws IOFailure
Creates a the log property file for every application. This is done by taking the inherited log file and changing "APPID" in the file into the identification of the application.

Parameters:
directory - The local directory for this machine
Throws:
IOFailure - If an error occurred during the creationg of the log property file.

createJmxRemotePasswordFile

protected void createJmxRemotePasswordFile(java.io.File directory)
                                    throws IOFailure
Creates the jmxremote.password file, based on the settings.

Parameters:
directory - The local directory for this machine
Throws:
IOFailure - If an error occurred during the creation of the jmx remote password file.

createJmxRemoteAccessFile

protected void createJmxRemoteAccessFile(java.io.File directory)
                                  throws IOFailure
Creates the jmxremote.password file, based on the settings.

Parameters:
directory - The local directory for this machine
Throws:
IOFailure - If an error occurred during the creation of the jmx remote access file.

getMonitorLogin

protected java.lang.String getMonitorLogin()
                                    throws IllegalState
For finding the jmxUsernames and jmxPasswords under the monitor branch in the settings. Goes through all applications, which all must have the same username and the same passwords.

Returns:
The string to add to the jmxremote.password file.
Throws:
IllegalState - If there is a different amount of usernames and passwords, or if two application has different values for their username or passwords (applications without values are ignored).

getMonitorUsername

protected java.lang.String getMonitorUsername()
                                       throws IllegalState
For retrieving the monitor username for the jmxremote.access file. This will have the rights 'readonly'.

Returns:
The string for the jmxremote.access file for allowing the monitor user to readonly.
Throws:
IllegalState - If different applications on the machine have different user names.

getHeritrixLogin

protected java.lang.String getHeritrixLogin()
                                     throws IllegalState
For finding the jmxUsernames and jmxPasswords under the harvest.harvesting.heritrix branch under in the settings. Goes through all applications, which all must have the same username and the same passwords.

Returns:
The string to add to the jmxremote.password file.
Throws:
IllegalState - If there is a different amount of usernames and passwords, or if two application has different values for their username or passwords (applications without values are ignored).

getHeritrixUsername

protected java.lang.String getHeritrixUsername()
For retrieving the Heritrix username for the jmxremote.access file. This will have the rights 'readwrite'.

Returns:
The string for the jmxremote.access file for allowing the heritrix user to readonly.

machineUserLogin

protected java.lang.String machineUserLogin()
The string for accessing this machine through SSH.

Returns:
The access through SSH to the machine

getEnvironmentName

protected java.lang.String getEnvironmentName()
For retrieving the environment name variable.

Returns:
The environment name.

createApplicationKillScripts

protected abstract void createApplicationKillScripts(java.io.File directory)
Creates the kill scripts for all the applications.

Parameters:
directory - The directory for this machine (use global variable?).

createApplicationStartScripts

protected abstract void createApplicationStartScripts(java.io.File directory)
Creates the start scripts for all the applications.

Parameters:
directory - The directory for this machine (use global variable?).

createOSLocalStartAllScript

protected abstract void createOSLocalStartAllScript(java.io.File directory)
This function creates the script to start all applications on this machine. The scripts calls all the start script for each application.

Parameters:
directory - The directory for this machine (use global variable?).

createOSLocalKillAllScript

protected abstract void createOSLocalKillAllScript(java.io.File directory)
This function creates the script to kill all applications on this machine. The scripts calls all the kill script for each application.

Parameters:
directory - The directory for this machine (use global variable?).

getInstallDirPath

protected abstract java.lang.String getInstallDirPath()
The operation system specific path to the installation directory.

Returns:
Install path.

getConfDirPath

protected abstract java.lang.String getConfDirPath()
The operation system specific path to the conf directory.

Returns:
Conf path.

osKillScript

protected abstract java.lang.String osKillScript()
Creates the operation system specific killing script for this machine.

Returns:
Operation system specific part of the killscript.

osInstallScript

protected abstract java.lang.String osInstallScript()
Creates the operation system specific installation script for this machine.

Returns:
Operation system specific part of the installscript.

osInstallScriptCreateDir

protected abstract java.lang.String osInstallScriptCreateDir()
Creates the specified directories in the deploy-configuration file.

Returns:
The script for creating the directories.

osStartScript

protected abstract java.lang.String osStartScript()
Creates the operation system specific starting script for this machine.

Returns:
Operation system specific part of the startscript.

osGetClassPath

protected abstract java.lang.String osGetClassPath(Application app)
Makes all the class paths into the operation system specific syntax, and puts them into a string where they are separated by the operation system specific separator (':' for linux, ';' for windows).

Parameters:
app - The application which has the class paths.
Returns:
The class paths in operation system specific syntax.

osInstallDatabase

protected abstract java.lang.String osInstallDatabase()
Checks if a specific directory for the database is given in the settings, and thus if the database should be installed on this machine. If no specific database is given as deploy argument (databaseFileName = null) then use the standard database extracted from NetarchiveSuite.zip. Else send the given new database to the standard database location. Extract the database in the standard database location to the specified database directory.

Returns:
The script for installing the database (if needed).

osInstallArchiveDatabase

protected abstract java.lang.String osInstallArchiveDatabase()
Checks if a specific directory for the archive database is given in the settings, and thus if the archive database should be installed on this machine. If not specific database is given (adminDatabaseFileName = null) then use the default in the NetarchiveSuite.zip package. Else send the new archive database to the standard database location, and extract it to the given location.

Returns:
The script for installing the archive database (if needed).

osInstallExternalJarFiles

protected abstract java.lang.String osInstallExternalJarFiles()
This function makes the part of the install script for installing the external jar files from within the jarFolder. If the jarFolder is null, then no action will be performed.

Returns:
The script for installing the external jar files (if needed).

scriptCreateDir

protected abstract java.lang.String scriptCreateDir(java.lang.String dir,
                                                    boolean clean)
This functions makes the script for creating the new directories. Linux creates directories directly through ssh. Windows creates an install a script file for installing the directories, which has to be sent to the machine, then executed and finally deleted.

Parameters:
dir - The name of the directory to create.
clean - Whether the directory should be cleaned\reset.
Returns:
The lines of code for creating the directories.
See Also:
createInstallDirScript(File)

getAppDirectories

protected abstract java.lang.String getAppDirectories()
Creates the script for creating the application specified directories. Also creates the directories along the path to the directories.

Returns:
The script for creating the application specified directories.

getJMXremoteFilesCommand

protected abstract java.lang.String getJMXremoteFilesCommand()
This method does the following: Retrieves the path to the jmxremote.access and jmxremote.password files. Moves these files, if they are different from standard. Makes the jmxremote.access and jmxremote.password files readonly.

Returns:
The commands for handling the jmxremote files.

createInstallDirScript

protected abstract void createInstallDirScript(java.io.File dir)
Function to create the script which installs the new directories. This is only used for windows machines!

Parameters:
dir - The directory to put the file

createRestartScript

protected abstract void createRestartScript(java.io.File dir)
Creates a script for restating all the applications on a given machine.

Parameters:
dir - The directory where the script will be placed.

createArchiveDatabaseStartScript

protected abstract void createArchiveDatabaseStartScript(java.io.File dir)
Creates a script for starting the archive database on a given machine. This is only created if the <globalArchiveDatabaseDir> parameter is defined on the machine level.

Parameters:
dir - The directory where the script will be placed.

createArchiveDatabaseKillScript

protected abstract void createArchiveDatabaseKillScript(java.io.File dir)
Creates a script for killing the archive database on a given machine. This is only created if the <globalArchiveDatabaseDir> parameter is defined on the machine level.

Parameters:
dir - The directory where the script will be placed.

createHarvestDatabaseStartScript

protected abstract void createHarvestDatabaseStartScript(java.io.File dir)
Creates a script for starting the harvest database on a given machine. This is only created if the <deployHarvestDatabaseDir> parameter is defined on the machine level.

Parameters:
dir - The directory where the script will be placed.

createHarvestDatabaseKillScript

protected abstract void createHarvestDatabaseKillScript(java.io.File dir)
Creates a script for killing the harvest database on a given machine. This is only created if the <globalHarvestDatabaseDir> parameter is defined on the machine level.

Parameters:
dir - The directory where the script will be placed.

changeFileDirPathForSecurity

protected abstract java.lang.String changeFileDirPathForSecurity(java.lang.String path)
Changes the file directory path to the format used in the security policy.

Parameters:
path - The current path.
Returns:
The formatted path.