Package org.opends.server.tools.tasks
Class TaskToolHelper
java.lang.Object
org.opends.server.tools.tasks.TaskToolHelper
A helper class for adding online capabilities to an offline tool. It allows for a tool or subcommand to add
task-related arguments and to run a task according to the argument values.
The methods must be called in this order:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Magic value used to indicate that the user would like to schedule this operation to run immediately as a task as opposed to running the operation in the local VM.static final boolean
The value to pass tovalidateTaskRelatedArguments(boolean)
if the offline mode does not modify server files.static final boolean
The value to pass tovalidateTaskRelatedArguments(boolean)
if the offline mode modifies sever files.static final String
The value for the long option compress.static final String
The value for the tmp directory long option.static final Character
The value for the "backendId" short option.static final char
The value for the short option compress. -
Constructor Summary
ConstructorDescriptionTaskToolHelper
(com.forgerock.opendj.cli.Tool printer, com.forgerock.opendj.cli.ArgumentParser argumentParser) Creates a new TaskToolHelper with the provided tool for printing the messages.TaskToolHelper
(com.forgerock.opendj.cli.Tool printer, com.forgerock.opendj.cli.ArgumentParser argumentParser, com.forgerock.opendj.cli.SubCommand subCommand) Creates a new TaskToolHelper with the provided tool for printing the messages. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addAttribute
(Entry taskEntry, String attrName, com.forgerock.opendj.cli.Argument argument) Adds the provided attribute with the argument value(s) to the provided task entry only if the argument has been provided on the command line.static void
addAttributeIfArgumentPresent
(Entry taskEntry, String attrName, com.forgerock.opendj.cli.Argument argument) Adds the attribute with the argument value to the task entry if the argument corresponding to the attribute has been provided on the command line.addTaskRelatedArgumentsToParser
(boolean offlineModifiesServerFiles) Add all the task-related arguments to the constructor-supplied argument parser or sub command.addTaskRelatedArgumentsToParser
(com.forgerock.opendj.cli.BooleanArgument offlineArgument) Add all the task-related arguments to the constructor-supplied argument parser or sub command.boolean
Indicates whether the offline argument was provided.com.forgerock.opendj.cli.ReturnCode
process
(TaskCommand taskCommand) Process locally or run a task depending on whether the offline argument was provided.static void
shutdownBackends
(ServerContext serverContext) Shutdowns all backends.void
validateTaskRelatedArguments
(boolean isEmbedded) Validates the task-related arguments and throw an exception if the user-provided values are invalid.
-
Field Details
-
OPTION_LONG_COMPRESS
The value for the long option compress.- See Also:
-
OPTION_SHORT_COMPRESS
public static final char OPTION_SHORT_COMPRESSThe value for the short option compress.- See Also:
-
OPTION_SHORT_BACKEND_ID
The value for the "backendId" short option. -
OPTION_LONG_TMP_DIRECTORY
The value for the tmp directory long option.- See Also:
-
OFFLINE_DOES_NOT_MODIFY_SERVER_FILES
public static final boolean OFFLINE_DOES_NOT_MODIFY_SERVER_FILESThe value to pass tovalidateTaskRelatedArguments(boolean)
if the offline mode does not modify server files.- See Also:
-
OFFLINE_MODIFIES_SERVER_FILES
public static final boolean OFFLINE_MODIFIES_SERVER_FILESThe value to pass tovalidateTaskRelatedArguments(boolean)
if the offline mode modifies sever files.- See Also:
-
NOW
Magic value used to indicate that the user would like to schedule this operation to run immediately as a task as opposed to running the operation in the local VM.- See Also:
-
-
Constructor Details
-
TaskToolHelper
public TaskToolHelper(com.forgerock.opendj.cli.Tool printer, com.forgerock.opendj.cli.ArgumentParser argumentParser) Creates a new TaskToolHelper with the provided tool for printing the messages. Task options will be added at the global level to the provided argument parser.- Parameters:
printer
- The tool used for printing the messages.argumentParser
- The argument parser
-
TaskToolHelper
public TaskToolHelper(com.forgerock.opendj.cli.Tool printer, com.forgerock.opendj.cli.ArgumentParser argumentParser, com.forgerock.opendj.cli.SubCommand subCommand) Creates a new TaskToolHelper with the provided tool for printing the messages. Task options will be added to the provided sub-command.- Parameters:
printer
- The tool used for printing the messages.argumentParser
- The argument parsersubCommand
- The sub-command
-
-
Method Details
-
shutdownBackends
Shutdowns all backends.- Parameters:
serverContext
- the server context
-
addAttributeIfArgumentPresent
public static void addAttributeIfArgumentPresent(Entry taskEntry, String attrName, com.forgerock.opendj.cli.Argument argument) Adds the attribute with the argument value to the task entry if the argument corresponding to the attribute has been provided on the command line.- Parameters:
taskEntry
- The taskEntry
to updateattrName
- The attribute corresponding to the argumentargument
- The argument representing the attribute
-
addAttribute
public static void addAttribute(Entry taskEntry, String attrName, com.forgerock.opendj.cli.Argument argument) Adds the provided attribute with the argument value(s) to the provided task entry only if the argument has been provided on the command line. -
addTaskRelatedArgumentsToParser
Add all the task-related arguments to the constructor-supplied argument parser or sub command. This includes ldap client arguments to connect to a directory server, task arguments to customize the task execution and the offline argument to distinguish between the task mode and offline mode.- Parameters:
offlineModifiesServerFiles
- Indicates whether the offline mode will modify server files- Returns:
- this object to be able to chain method calls
- See Also:
-
addTaskRelatedArgumentsToParser
public TaskToolHelper addTaskRelatedArgumentsToParser(com.forgerock.opendj.cli.BooleanArgument offlineArgument) Add all the task-related arguments to the constructor-supplied argument parser or sub command. This includes ldap client arguments to connect to a directory server, task arguments to customize the task execution and the provided offline argument to distinguish between the task mode and offline mode.- Parameters:
offlineArgument
- the offline argument- Returns:
- this object to be able to chain method calls
- See Also:
-
validateTaskRelatedArguments
public void validateTaskRelatedArguments(boolean isEmbedded) throws com.forgerock.opendj.cli.ClientException Validates the task-related arguments and throw an exception if the user-provided values are invalid.- Parameters:
isEmbedded
- Whether the tool is embedded.- Throws:
com.forgerock.opendj.cli.ClientException
- If the user provided values for task-related argument are invalid.
-
isOffline
public boolean isOffline()Indicates whether the offline argument was provided.- Returns:
- whether the offline argument was provided.
-
process
public com.forgerock.opendj.cli.ReturnCode process(TaskCommand taskCommand) throws com.forgerock.opendj.cli.ClientException Process locally or run a task depending on whether the offline argument was provided. The task will be run according to the user provided task-related arguments.- Parameters:
taskCommand
- the command that should be executed.- Returns:
- the return code.
- Throws:
com.forgerock.opendj.cli.ClientException
- If there is a problem when running the task.
-