use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class NamespacesInstanceResource method createOrUpdate.
// Do the actual namespace create or alter.
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 updateExisting ? Response.ok(uriInfo.getAbsolutePath()).build() : Response.created(uriInfo.getAbsolutePath()).build();
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class HMaster method listNamespaces.
/**
* List namespace names
* @return All namespace names
*/
public List<String> listNamespaces() throws IOException {
checkInitialized();
List<String> namespaces = new ArrayList<>();
if (cpHost != null) {
cpHost.preListNamespaces(namespaces);
}
for (NamespaceDescriptor namespace : clusterSchemaService.getNamespaces()) {
namespaces.add(namespace.getName());
}
if (cpHost != null) {
cpHost.postListNamespaces(namespaces);
}
return namespaces;
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class TestNamespacesInstanceResource method testNamespaceCreateAndDeleteXMLAndJSON.
@Test
public void testNamespaceCreateAndDeleteXMLAndJSON() throws IOException, JAXBException {
String namespacePath1 = "/namespaces/" + NAMESPACE1;
String namespacePath2 = "/namespaces/" + NAMESPACE2;
NamespacesInstanceModel model1;
NamespacesInstanceModel model2;
Response response;
// Check that namespaces don't exist via non-REST call.
Admin admin = TEST_UTIL.getAdmin();
assertNull(findNamespace(admin, NAMESPACE1));
assertNull(findNamespace(admin, NAMESPACE2));
model1 = testNamespacesInstanceModel.buildTestModel(NAMESPACE1, NAMESPACE1_PROPS);
testNamespacesInstanceModel.checkModel(model1, NAMESPACE1, NAMESPACE1_PROPS);
model2 = testNamespacesInstanceModel.buildTestModel(NAMESPACE2, NAMESPACE2_PROPS);
testNamespacesInstanceModel.checkModel(model2, NAMESPACE2, NAMESPACE2_PROPS);
// Test cannot PUT (alter) non-existent namespace.
response = client.put(namespacePath1, Constants.MIMETYPE_XML, toXML(model1));
assertEquals(403, response.getCode());
String jsonString = jsonMapper.writeValueAsString(model2);
response = client.put(namespacePath2, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
assertEquals(403, response.getCode());
// Test cannot create tables when in read only mode.
conf.set("hbase.rest.readonly", "true");
response = client.post(namespacePath1, Constants.MIMETYPE_XML, toXML(model1));
assertEquals(403, response.getCode());
jsonString = jsonMapper.writeValueAsString(model2);
response = client.post(namespacePath2, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
assertEquals(403, response.getCode());
NamespaceDescriptor nd1 = findNamespace(admin, NAMESPACE1);
NamespaceDescriptor nd2 = findNamespace(admin, NAMESPACE2);
assertNull(nd1);
assertNull(nd2);
conf.set("hbase.rest.readonly", "false");
// Create namespace via XML and JSON.
response = client.post(namespacePath1, Constants.MIMETYPE_XML, toXML(model1));
assertEquals(201, response.getCode());
jsonString = jsonMapper.writeValueAsString(model2);
response = client.post(namespacePath2, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
assertEquals(201, response.getCode());
// check passing null content-type with a payload returns 415
Header[] nullHeaders = null;
response = client.post(namespacePath1, nullHeaders, toXML(model1));
assertEquals(415, response.getCode());
response = client.post(namespacePath1, nullHeaders, Bytes.toBytes(jsonString));
assertEquals(415, response.getCode());
// Check that created namespaces correctly.
nd1 = findNamespace(admin, NAMESPACE1);
nd2 = findNamespace(admin, NAMESPACE2);
assertNotNull(nd1);
assertNotNull(nd2);
checkNamespaceProperties(nd1, NAMESPACE1_PROPS);
checkNamespaceProperties(nd1, NAMESPACE1_PROPS);
// Test cannot delete tables when in read only mode.
conf.set("hbase.rest.readonly", "true");
response = client.delete(namespacePath1);
assertEquals(403, response.getCode());
response = client.delete(namespacePath2);
assertEquals(403, response.getCode());
nd1 = findNamespace(admin, NAMESPACE1);
nd2 = findNamespace(admin, NAMESPACE2);
assertNotNull(nd1);
assertNotNull(nd2);
conf.set("hbase.rest.readonly", "false");
// Delete namespaces via XML and JSON.
response = client.delete(namespacePath1);
assertEquals(200, response.getCode());
response = client.delete(namespacePath2);
assertEquals(200, response.getCode());
nd1 = findNamespace(admin, NAMESPACE1);
nd2 = findNamespace(admin, NAMESPACE2);
assertNull(nd1);
assertNull(nd2);
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class TableNamespaceManager method loadNamespaceIntoCache.
private void loadNamespaceIntoCache() throws IOException {
try (Table table = masterServices.getConnection().getTable(TableName.META_TABLE_NAME);
ResultScanner scanner = table.getScanner(HConstants.NAMESPACE_FAMILY)) {
for (Result result; ; ) {
result = scanner.next();
if (result == null) {
break;
}
Cell cell = result.getColumnLatestCell(HConstants.NAMESPACE_FAMILY, HConstants.NAMESPACE_COL_DESC_QUALIFIER);
NamespaceDescriptor ns = ProtobufUtil.toNamespaceDescriptor(HBaseProtos.NamespaceDescriptor.parseFrom(CodedInputStream.newInstance(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())));
cache.put(ns.getName(), ns);
}
}
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class NamespaceStateManager method checkAndUpdateNamespaceTableCount.
synchronized void checkAndUpdateNamespaceTableCount(TableName table, int numRegions) throws IOException {
String namespace = table.getNamespaceAsString();
NamespaceDescriptor nspdesc = getNamespaceDescriptor(namespace);
if (nspdesc != null) {
NamespaceTableAndRegionInfo currentStatus;
currentStatus = getState(nspdesc.getName());
if ((currentStatus.getTables().size()) >= TableNamespaceManager.getMaxTables(nspdesc)) {
throw new QuotaExceededException("The table " + table.getNameAsString() + " cannot be created as it would exceed maximum number of tables allowed " + " in the namespace. The total number of tables permitted is " + TableNamespaceManager.getMaxTables(nspdesc));
}
if ((currentStatus.getRegionCount() + numRegions) > TableNamespaceManager.getMaxRegions(nspdesc)) {
throw new QuotaExceededException("The table " + table.getNameAsString() + " is not allowed to have " + numRegions + " regions. The total number of regions permitted is only " + TableNamespaceManager.getMaxRegions(nspdesc) + ", while current region count is " + currentStatus.getRegionCount() + ". This may be transient, please retry later if there are any" + " ongoing split operations in the namespace.");
}
} else {
throw new IOException("Namespace Descriptor found null for " + namespace + " This is unexpected.");
}
addTable(table, numRegions);
}
Aggregations