Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion server/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@
provides org.elasticsearch.features.FeatureSpecification
with
org.elasticsearch.action.bulk.BulkFeatures,
org.elasticsearch.features.FeatureInfrastructureFeatures,
org.elasticsearch.features.InfrastructureFeatures,
org.elasticsearch.rest.action.admin.cluster.ClusterRerouteFeatures,
org.elasticsearch.index.mapper.MapperFeatures,
org.elasticsearch.index.IndexFeatures,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

import org.elasticsearch.action.support.nodes.BaseNodesRequest;
import org.elasticsearch.common.Strings;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.rest.RestRequest;

import java.util.Optional;
import java.util.Set;

public class NodesCapabilitiesRequest extends BaseNodesRequest {
Expand All @@ -22,7 +24,7 @@ public class NodesCapabilitiesRequest extends BaseNodesRequest {
private String path = "/";
private Set<String> parameters = Set.of();
private Set<String> capabilities = Set.of();
private RestApiVersion restApiVersion = RestApiVersion.current();
private @Nullable RestApiVersion restApiVersion;

public NodesCapabilitiesRequest() {
// send to all nodes
Expand Down Expand Up @@ -75,7 +77,7 @@ public NodesCapabilitiesRequest restApiVersion(RestApiVersion restApiVersion) {
return this;
}

public RestApiVersion restApiVersion() {
return restApiVersion;
public Optional<RestApiVersion> restApiVersion() {
return Optional.ofNullable(restApiVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.core.UpdateForV10;
import org.elasticsearch.features.FeatureService;
import org.elasticsearch.features.InfrastructureFeatures;
import org.elasticsearch.injection.guice.Inject;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
Expand All @@ -41,14 +43,16 @@ public class TransportNodesCapabilitiesAction extends TransportNodesAction<
public static final ActionType<NodesCapabilitiesResponse> TYPE = new ActionType<>("cluster:monitor/nodes/capabilities");

private final RestController restController;
private final FeatureService featureService;

@Inject
public TransportNodesCapabilitiesAction(
ThreadPool threadPool,
ClusterService clusterService,
TransportService transportService,
ActionFilters actionFilters,
RestController restController
RestController restController,
FeatureService featureService
) {
super(
TYPE.name(),
Expand All @@ -59,6 +63,7 @@ public TransportNodesCapabilitiesAction(
threadPool.executor(ThreadPool.Names.MANAGEMENT)
);
this.restController = restController;
this.featureService = featureService;
}

@Override
Expand All @@ -72,13 +77,21 @@ protected NodesCapabilitiesResponse newResponse(

@Override
protected NodeCapabilitiesRequest newNodeRequest(NodesCapabilitiesRequest request) {
return new NodeCapabilitiesRequest(
request.method(),
request.path(),
request.parameters(),
request.capabilities(),
request.restApiVersion()
);
@UpdateForV10(owner = UpdateForV10.Owner.CORE_INFRA) // rather than v8/v9, this should handle v9/v10
RestApiVersion restVersion;
if (request.restApiVersion().isPresent()) {
// explicit version - just use it, and see what happens
restVersion = request.restApiVersion().get();
} else if (featureService.clusterHasFeature(clusterService.state(), InfrastructureFeatures.ELASTICSEARCH_V9)) {
restVersion = RestApiVersion.V_9; // every node is at least v9, so use that
} else {
// not all nodes are v9. v8 nodes do not understand v9 rest API, so query using v8.
// Capabilities can come and go, so it's ok for the response to change
// when the nodes change
restVersion = RestApiVersion.V_8;
}

return new NodeCapabilitiesRequest(request.method(), request.path(), request.parameters(), request.capabilities(), restVersion);
}

@Override
Expand Down Expand Up @@ -129,10 +142,6 @@ public NodeCapabilitiesRequest(
this.restApiVersion = restApiVersion;
}

@UpdateForV9(owner = UpdateForV9.Owner.CORE_INFRA) // 8.x blows up in a mixed cluster when trying to read RestApiVersion.forMajor(9)
// ./gradlew ":qa:mixed-cluster:v8.16.0#mixedClusterTest"
// -Dtests.class="org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT"
// -Dtests.method="test {p0=capabilities/10_basic/Capabilities API}"
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand All @@ -141,9 +150,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(path);
out.writeCollection(parameters, StreamOutput::writeString);
out.writeCollection(capabilities, StreamOutput::writeString);
// Fixme: lies! all lies!
out.writeVInt(8);
// out.writeVInt(restApiVersion.major);
out.writeVInt(restApiVersion.major);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@
import java.util.Set;

/**
* This class specifies features for the features functionality itself.
* This class specifies features for Elasticsearch infrastructure.
*/
public class FeatureInfrastructureFeatures implements FeatureSpecification {
public class InfrastructureFeatures implements FeatureSpecification {

public static final NodeFeature ELASTICSEARCH_V9 = new NodeFeature("es_v9");

@Override
public Set<NodeFeature> getFeatures() {
return Set.of(ELASTICSEARCH_V9);
}

@Override
public Set<NodeFeature> getTestFeatures() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
NodesCapabilitiesRequest r = requestNodes.method(RestRequest.Method.valueOf(request.param("method", "GET")))
.path(path)
.parameters(request.paramAsStringArray("parameters", Strings.EMPTY_ARRAY))
.capabilities(request.paramAsStringArray("capabilities", Strings.EMPTY_ARRAY))
.restApiVersion(request.getRestApiVersion());
.capabilities(request.paramAsStringArray("capabilities", Strings.EMPTY_ARRAY));
if (request.hasExplicitRestApiVersion()) {
r.restApiVersion(request.getRestApiVersion());
}

return channel -> client.admin().cluster().nodesCapabilities(r, new NodesResponseRestListener<>(channel));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#

org.elasticsearch.action.bulk.BulkFeatures
org.elasticsearch.features.FeatureInfrastructureFeatures
org.elasticsearch.features.InfrastructureFeatures
org.elasticsearch.rest.action.admin.cluster.ClusterRerouteFeatures
org.elasticsearch.index.IndexFeatures
org.elasticsearch.index.mapper.MapperFeatures
Expand Down