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;
}
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());
}
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");
}
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);
}
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);
}
Aggregations