Class LocalServerCommand

java.lang.Object
com.sun.enterprise.admin.cli.CLICommand
com.sun.enterprise.admin.servermgmt.cli.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
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    Override this method and return false to turn-off the file validation.
    protected final com.sun.enterprise.util.HostAndPort
    Returns the admin address.
    protected final com.sun.enterprise.util.HostAndPort
    getAdminAddress(String serverName)
    Returns the admin address of a particular server parsed from the domain.xml.
    protected final File
     
    protected final String
    Get the master password, either from a password file or by asking the user.
    protected File
     
    protected final com.sun.enterprise.util.io.ServerDirs
     
    protected final int
    Asks remote server for the PID
    protected final long
     
    protected final boolean
     
    protected final boolean
    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.
    protected final boolean
    isThisServer(File ourDir, String directoryKey)
    See if the server is alive and is the one at the specified directory.
    protected boolean
     
    protected final String
    Checks if the create-domain was created using --savemasterpassword flag which obtains security by obfuscation!
    protected final void
     
    protected final void
    Sets the local password loaded from serverDirs.
    protected final void
    setServerDirs(com.sun.enterprise.util.io.ServerDirs sd)
     
    protected final void
     
    protected final boolean
     
    protected final void
    waitForRestart(int oldPid, com.sun.enterprise.util.HostAndPort oldAdminAddress, com.sun.enterprise.util.HostAndPort newAdminAddress)
    Waits until server stops and starts

    Methods inherited from class com.sun.enterprise.admin.cli.CLICommand

    checkHelp, checkSanity, 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, processProgramOptions, quote, readPassword, setCommandScope, toString, usageOptions, validate

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • LocalServerCommand

      public LocalServerCommand()
  • Method Details

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

      The address atributes can be overriden from the command line by specifying --host, --port and --secure arguments. If some is missing, it is loaded from domain.xml or set to default.

      For remote access it uses just command line arguments and defaults.

      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 parsed from the domain.xml. For remote access it uses command line arguments and defaults.
      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()
      Returns:
      true if something called setServerDirs(ServerDirs) to a non-null value and serverName is not null.
    • setLocalPassword

      protected final void setLocalPassword()
      Sets the local password loaded from serverDirs.
    • unsetLocalPassword

      protected final void unsetLocalPassword()
    • resetServerDirs

      protected final void resetServerDirs() throws IOException
      Throws:
      IOException
    • 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()
      Asks remote server for the PID
      Returns:
      PID or -1 if unreachable
    • waitForRestart

      protected final void waitForRestart(int oldPid, com.sun.enterprise.util.HostAndPort oldAdminAddress, com.sun.enterprise.util.HostAndPort newAdminAddress) throws org.glassfish.api.admin.CommandException
      Waits until server stops and starts
      Parameters:
      oldPid -
      oldAdminAddress -
      newAdminAddress - new admin endpoint - usually same as old, but it could change with restart.
      Throws:
      org.glassfish.api.admin.CommandException - if we time out.
    • getUptime

      protected final long getUptime() throws org.glassfish.api.admin.CommandException
      Returns:
      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()