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, databaseFile, inheritedLogPropFile, inheritedSecurityPolicyFile, log, machineDirectory, machineParameters, machineRoot, name, netarchiveSuiteFileName, OS, resetTempDir, scriptExtension, settings
 
Constructor Summary
WindowsMachine(org.dom4j.Element e, XmlStructure parentSettings, Parameters param, java.lang.String netarchiveSuiteSource, java.io.File logProp, java.io.File securityPolicy, java.io.File dbFile, boolean resetDir)
          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 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  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 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 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 e,
                      XmlStructure parentSettings,
                      Parameters param,
                      java.lang.String netarchiveSuiteSource,
                      java.io.File logProp,
                      java.io.File securityPolicy,
                      java.io.File dbFile,
                      boolean resetDir)
The constructor. Starts by initialising the parent abstract class, then sets the operating system dependent variables.

Parameters:
e - 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 name of the database file.
resetDir - Whether the temporary directory should be reset.
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\\security.policy echo 1 ) ]; then echo Y | ssh 'login'@'machine' cmd /c cacls 'environmentName'\\conf\\security.policy /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 - echo Y | ssh 'login'@'machine' cmd /c cacls 'environmentName'\\conf\\jmxremote.password /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 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()
The operation system specific path to the installation directory.

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

getConfDirPath

protected java.lang.String getConfDirPath()
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)
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?).

createOSLocalStartAllScript

protected 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.

Specified by:
createOSLocalStartAllScript in class Machine
Parameters:
directory - The directory for this machine (use global variable?).

createApplicationKillScripts

protected void createApplicationKillScripts(java.io.File directory)
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?).

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)
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)
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.

windowsStartVbsScript

protected void windowsStartVbsScript(Application app,
                                     java.io.File directory)
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 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.

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).

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)
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:
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()
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)
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

changeFileDirPathForSecurity

protected java.lang.String changeFileDirPathForSecurity(java.lang.String path)
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. Makes the jmxremote.access and jmxremote.password files readonly.

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