spaceBuilder.setRemove(true).clearSoftLimit().clearViolationPolicy(); } else { spaceBuilder.mergeFrom(quotaToMerge); (spaceBuilder == null) || (spaceBuilder.hasRemove() && spaceBuilder.getRemove()); getUserName(), getTableName(), getNamespace(), getRegionServer(), (throttleBuilder == null ? null : throttleBuilder.build()), bypassGlobals, (removeSpaceBuilder ? null : spaceBuilder.build()));
TableName tn3 = TableName.valueOf("observance2"); SpaceQuota quota = SpaceQuota.newBuilder() .setSoftLimit(1024L * 1024L) .setViolationPolicy(ProtobufUtil.toProtoViolationPolicy(SpaceViolationPolicy.DISABLE)) .build();
subBuilder.mergeFrom(space_); space_ = subBuilder.buildPartial();
subBuilder.mergeFrom(quota_); quota_ = subBuilder.buildPartial();
TableName tn3 = TableName.valueOf("observance2"); SpaceQuota quota = SpaceQuota.newBuilder() .setSoftLimit(1024L * 1024L) .setViolationPolicy(ProtobufUtil.toProtoViolationPolicy(SpaceViolationPolicy.DISABLE)) .build();
TableName tn3 = TableName.valueOf("tn3"); SpaceQuota quota = SpaceQuota.newBuilder() .setSoftLimit(ONE_MEGABYTE) .setViolationPolicy(ProtobufUtil.toProtoViolationPolicy(SpaceViolationPolicy.DISABLE)) .build();
@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; } }
/** * <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 { 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 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; } /**
@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"))); }
public Builder mergeFrom( org.apache.hbase.thirdparty.com.google.protobuf.CodedInputStream input, org.apache.hbase.thirdparty.com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota parsedMessage = null; try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException e) { parsedMessage = (org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota) e.getUnfinishedMessage(); throw e.unwrapIOException(); } finally { if (parsedMessage != null) { mergeFrom(parsedMessage); } } return this; } private int bitField0_;
/** * <code>optional .hbase.pb.SpaceQuota quota = 1;</code> */ public Builder setQuota( org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota.Builder builderForValue) { if (quotaBuilder_ == null) { quota_ = builderForValue.build(); onChanged(); } else { quotaBuilder_.setMessage(builderForValue.build()); } bitField0_ |= 0x00000001; return this; } /**
/** * <code>optional .hbase.pb.SpaceQuota space = 3;</code> */ public Builder setSpace( org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota.Builder builderForValue) { if (spaceBuilder_ == null) { space_ = builderForValue.build(); onChanged(); } else { spaceBuilder_.setMessage(builderForValue.build()); } bitField0_ |= 0x00000004; return this; } /**
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; }
/** * Builds a protocol buffer SpaceQuota. * * @param limit The maximum space usage for the quota in bytes. * @param violationPolicy The policy to apply when the quota is violated. * @return The protocol buffer SpaceQuota. */ public static QuotaProtos.SpaceQuota toProtoSpaceQuota( final long limit, final SpaceViolationPolicy violationPolicy) { return QuotaProtos.SpaceQuota.newBuilder() .setSoftLimit(limit) .setViolationPolicy(toProtoViolationPolicy(violationPolicy)) .build(); }
/** * 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 static Builder newBuilder(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota prototype) { return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); } public Builder toBuilder() {
@java.lang.Override protected Builder newBuilderForType( org.apache.hbase.thirdparty.com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } /**