use of org.apache.hadoop.hbase.rest.model.ColumnSchemaModel in project hbase by apache.
the class SchemaResource method update.
private Response update(final TableName name, final TableSchemaModel model, final UriInfo uriInfo, final Admin admin) {
if (servlet.isReadOnly()) {
return Response.status(Response.Status.FORBIDDEN).type(MIMETYPE_TEXT).entity("Forbidden" + CRLF).build();
}
try {
HTableDescriptor htd = admin.getTableDescriptor(name);
admin.disableTable(name);
try {
for (ColumnSchemaModel family : model.getColumns()) {
HColumnDescriptor hcd = new HColumnDescriptor(family.getName());
for (Map.Entry<QName, Object> e : family.getAny().entrySet()) {
hcd.setValue(e.getKey().getLocalPart(), e.getValue().toString());
}
if (htd.hasFamily(hcd.getName())) {
admin.modifyColumnFamily(name, hcd);
} else {
admin.addColumnFamily(name, hcd);
}
}
} catch (IOException e) {
return Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT).entity("Unavailable" + CRLF).build();
} finally {
admin.enableTable(TableName.valueOf(tableResource.getName()));
}
servlet.getMetrics().incrementSucessfulPutRequests(1);
return Response.ok().build();
} catch (Exception e) {
servlet.getMetrics().incrementFailedPutRequests(1);
return processException(e);
}
}
use of org.apache.hadoop.hbase.rest.model.ColumnSchemaModel in project hbase by apache.
the class SchemaResource method replace.
private Response replace(final TableName name, final TableSchemaModel model, final UriInfo uriInfo, final Admin admin) {
if (servlet.isReadOnly()) {
return Response.status(Response.Status.FORBIDDEN).type(MIMETYPE_TEXT).entity("Forbidden" + CRLF).build();
}
try {
HTableDescriptor htd = new HTableDescriptor(name);
for (Map.Entry<QName, Object> e : model.getAny().entrySet()) {
htd.setValue(e.getKey().getLocalPart(), e.getValue().toString());
}
for (ColumnSchemaModel family : model.getColumns()) {
HColumnDescriptor hcd = new HColumnDescriptor(family.getName());
for (Map.Entry<QName, Object> e : family.getAny().entrySet()) {
hcd.setValue(e.getKey().getLocalPart(), e.getValue().toString());
}
htd.addFamily(hcd);
}
if (admin.tableExists(name)) {
admin.disableTable(name);
admin.modifyTable(name, htd);
admin.enableTable(name);
servlet.getMetrics().incrementSucessfulPutRequests(1);
} else
try {
admin.createTable(htd);
servlet.getMetrics().incrementSucessfulPutRequests(1);
} catch (TableExistsException e) {
// race, someone else created a table with the same name
return Response.status(Response.Status.NOT_MODIFIED).type(MIMETYPE_TEXT).entity("Not modified" + CRLF).build();
}
return Response.created(uriInfo.getAbsolutePath()).build();
} catch (Exception e) {
servlet.getMetrics().incrementFailedPutRequests(1);
return processException(e);
}
}
Aggregations