@Override public ZkRing load(ZooKeeperPlus zk, String basePath, String relPath) throws KeeperException, InterruptedException { if (relPath.matches("ring-\\d+")) { return new ZkRing(zk, ZkPath.append(basePath, relPath), ZkRingGroup.this, coordinator, dataLocationChangeListener); } return null; } });
@Override public WatchedThriftNode<ClientMetadata> load(ZooKeeperPlus zk, String basePath, String relPath) throws KeeperException, InterruptedException, IOException { return new WatchedThriftNode<ClientMetadata>(zk, ZkPath.append(basePath, relPath), true, null, null, emptyClientMetadata); } });
@Override public void clearCommandQueue() throws IOException { try { List<String> children = zk.getChildren(ZkPath.append(path, COMMAND_QUEUE_PATH), false); for (String child : children) { zk.delete(ZkPath.append(path, COMMAND_QUEUE_PATH, child), 0); } } catch (Exception e) { throw new IOException(e); } }
@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); } });
public ZkPartitionProperties(ZooKeeperPlus zk, String partInfoPath) throws KeeperException, InterruptedException { String filename = ZkPath.getFilename(partInfoPath); String[] tokens = filename.split("-"); this.partNum = Integer.parseInt(tokens[tokens.length - 1]); this.numBytes = zk.getLong(ZkPath.append(partInfoPath, "num_bytes")); this.numRecords = zk.getLong(ZkPath.append(partInfoPath, "num_records")); }
@Override public void enqueueCommand(HostCommand command) throws IOException { try { zk.create(ZkPath.append(path, COMMAND_QUEUE_PATH, "command_"), command.toString().getBytes(), CreateMode.PERSISTENT_SEQUENTIAL); } catch (Exception e) { throw new IOException(e); } }
public static ZkRingGroup create(ZooKeeperPlus zk, String path, ZkDomainGroup domainGroup, Coordinator coordinator) throws KeeperException, InterruptedException, IOException { zk.create(path, domainGroup.getName().getBytes()); zk.create(ZkPath.append(path, CLIENTS_PATH), null); zk.create(ZkPath.append(path, SERVERS_PATH), null); zk.create(ZkPath.append(path, DotComplete.NODE_NAME), null); return new ZkRingGroup(zk, path, domainGroup, coordinator); }
private int countDescendants(String node) throws InterruptedException, KeeperException { List<String> children = zk.getChildren(node, false); int count = 0; for (String child : children) { count += countDescendants(ZkPath.append(node, child)); } return 1 + count; }
public static ZkDomainGroup create(final ZooKeeperPlus zk, final Coordinator coordinator, final String rootPath, final String name) throws InterruptedException, KeeperException, IOException { String path = ZkPath.append(rootPath, name); DomainGroupMetadata initialMetadata = new DomainGroupMetadata(); initialMetadata.set_domain_versions(new HashMap<Integer, Integer>()); return new ZkDomainGroup(zk, coordinator, path, true, initialMetadata); }
public static ZkRing create(ZooKeeperPlus zk, Coordinator coordinator, String ringGroup, int ringNum, RingGroup group, DataLocationChangeListener dataLocationChangeListener) throws KeeperException, InterruptedException { String ringPath = ZkPath.append(ringGroup, "ring-" + ringNum); zk.create(ringPath, null); zk.create(ZkPath.append(ringPath, HOSTS_PATH_SEGMENT), null); return new ZkRing(zk, ringPath, group, coordinator, dataLocationChangeListener); }
@Override public RingGroup addRingGroup(String ringGroupName, String domainGroupName) throws IOException { try { RingGroup rg = ZkRingGroup.create(zk, ZkPath.append(ringGroupsRoot, ringGroupName), (ZkDomainGroup)getDomainGroup(domainGroupName), this); ringGroups.put(ringGroupName, (ZkRingGroup)rg); return rg; } catch (Exception e) { throw new IOException(e); } }
protected Coordinator getMockCoordinator() throws Exception { return new ZooKeeperCoordinator.Factory().getCoordinator( ZooKeeperCoordinator.Factory.requiredOptions(getZkConnectString(), 100000000, ZkPath.append(getRoot(), "domains"), ZkPath.append(getRoot(), "domain_groups"), ZkPath.append(getRoot(), "ring_groups"), 5) ); }
public static ZkDomainVersion create(ZooKeeperPlus zk, String domainPath, int versionNumber, DomainVersionProperties domainVersionProperties, DomainVersionPropertiesSerialization domainVersionPropertiesSerialization) throws InterruptedException, KeeperException, IOException { String versionPath = ZkPath.append(domainPath, ZkDomain.VERSIONS_PATH, getPathName(versionNumber)); DomainVersionMetadata initialMetadata = new DomainVersionMetadata(null, new HashMap<Integer, PartitionMetadata>(), false, 0); setProperties(domainVersionPropertiesSerialization, domainVersionProperties, initialMetadata); return new ZkDomainVersion(zk, versionPath, domainVersionPropertiesSerialization, true, initialMetadata); }
@Before public void setUp() throws Exception { create(ZkPath.append(getRoot(), "ring-group-one")); TestZkRing.coordinator = new MockCoordinator(); }
@Before public void setUp() throws Exception { getZk().create(ZkPath.append(getRoot(), ZkDomain.VERSIONS_PATH), null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } }
@Test public void testLoad() throws Exception { ZkRing ring = ZkRing.create(getZk(), coordinator, ring_group_root, 1, null, null); ring.close(); ring = new ZkRing(getZk(), ZkPath.append(ring_group_root, "ring-1"), null, coordinator, null); assertEquals("ring number", 1, ring.getRingNumber()); assertEquals("number of hosts", 0, ring.getHosts().size()); ring.close(); }
@Test public void testLoad() throws Exception { ZkPartitionProperties.create(getZk(), getRoot(), 1, 15000, 550); ZkPartitionProperties pi = new ZkPartitionProperties(getZk(), ZkPath.append(getRoot(), "part-1")); assertEquals(1, pi.getPartitionNumber()); assertEquals(15000, pi.getNumBytes()); assertEquals(550, pi.getNumRecords()); } }
@Test public void testLoad() throws Exception { ZkDomainVersion.create(getZk(), getRoot(), 1, null, null); DomainVersion dv = new ZkDomainVersion(getZk(), ZkPath.append(getRoot(), "v/" + 1), null); assertEquals(1, dv.getVersionNumber()); assertNull(dv.getClosedAt()); assertFalse(DomainVersions.isClosed(dv)); assertFalse(dv.isDefunct()); }
@Test public void testCancelVersion() throws Exception { DomainVersion dv = ZkDomainVersion.create(getZk(), getRoot(), 1, null, null); assertEquals(1, dv.getVersionNumber()); assertNull(dv.getClosedAt()); assertFalse(DomainVersions.isClosed(dv)); dv.cancel(); assertNull(getZk().exists(ZkPath.append(getRoot(), "v/1"), false)); }