Search in sources :

Example 26 with Group

use of io.fabric8.openshift.api.model.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);
    }
}
Also used : RuntimeProperties(io.fabric8.api.RuntimeProperties) KeeperException(org.apache.zookeeper.KeeperException) InstanceNotFoundException(javax.management.InstanceNotFoundException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 27 with Group

use of io.fabric8.openshift.api.model.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();
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) ZooKeeperGroup(io.fabric8.groups.internal.ZooKeeperGroup) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) Test(org.junit.Test)

Example 28 with Group

use of io.fabric8.openshift.api.model.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();
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) ZooKeeperGroup(io.fabric8.groups.internal.ZooKeeperGroup) Test(org.junit.Test)

Example 29 with Group

use of io.fabric8.openshift.api.model.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();
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) ZooKeeperGroup(io.fabric8.groups.internal.ZooKeeperGroup) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) Test(org.junit.Test)

Example 30 with Group

use of io.fabric8.openshift.api.model.Group in project fabric8 by jboss-fuse.

the class GroupTest method testGroupClose.

// Tests that if close() is executed right after start(), there are no left over entries.
// (see  https://github.com/jboss-fuse/fuse/issues/133)
@Test
public void testGroupClose() throws Exception {
    int port = findFreePort();
    NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + port).connectionTimeoutMs(6000).sessionTimeoutMs(6000).retryPolicy(new RetryNTimes(10, 100));
    CuratorFramework curator = builder.build();
    curator.start();
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    String groupNode = "/singletons/test" + System.currentTimeMillis();
    curator.create().creatingParentsIfNeeded().forPath(groupNode);
    for (int i = 0; i < 100; i++) {
        ZooKeeperGroup<NodeState> group = new ZooKeeperGroup<NodeState>(curator, groupNode, NodeState.class);
        group.add(listener);
        group.update(new NodeState("foo"));
        group.start();
        group.close();
        List<String> entries = curator.getChildren().forPath(groupNode);
        assertTrue(entries.isEmpty() || group.isUnstable());
        if (group.isUnstable()) {
            // let's wait for session timeout
            curator.close();
            curator = builder.build();
            curator.start();
            curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
        }
    }
    curator.close();
    cnxnFactory.shutdown();
    cnxnFactory.join();
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) ZooKeeperGroup(io.fabric8.groups.internal.ZooKeeperGroup) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 CuratorFramework (org.apache.curator.framework.CuratorFramework)12 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)9 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 RetryNTimes (org.apache.curator.retry.RetryNTimes)8 NodeState (io.fabric8.groups.NodeState)7 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)6 File (java.io.File)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Profile (io.fabric8.api.Profile)4 GitNode (io.fabric8.git.GitNode)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 RuntimeProperties (io.fabric8.api.RuntimeProperties)3 MQBrokerConfigDTO (io.fabric8.api.jmx.MQBrokerConfigDTO)3 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)3 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)3 TcpGateway (io.fabric8.gateway.handlers.tcp.TcpGateway)2 Group (io.fabric8.groups.Group)2