You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/02/25 04:58:27 UTC

[GitHub] [ozone] siddhantsangwan commented on a change in pull request #1919: HDDS-4816. Add UsageInfoSubcommand to get Datanode usage information.

siddhantsangwan commented on a change in pull request #1919:
URL: https://github.com/apache/ozone/pull/1919#discussion_r582546009



##########
File path: hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java
##########
@@ -618,6 +620,73 @@ public boolean getReplicationManagerStatus() {
     return scm.getReplicationManager().isRunning();
   }
 
+  /**
+   * Get Datanode usage info (such as capacity, used) by ip or uuid.
+   *
+   * @param ipaddress - Datanode Address String
+   * @param uuid - Datanode UUID String
+   * @return List of DatanodeUsageInfo. Each element contains usage info such
+   * as capacity, SCMUsed, and remaining space.
+   * @throws IOException
+   */
+  @Override
+  public List<HddsProtos.DatanodeUsageInfo> getDatanodeUsageInfo(
+      String ipaddress, String uuid) throws IOException {
+
+    // check admin authorisation
+    String remoteUser = getRpcRemoteUsername();
+    try {
+      getScm().checkAdminAccess(remoteUser);
+    } catch (IOException e) {
+      LOG.error("Authorisation failed", e);
+      throw e;
+    }
+
+    // get datanodes by ip or uuid
+    List<DatanodeDetails> nodes = new ArrayList<>();
+    if (!Strings.isNullOrEmpty(uuid)) {
+      nodes.add(scm.getScmNodeManager().getNodeByUuid(uuid));
+    } else if (!Strings.isNullOrEmpty(ipaddress)) {
+      nodes = scm.getScmNodeManager().getNodesByAddress(ipaddress);
+    } else {
+      throw new IOException(
+          "Could not get datanode with the specified parameters."
+      );
+    }
+
+    // get datanode usage info
+    List<HddsProtos.DatanodeUsageInfo> infoList = new ArrayList<>();
+    for (DatanodeDetails node : nodes) {
+      infoList.add(getUsageInfoFromDatanodeDetails(node));
+    }
+
+    return infoList;
+  }
+
+  /**
+   * Get usage details for a specific DatanodeDetails node.
+   *
+   * @param node - DatanodeDetails
+   * @return Usage info such as capacity, SCMUsed, and remaining space.
+   * @throws IOException
+   */
+  public HddsProtos.DatanodeUsageInfo getUsageInfoFromDatanodeDetails(

Review comment:
       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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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