/** * Write an annotation key value to the meta table. * * @param metaTableKey meta table key of the annotation to write. * @param value String value of the annotation to write. * @throws java.io.IOException in case of an error writing to the meta table. */ private void setKV( final String metaTableKey, final String value ) throws IOException { mTable.getFiji().getMetaTable().putValue(mTable.getName(), metaTableKey, Bytes.toBytes(value)); }
/** * Implements the --do=dump operation. * * @throws Exception on error. */ private void dumpLayout() throws Exception { final FijiTableLayout layout = mFiji.getMetaTable().getTableLayout(mTableURI.getTable()); final StringBuilder json = new StringBuilder(); json.append("/*\n"); json.append(" The raw JSON view of table layouts is intended for use by\n"); json.append(" system administrators or for debugging purposes.\n"); json.append("\n"); json.append(" Most users should use the 'fiji-schema-shell' DDL tool to modify\n"); json.append(" your table layouts instead.\n"); json.append("*/\n"); json.append(ToJson.toJsonString(layout.getDesc())); if (mWriteTo.isEmpty()) { System.out.println(json.toString()); } else { final String fileName = String.format("%s.json", mWriteTo); final FileOutputStream fos = new FileOutputStream(fileName); try { fos.write(Bytes.toBytes(json.toString())); } finally { ResourceUtils.closeOrLog(fos); } } }
/** * Write an annotation key value to the meta table. * * @param metaTableKey meta table key of the annotation to write. * @param value String value of the annotation to write. * @throws IOException in case of an error writing to the meta table. */ private void setKV( final String metaTableKey, final String value ) throws IOException { mTable.getFiji().getMetaTable().putValue(mTable.getName(), metaTableKey, Bytes.toBytes(value)); }
/** * Get the String value of an annotation from its meta table key. * * @param metaTableKey the meta table key of the annotation to retrieve. * @return the value of the given annotation or null if no annotation exists. * @throws IOException in case of an error reading from the meta table. */ private String getKV( final String metaTableKey ) throws IOException { try { return Bytes.toString( mTable.getFiji().getMetaTable().getValue(mTable.getName(), metaTableKey)); } catch (IOException ioe) { if (ioe.getMessage().equals(String.format( "Could not find any values associated with table %s and key %s", mTable.getName(), metaTableKey))) { return null; } else { throw ioe; } } }
/** * Get the String value of an annotation from its meta table key. * * @param metaTableKey the meta table key of the annotation to retrieve. * @return the value of the given annotation or null if no annotation exists. * @throws java.io.IOException in case of an error reading from the meta table. */ private String getKV( final String metaTableKey ) throws IOException { try { return Bytes.toString( mTable.getFiji().getMetaTable().getValue(mTable.getName(), metaTableKey)); } catch (IOException ioe) { if (ioe.getMessage().equals(String.format( "Could not find any values associated with table %s and key %s", mTable.getName(), metaTableKey))) { return null; } else { throw ioe; } } }
/** * Get the keySet from the meta table for the table served by this annotator. * * @return the meta table key set for the table served by this annotator. * @throws IOException in case of an error reading form the meta table. */ private Set<String> keySet() throws IOException { return mTable.getFiji().getMetaTable().keySet(mTable.getName()); }
/** * Dumps the history of layouts of a given table. * * @throws Exception on error. */ private void history() throws Exception { // Gather all of the layouts stored in the metaTable. final NavigableMap<Long, FijiTableLayout> timedLayouts = mFiji.getMetaTable().getTimedTableLayoutVersions(mTableURI.getTable(), mMaxVersions); if (timedLayouts.isEmpty()) { throw new RuntimeException("No such table: " + mTableURI.getTable()); } for (Map.Entry<Long, FijiTableLayout> entry: timedLayouts.entrySet()) { final long timestamp = entry.getKey(); final FijiTableLayout layout = entry.getValue(); final String json = ToJson.toJsonString(layout.getDesc()); if (mWriteTo.isEmpty()) { // SCHEMA-14: Add a newline to separate the dumped JSON versions of the layout. System.out.printf("timestamp: %d:%n%s%n", timestamp, json); } else { final String fileName = String.format("%s-%d.json", mWriteTo, timestamp); final FileOutputStream fos = new FileOutputStream(fileName); try { fos.write(Bytes.toBytes(json)); } finally { ResourceUtils.closeOrLog(fos); } } } }
/** * Remove the given meta table key. * * @param metaTableKey the key to remove from the meta table. * @throws java.io.IOException in case of an error writing to the meta table. */ private void removeKV( final String metaTableKey ) throws IOException { mTable.getFiji().getMetaTable().removeValues(mTable.getName(), metaTableKey); }
/** * Get the keySet from the meta table for the table served by this annotator. * * @return the meta table key set for the table served by this annotator. * @throws java.io.IOException in case of an error reading form the meta table. */ private Set<String> keySet() throws IOException { return mTable.getFiji().getMetaTable().keySet(mTable.getName()); }
/** * Remove the given meta table key. * * @param metaTableKey the key to remove from the meta table. * @throws IOException in case of an error writing to the meta table. */ private void removeKV( final String metaTableKey ) throws IOException { mTable.getFiji().getMetaTable().removeValues(mTable.getName(), metaTableKey); }
mFiji.getMetaTable(); } catch (IllegalStateException e) { issues.add(String.format("Fiji instance %s is in illegal state.", mFiji));
/** * Install the job history table into a Fiji instance. This should be called only * via open, because we might want to update the layout of the job history table. * * @param fiji The Fiji instance to install this table in. * @throws IOException If there is an error. */ private static void install(Fiji fiji) throws IOException { if (!fiji.getTableNames().contains(TABLE_NAME)) { // Try to install the job history table if necessary. fiji.createTable( FijiTableLayout.createFromEffectiveJsonResource(TABLE_LAYOUT_RESOURCE).getDesc()); } // At this point, we either have an existing table or we just installed a new // one. Check if the table is using the old layout, and update it if it is. if (fiji.getMetaTable().getTableLayout(TABLE_NAME).getDesc().getLayoutId() .equals(PREV_TABLE_LAYOUT_VERSION)) { FijiTableLayout ktl = FijiTableLayout .createFromEffectiveJsonResource(TABLE_LAYOUT_V2); fiji.modifyTableLayout(ktl.getDesc()); } // If there are further updates to the job history layout, they should probably be added here. }
/** * Restores all tables from the metadata backup into the running Fiji instance. * * @param backup the deserialized backup of the metadata. * @param fiji the connected Fiji instance. * @throws IOException if there is an error communicating with HBase. */ public void restoreTables(MetadataBackup backup, Fiji fiji) throws IOException { final HBaseFactory hbaseFactory = HBaseFactory.Provider.get(); final HBaseAdmin hbaseAdmin = hbaseFactory.getHBaseAdminFactory(fiji.getURI()).create(fiji.getConf()); final FijiMetaTable metaTable = fiji.getMetaTable(); try { HBaseMetaTable.uninstall(hbaseAdmin, fiji.getURI()); HBaseMetaTable.install(hbaseAdmin, fiji.getURI()); final Map<String, TableBackup> tables = backup.getMetaTable().getTables(); for (Map.Entry<String, TableBackup> layoutEntry : tables.entrySet()) { final String tableName = layoutEntry.getKey(); LOG.debug("Found table backup entry for " + tableName); final TableBackup tableBackup = layoutEntry.getValue(); restoreTable(tableName, tableBackup, metaTable, fiji); } } finally { ResourceUtils.closeOrLog(hbaseAdmin); } }
.setSystemTable(fiji.getSystemTable().toBackup()) .setSchemaTable(fiji.getSchemaTable().toBackup()) .setMetaTable(fiji.getMetaTable().toBackup()) .build();
.setSystemTable(fiji.getSystemTable().toBackup()) .setSchemaTable(fiji.getSchemaTable().toBackup()) .setMetaTable(fiji.getMetaTable().toBackup()) .build();