use of org.opensearch.action.admin.cluster.node.info.NodesInfoRequest in project OpenSearch by opensearch-project.
the class RestNodesInfoAction method prepareRequest.
static NodesInfoRequest prepareRequest(final RestRequest request) {
String[] nodeIds;
Set<String> metrics;
// this means one must differentiate between allowed metrics and arbitrary node ids in the same place
if (request.hasParam("nodeId") && !request.hasParam("metrics")) {
String nodeId = request.param("nodeId", "_all");
Set<String> metricsOrNodeIds = Strings.tokenizeByCommaToSet(nodeId);
boolean isMetricsOnly = ALLOWED_METRICS.containsAll(metricsOrNodeIds);
if (isMetricsOnly) {
nodeIds = new String[] { "_all" };
metrics = metricsOrNodeIds;
} else {
nodeIds = Strings.tokenizeToStringArray(nodeId, ",");
metrics = Sets.newHashSet("_all");
}
} else {
nodeIds = Strings.tokenizeToStringArray(request.param("nodeId", "_all"), ",");
metrics = Strings.tokenizeByCommaToSet(request.param("metrics", "_all"));
}
final NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(nodeIds);
nodesInfoRequest.timeout(request.param("timeout"));
// shortcut, don't do checks if only all is specified
if (metrics.size() == 1 && metrics.contains("_all")) {
nodesInfoRequest.all();
} else {
nodesInfoRequest.clear();
// disregard unknown metrics
metrics.retainAll(ALLOWED_METRICS);
nodesInfoRequest.addMetrics(metrics.stream().toArray(String[]::new));
}
return nodesInfoRequest;
}
use of org.opensearch.action.admin.cluster.node.info.NodesInfoRequest in project OpenSearch by opensearch-project.
the class RestThreadPoolAction method doCatRequest.
@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
clusterStateRequest.clear().nodes(true);
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
@Override
public void processResponse(final ClusterStateResponse clusterStateResponse) {
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
nodesInfoRequest.timeout(request.param("timeout"));
nodesInfoRequest.clear().addMetrics(NodesInfoRequest.Metric.PROCESS.metricName(), NodesInfoRequest.Metric.THREAD_POOL.metricName());
client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {
@Override
public void processResponse(final NodesInfoResponse nodesInfoResponse) {
NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
nodesStatsRequest.timeout(request.param("timeout"));
nodesStatsRequest.clear().addMetric(NodesStatsRequest.Metric.THREAD_POOL.metricName());
client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {
@Override
public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
}
});
}
});
}
});
}
use of org.opensearch.action.admin.cluster.node.info.NodesInfoRequest in project job-scheduler by opensearch-project.
the class SampleExtensionPluginIT method testPluginsAreInstalled.
public void testPluginsAreInstalled() {
ClusterHealthRequest request = new ClusterHealthRequest();
ClusterHealthResponse response = OpenSearchIntegTestCase.client().admin().cluster().health(request).actionGet();
Assert.assertEquals(ClusterHealthStatus.GREEN, response.getStatus());
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
nodesInfoRequest.addMetric(NodesInfoRequest.Metric.PLUGINS.metricName());
NodesInfoResponse nodesInfoResponse = OpenSearchIntegTestCase.client().admin().cluster().nodesInfo(nodesInfoRequest).actionGet();
List<PluginInfo> pluginInfos = nodesInfoResponse.getNodes().get(0).getInfo(PluginsAndModules.class).getPluginInfos();
Assert.assertTrue(pluginInfos.stream().anyMatch(pluginInfo -> pluginInfo.getName().equals("opensearch-job-scheduler")));
Assert.assertTrue(pluginInfos.stream().anyMatch(pluginInfo -> pluginInfo.getName().equals("opensearch-job-scheduler-sample-extension")));
}
use of org.opensearch.action.admin.cluster.node.info.NodesInfoRequest in project OpenSearch by opensearch-project.
the class RestNodesInfoActionTests method testSeparateNodeIdsAndMetrics.
public void testSeparateNodeIdsAndMetrics() {
Map<String, String> params = new HashMap<>();
List<String> nodeIds = new ArrayList<>(5);
List<String> metrics = new ArrayList<>(5);
for (int i = 0; i < 5; i++) {
nodeIds.add(randomValueOtherThanMany(ALLOWED_METRICS::contains, () -> randomAlphaOfLength(23)));
metrics.add(randomFrom(ALLOWED_METRICS));
}
params.put("nodeId", String.join(",", nodeIds));
params.put("metrics", String.join(",", metrics));
RestRequest restRequest = buildRestRequest(params);
NodesInfoRequest actual = RestNodesInfoAction.prepareRequest(restRequest);
assertArrayEquals(nodeIds.toArray(), actual.nodesIds());
assertMetrics(metrics, actual);
}
use of org.opensearch.action.admin.cluster.node.info.NodesInfoRequest in project OpenSearch by opensearch-project.
the class RestNodesInfoActionTests method testOnlyMetrics.
public void testOnlyMetrics() {
Map<String, String> params = new HashMap<>();
int metricsCount = randomIntBetween(1, ALLOWED_METRICS.size());
List<String> metrics = new ArrayList<>();
for (int i = 0; i < metricsCount; i++) {
metrics.add(randomFrom(ALLOWED_METRICS));
}
params.put("nodeId", String.join(",", metrics));
RestRequest restRequest = buildRestRequest(params);
NodesInfoRequest actual = RestNodesInfoAction.prepareRequest(restRequest);
assertArrayEquals(new String[] { "_all" }, actual.nodesIds());
assertMetrics(metrics, actual);
}
Aggregations