Skip to content

Commit

Permalink
Add ?master_timeout to ent search APIs (elastic#108719)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveCTurner authored and parkertimmins committed May 17, 2024
1 parent c7c5ec2 commit 9599846
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ protected void masterOperation(

// Step 1: Fetch analytics collections count
GetAnalyticsCollectionAction.Request analyticsCollectionsCountRequest = new GetAnalyticsCollectionAction.Request(
request.masterNodeTimeout(),
new String[] { "*" }
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;
import java.util.Objects;

import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;

public class DeleteAnalyticsCollectionAction {

Expand All @@ -43,8 +41,8 @@ public Request(StreamInput in) throws IOException {
this.collectionName = in.readString();
}

public Request(String collectionName) {
super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT);
public Request(TimeValue masterNodeTimeout, String collectionName) {
super(masterNodeTimeout);
this.collectionName = collectionName;
}

Expand Down Expand Up @@ -89,19 +87,5 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.endObject();
return builder;
}

@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<Request, Void> PARSER = new ConstructingObjectParser<>(
"delete_analytics_collection_request",
p -> new Request((String) p[0])
);

static {
PARSER.declareString(constructorArg(), COLLECTION_NAME_FIELD);
}

public static Request parse(XContentParser parser) {
return PARSER.apply(parser, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,18 @@
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xpack.application.analytics.AnalyticsCollection;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;

public class GetAnalyticsCollectionAction {

public static final String NAME = "cluster:admin/xpack/application/analytics/get";
Expand All @@ -40,8 +37,8 @@ public static class Request extends MasterNodeReadRequest<Request> implements To

public static ParseField NAMES_FIELD = new ParseField("names");

public Request(String[] names) {
super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT);
public Request(TimeValue masterNodeTimeout, String[] names) {
super(masterNodeTimeout);
this.names = Objects.requireNonNull(names, "Collection names cannot be null");
}

Expand Down Expand Up @@ -78,19 +75,6 @@ public boolean equals(Object o) {
return Arrays.equals(this.names, request.names);
}

@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<Request, Void> PARSER = new ConstructingObjectParser<>(
"get_analytics_collection_request",
p -> new Request(((List<String>) p[0]).toArray(String[]::new))
);
static {
PARSER.declareStringArray(constructorArg(), NAMES_FIELD);
}

public static Request parse(XContentParser parser) {
return PARSER.apply(parser, null);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
import org.elasticsearch.action.support.master.MasterNodeRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;
import java.util.Objects;

import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;

public class PutAnalyticsCollectionAction {

Expand All @@ -42,8 +40,8 @@ public Request(StreamInput in) throws IOException {
this.name = in.readString();
}

public Request(String name) {
super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT);
public Request(TimeValue masterNodeTimeout, String name) {
super(masterNodeTimeout);
this.name = name;
}

Expand Down Expand Up @@ -81,19 +79,6 @@ public int hashCode() {
return Objects.hash(name);
}

private static final ConstructingObjectParser<Request, String> PARSER = new ConstructingObjectParser<>(
"put_analytics_collection_request",
false,
(p) -> new Request((String) p[0])
);
static {
PARSER.declareString(constructorArg(), NAME_FIELD);
}

public static Request parse(XContentParser parser) {
return PARSER.apply(parser, null);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
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.license.XPackLicenseState;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestUtils;
import org.elasticsearch.rest.Scope;
import org.elasticsearch.rest.ServerlessScope;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand Down Expand Up @@ -40,7 +41,10 @@ public List<Route> routes() {

@Override
protected RestChannelConsumer innerPrepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
DeleteAnalyticsCollectionAction.Request request = new DeleteAnalyticsCollectionAction.Request(restRequest.param("collection_name"));
DeleteAnalyticsCollectionAction.Request request = new DeleteAnalyticsCollectionAction.Request(
RestUtils.getMasterNodeTimeout(restRequest),
restRequest.param("collection_name")
);
return channel -> client.execute(DeleteAnalyticsCollectionAction.INSTANCE, request, new RestToXContentListener<>(channel));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestUtils;
import org.elasticsearch.rest.Scope;
import org.elasticsearch.rest.ServerlessScope;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand Down Expand Up @@ -44,6 +45,7 @@ public List<Route> routes() {
@Override
protected RestChannelConsumer innerPrepareRequest(RestRequest restRequest, NodeClient client) {
GetAnalyticsCollectionAction.Request request = new GetAnalyticsCollectionAction.Request(
RestUtils.getMasterNodeTimeout(restRequest),
Strings.splitStringByCommaToArray(restRequest.param("collection_name"))
);
return channel -> client.execute(GetAnalyticsCollectionAction.INSTANCE, request, new RestToXContentListener<>(channel));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.rest.RestUtils;
import org.elasticsearch.rest.Scope;
import org.elasticsearch.rest.ServerlessScope;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand Down Expand Up @@ -41,7 +42,10 @@ public List<RestHandler.Route> routes() {

@Override
protected RestChannelConsumer innerPrepareRequest(RestRequest restRequest, NodeClient client) {
PutAnalyticsCollectionAction.Request request = new PutAnalyticsCollectionAction.Request(restRequest.param("collection_name"));
PutAnalyticsCollectionAction.Request request = new PutAnalyticsCollectionAction.Request(
RestUtils.getMasterNodeTimeout(restRequest),
restRequest.param("collection_name")
);
String location = routes().get(0).getPath().replace("{collection_name}", request.getName());
return channel -> client.execute(
PutAnalyticsCollectionAction.INSTANCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.TriFunction;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.client.NoOpClient;
Expand Down Expand Up @@ -400,7 +401,7 @@ private List<AnalyticsCollection> awaitGetAnalyticsCollections(
ClusterState clusterState,
String... collectionName
) throws Exception {
GetAnalyticsCollectionAction.Request request = new GetAnalyticsCollectionAction.Request(collectionName);
GetAnalyticsCollectionAction.Request request = new GetAnalyticsCollectionAction.Request(TimeValue.THIRTY_SECONDS, collectionName);
return new Executor<>(clusterState, analyticsCollectionService::getAnalyticsCollection).execute(request).getAnalyticsCollections();
}

Expand All @@ -409,7 +410,7 @@ private PutAnalyticsCollectionAction.Response awaitPutAnalyticsCollection(
ClusterState clusterState,
String collectionName
) throws Exception {
PutAnalyticsCollectionAction.Request request = new PutAnalyticsCollectionAction.Request(collectionName);
PutAnalyticsCollectionAction.Request request = new PutAnalyticsCollectionAction.Request(TimeValue.THIRTY_SECONDS, collectionName);
return new Executor<>(clusterState, analyticsCollectionService::putAnalyticsCollection).execute(request);
}

Expand All @@ -418,7 +419,10 @@ private AcknowledgedResponse awaitDeleteAnalyticsCollection(
ClusterState clusterState,
String collectionName
) throws Exception {
DeleteAnalyticsCollectionAction.Request request = new DeleteAnalyticsCollectionAction.Request(collectionName);
DeleteAnalyticsCollectionAction.Request request = new DeleteAnalyticsCollectionAction.Request(
TimeValue.THIRTY_SECONDS,
collectionName
);
return new Executor<>(clusterState, analyticsCollectionService::deleteAnalyticsCollection).execute(request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@

import org.elasticsearch.TransportVersion;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xpack.core.ml.AbstractBWCSerializationTestCase;

import java.io.IOException;

import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
import static org.elasticsearch.xpack.application.analytics.action.DeleteAnalyticsCollectionAction.Request.COLLECTION_NAME_FIELD;

public class DeleteAnalyticsCollectionRequestBWCSerializingTests extends AbstractBWCSerializationTestCase<
DeleteAnalyticsCollectionAction.Request> {

Expand All @@ -24,7 +29,7 @@ protected Writeable.Reader<DeleteAnalyticsCollectionAction.Request> instanceRead

@Override
protected DeleteAnalyticsCollectionAction.Request createTestInstance() {
return new DeleteAnalyticsCollectionAction.Request(randomIdentifier());
return new DeleteAnalyticsCollectionAction.Request(TimeValue.THIRTY_SECONDS, randomIdentifier());
}

@Override
Expand All @@ -34,14 +39,24 @@ protected DeleteAnalyticsCollectionAction.Request mutateInstance(DeleteAnalytics

@Override
protected DeleteAnalyticsCollectionAction.Request doParseInstance(XContentParser parser) throws IOException {
return DeleteAnalyticsCollectionAction.Request.parse(parser);
return PARSER.apply(parser, null);
}

@Override
protected DeleteAnalyticsCollectionAction.Request mutateInstanceForVersion(
DeleteAnalyticsCollectionAction.Request instance,
TransportVersion version
) {
return new DeleteAnalyticsCollectionAction.Request(instance.getCollectionName());
return new DeleteAnalyticsCollectionAction.Request(TimeValue.THIRTY_SECONDS, instance.getCollectionName());
}

private static final ConstructingObjectParser<DeleteAnalyticsCollectionAction.Request, Void> PARSER = new ConstructingObjectParser<>(
"delete_analytics_collection_request",
p -> new DeleteAnalyticsCollectionAction.Request(TimeValue.THIRTY_SECONDS, (String) p[0])
);

static {
PARSER.declareString(constructorArg(), COLLECTION_NAME_FIELD);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@

import org.elasticsearch.TransportVersion;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xpack.core.ml.AbstractBWCSerializationTestCase;

import java.io.IOException;
import java.util.List;

import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
import static org.elasticsearch.xpack.application.analytics.action.GetAnalyticsCollectionAction.Request.NAMES_FIELD;

public class GetAnalyticsCollectionRequestBWCSerializingTests extends AbstractBWCSerializationTestCase<
GetAnalyticsCollectionAction.Request> {
Expand All @@ -24,7 +30,7 @@ protected Writeable.Reader<GetAnalyticsCollectionAction.Request> instanceReader(

@Override
protected GetAnalyticsCollectionAction.Request createTestInstance() {
return new GetAnalyticsCollectionAction.Request(new String[] { randomIdentifier() });
return new GetAnalyticsCollectionAction.Request(TimeValue.THIRTY_SECONDS, new String[] { randomIdentifier() });
}

@Override
Expand All @@ -34,14 +40,23 @@ protected GetAnalyticsCollectionAction.Request mutateInstance(GetAnalyticsCollec

@Override
protected GetAnalyticsCollectionAction.Request doParseInstance(XContentParser parser) throws IOException {
return GetAnalyticsCollectionAction.Request.parse(parser);
return PARSER.apply(parser, null);
}

@Override
protected GetAnalyticsCollectionAction.Request mutateInstanceForVersion(
GetAnalyticsCollectionAction.Request instance,
TransportVersion version
) {
return new GetAnalyticsCollectionAction.Request(instance.getNames());
return new GetAnalyticsCollectionAction.Request(TimeValue.THIRTY_SECONDS, instance.getNames());
}

@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<GetAnalyticsCollectionAction.Request, Void> PARSER = new ConstructingObjectParser<>(
"get_analytics_collection_request",
p -> new GetAnalyticsCollectionAction.Request(TimeValue.THIRTY_SECONDS, ((List<String>) p[0]).toArray(String[]::new))
);
static {
PARSER.declareStringArray(constructorArg(), NAMES_FIELD);
}
}

0 comments on commit 9599846

Please sign in to comment.