@Override public void setConf(Configuration config) { // Make my own Configuration. Then I'll have my own connection to zk that // I can close myself when comes time. Configuration conf = new Configuration(config); try { setConf(conf, new ZKWatcher(conf, "replicationLogCleaner", null)); } catch (IOException e) { LOG.error("Error while configuring " + this.getClass().getName(), e); } }
private static void resetAcls(final Configuration conf, boolean eraseAcls) throws Exception { ZKWatcher zkw = new ZKWatcher(conf, "ZKAclReset", null); try { LOG.info((eraseAcls ? "Erase" : "Set") + " HBase ACLs for " + zkw.getQuorum() + " " + zkw.getZNodePaths().baseZNode); resetAcls(zkw, zkw.getZNodePaths().baseZNode, eraseAcls); } finally { zkw.close(); } }
@Override public void checkTaskStillAvailable(String path) { // A negative retry count will lead to ignoring all error processing. this.watcher .getRecoverableZooKeeper() .getZooKeeper() .getData(path, this.watcher, new GetDataAsyncCallback(), Long.valueOf(-1) /* retry count */); SplitLogCounters.tot_mgr_get_data_queued.increment(); }
private TableHFileArchiveTracker(ZKWatcher watcher, HFileArchiveTableMonitor monitor) { super(watcher); watcher.registerListener(this); this.monitor = monitor; this.archiveHFileZNode = ZKTableArchiveClient.getArchiveZNode(watcher.getConfiguration(), watcher); }
public HFileArchiveManager(Connection connection, Configuration conf) throws ZooKeeperConnectionException, IOException { this.zooKeeper = new ZKWatcher(conf, "hfileArchiveManager-on-" + connection.toString(), connection); this.archiveZnode = ZKTableArchiveClient.getArchiveZNode(this.zooKeeper.getConfiguration(), this.zooKeeper); }
/** * Get the authentication token of the user for the cluster specified in the configuration * @return null if the user does not have the token, otherwise the auth token for the cluster. */ private static Token<AuthenticationTokenIdentifier> getAuthToken(Configuration conf, User user) throws IOException, InterruptedException { ZKWatcher zkw = new ZKWatcher(conf, "TokenUtil-getAuthToken", null); try { String clusterId = ZKClusterId.readClusterIdZNode(zkw); if (clusterId == null) { throw new IOException("Failed to get cluster ID"); } return new AuthenticationTokenSelector().selectToken(new Text(clusterId), user.getTokens()); } catch (KeeperException e) { throw new IOException(e); } finally { zkw.close(); } }
/** * Creates a cluster status tracker. * * <p>After construction, use {@link #start} to kick off tracking. * * @param watcher reference to the {@link ZKWatcher} which also contains configuration and * constants * @param abortable used to abort if a fatal error occurs */ public ClusterStatusTracker(ZKWatcher watcher, Abortable abortable) { super(watcher, watcher.getZNodePaths().clusterStateZNode, abortable); }
/** * Closes the current ZKW (if not null) and creates a new one * @throws IOException If anything goes wrong connecting */ synchronized void reloadZkWatcher() throws IOException { if (zkw != null) zkw.close(); zkw = new ZKWatcher(ctx.getConfiguration(), "connection to cluster: " + ctx.getPeerId(), this); getZkw().registerListener(new PeerRegionServerListener(this)); }
@After public void tearDown() throws KeeperException, ZooKeeperConnectionException, IOException { // Make sure zk is clean before we run the next test. ZKWatcher zkw = new ZKWatcher(TESTUTIL.getConfiguration(), "@Before", new Abortable() { @Override public void abort(String why, Throwable e) { throw new RuntimeException(why, e); } @Override public boolean isAborted() { return false; } }); ZKUtil.deleteNodeRecursively(zkw, zkw.getZNodePaths().baseZNode); zkw.close(); }
/** * Stop this tracker and the passed zookeeper */ public void stop() { if (this.stopped) return; this.stopped = true; this.watcher.close(); } }
private void testZNodeACLs() throws IOException, KeeperException, InterruptedException { ZKWatcher watcher = new ZKWatcher(conf, "IntegrationTestZnodeACLs", null); RecoverableZooKeeper zk = ZKUtil.connect(this.conf, watcher); String baseZNode = watcher.getZNodePaths().baseZNode; LOG.info(""); LOG.info("***********************************************************************************"); LOG.info("Checking ZK permissions, root znode: " + baseZNode); LOG.info("***********************************************************************************"); LOG.info(""); checkZnodePermsRecursive(watcher, zk, baseZNode); LOG.info("Checking ZK permissions: SUCCESS"); }
/** * create an address tracker instance * @param sn if not-null set the active master * @param infoPort if there is an active master, set its info port. */ private MasterAddressTracker setupMasterTracker(final ServerName sn, final int infoPort) throws Exception { ZKWatcher zk = new ZKWatcher(TEST_UTIL.getConfiguration(), name.getMethodName(), null); ZKUtil.createAndFailSilent(zk, zk.getZNodePaths().baseZNode); // Should not have a master yet MasterAddressTracker addressTracker = new MasterAddressTracker(zk, null); addressTracker.start(); assertFalse(addressTracker.hasMaster()); zk.registerListener(addressTracker); // Use a listener to capture when the node is actually created NodeCreationListener listener = new NodeCreationListener(zk, zk.getZNodePaths().masterAddressZNode); zk.registerListener(listener); if (sn != null) { LOG.info("Creating master node"); MasterAddressTracker.setMasterAddress(zk, zk.getZNodePaths().masterAddressZNode, sn, infoPort); // Wait for the node to be created LOG.info("Waiting for master address manager to be notified"); listener.waitForCreation(); LOG.info("Master node created"); } return addressTracker; }
/** * Starts the syncer * @throws KeeperException if error occurs when trying to create base nodes on client ZK */ public void start() throws KeeperException { LOG.debug("Starting " + getClass().getSimpleName()); this.watcher.registerListener(this); // create base znode on remote ZK ZKUtil.createWithParents(clientZkWatcher, watcher.getZNodePaths().baseZNode); // set meta znodes for client ZK Collection<String> nodes = getNodesToWatch(); LOG.debug("Znodes to watch: " + nodes); // initialize queues and threads for (String node : nodes) { BlockingQueue<byte[]> queue = new ArrayBlockingQueue<>(1); queues.put(node, queue); Thread updater = new ClientZkUpdater(node, queue); updater.setDaemon(true); updater.start(); watchAndCheckExists(node); } }
/** * @param watcher * @param sn ServerName * @param master In an instance of a Master. */ ActiveMasterManager(ZKWatcher watcher, ServerName sn, Server master) { super(watcher); watcher.registerListener(this); this.sn = sn; this.master = master; }
try { ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher(); List<String> servers = ZKUtil.listChildrenNoWatch(zkw, zkw.getZNodePaths().rsZNode); server.startsWith(hostName.toLowerCase(Locale.ROOT)+",")); zkw.close(); } finally { TEST_UTIL.shutdownMiniCluster();
/** * Delete the specified node with the specified version. Sets no watches. * Throws all exceptions. */ public static boolean deleteNode(ZKWatcher zkw, String node, int version) throws KeeperException { try { zkw.getRecoverableZooKeeper().delete(node, version); return true; } catch(KeeperException.BadVersionException bve) { return false; } catch(InterruptedException ie) { zkw.interruptedException(ie); return false; } }
private static byte[] getDataInternal(ZKWatcher zkw, String znode, Stat stat, boolean watcherSet) throws KeeperException { try { byte [] data = zkw.getRecoverableZooKeeper().getData(znode, zkw, stat); logRetrievedMsg(zkw, znode, data, watcherSet); return data; } catch (KeeperException.NoNodeException e) { // This log can get pretty annoying when we cycle on 100ms waits. // Enable trace if you really want to see it. LOG.trace(zkw.prefix("Unable to get data of znode " + znode + " " + "because node does not exist (not an error)")); return null; } catch (KeeperException e) { LOG.warn(zkw.prefix("Unable to get data of znode " + znode), e); zkw.keeperException(e); return null; } catch (InterruptedException e) { LOG.warn(zkw.prefix("Unable to get data of znode " + znode), e); zkw.interruptedException(e); return null; } }
/** * Get znode data. Does not set a watcher. * * @return ZNode data, null if the node does not exist or if there is an error. */ public static byte [] getData(ZKWatcher zkw, String znode) throws KeeperException, InterruptedException { try { byte [] data = zkw.getRecoverableZooKeeper().getData(znode, null, null); logRetrievedMsg(zkw, znode, data, false); return data; } catch (KeeperException.NoNodeException e) { LOG.debug(zkw.prefix("Unable to get data of znode " + znode + " " + "because node does not exist (not an error)")); return null; } catch (KeeperException e) { LOG.warn(zkw.prefix("Unable to get data of znode " + znode), e); zkw.keeperException(e); return null; } }
if (zkw.getConfiguration().get("hbase.zookeeper.useMulti") != null) { LOG.warn("hbase.zookeeper.useMulti is deprecated. Default to true always."); zkw.getRecoverableZooKeeper().multi(zkOps); } catch (KeeperException ke) { switch (ke.code()) { zkw.interruptedException(ie);
public static ArrayList<ACL> createACL(ZKWatcher zkw, String node, boolean isSecureZooKeeper) { if (!node.startsWith(zkw.getZNodePaths().baseZNode)) { return Ids.OPEN_ACL_UNSAFE; ArrayList<ACL> acls = new ArrayList<>(); String[] superUsers = zkw.getConfiguration().getStrings(Superusers.SUPERUSER_CONF_KEY); String hbaseUser = null; try { if (zkw.getZNodePaths().isClientReadable(node)) { acls.addAll(Ids.CREATOR_ALL_ACL); acls.addAll(Ids.READ_ACL_UNSAFE);