Revert "HADOOP-15852. Refactor QuotaUsage. Contributed by Beluga Behr."
This reverts commit fb9deed41d
.
This commit is contained in:
parent
e89941fdbb
commit
aa89492f29
@ -40,12 +40,14 @@ public class QuotaUsage {
|
|||||||
/** Builder class for QuotaUsage. */
|
/** Builder class for QuotaUsage. */
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
public Builder() {
|
public Builder() {
|
||||||
this.quota = -1L;
|
this.quota = -1;
|
||||||
this.spaceQuota = -1L;
|
this.spaceQuota = -1;
|
||||||
|
|
||||||
typeConsumed = new long[StorageType.values().length];
|
typeConsumed = new long[StorageType.values().length];
|
||||||
typeQuota = new long[StorageType.values().length];
|
typeQuota = new long[StorageType.values().length];
|
||||||
Arrays.fill(typeQuota, -1L);
|
for (int i = 0; i < typeQuota.length; i++) {
|
||||||
|
typeQuota[i] = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder fileAndDirectoryCount(long count) {
|
public Builder fileAndDirectoryCount(long count) {
|
||||||
@ -69,8 +71,9 @@ public Builder spaceQuota(long spaceQuota) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Builder typeConsumed(long[] typeConsumed) {
|
public Builder typeConsumed(long[] typeConsumed) {
|
||||||
System.arraycopy(typeConsumed, 0, this.typeConsumed, 0,
|
for (int i = 0; i < typeConsumed.length; i++) {
|
||||||
typeConsumed.length);
|
this.typeConsumed[i] = typeConsumed[i];
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,8 +88,9 @@ public Builder typeConsumed(StorageType type, long consumed) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Builder typeQuota(long[] typeQuota) {
|
public Builder typeQuota(long[] typeQuota) {
|
||||||
System.arraycopy(typeQuota, 0, this.typeQuota, 0,
|
for (int i = 0; i < typeQuota.length; i++) {
|
||||||
typeQuota.length);
|
this.typeQuota[i] = typeQuota[i];
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,12 +153,22 @@ public long getSpaceQuota() {
|
|||||||
|
|
||||||
/** Return storage type quota. */
|
/** Return storage type quota. */
|
||||||
public long getTypeQuota(StorageType type) {
|
public long getTypeQuota(StorageType type) {
|
||||||
return (typeQuota != null) ? typeQuota[type.ordinal()] : -1L;
|
return (typeQuota != null) ? typeQuota[type.ordinal()] : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return storage type consumed. */
|
/** Return storage type consumed. */
|
||||||
public long getTypeConsumed(StorageType type) {
|
public long getTypeConsumed(StorageType type) {
|
||||||
return (typeConsumed != null) ? typeConsumed[type.ordinal()] : 0L;
|
return (typeConsumed != null) ? typeConsumed[type.ordinal()] : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return storage type quota. */
|
||||||
|
private long[] getTypesQuota() {
|
||||||
|
return typeQuota;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return storage type quota. */
|
||||||
|
private long[] getTypesConsumed() {
|
||||||
|
return typeConsumed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return true if any storage type quota has been set. */
|
/** Return true if any storage type quota has been set. */
|
||||||
@ -163,7 +177,7 @@ public boolean isTypeQuotaSet() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (StorageType t : StorageType.getTypesSupportingQuota()) {
|
for (StorageType t : StorageType.getTypesSupportingQuota()) {
|
||||||
if (typeQuota[t.ordinal()] > 0L) {
|
if (typeQuota[t.ordinal()] > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,7 +190,7 @@ public boolean isTypeConsumedAvailable() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (StorageType t : StorageType.getTypesSupportingQuota()) {
|
for (StorageType t : StorageType.getTypesSupportingQuota()) {
|
||||||
if (typeConsumed[t.ordinal()] > 0L) {
|
if (typeConsumed[t.ordinal()] > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,50 +198,33 @@ public boolean isTypeConsumedAvailable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public boolean equals(Object to) {
|
||||||
final int prime = 31;
|
return (this == to || (to instanceof QuotaUsage &&
|
||||||
int result = 1;
|
getFileAndDirectoryCount() ==
|
||||||
result = prime * result
|
((QuotaUsage) to).getFileAndDirectoryCount() &&
|
||||||
+ (int) (fileAndDirectoryCount ^ (fileAndDirectoryCount >>> 32));
|
getQuota() == ((QuotaUsage) to).getQuota() &&
|
||||||
result = prime * result + (int) (quota ^ (quota >>> 32));
|
getSpaceConsumed() == ((QuotaUsage) to).getSpaceConsumed() &&
|
||||||
result = prime * result + (int) (spaceConsumed ^ (spaceConsumed >>> 32));
|
getSpaceQuota() == ((QuotaUsage) to).getSpaceQuota() &&
|
||||||
result = prime * result + (int) (spaceQuota ^ (spaceQuota >>> 32));
|
Arrays.equals(getTypesQuota(), ((QuotaUsage) to).getTypesQuota()) &&
|
||||||
result = prime * result + Arrays.hashCode(typeConsumed);
|
Arrays.equals(getTypesConsumed(),
|
||||||
result = prime * result + Arrays.hashCode(typeQuota);
|
((QuotaUsage) to).getTypesConsumed())));
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public int hashCode() {
|
||||||
if (this == obj) {
|
long result = (getFileAndDirectoryCount() ^ getQuota() ^
|
||||||
return true;
|
getSpaceConsumed() ^ getSpaceQuota());
|
||||||
|
if (getTypesQuota() != null) {
|
||||||
|
for (long quota : getTypesQuota()) {
|
||||||
|
result ^= quota;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (obj == null) {
|
if (getTypesConsumed() != null) {
|
||||||
return false;
|
for (long consumed : getTypesConsumed()) {
|
||||||
|
result ^= consumed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
return (int)result;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
QuotaUsage other = (QuotaUsage) obj;
|
|
||||||
if (fileAndDirectoryCount != other.fileAndDirectoryCount) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (quota != other.quota) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (spaceConsumed != other.spaceConsumed) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (spaceQuota != other.spaceQuota) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Arrays.equals(typeConsumed, other.typeConsumed)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Arrays.equals(typeQuota, other.typeQuota)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -295,11 +292,11 @@ protected String getQuotaUsage(boolean hOption) {
|
|||||||
String spaceQuotaStr = QUOTA_NONE;
|
String spaceQuotaStr = QUOTA_NONE;
|
||||||
String spaceQuotaRem = QUOTA_INF;
|
String spaceQuotaRem = QUOTA_INF;
|
||||||
|
|
||||||
if (quota > 0L) {
|
if (quota > 0) {
|
||||||
quotaStr = formatSize(quota, hOption);
|
quotaStr = formatSize(quota, hOption);
|
||||||
quotaRem = formatSize(quota-fileAndDirectoryCount, hOption);
|
quotaRem = formatSize(quota-fileAndDirectoryCount, hOption);
|
||||||
}
|
}
|
||||||
if (spaceQuota >= 0L) {
|
if (spaceQuota >= 0) {
|
||||||
spaceQuotaStr = formatSize(spaceQuota, hOption);
|
spaceQuotaStr = formatSize(spaceQuota, hOption);
|
||||||
spaceQuotaRem = formatSize(spaceQuota - spaceConsumed, hOption);
|
spaceQuotaRem = formatSize(spaceQuota - spaceConsumed, hOption);
|
||||||
}
|
}
|
||||||
@ -310,7 +307,7 @@ protected String getQuotaUsage(boolean hOption) {
|
|||||||
|
|
||||||
protected String getTypesQuotaUsage(boolean hOption,
|
protected String getTypesQuotaUsage(boolean hOption,
|
||||||
List<StorageType> types) {
|
List<StorageType> types) {
|
||||||
StringBuilder content = new StringBuilder();
|
StringBuffer content = new StringBuffer();
|
||||||
for (StorageType st : types) {
|
for (StorageType st : types) {
|
||||||
long typeQuota = getTypeQuota(st);
|
long typeQuota = getTypeQuota(st);
|
||||||
long typeConsumed = getTypeConsumed(st);
|
long typeConsumed = getTypeConsumed(st);
|
||||||
@ -335,12 +332,13 @@ protected String getTypesQuotaUsage(boolean hOption,
|
|||||||
* @return storage header string
|
* @return storage header string
|
||||||
*/
|
*/
|
||||||
public static String getStorageTypeHeader(List<StorageType> storageTypes) {
|
public static String getStorageTypeHeader(List<StorageType> storageTypes) {
|
||||||
StringBuilder header = new StringBuilder();
|
StringBuffer header = new StringBuffer();
|
||||||
|
|
||||||
for (StorageType st : storageTypes) {
|
for (StorageType st : storageTypes) {
|
||||||
/* the field length is 13/17 for quota and remain quota
|
/* the field length is 13/17 for quota and remain quota
|
||||||
* as the max length for quota name is ARCHIVE_QUOTA
|
* as the max length for quota name is ARCHIVE_QUOTA
|
||||||
* and remain quota name REM_ARCHIVE_QUOTA */
|
* and remain quota name REM_ARCHIVE_QUOTA */
|
||||||
final String storageName = st.toString();
|
String storageName = st.toString();
|
||||||
header.append(String.format(STORAGE_TYPE_SUMMARY_FORMAT,
|
header.append(String.format(STORAGE_TYPE_SUMMARY_FORMAT,
|
||||||
storageName + "_QUOTA", "REM_" + storageName + "_QUOTA"));
|
storageName + "_QUOTA", "REM_" + storageName + "_QUOTA"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user