@Test public void testMigrateDirectory() throws Exception { tool.createOrMigrateSchemaDirectory("classpath:SchemaTool", true); tableName = "simple"; Dao<SimpleHBaseRecord> dao = new SpecificAvroDao<SimpleHBaseRecord>( tablePool, tableName, "SimpleHBaseRecord", manager); testBasicOperations(dao); }
public void createOrMigrateSchemaDirectory(String schemaDirectory, boolean createTableAndFamilies) throws InterruptedException { List<String> schemaStrings; if (schemaDirectory.startsWith(CLASSPATH_PREFIX)) { URL dirURL = getClass().getClassLoader().getResource( schemaDirectory.substring(CLASSPATH_PREFIX.length())); if (dirURL != null && dirURL.getProtocol().equals("file")) { try { schemaStrings = getSchemaStringsFromDir(new File(dirURL.toURI())); } catch (URISyntaxException e) { throw new DatasetException(e); } } else if (dirURL != null && dirURL.getProtocol().equals("jar")) { String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); schemaStrings = getSchemaStringsFromJar(jarPath, schemaDirectory.substring(CLASSPATH_PREFIX.length())); } else { String msg = "Could not find classpath resource: " + schemaDirectory; LOG.error(msg); throw new DatasetException(msg); } } else { schemaStrings = getSchemaStringsFromDir(new File(schemaDirectory)); } Map<String, List<String>> tableEntitySchemaMap = new HashMap<String, List<String>>(); for (String schemaString : schemaStrings) { List<String> tables = getTablesFromSchemaString(schemaString); for (String table : tables) { if (tableEntitySchemaMap.containsKey(table)) { tableEntitySchemaMap.get(table).add(schemaString); } else { List<String> entityList = new ArrayList<String>(); entityList.add(schemaString); tableEntitySchemaMap.put(table, entityList); } } } for (Entry<String, List<String>> entry : tableEntitySchemaMap.entrySet()) { String table = entry.getKey(); List<String> entitySchemas = entry.getValue(); if (entitySchemas.size() == 0) { String msg = "Table requested, but no entity schemas for Table: " + table; LOG.error(msg); throw new ValidationException(msg); } } Collection<HTableDescriptor> tableDescriptors = Lists.newArrayList(); for (Entry<String, List<String>> entry : tableEntitySchemaMap.entrySet()) { String table = entry.getKey(); for (String entitySchemaString : entry.getValue()) { boolean migrationRequired = prepareManagedSchema(table, entitySchemaString); if (migrationRequired) { tableDescriptors.add( prepareTableDescriptor(table, entitySchemaString)); } } } if (createTableAndFamilies) { createTables(tableDescriptors); } }
SchemaTool { public void createOrMigrateSchemaDirectory(String schemaDirectory, boolean createTableAndFamilies) throws InterruptedException { List<String> schemaStrings; if (schemaDirectory.startsWith(CLASSPATH_PREFIX)) { URL dirURL = getClass().getClassLoader().getResource( schemaDirectory.substring(CLASSPATH_PREFIX.length())); if (dirURL != null && dirURL.getProtocol().equals("file")) { try { schemaStrings = getSchemaStringsFromDir(new File(dirURL.toURI())); } catch (URISyntaxException e) { throw new DatasetException(e); } } else if (dirURL != null && dirURL.getProtocol().equals("jar")) { String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); schemaStrings = getSchemaStringsFromJar(jarPath, schemaDirectory.substring(CLASSPATH_PREFIX.length())); } else { String msg = "Could not find classpath resource: " + schemaDirectory; LOG.error(msg); throw new DatasetException(msg); } } else { schemaStrings = getSchemaStringsFromDir(new File(schemaDirectory)); } Map<String, List<String>> tableEntitySchemaMap = new HashMap<String, List<String>>(); for (String schemaString : schemaStrings) { List<String> tables = getTablesFromSchemaString(schemaString); for (String table : tables) { if (tableEntitySchemaMap.containsKey(table)) { tableEntitySchemaMap.get(table).add(schemaString); } else { List<String> entityList = new ArrayList<String>(); entityList.add(schemaString); tableEntitySchemaMap.put(table, entityList); } } } for (Entry<String, List<String>> entry : tableEntitySchemaMap.entrySet()) { String table = entry.getKey(); List<String> entitySchemas = entry.getValue(); if (entitySchemas.size() == 0) { String msg = "Table requested, but no entity schemas for Table: " + table; LOG.error(msg); throw new ValidationException(msg); } } Collection<HTableDescriptor> tableDescriptors = Lists.newArrayList(); for (Entry<String, List<String>> entry : tableEntitySchemaMap.entrySet()) { String table = entry.getKey(); for (String entitySchemaString : entry.getValue()) { boolean migrationRequired = prepareManagedSchema(table, entitySchemaString); if (migrationRequired) { tableDescriptors.add( prepareTableDescriptor(table, entitySchemaString)); } } } if (createTableAndFamilies) { createTables(tableDescriptors); } } }
SchemaTool { public void createOrMigrateSchemaDirectory(String schemaDirectory, boolean createTableAndFamilies) throws InterruptedException { List<String> schemaStrings; if (schemaDirectory.startsWith(CLASSPATH_PREFIX)) { URL dirURL = getClass().getClassLoader().getResource( schemaDirectory.substring(CLASSPATH_PREFIX.length())); if (dirURL != null && dirURL.getProtocol().equals("file")) { try { schemaStrings = getSchemaStringsFromDir(new File(dirURL.toURI())); } catch (URISyntaxException e) { throw new DatasetException(e); } } else if (dirURL != null && dirURL.getProtocol().equals("jar")) { String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); schemaStrings = getSchemaStringsFromJar(jarPath, schemaDirectory.substring(CLASSPATH_PREFIX.length())); } else { String msg = "Could not find classpath resource: " + schemaDirectory; LOG.error(msg); throw new DatasetException(msg); } } else { schemaStrings = getSchemaStringsFromDir(new File(schemaDirectory)); } Map<String, List<String>> tableEntitySchemaMap = new HashMap<String, List<String>>(); for (String schemaString : schemaStrings) { List<String> tables = getTablesFromSchemaString(schemaString); for (String table : tables) { if (tableEntitySchemaMap.containsKey(table)) { tableEntitySchemaMap.get(table).add(schemaString); } else { List<String> entityList = new ArrayList<String>(); entityList.add(schemaString); tableEntitySchemaMap.put(table, entityList); } } } for (Entry<String, List<String>> entry : tableEntitySchemaMap.entrySet()) { String table = entry.getKey(); List<String> entitySchemas = entry.getValue(); if (entitySchemas.size() == 0) { String msg = "Table requested, but no entity schemas for Table: " + table; LOG.error(msg); throw new ValidationException(msg); } } Collection<HTableDescriptor> tableDescriptors = Lists.newArrayList(); for (Entry<String, List<String>> entry : tableEntitySchemaMap.entrySet()) { String table = entry.getKey(); for (String entitySchemaString : entry.getValue()) { boolean migrationRequired = prepareManagedSchema(table, entitySchemaString); if (migrationRequired) { tableDescriptors.add( prepareTableDescriptor(table, entitySchemaString)); } } } if (createTableAndFamilies) { createTables(tableDescriptors); } } SchemaTool(HBaseAdmin hbaseAdmin, SchemaManager entityManager); }
SchemaTool { public void createOrMigrateSchemaDirectory(String schemaDirectory, boolean createTableAndFamilies) throws InterruptedException { List<String> schemaStrings; if (schemaDirectory.startsWith(CLASSPATH_PREFIX)) { URL dirURL = getClass().getClassLoader().getResource( schemaDirectory.substring(CLASSPATH_PREFIX.length())); if (dirURL != null && dirURL.getProtocol().equals("file")) { try { schemaStrings = getSchemaStringsFromDir(new File(dirURL.toURI())); } catch (URISyntaxException e) { throw new DatasetException(e); } } else if (dirURL != null && dirURL.getProtocol().equals("jar")) { String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); schemaStrings = getSchemaStringsFromJar(jarPath, schemaDirectory.substring(CLASSPATH_PREFIX.length())); } else { String msg = "Could not find classpath resource: " + schemaDirectory; LOG.error(msg); throw new DatasetException(msg); } } else { schemaStrings = getSchemaStringsFromDir(new File(schemaDirectory)); } Map<String, List<String>> tableEntitySchemaMap = new HashMap<String, List<String>>(); for (String schemaString : schemaStrings) { List<String> tables = getTablesFromSchemaString(schemaString); for (String table : tables) { if (tableEntitySchemaMap.containsKey(table)) { tableEntitySchemaMap.get(table).add(schemaString); } else { List<String> entityList = new ArrayList<String>(); entityList.add(schemaString); tableEntitySchemaMap.put(table, entityList); } } } for (Entry<String, List<String>> entry : tableEntitySchemaMap.entrySet()) { String table = entry.getKey(); List<String> entitySchemas = entry.getValue(); if (entitySchemas.size() == 0) { String msg = "Table requested, but no entity schemas for Table: " + table; LOG.error(msg); throw new ValidationException(msg); } } Collection<HTableDescriptor> tableDescriptors = Lists.newArrayList(); for (Entry<String, List<String>> entry : tableEntitySchemaMap.entrySet()) { String table = entry.getKey(); for (String entitySchemaString : entry.getValue()) { boolean migrationRequired = prepareManagedSchema(table, entitySchemaString); if (migrationRequired) { tableDescriptors.add( prepareTableDescriptor(table, entitySchemaString)); } } } if (createTableAndFamilies) { createTables(tableDescriptors); } } SchemaTool(HBaseAdmin hbaseAdmin, SchemaManager entityManager); void createOrMigrateSchemaDirectory(String schemaDirectory,
      boolean createTableAndFamilies); void createOrMigrateSchemaFile(String tableName,
      String entitySchemaFilePath, boolean createTableAndFamilies); void createOrMigrateSchemaFile(String tableName,
      File entitySchemaFile, boolean createTableAndFamilies); void createOrMigrateSchema(String tableName, String entitySchemaString,
      boolean createTableAndFamilies); }
