devmadhuu commented on code in PR #6376:
URL: https://github.com/apache/ozone/pull/6376#discussion_r1550831636


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/NodeEndpoint.java:
##########
@@ -171,4 +187,75 @@ private DatanodeStorageReport 
getStorageReport(DatanodeDetails datanode) {
     long committed = nodeStat.getCommitted().get();
     return new DatanodeStorageReport(capacity, used, remaining, committed);
   }
+
+  /**
+   * This GET API provides the information of all datanodes for which 
decommissioning is initiated.
+   * @return the wrapped  Response output
+   */
+  @GET
+  @Path("/decommission/info")
+  public Response getDatanodesDecommissionInfo() {
+    // Command to execute
+    List<String> commandArgs = Arrays.asList("ozone", "admin", "datanode", 
"status", "decommission", "--json");
+
+    return getDecommissionStatusResponse(commandArgs);
+  }
+
+  /**
+   * This GET API provides the information of a specific datanode for which 
decommissioning is initiated.
+   * @return the wrapped  Response output
+   */
+  @GET
+  @Path("/decommission/info/{uuid}")
+  public Response getDecommissionInfoForDatanode(@PathParam("uuid") String 
uuid) {
+    Preconditions.checkNotNull(uuid, "uuid of a datanode cannot be null !!!");
+    Preconditions.checkArgument(!uuid.isEmpty(), "uuid of a datanode cannot be 
empty !!!");
+
+    // Command to execute
+    List<String> commandArgs =
+        Arrays.asList("ozone", "admin", "datanode", "status", "decommission", 
"--id", uuid, "--json");
+
+    return getDecommissionStatusResponse(commandArgs);
+  }
+
+  private Response getDecommissionStatusResponse(List<String> commandArgs) {
+    Response.ResponseBuilder builder = Response.status(Response.Status.OK);
+    Map<Integer, String> commandOutputMap = 
reconUtils.executeCommand(commandArgs);
+    Map<String, Object> responseMap = new HashMap<>();
+
+    for (Map.Entry<Integer, String> entry : commandOutputMap.entrySet()) {
+      Integer exitCode = entry.getKey();
+      String processOutput = entry.getValue();
+      if (exitCode != 0) {
+        builder.status(Response.Status.INTERNAL_SERVER_ERROR);
+        builder.entity(
+            reconUtils.joinListArgs(commandArgs) + " command execution is not 
successful : " + processOutput);
+        return builder.build();
+      } else {
+        // Create ObjectMapper
+        ObjectMapper objectMapper = new ObjectMapper();
+        SimpleModule module = new SimpleModule();
+        module.addDeserializer(DatanodeDetails.class, new 
CustomDatanodeDetailsDeserializer());

Review Comment:
   As we have seen in past, that any change is CLI output happens due to change 
in removing or updating or adding additional field in API itself which CLI is 
using. So if we think of using ```
   scmClient.queryNode(DECOMMISSIONING,
           null, HddsProtos.QueryScope.CLUSTER, "")
   ```
   then also there are chances that Recon may give wrong result or break. So 
this PR objective is to reuse the functionality, so any change in API or CLI  
in future will require  to assess the impact anyways.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to