public void ensureCreated(String path, byte[] value) throws InterruptedException, KeeperException { ensureCreated(path, value, DEFAULT_CREATE_MODE); }
public void ensureCreated(CreateMode createMode) throws InterruptedException, KeeperException { zk.ensureCreated(nodePath, encode(initialValue), createMode); } }
public void ensureCreated(String path, byte[] value, CreateMode createMode) throws InterruptedException, KeeperException { if (!path.isEmpty() && exists(path, false) == null) { ensureCreated(new File(path).getParent(), null, createMode); create(path, value, DEFAULT_ACL, createMode); NodeCreationBarrier.block(ZooKeeperPlus.this, path); } }
@Override public List<ConnectedServerMetadata> getLiveServers(){ if (servers == null) { // TODO this is a kinda temporary hack. ring groups in prod haven't created the servers path so we can't rely // on it being there. prolly sweep after migrating. try { zk.ensureCreated(ZkPath.append(ringGroupPath, SERVERS_PATH), null); } catch (Exception e) { LOG.error("Error creating server path!", e); } servers = new WatchedMap<WatchedThriftNode<ConnectedServerMetadata>>(zk, ZkPath.append(ringGroupPath, SERVER_NODE), new ElementLoader<WatchedThriftNode<ConnectedServerMetadata>>() { @Override public WatchedThriftNode<ConnectedServerMetadata> load(ZooKeeperPlus zk, String basePath, String relPath) throws KeeperException, InterruptedException, IOException { return new WatchedThriftNode<>(zk, ZkPath.append(basePath, relPath), true, null, null, emptyConnectedServerMetadata); } }); } ArrayList<ConnectedServerMetadata> result = Lists.newArrayList(); for (WatchedThriftNode<ConnectedServerMetadata> host : servers.values()) { result.add(host.get()); } return result; }
zk.ensureCreated(domainsRoot, null); domains = new WatchedMap<ZkDomain>(zk, domainsRoot, new WatchedMap.ElementLoader<ZkDomain>() { @Override zk.ensureCreated(domainGroupsRoot, null); domainGroups = new WatchedMap<ZkDomainGroup>(zk, domainGroupsRoot, new WatchedMap.ElementLoader<ZkDomainGroup>() { @Override zk.ensureCreated(ringGroupsRoot, null); ringGroups = new WatchedMap<ZkRingGroup>(zk, ringGroupsRoot, new WatchedMap.ElementLoader<ZkRingGroup>() { @Override
@Test public void testIt() throws Exception { final ZooKeeperPlus zk = getZk(); zk.ensureCreated("/", null, CreateMode.PERSISTENT); assertExists("/", zk); zk.ensureCreated("/simple", "1".getBytes(), CreateMode.PERSISTENT); assertExists("/simple", zk); zk.ensureCreated("/simple", "2".getBytes(), CreateMode.PERSISTENT); assertExists("/simple", zk); assertTrue(Arrays.equals(zk.getData("/simple", false, null), "1".getBytes())); zk.ensureCreated("/deeper/file", null, CreateMode.PERSISTENT); assertExists("/deeper/file", zk); assertExists("/deeper", zk); zk.ensureCreated("/simple/even/deeper", "3".getBytes(), CreateMode.PERSISTENT); assertTrue(Arrays.equals(zk.getData("/simple", false, null), "1".getBytes())); }
public ZkDomain(ZooKeeperPlus zk, String path, boolean create, DomainMetadata initialMetadata) throws KeeperException, InterruptedException { this.zk = zk; this.path = path; this.name = ZkPath.getFilename(path); metadata = new WatchedThriftNode<DomainMetadata>(zk, path, true, create ? CreateMode.PERSISTENT : null, initialMetadata, new DomainMetadata()); if (create) { zk.ensureCreated(ZkPath.append(path, VERSIONS_PATH), null); } this.versions = new WatchedMap<ZkDomainVersion>(zk, ZkPath.append(path, VERSIONS_PATH), new WatchedMap.ElementLoader<ZkDomainVersion>() { @Override public ZkDomainVersion load(ZooKeeperPlus zk, String basePath, String relPath) throws KeeperException, InterruptedException { return new ZkDomainVersion(zk, ZkPath.append(basePath, relPath), getDomainVersionPropertiesSerialization()); } } ); }