Class LocalServerCommand

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

    public abstract class LocalServerCommand
    extends 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
    • 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 HostAndPort getAdminAddress()
                                             throws 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:
        CommandException - in case of parsing errors
      • getAdminAddress

        protected final HostAndPort getAdminAddress​(String serverName)
                                             throws 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.
        Parameters:
        serverName - the server name
        Returns:
        HostAndPort object with admin server address
        Throws:
        CommandException - in case of parsing errors
      • setServerDirs

        protected final void setServerDirs​(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 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 CommandException
        Get the master password, either from a password file or by asking the user.
        Returns:
        the actual master password
        Throws:
        CommandException
      • isThisServer

        protected final boolean isThisServer​(File ourDir,
                                             String directoryKey)
        See if the server is alive and is the one at the specified directory.
        Parameters:
        ourDir - the directory to check if the server is alive agains
        directoryKey - the key for the 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.

        Parameters:
        host - the host to check
        port - the port to check agains
        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.

        Returns:
      • waitForRestart

        protected final void waitForRestart​(int oldServerPid,
                                            long timeout)
                                     throws 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:
        CommandException - if we time out.
      • getPrevPid

        protected final int getPrevPid()
      • getUptime

        protected final long getUptime()
                                throws CommandException
        Get uptime from the server.
        Returns:
        uptime in milliseconds
        Throws:
        CommandException - if the server is not running
      • isRestartable

        protected final boolean isRestartable()
                                       throws 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.
        Returns:
        true if the server is restartable
        Throws:
        CommandException
      • getMasterPasswordFile

        protected File getMasterPasswordFile()
      • getInstallRootPath

        protected String getInstallRootPath()
                                     throws CommandException
        Gets the GlassFish installation root (using property com.sun.aas.installRoot), first from asenv.conf. If that's not available, then from java.lang.System.
        Returns:
        path of GlassFish install root
        Throws:
        CommandException - if the GlassFish install root is not found