SchemaTool { public void createOrMigrateSchemaDirectory(String schemaDirectory, boolean createTableAndFamilies) throws InterruptedException { List<String> schemaStrings; if (schemaDirectory.startsWith(CLASSPATH_PREFIX)) { URL dirURL = getClass().getClassLoader().getResource( schemaDirectory.substring(CLASSPATH_PREFIX.length())); if (dirURL != null && dirURL.getProtocol().equals("file")) { try { schemaStrings = getSchemaStringsFromDir(new File(dirURL.toURI())); } catch (URISyntaxException e) { throw new DatasetException(e); } } else if (dirURL != null && dirURL.getProtocol().equals("jar")) { String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); schemaStrings = getSchemaStringsFromJar(jarPath, schemaDirectory.substring(CLASSPATH_PREFIX.length())); } else { String msg = "Could not find classpath resource: " + schemaDirectory; LOG.error(msg); throw new DatasetException(msg); } } else { schemaStrings = getSchemaStringsFromDir(new File(schemaDirectory)); } Map<String, List<String>> tableEntitySchemaMap = new HashMap<String, List<String>>(); for (String schemaString : schemaStrings) { List<String> tables = getTablesFromSchemaString(schemaString); for (String table : tables) { if (tableEntitySchemaMap.containsKey(table)) { tableEntitySchemaMap.get(table).add(schemaString); } else { List<String> entityList = new ArrayList<String>(); entityList.add(schemaString); tableEntitySchemaMap.put(table, entityList); } } } for (Entry<String, List<String>> entry : tableEntitySchemaMap.entrySet()) { String table = entry.getKey(); List<String> entitySchemas = entry.getValue(); if (entitySchemas.size() == 0) { String msg = "Table requested, but no entity schemas for Table: " + table; LOG.error(msg); throw new ValidationException(msg); } } Collection<HTableDescriptor> tableDescriptors = Lists.newArrayList(); for (Entry<String, List<String>> entry : tableEntitySchemaMap.entrySet()) { String table = entry.getKey(); for (String entitySchemaString : entry.getValue()) { boolean migrationRequired = prepareManagedSchema(table, entitySchemaString); if (migrationRequired) { tableDescriptors.add( prepareTableDescriptor(table, entitySchemaString)); } } } if (createTableAndFamilies) { createTables(tableDescriptors); } } SchemaTool(HBaseAdmin hbaseAdmin, SchemaManager entityManager); void createOrMigrateSchemaDirectory(String schemaDirectory,
      boolean createTableAndFamilies); void createOrMigrateSchemaFile(String tableName,
      String entitySchemaFilePath, boolean createTableAndFamilies); void createOrMigrateSchemaFile(String tableName,
      File entitySchemaFile, boolean createTableAndFamilies); void createOrMigrateSchema(String tableName, String entitySchemaString,
      boolean createTableAndFamilies);  }