public class RemoteAdminCommand extends Object
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.
Modifier and Type | Field and Description |
---|---|
protected String |
authToken |
static String |
COMMAND_MODEL_MATCH_HEADER |
protected String |
host |
protected Logger |
logger |
protected String |
name |
protected List<String> |
operands |
protected ParameterMap |
options |
protected String |
output |
protected char[] |
password |
protected int |
port |
protected boolean |
prohibitDirectoryUploads |
protected String |
scope |
protected boolean |
secure |
protected String |
user |
Constructor and Description |
---|
RemoteAdminCommand(String name,
String host,
int port) |
RemoteAdminCommand(String name,
String host,
int port,
boolean secure,
String user,
char[] password,
Logger logger) |
RemoteAdminCommand(String name,
String host,
int port,
boolean secure,
String user,
char[] password,
Logger logger,
String scope,
String authToken,
boolean prohibitDirectoryUploads)
Construct a new remote command object.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addAdditionalHeaders(URLConnection urlConnection)
Adds any headers needed for the current environment to the admin
request.
|
protected AuthenticationInfo |
authenticationInfo() |
String |
executeCommand(ParameterMap opts)
Run the command using the specified arguments.
|
protected void |
fetchCommandModel()
Fetch the command metadata from the remote server.
|
Map<String,String> |
getAttributes()
After a successful command execution, the attributes returned
by the command are saved.
|
protected String |
getCanonicalHost() |
CommandModel |
getCommandModel()
Get the CommandModel for the command from the server.
|
protected StringBuilder |
getCommandURI()
Get the URI for executing the command.
|
protected String |
getFromEnvironment(String name)
Subclasses can override to supply parameter values from environment.
|
protected HttpConnectorAddress |
getHttpConnectorAddress(String host,
int port,
boolean shouldUseSecure)
Provides an HttpConnectorAddress for use in connecting to the desired
admin listener.
|
static int |
getReadTimeout() |
String |
getUsage()
Get the usage text.
|
List<Header> |
headers()
Return a modifiable list of headers to be added to the request.
|
boolean |
isCommandModelFromCache()
If command model was load from local cache.
|
protected void |
processHeaders(URLConnection urlConnection)
Process any headers needed from the reply to the admin
request.
|
protected String |
reportAuthenticationException()
Return the error message to be used in the AuthenticationException.
|
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.
|
void |
setCommandModel(CommandModel commandModel)
Set the CommandModel used by this command.
|
void |
setConnectTimeout(int connectTimeout)
Set the connect timeout for the URLConnection.
|
void |
setFileOutputDirectory(File dir)
Set the directory in which any returned files will be stored.
|
void |
setInteractive(boolean state)
Set the interactive mode for the command.
|
void |
setOmitCache(boolean omitCache)
Omit local
AdminCache to process command metadata. |
void |
setReadTimeout(int readTimeout)
Set the read timeout for the URLConnection.
|
void |
setResponseFormatType(String responseFormatType)
Set the response type used in requests to the server.
|
void |
setUserOut(OutputStream userOut)
If set, the raw response from the command is written to the
specified stream.
|
protected boolean |
updateAuthentication()
Return true if we're successful in collecting new information
(and thus the caller should try the request again).
|
public static final String COMMAND_MODEL_MATCH_HEADER
protected String output
protected String name
protected String host
protected int port
protected boolean secure
protected String user
protected char[] password
protected Logger logger
protected String scope
protected String authToken
protected boolean prohibitDirectoryUploads
protected ParameterMap options
public RemoteAdminCommand(String name, String host, int port) throws CommandException
CommandException
public RemoteAdminCommand(String name, String host, int port, boolean secure, String user, char[] password, Logger logger) throws CommandException
CommandException
public RemoteAdminCommand(String name, String host, int port, boolean secure, String user, char[] password, Logger logger, String scope, String authToken, boolean prohibitDirectoryUploads) throws CommandException
CommandException
public void setResponseFormatType(String responseFormatType)
responseFormatType
- the user-agent to send. The default is hk2-agent
public void setUserOut(OutputStream userOut)
userOut
- the OutputStream
to write topublic void setCommandModel(CommandModel commandModel)
public void setReadTimeout(int readTimeout)
readTimeout
- the timeout in millisedondspublic static int getReadTimeout()
public void setConnectTimeout(int connectTimeout)
connectTimeout
- the timeout in millisecondspublic void setInteractive(boolean state)
state
- whether the command is interactivepublic void setOmitCache(boolean omitCache)
AdminCache
to process command metadata.omitCache
- If true
it will download the metadata from remote server.false
public CommandModel getCommandModel() throws CommandException
CommandException
- if the server can't be contactedpublic boolean isCommandModelFromCache()
public void setFileOutputDirectory(File dir)
dir
- public List<Header> headers()
public String executeCommand(ParameterMap opts) throws CommandException
opts
- CommandException
public Map<String,String> getAttributes()
protected boolean updateAuthentication()
protected String getFromEnvironment(String name)
protected boolean retryUsingSecureConnection(String host, int port)
host
- Host to say we are retrying onport
- Port to say we are retrying onprotected String reportAuthenticationException()
protected StringBuilder getCommandURI()
/__asadmin/name?
protected HttpConnectorAddress getHttpConnectorAddress(String host, int port, boolean shouldUseSecure)
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.
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 notprotected void addAdditionalHeaders(URLConnection urlConnection)
urlConnection
- protected void processHeaders(URLConnection urlConnection)
urlConnection
- protected AuthenticationInfo authenticationInfo()
public String getUsage()
protected void fetchCommandModel() throws CommandException
CommandException
protected String getCanonicalHost()
Copyright © 2021. All rights reserved.