Search in sources :

Example 11 with NamespaceDescriptor

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();
}
Also used : NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) IOException(java.io.IOException)

Example 12 with NamespaceDescriptor

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;
}
Also used : ArrayList(java.util.ArrayList) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor)

Example 13 with NamespaceDescriptor

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);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) TestNamespacesInstanceModel(org.apache.hadoop.hbase.rest.model.TestNamespacesInstanceModel) NamespacesInstanceModel(org.apache.hadoop.hbase.rest.model.NamespacesInstanceModel) Header(org.apache.http.Header) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) Admin(org.apache.hadoop.hbase.client.Admin) Test(org.junit.Test)

Example 14 with NamespaceDescriptor

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);
        }
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) Cell(org.apache.hadoop.hbase.Cell) Result(org.apache.hadoop.hbase.client.Result)

Example 15 with NamespaceDescriptor

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);
}
Also used : QuotaExceededException(org.apache.hadoop.hbase.quotas.QuotaExceededException) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) IOException(java.io.IOException)

Aggregations

NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)97 Test (org.junit.Test)51 TableName (org.apache.hadoop.hbase.TableName)26 IOException (java.io.IOException)17 Admin (org.apache.hadoop.hbase.client.Admin)15 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)13 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)11 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)11 QuotaExceededException (org.apache.hadoop.hbase.quotas.QuotaExceededException)9 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)8 Table (org.apache.hadoop.hbase.client.Table)8 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)7 NamespaceNotFoundException (org.apache.hadoop.hbase.NamespaceNotFoundException)7 Connection (org.apache.hadoop.hbase.client.Connection)7 ConstraintException (org.apache.hadoop.hbase.constraint.ConstraintException)7 RestoreSnapshotException (org.apache.hadoop.hbase.snapshot.RestoreSnapshotException)7 KeeperException (org.apache.zookeeper.KeeperException)7 ArrayList (java.util.ArrayList)6 ExecutionException (java.util.concurrent.ExecutionException)5 NamespaceExistException (org.apache.hadoop.hbase.NamespaceExistException)5