Search in sources :

Example 71 with CuratorFramework

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

the class EncryptedPropertyResolverTest method testResolveZkEnc.

@Test
public void testResolveZkEnc() throws Exception {
    CuratorFramework curator = createMock(CuratorFramework.class);
    GetDataBuilder getDataBuilder = createMock(GetDataBuilder.class);
    expect(curator.getData()).andReturn(getDataBuilder).anyTimes();
    expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_ALGORITHM.getPath())).andReturn("PBEWithMD5AndDES".getBytes()).anyTimes();
    expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_PASSWORD.getPath())).andReturn("ZKENC=bXlwYXNzd29yZA==".getBytes()).anyTimes();
    replay(curator);
    replay(getDataBuilder);
    FabricService fabricService = createMock(FabricService.class);
    expect(fabricService.adapt(CuratorFramework.class)).andReturn(curator).anyTimes();
    replay(fabricService);
    PlaceholderResolver resolver = getEncryptedPropertyResolver();
    assertEquals("encryptedpassword", resolver.resolve(fabricService, null, null, null, "crypt:URdoo9++D3tsoC9ODrTfLNK5WzviknO3Ig6qbI2HuvQ="));
    verify(curator);
    verify(getDataBuilder);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) FabricService(io.fabric8.api.FabricService) GetDataBuilder(org.apache.curator.framework.api.GetDataBuilder) PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Test(org.junit.Test)

Example 72 with CuratorFramework

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

the class ZooKeeperClusterServiceImpl method obtainValid.

private CuratorFramework obtainValid(ValidatingReference<CuratorFramework> curator) throws InterruptedException {
    int counter = 1;
    while (true) {
        if (counter > 18) {
            throw new IllegalStateException("Unable to obtain a valid reference of Curator after " + counter + " tries");
        }
        LOGGER.debug("Getting CuratorFramework reference. Attempt {}", counter);
        CuratorFramework result = curator.getOptional();
        if (result == null) {
            LOGGER.warn("Curator instance not ready");
            counter++;
            Thread.sleep(5 * 1000);
        } else {
            return curator.get();
        }
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework)

Example 73 with CuratorFramework

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

the class FabricLoadBalancerFeature method getCurator.

public synchronized CuratorFramework getCurator() throws Exception {
    if (curator == null) {
        String connectString = getZooKeeperUrl();
        if (connectString == null) {
            connectString = System.getProperty(ZOOKEEPER_URL, "localhost:2181");
        }
        String password = getZooKeeperPassword();
        if (password == null) {
            System.getProperty(ZOOKEEPER_PASSWORD);
        }
        LOG.debug("Zookeeper client not find in camel registry, creating new with connection " + connectString);
        CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString(connectString).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(maximumConnectionTimeout);
        if (password != null && !password.isEmpty()) {
            builder.authorization("digest", ("fabric:" + password).getBytes());
        }
        CuratorFramework client = builder.build();
        LOG.debug("Starting curator " + curator);
        client.start();
        curator = client;
        setShouldCloseZkClient(true);
    }
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    return curator;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory)

Example 74 with CuratorFramework

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

the class FabricServiceImpl method getGitUrl.

@Override
public String getGitUrl() {
    assertValid();
    String gitServers = ZkPath.GIT.getPath();
    try {
        CuratorFramework curatorFramework = curator.get();
        if (curatorFramework != null) {
            List<String> servers = getChildrenSafe(curatorFramework, gitServers);
            for (String server : servers) {
                String serverPath = gitServers + "/" + server;
                String answer = getFirstService(serverPath);
                if (!Strings.isNullOrEmpty(answer)) {
                    return answer;
                }
            }
        }
    } catch (Exception e) {
        // On exception just return uri.
        LOGGER.warn("Failed to find Git URL " + gitServers + ". " + e, e);
    }
    return null;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ProfileDependencyException(io.fabric8.api.ProfileDependencyException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) FabricException(io.fabric8.api.FabricException) IOException(java.io.IOException)

Example 75 with CuratorFramework

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

the class ZooKeeperFacade method getCurator.

/**
 * Returns the ZooKeeper client or throwns an exception if its not configured properly
 */
protected CuratorFramework getCurator() {
    CuratorFramework curator = fabricService.adapt(CuratorFramework.class);
    notNull(curator, "curator");
    return curator;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework)

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