HBASE-26033 complement the admin operations in thrift2 after HBASE-21674 (#3428)

Signed-off-by: Reid Chan <reidchan@apache.org>
This commit is contained in:
YutSean 2021-07-05 12:12:59 +08:00 committed by GitHub
parent cad219d844
commit 67b26c2760
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 316 additions and 49 deletions

View File

@ -21,25 +21,36 @@ package org.apache.hadoop.hbase.thrift2;
import static org.apache.hadoop.hbase.thrift.Constants.THRIFT_READONLY_ENABLED; import static org.apache.hadoop.hbase.thrift.Constants.THRIFT_READONLY_ENABLED;
import static org.apache.hadoop.hbase.thrift.Constants.THRIFT_READONLY_ENABLED_DEFAULT; import static org.apache.hadoop.hbase.thrift.Constants.THRIFT_READONLY_ENABLED_DEFAULT;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.appendFromThrift; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.appendFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.columnDescriptorFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.deleteFromThrift; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.deleteFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.deletesFromThrift; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.deletesFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.getFromThrift; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.getFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.getsFromThrift; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.getsFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.incrementFromThrift; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.incrementFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.namespaceDescriptorFromHBase;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.namespaceDescriptorFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.namespaceDescriptorsFromHBase;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.putFromThrift; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.putFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.putsFromThrift; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.putsFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.regionLocationFromHBase;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.regionLocationsFromHBase;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.resultFromHBase; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.resultFromHBase;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.resultsFromHBase; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.resultsFromHBase;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.rowMutationsFromThrift; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.rowMutationsFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.scanFromThrift; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.scanFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.splitKeyFromThrift; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.splitKeyFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.tableDescriptorFromHBase;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.tableDescriptorFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.tableDescriptorsFromHBase;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.tableNameFromThrift; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.tableNameFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.tableNamesFromHBase; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.tableNamesFromHBase;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.tableNamesFromThrift;
import static org.apache.thrift.TBaseHelper.byteBufferToByteArray; import static org.apache.thrift.TBaseHelper.byteBufferToByteArray;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -53,7 +64,10 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.client.RegionLocator; import org.apache.hadoop.hbase.client.RegionLocator;
@ -345,14 +359,28 @@ public class ThriftHBaseServiceHandler extends HBaseServiceHandler implements TH
} }
} }
@Override public TTableDescriptor getTableDescriptor(TTableName table) @Override
public TTableDescriptor getTableDescriptor(TTableName table)
throws TIOError, TException { throws TIOError, TException {
return null; try {
TableName tableName = tableNameFromThrift(table);
HTableDescriptor tableDescriptor = connectionCache.getAdmin().getTableDescriptor(tableName);
return tableDescriptorFromHBase(tableDescriptor);
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public List<TTableDescriptor> getTableDescriptors(List<TTableName> tables) @Override
public List<TTableDescriptor> getTableDescriptors(List<TTableName> tables)
throws TIOError, TException { throws TIOError, TException {
return null; try {
List<TableName> tableNames = tableNamesFromThrift(tables);
return tableDescriptorsFromHBase(
Arrays.asList(connectionCache.getAdmin().getTableDescriptorsByTableName(tableNames)));
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override @Override
@ -448,8 +476,6 @@ public class ThriftHBaseServiceHandler extends HBaseServiceHandler implements TH
return results; return results;
} }
@Override @Override
public void closeScanner(int scannerId) throws TIOError, TIllegalArgument, TException { public void closeScanner(int scannerId) throws TIOError, TIllegalArgument, TException {
LOG.debug("scannerClose: id=" + scannerId); LOG.debug("scannerClose: id=" + scannerId);
@ -484,8 +510,7 @@ public class ThriftHBaseServiceHandler extends HBaseServiceHandler implements TH
RegionLocator locator = null; RegionLocator locator = null;
try { try {
locator = getLocator(table); locator = getLocator(table);
return ThriftUtilities.regionLocationsFromHBase(locator.getAllRegionLocations()); return regionLocationsFromHBase(locator.getAllRegionLocations());
} catch (IOException e) { } catch (IOException e) {
throw getTIOError(e); throw getTIOError(e);
} finally { } finally {
@ -508,8 +533,7 @@ public class ThriftHBaseServiceHandler extends HBaseServiceHandler implements TH
locator = getLocator(table); locator = getLocator(table);
byte[] rowBytes = byteBufferToByteArray(row); byte[] rowBytes = byteBufferToByteArray(row);
HRegionLocation hrl = locator.getRegionLocation(rowBytes, reload); HRegionLocation hrl = locator.getRegionLocation(rowBytes, reload);
return ThriftUtilities.regionLocationFromHBase(hrl); return regionLocationFromHBase(hrl);
} catch (IOException e) { } catch (IOException e) {
throw getTIOError(e); throw getTIOError(e);
} finally { } finally {
@ -546,12 +570,25 @@ public class ThriftHBaseServiceHandler extends HBaseServiceHandler implements TH
@Override @Override
public List<TTableDescriptor> getTableDescriptorsByPattern(String regex, boolean includeSysTables) public List<TTableDescriptor> getTableDescriptorsByPattern(String regex, boolean includeSysTables)
throws TIOError, TException { throws TIOError, TException {
return null; try {
Pattern pattern = (regex == null ? null : Pattern.compile(regex));
List<HTableDescriptor> tableDescriptors =
Arrays.asList(connectionCache.getAdmin().listTables(pattern));
return tableDescriptorsFromHBase(tableDescriptors);
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public List<TTableDescriptor> getTableDescriptorsByNamespace(String name) @Override
public List<TTableDescriptor> getTableDescriptorsByNamespace(String name)
throws TIOError, TException { throws TIOError, TException {
return null; try {
HTableDescriptor[] tables = connectionCache.getAdmin().listTableDescriptorsByNamespace(name);
return tableDescriptorsFromHBase(Arrays.asList(tables));
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override @Override
@ -577,26 +614,57 @@ public class ThriftHBaseServiceHandler extends HBaseServiceHandler implements TH
} }
} }
@Override public void createTable(TTableDescriptor desc, List<ByteBuffer> splitKeys) @Override
public void createTable(TTableDescriptor desc, List<ByteBuffer> splitKeys)
throws TIOError, TException { throws TIOError, TException {
try {
HTableDescriptor descriptor = tableDescriptorFromThrift(desc);
byte[][] split = splitKeyFromThrift(splitKeys);
connectionCache.getAdmin().createTable(descriptor, split);
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public void deleteTable(TTableName tableName) throws TIOError, TException { @Override
public void deleteTable(TTableName tableName) throws TIOError, TException {
try {
TableName table = tableNameFromThrift(tableName);
connectionCache.getAdmin().deleteTable(table);
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public void truncateTable(TTableName tableName, boolean preserveSplits) @Override
public void truncateTable(TTableName tableName, boolean preserveSplits)
throws TIOError, TException { throws TIOError, TException {
try {
TableName table = tableNameFromThrift(tableName);
connectionCache.getAdmin().truncateTable(table, preserveSplits);
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public void enableTable(TTableName tableName) throws TIOError, TException { @Override
public void enableTable(TTableName tableName) throws TIOError, TException {
try {
TableName table = tableNameFromThrift(tableName);
connectionCache.getAdmin().enableTable(table);
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public void disableTable(TTableName tableName) throws TIOError, TException { @Override
public void disableTable(TTableName tableName) throws TIOError, TException {
try {
TableName table = tableNameFromThrift(tableName);
connectionCache.getAdmin().disableTable(table);
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override @Override
@ -641,51 +709,113 @@ public class ThriftHBaseServiceHandler extends HBaseServiceHandler implements TH
} }
} }
@Override public void addColumnFamily(TTableName tableName, TColumnFamilyDescriptor column) @Override
public void addColumnFamily(TTableName tableName, TColumnFamilyDescriptor column)
throws TIOError, TException { throws TIOError, TException {
throw new NotImplementedException(); try {
TableName table = tableNameFromThrift(tableName);
HColumnDescriptor columnFamilyDescriptor = columnDescriptorFromThrift(column);
connectionCache.getAdmin().addColumn(table, columnFamilyDescriptor);
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public void deleteColumnFamily(TTableName tableName, ByteBuffer column) @Override
public void deleteColumnFamily(TTableName tableName, ByteBuffer column)
throws TIOError, TException { throws TIOError, TException {
throw new NotImplementedException(); try {
TableName table = tableNameFromThrift(tableName);
connectionCache.getAdmin().deleteColumn(table, column.array());
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public void modifyColumnFamily(TTableName tableName, TColumnFamilyDescriptor column) @Override
public void modifyColumnFamily(TTableName tableName, TColumnFamilyDescriptor column)
throws TIOError, TException { throws TIOError, TException {
throw new NotImplementedException(); try {
TableName table = tableNameFromThrift(tableName);
HColumnDescriptor columnFamilyDescriptor = columnDescriptorFromThrift(column);
connectionCache.getAdmin().modifyColumn(table, columnFamilyDescriptor);
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public void modifyTable(TTableDescriptor desc) throws TIOError, TException { @Override
throw new NotImplementedException(); public void modifyTable(TTableDescriptor desc) throws TIOError, TException {
try {
HTableDescriptor descriptor = tableDescriptorFromThrift(desc);
connectionCache.getAdmin().modifyTable(descriptor.getTableName(), descriptor);
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public void createNamespace(TNamespaceDescriptor namespaceDesc) @Override
public void createNamespace(TNamespaceDescriptor namespaceDesc)
throws TIOError, TException { throws TIOError, TException {
throw new NotImplementedException(); try {
NamespaceDescriptor descriptor = namespaceDescriptorFromThrift(namespaceDesc);
connectionCache.getAdmin().createNamespace(descriptor);
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public void modifyNamespace(TNamespaceDescriptor namespaceDesc) @Override
public void modifyNamespace(TNamespaceDescriptor namespaceDesc)
throws TIOError, TException { throws TIOError, TException {
throw new NotImplementedException(); try {
NamespaceDescriptor descriptor = namespaceDescriptorFromThrift(namespaceDesc);
connectionCache.getAdmin().modifyNamespace(descriptor);
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public void deleteNamespace(String name) throws TIOError, TException { @Override
throw new NotImplementedException(); public void deleteNamespace(String name) throws TIOError, TException {
try {
connectionCache.getAdmin().deleteNamespace(name);
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public TNamespaceDescriptor getNamespaceDescriptor(String name) @Override
public TNamespaceDescriptor getNamespaceDescriptor(String name)
throws TIOError, TException { throws TIOError, TException {
throw new NotImplementedException(); try {
return namespaceDescriptorFromHBase(connectionCache.getAdmin().getNamespaceDescriptor(name));
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public List<TNamespaceDescriptor> listNamespaceDescriptors() @Override
public List<TNamespaceDescriptor> listNamespaceDescriptors()
throws TIOError, TException { throws TIOError, TException {
throw new NotImplementedException(); try {
return namespaceDescriptorsFromHBase(connectionCache.getAdmin().listNamespaceDescriptors());
} catch (IOException e) {
throw getTIOError(e);
}
} }
@Override public List<String> listNamespaces() throws TIOError, TException { @Override
throw new NotImplementedException(); public List<String> listNamespaces() throws TIOError, TException {
List<String> result = new ArrayList<>();
try {
for (NamespaceDescriptor nd : connectionCache.getAdmin().listNamespaceDescriptors()) {
result.add(nd.getName());
}
} catch (IOException e) {
throw getTIOError(e);
}
return result;
} }
@Override @Override
@ -693,12 +823,14 @@ public class ThriftHBaseServiceHandler extends HBaseServiceHandler implements TH
return TThriftServerType.TWO; return TThriftServerType.TWO;
} }
@Override public List<TOnlineLogRecord> getSlowLogResponses(Set<TServerName> serverNames, @Override
public List<TOnlineLogRecord> getSlowLogResponses(Set<TServerName> serverNames,
TLogQueryFilter logQueryFilter) throws TIOError, TException { TLogQueryFilter logQueryFilter) throws TIOError, TException {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override public List<Boolean> clearSlowLogResponses(Set<TServerName> serverNames) @Override
public List<Boolean> clearSlowLogResponses(Set<TServerName> serverNames)
throws TIOError, TException { throws TIOError, TException {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -31,9 +31,11 @@ import java.util.Set;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeepDeletedCells; import org.apache.hadoop.hbase.KeepDeletedCells;
import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.NamespaceDescriptor;
@ -57,6 +59,7 @@ import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.filter.CompareFilter; import org.apache.hadoop.hbase.filter.CompareFilter;
import org.apache.hadoop.hbase.filter.Filter; import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.ParseFilter; import org.apache.hadoop.hbase.filter.ParseFilter;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.io.TimeRange; import org.apache.hadoop.hbase.io.TimeRange;
import org.apache.hadoop.hbase.io.compress.Compression; import org.apache.hadoop.hbase.io.compress.Compression;
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding; import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
@ -70,6 +73,7 @@ import org.apache.hadoop.hbase.thrift2.generated.TAuthorization;
import org.apache.hadoop.hbase.thrift2.generated.TBloomFilterType; import org.apache.hadoop.hbase.thrift2.generated.TBloomFilterType;
import org.apache.hadoop.hbase.thrift2.generated.TCellVisibility; import org.apache.hadoop.hbase.thrift2.generated.TCellVisibility;
import org.apache.hadoop.hbase.thrift2.generated.TColumn; import org.apache.hadoop.hbase.thrift2.generated.TColumn;
import org.apache.hadoop.hbase.thrift2.generated.TColumnFamilyDescriptor;
import org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement; import org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement;
import org.apache.hadoop.hbase.thrift2.generated.TColumnValue; import org.apache.hadoop.hbase.thrift2.generated.TColumnValue;
import org.apache.hadoop.hbase.thrift2.generated.TCompareOp; import org.apache.hadoop.hbase.thrift2.generated.TCompareOp;
@ -92,6 +96,7 @@ import org.apache.hadoop.hbase.thrift2.generated.TResult;
import org.apache.hadoop.hbase.thrift2.generated.TRowMutations; import org.apache.hadoop.hbase.thrift2.generated.TRowMutations;
import org.apache.hadoop.hbase.thrift2.generated.TScan; import org.apache.hadoop.hbase.thrift2.generated.TScan;
import org.apache.hadoop.hbase.thrift2.generated.TServerName; import org.apache.hadoop.hbase.thrift2.generated.TServerName;
import org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor;
import org.apache.hadoop.hbase.thrift2.generated.TTableName; import org.apache.hadoop.hbase.thrift2.generated.TTableName;
import org.apache.hadoop.hbase.thrift2.generated.TTimeRange; import org.apache.hadoop.hbase.thrift2.generated.TTimeRange;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
@ -104,8 +109,6 @@ public class ThriftUtilities {
private final static Result EMPTY_RESULT = Result.create(EMPTY_CELL_ARRAY); private final static Result EMPTY_RESULT = Result.create(EMPTY_CELL_ARRAY);
private final static Result EMPTY_RESULT_STALE = Result.create(EMPTY_CELL_ARRAY, null, true); private final static Result EMPTY_RESULT_STALE = Result.create(EMPTY_CELL_ARRAY, null, true);
private ThriftUtilities() { private ThriftUtilities() {
throw new UnsupportedOperationException("Can't initialize class"); throw new UnsupportedOperationException("Can't initialize class");
} }
@ -930,8 +933,6 @@ public class ThriftUtilities {
} }
} }
public static TBloomFilterType bloomFilterFromHBase(BloomType in) { public static TBloomFilterType bloomFilterFromHBase(BloomType in) {
switch (in) { switch (in) {
case NONE: return TBloomFilterType.NONE; case NONE: return TBloomFilterType.NONE;
@ -1293,4 +1294,138 @@ public class ThriftUtilities {
} }
return result; return result;
} }
public static HColumnDescriptor columnDescriptorFromThrift(TColumnFamilyDescriptor in) {
HColumnDescriptor out = new HColumnDescriptor(in.getName());
if (in.isSetAttributes()) {
for (Map.Entry<ByteBuffer, ByteBuffer> attribute : in.getAttributes().entrySet()) {
out.setValue(attribute.getKey().array(), attribute.getValue().array());
}
}
if (in.isSetConfiguration()) {
for (Map.Entry<String, String> conf : in.getConfiguration().entrySet()) {
out.setConfiguration(conf.getKey(), conf.getValue());
}
}
if (in.isSetBlockSize()) {
out.setBlocksize(in.getBlockSize());
}
if (in.isSetBloomnFilterType()) {
out.setBloomFilterType(bloomFilterFromThrift(in.getBloomnFilterType()));
}
if (in.isSetCompressionType()) {
out.setCompressionType(compressionAlgorithmFromThrift(in.getCompressionType()));
}
if (in.isSetDfsReplication()) {
out.setDFSReplication(in.getDfsReplication());
}
if (in.isSetDataBlockEncoding()) {
out.setDataBlockEncoding(dataBlockEncodingFromThrift(in.getDataBlockEncoding()));
}
if (in.isSetKeepDeletedCells()) {
out.setKeepDeletedCells(keepDeletedCellsFromThrift(in.getKeepDeletedCells()));
}
if (in.isSetMaxVersions()) {
out.setMaxVersions(in.getMaxVersions());
}
if (in.isSetMinVersions()) {
out.setMinVersions(in.getMinVersions());
}
if (in.isSetScope()) {
out.setScope(in.getScope());
}
if (in.isSetTimeToLive()) {
out.setTimeToLive(in.getTimeToLive());
}
if (in.isSetBlockCacheEnabled()) {
out.setBlockCacheEnabled(in.isBlockCacheEnabled());
}
if (in.isSetCacheBloomsOnWrite()) {
out.setCacheBloomsOnWrite(in.isCacheBloomsOnWrite());
}
if (in.isSetCacheDataOnWrite()) {
out.setCacheDataOnWrite(in.isCacheDataOnWrite());
}
if (in.isSetCacheIndexesOnWrite()) {
out.setCacheIndexesOnWrite(in.isCacheIndexesOnWrite());
}
if (in.isSetCompressTags()) {
out.setCompressTags(in.isCompressTags());
}
if (in.isSetEvictBlocksOnClose()) {
out.setEvictBlocksOnClose(in.isEvictBlocksOnClose());
}
if (in.isSetInMemory()) {
out.setInMemory(in.isInMemory());
}
return out;
}
public static TColumnFamilyDescriptor columnDescriptorFromHBase(HColumnDescriptor in) {
TColumnFamilyDescriptor out = new TColumnFamilyDescriptor();
out.setName(in.getName());
for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> attribute :
in.getValues().entrySet()) {
out.putToAttributes(ByteBuffer.wrap(attribute.getKey().get()),
ByteBuffer.wrap(attribute.getValue().get()));
}
for (Map.Entry<String, String> conf : in.getConfiguration().entrySet()) {
out.putToConfiguration(conf.getKey(), conf.getValue());
}
out.setBlockSize(in.getBlocksize());
out.setBloomnFilterType(bloomFilterFromHBase(in.getBloomFilterType()));
out.setCompressionType(compressionAlgorithmFromHBase(in.getCompressionType()));
out.setDfsReplication(in.getDFSReplication());
out.setDataBlockEncoding(dataBlockEncodingFromHBase(in.getDataBlockEncoding()));
out.setKeepDeletedCells(keepDeletedCellsFromHBase(in.getKeepDeletedCells()));
out.setMaxVersions(in.getMaxVersions());
out.setMinVersions(in.getMinVersions());
out.setScope(in.getScope());
out.setTimeToLive(in.getTimeToLive());
out.setBlockCacheEnabled(in.isBlockCacheEnabled());
out.setCacheBloomsOnWrite(in.isCacheBloomsOnWrite());
out.setCacheDataOnWrite(in.isCacheDataOnWrite());
out.setCacheIndexesOnWrite(in.isCacheIndexesOnWrite());
out.setCompressTags(in.isCompressTags());
out.setEvictBlocksOnClose(in.isEvictBlocksOnClose());
out.setInMemory(in.isInMemory());
return out;
}
public static HTableDescriptor tableDescriptorFromThrift(TTableDescriptor in) {
HTableDescriptor out = new HTableDescriptor(tableNameFromThrift(in.getTableName()));
for (TColumnFamilyDescriptor col : in.getColumns()) {
out.addFamily(columnDescriptorFromThrift(col));
}
Map<ByteBuffer, ByteBuffer> map = in.getAttributes();
for (Map.Entry<ByteBuffer, ByteBuffer> e : map.entrySet()) {
out.setValue(e.getKey().array(), e.getValue().array());
}
return out;
}
public static TTableDescriptor tableDescriptorFromHBase(HTableDescriptor in) {
TTableDescriptor out = new TTableDescriptor();
out.setTableName(tableNameFromHBase(in.getTableName()));
Map<ImmutableBytesWritable, ImmutableBytesWritable> attributes = in.getValues();
for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> attribute
: attributes.entrySet()) {
out.putToAttributes(ByteBuffer.wrap(attribute.getKey().get()),
ByteBuffer.wrap(attribute.getValue().get()));
}
for (HColumnDescriptor column : in.getColumnFamilies()) {
out.addToColumns(columnDescriptorFromHBase(column));
}
out.setDurability(durabilityFromHBase(in.getDurability()));
return out;
}
public static List<TTableDescriptor> tableDescriptorsFromHBase(List<HTableDescriptor> in) {
List<TTableDescriptor> out = new ArrayList<>(in.size());
for (HTableDescriptor descriptor : in) {
out.add(tableDescriptorFromHBase(descriptor));
}
return out;
}
} }