Skip to content

Commit

Permalink
Fixing nodes api response for protobuf
Browse files Browse the repository at this point in the history
Signed-off-by: Vacha Shah <[email protected]>
  • Loading branch information
VachaShah committed Jun 30, 2023
1 parent 21c1ab5 commit 3566241
Show file tree
Hide file tree
Showing 158 changed files with 3,756 additions and 2,947 deletions.
40 changes: 24 additions & 16 deletions server/src/main/java/org/opensearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.metadata.ProtobufIndexNameExpressionResolver;
import org.opensearch.cluster.node.DiscoveryNodes;
import org.opensearch.cluster.node.ProtobufDiscoveryNodes;
import org.opensearch.common.NamedRegistry;
import org.opensearch.common.inject.AbstractModule;
import org.opensearch.common.inject.TypeLiteral;
Expand Down Expand Up @@ -545,9 +544,11 @@ public ActionModule(
this.settingsFilter = settingsFilter;
this.actionPlugins = actionPlugins;
this.protobufIndexNameExpressionResolver = null;
this.protobufActionPlugins = new ArrayList<>();;
this.protobufActionPlugins = new ArrayList<>();
;
this.protobufActions = new HashMap<String, ProtobufActionPlugin.ActionHandler<?, ?>>();
this.protobufActionFilters = setupProtobufActionFilters(this.protobufActionPlugins);;
this.protobufActionFilters = setupProtobufActionFilters(this.protobufActionPlugins);
;
this.threadPool = threadPool;
actions = setupActions(actionPlugins);
actionFilters = setupActionFilters(actionPlugins);
Expand Down Expand Up @@ -646,7 +647,15 @@ public ActionModule(
actionPlugins.stream().flatMap(p -> p.indicesAliasesRequestValidators().stream()).collect(Collectors.toList())
);

restController = new RestController(headers, restWrapper, nodeClient, protobufRestWrapper, protobufNodeClient, circuitBreakerService, usageService);
restController = new RestController(
headers,
restWrapper,
nodeClient,
protobufRestWrapper,
protobufNodeClient,
circuitBreakerService,
usageService
);
}

