-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Offline Nodes] Adds new library offline tasks
- Loading branch information
Showing
7 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
dependencies { | ||
api project(':libs:opensearch-common') | ||
|
||
testImplementation "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}" | ||
testImplementation "junit:junit:${versions.junit}" | ||
testImplementation "org.hamcrest:hamcrest:${versions.hamcrest}" | ||
testImplementation(project(":test:framework")) { | ||
exclude group: 'org.opensearch', module: 'opensearch-offline-tasks' | ||
} | ||
} | ||
|
||
tasks.named('forbiddenApisMain').configure { | ||
replaceSignatureFiles 'jdk-signatures' | ||
} |
43 changes: 43 additions & 0 deletions
43
libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/Task.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* A Background Task to be run on Offline Node. | ||
*/ | ||
public class Task { | ||
|
||
/** | ||
* Task identifier used to uniquely identify a Task | ||
*/ | ||
private TaskId taskId; | ||
|
||
/** | ||
* Various params to used for Task execution | ||
*/ | ||
private TaskParams params; | ||
|
||
/** | ||
* Type/Category of the Task | ||
*/ | ||
private TaskType taskType; | ||
|
||
/** | ||
* Constructor for Task | ||
* | ||
* @param taskId Task identifier | ||
* @param params Task Params | ||
* @param taskType Task Type | ||
*/ | ||
public Task(TaskId taskId, TaskParams params, TaskType taskType) { | ||
this.taskId = taskId; | ||
this.params = params; | ||
this.taskType = taskType; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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; | ||
|
||
import org.opensearch.common.annotation.ExperimentalApi; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Client used to interact with Task Store/Queue | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
@ExperimentalApi | ||
public interface TaskClient { | ||
|
||
/** | ||
* Submit a new task to Task Store/Queue | ||
* | ||
* @param task | ||
*/ | ||
void submitTask(Task task); | ||
|
||
/** | ||
* Claim task from Task Store/Queue. This ensure no 2 nodes work on the same task. | ||
* | ||
* @param taskId | ||
*/ | ||
void claimTask(TaskId taskId); | ||
|
||
/** | ||
* Get task from Task Store/Queue | ||
* | ||
* @param taskId | ||
* @return | ||
*/ | ||
Task getTask(TaskId taskId); | ||
|
||
/** | ||
* Update task in Task Store/Queue | ||
* | ||
* @param task | ||
* @return | ||
*/ | ||
Task updateTask(Task task); | ||
|
||
/** | ||
* Mark task as cancelled | ||
* | ||
* @param taskId | ||
*/ | ||
void cancelTask(TaskId taskId); | ||
|
||
/** | ||
* List all unassigned tasks | ||
* | ||
* @return | ||
*/ | ||
List<Task> getUnassignedTasks(); | ||
|
||
/** | ||
* List all active tasks | ||
* | ||
* @return | ||
*/ | ||
List<Task> getActiveTasks(); | ||
|
||
/** | ||
* List all completed tasks | ||
* | ||
* @return | ||
*/ | ||
List<Task> getCompletedTasks(); | ||
|
||
/** | ||
* Sends task heart beat to Task Store/Queue | ||
* | ||
* @param taskId | ||
* @param timestamp | ||
*/ | ||
void sendTaskHeartbeat(TaskId taskId, long timestamp); | ||
} |
24 changes: 24 additions & 0 deletions
24
libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Class encapsulating Task id | ||
*/ | ||
public class TaskId { | ||
|
||
/** | ||
* Id of the Task | ||
*/ | ||
String id; | ||
|
||
public TaskId(String id) { | ||
this.id = id; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Base class for all TaskParams implementation of various TaskTypes | ||
*/ | ||
public abstract class TaskParams { | ||
} |
24 changes: 24 additions & 0 deletions
24
libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/TaskType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Enum for task type | ||
*/ | ||
public enum TaskType { | ||
/** | ||
* For all segment merge related tasks | ||
*/ | ||
MERGE, | ||
|
||
/** | ||
* For all snapshot related tasks | ||
*/ | ||
SNAPSHOT | ||
} |
12 changes: 12 additions & 0 deletions
12
libs/offline-tasks/src/main/java/org/opensearch/offline_tasks/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 telemetry related classes | ||
*/ | ||
package org.opensearch.offline_tasks; |