Search in sources :

Example 76 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project fabric8 by jboss-fuse.

the class Kill method createNewAction.

@Override
public Action createNewAction() {
    assertValid();
    // this is how we get hold of the curator framework
    CuratorFramework curator = CuratorFrameworkLocator.getCuratorFramework();
    return new KillAction(curator);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework)

Example 77 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project fabric8 by jboss-fuse.

the class List method createNewAction.

@Override
public Action createNewAction() {
    assertValid();
    // this is how we get hold of the curator framework
    CuratorFramework curator = CuratorFrameworkLocator.getCuratorFramework();
    return new ListAction(curator);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework)

Example 78 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project fabric8 by jboss-fuse.

the class Delete method createNewAction.

@Override
public Action createNewAction() {
    assertValid();
    // this is how we get hold of the curator framework
    CuratorFramework curator = CuratorFrameworkLocator.getCuratorFramework();
    return new DeleteAction(curator);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework)

Example 79 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project fabric8 by jboss-fuse.

the class ManagedCuratorFramework method bindConnectionStateListener.

void bindConnectionStateListener(ConnectionStateListener connectionStateListener) {
    connectionStateListeners.add(connectionStateListener);
    State curr = state.get();
    CuratorFramework curator = curr != null ? curr.curator : null;
    if (curator != null && curator.getZookeeperClient().isConnected()) {
        connectionStateListener.stateChanged(curator, ConnectionState.CONNECTED);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ConnectionState(org.apache.curator.framework.state.ConnectionState)

Example 80 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project fabric8 by jboss-fuse.

the class ManagerTest method testManager.

@Test
public void testManager() throws Exception {
    ZKServerFactoryBean zkServerFactoryBean = null;
    try {
        int zooKeeperPort = getFreePort();
        int serverPort = getFreePort();
        zkServerFactoryBean = new ZKServerFactoryBean();
        zkServerFactoryBean.setPurge(true);
        zkServerFactoryBean.setClientPortAddress(new InetSocketAddress("localhost", zooKeeperPort));
        zkServerFactoryBean.afterPropertiesSet();
        CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zooKeeperPort).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(60000);
        CuratorFramework curator = builder.build();
        curator.start();
        curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
        BundleContext bundleContext = createMock(BundleContext.class);
        ServiceRegistration registration = createMock(ServiceRegistration.class);
        Manager manager = new Manager(bundleContext, curator, "tcp://localhost:" + serverPort, "localhost", TimeUnit.MINUTES.toMillis(5));
        bundleContext.addServiceListener(manager, "(service.exported.interfaces=*)");
        expect(bundleContext.getProperty("org.osgi.framework.uuid")).andReturn("the-framework-uuid");
        expect(bundleContext.registerService(EasyMock.<String[]>anyObject(), same(manager), EasyMock.<Dictionary>same(null))).andReturn(registration);
        expect(bundleContext.getServiceReferences((String) null, "(service.exported.interfaces=*)")).andReturn(null);
        replay(bundleContext, registration);
        manager.init();
        verify(bundleContext, registration);
        reset(bundleContext, registration);
        BundleContext expBundleContext = createMock(BundleContext.class);
        Bundle expBundle = createMock(Bundle.class);
        ServiceReference reference = createMock(ServiceReference.class);
        final Properties props = new Properties();
        props.put(Constants.OBJECTCLASS, new String[] { ConfigurationAdmin.class.getName() });
        expect(reference.getProperty(EasyMock.<String>anyObject())).andAnswer(new IAnswer<Object>() {

            public Object answer() throws Throwable {
                return props.get(EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();
        expect(reference.getPropertyKeys()).andReturn(props.keySet().toArray(new String[0]));
        expect(reference.getBundle()).andReturn(expBundle).anyTimes();
        expect(expBundle.getBundleContext()).andReturn(expBundleContext).anyTimes();
        expect(expBundle.getState()).andReturn(Bundle.ACTIVE).anyTimes();
        replay(bundleContext, registration, reference, expBundleContext, expBundle);
        manager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, reference));
        Thread.sleep(1000);
        verify(bundleContext, registration, reference, expBundleContext, expBundle);
    } finally {
        try {
            zkServerFactoryBean.destroy();
        } catch (Throwable t) {
        }
    }
}
Also used : RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) InetSocketAddress(java.net.InetSocketAddress) Bundle(org.osgi.framework.Bundle) ZKServerFactoryBean(io.fabric8.zookeeper.spring.ZKServerFactoryBean) Manager(io.fabric8.dosgi.impl.Manager) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) IAnswer(org.easymock.IAnswer) CuratorFramework(org.apache.curator.framework.CuratorFramework) ServiceEvent(org.osgi.framework.ServiceEvent) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Aggregations

CuratorFramework (org.apache.curator.framework.CuratorFramework)924 Test (org.testng.annotations.Test)290 RetryOneTime (org.apache.curator.retry.RetryOneTime)271 Test (org.junit.Test)199 Timing (org.apache.curator.test.Timing)147 CountDownLatch (java.util.concurrent.CountDownLatch)124 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)114 KeeperException (org.apache.zookeeper.KeeperException)93 IOException (java.io.IOException)79 ConnectionState (org.apache.curator.framework.state.ConnectionState)71 CuratorEvent (org.apache.curator.framework.api.CuratorEvent)58 ExecutorService (java.util.concurrent.ExecutorService)55 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)53 ArrayList (java.util.ArrayList)51 RetryNTimes (org.apache.curator.retry.RetryNTimes)51 RetryPolicy (org.apache.curator.RetryPolicy)41 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)38 Cleanup (lombok.Cleanup)37 BackgroundCallback (org.apache.curator.framework.api.BackgroundCallback)37 Stat (org.apache.zookeeper.data.Stat)36