Search in sources :

Example 66 with Group

use of io.fabric8.groups.Group in project fabric8 by jboss-fuse.

the class ServiceFactoryTest method testCallbackOnDisconnectCanClose.

@Test
public void testCallbackOnDisconnectCanClose() throws Exception {
    curator.close();
    LOG.info("....");
    SocketProxy socketProxy = new SocketProxy(new URI("tcp://localhost:" + zkPort));
    final CuratorFramework proxyCurator = CuratorFrameworkFactory.builder().connectString("localhost:" + socketProxy.getUrl().getPort()).sessionTimeoutMs(5000).connectionTimeoutMs(3000).retryPolicy(new RetryNTimes(10, 1000)).build();
    proxyCurator.start();
    proxyCurator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    LOG.info("curator is go: " + proxyCurator);
    final String path = "/singletons/test/threads" + System.currentTimeMillis() + "**";
    final ArrayList<Runnable> members = new ArrayList<Runnable>();
    final int nThreads = 1;
    final CountDownLatch gotDisconnectEvent = new CountDownLatch(1);
    class GroupRunnable implements Runnable, GroupListener<NodeState> {

        final int id;

        private final BlockingQueue<Integer> jobQueue = new LinkedBlockingDeque<Integer>();

        ZooKeeperGroup<NodeState> group;

        NodeState nodeState;

        public GroupRunnable(int id) {
            this.id = id;
            members.add(this);
            nodeState = new NodeState("foo" + id);
        }

        @Override
        public void run() {
            group = new ZooKeeperGroup<NodeState>(proxyCurator, path, NodeState.class);
            group.add(this);
            LOG.info("run: Added: " + this);
            try {
                while (true) {
                    switch(jobQueue.take()) {
                        case 0:
                            LOG.info("run: close: " + this);
                            try {
                                group.close();
                            } catch (IOException ignored) {
                            }
                            return;
                        case 1:
                            LOG.info("run: start: " + this);
                            group.start();
                            group.update(nodeState);
                            break;
                        case 2:
                            LOG.info("run: update: " + this);
                            nodeState.setId(nodeState.getId() + id);
                            group.update(nodeState);
                            break;
                    }
                }
            } catch (InterruptedException exit) {
            }
        }

        @Override
        public void groupEvent(Group<NodeState> group, GroupEvent event) {
            LOG.info("Got: event: " + event);
            if (event.equals(GroupEvent.DISCONNECTED)) {
                gotDisconnectEvent.countDown();
            }
        }
    }
    ;
    ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
    for (int i = 0; i < nThreads; i++) {
        executorService.execute(new GroupRunnable(i));
    }
    for (Runnable r : members) {
        GroupRunnable groupRunnable = (GroupRunnable) r;
        groupRunnable.jobQueue.offer(1);
        // wait for registration
        while (groupRunnable.group == null || groupRunnable.group.getId() == null) {
            TimeUnit.MILLISECONDS.sleep(100);
        }
    }
    boolean firsStartedIsMaster = ((GroupRunnable) members.get(0)).group.isMaster();
    assertTrue("first started is master", firsStartedIsMaster);
    LOG.info("got master...");
    // lets see how long they take to notice a no responses to heart beats
    socketProxy.pause();
    // splash in an update
    for (Runnable r : members) {
        GroupRunnable groupRunnable = (GroupRunnable) r;
        groupRunnable.jobQueue.offer(2);
    }
    boolean hasMaster = true;
    while (hasMaster) {
        for (Runnable r : members) {
            GroupRunnable groupRunnable = (GroupRunnable) r;
            hasMaster &= groupRunnable.group.isMaster();
        }
        if (hasMaster) {
            LOG.info("Waiting for no master state on proxy pause");
            TimeUnit.SECONDS.sleep(1);
        }
    }
    try {
        boolean gotDisconnect = gotDisconnectEvent.await(15, TimeUnit.SECONDS);
        assertTrue("got disconnect event", gotDisconnect);
        LOG.info("do close");
        for (Runnable r : members) {
            GroupRunnable groupRunnable = (GroupRunnable) r;
            groupRunnable.jobQueue.offer(0);
        }
        executorService.shutdown();
        // at a min when the session has expired
        boolean allThreadComplete = executorService.awaitTermination(6, TimeUnit.SECONDS);
        assertTrue("all threads complete", allThreadComplete);
    } finally {
        proxyCurator.close();
        socketProxy.close();
    }
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Group(io.fabric8.groups.Group) ZooKeeperGroup(io.fabric8.groups.internal.ZooKeeperGroup) NodeState(io.fabric8.groups.NodeState) GroupListener(io.fabric8.groups.GroupListener) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SocketProxy(org.apache.activemq.util.SocketProxy) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CuratorFramework(org.apache.curator.framework.CuratorFramework) ExecutorService(java.util.concurrent.ExecutorService) ZooKeeperGroup(io.fabric8.groups.internal.ZooKeeperGroup) Test(org.junit.Test)

Example 67 with Group

use of io.fabric8.groups.Group in project fabric8 by jboss-fuse.

the class ServiceFactoryTest method testThreadsOnTimeout.

@Test
public void testThreadsOnTimeout() throws Exception {
    curator.close();
    SocketProxy socketProxy = new SocketProxy(new URI("tcp://localhost:" + zkPort));
    final CuratorFramework proxyCurator = CuratorFrameworkFactory.builder().connectString("localhost:" + socketProxy.getUrl().getPort()).sessionTimeoutMs(5000).connectionTimeoutMs(3000).retryPolicy(new RetryNTimes(10, 1000)).build();
    proxyCurator.start();
    proxyCurator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    LOG.info("curator is go: " + proxyCurator);
    final String path = "/singletons/test/threads" + System.currentTimeMillis() + "**";
    final ArrayList<Runnable> members = new ArrayList<Runnable>();
    final int nThreads = 1;
    class GroupRunnable implements Runnable, GroupListener<NodeState> {

        final int id;

        private final BlockingQueue<Integer> jobQueue = new LinkedBlockingDeque<Integer>();

        ZooKeeperGroup<NodeState> group;

        NodeState nodeState;

        public GroupRunnable(int id) {
            this.id = id;
            members.add(this);
            nodeState = new NodeState("foo" + id);
        }

        @Override
        public void run() {
            group = new ZooKeeperGroup<NodeState>(proxyCurator, path, NodeState.class);
            group.add(this);
            LOG.info("run: Added: " + this);
            try {
                while (true) {
                    switch(jobQueue.take()) {
                        case 0:
                            LOG.info("run: close: " + this);
                            try {
                                group.close();
                            } catch (IOException ignored) {
                            }
                            return;
                        case 1:
                            LOG.info("run: start: " + this);
                            group.start();
                            group.update(nodeState);
                            break;
                        case 2:
                            LOG.info("run: update: " + this);
                            nodeState.setId(nodeState.getId() + id);
                            group.update(nodeState);
                            break;
                    }
                }
            } catch (InterruptedException exit) {
            }
        }

        @Override
        public void groupEvent(Group<NodeState> group, GroupEvent event) {
        }
    }
    ;
    ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
    for (int i = 0; i < nThreads; i++) {
        executorService.execute(new GroupRunnable(i));
    }
    for (Runnable r : members) {
        GroupRunnable groupRunnable = (GroupRunnable) r;
        groupRunnable.jobQueue.offer(1);
        // wait for registration
        while (groupRunnable.group == null || groupRunnable.group.getId() == null) {
            TimeUnit.MILLISECONDS.sleep(100);
        }
    }
    boolean firsStartedIsMaster = ((GroupRunnable) members.get(0)).group.isMaster();
    assertTrue("first started is master", firsStartedIsMaster);
    LOG.info("got master...");
    // lets see how long they take to notice a no responses to heart beats
    socketProxy.pause();
    // splash in an update
    for (Runnable r : members) {
        GroupRunnable groupRunnable = (GroupRunnable) r;
        groupRunnable.jobQueue.offer(2);
    }
    boolean hasMaster = true;
    while (hasMaster) {
        for (Runnable r : members) {
            GroupRunnable groupRunnable = (GroupRunnable) r;
            hasMaster &= groupRunnable.group.isMaster();
        }
        if (hasMaster) {
            LOG.info("Waiting for no master state on proxy pause");
            TimeUnit.SECONDS.sleep(1);
        }
    }
    for (Runnable r : members) {
        GroupRunnable groupRunnable = (GroupRunnable) r;
        groupRunnable.jobQueue.offer(0);
    }
    executorService.shutdown();
    // at a min when the session has expired
    boolean allThreadComplete = executorService.awaitTermination(6, TimeUnit.SECONDS);
    proxyCurator.close();
    socketProxy.close();
    assertTrue("all threads complete", allThreadComplete);
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Group(io.fabric8.groups.Group) ZooKeeperGroup(io.fabric8.groups.internal.ZooKeeperGroup) NodeState(io.fabric8.groups.NodeState) GroupListener(io.fabric8.groups.GroupListener) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SocketProxy(org.apache.activemq.util.SocketProxy) URI(java.net.URI) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CuratorFramework(org.apache.curator.framework.CuratorFramework) ExecutorService(java.util.concurrent.ExecutorService) ZooKeeperGroup(io.fabric8.groups.internal.ZooKeeperGroup) Test(org.junit.Test)

Example 68 with Group

use of io.fabric8.groups.Group in project jointware by isdream.

the class KubernetesKeyValueStyleGeneratorTest method testOpenShiftWithAllKind.

protected static void testOpenShiftWithAllKind() throws Exception {
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Policy());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Group());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new User());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new OAuthClient());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new ClusterRoleBinding());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new ImageStreamTag());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new ImageStream());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Build());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new BuildConfig());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new RoleBinding());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Route());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new PolicyBinding());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new OAuthAuthorizeToken());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Role());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Project());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new OAuthAccessToken());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new DeploymentConfig());
}
Also used : NetworkPolicy(io.fabric8.kubernetes.api.model.extensions.NetworkPolicy) Policy(io.fabric8.openshift.api.model.Policy) Group(io.fabric8.openshift.api.model.Group) User(io.fabric8.openshift.api.model.User) OAuthClient(io.fabric8.openshift.api.model.OAuthClient) ClusterRoleBinding(io.fabric8.openshift.api.model.ClusterRoleBinding) ImageStreamTag(io.fabric8.openshift.api.model.ImageStreamTag) ImageStream(io.fabric8.openshift.api.model.ImageStream) PolicyBinding(io.fabric8.openshift.api.model.PolicyBinding) OAuthAuthorizeToken(io.fabric8.openshift.api.model.OAuthAuthorizeToken) Role(io.fabric8.openshift.api.model.Role) Project(io.fabric8.openshift.api.model.Project) Build(io.fabric8.openshift.api.model.Build) OpenShiftDocumentKeyValueStyleGenerator(com.github.isdream.chameleon.docs.OpenShiftDocumentKeyValueStyleGenerator) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) OAuthAccessToken(io.fabric8.openshift.api.model.OAuthAccessToken) ClusterRoleBinding(io.fabric8.openshift.api.model.ClusterRoleBinding) RoleBinding(io.fabric8.openshift.api.model.RoleBinding) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Route(io.fabric8.openshift.api.model.Route)

