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
,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
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
DEFAULT_MASTER_PASSWORD
-
Fields inherited from class com.sun.enterprise.admin.cli.CLICommand
argv, ASADMIN, commandModel, CONNECTION_ERROR, env, ERROR, INVALID_COMMAND_ERROR, lineReader, logger, metadataErrors, name, operands, options, passwords, programOpts, SUCCESS, terminal, WARNING
-
-
Constructor Summary
Constructors Constructor Description LocalServerCommand()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkAdditionalTrustAndKeyStores()
protected boolean
checkForSpecialFiles()
Override this method and return false to turn-off the file validation.protected boolean
dataGridEncryptionEnabled()
protected HostAndPort
getAdminAddress()
Returns the admin address of the local domain.protected HostAndPort
getAdminAddress(String serverName)
Returns the admin address of a particular server.protected File
getDomainXml()
protected String
getInstallRootPath()
Gets the GlassFish installation root (using property com.sun.aas.installRoot), first from asenv.conf.protected String
getMasterPassword()
Get the master password, either from a password file or by asking the user.protected File
getMasterPasswordFile()
protected int
getPrevPid()
protected 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.the user deleted it or made it unreadable.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 alocal 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.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(ServerDirs sd)
protected void
unsetLocalPassword()
protected boolean
verifyMasterPassword(String mpv)
protected void
waitForRestart(int oldServerPid)
protected void
waitForRestart(int oldServerPid, long timeout)
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
buildLineReader, buildTerminal, checkHelp, closeTerminal, execute, execute, executeCommand, expandManPage, getBooleanOption, getBriefCommandUsage, getCommand, getCommand, getCommandScope, getCommandUsage, getManPage, getName, getOperandModel, getOption, getOptions, getPassword, getPassword, getProgramOptions, getSystemProperties, getSystemProperty, getUsage, initializeLogger, initializePasswords, inject, newLineReaderBuilder, ok, parse, postConstruct, prepare, prevalidate, printExceptionStackTrace, processProgramOptions, quote, readPassword, setCommandScope, toString, usageOptions, validate
-
-
-
-
Field Detail
-
DEFAULT_MASTER_PASSWORD
protected static final String DEFAULT_MASTER_PASSWORD
- See Also:
- Constant Field Values
-
-
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()
-
resetServerDirs
protected final void resetServerDirs() throws IOException
- Throws:
IOException
-
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)
-
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 againsdirectoryKey
- 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 alocal 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 checkport
- 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 necessarybnevins, 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) throws CommandException
- Throws:
CommandException
-
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()
-
dataGridEncryptionEnabled
protected boolean dataGridEncryptionEnabled() throws IOException, XMLStreamException
- Throws:
IOException
XMLStreamException
-
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
-
checkAdditionalTrustAndKeyStores
protected void checkAdditionalTrustAndKeyStores() throws IOException, XMLStreamException
- Throws:
IOException
XMLStreamException
-
-