Skip to content

Commit

Permalink
[Offline Nodes] Adds new library offline tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxpi committed May 7, 2024
1 parent 7c5739b commit a444dd6
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 0 deletions.
25 changes: 25 additions & 0 deletions libs/offline-tasks/build.gradle
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'
}
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;
}
}
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);
}
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;
}
}
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 {
}
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
}
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;

0 comments on commit a444dd6

Please sign in to comment.