Class 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.
    • Constructor Detail

      • WindowsMachine

        public WindowsMachine​(org.dom4j.Element root,
                              XmlStructure parentSettings,
                              Parameters param,
                              String netarchiveSuiteSource,
                              File slf4JConfig,
                              File securityPolicy,
                              File dbFile,
                              File arcdbFile,
                              boolean resetDir,
                              File externalJarFolder,
                              File logoFile,
                              File menulogoFile,
                              File bitmagDir)
        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'.
        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.
        bitmagDir - The folder containing the bitmagasin configuration.
    • Method Detail

      • copyBitmagClientConfig

        protected void copyBitmagClientConfig()
        Description copied from class: Machine
        Copies the directory containing the client configuration for connecting to bitmag into the "conf" directory for the installation on this machine. This only needs to be done for machine with HarvestControllerApplications and hence only needs a non-trivial implementation for Linux machines.
        Specified by:
        copyBitmagClientConfig in class Machine
      • osInstallScript

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

        protected String getLibDirPath()
        Description copied from class: Machine
        The operation system specific path to the lib directory.
        Specified by:
        getLibDirPath in class Machine
        Returns:
        Lib path.
      • getLocalConfDirPath

        protected String getLocalConfDirPath()
        Creates the local path to the conf dir.
        Returns:
        The path to the conf dir for ssh.
      • getLocalLibDirPath

        protected String getLocalLibDirPath()
        Creates the local path to the lib dir.
        Returns:
        The path to the lib dir for ssh.
      • getLocalInstallDirPath

        protected String getLocalInstallDirPath()
        Creates the local path to the installation directory.
        Returns:
        The path to the installation directory for ssh.
      • createOSLocalKillAllScript

        protected void createOSLocalKillAllScript​(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​(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​(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.
      • osGetClassPath

        protected 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,
                                             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,
                                             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 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 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 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 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 String scriptCreateDir​(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 String createPathToDir​(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 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 String getMakeDirectoryName()
        Creates the name for the make dir script.
        Returns:
        The name of the script for creating the directories.
      • createInstallDirScript

        protected void createInstallDirScript​(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 String changeFileDirPathForSecurity​(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 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​(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​(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​(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​(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​(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​(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.
      • createHarvestDatabaseUpdateScript

        protected void createHarvestDatabaseUpdateScript​(File machineDirectory,
                                                         boolean forceCreate)
        Description copied from class: Machine
        create a harvestDatabaseUpdatescript in the given machineDirectory.
        Specified by:
        createHarvestDatabaseUpdateScript in class Machine
        Parameters:
        machineDirectory - a given MachineDirectory.
      • osUpdateLogos

        protected String osUpdateLogos()
        Description copied from class: Machine
        Updates user specific Logos in all war files.
        Specified by:
        osUpdateLogos in class Machine
        Returns:
        The script for updating logos in all war files.