Search in sources :

Example 1 with TableListModel

use of org.apache.hadoop.hbase.rest.model.TableListModel in project hbase by apache.

the class RootResource method getTableList.

private final TableListModel getTableList() throws IOException {
    TableListModel tableList = new TableListModel();
    TableName[] tableNames = servlet.getAdmin().listTableNames();
    for (TableName name : tableNames) {
        tableList.add(new TableModel(name.getNameAsString()));
    }
    return tableList;
}
Also used : TableName(org.apache.hadoop.hbase.TableName) TableListModel(org.apache.hadoop.hbase.rest.model.TableListModel) TableModel(org.apache.hadoop.hbase.rest.model.TableModel)

Example 2 with TableListModel

use of org.apache.hadoop.hbase.rest.model.TableListModel in project hbase by apache.

the class TestNamespacesInstanceResource method testGetNamespaceTablesAndCannotDeleteNamespace.

@Test
public void testGetNamespaceTablesAndCannotDeleteNamespace() throws IOException, JAXBException {
    Admin admin = TEST_UTIL.getAdmin();
    String nsName = "TestNamespacesInstanceResource5";
    Response response;
    // Create namespace via admin.
    NamespaceDescriptor.Builder nsBuilder = NamespaceDescriptor.create(nsName);
    NamespaceDescriptor nsd = nsBuilder.build();
    nsd.setConfiguration("key1", "value1");
    admin.createNamespace(nsd);
    // Create two tables via admin.
    TableName tn1 = TableName.valueOf(nsName + ":table1");
    TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tn1);
    ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf1")).build();
    tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
    admin.createTable(tableDescriptorBuilder.build());
    TableName tn2 = TableName.valueOf(nsName + ":table2");
    tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tn2);
    tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
    admin.createTable(tableDescriptorBuilder.build());
    Map<String, String> nsProperties = new HashMap<>();
    nsProperties.put("key1", "value1");
    List<String> nsTables = Arrays.asList("table1", "table2");
    // Check get namespace properties as XML, JSON and Protobuf.
    String namespacePath = "/namespaces/" + nsName;
    response = client.get(namespacePath);
    assertEquals(200, response.getCode());
    response = client.get(namespacePath, Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    NamespacesInstanceModel model = fromXML(response.getBody());
    checkNamespaceProperties(model.getProperties(), nsProperties);
    response = client.get(namespacePath, Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    model = jsonMapper.readValue(response.getBody(), NamespacesInstanceModel.class);
    checkNamespaceProperties(model.getProperties(), nsProperties);
    response = client.get(namespacePath, Constants.MIMETYPE_PROTOBUF);
    assertEquals(200, response.getCode());
    model.getObjectFromMessage(response.getBody());
    checkNamespaceProperties(model.getProperties(), nsProperties);
    // Check get namespace tables as XML, JSON and Protobuf.
    namespacePath = "/namespaces/" + nsName + "/tables";
    response = client.get(namespacePath);
    assertEquals(200, response.getCode());
    response = client.get(namespacePath, Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    TableListModel tablemodel = fromXML(response.getBody());
    checkNamespaceTables(tablemodel.getTables(), nsTables);
    response = client.get(namespacePath, Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    tablemodel = jsonMapper.readValue(response.getBody(), TableListModel.class);
    checkNamespaceTables(tablemodel.getTables(), nsTables);
    response = client.get(namespacePath, Constants.MIMETYPE_PROTOBUF);
    assertEquals(200, response.getCode());
    tablemodel.setTables(new ArrayList<>());
    tablemodel.getObjectFromMessage(response.getBody());
    checkNamespaceTables(tablemodel.getTables(), nsTables);
    // Check cannot delete namespace via REST because it contains tables.
    response = client.delete(namespacePath);
    namespacePath = "/namespaces/" + nsName;
    assertEquals(503, response.getCode());
}
Also used : TableListModel(org.apache.hadoop.hbase.rest.model.TableListModel) HashMap(java.util.HashMap) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Admin(org.apache.hadoop.hbase.client.Admin) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) Response(org.apache.hadoop.hbase.rest.client.Response) TableName(org.apache.hadoop.hbase.TableName) TestNamespacesInstanceModel(org.apache.hadoop.hbase.rest.model.TestNamespacesInstanceModel) NamespacesInstanceModel(org.apache.hadoop.hbase.rest.model.NamespacesInstanceModel) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) Test(org.junit.Test)

Example 3 with TableListModel

use of org.apache.hadoop.hbase.rest.model.TableListModel in project hbase by apache.

the class RemoteAdmin method getTableList.

/**
 * @return string representing the cluster's version
 * @throws IOException
 *           if the endpoint does not exist, there is a timeout, or some other
 *           general failure mode
 */
public TableListModel getTableList() throws IOException {
    StringBuilder path = new StringBuilder();
    path.append('/');
    if (accessToken != null) {
        path.append(accessToken);
        path.append('/');
    }
    int code = 0;
    for (int i = 0; i < maxRetries; i++) {
        // Response response = client.get(path.toString(),
        // Constants.MIMETYPE_XML);
        Response response = client.get(path.toString(), Constants.MIMETYPE_PROTOBUF);
        code = response.getCode();
        switch(code) {
            case 200:
                TableListModel t = new TableListModel();
                return (TableListModel) t.getObjectFromMessage(response.getBody());
            case 404:
                throw new IOException("Table list not found");
            case 509:
                try {
                    Thread.sleep(sleepTime);
                } catch (InterruptedException e) {
                    throw (InterruptedIOException) new InterruptedIOException().initCause(e);
                }
                break;
            default:
                throw new IOException("get request to " + path.toString() + " request returned " + code);
        }
    }
    throw new IOException("get request to " + path.toString() + " request timed out");
}
Also used : InterruptedIOException(java.io.InterruptedIOException) TableListModel(org.apache.hadoop.hbase.rest.model.TableListModel) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Example 4 with TableListModel

use of org.apache.hadoop.hbase.rest.model.TableListModel in project hbase by apache.

the class TestTableResource method testTableListPB.

@Test
public void testTableListPB() throws IOException, JAXBException {
    Response response = client.get("/", Constants.MIMETYPE_PROTOBUF);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
    TableListModel model = new TableListModel();
    model.getObjectFromMessage(response.getBody());
    checkTableList(model);
    response = client.get("/", Constants.MIMETYPE_PROTOBUF_IETF);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
    model = new TableListModel();
    model.getObjectFromMessage(response.getBody());
    checkTableList(model);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) TableListModel(org.apache.hadoop.hbase.rest.model.TableListModel) Test(org.junit.Test)

Example 5 with TableListModel

use of org.apache.hadoop.hbase.rest.model.TableListModel in project hbase by apache.

the class TestTableResource method testTableListXML.

@Test
public void testTableListXML() throws IOException, JAXBException {
    Response response = client.get("/", Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
    TableListModel model = (TableListModel) context.createUnmarshaller().unmarshal(new ByteArrayInputStream(response.getBody()));
    checkTableList(model);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) TableListModel(org.apache.hadoop.hbase.rest.model.TableListModel) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Aggregations

TableListModel (org.apache.hadoop.hbase.rest.model.TableListModel)6 Response (org.apache.hadoop.hbase.rest.client.Response)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 TableName (org.apache.hadoop.hbase.TableName)2 NamespacesInstanceModel (org.apache.hadoop.hbase.rest.model.NamespacesInstanceModel)2 TableModel (org.apache.hadoop.hbase.rest.model.TableModel)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InterruptedIOException (java.io.InterruptedIOException)1 HashMap (java.util.HashMap)1 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)1 Admin (org.apache.hadoop.hbase.client.Admin)1 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)1 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)1 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)1 TestNamespacesInstanceModel (org.apache.hadoop.hbase.rest.model.TestNamespacesInstanceModel)1 GET (org.apache.hbase.thirdparty.javax.ws.rs.GET)1 Produces (org.apache.hbase.thirdparty.javax.ws.rs.Produces)1