diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ContentSummary.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ContentSummary.java index 20e205a8b3..80a6c0c05b 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ContentSummary.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ContentSummary.java @@ -281,6 +281,20 @@ public int hashCode() { private static final String ALL_HEADER = QUOTA_HEADER + SUMMARY_HEADER; + /** + * Output format: + * <--------20--------> + * ERASURECODING_POLICY + */ + private static final String ERASURECODING_POLICY_FORMAT = "%20s "; + + private static final String ERASURECODING_POLICY_HEADER_FIELD = + "ERASURECODING_POLICY"; + + /** The header string. */ + private static final String ERASURECODING_POLICY_HEADER = String.format( + ERASURECODING_POLICY_FORMAT, ERASURECODING_POLICY_HEADER_FIELD); + /** * Output format:<-------18-------> <----------24----------> * <----------24---------->. <-------------28------------> SNAPSHOT_LENGTH @@ -308,6 +322,10 @@ public static String getHeader(boolean qOption) { return qOption ? ALL_HEADER : SUMMARY_HEADER; } + public static String getErasureCodingPolicyHeader() { + return ERASURECODING_POLICY_HEADER; + } + public static String getSnapshotHeader() { return SNAPSHOT_HEADER; } @@ -444,6 +462,13 @@ private String formatSize(long size, boolean humanReadable) { : String.valueOf(size); } + /** + * @return Constant-width String representation of Erasure Coding Policy + */ + public String toErasureCodingPolicy() { + return String.format(ERASURECODING_POLICY_FORMAT, erasureCodingPolicy); + } + /** * Return the string representation of the snapshot counts in the output * format. diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/QuotaUsage.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/QuotaUsage.java index 11cc934017..b00a31891c 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/QuotaUsage.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/QuotaUsage.java @@ -242,12 +242,14 @@ public boolean equals(Object obj) { /** * Output format: - * |----12----| |------15-----| |------15-----| |------15-----| - * QUOTA REM_QUOTA SPACE_QUOTA REM_SPACE_QUOTA - * |----12----| |----12----| |-------18-------| - * DIR_COUNT FILE_COUNT CONTENT_SIZE + * |-----14-----| |-------18------| |-----14-----| |-------18------| + * SSD_QUOTA REM_SSD_QUOTA DISK_QUOTA REM_DISK_QUOTA + * |-----14-----| |-------18------| |-----14-----| |-------18------| + * ARCHIVE_QUOTA REM_ARCHIVE_QUOTA PROVIDED_QUOTA REM_PROVIDED_QUOTA + * |-----14-----| |-------18------| |-------18------| + * NVDIMM_QUOTA REM_NVDIMM_QUOTA PATHNAME */ - private static final String STORAGE_TYPE_SUMMARY_FORMAT = "%13s %17s "; + private static final String STORAGE_TYPE_SUMMARY_FORMAT = "%14s %18s "; /** Return the header of the output. * @return the header of the output diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Count.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Count.java index cb3858d63b..bd7be22972 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Count.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Count.java @@ -166,8 +166,8 @@ protected void processOptions(LinkedList args) { headString.append(ContentSummary.getHeader(showQuotas)); } } - if(displayECPolicy){ - headString.append("ERASURECODING_POLICY "); + if (displayECPolicy) { + headString.append(ContentSummary.getErasureCodingPolicyHeader()); } if (showSnapshot) { headString.append(ContentSummary.getSnapshotHeader()); @@ -204,13 +204,9 @@ protected void processPath(PathData src) throws IOException { outputString.append(summary.toString( showQuotas, isHumanReadable(), excludeSnapshots)); } - if(displayECPolicy){ + if (displayECPolicy) { ContentSummary summary = src.fs.getContentSummary(src.path); - if(!summary.getErasureCodingPolicy().equals("Replicated")){ - outputString.append("EC:"); - } - outputString.append(summary.getErasureCodingPolicy()) - .append(" "); + outputString.append(summary.toErasureCodingPolicy()); } if (showSnapshot) { ContentSummary summary = src.fs.getContentSummary(src.path); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCount.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCount.java index 19516b8c40..c86a4c89df 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCount.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCount.java @@ -282,11 +282,10 @@ public void processPathWithQuotasByStorageTypesHeader() throws Exception { options.add("dummy"); count.processOptions(options); String withStorageTypeHeader = - // <----13---> <-------17------> <----13-----> <------17-------> - " SSD_QUOTA REM_SSD_QUOTA DISK_QUOTA REM_DISK_QUOTA " + - // <----13---> <-------17------> - "ARCHIVE_QUOTA REM_ARCHIVE_QUOTA PROVIDED_QUOTA REM_PROVIDED_QUOTA " + - " NVDIMM_QUOTA REM_NVDIMM_QUOTA " + + // <----14----> <-------18-------> <-----14-----> <-------18-------> + " SSD_QUOTA REM_SSD_QUOTA DISK_QUOTA REM_DISK_QUOTA " + + " ARCHIVE_QUOTA REM_ARCHIVE_QUOTA PROVIDED_QUOTA REM_PROVIDED_QUOTA " + + " NVDIMM_QUOTA REM_NVDIMM_QUOTA " + "PATHNAME"; verify(out).println(withStorageTypeHeader); verifyNoMoreInteractions(out); @@ -311,8 +310,8 @@ public void processPathWithQuotasBySSDStorageTypesHeader() throws Exception { options.add("dummy"); count.processOptions(options); String withStorageTypeHeader = - // <----13---> <-------17------> - " SSD_QUOTA REM_SSD_QUOTA " + + // <----14----> <-------18-------> + " SSD_QUOTA REM_SSD_QUOTA " + "PATHNAME"; verify(out).println(withStorageTypeHeader); verifyNoMoreInteractions(out); @@ -337,12 +336,12 @@ public void processPathWithQuotasByQTVH() throws Exception { options.add("dummy"); count.processOptions(options); String withStorageTypeHeader = - // <----13---> <-------17------> - " SSD_QUOTA REM_SSD_QUOTA " + - " DISK_QUOTA REM_DISK_QUOTA " + - "ARCHIVE_QUOTA REM_ARCHIVE_QUOTA " + + // <----14----> <-------18-------> + " SSD_QUOTA REM_SSD_QUOTA " + + " DISK_QUOTA REM_DISK_QUOTA " + + " ARCHIVE_QUOTA REM_ARCHIVE_QUOTA " + "PROVIDED_QUOTA REM_PROVIDED_QUOTA " + - " NVDIMM_QUOTA REM_NVDIMM_QUOTA " + + " NVDIMM_QUOTA REM_NVDIMM_QUOTA " + "PATHNAME"; verify(out).println(withStorageTypeHeader); verifyNoMoreInteractions(out); @@ -405,9 +404,9 @@ public void processPathWithQuotasByMultipleStorageTypes() throws Exception { options.add("dummy"); count.processOptions(options); String withStorageTypeHeader = - // <----13---> <------17-------> - " SSD_QUOTA REM_SSD_QUOTA " + - " DISK_QUOTA REM_DISK_QUOTA " + + // <----14----> <------18--------> + " SSD_QUOTA REM_SSD_QUOTA " + + " DISK_QUOTA REM_DISK_QUOTA " + "PATHNAME"; verify(out).println(withStorageTypeHeader); verifyNoMoreInteractions(out);