dk.netarkivet.deploy
Class WindowsMachine

java.lang.Object
  extended by dk.netarkivet.deploy.Machine
      extended by dk.netarkivet.deploy.WindowsMachine

public class WindowsMachine
extends Machine

A WindowsMachine is the instance of the abstract machine class, which runs the operating system Windows. This class only contains the operating system specific functions.


Field Summary
 
Fields inherited from class dk.netarkivet.deploy.Machine
applications, arcDatabaseFile, databaseFile, inheritedLogPropFile, inheritedSecurityPolicyFile, jarFolder, log, machineDirectory, machineParameters, machineRoot, name, netarchiveSuiteFileName, operatingSystem, resetTempDir, scriptExtension, settings
 
Constructor Summary
WindowsMachine(org.dom4j.Element root, XmlStructure parentSettings, Parameters param, java.lang.String netarchiveSuiteSource, java.io.File logProp, java.io.File securityPolicy, java.io.File dbFile, java.io.File arcdbFile, boolean resetDir, java.io.File externalJarFolder)
          The constructor.
 
Method Summary
protected  java.lang.String changeFileDirPathForSecurity(java.lang.String path)
          Changes the file directory path to the format used in the security policy.
protected  void createApplicationKillScripts(java.io.File directory)
          Creates the kill scripts for all the applications.
protected  void createApplicationStartScripts(java.io.File directory)
          Creates the start scripts for all the applications.
protected  void createArchiveDatabaseKillScript(java.io.File dir)
          Creates a script for killing the archive database on a given machine.
protected  void createArchiveDatabaseStartScript(java.io.File dir)
          Creates a script for starting the archive database on a given machine.
protected  void createHarvestDatabaseKillScript(java.io.File dir)
          Creates a script for killing the harvest database on a given machine.
protected  void createHarvestDatabaseStartScript(java.io.File dir)
          Creates a script for starting the harvest database on a given machine.
protected  void createInstallDirScript(java.io.File directory)
          Function to create the script which installs the new directories.
protected  void createOSLocalKillAllScript(java.io.File directory)
          This function creates the script to kill all applications on this machine.
protected  void createOSLocalStartAllScript(java.io.File directory)
          This function creates the script to start all applications on this machine.
protected  java.lang.String createPathToDir(java.lang.String dir)
          Function for creating the directories along the path until the end directory.
protected  void createRestartScript(java.io.File dir)
          Creates scripts for restarting all the applications on a machine.
protected  void createWaitScript(java.io.File dir)
          Creates the script for waiting during restart.
protected  java.lang.String getAppDirectories()
          Creates the script for creating the application specified directories.
protected  java.lang.String getConfDirPath()
          The operation system specific path to the conf directory.
protected  java.lang.String getInstallDirPath()
          The operation system specific path to the installation directory.
protected  java.lang.String getJMXremoteFilesCommand()
          This method does the following: Retrieves the path to the jmxremote.access and jmxremote.password files.
protected  java.lang.String getLocalConfDirPath()
          Creates the local path to the conf dir.
protected  java.lang.String getLocalInstallDirPath()
          Creates the local path to the installation directory.
protected  java.lang.String getMakeDirectoryName()
          Creates the name for the make dir script.
protected  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  java.lang.String osInstallArchiveDatabase()
          THIS HAS NOT BEEN IMPLEMENTED FOR WINDOWS YET - ONLY LINUX! 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  java.lang.String osInstallDatabase()
          THIS HAS NOT BEEN IMPLEMENTED FOR WINDOWS YET - ONLY LINUX! 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  java.lang.String osInstallExternalJarFiles()
          This function makes the part of the install script for installing the external jar files from within the jarFolder.
protected  java.lang.String osInstallScript()
          Creates the operation system specific installation script for this machine.
protected  java.lang.String osInstallScriptCreateDir()
          Creates the specified directories in the deploy config file.
protected  java.lang.String osKillScript()
          Creates the operation system specific killing script for this machine.
protected  java.lang.String osStartScript()
          Creates the operation system specific starting script for this machine.
protected  java.lang.String scriptCreateDir(java.lang.String dir, boolean clean)
          This functions makes the script for creating the new directories.
protected  void windowsStartBatScript(Application app, java.io.File directory)
          Creates the batch script for starting the application.
protected  void windowsStartVbsScript(Application app, java.io.File directory)
          This function creates the VBscript to start the application.
 
Methods inherited from class dk.netarkivet.deploy.Machine
createJmxRemoteAccessFile, createJmxRemotePasswordFile, createLogPropertyFiles, createSecurityPolicyFile, getEnvironmentName, getHeritrixLogin, getHeritrixUsername, getMonitorLogin, getMonitorUsername, machineUserLogin, write, writeToGlobalInstallScript, writeToGlobalKillScript, writeToGlobalStartScript
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WindowsMachine

