public GenericArray<ATableDescriptor> listTables() throws AIOError { try { HTableDescriptor[] tables = admin.listTables(); Schema atdSchema = Schema.createArray(ATableDescriptor.SCHEMA$); GenericData.Array<ATableDescriptor> result = null; result = new GenericData.Array<ATableDescriptor>(tables.length, atdSchema); for (HTableDescriptor table : tables) { result.add(AvroUtil.htdToATD(table)); } return result; } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } }
static public ATableDescriptor htdToATD(HTableDescriptor table) throws IOException { ATableDescriptor atd = new ATableDescriptor(); atd.name = ByteBuffer.wrap(table.getName()); Collection<HColumnDescriptor> families = table.getFamilies(); Schema afdSchema = Schema.createArray(AFamilyDescriptor.SCHEMA$); GenericData.Array<AFamilyDescriptor> afamilies = null; if (families.size() > 0) { afamilies = new GenericData.Array<AFamilyDescriptor>(families.size(), afdSchema); for (HColumnDescriptor hcd : families) { AFamilyDescriptor afamily = hcdToAFD(hcd); afamilies.add(afamily); } } else { afamilies = new GenericData.Array<AFamilyDescriptor>(0, afdSchema); } atd.families = afamilies; atd.maxFileSize = table.getMaxFileSize(); atd.memStoreFlushSize = table.getMemStoreFlushSize(); atd.rootRegion = table.isRootRegion(); atd.metaRegion = table.isMetaRegion(); atd.metaTable = table.isMetaTable(); atd.readOnly = table.isReadOnly(); atd.deferredLogFlush = table.isDeferredLogFlush(); return atd; }
static public HTableDescriptor atdToHTD(ATableDescriptor atd) throws IOException, AIllegalArgument { HTableDescriptor htd = new HTableDescriptor(Bytes.toBytes(atd.name)); if (atd.families != null && atd.families.size() > 0) { for (AFamilyDescriptor afd : atd.families) { htd.addFamily(afdToHCD(afd)); } } if (atd.maxFileSize != null) { htd.setMaxFileSize(atd.maxFileSize); } if (atd.memStoreFlushSize != null) { htd.setMemStoreFlushSize(atd.memStoreFlushSize); } if (atd.readOnly != null) { htd.setReadOnly(atd.readOnly); } if (atd.deferredLogFlush != null) { htd.setDeferredLogFlush(atd.deferredLogFlush); } if (atd.rootRegion != null || atd.metaRegion != null || atd.metaTable != null) { AIllegalArgument aie = new AIllegalArgument(); aie.message = new Utf8("Can't set root or meta flag on create table."); throw aie; } return htd; }
public Void modifyTable(ByteBuffer tableName, ATableDescriptor tableDescriptor) throws AIOError { try { admin.modifyTable(Bytes.toBytes(tableName), AvroUtil.atdToHTD(tableDescriptor)); return null; } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } }
/** * Tests for creating, modifying, and deleting column families. * * @throws Exception */ @Test public void testFamilyAdminAndMetadata() throws Exception { AvroServer.HBaseImpl impl = new AvroServer.HBaseImpl(TEST_UTIL.getConfiguration()); ATableDescriptor tableA = new ATableDescriptor(); tableA.name = tableAname; AFamilyDescriptor familyA = new AFamilyDescriptor(); familyA.name = familyAname; Schema familyArraySchema = Schema.createArray(AFamilyDescriptor.SCHEMA$); GenericArray<AFamilyDescriptor> families = new GenericData.Array<AFamilyDescriptor>(1, familyArraySchema); families.add(familyA); tableA.families = families; impl.createTable(tableA); assertEquals(impl.describeTable(tableAname).families.size(), 1); impl.disableTable(tableAname); assertFalse(impl.isTableEnabled(tableAname)); familyA.maxVersions = 123456; impl.modifyFamily(tableAname, familyAname, familyA); assertEquals((int) impl.describeFamily(tableAname, familyAname).maxVersions, 123456); impl.deleteFamily(tableAname, familyAname); assertEquals(impl.describeTable(tableAname).families.size(), 0); impl.deleteTable(tableAname); }
/** * Tests for creating, enabling, disabling, modifying, and deleting tables. * * @throws Exception */ @Test (timeout=300000) public void testTableAdminAndMetadata() throws Exception { AvroServer.HBaseImpl impl = new AvroServer.HBaseImpl(TEST_UTIL.getConfiguration()); assertEquals(impl.listTables().size(), 0); ATableDescriptor tableA = new ATableDescriptor(); tableA.name = tableAname; impl.createTable(tableA); assertEquals(impl.listTables().size(), 1); assertTrue(impl.isTableEnabled(tableAname)); assertTrue(impl.tableExists(tableAname)); ATableDescriptor tableB = new ATableDescriptor(); tableB.name = tableBname; impl.createTable(tableB); assertEquals(impl.listTables().size(), 2); impl.disableTable(tableBname); assertFalse(impl.isTableEnabled(tableBname)); impl.deleteTable(tableBname); assertEquals(impl.listTables().size(), 1); impl.disableTable(tableAname); assertFalse(impl.isTableEnabled(tableAname)); long oldMaxFileSize = impl.describeTable(tableAname).maxFileSize; tableA.maxFileSize = 123456L; impl.modifyTable(tableAname, tableA); // It can take a while for the change to take effect. Wait here a while. while(impl.describeTable(tableAname).maxFileSize == oldMaxFileSize) { Threads.sleep(100); } assertTrue(impl.describeTable(tableAname).maxFileSize == 123456L); assertEquals(123456L, (long) impl.describeTable(tableAname).maxFileSize); /* DISABLED FOR NOW TILL WE HAVE BETTER DISABLE/ENABLE impl.enableTable(tableAname); assertTrue(impl.isTableEnabled(tableAname)); impl.disableTable(tableAname); */ impl.deleteTable(tableAname); }
/** * Tests for adding, reading, and deleting data. * * @throws Exception */ @Test public void testDML() throws Exception { AvroServer.HBaseImpl impl = new AvroServer.HBaseImpl(TEST_UTIL.getConfiguration()); ATableDescriptor tableA = new ATableDescriptor(); tableA.name = tableAname; AFamilyDescriptor familyA = new AFamilyDescriptor(); familyA.name = familyAname; Schema familyArraySchema = Schema.createArray(AFamilyDescriptor.SCHEMA$); GenericArray<AFamilyDescriptor> families = new GenericData.Array<AFamilyDescriptor>(1, familyArraySchema); families.add(familyA); tableA.families = families; impl.createTable(tableA); assertEquals(impl.describeTable(tableAname).families.size(), 1); AGet getA = new AGet(); getA.row = rowAname; Schema columnsSchema = Schema.createArray(AColumn.SCHEMA$); GenericArray<AColumn> columns = new GenericData.Array<AColumn>(1, columnsSchema); AColumn column = new AColumn(); column.family = familyAname; column.qualifier = qualifierAname; columns.add(column); getA.columns = columns; assertFalse(impl.exists(tableAname, getA)); APut putA = new APut(); putA.row = rowAname; Schema columnValuesSchema = Schema.createArray(AColumnValue.SCHEMA$); GenericArray<AColumnValue> columnValues = new GenericData.Array<AColumnValue>(1, columnValuesSchema); AColumnValue acv = new AColumnValue(); acv.family = familyAname; acv.qualifier = qualifierAname; acv.value = valueA; columnValues.add(acv); putA.columnValues = columnValues; impl.put(tableAname, putA); assertTrue(impl.exists(tableAname, getA)); assertEquals(impl.get(tableAname, getA).entries.size(), 1); impl.disableTable(tableAname); impl.deleteTable(tableAname); }