Class Machine

  • Direct Known Subclasses:
    LinuxMachine, WindowsMachine

    public abstract class Machine
    extends 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 Detail

      • log

        protected static final org.slf4j.Logger 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 List<Application> applications
        The list of the application on this machine.
      • hostname

        protected String hostname
        The name of this machine.
      • operatingSystem

        protected String operatingSystem
        The operating system on this machine: 'windows' or 'linux'.
      • scriptExtension

        protected String scriptExtension
        The extension on the script files (specified by operating system).
      • netarchiveSuiteFileName

        protected String netarchiveSuiteFileName
        The name of the NetarchiveSuite.zip file.
      • inheritedSlf4jConfigFile

        protected File inheritedSlf4jConfigFile
        The inherited SLF4J config file.
      • inheritedSecurityPolicyFile

        protected File inheritedSecurityPolicyFile
        The inherited security.policy file.
      • databaseFile

        protected File databaseFile
        The inherited database file name.
      • arcDatabaseFile

        protected File arcDatabaseFile
        The inherited archive database file name.
      • machineDirectory

        protected File machineDirectory
        The directory for this machine.
      • resetTempDir

        protected boolean resetTempDir
        Whether the temp dir should be cleaned.
      • jarFolder

        protected File jarFolder
        The folder containing the external jar library files.
      • targetEncoding

        protected String targetEncoding
        The encoding to use when writing files.
      • logoFile

        protected File logoFile
        user specific logo png file
      • menulogoFile

        protected File menulogoFile
        user specific menulogo png file
      • bitmagasinFolder

        protected File bitmagasinFolder
        The folder containing bitmagasin configuration.
    • Constructor Detail

      • Machine

        public Machine​(org.dom4j.Element subTreeRoot,
                       XmlStructure parentSettings,
                       Parameters param,
                       String netarchiveSuiteSource,
                       File slf4JConfig,
                       File securityPolicy,
                       File dbFileName,
                       File archiveDbFileName,
                       boolean resetDir,
                       File externalJarFolder,
                       File aLogoFile,
                       File aMenulogoFile,
                       File bitmagDir)
                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.
        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.
        bitmagDir - The folder containing the bitmagasin configuration. May be null if not installation does not involve use of bitmag.
        Throws:
        ArgumentNotValid - If one of the following arguments are null: subTreeRoot, parentSettings, param, netarchiveSuiteSource, logProp, securityPolicy.
    • Method Detail

      • write

        public void write​(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 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 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 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​(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.
      • createSlf4jConfigFiles

        protected void createSlf4jConfigFiles​(File directory)
                                       throws IOFailure
        Creates a the SLF4J config 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.
      • modifyLogProperties

        protected String modifyLogProperties​(String logProperties)
        Make any OS-specific modifications to logging properties. The default makes no modifications, but this can be overridden in subclasses.
        Parameters:
        logProperties - the contents of the logging properties file.
        Returns:
        the contents of the logging properties file with any desired modifications.
      • createJmxRemotePasswordFile

        protected void createJmxRemotePasswordFile​(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​(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 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 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 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 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.
      • copyBitmagClientConfig

        protected abstract void copyBitmagClientConfig()
        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.
      • machineUserLogin

        protected String machineUserLogin()
        The string for accessing this machine through SSH.
        Returns:
        The access through SSH to the machine
      • getEnvironmentName

        protected String getEnvironmentName()
        For retrieving the environment name variable.
        Returns:
        The environment name.
      • createApplicationKillScripts

        protected abstract void createApplicationKillScripts​(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​(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​(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​(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 String getInstallDirPath()
        The operation system specific path to the installation directory.
        Returns:
        Install path.
      • getConfDirPath

        protected abstract String getConfDirPath()
        The operation system specific path to the conf directory.
        Returns:
        Conf path.
      • getLibDirPath

        protected abstract String getLibDirPath()
        The operation system specific path to the lib directory.
        Returns:
        Lib path.
      • osKillScript

        protected abstract String osKillScript()
        Creates the operation system specific killing script for this machine.
        Returns:
        Operation system specific part of the killscript.
      • osInstallScript

        protected abstract String osInstallScript()
        Creates the operation system specific installation script for this machine.
        Returns:
        Operation system specific part of the installscript.
      • osInstallScriptCreateDir

        protected abstract String osInstallScriptCreateDir()
        Creates the specified directories in the deploy-configuration file.
        Returns:
        The script for creating the directories.
      • osUpdateLogos

        protected abstract String osUpdateLogos()
        Updates user specific Logos in all war files.
        Returns:
        The script for updating logos in all war files.
      • osStartScript

        protected abstract String osStartScript()
        Creates the operation system specific starting script for this machine.
        Returns:
        Operation system specific part of the startscript.
      • osGetClassPath

        protected abstract 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 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 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 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 String scriptCreateDir​(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 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 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​(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​(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​(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​(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​(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​(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 String changeFileDirPathForSecurity​(String path)
        Changes the file directory path to the format used in the security policy.
        Parameters:
        path - The current path.
        Returns:
        The formatted path.
      • createHarvestDatabaseUpdateScript

        protected abstract void createHarvestDatabaseUpdateScript​(File machineDirectory,
                                                                  boolean forceCreate)
        create a harvestDatabaseUpdatescript in the given machineDirectory.
        Parameters:
        machineDirectory - a given MachineDirectory.
        forceCreate -
      • getTargetEncoding

        protected String getTargetEncoding()