use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas in project hbase by apache.
the class QuotaTableUtil method parseTableResult.
protected static void parseTableResult(final TableName table, final Result result, final TableQuotasVisitor visitor) throws IOException {
byte[] data = result.getValue(QUOTA_FAMILY_INFO, QUOTA_QUALIFIER_SETTINGS);
if (data != null) {
Quotas quotas = quotasFromData(data);
visitor.visitTableQuotas(table, quotas);
}
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas in project hbase by apache.
the class TestWithDisabledAuthorization method testPassiveMasterOperations.
/** Test master observer */
@Test
public void testPassiveMasterOperations() throws Exception {
// preCreateTable
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
ACCESS_CONTROLLER.preCreateTable(ObserverContext.createAndPrepare(CP_ENV, null), htd, null);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preModifyTable
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
htd.addFamily(new HColumnDescriptor(TEST_FAMILY2));
ACCESS_CONTROLLER.preModifyTable(ObserverContext.createAndPrepare(CP_ENV, null), TEST_TABLE.getTableName(), htd);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preDeleteTable
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preDeleteTable(ObserverContext.createAndPrepare(CP_ENV, null), TEST_TABLE.getTableName());
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preTruncateTable
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preTruncateTable(ObserverContext.createAndPrepare(CP_ENV, null), TEST_TABLE.getTableName());
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preAddColumnFamily
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY2);
ACCESS_CONTROLLER.preAddColumnFamily(ObserverContext.createAndPrepare(CP_ENV, null), TEST_TABLE.getTableName(), hcd);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preModifyColumnFamily
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY2);
ACCESS_CONTROLLER.preModifyColumnFamily(ObserverContext.createAndPrepare(CP_ENV, null), TEST_TABLE.getTableName(), hcd);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preDeleteColumnFamily
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preDeleteColumnFamily(ObserverContext.createAndPrepare(CP_ENV, null), TEST_TABLE.getTableName(), TEST_FAMILY2);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preEnableTable
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preEnableTable(ObserverContext.createAndPrepare(CP_ENV, null), TEST_TABLE.getTableName());
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preDisableTable
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preDisableTable(ObserverContext.createAndPrepare(CP_ENV, null), TEST_TABLE.getTableName());
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preMove
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
HRegionInfo region = new HRegionInfo(TEST_TABLE.getTableName());
ServerName srcServer = ServerName.valueOf("1.1.1.1", 1, 0);
ServerName destServer = ServerName.valueOf("2.2.2.2", 2, 0);
ACCESS_CONTROLLER.preMove(ObserverContext.createAndPrepare(CP_ENV, null), region, srcServer, destServer);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preAssign
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
HRegionInfo region = new HRegionInfo(TEST_TABLE.getTableName());
ACCESS_CONTROLLER.preAssign(ObserverContext.createAndPrepare(CP_ENV, null), region);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preUnassign
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
HRegionInfo region = new HRegionInfo(TEST_TABLE.getTableName());
ACCESS_CONTROLLER.preUnassign(ObserverContext.createAndPrepare(CP_ENV, null), region, true);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preBalance
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preBalance(ObserverContext.createAndPrepare(CP_ENV, null));
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preBalanceSwitch
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preBalanceSwitch(ObserverContext.createAndPrepare(CP_ENV, null), true);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preSnapshot
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("foo").build();
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
ACCESS_CONTROLLER.preSnapshot(ObserverContext.createAndPrepare(CP_ENV, null), snapshot, htd);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preListSnapshot
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("foo").build();
ACCESS_CONTROLLER.preListSnapshot(ObserverContext.createAndPrepare(CP_ENV, null), snapshot);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preCloneSnapshot
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("foo").build();
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
ACCESS_CONTROLLER.preCloneSnapshot(ObserverContext.createAndPrepare(CP_ENV, null), snapshot, htd);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preRestoreSnapshot
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("foo").build();
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
ACCESS_CONTROLLER.preRestoreSnapshot(ObserverContext.createAndPrepare(CP_ENV, null), snapshot, htd);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preDeleteSnapshot
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("foo").build();
ACCESS_CONTROLLER.preDeleteSnapshot(ObserverContext.createAndPrepare(CP_ENV, null), snapshot);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preGetTableDescriptors
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
List<TableName> tableNamesList = Lists.newArrayList();
tableNamesList.add(TEST_TABLE.getTableName());
List<HTableDescriptor> descriptors = Lists.newArrayList();
ACCESS_CONTROLLER.preGetTableDescriptors(ObserverContext.createAndPrepare(CP_ENV, null), tableNamesList, descriptors, ".+");
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preGetTableNames
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
List<HTableDescriptor> descriptors = Lists.newArrayList();
ACCESS_CONTROLLER.preGetTableNames(ObserverContext.createAndPrepare(CP_ENV, null), descriptors, ".+");
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preCreateNamespace
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
NamespaceDescriptor ns = NamespaceDescriptor.create("test").build();
ACCESS_CONTROLLER.preCreateNamespace(ObserverContext.createAndPrepare(CP_ENV, null), ns);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preDeleteNamespace
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preDeleteNamespace(ObserverContext.createAndPrepare(CP_ENV, null), "test");
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preModifyNamespace
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
NamespaceDescriptor ns = NamespaceDescriptor.create("test").build();
ACCESS_CONTROLLER.preModifyNamespace(ObserverContext.createAndPrepare(CP_ENV, null), ns);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preGetNamespaceDescriptor
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preGetNamespaceDescriptor(ObserverContext.createAndPrepare(CP_ENV, null), "test");
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preListNamespaceDescriptors
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
List<NamespaceDescriptor> descriptors = Lists.newArrayList();
ACCESS_CONTROLLER.preListNamespaceDescriptors(ObserverContext.createAndPrepare(CP_ENV, null), descriptors);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preSplit
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preSplitRegion(ObserverContext.createAndPrepare(CP_ENV, null), TEST_TABLE.getTableName(), Bytes.toBytes("ss"));
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preSetUserQuota
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
Quotas quotas = Quotas.newBuilder().build();
ACCESS_CONTROLLER.preSetUserQuota(ObserverContext.createAndPrepare(CP_ENV, null), "testuser", quotas);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preSetTableQuota
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
Quotas quotas = Quotas.newBuilder().build();
ACCESS_CONTROLLER.preSetTableQuota(ObserverContext.createAndPrepare(CP_ENV, null), TEST_TABLE.getTableName(), quotas);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preSetNamespaceQuota
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
Quotas quotas = Quotas.newBuilder().build();
ACCESS_CONTROLLER.preSetNamespaceQuota(ObserverContext.createAndPrepare(CP_ENV, null), "test", quotas);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas in project hbase by apache.
the class MasterQuotaManager method setQuota.
private void setQuota(final SetQuotaRequest req, final SetQuotaOperations quotaOps) throws IOException, InterruptedException {
if (req.hasRemoveAll() && req.getRemoveAll() == true) {
quotaOps.preApply(null);
quotaOps.delete();
quotaOps.postApply(null);
return;
}
// Apply quota changes
Quotas quotas = quotaOps.fetch();
quotaOps.preApply(quotas);
Quotas.Builder builder = (quotas != null) ? quotas.toBuilder() : Quotas.newBuilder();
if (req.hasThrottle())
applyThrottle(builder, req.getThrottle());
if (req.hasBypassGlobals())
applyBypassGlobals(builder, req.getBypassGlobals());
// Submit new changes
quotas = builder.build();
if (QuotaUtil.isEmptyQuota(quotas)) {
quotaOps.delete();
} else {
quotaOps.update(quotas);
}
quotaOps.postApply(quotas);
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas in project hbase by apache.
the class TestQuotaTableUtil method testUserQuotaUtil.
@Test
public void testUserQuotaUtil() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
final String namespace = "testNS";
final String user = "testUser";
Quotas quotaNamespace = Quotas.newBuilder().setThrottle(Throttle.newBuilder().setReqNum(ProtobufUtil.toTimedQuota(50000, TimeUnit.SECONDS, QuotaScope.MACHINE)).build()).build();
Quotas quotaTable = Quotas.newBuilder().setThrottle(Throttle.newBuilder().setReqNum(ProtobufUtil.toTimedQuota(1000, TimeUnit.SECONDS, QuotaScope.MACHINE)).setWriteNum(ProtobufUtil.toTimedQuota(600, TimeUnit.SECONDS, QuotaScope.MACHINE)).setReadSize(ProtobufUtil.toTimedQuota(10000, TimeUnit.SECONDS, QuotaScope.MACHINE)).build()).build();
Quotas quota = Quotas.newBuilder().setThrottle(Throttle.newBuilder().setReqSize(ProtobufUtil.toTimedQuota(8192, TimeUnit.SECONDS, QuotaScope.MACHINE)).setWriteSize(ProtobufUtil.toTimedQuota(4096, TimeUnit.SECONDS, QuotaScope.MACHINE)).setReadNum(ProtobufUtil.toTimedQuota(1000, TimeUnit.SECONDS, QuotaScope.MACHINE)).build()).build();
// Add user global quota
QuotaUtil.addUserQuota(this.connection, user, quota);
Quotas resQuota = QuotaUtil.getUserQuota(this.connection, user);
assertEquals(quota, resQuota);
// Add user quota for table
QuotaUtil.addUserQuota(this.connection, user, tableName, quotaTable);
Quotas resQuotaTable = QuotaUtil.getUserQuota(this.connection, user, tableName);
assertEquals(quotaTable, resQuotaTable);
// Add user quota for namespace
QuotaUtil.addUserQuota(this.connection, user, namespace, quotaNamespace);
Quotas resQuotaNS = QuotaUtil.getUserQuota(this.connection, user, namespace);
assertEquals(quotaNamespace, resQuotaNS);
// Delete user global quota
QuotaUtil.deleteUserQuota(this.connection, user);
resQuota = QuotaUtil.getUserQuota(this.connection, user);
assertEquals(null, resQuota);
// Delete user quota for table
QuotaUtil.deleteUserQuota(this.connection, user, tableName);
resQuotaTable = QuotaUtil.getUserQuota(this.connection, user, tableName);
assertEquals(null, resQuotaTable);
// Delete user quota for namespace
QuotaUtil.deleteUserQuota(this.connection, user, namespace);
resQuotaNS = QuotaUtil.getUserQuota(this.connection, user, namespace);
assertEquals(null, resQuotaNS);
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas in project hbase by apache.
the class QuotaTableUtil method parseNamespaceResult.
protected static void parseNamespaceResult(final String namespace, final Result result, final NamespaceQuotasVisitor visitor) throws IOException {
byte[] data = result.getValue(QUOTA_FAMILY_INFO, QUOTA_QUALIFIER_SETTINGS);
if (data != null) {
Quotas quotas = quotasFromData(data);
visitor.visitNamespaceQuotas(namespace, quotas);
}
}
Aggregations