use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder 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 {
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(name);
for (Map.Entry<QName, Object> e : model.getAny().entrySet()) {
tableDescriptorBuilder.setValue(e.getKey().getLocalPart(), e.getValue().toString());
}
for (ColumnSchemaModel family : model.getColumns()) {
ColumnFamilyDescriptorBuilder columnFamilyDescriptorBuilder = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family.getName()));
for (Map.Entry<QName, Object> e : family.getAny().entrySet()) {
columnFamilyDescriptorBuilder.setValue(e.getKey().getLocalPart(), e.getValue().toString());
}
tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptorBuilder.build());
}
TableDescriptor tableDescriptor = tableDescriptorBuilder.build();
if (admin.tableExists(name)) {
admin.disableTable(name);
admin.modifyTable(tableDescriptor);
admin.enableTable(name);
servlet.getMetrics().incrementSucessfulPutRequests(1);
} else {
try {
admin.createTable(tableDescriptor);
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) {
LOG.info("Caught exception", e);
servlet.getMetrics().incrementFailedPutRequests(1);
return processException(e);
}
}
use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder 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 {
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(admin.getDescriptor(name));
admin.disableTable(name);
try {
for (ColumnSchemaModel family : model.getColumns()) {
ColumnFamilyDescriptorBuilder columnFamilyDescriptorBuilder = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family.getName()));
for (Map.Entry<QName, Object> e : family.getAny().entrySet()) {
columnFamilyDescriptorBuilder.setValue(e.getKey().getLocalPart(), e.getValue().toString());
}
TableDescriptor tableDescriptor = tableDescriptorBuilder.build();
ColumnFamilyDescriptor columnFamilyDescriptor = columnFamilyDescriptorBuilder.build();
if (tableDescriptor.hasColumnFamily(columnFamilyDescriptor.getName())) {
admin.modifyColumnFamily(name, columnFamilyDescriptor);
} else {
admin.addColumnFamily(name, columnFamilyDescriptor);
}
}
} 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.client.ColumnFamilyDescriptorBuilder in project hbase by apache.
the class ProtobufUtil method toColumnFamilyDescriptor.
/**
* Converts a ColumnFamilySchema to ColumnFamilyDescriptor
* @param cfs the ColumnFamilySchema
* @return An {@link ColumnFamilyDescriptor} made from the passed in <code>cfs</code>
*/
public static ColumnFamilyDescriptor toColumnFamilyDescriptor(final ColumnFamilySchema cfs) {
// Use the empty constructor so we preserve the initial values set on construction for things
// like maxVersion. Otherwise, we pick up wrong values on deserialization which makes for
// unrelated-looking test failures that are hard to trace back to here.
ColumnFamilyDescriptorBuilder builder = ColumnFamilyDescriptorBuilder.newBuilder(cfs.getName().toByteArray());
cfs.getAttributesList().forEach(a -> builder.setValue(a.getFirst().toByteArray(), a.getSecond().toByteArray()));
cfs.getConfigurationList().forEach(a -> builder.setConfiguration(a.getName(), a.getValue()));
return builder.build();
}
use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.
the class TableSchemaModel method getTableDescriptor.
/**
* @return a table descriptor
*/
@JsonIgnore
public TableDescriptor getTableDescriptor() {
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(TableName.valueOf(getName()));
for (Map.Entry<QName, Object> e : getAny().entrySet()) {
tableDescriptorBuilder.setValue(e.getKey().getLocalPart(), e.getValue().toString());
}
for (ColumnSchemaModel column : getColumns()) {
ColumnFamilyDescriptorBuilder cfdb = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(column.getName()));
for (Map.Entry<QName, Object> e : column.getAny().entrySet()) {
cfdb.setValue(e.getKey().getLocalPart(), e.getValue().toString());
}
tableDescriptorBuilder.setColumnFamily(cfdb.build());
}
return tableDescriptorBuilder.build();
}
use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.
the class CloneSnapshotProcedure method updateTableDescriptorWithSFT.
/**
* If a StoreFileTracker is specified we strip the TableDescriptor from previous SFT config
* and set the specified SFT on the table level
*/
private void updateTableDescriptorWithSFT() {
if (StringUtils.isEmpty(customSFT)) {
return;
}
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor);
builder.setValue(StoreFileTrackerFactory.TRACKER_IMPL, customSFT);
for (ColumnFamilyDescriptor family : tableDescriptor.getColumnFamilies()) {
ColumnFamilyDescriptorBuilder cfBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family);
cfBuilder.setConfiguration(StoreFileTrackerFactory.TRACKER_IMPL, null);
cfBuilder.setValue(StoreFileTrackerFactory.TRACKER_IMPL, null);
builder.modifyColumnFamily(cfBuilder.build());
}
tableDescriptor = builder.build();
}
Aggregations