public class Task extends Object implements AutoCloseable
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.Modifier and Type | Method and Description |
---|---|
static TaskBuilder |
builder(DataFlowOperations dataFlowOperations)
Fluent API method to create a
TaskBuilder . |
void |
cleanupAllTaskExecutions()
Remove all task executions.
|
void |
cleanupTaskExecution(long taskExecutionId)
Remove specified task execution for the specified task execution id.
|
void |
close() |
Optional<TaskExecutionResource> |
composedTaskChildExecution(String childTaskName)
Retrieve task executions for child task name associated with this task's instance.
|
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() |
Collection<StepExecutionResource> |
jobStepExecutions(long jobExecutionId) |
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. |
public static TaskBuilder builder(DataFlowOperations dataFlowOperations)
TaskBuilder
.dataFlowOperations
- DataFlowOperations
Data Flow Rest client instance.public long launch()
public long launch(List<String> arguments)
arguments
- the command line arguments.public long launch(Map<String,String> properties, List<String> arguments)
properties
- the deployment properties.arguments
- the command line arguments.public void stop()
TaskExecution
s.
Note: this functionality is platform dependent! It works for local platform but does nothing on K8s!public void stop(long... taskExecutionIds)
TaskExecution
s.taskExecutionIds
- List of TaskExecution
ids to stop.
Note: this functionality is platform dependent! It works for local platform but does nothing on K8s!public void destroy()
public Collection<TaskExecutionResource> executions()
public Optional<TaskExecutionResource> execution(long executionId)
executionId
- Task execution Idpublic Optional<TaskExecutionResource> executionByParentExecutionId(long parentExecutionId)
TaskExecutionResource
by a parent execution id.parentExecutionId
- parent task execution id.public TaskExecutionStatus executionStatus(long executionId)
executionId
- execution Idpublic boolean isComposed()
public List<Task> composedTaskChildTasks()
public Optional<Task> composedTaskChildTaskByLabel(String childTaskLabel)
childTaskLabel
- Name of the child composed task (excluding the parent prefix).public Collection<JobExecutionResource> jobExecutionResources()
JobExecutionResource
belonging to the task.public Collection<StepExecutionResource> jobStepExecutions(long jobExecutionId)
StepExecutionResource
belonging to the job.public Collection<JobInstanceResource> jobInstanceResources()
JobInstanceResource
belonging to this task.public String getTaskName()
public void close()
close
in interface AutoCloseable
public void cleanupTaskExecution(long taskExecutionId)
taskExecutionId
- the id of the task execution to be removed.public void cleanupAllTaskExecutions()
public Optional<TaskExecutionResource> composedTaskChildExecution(String childTaskName)
childTaskName
- to be used to search for the associated task executions.Copyright © 2022 Pivotal Software, Inc.. All rights reserved.