-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create task in rest action and give parent child corelation.
- Loading branch information
Showing
21 changed files
with
420 additions
and
14 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
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
64 changes: 64 additions & 0 deletions
64
server/src/main/java/org/opensearch/action/admin/cluster/node/tasks/CreateTaskRequest.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,64 @@ | ||
/* | ||
* 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.action.admin.cluster.node.tasks; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.common.annotation.PublicApi; | ||
import org.opensearch.common.unit.TimeValue; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.tasks.TaskId; | ||
import org.opensearch.rest.action.admin.cluster.ClusterTask; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* Creates a new task. | ||
* | ||
* @opensearch.api | ||
*/ | ||
@PublicApi(since = "1.0.0") | ||
public class CreateTaskRequest extends ActionRequest { | ||
|
||
private TimeValue cancelAfterTimeInterval = null; | ||
private String actionName; | ||
|
||
public CreateTaskRequest() {} | ||
|
||
public CreateTaskRequest(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public ClusterTask createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) { | ||
return new ClusterTask(id, type, action, parentTaskId, headers, cancelAfterTimeInterval); | ||
} | ||
|
||
public void setCancelAfterTimeInterval(TimeValue cancelAfterTimeInterval) { | ||
this.cancelAfterTimeInterval = cancelAfterTimeInterval; | ||
} | ||
|
||
public TimeValue getCancelAfterTimeInterval() { | ||
return cancelAfterTimeInterval; | ||
} | ||
|
||
public void setActionName(String actionName) { | ||
this.actionName = actionName; | ||
} | ||
|
||
public String getActionName() { | ||
return this.actionName; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
server/src/main/java/org/opensearch/action/admin/cluster/node/tasks/CreateTaskResponse.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,48 @@ | ||
/* | ||
* 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.action.admin.cluster.node.tasks; | ||
|
||
import org.opensearch.common.annotation.PublicApi; | ||
import org.opensearch.core.action.ActionResponse; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
import org.opensearch.tasks.Task; | ||
import org.opensearch.tasks.TaskResult; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Returns a new task. | ||
* | ||
* @opensearch.api | ||
*/ | ||
@PublicApi(since = "1.0.0") | ||
public class CreateTaskResponse extends ActionResponse { | ||
|
||
private final Task task; | ||
|
||
public CreateTaskResponse(Task task) { | ||
this.task = task; | ||
} | ||
|
||
// public CreateTaskResponse(StreamInput in) throws IOException { | ||
// super(in); | ||
//// task = in.readOptionalWriteable(Task); | ||
// } | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeOptionalWriteable((Writeable) task); | ||
} | ||
|
||
public Task getTask() { | ||
return task; | ||
} | ||
} |
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
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
114 changes: 114 additions & 0 deletions
114
server/src/main/java/org/opensearch/action/admin/cluster/shards/TransportShardsAction.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,114 @@ | ||
/* | ||
* 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.action.admin.cluster.shards; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.admin.cluster.node.tasks.CreateTaskRequest; | ||
import org.opensearch.action.admin.cluster.node.tasks.CreateTaskResponse; | ||
import org.opensearch.action.admin.cluster.node.tasks.get.GetTaskAction; | ||
import org.opensearch.action.admin.cluster.node.tasks.get.GetTaskRequest; | ||
import org.opensearch.action.admin.cluster.node.tasks.get.GetTaskResponse; | ||
import org.opensearch.action.admin.cluster.state.ClusterStateRequest; | ||
import org.opensearch.action.admin.cluster.state.ClusterStateResponse; | ||
import org.opensearch.action.admin.indices.stats.IndicesStatsRequest; | ||
import org.opensearch.action.admin.indices.stats.IndicesStatsResponse; | ||
import org.opensearch.action.search.SearchRequest; | ||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.action.search.TransportSearchAction; | ||
import org.opensearch.action.support.ActionFilters; | ||
import org.opensearch.action.support.HandledTransportAction; | ||
import org.opensearch.action.support.clustermanager.ClusterManagerNodeRequest; | ||
import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.client.OriginSettingClient; | ||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.common.Table; | ||
import org.opensearch.common.inject.Inject; | ||
import org.opensearch.common.logging.DeprecationLogger; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.action.ActionResponse; | ||
import org.opensearch.core.common.Strings; | ||
import org.opensearch.core.tasks.TaskId; | ||
import org.opensearch.core.xcontent.NamedXContentRegistry; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.rest.RestResponse; | ||
import org.opensearch.rest.action.RestActionListener; | ||
import org.opensearch.rest.action.RestResponseListener; | ||
import org.opensearch.rest.action.cat.AbstractCatAction; | ||
import org.opensearch.rest.action.cat.RestShardsAction; | ||
import org.opensearch.rest.action.cat.RestTable; | ||
import org.opensearch.tasks.*; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.transport.TransportService; | ||
|
||
import static org.opensearch.rest.BaseRestHandler.parseDeprecatedMasterTimeoutParameter; | ||
|
||
public class TransportShardsAction extends HandledTransportAction<GetTaskRequest, GetTaskResponse> { | ||
|
||
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(TransportShardsAction.class); | ||
private final TransportService transportService; | ||
private final ClusterService clusterService; | ||
private final ThreadPool threadPool; | ||
// private final ActionFilters actionFilter; | ||
private final NodeClient client; | ||
|
||
@Inject | ||
public TransportShardsAction( | ||
NodeClient client, | ||
ThreadPool threadPool, | ||
TransportService transportService, | ||
ActionFilters actionFilters, | ||
ClusterService clusterService | ||
) { | ||
super(GetTaskAction.NAME, transportService, actionFilters, GetTaskRequest::new); | ||
this.threadPool = threadPool; | ||
this.clusterService = clusterService; | ||
this.transportService = transportService; | ||
this.client = client; | ||
// this.client = new OriginSettingClient(client, GetTaskAction.TASKS_ORIGIN); | ||
} | ||
|
||
// @Override | ||
// protected void doExecute(Task task, final Request request, ActionListener<Task> listener) { | ||
// executeRequest(task, request, listener); | ||
// } | ||
|
||
@Override | ||
protected void doExecute(Task task, GetTaskRequest request, ActionListener<GetTaskResponse> listener) { | ||
Task new_task = transportService.getTaskManager().register("transport", "Admin-action", request); | ||
TaskResult result = new TaskResult(false, new TaskInfo(new TaskId(clusterService.localNode().getId(), new_task.getId()), new_task.getType(), new_task.getAction(), new_task.getDescription(), new_task.getStatus(), new_task.getStartTime(), new_task.getStartTimeNanos(), true, false, new_task.getParentTaskId(), null, null)); | ||
GetTaskResponse response = new GetTaskResponse(result); | ||
// new_task.getCancellationTimeout() | ||
response.setNewTask(new_task); | ||
listener.onResponse(response); | ||
|
||
} | ||
|
||
// @Override | ||
// protected void doExecute(Task task, CreateTaskRequest request, ActionListener<CreateTaskResponse> listener) { | ||
// Task new_task = transportService.getTaskManager().register("transport", "Admin-action", request); | ||
// TaskResult result = new TaskResult(false, new TaskInfo(new TaskId(clusterService.localNode().getId(), new_task.getId()), new_task.getType(), new_task.getAction(), new_task.getDescription(), new_task.getStatus(), new_task.getStartTime(), new_task.getStartTimeNanos(), true, false, new_task.getParentTaskId(), null, null)); | ||
//// GetTaskResponse response = new GetTaskResponse(result); | ||
// CreateTaskResponse response = new CreateTaskResponse(new_task); | ||
// listener.onResponse(response); | ||
// } | ||
|
||
// private void executeRequest( | ||
// Task task, | ||
// Request request, | ||
// ActionListener<Task> originalListener | ||
// ) { | ||
// Task new_task = transportService.getTaskManager().register("transport", "Admin-action", request); | ||
// originalListener.onResponse(new_task); | ||
// } | ||
|
||
|
||
|
||
} |
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
23 changes: 23 additions & 0 deletions
23
server/src/main/java/org/opensearch/action/admin/cluster/state/ShardsAction.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,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.action.admin.cluster.state; | ||
|
||
import org.opensearch.action.ActionType; | ||
import org.opensearch.action.admin.cluster.node.tasks.CreateTaskResponse; | ||
import org.opensearch.action.admin.cluster.node.tasks.get.GetTaskResponse; | ||
import org.opensearch.tasks.Task; | ||
|
||
public class ShardsAction extends ActionType<GetTaskResponse> { | ||
public static final ShardsAction INSTANCE = new ShardsAction(); | ||
public static final String NAME = "cluster:monitor/create/task"; | ||
|
||
private ShardsAction() { | ||
super(NAME, GetTaskResponse::new); | ||
} | ||
} |
Oops, something went wrong.