hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aajis...@apache.org
Subject hadoop git commit: HDFS-11417. Add datanode admin command to get the storage info. Contributed by Surendra Singh Lilhore.
Date Wed, 26 Apr 2017 09:09:02 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 1e60cfed7 -> cc66153e1


HDFS-11417. Add datanode admin command to get the storage info. Contributed by Surendra Singh
Lilhore.

(cherry picked from commit 93fa48fcf243dc759db1736af145633da760f937)

 Conflicts:
	hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ClientDatanodeProtocol.java
	hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientDatanodeProtocolTranslatorPB.java
	hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientDatanodeProtocolServerSideTranslatorPB.java


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/cc66153e
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/cc66153e
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/cc66153e

Branch: refs/heads/branch-2
Commit: cc66153e121e71f5f87166be3c3e1331517bc594
Parents: 1e60cfe
Author: Akira Ajisaka <aajisaka@apache.org>
Authored: Wed Apr 26 17:43:29 2017 +0900
Committer: Akira Ajisaka <aajisaka@apache.org>
Committed: Wed Apr 26 18:08:12 2017 +0900

----------------------------------------------------------------------
 .../hdfs/protocol/ClientDatanodeProtocol.java   |   5 +
 .../hdfs/protocol/DatanodeVolumeInfo.java       | 122 +++++++++++++++++++
 .../ClientDatanodeProtocolTranslatorPB.java     |  28 +++++
 .../src/main/proto/ClientDatanodeProtocol.proto |   9 ++
 .../src/main/proto/hdfs.proto                   |  13 ++
 ...tDatanodeProtocolServerSideTranslatorPB.java |  29 ++++-
 .../hadoop/hdfs/server/datanode/DataNode.java   |  27 ++++
 .../org/apache/hadoop/hdfs/tools/DFSAdmin.java  |  30 ++++-
 .../src/site/markdown/HDFSCommands.md           |   2 +
 .../apache/hadoop/hdfs/tools/TestDFSAdmin.java  |  20 +++
 10 files changed, 283 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/cc66153e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ClientDatanodeProtocol.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ClientDatanodeProtocol.java
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ClientDatanodeProtocol.java
index a60c17d..0202335 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ClientDatanodeProtocol.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ClientDatanodeProtocol.java
@@ -182,4 +182,9 @@ public interface ClientDatanodeProtocol {
    * @return balancer bandwidth
    */
   long getBalancerBandwidth() throws IOException;
+
+  /**
+   * Get volume report of datanode.
+   */
+  List<DatanodeVolumeInfo> getVolumeReport() throws IOException;
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cc66153e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/DatanodeVolumeInfo.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/DatanodeVolumeInfo.java
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/DatanodeVolumeInfo.java
new file mode 100644
index 0000000..40e0918
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/DatanodeVolumeInfo.java
@@ -0,0 +1,122 @@
+/**
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.hdfs.protocol;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.fs.StorageType;
+import org.apache.hadoop.util.StringUtils;
+
+/**
+ * Locally available datanode volume information.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Evolving
+public class DatanodeVolumeInfo {
+  private long usedSpace;
+  private long freeSpace;
+  private long reservedSpace;
+  private long reservedSpaceForReplicas;
+  private long numBlocks;
+  private StorageType storageType;
+  private String path;
+
+  public DatanodeVolumeInfo(String path, long usedSpace, long freeSpace,
+      long reservedSpace, long reservedSpaceForReplicas, long numBlocks,
+      StorageType type) {
+    this.usedSpace = usedSpace;
+    this.freeSpace = freeSpace;
+    this.reservedSpace = reservedSpace;
+    this.reservedSpaceForReplicas = reservedSpaceForReplicas;
+    this.numBlocks = numBlocks;
+    this.storageType = type;
+    this.path = path;
+  }
+
+  /** get used space. */
+  public long getUsedSpace() {
+    return usedSpace;
+  }
+
+  /**
+   * get free space.
+   */
+  public long getFreeSpace() {
+    return freeSpace;
+  }
+
+  /**
+   * get reserved space.
+   */
+  public long getReservedSpace() {
+    return reservedSpace;
+  }
+
+  /**
+   * get reserved space for replicas.
+   */
+  public long getReservedSpaceForReplicas() {
+    return reservedSpaceForReplicas;
+  }
+
+  /**
+   * get number of blocks.
+   */
+  public long getNumBlocks() {
+    return numBlocks;
+  }
+
+  /**
+   * get storage type.
+   */
+  public StorageType getStorageType() {
+    return storageType;
+  }
+
+  /**
+   * get volume path.
+   */
+  public String getPath() {
+    return path;
+  }
+
+  /**
+   * get volume report.
+   */
+  public String getDatanodeVolumeReport() {
+    StringBuilder report = new StringBuilder();
+    report
+        .append("Directory: " + path)
+        .append("\nStorageType: " + storageType)
+        .append(
+            "\nCapacity Used: " + usedSpace + "("
+                + StringUtils.byteDesc(usedSpace) + ")")
+        .append(
+            "\nCapacity Left: " + freeSpace + "("
+                + StringUtils.byteDesc(freeSpace) + ")")
+        .append(
+            "\nCapacity Reserved: " + reservedSpace + "("
+                + StringUtils.byteDesc(reservedSpace) + ")")
+        .append(
+            "\nReserved Space for Replicas: " + reservedSpaceForReplicas + "("
+                + StringUtils.byteDesc(reservedSpaceForReplicas) + ")")
+        .append("\nBlocks: " + numBlocks);
+    return report.toString();
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cc66153e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientDatanodeProtocolTranslatorPB.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientDatanodeProtocolTranslatorPB.java
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientDatanodeProtocolTranslatorPB.java
index a2e0b35..80f818d 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientDatanodeProtocolTranslatorPB.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientDatanodeProtocolTranslatorPB.java
@@ -35,6 +35,7 @@ import org.apache.hadoop.hdfs.protocol.BlockLocalPathInfo;
 import org.apache.hadoop.hdfs.protocol.ClientDatanodeProtocol;
 import org.apache.hadoop.hdfs.protocol.DatanodeID;
 import org.apache.hadoop.hdfs.protocol.DatanodeLocalInfo;
+import org.apache.hadoop.hdfs.protocol.DatanodeVolumeInfo;
 import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
 import org.apache.hadoop.hdfs.protocol.HdfsBlocksMetadata;
 import org.apache.hadoop.hdfs.protocol.LocatedBlock;
@@ -49,6 +50,9 @@ import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.GetDat
 import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.GetHdfsBlockLocationsRequestProto;
 import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.GetHdfsBlockLocationsResponseProto;
 import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.GetReplicaVisibleLengthRequestProto;
+import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.GetVolumeReportRequestProto;
+import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.GetVolumeReportResponseProto;
+import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.DatanodeVolumeInfoProto;
 import org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.ListReconfigurablePropertiesRequestProto;
 import org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.ListReconfigurablePropertiesResponseProto;
 import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.RefreshNamenodesRequestProto;
@@ -72,6 +76,7 @@ import com.google.common.primitives.Longs;
 import com.google.protobuf.ByteString;
 import com.google.protobuf.RpcController;
 import com.google.protobuf.ServiceException;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -95,6 +100,9 @@ public class ClientDatanodeProtocolTranslatorPB implements
       RefreshNamenodesRequestProto.newBuilder().build();
   private final static GetDatanodeInfoRequestProto VOID_GET_DATANODE_INFO =
       GetDatanodeInfoRequestProto.newBuilder().build();
+  private final static GetVolumeReportRequestProto
+      VOID_GET_DATANODE_STORAGE_INFO =
+      GetVolumeReportRequestProto.newBuilder().build();
   private final static GetReconfigurationStatusRequestProto VOID_GET_RECONFIG_STATUS =
       GetReconfigurationStatusRequestProto.newBuilder().build();
   private final static StartReconfigurationRequestProto VOID_START_RECONFIG =
@@ -369,4 +377,24 @@ public class ClientDatanodeProtocolTranslatorPB implements
       throw ProtobufHelper.getRemoteException(e);
     }
   }
