Class ExecTask
- java.lang.Object
-
- com.unboundid.ldap.sdk.unboundidds.tasks.Task
-
- com.unboundid.ldap.sdk.unboundidds.tasks.ExecTask
-
- All Implemented Interfaces:
java.io.Serializable
@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class ExecTask extends Task
This class defines a Directory Server task that can be used to cause the server to execute a specified command with a given set of arguments.
NOTE: This class, and other classes within the
com.unboundid.ldap.sdk.unboundidds
package structure, are only supported for use against Ping Identity, UnboundID, and Nokia/Alcatel-Lucent 8661 server products. These classes provide support for proprietary functionality or for external specifications that are not considered stable or mature enough to be guaranteed to work in an interoperable way with other types of LDAP servers.
The server imposes limitation on the commands that can be executed and on the circumstances in which they can be invoked. See the exec-command-whitelist.txt file in the server's config directory for a summary of these restrictions, and for additional information about exec tasks.
The properties that are available for use with this type of task include:- The absolute path to the command to execute. This must be provided.
- An optional string with arguments to provide to the command.
- An optional path to a file to which the command's output should be written.
- An optional boolean flag that indicates whether to log the command's output to the server error log.
- An optional string that specifies the task state that should be used if the command completes with a nonzero exit code.
- An optional string that specifies the path to the working directory to use when executing the command.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ExecTask()
Creates a new, uninitialized exec task instance that should only be used for obtaining general information about this task, including the task name, description, and supported properties.ExecTask(Entry entry)
Creates a new exec task from the provided entry.ExecTask(java.lang.String commandPath, java.lang.String commandArguments, java.lang.String commandOutputFile, java.lang.Boolean logCommandOutput, TaskState taskStateForNonZeroExitCode)
Creates a new exec task with the provided information.ExecTask(java.lang.String commandPath, java.lang.String commandArguments, java.lang.String commandOutputFile, java.lang.Boolean logCommandOutput, TaskState taskStateForNonZeroExitCode, java.lang.String workingDirectory)
Creates a new exec task with the provided information.ExecTask(java.lang.String taskID, java.lang.String commandPath, java.lang.String commandArguments, java.lang.String commandOutputFile, java.lang.Boolean logCommandOutput, TaskState taskStateForNonZeroExitCode, java.lang.String workingDirectory, java.util.Date scheduledStartTime, java.util.List<java.lang.String> dependencyIDs, FailedDependencyAction failedDependencyAction, java.util.List<java.lang.String> notifyOnStart, java.util.List<java.lang.String> notifyOnCompletion, java.util.List<java.lang.String> notifyOnSuccess, java.util.List<java.lang.String> notifyOnError, java.lang.Boolean alertOnStart, java.lang.Boolean alertOnSuccess, java.lang.Boolean alertOnError)
Creates a new exec task with the provided information.ExecTask(java.lang.String taskID, java.lang.String commandPath, java.lang.String commandArguments, java.lang.String commandOutputFile, java.lang.Boolean logCommandOutput, TaskState taskStateForNonZeroExitCode, java.util.Date scheduledStartTime, java.util.List<java.lang.String> dependencyIDs, FailedDependencyAction failedDependencyAction, java.util.List<java.lang.String> notifyOnCompletion, java.util.List<java.lang.String> notifyOnError)
Creates a new exec task with the provided information.ExecTask(java.lang.String taskID, java.lang.String commandPath, java.lang.String commandArguments, java.lang.String commandOutputFile, java.lang.Boolean logCommandOutput, TaskState taskStateForNonZeroExitCode, java.util.Date scheduledStartTime, java.util.List<java.lang.String> dependencyIDs, FailedDependencyAction failedDependencyAction, java.util.List<java.lang.String> notifyOnStart, java.util.List<java.lang.String> notifyOnCompletion, java.util.List<java.lang.String> notifyOnSuccess, java.util.List<java.lang.String> notifyOnError, java.lang.Boolean alertOnStart, java.lang.Boolean alertOnSuccess, java.lang.Boolean alertOnError)
Creates a new exec task with the provided information.ExecTask(java.util.Map<TaskProperty,java.util.List<java.lang.Object>> properties)
Creates a new exec task from the provided set of task properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.List<Attribute>
getAdditionalAttributes()
Retrieves a list of the additional attributes (other than attributes common to all task types) that should be included when creating new task entries of this type.protected java.util.List<java.lang.String>
getAdditionalObjectClasses()
Retrieves a list of the additional object classes (other than the base "top" and "ds-task" classes) that should be included when creating new task entries of this type.java.lang.String
getCommandArguments()
Retrieves a string with the values of the arguments that should be provided when running the command.java.lang.String
getCommandOutputFile()
Retrieves the path to a file to which the command's output should be written.java.lang.String
getCommandPath()
Retrieves the path to the command to be executed.java.lang.String
getTaskDescription()
Retrieves a human-readable description for this task.java.lang.String
getTaskName()
Retrieves a human-readable name for this task.java.util.Map<TaskProperty,java.util.List<java.lang.Object>>
getTaskPropertyValues()
Retrieves the values of the task properties for this task.java.util.List<TaskProperty>
getTaskSpecificProperties()
Retrieves a list of task-specific properties that may be provided when scheduling a task of this type.java.lang.String
getTaskStateForNonZeroExitCode()
Retrieves a string representation of the task state that should be returned if the command completes with a nonzero exit code.java.lang.String
getWorkingDirectory()
Retrieves the path to the working directory to use when executing the command.java.lang.Boolean
logCommandOutput()
Indicates whether the command's output should be recorded in the server's error log.-
Methods inherited from class com.unboundid.ldap.sdk.unboundidds.tasks.Task
createTaskEntry, decodeTask, getActualStartTime, getAlertOnError, getAlertOnStart, getAlertOnSuccess, getAvailableTaskTypes, getCommonTaskProperties, getCompletionTime, getDependencyIDs, getFailedDependencyAction, getLogMessages, getNotifyOnCompletionAddresses, getNotifyOnErrorAddresses, getNotifyOnStartAddresses, getNotifyOnSuccessAddresses, getScheduledStartTime, getState, getTaskClassName, getTaskEntry, getTaskEntryDN, getTaskID, isCompleted, isPending, isRunning, parseBoolean, parseBooleanValue, parseDate, parseLong, parseString, parseStringList, parseStrings, toString, toString
-
-
-
-
Constructor Detail
-
ExecTask
public ExecTask()
Creates a new, uninitialized exec task instance that should only be used for obtaining general information about this task, including the task name, description, and supported properties. Attempts to use a task created with this constructor for any other reason will likely fail.
-
ExecTask
public ExecTask(@NotNull java.lang.String commandPath, @Nullable java.lang.String commandArguments, @Nullable java.lang.String commandOutputFile, @Nullable java.lang.Boolean logCommandOutput, @Nullable TaskState taskStateForNonZeroExitCode) throws TaskException
Creates a new exec task with the provided information.- Parameters:
commandPath
- The absolute path (on the server filesystem) to the command that should be executed. This must not benull
.commandArguments
- The complete set of arguments that should be used when running the command. This may benull
if no arguments should be provided.commandOutputFile
- The path to an output file that should be used to record all output that the command writes to standard output or standard error. This may benull
if the command output should not be recorded in a file.logCommandOutput
- Indicates whether to record the command output in the server error log. If this istrue
, then all non-blank lines that the command writes to standard output or standard error will be recorded in the server error log. if this isfalse
, then the output will not be recorded in the server error log. If this isnull
, then the server will determine whether to log command output. Note that a value oftrue
should only be used if you are certain that the tool will only generate text-based output, and you should usefalse
if you know that the command may generate non-text output.taskStateForNonZeroExitCode
- The task state that should be used if the command completes with a nonzero exit code. This may benull
to indicate that the server should determine the appropriate task state. If it is non-null
, then the value must be one ofTaskState.STOPPED_BY_ERROR
,TaskState.COMPLETED_WITH_ERRORS
, orTaskState.COMPLETED_SUCCESSFULLY
.- Throws:
TaskException
- If there is a problem with any of the provided arguments.
-
ExecTask
public ExecTask(@NotNull java.lang.String commandPath, @Nullable java.lang.String commandArguments, @Nullable java.lang.String commandOutputFile, @Nullable java.lang.Boolean logCommandOutput, @Nullable TaskState taskStateForNonZeroExitCode, @Nullable java.lang.String workingDirectory) throws TaskException
Creates a new exec task with the provided information.- Parameters:
commandPath
- The absolute path (on the server filesystem) to the command that should be executed. This must not benull
.commandArguments
- The complete set of arguments that should be used when running the command. This may benull
if no arguments should be provided.commandOutputFile
- The path to an output file that should be used to record all output that the command writes to standard output or standard error. This may benull
if the command output should not be recorded in a file.logCommandOutput
- Indicates whether to record the command output in the server error log. If this istrue
, then all non-blank lines that the command writes to standard output or standard error will be recorded in the server error log. if this isfalse
, then the output will not be recorded in the server error log. If this isnull
, then the server will determine whether to log command output. Note that a value oftrue
should only be used if you are certain that the tool will only generate text-based output, and you should usefalse
if you know that the command may generate non-text output.taskStateForNonZeroExitCode
- The task state that should be used if the command completes with a nonzero exit code. This may benull
to indicate that the server should determine the appropriate task state. If it is non-null
, then the value must be one ofTaskState.STOPPED_BY_ERROR
,TaskState.COMPLETED_WITH_ERRORS
, orTaskState.COMPLETED_SUCCESSFULLY
.workingDirectory
- The path to the working directory to use when executing the command.- Throws:
TaskException
- If there is a problem with any of the provided arguments.
-
ExecTask
public ExecTask(@Nullable java.lang.String taskID, @NotNull java.lang.String commandPath, @Nullable java.lang.String commandArguments, @Nullable java.lang.String commandOutputFile, @Nullable java.lang.Boolean logCommandOutput, @Nullable TaskState taskStateForNonZeroExitCode, @Nullable java.util.Date scheduledStartTime, @Nullable java.util.List<java.lang.String> dependencyIDs, @Nullable FailedDependencyAction failedDependencyAction, @Nullable java.util.List<java.lang.String> notifyOnCompletion, @Nullable java.util.List<java.lang.String> notifyOnError) throws TaskException
Creates a new exec task with the provided information.- Parameters:
taskID
- The task ID to use for this task. If it isnull
then a UUID will be generated for use as the task ID.commandPath
- The absolute path (on the server filesystem) to the command that should be executed. This must not benull
.commandArguments
- The complete set of arguments that should be used when running the command. This may benull
if no arguments should be provided.commandOutputFile
- The path to an output file that should be used to record all output that the command writes to standard output or standard error. This may benull
if the command output should not be recorded in a file.logCommandOutput
- Indicates whether to record the command output in the server error log. If this istrue
, then all non-blank lines that the command writes to standard output or standard error will be recorded in the server error log. if this isfalse
, then the output will not be recorded in the server error log. If this isnull
, then the server will determine whether to log command output. Note that a value oftrue
should only be used if you are certain that the tool will only generate text-based output, and you should usefalse
if you know that the command may generate non-text output.taskStateForNonZeroExitCode
- The task state that should be used if the command completes with a nonzero exit code. This may benull
to indicate that the server should determine the appropriate task state. If it is non-null
, then the value must be one ofTaskState.STOPPED_BY_ERROR
,TaskState.COMPLETED_WITH_ERRORS
, orTaskState.COMPLETED_SUCCESSFULLY
.scheduledStartTime
- The time that this task should start running.dependencyIDs
- The list of task IDs that will be required to complete before this task will be eligible to start.failedDependencyAction
- Indicates what action should be taken if any of the dependencies for this task do not complete successfully.notifyOnCompletion
- The list of e-mail addresses of individuals that should be notified when this task completes.notifyOnError
- The list of e-mail addresses of individuals that should be notified if this task does not complete successfully.- Throws:
TaskException
- If there is a problem with any of the provided arguments.
-
ExecTask
public ExecTask(@Nullable java.lang.String taskID, @NotNull java.lang.String commandPath, @Nullable java.lang.String commandArguments, @Nullable java.lang.String commandOutputFile, @Nullable java.lang.Boolean logCommandOutput, @Nullable TaskState taskStateForNonZeroExitCode, @Nullable java.util.Date scheduledStartTime, @Nullable java.util.List<java.lang.String> dependencyIDs, @Nullable FailedDependencyAction failedDependencyAction, @Nullable java.util.List<java.lang.String> notifyOnStart, @Nullable java.util.List<java.lang.String> notifyOnCompletion, @Nullable java.util.List<java.lang.String> notifyOnSuccess, @Nullable java.util.List<java.lang.String> notifyOnError, @Nullable java.lang.Boolean alertOnStart, @Nullable java.lang.Boolean alertOnSuccess, @Nullable java.lang.Boolean alertOnError) throws TaskException
Creates a new exec task with the provided information.- Parameters:
taskID
- The task ID to use for this task. If it isnull
then a UUID will be generated for use as the task ID.commandPath
- The absolute path (on the server filesystem) to the command that should be executed. This must not benull
.commandArguments
- The complete set of arguments that should be used when running the command. This may benull
if no arguments should be provided.commandOutputFile
- The path to an output file that should be used to record all output that the command writes to standard output or standard error. This may benull
if the command output should not be recorded in a file.logCommandOutput
- Indicates whether to record the command output in the server error log. If this istrue
, then all non-blank lines that the command writes to standard output or standard error will be recorded in the server error log. if this isfalse
, then the output will not be recorded in the server error log. If this isnull
, then the server will determine whether to log command output. Note that a value oftrue
should only be used if you are certain that the tool will only generate text-based output, and you should usefalse
if you know that the command may generate non-text output.taskStateForNonZeroExitCode
- The task state that should be used if the command completes with a nonzero exit code. This may benull
to indicate that the server should determine the appropriate task state. If it is non-null
, then the value must be one ofTaskState.STOPPED_BY_ERROR
,TaskState.COMPLETED_WITH_ERRORS
, orTaskState.COMPLETED_SUCCESSFULLY
.scheduledStartTime
- The time that this task should start running.dependencyIDs
- The list of task IDs that will be required to complete before this task will be eligible to start.failedDependencyAction
- Indicates what action should be taken if any of the dependencies for this task do not complete successfully.notifyOnStart
- The list of e-mail addresses of individuals that should be notified when this task starts.notifyOnCompletion
- The list of e-mail addresses of individuals that should be notified when this task completes.notifyOnSuccess
- The list of e-mail addresses of individuals that should be notified if this task completes successfully.notifyOnError
- The list of e-mail addresses of individuals that should be notified if this task does not complete successfully.alertOnStart
- Indicates whether the server should send an alert notification when this task starts.alertOnSuccess
- Indicates whether the server should send an alert notification if this task completes successfully.alertOnError
- Indicates whether the server should send an alert notification if this task fails to complete successfully.- Throws:
TaskException
- If there is a problem with any of the provided arguments.
-
ExecTask
public ExecTask(@Nullable java.lang.String taskID, @NotNull java.lang.String commandPath, @Nullable java.lang.String commandArguments, @Nullable java.lang.String commandOutputFile, @Nullable java.lang.Boolean logCommandOutput, @Nullable TaskState taskStateForNonZeroExitCode, @Nullable java.lang.String workingDirectory, @Nullable java.util.Date scheduledStartTime, @Nullable java.util.List<java.lang.String> dependencyIDs, @Nullable FailedDependencyAction failedDependencyAction, @Nullable java.util.List<java.lang.String> notifyOnStart, @Nullable java.util.List<java.lang.String> notifyOnCompletion, @Nullable java.util.List<java.lang.String> notifyOnSuccess, @Nullable java.util.List<java.lang.String> notifyOnError, @Nullable java.lang.Boolean alertOnStart, @Nullable java.lang.Boolean alertOnSuccess, @Nullable java.lang.Boolean alertOnError) throws TaskException
Creates a new exec task with the provided information.- Parameters:
taskID
- The task ID to use for this task. If it isnull
then a UUID will be generated for use as the task ID.commandPath
- The absolute path (on the server filesystem) to the command that should be executed. This must not benull
.commandArguments
- The complete set of arguments that should be used when running the command. This may benull
if no arguments should be provided.commandOutputFile
- The path to an output file that should be used to record all output that the command writes to standard output or standard error. This may benull
if the command output should not be recorded in a file.logCommandOutput
- Indicates whether to record the command output in the server error log. If this istrue
, then all non-blank lines that the command writes to standard output or standard error will be recorded in the server error log. if this isfalse
, then the output will not be recorded in the server error log. If this isnull
, then the server will determine whether to log command output. Note that a value oftrue
should only be used if you are certain that the tool will only generate text-based output, and you should usefalse
if you know that the command may generate non-text output.taskStateForNonZeroExitCode
- The task state that should be used if the command completes with a nonzero exit code. This may benull
to indicate that the server should determine the appropriate task state. If it is non-null
, then the value must be one ofTaskState.STOPPED_BY_ERROR
,TaskState.COMPLETED_WITH_ERRORS
, orTaskState.COMPLETED_SUCCESSFULLY
.workingDirectory
- The path to the working directory to use when executing the command.scheduledStartTime
- The time that this task should start running.dependencyIDs
- The list of task IDs that will be required to complete before this task will be eligible to start.failedDependencyAction
- Indicates what action should be taken if any of the dependencies for this task do not complete successfully.notifyOnStart
- The list of e-mail addresses of individuals that should be notified when this task starts.notifyOnCompletion
- The list of e-mail addresses of individuals that should be notified when this task completes.notifyOnSuccess
- The list of e-mail addresses of individuals that should be notified if this task completes successfully.notifyOnError
- The list of e-mail addresses of individuals that should be notified if this task does not complete successfully.alertOnStart
- Indicates whether the server should send an alert notification when this task starts.alertOnSuccess
- Indicates whether the server should send an alert notification if this task completes successfully.alertOnError
- Indicates whether the server should send an alert notification if this task fails to complete successfully.- Throws:
TaskException
- If there is a problem with any of the provided arguments.
-
ExecTask
public ExecTask(@NotNull Entry entry) throws TaskException
Creates a new exec task from the provided entry.- Parameters:
entry
- The entry to use to create this exec task.- Throws:
TaskException
- If the provided entry cannot be parsed as an exec task entry.
-
ExecTask
public ExecTask(@NotNull java.util.Map<TaskProperty,java.util.List<java.lang.Object>> properties) throws TaskException
Creates a new exec task from the provided set of task properties.- Parameters:
properties
- The set of task properties and their corresponding values to use for the task. It must not benull
.- Throws:
TaskException
- If the provided set of properties cannot be used to create a valid exec task.
-
-
Method Detail
-
getTaskName
@NotNull public java.lang.String getTaskName()
Retrieves a human-readable name for this task.- Overrides:
getTaskName
in classTask
- Returns:
- A human-readable name for this task.
-
getTaskDescription
@NotNull public java.lang.String getTaskDescription()
Retrieves a human-readable description for this task.- Overrides:
getTaskDescription
in classTask
- Returns:
- A human-readable description for this task.
-
getCommandPath
@NotNull public java.lang.String getCommandPath()
Retrieves the path to the command to be executed.- Returns:
- The path to the command to be executed.
-
getCommandArguments
@Nullable public java.lang.String getCommandArguments()
Retrieves a string with the values of the arguments that should be provided when running the command.- Returns:
- A string with the values of the arguments that should be provided
when running the command, or
null
if the command should be run without any arguments.
-
getCommandOutputFile
@Nullable public java.lang.String getCommandOutputFile()
Retrieves the path to a file to which the command's output should be written.- Returns:
- The path to a file to which the command's output should be
written, or
null
if the output should not be written to a file.
-
logCommandOutput
@Nullable public java.lang.Boolean logCommandOutput()
Indicates whether the command's output should be recorded in the server's error log.- Returns:
true
if the command's output should be recorded in the server's error log,false
if the output should not be logged, ornull
if the task should not specify the behavior.
-
getTaskStateForNonZeroExitCode
@Nullable public java.lang.String getTaskStateForNonZeroExitCode()
Retrieves a string representation of the task state that should be returned if the command completes with a nonzero exit code.- Returns:
- A string representation of the task state that should be returned
if the command completes with a nonzero exit state, or
null
if the task should not specify the return state.
-
getWorkingDirectory
@Nullable public java.lang.String getWorkingDirectory()
Retrieves the path to the working directory to use when executing the command.- Returns:
- The path to the working directory to use when executing the
command, or
null
if the task should not specify the working directory and the server root directory should be used by default.
-
getAdditionalObjectClasses
@NotNull protected java.util.List<java.lang.String> getAdditionalObjectClasses()
Retrieves a list of the additional object classes (other than the base "top" and "ds-task" classes) that should be included when creating new task entries of this type.- Overrides:
getAdditionalObjectClasses
in classTask
- Returns:
- A list of the additional object classes that should be included in new task entries of this type, or an empty list if there do not need to be any additional classes.
-
getAdditionalAttributes
@NotNull protected java.util.List<Attribute> getAdditionalAttributes()
Retrieves a list of the additional attributes (other than attributes common to all task types) that should be included when creating new task entries of this type.- Overrides:
getAdditionalAttributes
in classTask
- Returns:
- A list of the additional attributes that should be included in new task entries of this type, or an empty list if there do not need to be any additional attributes.
-
getTaskSpecificProperties
@NotNull public java.util.List<TaskProperty> getTaskSpecificProperties()
Retrieves a list of task-specific properties that may be provided when scheduling a task of this type. This method should be overridden by subclasses in order to provide an appropriate set of properties.- Overrides:
getTaskSpecificProperties
in classTask
- Returns:
- A list of task-specific properties that may be provided when scheduling a task of this type.
-
getTaskPropertyValues
@NotNull public java.util.Map<TaskProperty,java.util.List<java.lang.Object>> getTaskPropertyValues()
Retrieves the values of the task properties for this task. The data type of the values will vary based on the data type of the corresponding task property and may be one of the following types:Boolean
,Date
,Long
, orString
. Task properties which do not have any values will be included in the map with an empty value list.
Note that subclasses which have additional task properties should override this method and return a map which contains both the property values from this class (obtained fromsuper.getTaskPropertyValues()
and the values of their own task-specific properties.- Overrides:
getTaskPropertyValues
in classTask
- Returns:
- A map of the task property values for this task.
-
-