Class LocalServerCommand

  • All Implemented Interfaces:
    org.glassfish.hk2.api.PostConstruct
    Direct Known Subclasses:
    LocalDomainCommand

    public abstract class LocalServerCommand
    extends com.sun.enterprise.admin.cli.CLICommand
    A class that's supposed to capture all the behavior common to operation on a "local" server. It's getting fairly complicated thus the "section headers" comments. This class plays two roles,
    • a place for putting common code - which are final methods. A parent class that is communicating with its own unknown sub-classes. These are non-final methods
    Author:
    Byron Nevins
    • Field Summary

      • Fields inherited from class com.sun.enterprise.admin.cli.CLICommand

        argv, commandModel, CONNECTION_ERROR, env, ERROR, INVALID_COMMAND_ERROR, logger, metadataErrors, name, operands, options, passwords, programOpts, SUCCESS, WARNING
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean checkForSpecialFiles()
      Override this method and return false to turn-off the file validation.
      protected com.sun.enterprise.util.HostAndPort getAdminAddress()
      Returns the admin address of the local domain.
      protected com.sun.enterprise.util.HostAndPort getAdminAddress​(String serverName)
      Returns the admin address of a particular server.
      protected File getDomainXml()  
      protected String getMasterPassword()
      Get the master password, either from a password file or by asking the user.
      protected File getMasterPasswordFile()  
      protected int getPrevPid()  
      protected com.sun.enterprise.util.io.ServerDirs getServerDirs()  
      protected int getServerPid()  
      protected long getUptime()
      Get uptime from the server.
      protected boolean isLocal()  
      protected boolean isRemote()  
      protected boolean isRestartable()
      See if the server is restartable As of March 2011 -- this only returns false if a passwordfile argument was given when the server started -- but it is no longer available - i.e.
      protected boolean isRunning()
      Is the server still running? This is only called when we're hanging around waiting for the server to die.
      protected boolean isRunning​(String host, int port)
      There is sometimes a need for subclasses to know if a local domain is running.
      protected boolean isThisServer​(File ourDir, String directoryKey)
      See if the server is alive and is the one at the specified directory.
      protected boolean loadAndVerifyKeystore​(File jks, String mpv)  
      protected String readFromMasterPasswordFile()
      Checks if the create-domain was created using --savemasterpassword flag which obtains security by obfuscation! Returns null in case of failure of any kind.
      protected void resetServerDirs()  
      protected void setLocalPassword()  
      protected void setServerDirs​(com.sun.enterprise.util.io.ServerDirs sd)  
      protected void unsetLocalPassword()  
      protected boolean verifyMasterPassword​(String mpv)  
      protected void waitForRestart​(int oldServerPid)
      Byron Nevins Says: We have quite a historical assortment of ways to determine if a server has restarted.
      • Methods inherited from class com.sun.enterprise.admin.cli.CLICommand

        checkHelp, execute, executeCommand, expandManPage, getBooleanOption, getBriefCommandUsage, getCommand, getCommand, getCommandScope, getCommandUsage, getManPage, getName, getOperandModel, getOption, getOptions, getPassword, getPassword, getProgramOptions, getSystemProperties, getSystemProperty, getUsage, initializeLogger, initializePasswords, inject, ok, parse, postConstruct, prepare, prevalidate, printExceptionStackTrace, processProgramOptions, quote, readPassword, setCommandScope, toString, usageOptions, validate
    • Constructor Detail

      • LocalServerCommand

        public LocalServerCommand()
    • Method Detail

      • checkForSpecialFiles

        protected boolean checkForSpecialFiles()
        Override this method and return false to turn-off the file validation. E.g. it demands that config/domain.xml be present. In special cases like Synchronization -- this is how you turn off the testing.
        Returns:
        true - do the checks, false - don't do the checks
      • getAdminAddress

        protected final com.sun.enterprise.util.HostAndPort getAdminAddress()
                                                                     throws org.glassfish.api.admin.CommandException
        Returns the admin address of the local domain. Note that this method should be called only when you own the domain that is available on an accessible file system.
        Returns:
        HostAndPort object with admin server address
        Throws:
        org.glassfish.api.admin.CommandException - in case of parsing errors
      • getAdminAddress

        protected final com.sun.enterprise.util.HostAndPort getAdminAddress​(String serverName)
                                                                     throws org.glassfish.api.admin.CommandException
        Returns the admin address of a particular server. Note that this method should be called only when you own the server that is available on an accessible file system.
        Returns:
        HostAndPort object with admin server address
        Throws:
        org.glassfish.api.admin.CommandException - in case of parsing errors
      • setServerDirs

        protected final void setServerDirs​(com.sun.enterprise.util.io.ServerDirs sd)
      • isLocal

        protected final boolean isLocal()
      • isRemote

        protected final boolean isRemote()
      • setLocalPassword

        protected final void setLocalPassword()
      • unsetLocalPassword

        protected final void unsetLocalPassword()
      • getServerDirs

        protected final com.sun.enterprise.util.io.ServerDirs getServerDirs()
      • getDomainXml

        protected final File getDomainXml()
      • readFromMasterPasswordFile

        protected final String readFromMasterPasswordFile()
        Checks if the create-domain was created using --savemasterpassword flag which obtains security by obfuscation! Returns null in case of failure of any kind.
        Returns:
        String representing the password from the JCEKS store named master-password in domain folder
      • verifyMasterPassword

        protected final boolean verifyMasterPassword​(String mpv)
      • loadAndVerifyKeystore

        protected boolean loadAndVerifyKeystore​(File jks,
                                                String mpv)
      • getMasterPassword

        protected final String getMasterPassword()
                                          throws org.glassfish.api.admin.CommandException
        Get the master password, either from a password file or by asking the user.
        Throws:
        org.glassfish.api.admin.CommandException
      • isThisServer

        protected final boolean isThisServer​(File ourDir,
                                             String directoryKey)
        See if the server is alive and is the one at the specified directory.
        Returns:
        true if it's the DAS at this domain directory
      • getServerPid

        protected final int getServerPid()
      • isRunning

        protected final boolean isRunning​(String host,
                                          int port)
        There is sometimes a need for subclasses to know if a local domain is running. An example of such a command is change-master-password command. The stop-domain command also needs to know if a domain is running without having to provide user name and password on command line (this is the case when I own a domain that has non-default admin user and password) and want to stop it without providing it.

        In such cases, we need to know if the domain is running and this method provides a way to do that.

        Returns:
        boolean indicating whether the server is running
      • isRunning

        protected boolean isRunning()
        Is the server still running? This is only called when we're hanging around waiting for the server to die. Byron Nevins, Nov 7, 2010 - Check to see if the process itself is still running We use OS tools to figure this out. See ProcessUtils for details. Failover to the JPS check if necessary bnevins, May 2013 http://serverfault.com/questions/181015/how-do-you-free-up-a-port-being-held-open-by-dead-process In WIndows the admin port may be held open for a while -- if there happens to be an attached running child process. This is the key message from the url: If your program spawned any processes while it was running, try killing them. That should cause its process record to be freed and the TCP port to be cleaned up. Apparently windows does this when the record is released not when the process exits as I would have expected.
      • waitForRestart

        protected final void waitForRestart​(int oldServerPid)
                                     throws org.glassfish.api.admin.CommandException
        Byron Nevins Says: We have quite a historical assortment of ways to determine if a server has restarted. There are little teeny timing issues with all of them. I'm confident that this new technique will clear them all up. Here we are just monitoring the PID of the new server and comparing it to the pid of the old server. The oldServerPid is guaranteed to be either the PID of the "old" server or -1 if we couldn't get it -- or it isn't running. If it is -1 then we make the assumption that once we DO get a valid pid that the server has started. If the old pid is valid we simply poll until we get a different pid. Notice that we will never get a valid pid back unless the server is officially up and running and "STARTED" Created April 2013
        Parameters:
        oldServerPid - The pid of the server which is being restarted.
        Throws:
        org.glassfish.api.admin.CommandException - if we time out.
      • getPrevPid

        protected final int getPrevPid()
      • getUptime

        protected final long getUptime()
                                throws org.glassfish.api.admin.CommandException
        Get uptime from the server.
        Throws:
        org.glassfish.api.admin.CommandException
      • isRestartable

        protected final boolean isRestartable()
                                       throws org.glassfish.api.admin.CommandException
        See if the server is restartable As of March 2011 -- this only returns false if a passwordfile argument was given when the server started -- but it is no longer available - i.e. the user deleted it or made it unreadable.
        Throws:
        org.glassfish.api.admin.CommandException
      • getMasterPasswordFile

        protected File getMasterPasswordFile()