StringBuilder builder = new StringBuilder(); builder.append("TYPE => THROTTLE"); if (proto.hasType()) { builder.append(", THROTTLE_TYPE => "); builder.append(proto.getType().toString()); if (proto.hasTimedQuota()) { QuotaProtos.TimedQuota timedQuota = proto.getTimedQuota(); builder.append(", LIMIT => "); if (timedQuota.hasSoftLimit()) {
@Override protected ThrottleSettings merge(QuotaSettings other) throws IOException { if (other instanceof ThrottleSettings) { ThrottleSettings otherThrottle = (ThrottleSettings) other; // Make sure this and the other target the same "subject" validateQuotaTarget(other); QuotaProtos.ThrottleRequest.Builder builder = proto.toBuilder(); if (!otherThrottle.proto.hasType()) { return null; } QuotaProtos.ThrottleRequest otherProto = otherThrottle.proto; if (otherProto.hasTimedQuota()) { if (otherProto.hasTimedQuota()) { validateTimedQuota(otherProto.getTimedQuota()); } if (!proto.getType().equals(otherProto.getType())) { throw new IllegalArgumentException( "Cannot merge a ThrottleRequest for " + proto.getType() + " with " + otherProto.getType()); } QuotaProtos.TimedQuota.Builder timedQuotaBuilder = proto.getTimedQuota().toBuilder(); timedQuotaBuilder.mergeFrom(otherProto.getTimedQuota()); QuotaProtos.ThrottleRequest mergedReq = builder.setTimedQuota( timedQuotaBuilder.build()).build(); return new ThrottleSettings(getUserName(), getTableName(), getNamespace(), getRegionServer(), mergedReq); } } return this; }
StringBuilder builder = new StringBuilder(); builder.append("TYPE => THROTTLE"); if (proto.hasType()) { builder.append(", THROTTLE_TYPE => "); builder.append(proto.getType().toString()); if (proto.hasTimedQuota()) { QuotaProtos.TimedQuota timedQuota = proto.getTimedQuota(); builder.append(", LIMIT => "); if (timedQuota.hasSoftLimit()) {
.setSoftLimit(500).build(); QuotaProtos.ThrottleRequest writeThrottle = QuotaProtos.ThrottleRequest.newBuilder() .setTimedQuota(writeQuota).setType(QuotaProtos.ThrottleType.WRITE_NUMBER).build();
@Override protected ThrottleSettings merge(QuotaSettings other) throws IOException { if (other instanceof ThrottleSettings) { ThrottleSettings otherThrottle = (ThrottleSettings) other; // Make sure this and the other target the same "subject" validateQuotaTarget(other); QuotaProtos.ThrottleRequest.Builder builder = proto.toBuilder(); if (!otherThrottle.proto.hasType()) { return null; } QuotaProtos.ThrottleRequest otherProto = otherThrottle.proto; if (otherProto.hasTimedQuota()) { if (otherProto.hasTimedQuota()) { validateTimedQuota(otherProto.getTimedQuota()); } if (!proto.getType().equals(otherProto.getType())) { throw new IllegalArgumentException( "Cannot merge a ThrottleRequest for " + proto.getType() + " with " + otherProto.getType()); } QuotaProtos.TimedQuota.Builder timedQuotaBuilder = proto.getTimedQuota().toBuilder(); timedQuotaBuilder.mergeFrom(otherProto.getTimedQuota()); QuotaProtos.ThrottleRequest mergedReq = builder.setTimedQuota( timedQuotaBuilder.build()).build(); return new ThrottleSettings(getUserName(), getTableName(), getNamespace(), mergedReq); } } 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.ThrottleRequest)) { return super.equals(obj); } org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.ThrottleRequest other = (org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.ThrottleRequest) obj; boolean result = true; result = result && (hasType() == other.hasType()); if (hasType()) { result = result && type_ == other.type_; } result = result && (hasTimedQuota() == other.hasTimedQuota()); if (hasTimedQuota()) { result = result && getTimedQuota() .equals(other.getTimedQuota()); } result = result && unknownFields.equals(other.unknownFields); return result; }
@Test public void testMergeThrottle() throws IOException { QuotaProtos.Quotas quota = QuotaProtos.Quotas.newBuilder() .setThrottle(THROTTLE).build(); QuotaProtos.TimedQuota writeQuota = REQUEST_THROTTLE.toBuilder() .setSoftLimit(500).build(); // Unset the req throttle, set a write throttle QuotaProtos.ThrottleRequest writeThrottle = QuotaProtos.ThrottleRequest.newBuilder() .setTimedQuota(writeQuota).setType(QuotaProtos.ThrottleType.WRITE_NUMBER).build(); GlobalQuotaSettingsImpl settings = new GlobalQuotaSettingsImpl("joe", null, null, quota); GlobalQuotaSettingsImpl merged = settings.merge( new ThrottleSettings("joe", null, null, writeThrottle)); QuotaProtos.Throttle mergedThrottle = merged.getThrottleProto(); // Verify the request throttle is in place assertTrue(mergedThrottle.hasReqNum()); QuotaProtos.TimedQuota actualReqNum = mergedThrottle.getReqNum(); assertEquals(REQUEST_THROTTLE.getSoftLimit(), actualReqNum.getSoftLimit()); // Verify the write throttle is in place assertTrue(mergedThrottle.hasWriteNum()); QuotaProtos.TimedQuota actualWriteNum = mergedThrottle.getWriteNum(); assertEquals(writeQuota.getSoftLimit(), actualWriteNum.getSoftLimit()); }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasType()) { hash = (37 * hash) + TYPE_FIELD_NUMBER; hash = (53 * hash) + type_; } if (hasTimedQuota()) { hash = (37 * hash) + TIMED_QUOTA_FIELD_NUMBER; hash = (53 * hash) + getTimedQuota().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 .computeEnumSize(1, type_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream .computeMessageSize(2, getTimedQuota()); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
public ThrottleType getThrottleType() { return ProtobufUtil.toThrottleType(proto.getType()); }
public long getSoftLimit() { return proto.hasTimedQuota() ? proto.getTimedQuota().getSoftLimit() : -1; }
public static Builder newBuilder(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.ThrottleRequest prototype) { return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); } public Builder toBuilder() {
public static Builder newBuilder() { return DEFAULT_INSTANCE.toBuilder(); } public static Builder newBuilder(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.ThrottleRequest prototype) {
public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized == 1) return true; if (isInitialized == 0) return false; if (hasTimedQuota()) { if (!getTimedQuota().isInitialized()) { memoizedIsInitialized = 0; return false; } } memoizedIsInitialized = 1; return true; }
public TimeUnit getTimeUnit() { return proto.hasTimedQuota() ? ProtobufUtil.toTimeUnit(proto.getTimedQuota().getTimeUnit()) : null; }
public void writeTo(org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeEnum(1, type_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeMessage(2, getTimedQuota()); } unknownFields.writeTo(output); }
private static QuotaSettings throttle(final String userName, final TableName tableName, final String namespace, final ThrottleType type, final long limit, final TimeUnit timeUnit) { QuotaProtos.ThrottleRequest.Builder builder = QuotaProtos.ThrottleRequest.newBuilder(); if (type != null) { builder.setType(ProtobufUtil.toProtoThrottleType(type)); } if (timeUnit != null) { builder.setTimedQuota(ProtobufUtil.toTimedQuota(limit, timeUnit, QuotaScope.MACHINE)); } return new ThrottleSettings(userName, tableName, namespace, builder.build()); }
static ThrottleSettings fromTimedQuota(final String userName, final TableName tableName, final String namespace, ThrottleType type, QuotaProtos.TimedQuota timedQuota) { QuotaProtos.ThrottleRequest.Builder builder = QuotaProtos.ThrottleRequest.newBuilder(); builder.setType(ProtobufUtil.toProtoThrottleType(type)); builder.setTimedQuota(timedQuota); return new ThrottleSettings(userName, tableName, namespace, builder.build()); } }
public Builder mergeFrom(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.ThrottleRequest other) { if (other == org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.ThrottleRequest.getDefaultInstance()) return this; if (other.hasType()) { setType(other.getType()); } if (other.hasTimedQuota()) { mergeTimedQuota(other.getTimedQuota()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }