Search in sources :

Example 91 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project knox by apache.

the class HBaseZookeeperURLManagerTest method setup.

@Before
public void setup() throws Exception {
    cluster = new TestingCluster(3);
    cluster.start();
    CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(cluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
    zooKeeperClient.start();
    zooKeeperClient.create().forPath("/hbase-unsecure");
    zooKeeperClient.create().forPath("/hbase-unsecure/rs");
    zooKeeperClient.close();
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TestingCluster(org.apache.curator.test.TestingCluster) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) Before(org.junit.Before)

Example 92 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project knox by apache.

the class HS2ZookeeperURLManagerTest method setup.

@Before
public void setup() throws Exception {
    cluster = new TestingCluster(3);
    cluster.start();
    CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(cluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
    String host1 = "hive.server2.authentication=NONE;hive.server2.transport.mode=http;hive.server2.thrift.http.path=cliservice;" + "hive.server2.thrift.http.port=10001;hive.server2.thrift.bind.host=host1;hive.server2.use.SSL=true";
    String host2 = "hive.server2.authentication=NONE;hive.server2.transport.mode=http;hive.server2.thrift.http.path=foobar;" + "hive.server2.thrift.http.port=10002;hive.server2.thrift.bind.host=host2;hive.server2.use.SSL=false";
    String host3 = "hive.server2.authentication=NONE;hive.server2.transport.mode=http;hive.server2.thrift.http.path=cliservice;" + "hive.server2.thrift.http.port=10003;hive.server2.thrift.bind.host=host3;hive.server2.use.SSL=false";
    String host4 = "hive.server2.authentication=NONE;hive.server2.transport.mode=http;hive.server2.thrift.http.path=cliservice;" + "hive.server2.thrift.http.port=10004;hive.server2.thrift.bind.host=host4;hive.server2.use.SSL=true";
    zooKeeperClient.start();
    zooKeeperClient.create().forPath("/hiveServer2");
    zooKeeperClient.create().forPath("/hiveServer2/host1", host1.getBytes());
    zooKeeperClient.create().forPath("/hiveServer2/host2", host2.getBytes());
    zooKeeperClient.create().forPath("/hiveServer2/host3", host3.getBytes());
    zooKeeperClient.create().forPath("/hiveServer2/host4", host4.getBytes());
    zooKeeperClient.close();
    manager = new HS2ZookeeperURLManager();
    HaServiceConfig config = new DefaultHaServiceConfig("HIVE");
    config.setEnabled(true);
    config.setZookeeperEnsemble(cluster.getConnectString());
    config.setZookeeperNamespace("hiveServer2");
    manager.setConfig(config);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TestingCluster(org.apache.curator.test.TestingCluster) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig) Before(org.junit.Before)

Example 93 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project knox by apache.

the class SOLRZookeeperURLManagerTest method setup.

@Before
public void setup() throws Exception {
    cluster = new TestingCluster(3);
    cluster.start();
    CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(cluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
    zooKeeperClient.start();
    zooKeeperClient.create().forPath("/live_nodes");
    zooKeeperClient.create().forPath("/live_nodes/host1:8983_solr");
    zooKeeperClient.create().forPath("/live_nodes/host2:8983_solr");
    zooKeeperClient.create().forPath("/live_nodes/host3:8983_solr");
    zooKeeperClient.close();
    manager = new SOLRZookeeperURLManager();
    HaServiceConfig config = new DefaultHaServiceConfig("SOLR");
    config.setEnabled(true);
    config.setZookeeperEnsemble(cluster.getConnectString());
    manager.setConfig(config);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TestingCluster(org.apache.curator.test.TestingCluster) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig) Before(org.junit.Before)

Example 94 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project knox by apache.

the class RemoteConfigurationRegistryClientServiceTest method testMultipleUnsecuredZooKeeperWithSimpleRegistryConfig.

/**
 * Test multiple configurations for an unsecured remote registry.
 */
@Test
public void testMultipleUnsecuredZooKeeperWithSimpleRegistryConfig() throws Exception {
    final String REGISTRY_CLIENT_NAME_1 = "zkclient1";
    final String REGISTRY_CLIENT_NAME_2 = "zkclient2";
    final String PRINCIPAL = null;
    final String PWD = null;
    final String CRED_ALIAS = null;
    // Configure and start a secure ZK cluster
    TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD);
    try {
        // Create the setup client for the test cluster, and initialize the test znodes
        CuratorFramework setupClient = initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
        // Mock configuration
        GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
        final String registryConfigValue1 = GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString();
        EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME_1)).andReturn(registryConfigValue1).anyTimes();
        final String registryConfigValue2 = GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString();
        EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME_2)).andReturn(registryConfigValue2).anyTimes();
        EasyMock.expect(config.getRemoteRegistryConfigurationNames()).andReturn(Arrays.asList(REGISTRY_CLIENT_NAME_1, REGISTRY_CLIENT_NAME_2)).anyTimes();
        EasyMock.replay(config);
        // Create the client service instance
        RemoteConfigurationRegistryClientService clientService = RemoteConfigurationRegistryClientServiceFactory.newInstance(config);
        assertEquals("Wrong registry client service type.", clientService.getClass(), CuratorClientService.class);
        clientService.setAliasService(null);
        clientService.init(config, null);
        clientService.start();
        RemoteConfigurationRegistryClient client1 = clientService.get(REGISTRY_CLIENT_NAME_1);
        assertNotNull(client1);
        RemoteConfigurationRegistryClient client2 = clientService.get(REGISTRY_CLIENT_NAME_2);
        assertNotNull(client2);
        doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME_1, clientService, false);
        doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME_2, clientService, false);
    } finally {
        zkCluster.stop();
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TestingCluster(org.apache.curator.test.TestingCluster) RemoteConfigurationRegistryClient(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient) RemoteConfigurationRegistryClientService(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 95 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project knox by apache.

the class RemoteConfigurationRegistryClientServiceTest method initializeTestClientAndZNodes.

/**
 * Create a ZooKeeper client with SASL digest auth configured, and initialize the test znodes.
 */
private CuratorFramework initializeTestClientAndZNodes(TestingCluster zkCluster, String principal) throws Exception {
    // Create the client for the test cluster
    CuratorFramework setupClient = CuratorFrameworkFactory.builder().connectString(zkCluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(100, 3)).build();
    assertNotNull(setupClient);
    setupClient.start();
    List<ACL> acls = new ArrayList<>();
    if (principal != null) {
        acls.add(new ACL(ZooDefs.Perms.ALL, new Id("sasl", principal)));
    } else {
        acls.add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.ANYONE_ID_UNSAFE));
    }
    setupClient.create().creatingParentsIfNeeded().withACL(acls).forPath("/knox/config/descriptors");
    setupClient.create().creatingParentsIfNeeded().withACL(acls).forPath("/knox/config/shared-providers");
    List<ACL> negativeACLs = new ArrayList<>();
    if (principal != null) {
        negativeACLs.add(new ACL(ZooDefs.Perms.ALL, new Id("sasl", "notyou")));
    } else {
        negativeACLs.add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.ANYONE_ID_UNSAFE));
    }
    setupClient.create().creatingParentsIfNeeded().withACL(negativeACLs).forPath("/someotherconfig");
    return setupClient;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ArrayList(java.util.ArrayList) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id)

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