From 68ae28f0ff9a08524a7f335e7137a1e33680a3a5 Mon Sep 17 00:00:00 2001 From: Varun Bansal Date: Tue, 7 May 2024 18:38:58 +0530 Subject: [PATCH] add documentation & TaskWorker interface --- .../opensearch/offline_tasks/TaskClient.java | 18 ++++++----- .../offline_tasks/{ => task}/Task.java | 5 ++- .../offline_tasks/{ => task}/TaskId.java | 13 ++++++-- .../offline_tasks/task/TaskParams.java | 23 ++++++++++++++ .../offline_tasks/{ => task}/TaskType.java | 2 +- .../{ => task}/package-info.java | 2 +- .../offline_tasks/worker/TaskWorker.java | 31 +++++++++++++++++++ .../offline_tasks/worker/package-info.java | 12 +++++++ .../offline_tasks/TaskClientTest.java} | 6 ++-- 9 files changed, 94 insertions(+), 18 deletions(-) rename libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/{ => task}/Task.java (88%) rename libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/{ => task}/TaskId.java (55%) create mode 100644 libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/TaskParams.java rename libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/{ => task}/TaskType.java (90%) rename libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/{ => task}/package-info.java (86%) create mode 100644 libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/worker/TaskWorker.java create mode 100644 libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/worker/package-info.java rename libs/offline-tasks/src/{main/java/org/opensearch/offline_tasks/TaskParams.java => test/java/org/opensearch/offline_tasks/TaskClientTest.java} (68%) diff --git a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskClient.java b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskClient.java index 6d228f01dfbf6..8bb8c5a211b41 100644 --- a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskClient.java +++ b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskClient.java @@ -9,6 +9,8 @@ package org.opensearch.offline_tasks; import org.opensearch.common.annotation.ExperimentalApi; +import org.opensearch.offline_tasks.task.Task; +import org.opensearch.offline_tasks.task.TaskId; import java.util.List; @@ -21,37 +23,37 @@ public interface TaskClient { /** - * Submit a new task to Task Store/Queue + * Submit a new task to TaskStore/Queue * * @param task */ void submitTask(Task task); /** - * Claim task from Task Store/Queue. This ensure no 2 nodes work on the same task. + * Claim task from TaskStore/Queue. This ensures no 2 Offline Nodes work on the same task. * * @param taskId */ void claimTask(TaskId taskId); /** - * Get task from Task Store/Queue + * Get task from TaskStore/Queue * * @param taskId - * @return + * @return Task corresponding to TaskId */ Task getTask(TaskId taskId); /** - * Update task in Task Store/Queue + * Update task in TaskStore/Queue * * @param task - * @return */ - Task updateTask(Task task); + void updateTask(Task task); /** - * Mark task as cancelled + * Mark task as cancelled. + * Ongoing Tasks can be cancelled as well if the corresponding worker supports cancellation * * @param taskId */ diff --git a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/Task.java b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/Task.java similarity index 88% rename from libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/Task.java rename to libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/Task.java index 68c7363e97290..0488cc3729e6f 100644 --- a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/Task.java +++ b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/Task.java @@ -6,11 +6,14 @@ * compatible open source license. */ -package org.opensearch.offline_tasks; +package org.opensearch.offline_tasks.task; + +import org.opensearch.common.annotation.ExperimentalApi; /** * A Background Task to be run on Offline Node. */ +@ExperimentalApi public class Task { /** diff --git a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskId.java b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/TaskId.java similarity index 55% rename from libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskId.java rename to libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/TaskId.java index 06f913a5ff67a..002020934ba18 100644 --- a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskId.java +++ b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/TaskId.java @@ -6,18 +6,25 @@ * compatible open source license. */ -package org.opensearch.offline_tasks; +package org.opensearch.offline_tasks.task; + +import org.opensearch.common.annotation.ExperimentalApi; /** - * Class encapsulating Task id + * Class encapsulating Task identifier */ +@ExperimentalApi public class TaskId { /** - * Id of the Task + * Identified of the Task */ String id; + /** + * Constructor to initialize TaskId + * @param id + */ public TaskId(String id) { this.id = id; } diff --git a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/TaskParams.java b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/TaskParams.java new file mode 100644 index 0000000000000..32af63a6cd788 --- /dev/null +++ b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/TaskParams.java @@ -0,0 +1,23 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.offline_tasks.task; + +import org.opensearch.common.annotation.ExperimentalApi; + +/** + * Base class for all TaskParams implementation of various TaskTypes + */ +@ExperimentalApi +public abstract class TaskParams { + + /** + * Default constructor + */ + public TaskParams() {} +} diff --git a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskType.java b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/TaskType.java similarity index 90% rename from libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskType.java rename to libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/TaskType.java index 8bbdfcbc0e42e..60bda87388ff9 100644 --- a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskType.java +++ b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/TaskType.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.offline_tasks; +package org.opensearch.offline_tasks.task; /** * Enum for task type diff --git a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/package-info.java b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/package-info.java similarity index 86% rename from libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/package-info.java rename to libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/package-info.java index d27d75762478d..9615d2918b40c 100644 --- a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/package-info.java +++ b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/task/package-info.java @@ -7,6 +7,6 @@ */ /** - * Contains telemetry related classes + * Contains tasks related classes */ package org.opensearch.offline_tasks; diff --git a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/worker/TaskWorker.java b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/worker/TaskWorker.java new file mode 100644 index 0000000000000..d197424e95331 --- /dev/null +++ b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/worker/TaskWorker.java @@ -0,0 +1,31 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.offline_tasks.worker; + +import org.opensearch.common.annotation.ExperimentalApi; +import org.opensearch.offline_tasks.task.Task; +import org.opensearch.offline_tasks.task.TaskParams; + +/** + * Task Worker that executes the Task + * + * @opensearch.experimental + */ +@ExperimentalApi +public interface TaskWorker { + + /** + * Execute the Task + * + * @param task Task to be execute + * @param taskParams TaskParams to be used while executing the task + */ + void executeTask(Task task, TaskParams taskParams); + +} diff --git a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/worker/package-info.java b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/worker/package-info.java new file mode 100644 index 0000000000000..998b5c6018358 --- /dev/null +++ b/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/worker/package-info.java @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** + * Contains task worker related classes + */ +package org.opensearch.offline_tasks.worker; diff --git a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskParams.java b/libs/offline-tasks/src/test/java/org/opensearch/offline_tasks/TaskClientTest.java similarity index 68% rename from libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskParams.java rename to libs/offline-tasks/src/test/java/org/opensearch/offline_tasks/TaskClientTest.java index e33712f0a8377..fb131604a50f1 100644 --- a/libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskParams.java +++ b/libs/offline-tasks/src/test/java/org/opensearch/offline_tasks/TaskClientTest.java @@ -8,8 +8,6 @@ package org.opensearch.offline_tasks; -/** - * Base class for all TaskParams implementation of various TaskTypes - */ -public abstract class TaskParams { +public class TaskClientTest { + public TaskClientTest() {} }