public Map<String, ActionHandler<?, ?>> getActions() {
Expand Down Expand Up @@ -1106,17 +1115,17 @@ public void initProtobufRestHandlers() {
registerHandler.accept(new ProtobufRestNodesAction());

// for (ActionPlugin plugin : actionPlugins) {
// for (ProtobufActionPlugin handler : plugin.getRestHandlers(
// settings,
// restController,
// clusterSettings,
// indexScopedSettings,
// settingsFilter,
// indexNameExpressionResolver,
// nodesInCluster
// )) {
// registerHandler.accept(handler);
// }
// for (ProtobufActionPlugin handler : plugin.getRestHandlers(
// settings,
// restController,
// clusterSettings,
// indexScopedSettings,
// settingsFilter,
// indexNameExpressionResolver,
// nodesInCluster
// )) {
// registerHandler.accept(handler);
// }
// }
registerHandler.accept(new ProtobufRestCatAction(catActions));
}
Expand Down Expand Up @@ -1173,7 +1182,6 @@ protected void configure() {
// register dynamic ActionType -> transportAction Map used by NodeClient
bind(ProtobufDynamicActionRegistry.class).toInstance(protobufDynamicActionRegistry);


}

public ActionFilters getActionFilters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.opensearch.Build;
import org.opensearch.Version;
import org.opensearch.action.support.nodes.ProtobufBaseNodeResponse;
import org.opensearch.cluster.node.ProtobufDiscoveryNode;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.common.Nullable;
import org.opensearch.common.io.stream.ProtobufStreamInput;
import org.opensearch.common.io.stream.ProtobufStreamOutput;
Expand All @@ -27,7 +27,7 @@
import org.opensearch.http.ProtobufHttpInfo;
import org.opensearch.ingest.ProtobufIngestInfo;
import org.opensearch.monitor.jvm.JvmInfo;
import org.opensearch.monitor.jvm.ProtobufJvmInfo;
import org.opensearch.monitor.jvm.JvmInfo;
import org.opensearch.monitor.os.OsInfo;
import org.opensearch.monitor.os.ProtobufOsInfo;
import org.opensearch.monitor.process.ProtobufProcessInfo;
Expand Down Expand Up @@ -79,7 +79,7 @@ public ProtobufNodeInfo(CodedInputStream in) throws IOException {
}
addInfoIfNonNull(ProtobufOsInfo.class, protobufStreamInput.readOptionalWriteable(ProtobufOsInfo::new));
addInfoIfNonNull(ProtobufProcessInfo.class, protobufStreamInput.readOptionalWriteable(ProtobufProcessInfo::new));
addInfoIfNonNull(ProtobufJvmInfo.class, protobufStreamInput.readOptionalWriteable(ProtobufJvmInfo::new));
addInfoIfNonNull(JvmInfo.class, protobufStreamInput.readOptionalWriteable(JvmInfo::new));
addInfoIfNonNull(ProtobufThreadPoolInfo.class, protobufStreamInput.readOptionalWriteable(ProtobufThreadPoolInfo::new));
addInfoIfNonNull(ProtobufTransportInfo.class, protobufStreamInput.readOptionalWriteable(ProtobufTransportInfo::new));
addInfoIfNonNull(ProtobufHttpInfo.class, protobufStreamInput.readOptionalWriteable(ProtobufHttpInfo::new));
Expand All @@ -94,11 +94,11 @@ public ProtobufNodeInfo(CodedInputStream in) throws IOException {
public ProtobufNodeInfo(
Version version,
Build build,
ProtobufDiscoveryNode node,
DiscoveryNode node,
@Nullable Settings settings,
@Nullable ProtobufOsInfo os,
@Nullable ProtobufProcessInfo process,
@Nullable ProtobufJvmInfo jvm,
@Nullable JvmInfo jvm,
@Nullable ProtobufThreadPoolInfo threadPool,
@Nullable ProtobufTransportInfo transport,
@Nullable ProtobufHttpInfo http,
Expand All @@ -114,7 +114,7 @@ public ProtobufNodeInfo(
this.settings = settings;
addInfoIfNonNull(ProtobufOsInfo.class, os);
addInfoIfNonNull(ProtobufProcessInfo.class, process);
addInfoIfNonNull(ProtobufJvmInfo.class, jvm);
addInfoIfNonNull(JvmInfo.class, jvm);
addInfoIfNonNull(ProtobufThreadPoolInfo.class, threadPool);
addInfoIfNonNull(ProtobufTransportInfo.class, transport);
addInfoIfNonNull(ProtobufHttpInfo.class, http);
Expand Down Expand Up @@ -204,7 +204,7 @@ public void writeTo(CodedOutputStream out) throws IOException {
}
protobufStreamOutput.writeOptionalWriteable(getInfo(ProtobufOsInfo.class));
protobufStreamOutput.writeOptionalWriteable(getInfo(ProtobufProcessInfo.class));
protobufStreamOutput.writeOptionalWriteable(getInfo(ProtobufJvmInfo.class));
protobufStreamOutput.writeOptionalWriteable(getInfo(JvmInfo.class));
protobufStreamOutput.writeOptionalWriteable(getInfo(ProtobufThreadPoolInfo.class));
protobufStreamOutput.writeOptionalWriteable(getInfo(ProtobufTransportInfo.class));
protobufStreamOutput.writeOptionalWriteable(getInfo(ProtobufHttpInfo.class));
Expand All @@ -216,7 +216,7 @@ public void writeTo(CodedOutputStream out) throws IOException {
}
}

public static ProtobufNodeInfo.Builder builder(Version version, Build build, ProtobufDiscoveryNode node) {
public static ProtobufNodeInfo.Builder builder(Version version, Build build, DiscoveryNode node) {
return new Builder(version, build, node);
}

Expand All @@ -226,9 +226,9 @@ public static ProtobufNodeInfo.Builder builder(Version version, Build build, Pro
public static class Builder {
private final Version version;
private final Build build;
private final ProtobufDiscoveryNode node;
private final DiscoveryNode node;

private Builder(Version version, Build build, ProtobufDiscoveryNode node) {
private Builder(Version version, Build build, DiscoveryNode node) {
this.version = version;
this.build = build;
this.node = node;
Expand All @@ -237,7 +237,7 @@ private Builder(Version version, Build build, ProtobufDiscoveryNode node) {
private Settings settings;
private ProtobufOsInfo os;
private ProtobufProcessInfo process;
private ProtobufJvmInfo jvm;
private JvmInfo jvm;
private ProtobufThreadPoolInfo threadPool;
private ProtobufTransportInfo transport;
private ProtobufHttpInfo http;
Expand All @@ -262,7 +262,7 @@ public Builder setProcess(ProtobufProcessInfo process) {
return this;
}

public Builder setJvm(ProtobufJvmInfo jvm) {
public Builder setJvm(JvmInfo jvm) {
this.jvm = jvm;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,42 @@
import com.google.protobuf.CodedOutputStream;
import org.opensearch.action.ProtobufFailedNodeException;
import org.opensearch.action.support.nodes.ProtobufBaseNodesResponse;
import org.opensearch.cluster.ProtobufClusterName;
import org.opensearch.cluster.ClusterName;
import org.opensearch.cluster.node.DiscoveryNodeRole;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.ProtobufStreamInput;
import org.opensearch.common.io.stream.ProtobufStreamOutput;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.core.xcontent.ToXContent.Params;
import org.opensearch.core.xcontent.ToXContentFragment;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.http.ProtobufHttpInfo;
import org.opensearch.ingest.ProtobufIngestInfo;
import org.opensearch.monitor.jvm.JvmInfo;
import org.opensearch.monitor.os.ProtobufOsInfo;
import org.opensearch.monitor.process.ProtobufProcessInfo;
import org.opensearch.search.aggregations.support.ProtobufAggregationInfo;
import org.opensearch.search.pipeline.ProtobufSearchPipelineInfo;
import org.opensearch.threadpool.ProtobufThreadPoolInfo;
import org.opensearch.transport.ProtobufTransportInfo;

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

/**
* Transport response for OpenSearch Node Information
*
* @opensearch.internal
*/
public class ProtobufNodesInfoResponse extends ProtobufBaseNodesResponse<ProtobufNodeInfo> {
public class ProtobufNodesInfoResponse extends ProtobufBaseNodesResponse<ProtobufNodeInfo> implements ToXContentFragment {

public ProtobufNodesInfoResponse(CodedInputStream in) throws IOException {
super(in);
}

public ProtobufNodesInfoResponse(
ProtobufClusterName clusterName,
List<ProtobufNodeInfo> nodes,
List<ProtobufFailedNodeException> failures
) {
public ProtobufNodesInfoResponse(ClusterName clusterName, List<ProtobufNodeInfo> nodes, List<ProtobufFailedNodeException> failures) {
super(clusterName, nodes, failures);
}

Expand All @@ -73,4 +86,93 @@ protected void writeNodesTo(CodedOutputStream out, List<ProtobufNodeInfo> nodes)
ProtobufStreamOutput protobufStreamOutput = new ProtobufStreamOutput(out);
protobufStreamOutput.writeCollection(nodes, (o, v) -> v.writeTo(o));
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject("nodes");
for (ProtobufNodeInfo nodeInfo : getNodes()) {
builder.startObject(nodeInfo.getNode().getId());

builder.field("name", nodeInfo.getNode().getName());
builder.field("transport_address", nodeInfo.getNode().getAddress().toString());
builder.field("host", nodeInfo.getNode().getHostName());
builder.field("ip", nodeInfo.getNode().getHostAddress());

builder.field("version", nodeInfo.getVersion());
builder.field("build_type", nodeInfo.getBuild().type().displayName());
builder.field("build_hash", nodeInfo.getBuild().hash());
if (nodeInfo.getTotalIndexingBuffer() != null) {
builder.humanReadableField("total_indexing_buffer", "total_indexing_buffer_in_bytes", nodeInfo.getTotalIndexingBuffer());
}

builder.startArray("roles");
for (DiscoveryNodeRole role : nodeInfo.getNode().getRoles()) {
builder.value(role.roleName());
}
builder.endArray();

if (!nodeInfo.getNode().getAttributes().isEmpty()) {
builder.startObject("attributes");
for (Map.Entry<String, String> entry : nodeInfo.getNode().getAttributes().entrySet()) {
builder.field(entry.getKey(), entry.getValue());
}
builder.endObject();
}

if (nodeInfo.getSettings() != null) {
builder.startObject("settings");
Settings settings = nodeInfo.getSettings();
settings.toXContent(builder, params);
builder.endObject();
}

if (nodeInfo.getInfo(ProtobufOsInfo.class) != null) {
nodeInfo.getInfo(ProtobufOsInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(ProtobufProcessInfo.class) != null) {
nodeInfo.getInfo(ProtobufProcessInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(JvmInfo.class) != null) {
nodeInfo.getInfo(JvmInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(ProtobufThreadPoolInfo.class) != null) {
nodeInfo.getInfo(ProtobufThreadPoolInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(ProtobufTransportInfo.class) != null) {
nodeInfo.getInfo(ProtobufTransportInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(ProtobufHttpInfo.class) != null) {
nodeInfo.getInfo(ProtobufHttpInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(ProtobufPluginsAndModules.class) != null) {
nodeInfo.getInfo(ProtobufPluginsAndModules.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(ProtobufIngestInfo.class) != null) {
nodeInfo.getInfo(ProtobufIngestInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(ProtobufAggregationInfo.class) != null) {
nodeInfo.getInfo(ProtobufAggregationInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(ProtobufSearchPipelineInfo.class) != null) {
nodeInfo.getInfo(ProtobufSearchPipelineInfo.class).toXContent(builder, params);
}

builder.endObject();
}
builder.endObject();
return builder;
}

@Override
public String toString() {
try {
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
toXContent(builder, EMPTY_PARAMS);
builder.endObject();
return Strings.toString(builder);
} catch (IOException e) {
return "{ \"error\" : \"" + e.getMessage() + "\"}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.opensearch.common.io.stream.ProtobufStreamInput;
import org.opensearch.common.io.stream.ProtobufStreamOutput;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.node.ProtobufReportingService;
import org.opensearch.plugins.ProtobufPluginInfo;

Expand Down Expand Up @@ -74,4 +75,21 @@ public void addPlugin(ProtobufPluginInfo info) {
public void addModule(ProtobufPluginInfo info) {
modules.add(info);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startArray("plugins");
for (ProtobufPluginInfo pluginInfo : getPluginInfos()) {
pluginInfo.toXContent(builder, params);
}
builder.endArray();
// TODO: not ideal, make a better api for this (e.g. with jar metadata, and so on)
builder.startArray("modules");
for (ProtobufPluginInfo moduleInfo : getModuleInfos()) {
moduleInfo.toXContent(builder, params);
}
builder.endArray();

return builder;
}
}
Loading

0 comments on commit 3566241

Please sign in to comment.