use of io.fabric8.groups.Group in project fabric8 by jboss-fuse.
the class GitHttpServerRegistrationHandler method createState.
private GitNode createState() {
RuntimeProperties sysprops = runtimeProperties.get();
String runtimeIdentity = sysprops.getRuntimeIdentity();
GitNode state = new GitNode("fabric-repo", runtimeIdentity);
if (group != null && group.isMaster()) {
String externalGitUrl = readExternalGitUrl();
if (externalGitUrl != null) {
state.setUrl(externalGitUrl);
} else {
String fabricRepoUrl = "${zk:" + runtimeIdentity + "/http}/git/fabric/";
state.setUrl(fabricRepoUrl);
}
}
return state;
}
use of io.fabric8.groups.Group in project fabric8 by jboss-fuse.
the class GitHttpServerRegistrationHandler method zkCleanUp.
private void zkCleanUp(Group<GitNode> group) {
try {
RuntimeProperties sysprops = runtimeProperties.get();
String runtimeIdentity = sysprops.getRuntimeIdentity();
curator.get().newNamespaceAwareEnsurePath(ZkPath.GIT.getPath()).ensure(curator.get().getZookeeperClient());
List<String> allChildren = ZooKeeperUtils.getAllChildren(curator.get(), ZkPath.GIT.getPath());
for (String path : allChildren) {
String stringData = ZooKeeperUtils.getStringData(curator.get(), path);
if (stringData.contains("\"container\":\"" + runtimeIdentity + "\"")) {
LOGGER.info("Found older ZK \"/fabric/registry/clusters/git\" entry for node " + runtimeIdentity);
ZooKeeperUtils.delete(curator.get(), path);
LOGGER.info("Older ZK \"/fabric/registry/clusters/git\" entry for node " + runtimeIdentity + " has been removed");
}
}
} catch (KeeperException.NoNodeException ignored) {
} catch (Exception e) {
handleException(e);
}
}
use of io.fabric8.groups.Group in project fabric8 by jboss-fuse.
the class GroupTest method testJoinBeforeConnect.
@Test
public void testJoinBeforeConnect() throws Exception {
int port = findFreePort();
CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryNTimes(10, 100)).build();
curator.start();
Group<NodeState> group = new ZooKeeperGroup<NodeState>(curator, "/singletons/test" + System.currentTimeMillis(), NodeState.class);
group.add(listener);
group.start();
GroupCondition groupCondition = new GroupCondition();
group.add(groupCondition);
assertFalse(group.isConnected());
assertFalse(group.isMaster());
group.update(new NodeState("foo"));
NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
assertTrue(groupCondition.waitForConnected(5, TimeUnit.SECONDS));
assertTrue(groupCondition.waitForMaster(5, TimeUnit.SECONDS));
group.close();
curator.close();
cnxnFactory.shutdown();
cnxnFactory.join();
}
use of io.fabric8.groups.Group in project fabric8 by jboss-fuse.
the class GroupTest method testRejoinAfterDisconnect.
@Test
public void testRejoinAfterDisconnect() throws Exception {
int port = findFreePort();
CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryNTimes(10, 100)).build();
curator.start();
NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
Group<NodeState> group = new ZooKeeperGroup<NodeState>(curator, "/singletons/test" + System.currentTimeMillis(), NodeState.class);
group.add(listener);
group.update(new NodeState("foo"));
group.start();
GroupCondition groupCondition = new GroupCondition();
group.add(groupCondition);
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
assertTrue(groupCondition.waitForConnected(5, TimeUnit.SECONDS));
assertTrue(groupCondition.waitForMaster(5, TimeUnit.SECONDS));
cnxnFactory.shutdown();
cnxnFactory.join();
groupCondition.waitForDisconnected(5, TimeUnit.SECONDS);
group.remove(groupCondition);
assertFalse(group.isConnected());
assertFalse(group.isMaster());
groupCondition = new GroupCondition();
group.add(groupCondition);
cnxnFactory = startZooKeeper(port);
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
assertTrue(groupCondition.waitForConnected(5, TimeUnit.SECONDS));
assertTrue(groupCondition.waitForMaster(5, TimeUnit.SECONDS));
group.close();
curator.close();
cnxnFactory.shutdown();
cnxnFactory.join();
}
use of io.fabric8.groups.Group in project fabric8 by jboss-fuse.
the class GroupTest method testJoinAfterConnect.
@Test
public void testJoinAfterConnect() throws Exception {
int port = findFreePort();
CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryNTimes(10, 100)).build();
curator.start();
final Group<NodeState> group = new ZooKeeperGroup<NodeState>(curator, "/singletons/test" + System.currentTimeMillis(), NodeState.class);
group.add(listener);
group.start();
assertFalse(group.isConnected());
assertFalse(group.isMaster());
GroupCondition groupCondition = new GroupCondition();
group.add(groupCondition);
NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
assertTrue(groupCondition.waitForConnected(5, TimeUnit.SECONDS));
assertFalse(group.isMaster());
group.update(new NodeState("foo"));
assertTrue(groupCondition.waitForMaster(5, TimeUnit.SECONDS));
group.close();
curator.close();
cnxnFactory.shutdown();
cnxnFactory.join();
}
Aggregations