@@ -76,19 +76,12 @@ public class ClusterAdapterOS implements ClusterAdapter {
7676 private static final Logger LOG = LoggerFactory .getLogger (ClusterAdapterOS .class );
7777 private final Duration requestTimeout ;
7878 private final OfficialOpensearchClient opensearchClient ;
79- private final PlainJsonApi jsonApi ;
80- private final OpenSearchCatClient catClient ;
81- private final OpenSearchClusterClient clusterClient ;
8279
8380 @ Inject
8481 public ClusterAdapterOS (OfficialOpensearchClient opensearchClient ,
85- @ Named ("elasticsearch_socket_timeout" ) Duration requestTimeout ,
86- PlainJsonApi jsonApi ) {
82+ @ Named ("elasticsearch_socket_timeout" ) Duration requestTimeout ) {
8783 this .requestTimeout = requestTimeout ;
88- this .jsonApi = jsonApi ;
8984 this .opensearchClient = opensearchClient ;
90- this .catClient = opensearchClient .sync ().cat ();
91- this .clusterClient = opensearchClient .sync ().cluster ();
9285 }
9386
9487 @ Override
@@ -117,8 +110,8 @@ public Set<NodeFileDescriptorStats> fileDescriptorStats() {
117110 }
118111
119112 List <NodesRecord > nodes () {
120- List <NodesRecord > allNodes = opensearchClient .execute (() ->
121- catClient .nodes (NodesRequest .builder ()
113+ List <NodesRecord > allNodes = opensearchClient .sync ( c ->
114+ c . cat () .nodes (NodesRequest .builder ()
122115 .fullId (true )
123116 .headers ("id" , "name" , "node.role" , "ip" , "version" ,
124117 "file_desc.max" , "disk.used" , "disk.total" , "disk.used_percent" )
@@ -153,8 +146,8 @@ public ClusterShardAllocation clusterShardAllocation() {
153146 LOG .warn ("Could not retrieve max_shards_per_node setting from cluster settings. Threshold warnings disabled." , e );
154147 }
155148
156- List <NodeShardAllocation > nodeShardAllocations = opensearchClient .execute (() ->
157- catClient .allocation ().valueBody ().stream ().map (this ::toNodeShardAllocation ).toList (),
149+ List <NodeShardAllocation > nodeShardAllocations = opensearchClient .sync ( c ->
150+ c . cat () .allocation ().valueBody ().stream ().map (this ::toNodeShardAllocation ).toList (),
158151 "Unable to retrieve node shard allocation"
159152 );
160153 return new ClusterShardAllocation (maxShardsPerNode , nodeShardAllocations );
@@ -216,7 +209,7 @@ private Optional<JsonNode> nodeById(String nodeId) {
216209 .endpoint ("/_nodes/" + nodeId )
217210 .method ("GET" )
218211 .build ();
219- return Optional .of (jsonApi .performRequest (request , "Couldn't read Opensearch nodes data!" ))
212+ return Optional .of (opensearchClient .performRequest (request , "Couldn't read Opensearch nodes data!" ))
220213 .map (jsonNode -> jsonNode .path ("nodes" ).path (nodeId ))
221214 .filter (node -> !node .isMissingNode ());
222215 }
@@ -250,8 +243,8 @@ private ClusterHealth clusterHealthFrom(HealthResponse response) {
250243
251244 @ Override
252245 public PendingTasksStats pendingTasks () {
253- PendingTasksResponse pendingTasks = opensearchClient .execute (
254- clusterClient :: pendingTasks ,
246+ PendingTasksResponse pendingTasks = opensearchClient .sync ( c ->
247+ c . cluster (). pendingTasks () ,
255248 "Unable to retrieve pending tasks"
256249 );
257250
@@ -302,7 +295,7 @@ public JsonNode rawClusterStats() {
302295 .endpoint ("/_cluster/stats/nodes/*" )
303296 .method ("GET" )
304297 .build ();
305- return jsonApi .performRequest (request , "Couldn't read Elasticsearch cluster stats" );
298+ return opensearchClient .performRequest (request , "Couldn't read Elasticsearch cluster stats" );
306299 }
307300
308301 @ Override
@@ -311,7 +304,7 @@ public Map<String, org.graylog2.system.stats.elasticsearch.NodeInfo> nodesInfo()
311304 .endpoint ("/_nodes" )
312305 .method ("GET" )
313306 .build ();
314- JsonNode json = jsonApi .performRequest (request , "Couldn't read Opensearch nodes data!" );
307+ JsonNode json = opensearchClient .performRequest (request , "Couldn't read Opensearch nodes data!" );
315308 JsonNode nodes = json .at ("/nodes" );
316309 return toStream (nodes .fieldNames ()).collect (Collectors .toMap (
317310 n -> n ,
@@ -334,7 +327,7 @@ public Map<String, NodeOSInfo> nodesHostInfo() {
334327 .endpoint ("/_nodes/stats/os" )
335328 .method ("GET" )
336329 .build ();
337- JsonNode json = jsonApi .performRequest (request , "Couldn't read Opensearch nodes os data!" );
330+ JsonNode json = opensearchClient .performRequest (request , "Couldn't read Opensearch nodes os data!" );
338331 JsonNode nodes = json .at ("/nodes" );
339332 return toStream (nodes .fieldNames ())
340333 .collect (Collectors .toMap (name -> name , name -> createNodeHostInfo (nodes .get (name ))));
@@ -370,7 +363,7 @@ public ShardStats shardStats() {
370363 private Optional <HealthResponse > clusterHealth () {
371364 final Time timeout = new Time .Builder ().time (requestTimeout .toSeconds () + "s" ).build ();
372365 try {
373- HealthResponse health = clusterClient .health (HealthRequest .builder ()
366+ HealthResponse health = opensearchClient . syncWithoutErrorMapping (). cluster () .health (HealthRequest .builder ()
374367 .timeout (timeout )
375368 .build ()
376369 );
@@ -392,7 +385,7 @@ public Optional<HealthStatus> deflectorHealth(Collection<String> indices) {
392385 }
393386
394387 final Map <String , String > aliasMapping ;
395- aliasMapping = opensearchClient .execute (() -> catClient .aliases ().valueBody ()
388+ aliasMapping = opensearchClient .sync ( c -> c . cat () .aliases ().valueBody ()
396389 .stream ()
397390 .filter (alias -> Objects .nonNull (alias .index ()))
398391 .collect (Collectors .toMap (AliasesRecord ::alias , AliasesRecord ::index )),
@@ -404,8 +397,8 @@ public Optional<HealthStatus> deflectorHealth(Collection<String> indices) {
404397 .map (index -> aliasMapping .getOrDefault (index , index ))
405398 .collect (Collectors .toSet ());
406399
407- final Set <IndicesRecord > indexSummaries = opensearchClient .execute (() ->
408- catClient .indices ().valueBody ()
400+ final Set <IndicesRecord > indexSummaries = opensearchClient .sync ( client ->
401+ client . cat () .indices ().valueBody ()
409402 .stream ()
410403 .filter (indexSummary -> mappedIndices .contains (indexSummary .index ()))
411404 .collect (Collectors .toSet ()),
@@ -423,7 +416,7 @@ public Optional<HealthStatus> deflectorHealth(Collection<String> indices) {
423416 }
424417
425418 private GetClusterSettingsResponse getClusterSettings () {
426- return opensearchClient .execute (() -> clusterClient .getSettings (
419+ return opensearchClient .sync ( c -> c . cluster () .getSettings (
427420 GetClusterSettingsRequest .builder ()
428421 .includeDefaults (true )
429422 .flatSettings (true )
0 commit comments