public WindowsMachine(org.dom4j.Element root,
                      XmlStructure parentSettings,
                      Parameters param,
                      java.lang.String netarchiveSuiteSource,
                      java.io.File logProp,
                      java.io.File securityPolicy,
                      java.io.File dbFile,
                      java.io.File arcdbFile,
                      boolean resetDir,
                      java.io.File externalJarFolder)
The constructor. Starts by initializing the parent abstract class, then sets the operating system dependent variables.

Parameters:
root - The XML root element.
parentSettings - The Settings to be inherited from the PhysicalLocation, where this machine is placed.
param - The machine parameters to be inherited from the PhysicalLocation.
netarchiveSuiteSource - The name of the NetarchiveSuite package file. Must be '.zip'.
logProp - The logging property file, to be copied into machine directory.
securityPolicy - The security policy file, to be copied into machine directory.
dbFile - The harvest definition database file.
arcdbFile - The archive database.
resetDir - Whether the temporary directory should be reset.
externalJarFolder - The folder containing the external jar library files.
Method Detail

osInstallScript

protected java.lang.String osInstallScript()
Creates the operation system specific installation script for this machine. Pseudo code: - echo copying 'NetarchiveSuite.zip' to: 'machine' - scp 'NetarchiveSuite.zip' 'login'@'machine': - echo unzipping 'NetarchiveSuite.zip' at: 'machine' - ssh 'login'@'machine' 'unzip' 'environmentName' -o 'NetarchiveSuite.zip - $'create directories'. - echo preparing for copying of settings and scripts - if [ $( ssh 'login'@'machine' cmd /c if exist 'environmentName'\\conf\\jmxremote.password echo 1 ) ]; then echo Y | ssh 'login'@'machine' cmd /c cacls 'environmentName'\\conf\\jmxremote.password /P BITARKIV\\'login':F; fi - if [ $( ssh 'login'@'machine' cmd /c if exist 'environmentName'\\conf\\jmxremote.access echo 1 ) ]; then echo Y | ssh 'login'@'machine' cmd /c cacls 'environmentName'\\conf\\jmxremote.access /P BITARKIV\\'login':F; fi - echo copying settings and scripts - scp -r 'machine'/* 'login'@'machine':'environmentName'\\conf\\ - $'apply database script' - echo make password files readonly * if 'jmxremote-password-path' != 'jmxremote-password-defaultpath' - ssh 'login'@'machine' move /Y 'jmxremote-password-defaultpath' 'jmxremote-password-path' * if 'jmxremote-access-path' != 'jmxremote-access-defaultpath' - ssh 'login'@'machine' move /Y 'jmxremote-access-defaultpath' 'jmxremote-access-path' - echo Y | ssh 'login'@'machine' cmd /c cacls 'environmentName'\\'jmxremote-password-path' /P BITARKIV\\'login':R - echo Y | ssh 'login'@'machine' cmd /c cacls 'environmentName'\\'jmxremote-access-path' /P BITARKIV\\'login':R variables: 'NetarchiveSuite.zip' = The NetarchiveSuitePackage with '.zip' extension. 'machine' = The machine name. 'login' = The username for the machine. 'unzip' = The command for unzipping. 'environmentName' = the environmentName from the configuration file. $'...' = call other function.

Specified by:
osInstallScript in class Machine
Returns:
Operation system specific part of the installscript

osKillScript

protected java.lang.String osKillScript()
Creates the operation system specific killing script for this machine. pseudocode: - ssh 'login'@'machine' cmd /c 'environmentName'\\conf\\killall.bat variables: 'login' = machine user name 'machine' = name of the machine 'environmentName' = the environmentName from configuration.

Specified by:
osKillScript in class Machine
Returns:
Operation system specific part of the killscript.

osStartScript

protected java.lang.String osStartScript()
Creates the operation system specific starting script for this machine. pseudocode: - ssh 'login'@'machine' cmd /c 'environmentName'\\conf\\startall.bat - sleep 5 - ssh 'login'@'machine' "more 'environmentName'\\start_APP.log variables: 'login' = machine user name 'machine' = name of the machine 'environmentName' = the environmentName from configuration.

Specified by:
osStartScript in class Machine
Returns:
Operation system specific part of the startscript.

getInstallDirPath

protected java.lang.String getInstallDirPath()
Description copied from class: Machine
The operation system specific path to the installation directory.

Specified by:
getInstallDirPath in class Machine
Returns:
Install path.

getConfDirPath

protected java.lang.String getConfDirPath()
Description copied from class: Machine
The operation system specific path to the conf directory.

Specified by:
getConfDirPath in class Machine
Returns:
Conf path.

getLocalConfDirPath

