org.springframework.cloud.dataflow.rest.client.dsl.task

## Class Task

- java.lang.Object
- - org.springframework.cloud.dataflow.rest.client.dsl.task.Task

- All Implemented Interfaces:
    AutoCloseable

      public class Task
      extends Object
      implements AutoCloseable

  Represents a Task defined on DataFlow server. New Task can be defined with the help of a fluent style builder pattern or use the `Task` static utility methods to retrieve existing tasks already defined in DataFlow. For for instance you can define a new task like this:

           Task task = Task.builder(dataflowOperations)
                    .name("myComposedTask")
                    .definition("a: timestamp && b:timestamp")
                    .description("My Composed Task")
                    .build();

  Next you can launch the task and inspect the executions result. Mind that the task is run asynchronously.

           import org.awaitility.Awaitility;

                long launchId = task.launch();

                // Leverage Awaitility to wait until task completion.
                Awaitility.await().until(() -> task.executionStatus(launchId) == TaskExecutionStatus.COMPLETE);

                // Check the executions
                task.executions().forEach( execution -> System.out.println(execution.getExitCode()));

  Use

       close()

  to destroy the task manually. Since tasks are auto-closable you can use the Java try block instead:

                try (Task task = Task.builder(dataFlowOperations)
                     .name("myTask")
                     .definition("timestamp")
                     .description("Test timestamp task")
                     .build()) {

                       long launchId1 = task.launch();
                       // Do something
                } // Task is destroyed.

  Use the `TaskBuilder.allTasks()` and `TaskBuilder.findByName(String)` static helper methods to list or retrieve existing tasks defined in DataFlow.
  Author:
    Christian Tzolov

- - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static TaskBuilder` | `builder(DataFlowOperations dataFlowOperations)` Fluent API method to create a `TaskBuilder`.
    `void` | `close()`
    `Optional<Task>` | `composedTaskChildTaskByLabel(String childTaskLabel)`
    `List<Task>` | `composedTaskChildTasks()`
    `void` | `destroy()` Destroy the task.
    `Optional<TaskExecutionResource>` | `execution(long executionId)` Retrieve task execution by Id.
    `Optional<TaskExecutionResource>` | `executionByParentExecutionId(long parentExecutionId)` Find `TaskExecutionResource` by a parent execution id.
    `Collection<TaskExecutionResource>` | `executions()` List task executions for this task.
    `TaskExecutionStatus` | `executionStatus(long executionId)` Task execution status
    `String` | `getTaskName()`
    `boolean` | `isComposed()`
    `Collection<JobExecutionResource>` | `jobExecutionResources()`
    `Collection<JobInstanceResource>` | `jobInstanceResources()`
    `long` | `launch()` Launch a task without properties or arguments.
    `long` | `launch(List<String> arguments)` Launch a task with command line arguments.
    `long` | `launch(Map<String,String> properties, List<String> arguments)` Launch a task with deployment properties and command line arguments.
    `void` | `stop()` Stop all Tasks' running `TaskExecution`s.
    `void` | `stop(long... taskExecutionIds)` Stop a list of `TaskExecution`s.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### builder

          public static TaskBuilder builder(DataFlowOperations dataFlowOperations)

      Fluent API method to create a `TaskBuilder`.
      Parameters:
        `dataFlowOperations` - `DataFlowOperations` Data Flow Rest client instance.
      Returns:
        A fluent style builder to create tasks.

    - #### launch

          public long launch()

      Launch a task without properties or arguments.
      Returns:
        long containing the TaskExecutionId

    - #### launch

          public long launch(List<String> arguments)

      Launch a task with command line arguments.
      Parameters:
        `arguments` - the command line arguments.
      Returns:
        long containing the TaskExecutionId

    - #### launch

          public long launch(Map<String,String> properties,
                             List<String> arguments)

      Launch a task with deployment properties and command line arguments.
      Parameters:
        `properties` - the deployment properties.
        `arguments` - the command line arguments.
      Returns:
        long containing the TaskExecutionId

    - #### stop

          public void stop()

      Stop all Tasks' running `TaskExecution`s. Note: this functionality is platform dependent! It works for local platform but does nothing on K8s!

    - #### stop

          public void stop(long... taskExecutionIds)

      Stop a list of `TaskExecution`s.
      Parameters:
        `taskExecutionIds` - List of `TaskExecution` ids to stop. Note: this functionality is platform dependent! It works for local platform but does nothing on K8s!

    - #### destroy

          public void destroy()

      Destroy the task.

    - #### executions

          public Collection<TaskExecutionResource> executions()

      List task executions for this task.
      Returns:
        List of task executions for the given task.

    - #### execution

          public Optional<TaskExecutionResource> execution(long executionId)

      Retrieve task execution by Id.
      Parameters:
        `executionId` - Task execution Id
      Returns:
        Task executions for the given task execution id.

    - #### executionByParentExecutionId

          public Optional<TaskExecutionResource> executionByParentExecutionId(long parentExecutionId)

      Find `TaskExecutionResource` by a parent execution id.
      Parameters:
        `parentExecutionId` - parent task execution id.
      Returns:
        Return TaskExecutionResource

    - #### executionStatus

          public TaskExecutionStatus executionStatus(long executionId)

      Task execution status
      Parameters:
        `executionId` - execution Id
      Returns:
        returns the task execution status.

    - #### isComposed

          public boolean isComposed()

      Returns:
        Return true if composed task or false otherwise.

    - #### composedTaskChildTasks

          public List<Task> composedTaskChildTasks()

      Returns:
        If a composed task return the list of children sub-tasks. Returns empty list if not composed task.

    - #### composedTaskChildTaskByLabel

          public Optional<Task> composedTaskChildTaskByLabel(String childTaskLabel)

      Parameters:
        `childTaskLabel` - Name of the child composed task (excluding the parent prefix).
      Returns:
        The child composed task for the given name.

    - #### jobExecutionResources

          public Collection<JobExecutionResource> jobExecutionResources()

      Returns:
        Returns list of `JobExecutionResource` belonging to the task.

    - #### jobInstanceResources

          public Collection<JobInstanceResource> jobInstanceResources()

      Returns:
        Returns list of `JobInstanceResource` belonging to this task.

    - #### getTaskName

          public String getTaskName()

      Returns:
        Returns the task name.

    - #### close

          public void close()

      Specified by:
        `close` in interface `AutoCloseable`

Copyright © 2021 Pivotal Software, Inc.. All rights reserved.