-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Add a transport action to get the features of a node #110645
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.node.features; | ||
|
||
import org.elasticsearch.action.support.nodes.BaseNodeResponse; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
import java.util.Set; | ||
|
||
public class NodeFeatures extends BaseNodeResponse { | ||
|
||
private final Set<String> features; | ||
|
||
public NodeFeatures(StreamInput in) throws IOException { | ||
super(in); | ||
features = in.readCollectionAsImmutableSet(StreamInput::readString); | ||
} | ||
|
||
public NodeFeatures(Set<String> features, DiscoveryNode node) { | ||
super(node); | ||
this.features = features; | ||
} | ||
|
||
public Set<String> nodeFeatures() { | ||
return features; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeCollection(features, StreamOutput::writeString); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.node.features; | ||
|
||
import org.elasticsearch.action.support.nodes.BaseNodesRequest; | ||
|
||
public class NodesFeaturesRequest extends BaseNodesRequest<NodesFeaturesRequest> { | ||
public NodesFeaturesRequest(String... nodes) { | ||
super(nodes); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.node.features; | ||
|
||
import org.elasticsearch.action.FailedNodeException; | ||
import org.elasticsearch.action.support.TransportAction; | ||
import org.elasticsearch.action.support.nodes.BaseNodesResponse; | ||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.xcontent.ToXContentFragment; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class NodesFeaturesResponse extends BaseNodesResponse<NodeFeatures> implements ToXContentFragment { | ||
protected NodesFeaturesResponse(ClusterName clusterName, List<NodeFeatures> nodes, List<FailedNodeException> failures) { | ||
super(clusterName, nodes, failures); | ||
} | ||
|
||
@Override | ||
protected List<NodeFeatures> readNodesFrom(StreamInput in) throws IOException { | ||
return TransportAction.localOnly(); | ||
} | ||
|
||
@Override | ||
protected void writeNodesTo(StreamOutput out, List<NodeFeatures> nodes) throws IOException { | ||
TransportAction.localOnly(); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject("features"); | ||
for (var nf : getNodesMap().entrySet()) { | ||
builder.array(nf.getKey(), nf.getValue().nodeFeatures().toArray(String[]::new)); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.node.features; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.FailedNodeException; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.nodes.TransportNodesAction; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.core.UpdateForV9; | ||
import org.elasticsearch.features.FeatureService; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportRequest; | ||
import org.elasticsearch.transport.TransportService; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
@UpdateForV9 // this is not needed in v9+, all applicable versions support features | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I expect it might be possible for a v8.last node might try and invoke this action on a v9+ node, so we'd need to preserve this until v10 even if it's unused in the v9 codebase. |
||
public class TransportNodesFeaturesAction extends TransportNodesAction< | ||
NodesFeaturesRequest, | ||
NodesFeaturesResponse, | ||
TransportNodesFeaturesAction.NodeFeaturesRequest, | ||
NodeFeatures> { | ||
|
||
public static final ActionType<NodesFeaturesResponse> TYPE = new ActionType<>("cluster:monitor/nodes/features"); | ||
|
||
private final FeatureService featureService; | ||
|
||
@Inject | ||
public TransportNodesFeaturesAction( | ||
ThreadPool threadPool, | ||
ClusterService clusterService, | ||
TransportService transportService, | ||
ActionFilters actionFilters, | ||
FeatureService featureService | ||
) { | ||
super( | ||
TYPE.name(), | ||
clusterService, | ||
transportService, | ||
actionFilters, | ||
NodeFeaturesRequest::new, | ||
threadPool.executor(ThreadPool.Names.MANAGEMENT) | ||
); | ||
this.featureService = featureService; | ||
} | ||
|
||
@Override | ||
protected NodesFeaturesResponse newResponse( | ||
NodesFeaturesRequest request, | ||
List<NodeFeatures> responses, | ||
List<FailedNodeException> failures | ||
) { | ||
return new NodesFeaturesResponse(clusterService.getClusterName(), responses, failures); | ||
} | ||
|
||
@Override | ||
protected NodeFeaturesRequest newNodeRequest(NodesFeaturesRequest request) { | ||
return new NodeFeaturesRequest(); | ||
} | ||
|
||
@Override | ||
protected NodeFeatures newNodeResponse(StreamInput in, DiscoveryNode node) throws IOException { | ||
return new NodeFeatures(in); | ||
} | ||
|
||
@Override | ||
protected NodeFeatures nodeOperation(NodeFeaturesRequest request, Task task) { | ||
return new NodeFeatures(featureService.getNodeFeatures().keySet(), transportService.getLocalNode()); | ||
} | ||
|
||
public static class NodeFeaturesRequest extends TransportRequest { | ||
public NodeFeaturesRequest(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
public NodeFeaturesRequest() {} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,9 @@ | |
import org.elasticsearch.action.admin.cluster.node.capabilities.NodesCapabilitiesRequest; | ||
import org.elasticsearch.action.admin.cluster.node.capabilities.NodesCapabilitiesResponse; | ||
import org.elasticsearch.action.admin.cluster.node.capabilities.TransportNodesCapabilitiesAction; | ||
import org.elasticsearch.action.admin.cluster.node.features.NodesFeaturesRequest; | ||
import org.elasticsearch.action.admin.cluster.node.features.NodesFeaturesResponse; | ||
import org.elasticsearch.action.admin.cluster.node.features.TransportNodesFeaturesAction; | ||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; | ||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequestBuilder; | ||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; | ||
|
@@ -242,6 +245,14 @@ public void nodesCapabilities(final NodesCapabilitiesRequest request, final Acti | |
execute(TransportNodesCapabilitiesAction.TYPE, request, listener); | ||
} | ||
|
||
public ActionFuture<NodesFeaturesResponse> nodesFeatures(final NodesFeaturesRequest request) { | ||
return execute(TransportNodesFeaturesAction.TYPE, request); | ||
} | ||
|
||
public void nodesFeatures(final NodesFeaturesRequest request, final ActionListener<NodesFeaturesResponse> listener) { | ||
execute(TransportNodesFeaturesAction.TYPE, request, listener); | ||
} | ||
|
||
Comment on lines
+248
to
+255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather not add to this API, especially for an action which is so very specialized. Let's just invoke |
||
public void nodesUsage(final NodesUsageRequest request, final ActionListener<NodesUsageResponse> listener) { | ||
execute(TransportNodesUsageAction.TYPE, request, listener); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we implementing
toXContent
for this response? We won't be exposing it to REST clients will we?