protected java.lang.String getLocalConfDirPath()
Creates the local path to the conf dir.

Returns:
The path to the conf dir for ssh.

getLocalInstallDirPath

protected java.lang.String getLocalInstallDirPath()
Creates the local path to the installation directory.

Returns:
The path to the installation directory for ssh.

createOSLocalKillAllScript

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

Specified by:
createOSLocalKillAllScript in class Machine
Parameters:
directory - The directory for this machine (use global variable?).
Throws:
IOFailure - If an error occurred during the creation of the local killall script.

createOSLocalStartAllScript

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

Specified by:
createOSLocalStartAllScript in class Machine
Parameters:
directory - The directory for this machine (use global variable?).
Throws:
IOFailure - If an error occurred during the creation of the local startall script.

createApplicationKillScripts

protected void createApplicationKillScripts(java.io.File directory)
                                     throws IOFailure
Creates the kill scripts for all the applications. Two script files are created: kill_app.bat and kill_ps_app.bat. kill_ps_app.bat kills the process of the application. kill_app.bat runs kill_ps_app.bat if the application is running. run_app tells if the application is running. It is deleted during kill. The kill_app.bat should have the following structure: - ECHO Killing application : app - CD "path" - IF EXIST run_app GOTO KILL - GOTO NOKILL - - :KILL - cmdrun kill_ps_app.bat - DEL run_app - GOTO DONE - - :NOKILL - ECHO Cannot kill application. Already running. - - :DONE where: app = application name. path = the path to the ./conf directory. cmdrun = the windows command to run other batch programs. The kill_ps_app.bat is empty upon creation. When the application is started, the command to kill the process of he application is written to this file as the only content. It will look something like this: - taskkill /F /PID id where: id = the process identification number of the running application. TODO kill the potential heritrix process, created by a harvester. Just like on Linux/Unix. If we in the future add the possibility of running heritrix on Windows.

Specified by:
createApplicationKillScripts in class Machine
Parameters:
directory - The directory for this machine (use global variable?).
Throws:
IOFailure - If an error occurred during the creation of the application kill script file.

createApplicationStartScripts

protected void createApplicationStartScripts(java.io.File directory)
Creates the start scripts for all the applications. It creates the batch and the VBscript for starting the application, which are called start_app.bat and start_app.vbs respectively. These files are created in each of their own function.

Specified by:
createApplicationStartScripts in class Machine
Parameters:
directory - The directory for this machine (use global variable?).
See Also:
windowsStartBatScript(Application, File), windowsStartVbsScript(Application, File)

osGetClassPath

protected java.lang.String osGetClassPath(Application app)
Description copied from class: Machine
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).

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

windowsStartBatScript

protected void windowsStartBatScript(Application app,
                                     java.io.File directory)
                              throws IOFailure
Creates the batch script for starting the application. It checks if the application is running and starts the application if it is not the case. The application is started by calling the start_app.vbs. The script should be the following: - echo Starting windows application : app - cd "path" - if exist ".\conf\run_app.txt" goto NOSTART - goto START - - :START - cscript .\conf\start_app.vbs - goto DONE - - :NOSTART - echo Application already running. - - :DONE where: app = the name of the application. path = the path to the installation directory.

Parameters:
app - The application to start.
directory - The directory where the script should be placed.
Throws:
IOFailure - If an error occurred during the creation of the windows start bat script.

windowsStartVbsScript

protected void windowsStartVbsScript(Application app,
                                     java.io.File directory)
                              throws IOFailure
This function creates the VBscript to start the application. It calls a command for executing the java application, then it writes the way to kill the process in the kill_ps_app.bat and finally it creates the run-file. It should have the following content: - set WshShell = CreateObject("WScript.Shell") - set oExec = WshShell.exec( JAVA ) - set fso = CreateObject("Scripting.FileSystemObject") - set f = fso.OpenTextFile(".\conf\kill_ps_app.bat", 2, True) - f.WriteLine "taskkill /F /PID " & oExec.ProcessID - f.close - 'Create a new start-log for the application - CreateObject("Scripting.FileSystemObject").OpenTextFile(" start_APP.log", 2, True).close - Do While oExec.Status = 0 - WScript.Sleep 1000 - Do While oExec.StdOut.AtEndOfStream <> True - Set outFile = CreateObject("Scripting.FileSystemObject") .OpenTextFile("start_APP.log", 8, True) - outFile.WriteLine oExec.StdOut.ReadLine - outFile.close - Loop - Do While oExec.StdErr.AtEndOfStream <> True - Set outFile = CreateObject("Scripting.FileSystemObject") .OpenTextFile("start_APP.log", 8, True) - outFile.WriteLine oExec.StdErr.ReadLine - outFile.close - Loop - Loop where: JAVA = the command for starting the java application (very long). app = the name of the application.

