/** * Program entry point. * * @param args The command-line arguments. * @throws Exception If there is an error. */ public static void main(String[] args) throws Exception { System.exit(new FijiToolLauncher().run(new LsTool(), args)); } }
/** * Lists all fiji instances. * * @param hbaseURI URI of the HBase instance to list the content of. * @return A program exit code (zero on success). * @throws IOException If there is an error. */ private int listInstances(FijiURI hbaseURI) throws IOException { for (String instanceName : getInstanceNames(hbaseURI)) { getPrintStream().println(FijiURI.newBuilder(hbaseURI).withInstanceName(instanceName).build()); } return SUCCESS; }
/** {@inheritDoc} */ @Override protected int run(List<String> nonFlagArgs) throws Exception { if (nonFlagArgs.isEmpty()) { nonFlagArgs.add(KConstants.DEFAULT_HBASE_URI); } int status = SUCCESS; for (String arg : nonFlagArgs) { status = (run(FijiURI.newBuilder(arg).build()) == SUCCESS) ? status : FAILURE; } return status; }
getPrintStream().printf("Specify a cluster with argument: fiji://zookeeper-quorum%n"); return FAILURE; return listInstances(argURI); final Fiji fiji = Fiji.Factory.open(argURI, getConf()); try { if (argURI.getTable() == null) { return listTables(fiji); for (FamilyLayout family : tableLayout.getFamilies()) { if (family.isMapType()) { getPrintStream().println(FijiURI.newBuilder(table.getURI()) .addColumnName(FijiColumnName.create(family.getName())) .build()); } else { for (ColumnLayout column : family.getColumns()) { getPrintStream().println(FijiURI.newBuilder(table.getURI()) .addColumnName(FijiColumnName.create(family.getName(), column.getName())) .build());
/** * 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; }
/** * Returns a set of instance names. * * @param hbaseURI URI of the HBase instance to list the content of. * @return ordered set of instance names. * @throws IOException on I/O error. */ protected static Set<String> getInstanceNames(FijiURI hbaseURI) throws IOException { // TODO(SCHEMA-188): Consolidate this logic in a single central place: final Configuration conf = HBaseConfiguration.create(); conf.set(HConstants.ZOOKEEPER_QUORUM, Joiner.on(",").join(hbaseURI.getZookeeperQuorumOrdered())); conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, hbaseURI.getZookeeperClientPort()); final HBaseAdmin hbaseAdmin = HBaseFactory.Provider.get().getHBaseAdminFactory(hbaseURI).create(conf); try { final Set<String> instanceNames = Sets.newTreeSet(); for (HTableDescriptor hTableDescriptor : hbaseAdmin.listTables()) { final String instanceName = parseInstanceName(hTableDescriptor.getNameAsString()); if (null != instanceName) { instanceNames.add(instanceName); } } return instanceNames; } finally { ResourceUtils.closeOrLog(hbaseAdmin); } }