Skip to content
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

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions server/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
exports org.elasticsearch.action.admin.cluster.health;
exports org.elasticsearch.action.admin.cluster.migration;
exports org.elasticsearch.action.admin.cluster.node.capabilities;
exports org.elasticsearch.action.admin.cluster.node.features;
exports org.elasticsearch.action.admin.cluster.node.hotthreads;
exports org.elasticsearch.action.admin.cluster.node.info;
exports org.elasticsearch.action.admin.cluster.node.reload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.elasticsearch.action.admin.cluster.migration.TransportGetFeatureUpgradeStatusAction;
import org.elasticsearch.action.admin.cluster.migration.TransportPostFeatureUpgradeAction;
import org.elasticsearch.action.admin.cluster.node.capabilities.TransportNodesCapabilitiesAction;
import org.elasticsearch.action.admin.cluster.node.features.TransportNodesFeaturesAction;
import org.elasticsearch.action.admin.cluster.node.hotthreads.TransportNodesHotThreadsAction;
import org.elasticsearch.action.admin.cluster.node.info.TransportNodesInfoAction;
import org.elasticsearch.action.admin.cluster.node.reload.TransportNodesReloadSecureSettingsAction;
Expand Down Expand Up @@ -621,6 +622,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(TransportNodesInfoAction.TYPE, TransportNodesInfoAction.class);
actions.register(TransportRemoteInfoAction.TYPE, TransportRemoteInfoAction.class);
actions.register(TransportNodesCapabilitiesAction.TYPE, TransportNodesCapabilitiesAction.class);
actions.register(TransportNodesFeaturesAction.TYPE, TransportNodesFeaturesAction.class);
actions.register(RemoteClusterNodesAction.TYPE, RemoteClusterNodesAction.TransportAction.class);
actions.register(TransportNodesStatsAction.TYPE, TransportNodesStatsAction.class);
actions.register(TransportNodesUsageAction.TYPE, TransportNodesUsageAction.class);
Expand Down
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 {
Copy link
Contributor

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?

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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 Client#execute directly as needed.

public void nodesUsage(final NodesUsageRequest request, final ActionListener<NodesUsageResponse> listener) {
execute(TransportNodesUsageAction.TYPE, request, listener);
}
Expand Down