Parameters:
app - The application to start.
directory - The directory where the script should be placed.
Throws:
IOFailure - If an error occurred during the creation of the windows vb script.

osInstallDatabase

protected java.lang.String osInstallDatabase()
THIS HAS NOT BEEN IMPLEMENTED FOR WINDOWS YET - ONLY LINUX! 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 (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.

Specified by:
osInstallDatabase in class Machine
Returns:
The script for installing the database (if needed).

osInstallArchiveDatabase

protected java.lang.String osInstallArchiveDatabase()
THIS HAS NOT BEEN IMPLEMENTED FOR WINDOWS YET - ONLY LINUX! 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 (archiveDatabaseFileName = 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.

Specified by:
osInstallArchiveDatabase in class Machine
Returns:
The script for installing the archive database (if needed).

osInstallExternalJarFiles

protected java.lang.String osInstallExternalJarFiles()
Description copied from class: Machine
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.

Specified by:
osInstallExternalJarFiles in class Machine
Returns:
The script for installing the external jar files (if needed).

osInstallScriptCreateDir

protected java.lang.String osInstallScriptCreateDir()
Creates the specified directories in the deploy config file.

Specified by:
osInstallScriptCreateDir in class Machine
Returns:
The script for creating the directories.

scriptCreateDir

protected java.lang.String scriptCreateDir(java.lang.String dir,
                                           boolean clean)
Description copied from class: Machine
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.

Specified by:
scriptCreateDir in class Machine
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:
Machine.createInstallDirScript(File)

createPathToDir

protected java.lang.String createPathToDir(java.lang.String dir)
Function for creating the directories along the path until the end directory. Does not create the end directory.

Parameters:
dir - The path to the directory.
Returns:
The script for creating the directory.

getAppDirectories

protected java.lang.String getAppDirectories()
Description copied from class: Machine
Creates the script for creating the application specified directories. Also creates the directories along the path to the directories.

Specified by:
getAppDirectories in class Machine
Returns:
The script for creating the application specified directories.

getMakeDirectoryName

protected java.lang.String getMakeDirectoryName()
Creates the name for the make dir script.

Returns:
The name of the script for creating the directories.

createInstallDirScript

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

Specified by:
createInstallDirScript in class Machine
Parameters:
directory - The directory to put the file.
Throws:
IOFailure - If an error occurred during the creation of the install-dir script.

changeFileDirPathForSecurity

protected java.lang.String changeFileDirPathForSecurity(java.lang.String path)
Description copied from class: Machine
Changes the file directory path to the format used in the security policy.

Specified by:
changeFileDirPathForSecurity in class Machine
Parameters:
path - The current path.
Returns:
The formatted path.

getJMXremoteFilesCommand

protected 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. This has to be a force move (command 'move /Y'). Makes the jmxremote.access and jmxremote.password files readonly.

Specified by:
getJMXremoteFilesCommand in class Machine
Returns:
The commands for handling the jmxremote files.

createRestartScript

protected void createRestartScript(java.io.File dir)
                            throws IOFailure
Creates scripts for restarting all the applications on a machine. This script should start by killing all the existing processes, and then starting them again. First the killall scripts is called, then wait for 5 seconds for the applications to be fully terminated, and finally call the startall script. The createWaitScript is called through this script to create the wait script which is used by the restart script.

Specified by:
createRestartScript in class Machine
Parameters:
dir - The directory where the script file will be placed.
Throws:
IOFailure - If the restart script cannot be created, or if the wait script cannot be created.

createWaitScript

protected void createWaitScript(java.io.File dir)
                         throws IOFailure
Creates the script for waiting during restart.

Parameters:
dir - The directory where the script should be placed.
Throws:
IOFailure - If the method fails in creating the wait script.

createArchiveDatabaseStartScript

protected void createArchiveDatabaseStartScript(java.io.File dir)
Description copied from class: Machine
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.

Specified by:
createArchiveDatabaseStartScript in class Machine
Parameters:
dir - The directory where the script will be placed.

createArchiveDatabaseKillScript

protected void createArchiveDatabaseKillScript(java.io.File dir)
Description copied from class: Machine
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.

Specified by:
createArchiveDatabaseKillScript in class Machine
Parameters:
dir - The directory where the script will be placed.

createHarvestDatabaseStartScript

protected void createHarvestDatabaseStartScript(java.io.File dir)
Description copied from class: Machine
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.

Specified by:
createHarvestDatabaseStartScript in class Machine
Parameters:
dir - The directory where the script will be placed.

createHarvestDatabaseKillScript

protected void createHarvestDatabaseKillScript(java.io.File dir)
Description copied from class: Machine
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.

Specified by:
createHarvestDatabaseKillScript in class Machine
Parameters:
dir - The directory where the script will be placed.