out.print( StringUtils.byteDesc(spaceQuota.getSoftLimit()) ); out.write("</td>\n </tr>\n <tr>\n <td>Policy</td>\n <td>"); out.print( spaceQuota.getViolationPolicy() ); out.write("</td>\n </tr>\n");
TableName tn2 = TableName.valueOf("observance1"); TableName tn3 = TableName.valueOf("observance2"); SpaceQuota quota = SpaceQuota.newBuilder() .setSoftLimit(1024L * 1024L) .setViolationPolicy(ProtobufUtil.toProtoViolationPolicy(SpaceViolationPolicy.DISABLE))
builder.append(", NAMESPACE => ").append(getNamespace()); if (spaceProto.getRemove()) { builder.append(", REMOVE => ").append(spaceProto.getRemove()); } else { builder.append(", LIMIT => ").append(sizeToString(spaceProto.getSoftLimit())); builder.append(", VIOLATION_POLICY => ").append(spaceProto.getViolationPolicy());
org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota.Builder subBuilder = null; if (((bitField0_ & 0x00000004) == 0x00000004)) { subBuilder = space_.toBuilder();
org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota.Builder subBuilder = null; if (((bitField0_ & 0x00000001) == 0x00000001)) { subBuilder = quota_.toBuilder();
TableName tn2 = TableName.valueOf("observance1"); TableName tn3 = TableName.valueOf("observance2"); SpaceQuota quota = SpaceQuota.newBuilder() .setSoftLimit(1024L * 1024L) .setViolationPolicy(ProtobufUtil.toProtoViolationPolicy(SpaceViolationPolicy.DISABLE))
TableName tn2 = TableName.valueOf(NS, "tn2"); TableName tn3 = TableName.valueOf("tn3"); SpaceQuota quota = SpaceQuota.newBuilder() .setSoftLimit(ONE_MEGABYTE) .setViolationPolicy(ProtobufUtil.toProtoViolationPolicy(SpaceViolationPolicy.DISABLE))
new ThrottleSettings(null, null, ns, writeThrottle)); GlobalQuotaSettingsImpl finalQuota = merged.merge(new SpaceLimitSettings( ns, SPACE_QUOTA.getSoftLimit(), SpaceViolationPolicy.NO_WRITES_COMPACTIONS)); assertEquals(SPACE_QUOTA.getSoftLimit(), finalSpaceQuota.getSoftLimit()); assertEquals( QuotaProtos.SpaceViolationPolicy.NO_WRITES_COMPACTIONS, finalSpaceQuota.getViolationPolicy());
@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 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; }
@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; }
@Test public void testGetSpaceQuota() throws Exception { NamespaceQuotaSnapshotStore mockStore = mock(NamespaceQuotaSnapshotStore.class); when(mockStore.getSpaceQuota(any())).thenCallRealMethod(); Quotas quotaWithSpace = Quotas.newBuilder().setSpace( SpaceQuota.newBuilder() .setSoftLimit(1024L) .setViolationPolicy(QuotaProtos.SpaceViolationPolicy.DISABLE) .build()) .build(); Quotas quotaWithoutSpace = Quotas.newBuilder().build(); AtomicReference<Quotas> quotaRef = new AtomicReference<>(); when(mockStore.getQuotaForNamespace(any())).then(new Answer<Quotas>() { @Override public Quotas answer(InvocationOnMock invocation) throws Throwable { return quotaRef.get(); } }); quotaRef.set(quotaWithSpace); assertEquals(quotaWithSpace.getSpace(), mockStore.getSpaceQuota("ns")); quotaRef.set(quotaWithoutSpace); assertNull(mockStore.getSpaceQuota("ns")); }
/** * <code>optional .hbase.pb.SpaceQuota quota = 1;</code> */ public Builder mergeQuota(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota value) { if (quotaBuilder_ == null) { if (((bitField0_ & 0x00000001) == 0x00000001) && quota_ != null && quota_ != org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota.getDefaultInstance()) { quota_ = org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota.newBuilder(quota_).mergeFrom(value).buildPartial(); } else { quota_ = value; } onChanged(); } else { quotaBuilder_.mergeFrom(value); } bitField0_ |= 0x00000001; return this; } /**
@Test public void testGetSpaceQuota() throws Exception { TableQuotaSnapshotStore mockStore = mock(TableQuotaSnapshotStore.class); when(mockStore.getSpaceQuota(any())).thenCallRealMethod(); Quotas quotaWithSpace = Quotas.newBuilder().setSpace( SpaceQuota.newBuilder() .setSoftLimit(1024L) .setViolationPolicy(QuotaProtos.SpaceViolationPolicy.DISABLE) .build()) .build(); Quotas quotaWithoutSpace = Quotas.newBuilder().build(); AtomicReference<Quotas> quotaRef = new AtomicReference<>(); when(mockStore.getQuotaForTable(any())).then(new Answer<Quotas>() { @Override public Quotas answer(InvocationOnMock invocation) throws Throwable { return quotaRef.get(); } }); quotaRef.set(quotaWithSpace); assertEquals(quotaWithSpace.getSpace(), mockStore.getSpaceQuota(TableName.valueOf("foo"))); quotaRef.set(quotaWithoutSpace); assertNull(mockStore.getSpaceQuota(TableName.valueOf("foo"))); }
/** * <code>optional .hbase.pb.SpaceQuota space = 3;</code> */ public Builder mergeSpace(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota value) { if (spaceBuilder_ == null) { if (((bitField0_ & 0x00000004) == 0x00000004) && space_ != null && space_ != org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota.getDefaultInstance()) { space_ = org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota.newBuilder(space_).mergeFrom(value).buildPartial(); } else { space_ = value; } onChanged(); } else { spaceBuilder_.mergeFrom(value); } bitField0_ |= 0x00000004; 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); } }
@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 newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
/** * Builds a {@link SpaceQuota} protobuf object given the arguments. * * @param sizeLimit The size limit of the quota. * @param violationPolicy The action to take when the quota is exceeded. * @return The protobuf SpaceQuota representation. */ private SpaceLimitRequest buildProtoAddQuota( long sizeLimit, SpaceViolationPolicy violationPolicy) { return buildProtoFromQuota(SpaceQuota.newBuilder() .setSoftLimit(sizeLimit) .setViolationPolicy(ProtobufUtil.toProtoViolationPolicy(violationPolicy)) .build()); }
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; }