Class WorkClientImpl

java.lang.Object
co.yellowdog.platform.clients.scheduler.WorkClientImpl
All Implemented Interfaces:
WorkClient, AutoCloseable

public class WorkClientImpl extends Object implements WorkClient, AutoCloseable
Implementation of the WorkClient interface.
  • Method Details

    • create

      public static WorkClientImpl create(@NonNull @NonNull ServicesSchema servicesSchema, @NonNull @NonNull RetryFactory retryFactory, @NonNull @NonNull AuthenticationHeadersProvider authenticationHeadersProvider, @NonNull @NonNull com.fasterxml.jackson.databind.ObjectMapper objectMapper, @NonNull @NonNull UserAgent userAgent)
    • addWorkRequirement

      public WorkRequirement addWorkRequirement(@NonNull @NonNull WorkRequirement workRequirement)
      Description copied from interface: WorkClient
      Submits a NEW work requirement to the YellowDog Scheduler service to be initialised and started.
      Specified by:
      addWorkRequirement in interface WorkClient
      Parameters:
      workRequirement - the work requirement to submit
      Returns:
      the latest state of the work requirement after it has been submitted
    • updateWorkRequirement

      public WorkRequirement updateWorkRequirement(@NonNull @NonNull WorkRequirement workRequirement)
      Description copied from interface: WorkClient
      Submits an existing work requirement to the YellowDog Scheduler service to be updated.
      Specified by:
      updateWorkRequirement in interface WorkClient
      Parameters:
      workRequirement - the work requirement to submit
      Returns:
      the latest state of the work requirement after it has been submitted
    • getWorkRequirement

      public WorkRequirement getWorkRequirement(@NonNull @NonNull WorkRequirement workRequirement)
      Description copied from interface: WorkClient
      Gets the latest state of the supplied work requirement.
      Specified by:
      getWorkRequirement in interface WorkClient
      Parameters:
      workRequirement - the work requirement for which to get the latest state
      Returns:
      the latest state of the work requirement
    • getWorkRequirement

      public WorkRequirement getWorkRequirement(@NonNull @NonNull String workRequirementId)
      Description copied from interface: WorkClient
      Gets the latest state of the supplied work requirement.
      Specified by:
      getWorkRequirement in interface WorkClient
      Parameters:
      workRequirementId - the ID of the work requirement
      Returns:
      the latest state of the work requirement
    • getWorkRequirement

      public WorkRequirement getWorkRequirement(@NonNull @NonNull String namespace, @NonNull @NonNull String workRequirementName)
      Description copied from interface: WorkClient
      Gets the latest state of the supplied work requirement.
      Specified by:
      getWorkRequirement in interface WorkClient
      Parameters:
      namespace - the namespace containing the requirement
      workRequirementName - the name of the requirement
      Returns:
      the latest state of the work requirement
    • holdWorkRequirement

      public WorkRequirement holdWorkRequirement(@NonNull @NonNull WorkRequirement workRequirement)
      Description copied from interface: WorkClient
      Instructs the Scheduler to hold the supplied work requirement, no further tasks will be executed until the work requirement is started again.
      Specified by:
      holdWorkRequirement in interface WorkClient
      Parameters:
      workRequirement - the work requirement to hold
      Returns:
      the latest state of the work requirement after the hold instruction was submitted
    • holdWorkRequirement

      public WorkRequirement holdWorkRequirement(@NonNull @NonNull String workRequirementId)
      Description copied from interface: WorkClient
      Instructs the Scheduler to hold the supplied work requirement, no further tasks will be executed until the work requirement is started again.
      Specified by:
      holdWorkRequirement in interface WorkClient
      Parameters:
      workRequirementId - the ID of the work requirement to hold
      Returns:
      the latest state of the work requirement after the hold instruction was submitted
    • startWorkRequirement

      public WorkRequirement startWorkRequirement(@NonNull @NonNull WorkRequirement workRequirement)
      Description copied from interface: WorkClient
      Instructs the Scheduler to start the supplied work requirement after it was held.
      Specified by:
      startWorkRequirement in interface WorkClient
      Parameters:
      workRequirement - the work requirement to start after being held
      Returns:
      the latest state of the work requirement after the start instruction was submitted
    • startWorkRequirement

      public WorkRequirement startWorkRequirement(@NonNull @NonNull String workRequirementId)
      Description copied from interface: WorkClient
      Instructs the Scheduler to start the supplied work requirement after it was held.
      Specified by:
      startWorkRequirement in interface WorkClient
      Parameters:
      workRequirementId - the ID of the work requirement to start after being held
      Returns:
      the latest state of the work requirement after the start instruction was submitted
    • cancelWorkRequirement

      public WorkRequirement cancelWorkRequirement(@NonNull @NonNull WorkRequirement workRequirement)
      Description copied from interface: WorkClient
      Instructs the Scheduler to cancel the supplied work requirement, no further tasks will be executed and all workers shall be released.
      Specified by:
      cancelWorkRequirement in interface WorkClient
      Parameters:
      workRequirement - the work requirement to cancel
      Returns:
      the latest state of the work requirement after the cancel instruction was submitted
    • cancelWorkRequirement

      public WorkRequirement cancelWorkRequirement(@NonNull @NonNull WorkRequirement workRequirement, boolean abort)
      Description copied from interface: WorkClient
      Instructs the Scheduler to cancel the supplied work requirement, no further tasks will be executed and all workers shall be released.
      Specified by:
      cancelWorkRequirement in interface WorkClient
      Parameters:
      workRequirement - the work requirement to cancel
      abort - if tasks should be aborted if they have been allocated to a worker
      Returns:
      the latest state of the work requirement after the cancel instruction was submitted
    • cancelWorkRequirement

      public WorkRequirement cancelWorkRequirement(@NonNull @NonNull String workRequirementId)
      Description copied from interface: WorkClient
      Instructs the Scheduler to cancel the supplied work requirement, no further tasks will be executed and all workers shall be released.
      Specified by:
      cancelWorkRequirement in interface WorkClient
      Parameters:
      workRequirementId - the ID of the work requirement to cancel
      Returns:
      the latest state of the work requirement after the cancel instruction was submitted
    • cancelWorkRequirement

      public WorkRequirement cancelWorkRequirement(@NonNull @NonNull String workRequirementId, boolean abort)
      Description copied from interface: WorkClient
      Instructs the Scheduler to cancel the supplied work requirement, no further tasks will be executed and all workers shall be released.
      Specified by:
      cancelWorkRequirement in interface WorkClient
      Parameters:
      workRequirementId - the ID of the work requirement to cancel
      abort - if tasks should be aborted if they have been allocated to a worker
      Returns:
      the latest state of the work requirement after the cancel instruction was submitted
    • addWorkRequirementListener

      public void addWorkRequirementListener(@NonNull @NonNull WorkRequirement workRequirement, @NonNull @NonNull SubscriptionEventListener<WorkRequirement> listener)
      Description copied from interface: WorkClient
      Adds an event listener to receive notifications of changes for the specified work requirement. The client manages subscriptions to YellowDog Scheduler such that the first listener created for a requirement will cause a Server-Sent Events subscription to be initiated; additional listeners for the same requirement share that subscription.
      Specified by:
      addWorkRequirementListener in interface WorkClient
      Parameters:
      workRequirement - the work requirement for which to receive notifications
      listener - the event listener that will be invoked for notifications
    • addWorkRequirementListener

      public void addWorkRequirementListener(@NonNull @NonNull String workRequirementId, @NonNull @NonNull SubscriptionEventListener<WorkRequirement> listener)
      Description copied from interface: WorkClient
      Adds an event listener to receive notifications of changes for the specified work requirement. The client manages subscriptions to YellowDog Scheduler such that the first listener created for a requirement will cause a Server-Sent Events subscription to be initiated; additional listeners for the same requirement share that subscription.
      Specified by:
      addWorkRequirementListener in interface WorkClient
      Parameters:
      workRequirementId - the ID of the work requirement for which to receive notifications
      listener - the event listener that will be invoked for notifications
    • removeWorkRequirementListener

      public void removeWorkRequirementListener(@NonNull @NonNull SubscriptionEventListener<WorkRequirement> listener)
      Description copied from interface: WorkClient
      Removes the specified event listener. The client manages subscriptions to YellowDog Scheduler such that when the last listener for a requirement is removed, the associated Server-Sent Events subscription is cancelled.
      Specified by:
      removeWorkRequirementListener in interface WorkClient
      Parameters:
      listener - the event listener that will no longer be invoked for notifications
    • getWorkRequirementHelper

      public WorkRequirementHelper getWorkRequirementHelper(@NonNull @NonNull WorkRequirement workRequirement)
      Description copied from interface: WorkClient
      Constructs a new work requirement helper for the specified requirement.
      Specified by:
      getWorkRequirementHelper in interface WorkClient
      Parameters:
      workRequirement - the work requirement for which the helper will be constructed
      Returns:
      a new work requirement helper
    • getWorkRequirementHelper

      public WorkRequirementHelper getWorkRequirementHelper(@NonNull @NonNull String workRequirementId)
      Description copied from interface: WorkClient
      Constructs a new work requirement helper for the specified requirement.
      Specified by:
      getWorkRequirementHelper in interface WorkClient
      Parameters:
      workRequirementId - the ID of the work requirement for which the helper will be constructed
      Returns:
      a new work requirement helper
    • findAllWorkRequirements

      public List<WorkRequirementSummary> findAllWorkRequirements()
      Description copied from interface: WorkClient
      Returns summaries of all existing work requirements within the system for the requesting user.
      Specified by:
      findAllWorkRequirements in interface WorkClient
      Returns:
      a list of work requirement summaries
    • getWorkRequirements

      public SearchClient<WorkRequirementSummary> getWorkRequirements(WorkRequirementSearch search)
      Description copied from interface: WorkClient
      Returns a SearchClient that offers the ability to search work requirements.
      Specified by:
      getWorkRequirements in interface WorkClient
      Parameters:
      search - the search
      Returns:
      the search client
    • addTasksToTaskGroup

      public List<Task> addTasksToTaskGroup(@NonNull @NonNull TaskGroup taskGroup, @NonNull @NonNull List<Task> tasks)
      Description copied from interface: WorkClient
      Submits NEW tasks to the YellowDog Scheduler service to be added to the specified task group.
      Specified by:
      addTasksToTaskGroup in interface WorkClient
      Parameters:
      taskGroup - the task group to add the tasks to
      tasks - the submitted tasks
      Returns:
      the latest state of the tasks after they have been submitted
    • addTasksToTaskGroup

      public List<Task> addTasksToTaskGroup(@NonNull @NonNull String taskGroupId, @NonNull @NonNull List<Task> tasks)
      Description copied from interface: WorkClient
      Submits NEW tasks to the YellowDog Scheduler service to be added to the specified task group.
      Specified by:
      addTasksToTaskGroup in interface WorkClient
      Parameters:
      taskGroupId - the ID of the task group to add the tasks to
      tasks - the submitted tasks
      Returns:
      the latest state of the tasks after they have been submitted
    • addTasksToTaskGroup

      public List<Task> addTasksToTaskGroup(@NonNull @NonNull String namespace, @NonNull @NonNull String workRequirementName, @NonNull @NonNull String taskGroupName, @NonNull @NonNull List<Task> tasks)
      Description copied from interface: WorkClient
      Submits NEW tasks to the YellowDog Scheduler service to be added to the specified task group.
      Specified by:
      addTasksToTaskGroup in interface WorkClient
      Parameters:
      namespace - the namespace
      workRequirementName - the work requirement name
      taskGroupName - the task group name
      tasks - the submitted tasks
      Returns:
      the latest state of the tasks after they have been submitted
    • getTask

      public Task getTask(@NonNull @NonNull Task task)
      Description copied from interface: WorkClient
      Gets the latest state of the supplied task.
      Specified by:
      getTask in interface WorkClient
      Parameters:
      task - the task for which to get the latest state
      Returns:
      the latest state of the task
    • getTask

      public Task getTask(String taskId)
      Description copied from interface: WorkClient
      Gets the latest state of the supplied task.
      Specified by:
      getTask in interface WorkClient
      Parameters:
      taskId - the ID of the task
      Returns:
      the latest state of the task
    • cancelTask

      public Task cancelTask(@NonNull @NonNull Task task, boolean abort)
      Description copied from interface: WorkClient
      Instructs the Scheduler to cancel the specified task.
      Specified by:
      cancelTask in interface WorkClient
      Parameters:
      task - the task to cancel
      abort - if the task should be aborted if it has been allocated to a worker
      Returns:
      the latest state of the task after the cancel instruction was submitted
    • cancelTask

      public Task cancelTask(@NonNull @NonNull String taskId, boolean abort)
      Description copied from interface: WorkClient
      Instructs the Scheduler to cancel the specified task.
      Specified by:
      cancelTask in interface WorkClient
      Parameters:
      taskId - the ID of the task to cancel
      abort - if the task should be aborted if it has been allocated to a worker
      Returns:
      the latest state of the task after the cancel instruction was submitted
    • findTasks

      public List<Task> findTasks(@NonNull @NonNull TaskSearch search)
      Description copied from interface: WorkClient
      Returns tasks within the system that match the specified search. WARNING: If your search matches too many tasks to fit into your application's memory limits, consider using WorkClient.streamTasks(TaskSearch) or WorkClient.findTasks(TaskSearch, SliceReference).
      Specified by:
      findTasks in interface WorkClient
      Parameters:
      search - the search
      Returns:
      a list of tasks
    • streamTasks

      public Stream<Task> streamTasks(@NonNull @NonNull TaskSearch search)
      Description copied from interface: WorkClient
      Streams tasks within the system that match the specified search.
      Specified by:
      streamTasks in interface WorkClient
      Parameters:
      search - the search
      Returns:
      a stream of tasks
    • findTasks

      public Slice<Task> findTasks(@NonNull @NonNull TaskSearch search, @NonNull @NonNull SliceReference sliceReference)
      Description copied from interface: WorkClient
      Returns a slice of tasks that match the specified search and slice reference.
      Specified by:
      findTasks in interface WorkClient
      Parameters:
      search - the search
      sliceReference - the slice reference
      Returns:
      a slice of tasks
    • getTasks

      public SearchClient<Task> getTasks(TaskSearch search)
      Description copied from interface: WorkClient
      Returns a SearchClient that offers the ability to search tasks.
      Specified by:
      getTasks in interface WorkClient
      Parameters:
      search - the search
      Returns:
      the search client
    • close

      public void close()
      Cancels any active Server-Sent Event subscriptions.
      Specified by:
      close in interface AutoCloseable