protected void wipeOutMeta() throws IOException { // Mess it up by blowing up meta. Admin admin = TEST_UTIL.getHBaseAdmin(); Scan s = new Scan(); Table meta = new HTable(conf, TableName.META_TABLE_NAME); ResultScanner scanner = meta.getScanner(s); List<Delete> dels = new ArrayList<Delete>(); for (Result r : scanner) { HRegionInfo info = HRegionInfo.getHRegionInfo(r); if(info != null && !info.getTable().getNamespaceAsString() .equals(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR)) { Delete d = new Delete(r.getRow()); dels.add(d); admin.unassign(r.getRow(), true); } } meta.delete(dels); scanner.close(); meta.close(); }
public OpenedRegionHandler(Server server, AssignmentManager assignmentManager, HRegionInfo regionInfo, OpenRegionCoordination coordination, OpenRegionCoordination.OpenRegionDetails ord) { super(server, EventType.RS_ZK_REGION_OPENED); this.assignmentManager = assignmentManager; this.regionInfo = regionInfo; this.coordination = coordination; this.ord = ord; if(regionInfo.isMetaRegion()) { priority = OpenedPriority.META; } else if(regionInfo.getTable() .getNamespaceAsString().equals(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR)) { priority = OpenedPriority.SYSTEM; } else { priority = OpenedPriority.USER; } }
@Override public NamespaceDescriptor getNamespaceDescriptor(String name) throws IOException { checkNamespaceManagerReady(); if (cpHost != null) { cpHost.preGetNamespaceDescriptor(name); } NamespaceDescriptor nsd = tableNamespaceManager.get(name); if (nsd == null) { throw new NamespaceNotFoundException(name); } if (cpHost != null) { cpHost.postGetNamespaceDescriptor(nsd); } return nsd; }
@Override public List<NamespaceDescriptor> listNamespaceDescriptors() throws IOException { checkNamespaceManagerReady(); final List<NamespaceDescriptor> descriptors = new ArrayList<NamespaceDescriptor>(); boolean bypass = false; if (cpHost != null) { bypass = cpHost.preListNamespaceDescriptors(descriptors); } if (!bypass) { descriptors.addAll(tableNamespaceManager.list()); if (cpHost != null) { cpHost.postListNamespaceDescriptors(descriptors); } } return descriptors; }
/** * Removes the table descriptors that don't match the pattern. * @param descriptors list of table descriptors to filter * @param pattern the regex to use */ private static void filterTablesByRegex(final Collection<HTableDescriptor> descriptors, final Pattern pattern) { final String defaultNS = NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR; Iterator<HTableDescriptor> itr = descriptors.iterator(); while (itr.hasNext()) { HTableDescriptor htd = itr.next(); String tableName = htd.getTableName().getNameAsString(); boolean matched = pattern.matcher(tableName).matches(); if (!matched && htd.getTableName().getNamespaceAsString().equals(defaultNS)) { matched = pattern.matcher(defaultNS + TableName.NAMESPACE_DELIM + tableName).matches(); } if (!matched) { itr.remove(); } } }
/** * List available namespace descriptors * @return List of descriptors * @throws IOException */ @Override public NamespaceDescriptor[] listNamespaceDescriptors() throws IOException { return executeCallable(new MasterCallable<NamespaceDescriptor[]>(getConnection()) { @Override public NamespaceDescriptor[] call(int callTimeout) throws Exception { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setCallTimeout(callTimeout); List<HBaseProtos.NamespaceDescriptor> list = master.listNamespaceDescriptors(controller, ListNamespaceDescriptorsRequest.newBuilder().build()) .getNamespaceDescriptorList(); NamespaceDescriptor[] res = new NamespaceDescriptor[list.size()]; for(int i = 0; i < list.size(); i++) { res[i] = ProtobufUtil.toNamespaceDescriptor(list.get(i)); } return res; } }); }
/** * Check and update region count for an existing table. To handle scenarios like restore snapshot * @param TableName name of the table for region count needs to be checked and updated * @param incr count of regions * @throws QuotaExceededException if quota exceeds for the number of regions allowed in a * namespace * @throws IOException Signals that an I/O exception has occurred. */ synchronized void checkAndUpdateNamespaceRegionCount(TableName name, int incr) throws IOException { String namespace = name.getNamespaceAsString(); NamespaceDescriptor nspdesc = getNamespaceDescriptor(namespace); if (nspdesc != null) { NamespaceTableAndRegionInfo currentStatus = getState(namespace); int regionCountOfTable = currentStatus.getRegionCountOfTable(name); if ((currentStatus.getRegionCount() - regionCountOfTable + incr) > TableNamespaceManager .getMaxRegions(nspdesc)) { throw new QuotaExceededException("The table " + name.getNameAsString() + " region count cannot be updated as it would exceed maximum number " + "of regions allowed in the namespace. The total number of regions permitted is " + TableNamespaceManager.getMaxRegions(nspdesc)); } currentStatus.removeTable(name); currentStatus.addTable(name, incr); } }
/** * Initialize namespace state cache by scanning meta table. */ private void initialize() throws IOException { List<NamespaceDescriptor> namespaces = this.master.listNamespaceDescriptors(); for (NamespaceDescriptor namespace : namespaces) { addNamespace(namespace.getName()); List<TableName> tables = this.master.listTableNamesByNamespace(namespace.getName()); for (TableName table : tables) { if (table.isSystemTable()) { continue; } int regionCount = 0; Map<HRegionInfo, ServerName> regions = MetaScanner.allTableRegions(this.master.getConnection(), table); for (HRegionInfo info : regions.keySet()) { if (!info.isSplit()) { regionCount++; } } addTable(table, regionCount); } } LOG.info("Finished updating state of " + nsStateCache.size() + " namespaces. "); initialized = true; }
@Before public void setUp() throws Exception { createNamespace(TEST_UTIL, NamespaceDescriptor.create(namespace).build()); try (Table table = createTable(TEST_UTIL, tableName, new byte[][] { TEST_FAMILY, TEST_FAMILY_2 })) { TEST_UTIL.waitTableEnabled(tableName); // Ingesting test data. table.put(Arrays.asList(new Put(TEST_ROW).addColumn(TEST_FAMILY, Q1, value1), new Put(TEST_ROW_2).addColumn(TEST_FAMILY, Q2, value2), new Put(TEST_ROW_3).addColumn(TEST_FAMILY_2, Q1, value1))); } assertEquals(1, AccessControlLists.getTablePermissions(conf, tableName).size()); try { assertEquals(1, AccessControlClient.getUserPermissions(systemUserConnection, tableName.toString()) .size()); } catch (Throwable e) { LOG.error("Error during call of AccessControlClient.getUserPermissions. ", e); } }
/** * Create a new namespace * @param descriptor descriptor which describes the new namespace * @throws IOException */ @Override public void createNamespace(final NamespaceDescriptor descriptor) throws IOException { executeCallable(new MasterCallable<Void>(getConnection()) { @Override public Void call(int callTimeout) throws Exception { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setCallTimeout(callTimeout); // TODO: set priority based on NS? master.createNamespace(controller, CreateNamespaceRequest.newBuilder() .setNamespaceDescriptor(ProtobufUtil .toProtoNamespaceDescriptor(descriptor)).build() ); return null; } }); }
@Test public void testModifyNamespace() throws Exception { AccessTestAction modifyNamespace = new AccessTestAction() { @Override public Object run() throws Exception { ACCESS_CONTROLLER.preModifyNamespace(ObserverContext.createAndPrepare(CP_ENV, null), NamespaceDescriptor.create(TEST_NAMESPACE).addConfiguration("abc", "156").build()); return null; } }; // modifyNamespace: superuser | global(A) | NS(A) verifyAllowed(modifyNamespace, SUPERUSER, USER_GLOBAL_ADMIN, USER_GROUP_ADMIN); verifyDenied(modifyNamespace, USER_GLOBAL_CREATE, USER_GLOBAL_WRITE, USER_GLOBAL_READ, USER_GLOBAL_EXEC, USER_NS_ADMIN, USER_NS_CREATE, USER_NS_WRITE, USER_NS_READ, USER_NS_EXEC, USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE); }
@Test (timeout=180000) public void testGetNamespacePermission() throws Exception { String namespace = "testGetNamespacePermission"; NamespaceDescriptor desc = NamespaceDescriptor.create(namespace).build(); createNamespace(TEST_UTIL, desc); grantOnNamespace(TEST_UTIL, USER_NONE.getShortName(), namespace, Permission.Action.READ); try { List<UserPermission> namespacePermissions = AccessControlClient.getUserPermissions( systemUserConnection, AccessControlLists.toNamespaceEntry(namespace)); assertTrue(namespacePermissions != null); assertTrue(namespacePermissions.size() == 1); } catch (Throwable thw) { throw new HBaseException(thw); } deleteNamespace(TEST_UTIL, namespace); }
private Response createOrUpdate(final NamespacesInstanceModel model, final UriInfo uriInfo, final Admin admin, final boolean updateExisting) { NamespaceDescriptor.Builder builder = NamespaceDescriptor.create(namespace); builder.addConfiguration(model.getProperties()); if(model.getProperties().size() > 0){ builder.addConfiguration(model.getProperties()); } NamespaceDescriptor nsd = builder.build(); try{ if(updateExisting){ admin.modifyNamespace(nsd); }else{ admin.createNamespace(nsd); } }catch (IOException e) { servlet.getMetrics().incrementFailedPutRequests(1); return processException(e); } servlet.getMetrics().incrementSucessfulPutRequests(1); return Response.created(uriInfo.getAbsolutePath()).build(); }
@Test(expected = QuotaExceededException.class) public void testExceedTableQuotaInNamespace() throws Exception { String nsp = prefix + "_testExceedTableQuotaInNamespace"; NamespaceDescriptor nspDesc = NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "1") .build(); ADMIN.createNamespace(nspDesc); assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp)); assertEquals(ADMIN.listNamespaceDescriptors().length, 3); HTableDescriptor tableDescOne = new HTableDescriptor(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1")); HTableDescriptor tableDescTwo = new HTableDescriptor(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table2")); ADMIN.createTable(tableDescOne); ADMIN.createTable(tableDescTwo, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4); }
@Test(expected = QuotaExceededException.class) public void testCloneSnapshotQuotaExceed() throws Exception { String nsp = prefix + "_testTableQuotaExceedWithCloneSnapshot"; NamespaceDescriptor nspDesc = NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "1") .build(); ADMIN.createNamespace(nspDesc); assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp)); TableName tableName = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1"); TableName cloneTableName = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table2"); HTableDescriptor tableDescOne = new HTableDescriptor(tableName); ADMIN.createTable(tableDescOne); String snapshot = "snapshot_testTableQuotaExceedWithCloneSnapshot"; ADMIN.snapshot(snapshot, tableName); ADMIN.cloneSnapshot(snapshot, cloneTableName); ADMIN.deleteSnapshot(snapshot); }
@Override public void preModifyNamespace(ObserverContext<MasterCoprocessorEnvironment> ctx, NamespaceDescriptor ns) throws IOException { // We require only global permission so that // a user with NS admin cannot altering namespace configurations. i.e. namespace quota requireGlobalPermission("modifyNamespace", Action.ADMIN, ns.getName()); }
@Override public void postListNamespaceDescriptors(ObserverContext<MasterCoprocessorEnvironment> ctx, List<NamespaceDescriptor> descriptors) throws IOException { // Retains only those which passes authorization checks, as the checks weren't done as part // of preGetTableDescriptors. Iterator<NamespaceDescriptor> itr = descriptors.iterator(); while (itr.hasNext()) { NamespaceDescriptor desc = itr.next(); try { requireNamespacePermission("listNamespaces", desc.getName(), Action.ADMIN); } catch (AccessDeniedException e) { itr.remove(); } } }
public void init() throws IOException { this.rootDir = FSUtils.getRootDir(conf); FSUtils.setFsDefault(getConf(), rootDir); this.fs = FileSystem.get(conf); Path tmpDataDir = new Path(rootDir, TMP_DATA_DIR); sysNsDir = new Path(tmpDataDir, NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR); defNsDir = new Path(tmpDataDir, NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR); baseDirs = new Path[]{rootDir, new Path(rootDir, HConstants.HFILE_ARCHIVE_DIRECTORY), new Path(rootDir, HConstants.HBASE_TEMP_DIRECTORY)}; backupDir = new Path(rootDir, HConstants.MIGRATION_NAME); }
/** * Rename all the dot dirs -- .data, .archive, etc. -- as data, archive, etc.; i.e. minus the dot. * @throws IOException */ public void migrateDotDirs() throws IOException { // Dot dirs to rename. Leave the tmp dir named '.tmp' and snapshots as .hbase-snapshot. final Path archiveDir = new Path(rootDir, HConstants.HFILE_ARCHIVE_DIRECTORY); Path [][] dirs = new Path[][] { new Path [] {new Path(rootDir, DOT_CORRUPT), new Path(rootDir, HConstants.CORRUPT_DIR_NAME)}, new Path [] {new Path(rootDir, DOT_LOGS), new Path(rootDir, HConstants.HREGION_LOGDIR_NAME)}, new Path [] {new Path(rootDir, DOT_OLD_LOGS), new Path(rootDir, HConstants.HREGION_OLDLOGDIR_NAME)}, new Path [] {new Path(rootDir, TMP_DATA_DIR), new Path(rootDir, HConstants.BASE_NAMESPACE_DIR)}, new Path[] { new Path(rootDir, DOT_LIB_DIR), new Path(rootDir, HConstants.LIB_DIR)}}; for (Path [] dir: dirs) { Path src = dir[0]; Path tgt = dir[1]; if (!this.fs.exists(src)) { LOG.info("Does not exist: " + src); continue; } rename(src, tgt); } // Do the .archive dir. Need to move its subdirs to the default ns dir under data dir... so // from '.archive/foo', to 'archive/data/default/foo'. Path oldArchiveDir = new Path(rootDir, DOT_ARCHIVE); if (this.fs.exists(oldArchiveDir)) { // This is a pain doing two nn calls but portable over h1 and h2. mkdirs(archiveDir); Path archiveDataDir = new Path(archiveDir, HConstants.BASE_NAMESPACE_DIR); mkdirs(archiveDataDir); rename(oldArchiveDir, new Path(archiveDataDir, NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR)); } // Update the system and user namespace dirs removing the dot in front of .data. Path dataDir = new Path(rootDir, HConstants.BASE_NAMESPACE_DIR); sysNsDir = new Path(dataDir, NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR); defNsDir = new Path(dataDir, NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR); }
public boolean preCreateNamespace(final NamespaceDescriptor ns) throws IOException { return execOperation(coprocessors.isEmpty() ? null : new CoprocessorOperation() { @Override public void call(MasterObserver oserver, ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException { oserver.preCreateNamespace(ctx, ns); } }); }
public void postCreateNamespace(final NamespaceDescriptor ns) throws IOException { execOperation(coprocessors.isEmpty() ? null : new CoprocessorOperation() { @Override public void call(MasterObserver oserver, ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException { oserver.postCreateNamespace(ctx, ns); } }); }
public boolean preModifyNamespace(final NamespaceDescriptor ns) throws IOException { return execOperation(coprocessors.isEmpty() ? null : new CoprocessorOperation() { @Override public void call(MasterObserver oserver, ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException { oserver.preModifyNamespace(ctx, ns); } }); }
public void postModifyNamespace(final NamespaceDescriptor ns) throws IOException { execOperation(coprocessors.isEmpty() ? null : new CoprocessorOperation() { @Override public void call(MasterObserver oserver, ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException { oserver.postModifyNamespace(ctx, ns); } }); }
public void postGetNamespaceDescriptor(final NamespaceDescriptor ns) throws IOException { execOperation(coprocessors.isEmpty() ? null : new CoprocessorOperation() { @Override public void call(MasterObserver oserver, ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException { oserver.postGetNamespaceDescriptor(ctx, ns); } }); }
public boolean preListNamespaceDescriptors(final List<NamespaceDescriptor> descriptors) throws IOException { return execOperation(coprocessors.isEmpty() ? null : new CoprocessorOperation() { @Override public void call(MasterObserver oserver, ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException { oserver.preListNamespaceDescriptors(ctx, descriptors); } }); }
public void postListNamespaceDescriptors(final List<NamespaceDescriptor> descriptors) throws IOException { execOperation(coprocessors.isEmpty() ? null : new CoprocessorOperation() { @Override public void call(MasterObserver oserver, ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException { oserver.postListNamespaceDescriptors(ctx, descriptors); } }); }
@Override public void createNamespace(NamespaceDescriptor descriptor) throws IOException { TableName.isLegalNamespaceName(Bytes.toBytes(descriptor.getName())); checkNamespaceManagerReady(); if (cpHost != null) { if (cpHost.preCreateNamespace(descriptor)) { return; } } LOG.info(getClientIdAuditPrefix() + " creating " + descriptor); tableNamespaceManager.create(descriptor); if (cpHost != null) { cpHost.postCreateNamespace(descriptor); } }
@Test public void testInvalidNamespacePostsAndPuts() throws IOException, JAXBException { String namespacePath1 = "/namespaces/" + NAMESPACE1; String namespacePath2 = "/namespaces/" + NAMESPACE2; String namespacePath3 = "/namespaces/" + NAMESPACE3; NamespacesInstanceModel model1; NamespacesInstanceModel model2; NamespacesInstanceModel model3; Response response; // Check that namespaces don't exist via non-REST call. Admin admin = TEST_UTIL.getHBaseAdmin(); assertNull(findNamespace(admin, NAMESPACE1)); assertNull(findNamespace(admin, NAMESPACE2)); assertNull(findNamespace(admin, NAMESPACE3)); model1 = testNamespacesInstanceModel.buildTestModel(NAMESPACE1, NAMESPACE1_PROPS); testNamespacesInstanceModel.checkModel(model1, NAMESPACE1, NAMESPACE1_PROPS); model2 = testNamespacesInstanceModel.buildTestModel(NAMESPACE2, NAMESPACE2_PROPS); testNamespacesInstanceModel.checkModel(model2, NAMESPACE2, NAMESPACE2_PROPS); model3 = testNamespacesInstanceModel.buildTestModel(NAMESPACE3, NAMESPACE3_PROPS); testNamespacesInstanceModel.checkModel(model3, NAMESPACE3, NAMESPACE3_PROPS); // Try REST post and puts with invalid content. response = client.post(namespacePath1, Constants.MIMETYPE_JSON, toXML(model1)); assertEquals(500, response.getCode()); String jsonString = jsonMapper.writeValueAsString(model2); response = client.put(namespacePath2, Constants.MIMETYPE_XML, Bytes.toBytes(jsonString)); assertEquals(400, response.getCode()); response = client.post(namespacePath3, Constants.MIMETYPE_PROTOBUF, toXML(model1)); assertEquals(500, response.getCode()); NamespaceDescriptor nd1 = findNamespace(admin, NAMESPACE1); NamespaceDescriptor nd2 = findNamespace(admin, NAMESPACE2); NamespaceDescriptor nd3 = findNamespace(admin, NAMESPACE3); assertNull(nd1); assertNull(nd2); assertNull(nd3); }
/** * Ensure that the specified namespace exists, otherwise throws a NamespaceNotFoundException * * @param name the namespace to check * @throws IOException if the namespace manager is not ready yet. * @throws NamespaceNotFoundException if the namespace does not exists */ private void ensureNamespaceExists(final String name) throws IOException, NamespaceNotFoundException { checkNamespaceManagerReady(); NamespaceDescriptor nsd = tableNamespaceManager.get(name); if (nsd == null) { throw new NamespaceNotFoundException(name); } }
public synchronized void update(NamespaceDescriptor ns) throws IOException { Table table = getNamespaceTable(); if (get(table, ns.getName()) == null) { throw new NamespaceNotFoundException(ns.getName()); } upsert(table, ns); }
private NamespaceDescriptor get(Table table, String name) throws IOException { Result res = table.get(new Get(Bytes.toBytes(name))); if (res.isEmpty()) { return null; } byte[] val = CellUtil.cloneValue(res.getColumnLatestCell( HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES, HTableDescriptor.NAMESPACE_COL_DESC_BYTES)); return ProtobufUtil.toNamespaceDescriptor( HBaseProtos.NamespaceDescriptor.parseFrom(val)); }
private void create(Table table, NamespaceDescriptor ns) throws IOException { if (get(table, ns.getName()) != null) { throw new NamespaceExistException(ns.getName()); } validateTableAndRegionCount(ns); FileSystem fs = masterServices.getMasterFileSystem().getFileSystem(); fs.mkdirs(FSUtils.getNamespaceDir( masterServices.getMasterFileSystem().getRootDir(), ns.getName())); upsert(table, ns); if (this.masterServices.isInitialized()) { this.masterServices.getMasterQuotaManager().setNamespaceQuota(ns); } }
private void upsert(Table table, NamespaceDescriptor ns) throws IOException { validateTableAndRegionCount(ns); Put p = new Put(Bytes.toBytes(ns.getName())); p.addImmutable(HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES, HTableDescriptor.NAMESPACE_COL_DESC_BYTES, ProtobufUtil.toProtoNamespaceDescriptor(ns).toByteArray()); table.put(p); try { zkNamespaceManager.update(ns); } catch(IOException ex) { String msg = "Failed to update namespace information in ZK. Aborting."; LOG.fatal(msg, ex); masterServices.abort(msg, ex); } }
public synchronized void remove(String name) throws IOException { if (get(name) == null) { throw new NamespaceNotFoundException(name); } if (NamespaceDescriptor.RESERVED_NAMESPACES.contains(name)) { throw new ConstraintException("Reserved namespace "+name+" cannot be removed."); } int tableCount; try { tableCount = masterServices.listTableDescriptorsByNamespace(name).size(); } catch (FileNotFoundException fnfe) { throw new NamespaceNotFoundException(name); } if (tableCount > 0) { throw new ConstraintException("Only empty namespaces can be removed. " + "Namespace "+name+" has "+tableCount+" tables"); } Delete d = new Delete(Bytes.toBytes(name)); getNamespaceTable().delete(d); //don't abort if cleanup isn't complete //it will be replaced on new namespace creation zkNamespaceManager.remove(name); FileSystem fs = masterServices.getMasterFileSystem().getFileSystem(); for(FileStatus status : fs.listStatus(FSUtils.getNamespaceDir( masterServices.getMasterFileSystem().getRootDir(), name))) { if (!HConstants.HBASE_NON_TABLE_DIRS.contains(status.getPath().getName())) { throw new IOException("Namespace directory contains table dir: "+status.getPath()); } } if (!fs.delete(FSUtils.getNamespaceDir( masterServices.getMasterFileSystem().getRootDir(), name), true)) { throw new IOException("Failed to remove namespace: "+name); } this.masterServices.getMasterQuotaManager().removeNamespaceQuota(name); }
void validateTableAndRegionCount(NamespaceDescriptor desc) throws IOException { if (getMaxRegions(desc) <= 0) { throw new ConstraintException("The max region quota for " + desc.getName() + " is less than or equal to zero."); } if (getMaxTables(desc) <= 0) { throw new ConstraintException("The max tables quota for " + desc.getName() + " is less than or equal to zero."); } }
public static long getMaxTables(NamespaceDescriptor ns) throws IOException { String value = ns.getConfigurationValue(KEY_MAX_TABLES); long maxTables = 0; if (StringUtils.isNotEmpty(value)) { try { maxTables = Long.parseLong(value); } catch (NumberFormatException exp) { throw new DoNotRetryIOException("NumberFormatException while getting max tables.", exp); } } else { // The property is not set, so assume its the max long value. maxTables = Long.MAX_VALUE; } return maxTables; }
public static long getMaxRegions(NamespaceDescriptor ns) throws IOException { String value = ns.getConfigurationValue(KEY_MAX_REGIONS); long maxRegions = 0; if (StringUtils.isNotEmpty(value)) { try { maxRegions = Long.parseLong(value); } catch (NumberFormatException exp) { throw new DoNotRetryIOException("NumberFormatException while getting max regions.", exp); } } else { // The property is not set, so assume its the max long value. maxRegions = Long.MAX_VALUE; } return maxRegions; }
@Override public ListNamespaceDescriptorsResponse listNamespaceDescriptors(RpcController c, ListNamespaceDescriptorsRequest request) throws ServiceException { try { ListNamespaceDescriptorsResponse.Builder response = ListNamespaceDescriptorsResponse.newBuilder(); for(NamespaceDescriptor ns: master.listNamespaceDescriptors()) { response.addNamespaceDescriptor(ProtobufUtil.toProtoNamespaceDescriptor(ns)); } return response.build(); } catch (IOException e) { throw new ServiceException(e); } }
public static NamespaceDescriptor toNamespaceDescriptor( HBaseProtos.NamespaceDescriptor desc) throws IOException { NamespaceDescriptor.Builder b = NamespaceDescriptor.create(desc.getName().toStringUtf8()); for(HBaseProtos.NameStringPair prop : desc.getConfigurationList()) { b.addConfiguration(prop.getName(), prop.getValue()); } return b.build(); }
/** * Modify an existing namespace * @param descriptor descriptor which describes the new namespace * @throws IOException */ @Override public void modifyNamespace(final NamespaceDescriptor descriptor) throws IOException { executeCallable(new MasterCallable<Void>(getConnection()) { @Override public Void call(int callTimeout) throws Exception { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setCallTimeout(callTimeout); master.modifyNamespace(controller, ModifyNamespaceRequest.newBuilder(). setNamespaceDescriptor(ProtobufUtil.toProtoNamespaceDescriptor(descriptor)).build()); return null; } }); }