Search in sources :

Example 51 with Group

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;
}
Also used : GitNode(io.fabric8.git.GitNode) RuntimeProperties(io.fabric8.api.RuntimeProperties)

Example 52 with Group

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);
    }
}
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 53 with Group

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();
}
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 54 with Group

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();
}
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 55 with Group

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();
}
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)

Aggregations

Group (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group)50 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)27 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)18 ActionGroup (org.opendaylight.genius.mdsalutil.actions.ActionGroup)15 GroupKey (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey)15 CuratorFramework (org.apache.curator.framework.CuratorFramework)12 Bucket (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket)11 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)11 IOException (java.io.IOException)9 StaleGroup (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.StaleGroup)9 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)9 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)8 RetryNTimes (org.apache.curator.retry.RetryNTimes)8 NodeState (io.fabric8.groups.NodeState)7 Map (java.util.Map)7 ItemSyncBox (org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox)7 BigInteger (java.math.BigInteger)6 HashMap (java.util.HashMap)6 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)6