Search in sources :

Example 61 with CuratorFramework

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

the class ClusterList method createNewAction.

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

Example 62 with CuratorFramework

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

the class JoinAction method registerContainer.

/**
 * Checks if there is an existing container using the same name.
 *
 * @param name
 * @return
 * @throws InterruptedException
 * @throws KeeperException
 */
private boolean registerContainer(String name, String registryPassword, String profile, boolean force) throws Exception {
    boolean exists = false;
    CuratorFramework curator = null;
    try {
        CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString(zookeeperUrl).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(60000);
        if (registryPassword != null && !registryPassword.isEmpty()) {
            builder.authorization("digest", ("fabric:" + registryPassword).getBytes());
        }
        curator = builder.build();
        curator.start();
        curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
        exists = exists(curator, ZkPath.CONTAINER.getPath(name)) != null;
        if (version == null) {
            // ENTESB-7554: let's find default version
            version = getStringData(curator, ZkPath.CONFIG_DEFAULT_VERSION.getPath());
            System.out.println("No version specified, using default version: " + version);
        } else {
        // ENTESB-7554: verify the version exists - not that easy, because after deleting a version
        // we still have it in ZK... to do?
        }
        if (!exists || force) {
            ZkPath.createContainerPaths(curator, containerName, version, profile);
        }
    } finally {
        if (curator != null) {
            curator.close();
        }
    }
    return !exists || force;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory)

Example 63 with CuratorFramework

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

the class ZKComponentSupport method doStart.

@Override
protected void doStart() throws Exception {
    super.doStart();
    if (curator == null) {
        try {
            CuratorFramework _curator = (CuratorFramework) getCamelContext().getRegistry().lookupByName("curator");
            setCurator(_curator);
            if (curator != null) {
                LOG.debug("Zookeeper client found in camel registry. " + curator);
            }
        } catch (Exception exception) {
            LOG.warn(exception);
        }
    }
    managedGroupFactory = ManagedGroupFactoryBuilder.create(curator, getClass().getClassLoader(), this);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework)

Example 64 with CuratorFramework

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

the class EncryptionAlgorithmGet method createNewAction.

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

Example 65 with CuratorFramework

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

the class EnsemblePasswordAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    if (!commit) {
        if (newPassword == null) {
            System.out.println(fabricService.getZookeeperPassword());
        } else {
            String zookeeperUrl = fabricService.getZookeeperUrl();
            String oldPassword = fabricService.getZookeeperPassword();
            System.out.println("Updating the password...");
            // Since we will be changing the password, create a new ZKClient that won't
            // be getting update by the password change.
            CuratorACLManager aclManager = new CuratorACLManager();
            CuratorFramework curator = CuratorFrameworkFactory.builder().connectString(zookeeperUrl).retryPolicy(new RetryOneTime(500)).aclProvider(aclManager).authorization("digest", ("fabric:" + oldPassword).getBytes()).sessionTimeoutMs(30000).build();
            curator.start();
            try {
                // Lets first adjust the acls so that the new password and old passwords work against the ZK paths.
                String digestedIdPass = DigestAuthenticationProvider.generateDigest("fabric:" + newPassword);
                aclManager.registerAcl("/fabric", "auth::acdrw,world:anyone:,digest:" + digestedIdPass + ":acdrw");
                aclManager.fixAcl(curator, "/fabric", true);
                // Ok now lets push out a config update of what the password is.
                curator.setData().forPath(ZkPath.CONFIG_ENSEMBLE_PASSWORD.getPath(), PasswordEncoder.encode(newPassword).getBytes(Charsets.UTF_8));
            } finally {
                curator.close();
            }
            // Refresh the default profile to cause all nodes to pickup the new password.
            ProfileService profileService = fabricService.adapt(ProfileService.class);
            for (String ver : profileService.getVersions()) {
                Version version = profileService.getVersion(ver);
                if (version != null) {
                    Profile profile = version.getProfile("default");
                    if (profile != null) {
                        Profiles.refreshProfile(fabricService, profile);
                    }
                }
            }
            System.out.println("");
            System.out.println("Password updated. Please wait a little while for the new password to");
            System.out.println("get delivered as a config update to all the fabric nodes. Once, the ");
            System.out.println("nodes all updated (nodes must be online), please run:");
            System.out.println("");
            System.out.println("  fabric:ensemble-password --commit ");
            System.out.println("");
        }
    } else {
        // Now lets connect with the new password and reset the ACLs so that the old password
        // does not work anymore.
        CuratorACLManager aclManager = new CuratorACLManager();
        CuratorFramework curator = CuratorFrameworkFactory.builder().connectString(fabricService.getZookeeperUrl()).retryPolicy(new RetryOneTime(500)).aclProvider(aclManager).authorization("digest", ("fabric:" + fabricService.getZookeeperPassword()).getBytes()).sessionTimeoutMs(30000).build();
        curator.start();
        try {
            aclManager.fixAcl(curator, "/fabric", true);
            System.out.println("Only the current password is allowed access to fabric now.");
        } finally {
            curator.close();
        }
    }
    return null;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorACLManager(io.fabric8.zookeeper.curator.CuratorACLManager)

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