Class RemoteRestAdminCommand
- java.lang.Object
-
- com.sun.enterprise.admin.event.AdminCommandEventBrokerImpl<GfSseInboundEvent>
-
- com.sun.enterprise.admin.remote.RemoteRestAdminCommand
-
- All Implemented Interfaces:
org.glassfish.api.admin.AdminCommandEventBroker<GfSseInboundEvent>
- Direct Known Subclasses:
ServerRemoteRestAdminCommand
public class RemoteRestAdminCommand extends AdminCommandEventBrokerImpl<GfSseInboundEvent>
Utility class for executing remote admin commands. Each instance of RemoteAdminCommand represents a particular remote command on a particular remote server accessed using particular credentials. The instance can be reused to execute the same command multiple times with different arguments.Arguments to the command are supplied using a ParameterMap passed to the executeCommand method. ParameterMap is a MultiMap where each key can have multiple values, although this class only supports a single value for each option. Operands for the command are stored as the option named "DEFAULT" and can have multiple values.
Before a command can be executed, the metadata for the command (in the form of a CommandModel) is required. The getCommandModel method will fetch the metadata from the server, save it, and return it. If the CommandModel for a command is known independently (e.g., stored in a local cache, or known a priori), it can be set using the setCommandModel method. If the metadata isn't known when the exectureCommand method is called, it will fetch the metadata from the server before executing the command.
Any files returned by the command will be stored in the current directory. The setFileOutputDirectory method can be used to control where returned files are saved.
This implementation is now in retention period. All content was migrated to RemoteRestAdminCommand. This implementation will be removed just after all necessary changes and tests will be done.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.glassfish.api.admin.AdminCommandEventBroker
org.glassfish.api.admin.AdminCommandEventBroker.AdminCommandListener<T extends Object>, org.glassfish.api.admin.AdminCommandEventBroker.BrokerListenerRegEvent, org.glassfish.api.admin.AdminCommandEventBroker.EventBrokerUtils
-
-
Field Summary
Fields Modifier and Type Field Description protected StringauthTokenstatic StringCOMMAND_MODEL_MATCH_HEADERprotected Stringhostprotected Loggerloggerprotected Stringnameprotected booleannotifyprotected List<String>operandsprotected org.glassfish.api.admin.ParameterMapoptionsprotected Stringoutputprotected char[]passwordprotected intportprotected booleanprohibitDirectoryUploadsprotected Stringscopeprotected booleansecureprotected Stringuser
-
Constructor Summary
Constructors Constructor Description RemoteRestAdminCommand(String name, String host, int port)RemoteRestAdminCommand(String name, String host, int port, boolean secure, String user, char[] password, Logger logger, boolean notify)RemoteRestAdminCommand(String name, String host, int port, boolean secure, String user, char[] password, Logger logger, String scope, String authToken, boolean prohibitDirectoryUploads, boolean notify)Construct a new remote command object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddAdditionalHeaders(URLConnection urlConnection)Adds any headers needed for the current environment to the admin request.protected AuthenticationInfoauthenticationInfo()voidcloseSse(String message, org.glassfish.api.ActionReport.ExitCode exitCode)StringexecuteCommand(org.glassfish.api.admin.ParameterMap opts)Run the command using the specified arguments.protected voidfetchCommandModel()Fetch the command metadata from the remote server.StringfindPropertyInReport(String key)org.glassfish.api.ActionReportgetActionReport()Map<String,String>getAttributes()After a successful command execution, the attributes returned by the command are saved.protected StringgetCanonicalHost()org.glassfish.api.admin.CommandModelgetCommandModel()Get the CommandModel for the command from the server.protected StringgetCommandURI()Get the URI for executing the command.protected StringgetFromEnvironment(String name)Subclasses can override to supply parameter values from environment.protected HttpConnectorAddressgetHttpConnectorAddress(String host, int port, boolean shouldUseSecure)Provides an HttpConnectorAddress for use in connecting to the desired admin listener.StringgetManPage()static intgetReadTimeout()StringgetUsage()Get the usage text.List<Header>headers()Return a modifiable list of headers to be added to the request.booleanisCommandModelFromCache()If command model was load from local cache.static voidpreinit()Can be called to start async preinitialisation.protected voidprocessHeaders(URLConnection urlConnection)Process any headers needed from the reply to the admin request.protected booleanrefetchInvalidModel()If admin model is invalid, will be automatically refetched?protected StringreportAuthenticationException()Return the error message to be used in the AuthenticationException.protected booleanretryUsingSecureConnection(String host, int port)Called when a non-secure connection attempt fails and it appears that the server requires a secure connection.protected voidsetActionReport(org.glassfish.api.ActionReport ar)voidsetCommandModel(org.glassfish.api.admin.CommandModel commandModel)Set the CommandModel used by this command.voidsetConnectTimeout(int connectTimeout)Set the connect timeout for the URLConnection.voidsetEnableCommandModelCache(boolean enableCommandModelCache)voidsetFileOutputDirectory(File dir)Set the directory in which any returned files will be stored.voidsetInteractive(boolean state)Set the interactive mode for the command.voidsetReadTimeout(int readTimeout)Set the read timeout for the URLConnection.voidsetResponseFormatType(String responseFormatType)Set the response type used in requests to the server.voidsetUserOut(OutputStream userOut)If set, the raw response from the command is written to the specified stream.protected booleanupdateAuthentication()Return true if we're successful in collecting new information (and thus the caller should try the request again).protected booleanuseSse()-
Methods inherited from class com.sun.enterprise.admin.event.AdminCommandEventBrokerImpl
fireEvent, fireEvent, getUtils, listening, registerListener, unregisterListener
-
-
-
-
Field Detail
-
COMMAND_MODEL_MATCH_HEADER
public static final String COMMAND_MODEL_MATCH_HEADER
- See Also:
- Constant Field Values
-
output
protected String output
-
name
protected String name
-
host
protected String host
-
port
protected int port
-
secure
protected boolean secure
-
notify
protected boolean notify
-
user
protected String user
-
password
protected char[] password
-
logger
protected Logger logger
-
scope
protected String scope
-
authToken
protected String authToken
-
prohibitDirectoryUploads
protected boolean prohibitDirectoryUploads
-
options
protected org.glassfish.api.admin.ParameterMap options
-
-
Constructor Detail
-
RemoteRestAdminCommand
public RemoteRestAdminCommand(String name, String host, int port) throws org.glassfish.api.admin.CommandException
- Throws:
org.glassfish.api.admin.CommandException
-
RemoteRestAdminCommand
public RemoteRestAdminCommand(String name, String host, int port, boolean secure, String user, char[] password, Logger logger, boolean notify) throws org.glassfish.api.admin.CommandException
- Throws:
org.glassfish.api.admin.CommandException
-
RemoteRestAdminCommand
public RemoteRestAdminCommand(String name, String host, int port, boolean secure, String user, char[] password, Logger logger, String scope, String authToken, boolean prohibitDirectoryUploads, boolean notify) throws org.glassfish.api.admin.CommandException
Construct a new remote command object. The command and arguments are supplied later using the execute method in the superclass.- Throws:
org.glassfish.api.admin.CommandException
-
-
Method Detail
-
closeSse
public void closeSse(String message, org.glassfish.api.ActionReport.ExitCode exitCode)
-
setResponseFormatType
public void setResponseFormatType(String responseFormatType)
Set the response type used in requests to the server. The response type is sent in the User-Agent HTTP header and tells the server what format of response to produce.
-
setUserOut
public void setUserOut(OutputStream userOut)
If set, the raw response from the command is written to the specified stream.
-
setCommandModel
public void setCommandModel(org.glassfish.api.admin.CommandModel commandModel)
Set the CommandModel used by this command. Normally the CommandModel will be fetched from the server using the getCommandModel method, which will also save the CommandModel for further use. If the CommandModel is known in advance, it can be set with this method and avoid the call to the server.
-
setReadTimeout
public void setReadTimeout(int readTimeout)
Set the read timeout for the URLConnection.
-
getReadTimeout
public static int getReadTimeout()
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout)
Set the connect timeout for the URLConnection.
-
setInteractive
public void setInteractive(boolean state)
Set the interactive mode for the command. By default, the command is interactive.
-
setEnableCommandModelCache
public void setEnableCommandModelCache(boolean enableCommandModelCache)
-
getCommandModel
public org.glassfish.api.admin.CommandModel getCommandModel() throws org.glassfish.api.admin.CommandExceptionGet the CommandModel for the command from the server. If the CommandModel hasn't been set, it's fetched from the server.- Returns:
- the model for the command
- Throws:
org.glassfish.api.admin.CommandException- if the server can't be contacted
-
isCommandModelFromCache
public boolean isCommandModelFromCache()
If command model was load from local cache.
-
setFileOutputDirectory
public void setFileOutputDirectory(File dir)
Set the directory in which any returned files will be stored. The default is the user's home directory.
-
headers
public List<Header> headers()
Return a modifiable list of headers to be added to the request.
-
useSse
protected boolean useSse() throws org.glassfish.api.admin.CommandException- Throws:
org.glassfish.api.admin.CommandException
-
executeCommand
public String executeCommand(org.glassfish.api.admin.ParameterMap opts) throws org.glassfish.api.admin.CommandException
Run the command using the specified arguments. Return the output of the command.- Throws:
org.glassfish.api.admin.CommandException
-
refetchInvalidModel
protected boolean refetchInvalidModel()
If admin model is invalid, will be automatically refetched?
-
getAttributes
public Map<String,String> getAttributes()
After a successful command execution, the attributes returned by the command are saved. This method returns those saved attributes.
-
updateAuthentication
protected boolean updateAuthentication()
Return true if we're successful in collecting new information (and thus the caller should try the request again). Subclasses can override to (e.g.) collect updated authentication information by prompting the user. The implementation in this class returns false, indicating that the authentication information was not updated.
-
getFromEnvironment
protected String getFromEnvironment(String name)
Subclasses can override to supply parameter values from environment. The implementation in this class returns null, indicating that the name is not available in the environment.
-
retryUsingSecureConnection
protected boolean retryUsingSecureConnection(String host, int port)
Called when a non-secure connection attempt fails and it appears that the server requires a secure connection. Subclasses can override to indicate that the connection should The implementation in this class returns false, indicating that the connection should not be retried.
-
reportAuthenticationException
protected String reportAuthenticationException()
Return the error message to be used in the AuthenticationException. Subclasses can override to provide a more detailed message, for example, indicating the source of the password that failed. The implementation in this class returns a default error message.
-
getCommandURI
protected String getCommandURI()
Get the URI for executing the command.
-
setActionReport
protected void setActionReport(org.glassfish.api.ActionReport ar)
-
getActionReport
public org.glassfish.api.ActionReport getActionReport()
-
getHttpConnectorAddress
protected HttpConnectorAddress getHttpConnectorAddress(String host, int port, boolean shouldUseSecure)
Provides an HttpConnectorAddress for use in connecting to the desired admin listener.This implementation works for true admin clients and will not work correctly for commands submitted to instances from inside the DAS. (That is done from the implementation in ServerRemoteAdminCommand which extends this class.)
This code constructs the HttpConnectorAddress in a way that uses either no SSLSocketFactory (if security is off) or uses an SSLSocketFactory linked to the asadmin truststore.
- Parameters:
host- the host name to which the connection should be madeport- the admin port on that hostshouldUseSecure- whether SSL should be used to connect or not- Returns:
-
addAdditionalHeaders
protected void addAdditionalHeaders(URLConnection urlConnection)
Adds any headers needed for the current environment to the admin request.- Parameters:
urlConnection-
-
processHeaders
protected void processHeaders(URLConnection urlConnection)
Process any headers needed from the reply to the admin request. Subclasses can override this method to handle processing headers in the command's reply.- Parameters:
urlConnection-
-
authenticationInfo
protected AuthenticationInfo authenticationInfo()
-
getUsage
public String getUsage()
Get the usage text. If we got usage information from the server, use it.- Returns:
- usage text
-
fetchCommandModel
protected void fetchCommandModel() throws org.glassfish.api.admin.CommandExceptionFetch the command metadata from the remote server.- Throws:
org.glassfish.api.admin.CommandException
-
getManPage
public String getManPage() throws org.glassfish.api.admin.CommandException
- Throws:
org.glassfish.api.admin.CommandException
-
getCanonicalHost
protected String getCanonicalHost()
-
preinit
public static void preinit()
Can be called to start async preinitialisation. It can help a little bit in usage performance.
-
-