avijayanhwx commented on a change in pull request #633: HDDS-3123. Create REST 
API to serve Pipeline information and integrate with UI in Recon
URL: https://github.com/apache/hadoop-ozone/pull/633#discussion_r387959523
 
 

 ##########
 File path: 
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/PipelineEndpoint.java
 ##########
 @@ -0,0 +1,114 @@
+/**
+ * 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.scm.pipeline.Pipeline;
+import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager;
+import org.apache.hadoop.ozone.recon.api.types.PipelineMetadata;
+import org.apache.hadoop.ozone.recon.api.types.PipelinesResponse;
+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.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * Endpoint to fetch details about Pipelines.
+ */
+@Path("/pipelines")
+@Produces(MediaType.APPLICATION_JSON)
+public class PipelineEndpoint {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(PipelineEndpoint.class);
+
+  private ReconPipelineManager pipelineManager;
+
+  @Inject
+  PipelineEndpoint(OzoneStorageContainerManager reconSCM) {
+    this.pipelineManager = (ReconPipelineManager) 
reconSCM.getPipelineManager();
+  }
+
+  /**
+   * Return the list of pipelines with detailed information about each 
pipeline.
+   * @return {@link Response}
+   */
+  @GET
+  public Response getPipelines() {
+    List<PipelineMetadata> pipelinesList = new ArrayList<>();
+    List<Pipeline> pipelines = pipelineManager.getPipelines();
+
+    for (Pipeline pipeline : pipelines) {
+      String leaderNode;
+      UUID pipelineId = pipeline.getId().getId();
+      List<String> datanodes = new ArrayList<>();
+      int containers;
+      long duration =
+          Instant.now().toEpochMilli() -
+              pipeline.getCreationTimestamp().toEpochMilli();
+      try {
+        leaderNode = pipeline.getLeaderNode().getHostName();
+      } catch (Exception e) {
 
 Review comment:
   Shouldn't this just be IOException? From 
   `public DatanodeDetails getLeaderNode() throws IOException {`.
   Why do we need to set leaderNode to "" on exception? It can be null, and 
handled in the UI maybe. 
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to