/** * Gets data at the given path. Status information is not returned. A watch is established by this * call. * * @param zPath * path to get * @return path data, or null if non-existent */ public byte[] get(final String zPath) { return get(zPath, null); }
public static byte[] getLockData(ZooCache zc, String path) { List<String> children = zc.getChildren(path); if (children == null || children.size() == 0) { return null; } children = new ArrayList<>(children); Collections.sort(children); String lockNode = children.get(0); return zc.get(path + "/" + lockNode); }
public static byte[] getLockData(org.apache.accumulo.fate.zookeeper.ZooCache zc, String path, ZcStat stat) { List<String> children = zc.getChildren(path); if (children == null || children.size() == 0) { return null; } children = new ArrayList<>(children); Collections.sort(children); String lockNode = children.get(0); if (!lockNode.startsWith(LOCK_PREFIX)) { throw new RuntimeException("Node " + lockNode + " at " + path + " is not a lock node"); } return zc.get(path + "/" + lockNode, stat); }
@Override public boolean userExists(String user) { return zooCache.get(ZKUserPath + "/" + user) != null; }
/** * Given a zooCache and instanceId, look up the instance name. */ public static String lookupInstanceName(ZooCache zooCache, UUID instanceId) { checkArgument(zooCache != null, "zooCache is null"); checkArgument(instanceId != null, "instanceId is null"); for (String name : zooCache.getChildren(Constants.ZROOT + Constants.ZINSTANCES)) { String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + name; byte[] bytes = zooCache.get(instanceNamePath); UUID iid = UUID.fromString(new String(bytes, UTF_8)); if (iid.equals(instanceId)) { return name; } } return null; } }
private String get(String path) { byte[] v = propCache.get(path); if (v != null) { return new String(v, UTF_8); } else { return null; } }
private void updateTableStateCache() { synchronized (tableStateCache) { for (String tableId : zooStateCache.getChildren(zkRoot + Constants.ZTABLES)) if (zooStateCache .get(zkRoot + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_STATE) != null) updateTableStateCache(Table.ID.of(tableId)); } }
public synchronized String getRootUsername() { if (rootUserName == null) rootUserName = new String(zooCache.get(ZKUserPath), UTF_8); return rootUserName; }
public static long getSessionId(ZooCache zc, String path) { List<String> children = zc.getChildren(path); if (children == null || children.size() == 0) { return 0; } children = new ArrayList<>(children); Collections.sort(children); String lockNode = children.get(0); ZcStat stat = new ZcStat(); if (zc.get(path + "/" + lockNode, stat) != null) return stat.getEphemeralOwner(); return 0; }
private String getRaw(String key) { String zPath = propPathPrefix + "/" + key; byte[] v = propCache.get(zPath); String value = null; if (v != null) value = new String(v, UTF_8); return value; }
public static boolean isLockHeld(ZooCache zc, LockID lid) { List<String> children = zc.getChildren(lid.path); if (children == null || children.size() == 0) { return false; } children = new ArrayList<>(children); Collections.sort(children); String lockNode = children.get(0); if (!lid.node.equals(lockNode)) return false; ZcStat stat = new ZcStat(); return zc.get(lid.path + "/" + lid.node, stat) != null && stat.getEphemeralOwner() == lid.eid; }
@Override public boolean hasCachedTablePermission(String user, String table, TablePermission permission) { byte[] serializedPerms = zooCache.get(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table); if (serializedPerms != null) { return ZKSecurityTool.convertTablePermissions(serializedPerms).contains(permission); } return false; }
/** * Gets all the namespaces from ZK. The first arg (t) the BiConsumer accepts is the ID and the * second (u) is the namespaceName. */ private static void getAllNamespaces(ClientContext context, BiConsumer<String,String> biConsumer) { final ZooCache zc = context.getZooCache(); List<String> namespaceIds = zc.getChildren(context.getZooKeeperRoot() + Constants.ZNAMESPACES); for (String id : namespaceIds) { byte[] path = zc.get(context.getZooKeeperRoot() + Constants.ZNAMESPACES + "/" + id + Constants.ZNAMESPACE_NAME); if (path != null) { biConsumer.accept(id, new String(path, UTF_8)); } } }
@Override public boolean hasCachedNamespacePermission(String user, String namespace, NamespacePermission permission) { byte[] serializedPerms = zooCache .get(ZKUserPath + "/" + user + ZKUserNamespacePerms + "/" + namespace); if (serializedPerms != null) { return ZKSecurityTool.convertNamespacePermissions(serializedPerms).contains(permission); } return false; }
@Override public boolean hasCachedSystemPermission(String user, SystemPermission permission) { byte[] perms = zooCache.get(ZKUserPath + "/" + user + ZKUserSysPerms); if (perms == null) return false; return ZKSecurityTool.convertSystemPermissions(perms).contains(permission); }
@Override public Authorizations getCachedUserAuthorizations(String user) { byte[] authsBytes = zooCache.get(ZKUserPath + "/" + user + ZKUserAuths); if (authsBytes != null) return ZKSecurityTool.convertAuthorizations(authsBytes); return Authorizations.EMPTY; }
/** * Iterate over the queued work to remove entries that have been completed. */ @Override protected void cleanupFinishedWork() { final Iterator<String> work = queuedWork.iterator(); final String instanceId = client.getInstanceID(); while (work.hasNext()) { String filename = work.next(); // Null equates to the work was finished if (zooCache.get(ZooUtil.getRoot(instanceId) + ReplicationConstants.ZOO_WORK_QUEUE + "/" + filename) == null) { work.remove(); } } }
@Override public byte[] get(String path) throws DistributedStoreException { try { return cache.get(relative(path)); } catch (Exception ex) { throw new DistributedStoreException(ex); } }
/** * Look for namespace name in ZK. Throw NamespaceNotFoundException if not found. */ public static String getNamespaceName(ClientContext context, Namespace.ID namespaceId) throws NamespaceNotFoundException { String name; ZooCache zc = context.getZooCache(); byte[] path = zc.get(context.getZooKeeperRoot() + Constants.ZNAMESPACES + "/" + namespaceId.canonicalID() + Constants.ZNAMESPACE_NAME); if (path != null) name = new String(path, UTF_8); else throw new NamespaceNotFoundException(namespaceId.canonicalID(), null, "getNamespaceName() failed to find namespace"); return name; }
@Override public MonitorLocation get() { // lazily set up path and zooCache (see comment in constructor) if (this.context == null) { this.context = new ServerContext(new SiteConfiguration()); this.path = context.getZooKeeperRoot() + Constants.ZMONITOR_LOG4J_ADDR; this.zooCache = context.getZooCache(); } // get the current location from the cache and update if necessary ZcStat stat = new ZcStat(); byte[] loc = zooCache.get(path, stat); // mzxid is 0 if location does not exist and the non-zero transaction id of the last // modification otherwise return new MonitorLocation(stat.getMzxid(), loc); } }