Package org.opends.server.tools.tasks
Class TaskToolHelper
- java.lang.Object
-
- org.opends.server.tools.tasks.TaskToolHelper
-
public final class TaskToolHelper extends Object
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
Fields Modifier and Type Field Description static String
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.static boolean
OFFLINE_DOES_NOT_MODIFY_SERVER_FILES
The value to pass tovalidateTaskRelatedArguments(ArgumentParser, boolean)
if the offline mode does not modify server files.static boolean
OFFLINE_MODIFIES_SERVER_FILES
The value to pass tovalidateTaskRelatedArguments(ArgumentParser, boolean)
if the offline mode modifies sever files.static String
OPTION_LONG_COMPRESS
The value for the long option compress.static String
OPTION_LONG_TMP_DIRECTORY
The value for the tmp directory long option.static Character
OPTION_SHORT_BACKEND_ID
The value for the "backendId" short option.static char
OPTION_SHORT_COMPRESS
The value for the short option compress.
-
Constructor Summary
Constructors Constructor Description TaskToolHelper(com.forgerock.opendj.cli.Tool printer)
Creates a new TaskToolHelper with the provided tool for printing the messages.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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.void
addTaskRelatedArgumentsToParser(com.forgerock.opendj.cli.ArgumentParser argParser, boolean offlineModifiesServerFiles)
Add all the task-related arguments to the provided argument parser.void
addTaskRelatedArgumentsToParser(com.forgerock.opendj.cli.ArgumentParser argParser, com.forgerock.opendj.cli.BooleanArgument offlineArgument)
Add all the task-related arguments to the provided argument parser.boolean
isOffline()
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()
Shutdowns all backends.void
throwIfContainsTaskRelatedArguments(com.forgerock.opendj.cli.ArgumentParser argParser, String subcommandName)
Throws wrong usage exception if at least one connection or task argument was provided.void
validateTaskRelatedArguments(com.forgerock.opendj.cli.ArgumentParser argParser, boolean isEmbedded)
Validates the task-related arguments and throw an exception if the user-provided values are invalid.
-
-
-
Field Detail
-
OPTION_LONG_COMPRESS
public static final String OPTION_LONG_COMPRESS
The value for the long option compress.- See Also:
- Constant Field Values
-
OPTION_SHORT_COMPRESS
public static final char OPTION_SHORT_COMPRESS
The value for the short option compress.- See Also:
- Constant Field Values
-
OPTION_SHORT_BACKEND_ID
public static final Character OPTION_SHORT_BACKEND_ID
The value for the "backendId" short option.
-
OPTION_LONG_TMP_DIRECTORY
public static final String OPTION_LONG_TMP_DIRECTORY
The value for the tmp directory long option.- See Also:
- Constant Field Values
-
OFFLINE_DOES_NOT_MODIFY_SERVER_FILES
public static final boolean OFFLINE_DOES_NOT_MODIFY_SERVER_FILES
The value to pass tovalidateTaskRelatedArguments(ArgumentParser, boolean)
if the offline mode does not modify server files.- See Also:
- Constant Field Values
-
OFFLINE_MODIFIES_SERVER_FILES
public static final boolean OFFLINE_MODIFIES_SERVER_FILES
The value to pass tovalidateTaskRelatedArguments(ArgumentParser, boolean)
if the offline mode modifies sever files.- See Also:
- Constant Field Values
-
NOW
public static final String 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:
- Constant Field Values
-
-
Method Detail
-
shutdownBackends
public static void shutdownBackends()
Shutdowns all backends.
-
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
public void addTaskRelatedArgumentsToParser(com.forgerock.opendj.cli.ArgumentParser argParser, boolean offlineModifiesServerFiles)
Add all the task-related arguments to the provided argument parser. 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:
argParser
- The argument parser.offlineModifiesServerFiles
- Indicates whether the offline mode will modify server files.- See Also:
OFFLINE_DOES_NOT_MODIFY_SERVER_FILES
,OFFLINE_MODIFIES_SERVER_FILES
-
addTaskRelatedArgumentsToParser
public void addTaskRelatedArgumentsToParser(com.forgerock.opendj.cli.ArgumentParser argParser, com.forgerock.opendj.cli.BooleanArgument offlineArgument)
Add all the task-related arguments to the provided argument parser. 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:
argParser
- The argument parser.offlineArgument
- The offline argument.- See Also:
OFFLINE_DOES_NOT_MODIFY_SERVER_FILES
,OFFLINE_MODIFIES_SERVER_FILES
-
validateTaskRelatedArguments
public void validateTaskRelatedArguments(com.forgerock.opendj.cli.ArgumentParser argParser, 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:
argParser
- The argument parser.isEmbedded
- Whether the tool is embedded.- Throws:
com.forgerock.opendj.cli.ClientException
- If the user provided values for task-related argument are invalid.
-
throwIfContainsTaskRelatedArguments
public void throwIfContainsTaskRelatedArguments(com.forgerock.opendj.cli.ArgumentParser argParser, String subcommandName) throws com.forgerock.opendj.cli.WrongUsageException
Throws wrong usage exception if at least one connection or task argument was provided.- Parameters:
argParser
- The argument parser.subcommandName
- The name of the sub-command that cannot run online.- Throws:
com.forgerock.opendj.cli.WrongUsageException
- if at least on connection or task argument was provided.
-
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.
-
-