Example 69 with Group

use of io.fabric8.groups.Group in project netvirt by opendaylight.

the class ElanInterfaceManager method removeElanBroadcastGroup.

public void removeElanBroadcastGroup(ElanInstance elanInfo, InterfaceInfo interfaceInfo, WriteTransaction deleteFlowGroupTx) {
    int bucketId = 0;
    int actionKey = 0;
    Long elanTag = elanInfo.getElanTag();
    List<Bucket> listBuckets = new ArrayList<>();
    List<Action> listAction = new ArrayList<>();
    listAction.add(new ActionGroup(++actionKey, ElanUtils.getElanLocalBCGId(elanTag)).buildAction());
    listBuckets.add(MDSALUtil.buildBucket(listAction, MDSALUtil.GROUP_WEIGHT, bucketId, MDSALUtil.WATCH_PORT, MDSALUtil.WATCH_GROUP));
    bucketId++;
    listBuckets.addAll(getRemoteBCGroupBucketInfos(elanInfo, bucketId, interfaceInfo, elanTag));
    BigInteger dpnId = interfaceInfo.getDpId();
    long groupId = ElanUtils.getElanRemoteBCGId(elanInfo.getElanTag());
    Group group = MDSALUtil.buildGroup(groupId, elanInfo.getElanInstanceName(), GroupTypes.GroupAll, MDSALUtil.buildBucketLists(listBuckets));
    LOG.trace("deleting the remoteBroadCast group:{}", group);
    mdsalManager.removeGroupToTx(dpnId, group, deleteFlowGroupTx);
}
Also used : ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) Group(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger)

Example 70 with Group

use of io.fabric8.groups.Group in project netvirt by opendaylight.

the class ElanInterfaceManager method removeLocalBroadcastGroup.

public void removeLocalBroadcastGroup(ElanInstance elanInfo, InterfaceInfo interfaceInfo, WriteTransaction deleteFlowGroupTx) {
    BigInteger dpnId = interfaceInfo.getDpId();
    long groupId = ElanUtils.getElanLocalBCGId(elanInfo.getElanTag());
    List<Bucket> listBuckets = new ArrayList<>();
    int bucketId = 0;
    listBuckets.add(getLocalBCGroupBucketInfo(interfaceInfo, bucketId));
    // listBuckets.addAll(getRemoteBCGroupBucketInfos(elanInfo, 1,
    // interfaceInfo));
    Group group = MDSALUtil.buildGroup(groupId, elanInfo.getElanInstanceName(), GroupTypes.GroupAll, MDSALUtil.buildBucketLists(listBuckets));
    LOG.trace("deleted the localBroadCast Group:{}", group);
    mdsalManager.removeGroupToTx(dpnId, group, deleteFlowGroupTx);
}
Also used : ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) Group(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group) Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger)

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