+
+  @Override
+  public List<DatanodeVolumeInfo> getVolumeReport() throws IOException {
+    try {
+      List<DatanodeVolumeInfo> volumeInfoList = new ArrayList<>();
+      GetVolumeReportResponseProto volumeReport = rpcProxy.getVolumeReport(
+          NULL_CONTROLLER, VOID_GET_DATANODE_STORAGE_INFO);
+      List<DatanodeVolumeInfoProto> volumeProtoList = volumeReport
+          .getVolumeInfoList();
+      for (DatanodeVolumeInfoProto proto : volumeProtoList) {
+        volumeInfoList.add(new DatanodeVolumeInfo(proto.getPath(), proto
+            .getUsedSpace(), proto.getFreeSpace(), proto.getReservedSpace(),
+            proto.getReservedSpaceForReplicas(), proto.getNumBlocks(),
+            PBHelperClient.convertStorageType(proto.getStorageType())));
+      }
+      return volumeInfoList;
+    } catch (ServiceException e) {
+      throw ProtobufHelper.getRemoteException(e);
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cc66153e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/proto/ClientDatanodeProtocol.proto
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/proto/ClientDatanodeProtocol.proto
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/proto/ClientDatanodeProtocol.proto
index 4e18599..b9077f6 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/proto/ClientDatanodeProtocol.proto
+++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/proto/ClientDatanodeProtocol.proto
@@ -157,6 +157,12 @@ message GetDatanodeInfoResponseProto {
   required DatanodeLocalInfoProto localInfo = 1;
 }
 
+message GetVolumeReportRequestProto {
+}
+
+message GetVolumeReportResponseProto {
+  repeated DatanodeVolumeInfoProto volumeInfo = 1;
+}
 
 message TriggerBlockReportRequestProto {
   required bool incremental = 1;
@@ -222,6 +228,9 @@ service ClientDatanodeProtocolService {
   rpc getDatanodeInfo(GetDatanodeInfoRequestProto)
       returns(GetDatanodeInfoResponseProto);
 
+  rpc getVolumeReport(GetVolumeReportRequestProto)
+      returns(GetVolumeReportResponseProto);
+
   rpc getReconfigurationStatus(GetReconfigurationStatusRequestProto)
       returns(GetReconfigurationStatusResponseProto);
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cc66153e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/proto/hdfs.proto
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/proto/hdfs.proto b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/proto/hdfs.proto
index 1cd05c9..04f8730 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/proto/hdfs.proto
+++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/proto/hdfs.proto
@@ -70,6 +70,19 @@ message DatanodeLocalInfoProto {
 }
 
 /**
+ * Datanode volume information
+ */
+message DatanodeVolumeInfoProto {
+  required string path = 1;
+  required StorageTypeProto storageType = 2;
+  required uint64 usedSpace = 3;
+  required uint64 freeSpace = 4;
+  required uint64 reservedSpace = 5;
+  required uint64 reservedSpaceForReplicas = 6;
+  required uint64 numBlocks = 7;
+}
+
+/**
  * DatanodeInfo array
  */
 message DatanodeInfosProto {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cc66153e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientDatanodeProtocolServerSideTranslatorPB.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientDatanodeProtocolServerSideTranslatorPB.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientDatanodeProtocolServerSideTranslatorPB.java
index e712a65..3de7f97 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientDatanodeProtocolServerSideTranslatorPB.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientDatanodeProtocolServerSideTranslatorPB.java
@@ -20,13 +20,13 @@ package org.apache.hadoop.hdfs.protocolPB;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.hdfs.client.BlockReportOptions;
 import org.apache.hadoop.hdfs.protocol.BlockLocalPathInfo;
 import org.apache.hadoop.hdfs.protocol.ClientDatanodeProtocol;
 import org.apache.hadoop.hdfs.protocol.HdfsBlocksMetadata;
+import org.apache.hadoop.hdfs.protocol.DatanodeVolumeInfo;
 import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.DeleteBlockPoolRequestProto;
 import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.DeleteBlockPoolResponseProto;
 import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.EvictWritersRequestProto;
@@ -44,6 +44,8 @@ import org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.GetRe
 import org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.GetReconfigurationStatusResponseProto;
 import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.GetReplicaVisibleLengthRequestProto;
 import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.GetReplicaVisibleLengthResponseProto;
+import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.GetVolumeReportRequestProto;
+import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.GetVolumeReportResponseProto;
 import org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.ListReconfigurablePropertiesRequestProto;
 import org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.ListReconfigurablePropertiesResponseProto;
 import org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.RefreshNamenodesRequestProto;
@@ -60,6 +62,7 @@ import org.apache.hadoop.security.token.Token;
 
 import com.google.common.primitives.Longs;
 import com.google.protobuf.ByteString;
+import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.DatanodeVolumeInfoProto;
 import com.google.protobuf.RpcController;
 import com.google.protobuf.ServiceException;
 
@@ -276,4 +279,28 @@ public class ClientDatanodeProtocolServerSideTranslatorPB implements
     return GetBalancerBandwidthResponseProto.newBuilder()
         .setBandwidth(bandwidth).build();
   }
+
+  @Override
+  public GetVolumeReportResponseProto getVolumeReport(RpcController controller,
+      GetVolumeReportRequestProto request) throws ServiceException {
+    try {
+      org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.
+          GetVolumeReportResponseProto.Builder builder =
+          GetVolumeReportResponseProto.newBuilder();
+      List<DatanodeVolumeInfo> volumeReport = impl.getVolumeReport();
+      for (DatanodeVolumeInfo info : volumeReport) {
+        builder.addVolumeInfo(DatanodeVolumeInfoProto.newBuilder()
+            .setPath(info.getPath()).setFreeSpace(info.getFreeSpace())
+            .setNumBlocks(info.getNumBlocks())
+            .setReservedSpace(info.getReservedSpace())
+            .setReservedSpaceForReplicas(info.getReservedSpaceForReplicas())
+            .setStorageType(
+                PBHelperClient.convertStorageType(info.getStorageType()))
+            .setUsedSpace(info.getUsedSpace()));
+      }
+      return builder.build();
+    } catch (Exception e) {
+      throw new ServiceException(e);
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cc66153e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
index d7f2abc..320a25e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
@@ -80,6 +80,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.Callable;
@@ -121,6 +122,7 @@ import org.apache.hadoop.hdfs.protocol.DatanodeID;
 import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
 import org.apache.hadoop.hdfs.protocol.DatanodeInfo.DatanodeInfoBuilder;
 import org.apache.hadoop.hdfs.protocol.DatanodeLocalInfo;
+import org.apache.hadoop.hdfs.protocol.DatanodeVolumeInfo;
 import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
 import org.apache.hadoop.hdfs.protocol.HdfsBlocksMetadata;
 import org.apache.hadoop.hdfs.protocol.HdfsConstants;
@@ -3381,4 +3383,29 @@ public class DataNode extends ReconfigurableBase
     Set<String> slowDisks = diskMetrics.getDiskOutliersStats().keySet();
     return JSON.toString(slowDisks);
   }
+
+
+  @Override
+  public List<DatanodeVolumeInfo> getVolumeReport() throws IOException {
+    checkSuperuserPrivilege();
+    Map<String, Object> volumeInfoMap = data.getVolumeInfoMap();
+    if (volumeInfoMap == null) {
+      LOG.warn("DataNode volume info not available.");
+      return new ArrayList<>(0);
+    }
+    List<DatanodeVolumeInfo> volumeInfoList = new ArrayList<>();
+    for (Entry<String, Object> volume : volumeInfoMap.entrySet()) {
+      @SuppressWarnings("unchecked")
+      Map<String, Object> volumeInfo = (Map<String, Object>) volume.getValue();
+      DatanodeVolumeInfo dnStorageInfo = new DatanodeVolumeInfo(
+          volume.getKey(), (Long) volumeInfo.get("usedSpace"),
+          (Long) volumeInfo.get("freeSpace"),
+          (Long) volumeInfo.get("reservedSpace"),
+          (Long) volumeInfo.get("reservedSpaceForReplicas"),
+          (Long) volumeInfo.get("numBlocks"),
+          (StorageType) volumeInfo.get("storageType"));
+      volumeInfoList.add(dnStorageInfo);
+    }
+    return volumeInfoList;
+  }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cc66153e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java
index cc667a4..72a76f1 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java
@@ -68,6 +68,7 @@ import org.apache.hadoop.hdfs.protocol.ClientDatanodeProtocol;
 import org.apache.hadoop.hdfs.protocol.ClientProtocol;
 import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
 import org.apache.hadoop.hdfs.protocol.DatanodeLocalInfo;
+import org.apache.hadoop.hdfs.protocol.DatanodeVolumeInfo;
 import org.apache.hadoop.hdfs.protocol.HdfsConstants;
 import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType;
 import org.apache.hadoop.hdfs.protocol.HdfsConstants.RollingUpgradeAction;
@@ -440,7 +441,8 @@ public class DFSAdmin extends FsShell {
     "\t[-reconfig <namenode|datanode> <host:ipc_port> " +
       "<start|status|properties>]\n" +
     "\t[-printTopology]\n" +
-    "\t[-refreshNamenodes datanode_host:ipc_port]\n"+
+      "\t[-refreshNamenodes datanode_host:ipc_port]\n" +
+      "\t[-getVolumeReport datanode_host:ipc_port]\n" +
     "\t[-deleteBlockPool datanode_host:ipc_port blockpoolId [force]]\n"+
     "\t[-setBalancerBandwidth <bandwidth in bytes per second>]\n" +
     "\t[-getBalancerBandwidth <datanode_host:ipc_port>]\n" +
@@ -1043,6 +1045,9 @@ public class DFSAdmin extends FsShell {
                               "\t\tstops serving the removed block-pools\n"+
                               "\t\tand starts serving new block-pools\n";
     
+    String getVolumeReport = "-getVolumeReport: Takes a datanodehost:port as "
+        + "argument,\n\t\tFor the given datanode, get the volume report\n";
+
     String deleteBlockPool = "-deleteBlockPool: Arguments are datanodehost:port, blockpool
id\n"+
                              "\t\t and an optional argument \"force\". If force is passed,\n"+
                              "\t\t block pool directory for the given blockpool id on the
given\n"+
@@ -1143,6 +1148,8 @@ public class DFSAdmin extends FsShell {
       System.out.println(printTopology);
     } else if ("refreshNamenodes".equals(cmd)) {
       System.out.println(refreshNamenodes);
+    } else if ("getVolumeReport".equals(cmd)) {
+      System.out.println(getVolumeReport);
     } else if ("deleteBlockPool".equals(cmd)) {
       System.out.println(deleteBlockPool);
     } else if ("setBalancerBandwidth".equals(cmd)) {
@@ -1810,6 +1817,9 @@ public class DFSAdmin extends FsShell {
     } else if ("-refreshNamenodes".equals(cmd)) {
       System.err.println("Usage: hdfs dfsadmin"
                          + " [-refreshNamenodes datanode-host:port]");
+    } else if ("-getVolumeReport".equals(cmd)) {
+      System.err.println("Usage: hdfs dfsadmin"
+          + " [-getVolumeReport datanode-host:port]");
     } else if ("-deleteBlockPool".equals(cmd)) {
       System.err.println("Usage: hdfs dfsadmin"
           + " [-deleteBlockPool datanode-host:port blockpoolId [force]]");
@@ -1942,6 +1952,11 @@ public class DFSAdmin extends FsShell {
         printUsage(cmd);
         return exitCode;
       }
+    } else if ("-getVolumeReport".equals(cmd)) {
+      if (argv.length != 2) {
+        printUsage(cmd);
+        return exitCode;
+      }
     } else if ("-reconfig".equals(cmd)) {
       if (argv.length != 4) {
         printUsage(cmd);
@@ -2043,6 +2058,8 @@ public class DFSAdmin extends FsShell {
         exitCode = printTopology();
       } else if ("-refreshNamenodes".equals(cmd)) {
         exitCode = refreshNamenodes(argv, i);
+      } else if ("-getVolumeReport".equals(cmd)) {
+        exitCode = getVolumeReport(argv, i);
       } else if ("-deleteBlockPool".equals(cmd)) {
         exitCode = deleteBlockPool(argv, i);
       } else if ("-setBalancerBandwidth".equals(cmd)) {
@@ -2105,6 +2122,17 @@ public class DFSAdmin extends FsShell {
     return exitCode;
   }
 
+  private int getVolumeReport(String[] argv, int i) throws IOException {
+    ClientDatanodeProtocol datanode = getDataNodeProxy(argv[i]);
+    List<DatanodeVolumeInfo> volumeReport = datanode
+        .getVolumeReport();
+    System.out.println("Active Volumes : " + volumeReport.size());
+    for (DatanodeVolumeInfo info : volumeReport) {
+      System.out.println("\n" + info.getDatanodeVolumeReport());
+    }
+    return 0;
+  }
+
   private ClientDatanodeProtocol getDataNodeProxy(String datanode)
       throws IOException {
     InetSocketAddress datanodeAddr = NetUtils.createSocketAddr(datanode);

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cc66153e/hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/HDFSCommands.md
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/HDFSCommands.md b/hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/HDFSCommands.md
index cd1bd86..fd51924 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/HDFSCommands.md
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/HDFSCommands.md
@@ -344,6 +344,7 @@ Usage:
         hdfs dfsadmin [-reconfig <namenode|datanode> <host:ipc_port> <start
|status |properties>]
         hdfs dfsadmin [-printTopology]
         hdfs dfsadmin [-refreshNamenodes datanodehost:port]
+        hdfs dfsadmin [-getVolumeReport datanodehost:port]
         hdfs dfsadmin [-deleteBlockPool datanode-host:port blockpoolId [force]]
         hdfs dfsadmin [-setBalancerBandwidth <bandwidth in bytes per second>]
         hdfs dfsadmin [-getBalancerBandwidth <datanode_host:ipc_port>]
@@ -379,6 +380,7 @@ Usage:
 | `-reconfig` \<datanode \|namenode\> \<host:ipc\_port\> \<start\|status\|properties\>
| Starts reconfiguration or gets the status of an ongoing reconfiguration, or gets a list
of reconfigurable properties. The second parameter specifies the node type. |
 | `-printTopology` | Print a tree of the racks and their nodes as reported by the Namenode
|
 | `-refreshNamenodes` datanodehost:port | For the given datanode, reloads the configuration
files, stops serving the removed block-pools and starts serving new block-pools. |
+| `-getVolumeReport` datanodehost:port | For the given datanode, get the volume report. |
 | `-deleteBlockPool` datanode-host:port blockpoolId [force] | If force is passed, block pool
directory for the given blockpool id on the given datanode is deleted along with its contents,
otherwise the directory is deleted only if it is empty. The command will fail if datanode
is still serving the block pool. Refer to refreshNamenodes to shutdown a block pool service
on a datanode. |
 | `-setBalancerBandwidth` \<bandwidth in bytes per second\> | Changes the network bandwidth
used by each datanode during HDFS block balancing. \<bandwidth\> is the maximum number
of bytes per second that will be used by each datanode. This value overrides the dfs.balance.bandwidthPerSec
parameter. NOTE: The new value is not persistent on the DataNode. |
 | `-getBalancerBandwidth` \<datanode\_host:ipc\_port\> | Get the network bandwidth(in
bytes per second) for the given datanode. This is the maximum network bandwidth used by the
datanode during HDFS block balancing.|

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cc66153e/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
index 8acf0c1..6204f67 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
@@ -216,6 +216,26 @@ public class TestDFSAdmin {
     }
   }
 
+  @Test(timeout = 30000)
+  public void testGetVolumeReport() throws Exception {
+    redirectStream();
+    final DFSAdmin dfsAdmin = new DFSAdmin(conf);
+
+    for (int i = 0; i < cluster.getDataNodes().size(); i++) {
+      resetStream();
+      final DataNode dn = cluster.getDataNodes().get(i);
+      final String addr = String.format("%s:%d", dn.getXferAddress()
+          .getHostString(), dn.getIpcPort());
+      final int ret = ToolRunner.run(dfsAdmin, new String[] {
+          "-getVolumeReport", addr });
+      assertEquals(0, ret);
+
+      /* collect outputs */
+      final List<String> outs = Lists.newArrayList();
+      scanIntoList(out, outs);
+      assertEquals(outs.get(0), "Active Volumes : 2");
+    }
+  }
   /**
    * Test that if datanode is not reachable, some DFSAdmin commands will fail
    * elegantly with non-zero ret error code along with exception error message.


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message