/** * Private constructor that opens a new JobHistoryFijiTable, creating it if necessary. * This method also updates an existing layout to the latest layout for the job * history table. * * @param fiji The fiji instance to retrieve the job history table from. * @throws IOException If there's an error opening the underlying HBaseFijiTable. */ private JobHistoryFijiTable(Fiji fiji) throws IOException { install(fiji); mFijiTable = fiji.openTable(TABLE_NAME); }
/** * Initializes a TableLayoutUpdateValidator which interprets schema IDs from the schema table of * the given Fiji instance. * * @param fiji the Fiji instance from which to get schema definitions. * @throws IOException in case of an error reading from the schema table. */ public TableLayoutUpdateValidator(Fiji fiji) throws IOException { mFiji = fiji; mSchemaTable = mFiji.getSchemaTable(); }
/** * Lists all the tables in a fiji instance. * * @param fiji Fiji instance to list the tables of. * @return A program exit code (zero on success). * @throws IOException If there is an error. */ private int listTables(Fiji fiji) throws IOException { for (String name : fiji.getTableNames()) { getPrintStream().println(fiji.getURI() + name); } return SUCCESS; }
/** * 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); } }
@Override protected int run(List<String> nonFlagArgs) throws Exception { Fiji fiji = null; FijiTable fijiTable = null; FijiSchemaTable schemaTable = null; try { fiji = Fiji.Factory.open(mTableURI); fijiTable = fiji.openTable(mTableURI.getTable()); FijiTableLayout fijiTableLayout = fijiTable.getLayout(); schemaTable = fiji.getSchemaTable(); getPrintStream().println(generateHiveDDLStatement(mTableURI, fijiTableLayout, schemaTable)); } catch (IOException ioe) { LOG.warn(ioe.getMessage()); return FAILURE; } finally { if (null != fiji) { ResourceUtils.releaseOrLog(fiji); } if (null != fijiTable) { ResourceUtils.releaseOrLog(fijiTable); } } return SUCCESS; } }
.setLayoutVersion(fiji.getSystemTable().getDataVersion().toString()) .setSystemTable(fiji.getSystemTable().toBackup()) .setSchemaTable(fiji.getSchemaTable().toBackup()) .setMetaTable(fiji.getMetaTable().toBackup()) .build();
if (fiji.isSecurityEnabled()) { FijiSecurityManager securityManager = fiji.getSecurityManager(); try { securityManager.checkCurrentGrantAccess(); for (String tableName : fiji.getTableNames()) { LOG.debug("Deleting fiji table " + tableName + "..."); fiji.deleteTable(tableName); fiji.release();
/** * Deletes an entire Fiji instance. * * @param instanceURI The Fiji instance to delete. * @return tool exit code. * @throws Exception on error. */ private int deleteInstance(FijiURI instanceURI) throws Exception { final Fiji fiji = Fiji.Factory.open(instanceURI); try { getPrintStream().println("WARNING: This instance contains the table(s):"); for (String name : fiji.getTableNames()) { getPrintStream().println(name); } if (isInteractive() && !inputConfirmation( String.format("Are you sure you want to delete Fiji instance '%s'?", instanceURI), instanceURI.getInstance())) { getPrintStream().println("Delete aborted."); return FAILURE; } } finally { fiji.release(); } FijiInstaller.get().uninstall(fiji.getURI(), getConf()); getPrintStream().println(String.format("Fiji instance '%s' deleted.", fiji.getURI())); return SUCCESS; }
/** {@inheritDoc} */ @Override public void close() throws IOException { mFiji.release(); mLock.close(); mZKClient.close(); } }
/** * 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)); }
for (String tableName : fiji.getTableNames()) { LOG.info("Deleting Fiji table {}.", tableName); fiji.deleteTable(tableName); fiji.release();
try { getPrintStream().println("WARNING: This instance contains the table(s):"); for (String name : fiji.getTableNames()) { getPrintStream().println(name); fiji.release();
if (fiji.isSecurityEnabled()) { throw new UnsupportedOperationException("Fiji Cassandra does not implement security."); fiji.release();
mFiji.getMetaTable(); } catch (IllegalStateException e) { issues.add(String.format("Fiji instance %s is in illegal state.", mFiji)); mFiji.getURI().getInstance()));
mInstanceUri = instanceUri; mFiji = Fiji.Factory.get().open(mInstanceUri); mSystemTable = mFiji.getSystemTable(); mFiji.release(); throw new FijiSecurityException("Cannot create a FijiSecurityManager for security version " + mSystemTable.getSecurityVersion() + ". Version must be "
/** {@inheritDoc} */ @Override public boolean equals(Object obj) { if (null == obj) { return false; } if (obj == this) { return true; } if (!getClass().equals(obj.getClass())) { return false; } final Fiji other = (Fiji) obj; // Equal if the two instances have the same URI: return mURI.equals(other.getURI()); }
if (mNumRegions >= 1) { mFiji.createTable(tableLayout, mNumRegions); mFiji.createTable(tableLayout, splitKeys.toArray(new byte[splitKeys.size()][])); mFiji.createTable(tableLayout);
for (String fijiTableName : mFiji.getTableNames()) { byte[] fijiHTableNameBytes = FijiManagedHBaseTableName.getFijiTableName(