/** * Look for namespace ID in ZK. Throw NamespaceNotFoundException if not found. */ public static Namespace.ID getNamespaceId(ClientContext context, String namespaceName) throws NamespaceNotFoundException { final ArrayList<Namespace.ID> singleId = new ArrayList<>(1); getAllNamespaces(context, (id, name) -> { if (name.equals(namespaceName)) singleId.add(Namespace.ID.of(id)); }); if (singleId.isEmpty()) throw new NamespaceNotFoundException(null, namespaceName, "getNamespaceId() failed to find namespace"); return singleId.get(0); }
/** * Return sorted map with key = ID, value = namespaceName */ public static SortedMap<Namespace.ID,String> getIdToNameMap(ClientContext context) { SortedMap<Namespace.ID,String> idMap = new TreeMap<>(); getAllNamespaces(context, (id, name) -> idMap.put(Namespace.ID.of(id), name)); return idMap; }
/** * Return sorted map with key = namespaceName, value = ID */ public static SortedMap<String,Namespace.ID> getNameToIdMap(ClientContext context) { SortedMap<String,Namespace.ID> nameMap = new TreeMap<>(); getAllNamespaces(context, (id, name) -> nameMap.put(name, Namespace.ID.of(id))); return nameMap; }
Namespace.ID namespaceId = Namespace.ID.of(namespaceIdStr);
namespaceName = null; } else { Namespace.ID namespaceId = Namespace.ID.of(new String(nId, UTF_8)); if (!namespaceId.equals(Namespace.ID.DEFAULT)) { try {
/** * Returns the namespace id for a given table ID. * * @param context * The Accumulo client context * @param tableId * The tableId * @return The namespace id which this table resides in. * @throws IllegalArgumentException * if the table doesn't exist in ZooKeeper */ public static Namespace.ID getNamespaceId(ClientContext context, Table.ID tableId) throws TableNotFoundException { checkArgument(context != null, "instance is null"); checkArgument(tableId != null, "tableId is null"); ZooCache zc = getZooCache(context); byte[] n = zc.get(context.getZooKeeperRoot() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_NAMESPACE); // We might get null out of ZooCache if this tableID doesn't exist if (n == null) { throw new TableNotFoundException(tableId.canonicalID(), null, null); } return Namespace.ID.of(new String(n, UTF_8)); } }