Skip to content

Commit

Permalink
Migrate NodeInfo service to accommodate refactor.
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Carroll <[email protected]>
  • Loading branch information
finnegancarroll committed Nov 15, 2024
1 parent d741356 commit 41e70eb
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
* compatible open source license.
*/

package org.opensearch.grpc.services.nodesInfo;
package org.opensearch.grpc.services;

import io.grpc.Status;
import io.grpc.stub.StreamObserver;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -17,8 +16,6 @@
import org.opensearch.action.admin.cluster.node.info.NodesInfoResponse;
import org.opensearch.action.admin.cluster.node.info.PluginsAndModules;
import org.opensearch.action.admin.cluster.node.info.proto.NodesInfoProto;
import org.opensearch.action.admin.cluster.node.info.proto.NodesInfoProtoService;
import org.opensearch.action.admin.cluster.node.info.proto.NodesInfoServiceGrpc;
import org.opensearch.client.node.NodeClient;
import org.opensearch.cluster.node.DiscoveryNodeRole;
import org.opensearch.core.service.ReportingService;
Expand All @@ -39,6 +36,8 @@
import java.util.Map;
import java.util.Optional;

import opensearch.proto.services.NodesInfoServiceGrpc;

import static org.opensearch.core.xcontent.ToXContent.EMPTY_PARAMS;

public class NodesInfoServiceImpl extends NodesInfoServiceGrpc.NodesInfoServiceImplBase {
Expand All @@ -50,15 +49,15 @@ public NodesInfoServiceImpl(NodeClient client) {
}

@Override
public void getNodesInfo(NodesInfoProtoService.NodesInfoRequestProto request, StreamObserver<NodesInfoProtoService.NodesInfoResponseProto> responseObserver) {
public void nodesInfo(NodesInfoProto.NodesInfoRequestProto request, StreamObserver<NodesInfoProto.NodesInfoResponseProto> responseObserver) {
NodesInfoResponse response = client.admin().cluster()
.nodesInfo(reqFromProto(request))
.actionGet();
responseObserver.onNext(respToProto(response));
responseObserver.onCompleted();
}
private static NodesInfoRequest reqFromProto(NodesInfoProtoService.NodesInfoRequestProto request) {

private static NodesInfoRequest reqFromProto(NodesInfoProto.NodesInfoRequestProto request) {
String[] nodeIds = request.getNodeIdsList().toArray(new String[0]);
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(nodeIds);
nodesInfoRequest.timeout(request.getTimeout());
Expand All @@ -74,8 +73,8 @@ private static NodesInfoRequest reqFromProto(NodesInfoProtoService.NodesInfoRequ
return nodesInfoRequest;
}

private static NodesInfoProtoService.NodesInfoResponseProto respToProto(NodesInfoResponse response) {
NodesInfoProtoService.NodesInfoResponseProto.Builder builder = NodesInfoProtoService.NodesInfoResponseProto.newBuilder();
private static NodesInfoProto.NodesInfoResponseProto respToProto(NodesInfoResponse response) {
NodesInfoProto.NodesInfoResponseProto.Builder builder = NodesInfoProto.NodesInfoResponseProto.newBuilder();

for (NodeInfo ni : response.getNodes()) {
NodesInfoProto.NodesInfo.Builder nib = NodesInfoProto.NodesInfo.newBuilder()
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/org/opensearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
import org.opensearch.gateway.remote.RemoteClusterStateService;
import org.opensearch.grpc.GrpcServerTransport;
import org.opensearch.grpc.services.GrpcServiceRegistry;
import org.opensearch.grpc.services.nodesInfo.NodesInfoServiceImpl;
import org.opensearch.grpc.services.NodesInfoServiceImpl;
import org.opensearch.http.HttpServerTransport;
import org.opensearch.identity.IdentityService;
import org.opensearch.index.IndexModule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ package org.opensearch.action.admin.cluster.node.info.proto;

option java_outer_classname = "NodesInfoProto";

message StringList {
repeated string str_list = 1;
}

message Metrics {
bool all = 1;
StringList metric_list = 2;
}

message NodesInfoRequestProto {
Metrics metrics = 1;
string timeout = 2;
Expand All @@ -34,6 +25,15 @@ message NodesInfoResponseProto {
repeated NodesInfo nodesInfo = 2;
}

message StringList {
repeated string str_list = 1;
}

message Metrics {
bool all = 1;
StringList metric_list = 2;
}

message NodesInfo {
string node_id = 1;
string node_name = 2;
Expand Down
22 changes: 22 additions & 0 deletions server/src/main/proto/services/NodeInfo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

syntax = "proto3";
package opensearch.proto.services;

import "org/opensearch/action/admin/cluster/node/info/NodesInfoProto.proto";

option java_outer_classname = "NodesInfoProtoService";

service NodesInfoService {
rpc NodesInfo(org.opensearch.action.admin.cluster.node.info.proto.NodesInfoRequestProto) returns (org.opensearch.action.admin.cluster.node.info.proto.NodesInfoResponseProto) {}
rpc StreamNodesInfo(org.opensearch.action.admin.cluster.node.info.proto.NodesInfoRequestProto) returns (stream org.opensearch.action.admin.cluster.node.info.proto.NodesInfoResponseProto) {}
}
22 changes: 22 additions & 0 deletions server/src/main/proto/services/Search.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

syntax = "proto3";
package opensearch.proto.services;

import "spec/search.proto";

option java_outer_classname = "Search";

service SearchService {
rpc Search(SearchRequest) returns (SearchResponse) {}
rpc StreamSearch(SearchRequest) returns (stream SearchResponse) {}
}

0 comments on commit 41e70eb

Please sign in to comment.