Search in sources :

Example 1 with ZooKeeperGroup

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

the class OpenShiftDeployAgent method activate.

@Activate
void activate(Map<String, ?> configuration) {
    // this.realm =  properties != null && properties.containsKey(REALM_PROPERTY_NAME) ? properties.get(REALM_PROPERTY_NAME) : DEFAULT_REALM;
    // this.role =  properties != null && properties.containsKey(ROLE_PROPERTY_NAME) ? properties.get(ROLE_PROPERTY_NAME) : DEFAULT_ROLE;
    group = new ZooKeeperGroup(curator.get(), ZkPath.OPENSHIFT.getPath(), ControllerNode.class);
    group.add(this);
    group.update(createState());
    group.start();
    activateComponent();
}
Also used : ZooKeeperGroup(io.fabric8.groups.internal.ZooKeeperGroup) Activate(org.apache.felix.scr.annotations.Activate)

Example 2 with ZooKeeperGroup

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

the class ZooKeeperGroupTest method putChildData.

private static void putChildData(ZooKeeperGroup<NodeState> group, String path, String container) throws Exception {
    NodeState node = new NodeState("test", container);
    ByteArrayOutputStream data = new ByteArrayOutputStream();
    new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).writeValue(data, node);
    ChildData<NodeState> child = new ChildData<>(path, new Stat(), data.toByteArray(), node);
    group.currentData.put(path, child);
}
Also used : NodeState(io.fabric8.groups.NodeState) Stat(org.apache.zookeeper.data.Stat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with ZooKeeperGroup

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

the class ZooKeeperGroupTest method setUp.

@Before
public void setUp() throws Exception {
    int port = findFreePort();
    curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryOneTime(1)).build();
    // curator.start();
    group = new ZooKeeperGroup<>(curator, PATH, NodeState.class);
// group.start();
// Starting curator and group is not necessary for the current tests.
}
Also used : RetryOneTime(org.apache.curator.retry.RetryOneTime) NodeState(io.fabric8.groups.NodeState) Before(org.junit.Before)

Example 4 with ZooKeeperGroup

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

the class GitHttpServerRegistrationHandler method activate.

@Activate
void activate(Map<String, ?> configuration) throws Exception {
    RuntimeProperties sysprops = runtimeProperties.get();
    realm = getConfiguredRealm(sysprops, configuration);
    roles = getConfiguredRoles(sysprops, configuration);
    dataPath = sysprops.getDataPath();
    activateComponent();
    group = new ZooKeeperGroup<GitNode>(curator.get(), ZkPath.GIT.getPath(), GitNode.class, new NamedThreadFactory("zkgroup-git-httpreg"));
    // if anything went wrong in a previous deactivation we still have to clean up the registry
    zkCleanUp(group);
    group.add(this);
    group.update(createState());
    group.start();
}
Also used : NamedThreadFactory(io.fabric8.utils.NamedThreadFactory) GitNode(io.fabric8.git.GitNode) RuntimeProperties(io.fabric8.api.RuntimeProperties) Activate(org.apache.felix.scr.annotations.Activate)

Example 5 with ZooKeeperGroup

use of io.fabric8.groups.internal.ZooKeeperGroup 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)

Aggregations

ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)9 CuratorFramework (org.apache.curator.framework.CuratorFramework)8 RetryNTimes (org.apache.curator.retry.RetryNTimes)8 Test (org.junit.Test)8 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)6 NodeState (io.fabric8.groups.NodeState)4 ArrayList (java.util.ArrayList)3 Group (io.fabric8.groups.Group)2 GroupListener (io.fabric8.groups.GroupListener)2 IOException (java.io.IOException)2 URI (java.net.URI)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 ExecutorService (java.util.concurrent.ExecutorService)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 SocketProxy (org.apache.activemq.util.SocketProxy)2 Activate (org.apache.felix.scr.annotations.Activate)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RuntimeProperties (io.fabric8.api.RuntimeProperties)1 GitNode (io.fabric8.git.GitNode)1