Package org.opends.server.tools.tasks
Class TaskClient
- java.lang.Object
-
- org.opends.server.tools.tasks.TaskClient
-
public final class TaskClient extends Object
Helper class for interacting with the task backend on behalf of utilities that are capable of being scheduled.
-
-
Constructor Summary
Constructors Constructor Description TaskClient(Connection conn)
Creates a new TaskClient for interacting with the task backend remotely.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancelTask(String taskId)
Changes that the state of the task in the backend to a canceled state.static Entry
createTask(TaskScheduleInformation information)
Creates anEntry
for the task described in the providedTaskScheduleInformation
.static String
getTaskDn(Entry taskEntry)
Uses provided task entry attributes to create a DN for the provided task entry.List<TaskEntry>
getTaskEntries()
Gets all the ds-task entries from the task root.TaskEntry
getTaskEntry(String taskId)
Gets the entry of the task associated to the provided identifier.static String
getTaskId(Entry taskEntry)
Returns the ID of the provided task entry.TaskEntry
schedule(TaskScheduleInformation information)
Schedule a task for execution by writing an entry to the task backend.TaskEntry
waitUntilTaskIsDone(String taskId, PrintStream stream)
Wait until the task with the provided id is done.
-
-
-
Constructor Detail
-
TaskClient
public TaskClient(Connection conn)
Creates a new TaskClient for interacting with the task backend remotely.- Parameters:
conn
- for accessing the task backend
-
-
Method Detail
-
getTaskId
public static String getTaskId(Entry taskEntry)
Returns the ID of the provided task entry.- Parameters:
taskEntry
- The taskEntry
.- Returns:
- the ID of the provided task
Entry
. - Throws:
IllegalArgumentException
- If the task ID cannot be retrieve from the providedEntry
.
-
getTaskDn
public static String getTaskDn(Entry taskEntry)
Uses provided task entry attributes to create a DN for the provided task entry.
-
waitUntilTaskIsDone
public TaskEntry waitUntilTaskIsDone(String taskId, PrintStream stream) throws LdapException, TaskClientException
Wait until the task with the provided id is done.The provided
taskClient
is used for retrieving task information. During the execution, tasks logs are printed on the providedstream
.- Parameters:
taskId
- A string representing the ID of the task to retrieve.stream
- The stream to use for printing task logs, may benull
.- Returns:
- A
task entry
object representing the task done. - Throws:
LdapException
- If an error occurs while retrieving task information from the server.TaskClientException
- If there is no task with the requested ID.
-
schedule
public TaskEntry schedule(TaskScheduleInformation information) throws LdapException, TaskClientException
Schedule a task for execution by writing an entry to the task backend.- Parameters:
information
- to be scheduled- Returns:
- String task ID assigned the new task
- Throws:
LdapException
- if there is a problem getting information out to the directoryTaskClientException
- if there is a problem with the task entry
-
createTask
public static Entry createTask(TaskScheduleInformation information)
Creates anEntry
for the task described in the providedTaskScheduleInformation
.- Parameters:
information
- The scheduling information from which to create the task entry.- Returns:
- A new entry representing a task.
-
getTaskEntries
public List<TaskEntry> getTaskEntries() throws LdapException
Gets all the ds-task entries from the task root.- Returns:
- list of entries from the task root
- Throws:
LdapException
- if there is a problem getting information out to the directory
-
getTaskEntry
public TaskEntry getTaskEntry(String taskId) throws LdapException, TaskClientException
Gets the entry of the task associated to the provided identifier.- Parameters:
taskId
- of the entry to retrieve- Returns:
- Entry for the task
- Throws:
LdapException
- if there is a problem getting information out to the directoryTaskClientException
- if there is no task with the requested id
-
cancelTask
public void cancelTask(String taskId) throws TaskClientException, LdapException
Changes that the state of the task in the backend to a canceled state.- Parameters:
taskId
- if the task to cancel- Throws:
LdapException
- if there is a problem getting information out to the directoryTaskClientException
- if there is no task with the requested id or if the task has finished and cannot be completed
-
-