@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("TYPE => SPACE"); if (getTableName() != null) { sb.append(", TABLE => ").append(getTableName()); } if (getNamespace() != null) { sb.append(", NAMESPACE => ").append(getNamespace()); } if (proto.getQuota().getRemove()) { sb.append(", REMOVE => ").append(proto.getQuota().getRemove()); } else { sb.append(", LIMIT => ").append(sizeToString(proto.getQuota().getSoftLimit())); sb.append(", VIOLATION_POLICY => ").append(proto.getQuota().getViolationPolicy()); } return sb.toString(); }
static QuotaSettings fromSpace(TableName table, String namespace, SpaceQuota protoQuota) { if (protoQuota == null) { return null; } if ((table == null && namespace == null) || (table != null && namespace != null)) { throw new IllegalArgumentException( "Can only construct SpaceLimitSettings for a table or namespace."); } if (table != null) { if (protoQuota.getRemove()) { return new SpaceLimitSettings(table); } return SpaceLimitSettings.fromSpaceQuota(table, protoQuota); } else { if (protoQuota.getRemove()) { return new SpaceLimitSettings(namespace); } // namespace must be non-null return SpaceLimitSettings.fromSpaceQuota(namespace, protoQuota); } }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota)) { return super.equals(obj); } org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota other = (org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota) obj; boolean result = true; result = result && (hasSoftLimit() == other.hasSoftLimit()); if (hasSoftLimit()) { result = result && (getSoftLimit() == other.getSoftLimit()); } result = result && (hasViolationPolicy() == other.hasViolationPolicy()); if (hasViolationPolicy()) { result = result && violationPolicy_ == other.violationPolicy_; } result = result && (hasRemove() == other.hasRemove()); if (hasRemove()) { result = result && (getRemove() == other.getRemove()); } result = result && unknownFields.equals(other.unknownFields); return result; }
static QuotaSettings fromSpace(TableName table, String namespace, SpaceQuota protoQuota) { if (protoQuota == null) { return null; } if ((table == null && namespace == null) || (table != null && namespace != null)) { throw new IllegalArgumentException( "Can only construct SpaceLimitSettings for a table or namespace."); } if (table != null) { if (protoQuota.getRemove()) { return new SpaceLimitSettings(table); } return SpaceLimitSettings.fromSpaceQuota(table, protoQuota); } else { if (protoQuota.getRemove()) { return new SpaceLimitSettings(namespace); } // namespace must be non-null return SpaceLimitSettings.fromSpaceQuota(namespace, protoQuota); } }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasSoftLimit()) { hash = (37 * hash) + SOFT_LIMIT_FIELD_NUMBER; hash = (53 * hash) + org.apache.hbase.thirdparty.com.google.protobuf.Internal.hashLong( getSoftLimit()); } if (hasViolationPolicy()) { hash = (37 * hash) + VIOLATION_POLICY_FIELD_NUMBER; hash = (53 * hash) + violationPolicy_; } if (hasRemove()) { hash = (37 * hash) + REMOVE_FIELD_NUMBER; hash = (53 * hash) + org.apache.hbase.thirdparty.com.google.protobuf.Internal.hashBoolean( getRemove()); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("TYPE => SPACE"); if (getTableName() != null) { sb.append(", TABLE => ").append(getTableName()); } if (getNamespace() != null) { sb.append(", NAMESPACE => ").append(getNamespace()); } if (proto.getQuota().getRemove()) { sb.append(", REMOVE => ").append(proto.getQuota().getRemove()); } else { sb.append(", LIMIT => ").append(proto.getQuota().getSoftLimit()); sb.append(", VIOLATION_POLICY => ").append(proto.getQuota().getViolationPolicy()); } return sb.toString(); }
public Builder mergeFrom(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota other) { if (other == org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota.getDefaultInstance()) return this; if (other.hasSoftLimit()) { setSoftLimit(other.getSoftLimit()); } if (other.hasViolationPolicy()) { setViolationPolicy(other.getViolationPolicy()); } if (other.hasRemove()) { setRemove(other.getRemove()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@Override protected QuotaSettings merge(QuotaSettings newSettings) { if (newSettings instanceof SpaceLimitSettings) { SpaceLimitSettings settingsToMerge = (SpaceLimitSettings) newSettings; // The message contained the expect SpaceQuota object if (settingsToMerge.proto.hasQuota()) { SpaceQuota quotaToMerge = settingsToMerge.proto.getQuota(); if (quotaToMerge.getRemove()) { return settingsToMerge; } else { // Validate that the two settings are for the same target. // SpaceQuotas either apply to a table or a namespace (no user spacequota). if (!Objects.equals(getTableName(), settingsToMerge.getTableName()) && !Objects.equals(getNamespace(), settingsToMerge.getNamespace())) { throw new IllegalArgumentException("Cannot merge " + newSettings + " into " + this); } // Create a builder from the old settings SpaceQuota.Builder mergedBuilder = this.proto.getQuota().toBuilder(); // Build a new SpaceQuotas object from merging in the new settings return new SpaceLimitSettings( getTableName(), getNamespace(), buildProtoFromQuota(mergedBuilder.mergeFrom(quotaToMerge).build())); } } // else, we don't know what to do, so return the original object } return this; } }
static QuotaSettings fromSpace(TableName table, String namespace, SpaceQuota protoQuota) { if (protoQuota == null) { return null; } if ((table == null && namespace == null) || (table != null && namespace != null)) { throw new IllegalArgumentException( "Can only construct SpaceLimitSettings for a table or namespace."); } if (table != null) { if (protoQuota.getRemove()) { return new SpaceLimitSettings(table); } return SpaceLimitSettings.fromSpaceQuota(table, protoQuota); } else { if (protoQuota.getRemove()) { return new SpaceLimitSettings(namespace); } // namespace must be non-null return SpaceLimitSettings.fromSpaceQuota(namespace, protoQuota); } }
@Test public void testSpaceLimitSettingsForDeletes() { final String ns = "ns1"; final TableName tn = TableName.valueOf("tn1"); QuotaSettings nsSettings = QuotaSettingsFactory.removeNamespaceSpaceLimit(ns); assertNotNull("QuotaSettings should not be null", nsSettings); assertTrue("Should be an instance of SpaceLimitSettings", nsSettings instanceof SpaceLimitSettings); SpaceLimitRequest nsProto = ((SpaceLimitSettings) nsSettings).getProto(); assertTrue("Request should have a SpaceQuota", nsProto.hasQuota()); assertTrue("The remove attribute should be true", nsProto.getQuota().getRemove()); QuotaSettings tableSettings = QuotaSettingsFactory.removeTableSpaceLimit(tn); assertNotNull("QuotaSettings should not be null", tableSettings); assertTrue("Should be an instance of SpaceLimitSettings", tableSettings instanceof SpaceLimitSettings); SpaceLimitRequest tableProto = ((SpaceLimitSettings) tableSettings).getProto(); assertTrue("Request should have a SpaceQuota", tableProto.hasQuota()); assertTrue("The remove attribute should be true", tableProto.getQuota().getRemove()); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("TYPE => SPACE"); if (getTableName() != null) { sb.append(", TABLE => ").append(getTableName()); } if (getNamespace() != null) { sb.append(", NAMESPACE => ").append(getNamespace()); } if (proto.getQuota().getRemove()) { sb.append(", REMOVE => ").append(proto.getQuota().getRemove()); } else { sb.append(", LIMIT => ").append(sizeToString(proto.getQuota().getSoftLimit())); sb.append(", VIOLATION_POLICY => ").append(proto.getQuota().getViolationPolicy()); } return sb.toString(); }
@Test public void testSpaceLimitSettings() { final TableName tableName = TableName.valueOf("foo"); final long sizeLimit = 1024L * 1024L * 1024L * 75; // 75GB final SpaceViolationPolicy violationPolicy = SpaceViolationPolicy.NO_INSERTS; QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(tableName, sizeLimit, violationPolicy); assertNotNull("QuotaSettings should not be null", settings); assertTrue("Should be an instance of SpaceLimitSettings", settings instanceof SpaceLimitSettings); SpaceLimitSettings spaceLimitSettings = (SpaceLimitSettings) settings; SpaceLimitRequest protoRequest = spaceLimitSettings.getProto(); assertTrue("Request should have a SpaceQuota", protoRequest.hasQuota()); SpaceQuota quota = protoRequest.getQuota(); assertEquals(sizeLimit, quota.getSoftLimit()); assertEquals(violationPolicy, ProtobufUtil.toViolationPolicy(quota.getViolationPolicy())); assertFalse("The remove attribute should be false", quota.getRemove()); }
if (quotaToMerge.getRemove()) {
@Override protected QuotaSettings merge(QuotaSettings newSettings) { if (newSettings instanceof SpaceLimitSettings) { SpaceLimitSettings settingsToMerge = (SpaceLimitSettings) newSettings; // The message contained the expect SpaceQuota object if (settingsToMerge.proto.hasQuota()) { SpaceQuota quotaToMerge = settingsToMerge.proto.getQuota(); if (quotaToMerge.getRemove()) { return settingsToMerge; } else { // Validate that the two settings are for the same target. // SpaceQuotas either apply to a table or a namespace (no user spacequota). if (!Objects.equals(getTableName(), settingsToMerge.getTableName()) && !Objects.equals(getNamespace(), settingsToMerge.getNamespace())) { throw new IllegalArgumentException("Cannot merge " + newSettings + " into " + this); } // Create a builder from the old settings SpaceQuota.Builder mergedBuilder = this.proto.getQuota().toBuilder(); // Build a new SpaceQuotas object from merging in the new settings return new SpaceLimitSettings( getTableName(), getNamespace(), buildProtoFromQuota(mergedBuilder.mergeFrom(quotaToMerge).build())); } } // else, we don't know what to do, so return the original object } return this; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasSoftLimit()) { hash = (37 * hash) + SOFT_LIMIT_FIELD_NUMBER; hash = (53 * hash) + org.apache.hbase.thirdparty.com.google.protobuf.Internal.hashLong( getSoftLimit()); } if (hasViolationPolicy()) { hash = (37 * hash) + VIOLATION_POLICY_FIELD_NUMBER; hash = (53 * hash) + violationPolicy_; } if (hasRemove()) { hash = (37 * hash) + REMOVE_FIELD_NUMBER; hash = (53 * hash) + org.apache.hbase.thirdparty.com.google.protobuf.Internal.hashBoolean( getRemove()); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota)) { return super.equals(obj); } org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota other = (org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota) obj; boolean result = true; result = result && (hasSoftLimit() == other.hasSoftLimit()); if (hasSoftLimit()) { result = result && (getSoftLimit() == other.getSoftLimit()); } result = result && (hasViolationPolicy() == other.hasViolationPolicy()); if (hasViolationPolicy()) { result = result && violationPolicy_ == other.violationPolicy_; } result = result && (hasRemove() == other.hasRemove()); if (hasRemove()) { result = result && (getRemove() == other.getRemove()); } result = result && unknownFields.equals(other.unknownFields); return result; }
@Test public void testSpaceLimitSettingsForDeletes() { final String ns = "ns1"; final TableName tn = TableName.valueOf("tn1"); QuotaSettings nsSettings = QuotaSettingsFactory.removeNamespaceSpaceLimit(ns); assertNotNull("QuotaSettings should not be null", nsSettings); assertTrue("Should be an instance of SpaceLimitSettings", nsSettings instanceof SpaceLimitSettings); SpaceLimitRequest nsProto = ((SpaceLimitSettings) nsSettings).getProto(); assertTrue("Request should have a SpaceQuota", nsProto.hasQuota()); assertTrue("The remove attribute should be true", nsProto.getQuota().getRemove()); QuotaSettings tableSettings = QuotaSettingsFactory.removeTableSpaceLimit(tn); assertNotNull("QuotaSettings should not be null", tableSettings); assertTrue("Should be an instance of SpaceLimitSettings", tableSettings instanceof SpaceLimitSettings); SpaceLimitRequest tableProto = ((SpaceLimitSettings) tableSettings).getProto(); assertTrue("Request should have a SpaceQuota", tableProto.hasQuota()); assertTrue("The remove attribute should be true", tableProto.getQuota().getRemove()); } }
@Test public void testSpaceLimitSettings() { final TableName tableName = TableName.valueOf("foo"); final long sizeLimit = 1024L * 1024L * 1024L * 75; // 75GB final SpaceViolationPolicy violationPolicy = SpaceViolationPolicy.NO_INSERTS; QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(tableName, sizeLimit, violationPolicy); assertNotNull("QuotaSettings should not be null", settings); assertTrue("Should be an instance of SpaceLimitSettings", settings instanceof SpaceLimitSettings); SpaceLimitSettings spaceLimitSettings = (SpaceLimitSettings) settings; SpaceLimitRequest protoRequest = spaceLimitSettings.getProto(); assertTrue("Request should have a SpaceQuota", protoRequest.hasQuota()); SpaceQuota quota = protoRequest.getQuota(); assertEquals(sizeLimit, quota.getSoftLimit()); assertEquals(violationPolicy, ProtobufUtil.toViolationPolicy(quota.getViolationPolicy())); assertFalse("The remove attribute should be false", quota.getRemove()); }
public Builder mergeFrom(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota other) { if (other == org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota.getDefaultInstance()) return this; if (other.hasSoftLimit()) { setSoftLimit(other.getSoftLimit()); } if (other.hasViolationPolicy()) { setViolationPolicy(other.getViolationPolicy()); } if (other.hasRemove()) { setRemove(other.getRemove()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }