forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] Adding get migration reindex status (elastic#118267) (elastic#1…
…18361) * Adding get migration reindex status (elastic#118267) This adds a new transport action to get the status of a migration reindex (started via the API at elastic#118109), and a new rest action to use it. The rest action accepts the data stream or index name, and returns the status. For example if the reindex task exists for data stream `my-data-stream`: ``` GET /_migration/reindex/my-data-stream/_status?pretty ``` returns ``` { "start_time" : 1733519098570, "complete" : true, "total_indices" : 1, "total_indices_requiring_upgrade" : 0, "successes" : 0, "in_progress" : 0, "pending" : 0, "errors" : [ ] } ``` If a reindex task does not exist: ``` GET _migration/reindex/my-data-stream/_status?pretty ``` Then a 404 is returned: ``` { "error" : { "root_cause" : [ { "type" : "resource_not_found_exception", "reason" : "No migration reindex status found for [my-data-stream]" } ], "type" : "resource_not_found_exception", "reason" : "No migration reindex status found for [my-data-stream]" }, "status" : 404 } ``` * adding migration reindex actions to OperatorPrivilegesIT
- Loading branch information
Showing
13 changed files
with
595 additions
and
9 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,5 @@ | ||
pr: 118267 | ||
summary: Adding get migration reindex status | ||
area: Data streams | ||
type: enhancement | ||
issues: [] |
31 changes: 31 additions & 0 deletions
31
rest-api-spec/src/main/resources/rest-api-spec/api/migrate.get_reindex_status.json
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,31 @@ | ||
{ | ||
"migrate.get_reindex_status":{ | ||
"documentation":{ | ||
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/data-stream-reindex.html", | ||
"description":"This API returns the status of a migration reindex attempt for a data stream or index" | ||
}, | ||
"stability":"experimental", | ||
"visibility":"private", | ||
"headers":{ | ||
"accept": [ "application/json"], | ||
"content_type": ["application/json"] | ||
}, | ||
"url":{ | ||
"paths":[ | ||
{ | ||
"path":"/_migration/reindex/{index}/_status", | ||
"methods":[ | ||
"GET" | ||
], | ||
"parts":{ | ||
"index":{ | ||
"type":"string", | ||
"description":"The index or data stream name" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
|
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
143 changes: 143 additions & 0 deletions
143
...src/main/java/org/elasticsearch/xpack/migrate/action/GetMigrationReindexStatusAction.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,143 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.migrate.action; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.IndicesRequest; | ||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.tasks.TaskResult; | ||
import org.elasticsearch.xcontent.ToXContentObject; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class GetMigrationReindexStatusAction extends ActionType<GetMigrationReindexStatusAction.Response> { | ||
|
||
public static final GetMigrationReindexStatusAction INSTANCE = new GetMigrationReindexStatusAction(); | ||
public static final String NAME = "indices:admin/migration/reindex_status"; | ||
|
||
public GetMigrationReindexStatusAction() { | ||
super(NAME); | ||
} | ||
|
||
public static class Response extends ActionResponse implements ToXContentObject { | ||
private final TaskResult task; | ||
|
||
public Response(TaskResult task) { | ||
this.task = requireNonNull(task, "task is required"); | ||
} | ||
|
||
public Response(StreamInput in) throws IOException { | ||
super(in); | ||
task = in.readOptionalWriteable(TaskResult::new); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeOptionalWriteable(task); | ||
} | ||
|
||
/** | ||
* Get the actual result of the fetch. | ||
*/ | ||
public TaskResult getTask() { | ||
return task; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
Task.Status status = task.getTask().status(); | ||
if (status != null) { | ||
task.getTask().status().toXContent(builder, params); | ||
} | ||
return builder; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(task); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other instanceof Response && task.equals(((Response) other).task); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String toString = Strings.toString(this); | ||
return toString.isEmpty() ? "unavailable" : toString; | ||
} | ||
|
||
} | ||
|
||
public static class Request extends ActionRequest implements IndicesRequest { | ||
private final String index; | ||
|
||
public Request(String index) { | ||
super(); | ||
this.index = index; | ||
} | ||
|
||
public Request(StreamInput in) throws IOException { | ||
super(in); | ||
this.index = in.readString(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeString(index); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
public String getIndex() { | ||
return index; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(index); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other instanceof Request && index.equals(((Request) other).index); | ||
} | ||
|
||
public Request nodeRequest(String thisNodeId, long thisTaskId) { | ||
Request copy = new Request(index); | ||
copy.setParentTask(thisNodeId, thisTaskId); | ||
return copy; | ||
} | ||
|
||
@Override | ||
public String[] indices() { | ||
return new String[] { index }; | ||
} | ||
|
||
@Override | ||
public IndicesOptions indicesOptions() { | ||
return IndicesOptions.strictSingleIndexNoExpandForbidClosed(); | ||
} | ||
} | ||
} |
Oops, something went wrong.