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


##########
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");

Review Comment:
   how about kinit in secure cluster? and need admin permission to execute the 
CLI



##########
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:
   Any change in CLI output or any logging on screen can give wrong result, can 
Recon use API directly to trigger and get data instead of depending on CLI ?



##########
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);

Review Comment:
   since recon run in its user space, and this needs ozone in path to be 
invoked. If Path is not set properly, this can fail. check if user have 
capability to set env variable, path or conf if required.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconUtils.java:
##########
@@ -385,4 +396,61 @@ public SCMNodeDetails 
getReconNodeDetails(OzoneConfiguration conf) {
         HddsServerUtil.getReconDataNodeBindAddress(conf));
     return builder.build();
   }
+
+  /**
+   * This method accepts the list of command args and supports execution of 
ozone CLI based commands only.
+   *
+   * @param commandArgs the list of command args
+   * @return the command output map with its exit code
+   */
+  public Map<Integer, String> executeCommand(List<String> commandArgs) {
+    String command = joinListArgs(commandArgs);
+    Map<Integer, String> processOutputMap = new HashMap<>();
+    LOG.info("Received command : '{}' to execute", command);
+    AtomicReference<String> processOutput = new AtomicReference<>();
+    ProcessBuilder pb = new ProcessBuilder(commandArgs);
+    try {
+      SecurityUtil.doAsLoginUser((PrivilegedExceptionAction<Map<Integer, 
String>>) () -> {
+        Process process = pb.start();
+        int exitCode = process.waitFor();

Review Comment:
   we may need provide max time for it to wait



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