Skip to content

Add ?master_timeout to POST /_ilm/migrate_to_data_tiers #120883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/120883.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 120883
summary: Add `?master_timeout` to `POST /_ilm/migrate_to_data_tiers`
area: Indices APIs
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
]
},
"params": {
"master_timeout":{
"type":"time",
"description":"Explicit operation timeout for connection to master node"
},
"dry_run": {
"type": "boolean",
"description": "If set to true it will simulate the migration, providing a way to retrieve the ILM policies and indices that need to be migrated. The default is false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.XContentParser;
Expand All @@ -23,11 +24,14 @@ public class MigrateToDataTiersRequest extends AcknowledgedRequest<MigrateToData
private static final ParseField LEGACY_TEMPLATE_TO_DELETE = new ParseField("legacy_template_to_delete");
private static final ParseField NODE_ATTRIBUTE_NAME = new ParseField("node_attribute");

@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<MigrateToDataTiersRequest, Void> PARSER = new ConstructingObjectParser<>(
public interface Factory {
MigrateToDataTiersRequest create(@Nullable String legacyTemplateToDelete, @Nullable String nodeAttributeName);
}

public static final ConstructingObjectParser<MigrateToDataTiersRequest, Factory> PARSER = new ConstructingObjectParser<>(
"index_template",
false,
a -> new MigrateToDataTiersRequest((String) a[0], (String) a[1])
(a, factory) -> factory.create((String) a[0], (String) a[1])
);

static {
Expand All @@ -48,20 +52,20 @@ public class MigrateToDataTiersRequest extends AcknowledgedRequest<MigrateToData
private final String legacyTemplateToDelete;
private boolean dryRun = false;

public static MigrateToDataTiersRequest parse(XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
public static MigrateToDataTiersRequest parse(Factory factory, XContentParser parser) throws IOException {
return PARSER.parse(parser, factory);
}

public MigrateToDataTiersRequest(@Nullable String legacyTemplateToDelete, @Nullable String nodeAttributeName) {
super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT, DEFAULT_ACK_TIMEOUT);
public MigrateToDataTiersRequest(
TimeValue masterNodeTimeout,
@Nullable String legacyTemplateToDelete,
@Nullable String nodeAttributeName
) {
super(masterNodeTimeout, DEFAULT_ACK_TIMEOUT);
this.legacyTemplateToDelete = legacyTemplateToDelete;
this.nodeAttributeName = nodeAttributeName;
}

public MigrateToDataTiersRequest() {
this(null, null);
}

public MigrateToDataTiersRequest(StreamInput in) throws IOException {
super(in);
dryRun = in.readBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected Writeable.Reader<MigrateToDataTiersRequest> instanceReader() {

@Override
protected MigrateToDataTiersRequest createTestInstance() {
return new MigrateToDataTiersRequest(randomAlphaOfLength(10), randomAlphaOfLength(10));
return new MigrateToDataTiersRequest(TEST_REQUEST_TIMEOUT, randomAlphaOfLength(10), randomAlphaOfLength(10));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestUtils;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.xpack.cluster.action.MigrateToDataTiersAction;
import org.elasticsearch.xpack.cluster.action.MigrateToDataTiersRequest;
Expand All @@ -33,13 +34,21 @@ public List<Route> routes() {

@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
MigrateToDataTiersRequest migrateRequest;
final var masterNodeTimeout = RestUtils.getMasterNodeTimeout(request);
final MigrateToDataTiersRequest migrateRequest;
if (request.hasContent()) {
try (var parser = request.contentParser()) {
migrateRequest = MigrateToDataTiersRequest.parse(parser);
migrateRequest = MigrateToDataTiersRequest.parse(
(legacyTemplateToDelete, nodeAttributeName) -> new MigrateToDataTiersRequest(
masterNodeTimeout,
legacyTemplateToDelete,
nodeAttributeName
),
parser
);
}
} else {
migrateRequest = new MigrateToDataTiersRequest();
migrateRequest = new MigrateToDataTiersRequest(masterNodeTimeout, null, null);
}
migrateRequest.setDryRun(request.paramAsBoolean("dry_run", false));
return channel -> client.execute(MigrateToDataTiersAction.INSTANCE, migrateRequest, new RestToXContentListener<>(channel));
Expand Down