private static List<QuotaSettings> fromQuotas(final String userName, final TableName tableName, final String namespace, final String regionServer, final Quotas quotas) { List<QuotaSettings> settings = new ArrayList<>(); if (quotas.hasThrottle()) { settings .addAll(fromThrottle(userName, tableName, namespace, regionServer, quotas.getThrottle())); } if (quotas.getBypassGlobals() == true) { settings .add(new QuotaGlobalsSettingsBypass(userName, tableName, namespace, regionServer, true)); } if (quotas.hasSpace()) { settings.add(fromSpace(tableName, namespace, quotas.getSpace())); } return settings; }
@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"))); }
@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")); }
public static boolean isEmptyQuota(final Quotas quotas) { boolean hasSettings = false; hasSettings |= quotas.hasThrottle(); hasSettings |= quotas.hasBypassGlobals(); // Only when there is a space quota, make sure there's actually both fields provided // Otherwise, it's a noop. if (quotas.hasSpace()) { hasSettings |= (quotas.getSpace().hasSoftLimit() && quotas.getSpace().hasViolationPolicy()); } return !hasSettings; }
private void assertSpaceQuota( long sizeLimit, SpaceViolationPolicy violationPolicy, Cell cell) throws Exception { Quotas q = QuotaTableUtil.quotasFromData( cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); assertTrue("Quota should have space quota defined", q.hasSpace()); QuotaProtos.SpaceQuota spaceQuota = q.getSpace(); assertEquals(sizeLimit, spaceQuota.getSoftLimit()); assertEquals(violationPolicy, ProtobufUtil.toViolationPolicy(spaceQuota.getViolationPolicy())); }
private static List<QuotaSettings> fromQuotas(final String userName, final TableName tableName, final String namespace, final Quotas quotas) { List<QuotaSettings> settings = new ArrayList<>(); if (quotas.hasThrottle()) { settings.addAll(fromThrottle(userName, tableName, namespace, quotas.getThrottle())); } if (quotas.getBypassGlobals() == true) { settings.add(new QuotaGlobalsSettingsBypass(userName, tableName, namespace, true)); } if (quotas.hasSpace()) { settings.add(fromSpace(tableName, namespace, quotas.getSpace())); } return settings; }
private static List<QuotaSettings> fromQuotas(final String userName, final TableName tableName, final String namespace, final Quotas quotas) { List<QuotaSettings> settings = new ArrayList<>(); if (quotas.hasThrottle()) { settings.addAll(fromThrottle(userName, tableName, namespace, quotas.getThrottle())); } if (quotas.getBypassGlobals() == true) { settings.add(new QuotaGlobalsSettingsBypass(userName, tableName, namespace, true)); } if (quotas.hasSpace()) { settings.add(fromSpace(tableName, namespace, quotas.getSpace())); } return settings; }
public static boolean isEmptyQuota(final Quotas quotas) { boolean hasSettings = false; hasSettings |= quotas.hasThrottle(); hasSettings |= quotas.hasBypassGlobals(); // Only when there is a space quota, make sure there's actually both fields provided // Otherwise, it's a noop. if (quotas.hasSpace()) { hasSettings |= (quotas.getSpace().hasSoftLimit() && quotas.getSpace().hasViolationPolicy()); } return !hasSettings; }
SpaceQuota spaceQuota = quota.getSpace();
Quotas quotaForTable = QuotaUtil.getTableQuota(getConnection(), tableName); if (quotaForTable != null && quotaForTable.hasSpace()) { SpaceViolationPolicy policy = quotaForTable.getSpace().getViolationPolicy(); if (SpaceViolationPolicy.DISABLE == policy) { throw new AccessDeniedException("Enabling the table '" + tableName
@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.Quotas)) { return super.equals(obj); } org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas other = (org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas) obj; boolean result = true; result = result && (hasBypassGlobals() == other.hasBypassGlobals()); if (hasBypassGlobals()) { result = result && (getBypassGlobals() == other.getBypassGlobals()); } result = result && (hasThrottle() == other.hasThrottle()); if (hasThrottle()) { result = result && getThrottle() .equals(other.getThrottle()); } result = result && (hasSpace() == other.hasSpace()); if (hasSpace()) { result = result && getSpace() .equals(other.getSpace()); } 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 (hasBypassGlobals()) { hash = (37 * hash) + BYPASS_GLOBALS_FIELD_NUMBER; hash = (53 * hash) + org.apache.hbase.thirdparty.com.google.protobuf.Internal.hashBoolean( getBypassGlobals()); } if (hasThrottle()) { hash = (37 * hash) + THROTTLE_FIELD_NUMBER; hash = (53 * hash) + getThrottle().hashCode(); } if (hasSpace()) { hash = (37 * hash) + SPACE_FIELD_NUMBER; hash = (53 * hash) + getSpace().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream .computeBoolSize(1, bypassGlobals_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream .computeMessageSize(2, getThrottle()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { size += org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream .computeMessageSize(3, getSpace()); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
public Builder mergeFrom(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas other) { if (other == org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas.getDefaultInstance()) return this; if (other.hasBypassGlobals()) { setBypassGlobals(other.getBypassGlobals()); } if (other.hasThrottle()) { mergeThrottle(other.getThrottle()); } if (other.hasSpace()) { mergeSpace(other.getSpace()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@Override public SpaceQuota getSpaceQuota(TableName subject) throws IOException { Quotas quotas = getQuotaForTable(subject); if (quotas != null && quotas.hasSpace()) { return quotas.getSpace(); } return null; } /**
public static boolean isEmptyQuota(final Quotas quotas) { boolean hasSettings = false; hasSettings |= quotas.hasThrottle(); hasSettings |= quotas.hasBypassGlobals(); // Only when there is a space quota, make sure there's actually both fields provided // Otherwise, it's a noop. if (quotas.hasSpace()) { hasSettings |= (quotas.getSpace().hasSoftLimit() && quotas.getSpace().hasViolationPolicy()); } return !hasSettings; }
@Override public SpaceQuota getSpaceQuota(String namespace) throws IOException { Quotas quotas = getQuotaForNamespace(namespace); if (quotas != null && quotas.hasSpace()) { return quotas.getSpace(); } return null; }
public void writeTo(org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeBool(1, bypassGlobals_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeMessage(2, getThrottle()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { output.writeMessage(3, getSpace()); } unknownFields.writeTo(output); }
private void assertSpaceQuota( long sizeLimit, SpaceViolationPolicy violationPolicy, Cell cell) throws Exception { Quotas q = QuotaTableUtil.quotasFromData( cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); assertTrue("Quota should have space quota defined", q.hasSpace()); QuotaProtos.SpaceQuota spaceQuota = q.getSpace(); assertEquals(sizeLimit, spaceQuota.getSoftLimit()); assertEquals(violationPolicy, ProtobufUtil.toViolationPolicy(spaceQuota.getViolationPolicy())); }
protected GlobalQuotaSettingsImpl(String username, TableName tableName, String namespace, String regionServer, QuotaProtos.Quotas quotas) { this(username, tableName, namespace, regionServer, (quotas != null && quotas.hasThrottle() ? quotas.getThrottle() : null), (quotas != null && quotas.hasBypassGlobals() ? quotas.getBypassGlobals() : null), (quotas != null && quotas.hasSpace() ? quotas.getSpace() : null)); }