avijayanhwx commented on a change in pull request #681: HDDS-3153. Create REST 
API to serve Recon Dashboard and integrate with UI in Recon.
URL: https://github.com/apache/hadoop-ozone/pull/681#discussion_r392628566
 
 

 ##########
 File path: 
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/ClusterStateEndpoint.java
 ##########
 @@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.recon.api;
+
+import org.apache.hadoop.hdds.protocol.DatanodeDetails;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeState;
+import org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat;
+import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager;
+import org.apache.hadoop.ozone.recon.api.types.ClusterStateResponse;
+import org.apache.hadoop.ozone.recon.api.types.DatanodeStorageReport;
+import org.apache.hadoop.ozone.recon.api.types.DatanodesCount;
+import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
+import org.apache.hadoop.ozone.recon.scm.ReconContainerManager;
+import org.apache.hadoop.ozone.recon.scm.ReconNodeManager;
+import org.apache.hadoop.ozone.recon.scm.ReconPipelineManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * Endpoint to fetch current state of ozone cluster.
+ */
+@Path("/clusterState")
+@Produces(MediaType.APPLICATION_JSON)
+public class ClusterStateEndpoint {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(ClusterStateEndpoint.class);
+
+  private ReconNodeManager nodeManager;
+  private ReconPipelineManager pipelineManager;
+  private ReconContainerManager containerManager;
+  private ReconOMMetadataManager omMetadataManager;
+
+  @Inject
+  ClusterStateEndpoint(OzoneStorageContainerManager reconSCM,
+                       ReconOMMetadataManager omMetadataManager) {
+    this.nodeManager =
+        (ReconNodeManager) reconSCM.getScmNodeManager();
+    this.pipelineManager = (ReconPipelineManager) 
reconSCM.getPipelineManager();
+    this.containerManager =
+        (ReconContainerManager) reconSCM.getContainerManager();
+    this.omMetadataManager = omMetadataManager;
+  }
+
+  /**
+   * Return a summary report on current cluster state.
+   * @return {@link Response}
+   */
+  @GET
+  public Response getClusterState() {
+    List<DatanodeDetails> datanodeDetails = nodeManager.getAllNodes();
+    AtomicInteger healthyDatanodes = new AtomicInteger();
+    int containers = this.containerManager.getContainerIDs().size();
+    int pipelines = this.pipelineManager.getPipelines().size();
+    long volumes;
+    long buckets;
+    long keys;
+    AtomicLong capacity = new AtomicLong(0L);
+    AtomicLong used = new AtomicLong(0L);
+    AtomicLong remaining = new AtomicLong(0L);
+    datanodeDetails.forEach(datanode -> {
 
 Review comment:
   We can use SCMNodeManager#getNodeCount(NodeState)  to get the number of 
nodes in a specific state.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org

Reply via email to