Search in sources :

Example 1 with ColumnSchemaModel

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);
    }
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) QName(javax.xml.namespace.QName) IOException(java.io.IOException) ColumnSchemaModel(org.apache.hadoop.hbase.rest.model.ColumnSchemaModel) Map(java.util.Map) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) TableNotEnabledException(org.apache.hadoop.hbase.TableNotEnabledException) TableExistsException(org.apache.hadoop.hbase.TableExistsException) IOException(java.io.IOException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 2 with ColumnSchemaModel

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);
    }
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) QName(javax.xml.namespace.QName) TableExistsException(org.apache.hadoop.hbase.TableExistsException) Map(java.util.Map) ColumnSchemaModel(org.apache.hadoop.hbase.rest.model.ColumnSchemaModel) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) TableNotEnabledException(org.apache.hadoop.hbase.TableNotEnabledException) TableExistsException(org.apache.hadoop.hbase.TableExistsException) IOException(java.io.IOException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Aggregations

IOException (java.io.IOException)2 Map (java.util.Map)2 QName (javax.xml.namespace.QName)2 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 TableExistsException (org.apache.hadoop.hbase.TableExistsException)2 TableNotEnabledException (org.apache.hadoop.hbase.TableNotEnabledException)2 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)2 ColumnSchemaModel (org.apache.hadoop.hbase.rest.model.ColumnSchemaModel)2