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


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/NodeEndpoint.java:
##########
@@ -171,4 +177,59 @@ private DatanodeStorageReport 
getStorageReport(DatanodeDetails datanode) {
     long committed = nodeStat.getCommitted().get();
     return new DatanodeStorageReport(capacity, used, remaining, committed);
   }
+
+  @PUT
+  @Path("/remove")
+  @Consumes(MediaType.APPLICATION_JSON)
+  public Response removeDatanodes(List<String> uuids) {
+    List<DatanodeMetadata> notFoundDatanodes = new ArrayList<>();
+    List<DatanodeMetadata> removedDatanodes = new ArrayList<>();
+
+    Preconditions.checkNotNull(uuids, "Datanode list argument should not be 
null");
+    Preconditions.checkArgument(!uuids.isEmpty(), "Datanode list argument 
should not be empty");
+    try {
+      for (String uuid : uuids) {
+        DatanodeDetails nodeByUuid = nodeManager.getNodeByUuid(uuid);
+        try {
+          NodeStatus nodeStatus = nodeManager.getNodeStatus(nodeByUuid);
+          boolean isNodeDecommissioned = nodeByUuid.getPersistedOpState() == 
NodeOperationalState.DECOMMISSIONED;
+          boolean isNodeInMaintenance = nodeByUuid.getPersistedOpState() == 
NodeOperationalState.DECOMMISSIONED;
+          if (isNodeDecommissioned || isNodeInMaintenance || 
nodeStatus.isDead()) {
+            removedDatanodes.add(DatanodeMetadata.newBuilder()
+                .withHostname(nodeManager.getHostName(nodeByUuid))
+                .withUUid(uuid)
+                .withState(nodeManager.getNodeStatus(nodeByUuid).getHealth())
+                .build());
+            nodeManager.removeNode(nodeByUuid);
+          } else {
+            Response.ResponseBuilder builder = 
Response.status(Response.Status.BAD_REQUEST);
+            builder.entity("Invalid request: Node: " + uuid + " should be in 
either DECOMMISSIONED or " +
+                "IN_MAINTENANCE mode or DEAD.");
+            // Build and return the response
+            return builder.build();

Review Comment:
   Ok done.



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