public static boolean isHostRegistered(final ZooKeeperClient client, final String host) { try { final Stat stat = client.exists(Paths.configHostId(host)); return stat != null; } catch (KeeperException e) { throw new HeliosRuntimeException("getting host " + host + " id failed", e); } }
/** * Registers a host into ZooKeeper. The {@code id} is initially generated randomly by the Agent * and persisted on disk. This way, in the event that you have two agents attempting to register * with the same value of @{code host}, the first one will win. */ @Override public void registerHost(final String host, final String id) { final ZooKeeperClient client = provider.get("registerHost"); try { ZooKeeperRegistrarUtil.registerHost(client, Paths.configHostId(host), host, id); } catch (Exception e) { throw new HeliosRuntimeException("registering host " + host + " failed", e); } }
operations.add(delete(Paths.configHostId(host))); operations.add(create(Paths.configHostId(host), hostId.getBytes(UTF_8)));
@Override public boolean tryToRegister(ZooKeeperClient client) throws KeeperException, HostNotFoundException { final String idPath = Paths.configHostId(name); final String hostInfoPath = Paths.statusHostInfo(name);
final String idPath = Paths.configHostId(host); if (client.exists(idPath) != null) { operations.add(delete(idPath));
new DefaultZooKeeperClient(zk().curatorWithSuperAuth()); final String idPath = Paths.configHostId(host); ZooKeeperRegistrarUtil.registerHost(zkClient, idPath, host, UUID.randomUUID().toString());
.rule(Paths.configHostId(PATH_COMPONENT_WILDCARD), CREATE | DELETE, agentId) .rule(Paths.configHostPorts(PATH_COMPONENT_WILDCARD), CREATE | DELETE, agentId) .rule(Paths.statusHosts(), CREATE | DELETE, agentId)
@Override public void tryToRegister(ZooKeeperClient client) throws KeeperException { final String idPath = Paths.configHostId(name);
final String idPath = Paths.configHostId(host); if (client.exists(idPath) != null) { operations.add(delete(idPath));
/** * Registers a host into ZooKeeper. The {@code id} is initially generated randomly by the Agent * and persisted on disk. This way, in the event that you have two agents attempting to register * with the same value of @{code host}, the first one will win. */ @Override public void registerHost(final String host, final String id) { log.info("registering host: {}", host); final ZooKeeperClient client = provider.get("registerHost"); try { // TODO (dano): this code is replicated in AgentZooKeeperRegistrar // This would've been nice to do in a transaction but PathChildrenCache ensures paths // so we can't know what paths already exist so assembling a suitable transaction is too // painful. client.ensurePath(Paths.configHost(host)); client.ensurePath(Paths.configHostJobs(host)); client.ensurePath(Paths.configHostPorts(host)); client.ensurePath(Paths.statusHost(host)); client.ensurePath(Paths.statusHostJobs(host)); // Finish registration by creating the id node last client.createAndSetData(Paths.configHostId(host), id.getBytes(UTF_8)); } catch (Exception e) { throw new HeliosRuntimeException("registering host " + host + " failed", e); } }
stat = client.exists(Paths.configHostId(host)); } catch (KeeperException e) { throw new HeliosRuntimeException("Failed to check host status", e);