Search in sources :

Example 6 with HaServiceConfig

use of org.apache.knox.gateway.ha.provider.HaServiceConfig 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 7 with HaServiceConfig

use of org.apache.knox.gateway.ha.provider.HaServiceConfig in project knox by apache.

the class HaDescriptorFactoryTest method testCreateServiceConfig.

@Test
public void testCreateServiceConfig() {
    HaServiceConfig serviceConfig = HaDescriptorFactory.createServiceConfig("foo", "enabled=true;maxFailoverAttempts=42;failoverSleep=50;maxRetryAttempts=1;retrySleep=1000");
    assertNotNull(serviceConfig);
    assertTrue(serviceConfig.isEnabled());
    assertEquals("foo", serviceConfig.getServiceName());
    assertEquals(42, serviceConfig.getMaxFailoverAttempts());
    assertEquals(50, serviceConfig.getFailoverSleep());
    assertEquals(1, serviceConfig.getMaxRetryAttempts());
    assertEquals(1000, serviceConfig.getRetrySleep());
    serviceConfig = HaDescriptorFactory.createServiceConfig("bar", "false", "3", "1000", "5", "3000", null, null);
    assertNotNull(serviceConfig);
    assertFalse(serviceConfig.isEnabled());
    assertEquals("bar", serviceConfig.getServiceName());
    assertEquals(3, serviceConfig.getMaxFailoverAttempts());
    assertEquals(1000, serviceConfig.getFailoverSleep());
    assertEquals(5, serviceConfig.getMaxRetryAttempts());
    assertEquals(3000, serviceConfig.getRetrySleep());
}
Also used : HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig) Test(org.junit.Test)

Example 8 with HaServiceConfig

use of org.apache.knox.gateway.ha.provider.HaServiceConfig in project knox by apache.

the class HaDescriptorManagerTest method testDescriptorLoad.

@Test
public void testDescriptorLoad() throws IOException {
    String xml = "<ha><service name='foo' maxFailoverAttempts='42' failoverSleep='4000' maxRetryAttempts='2' retrySleep='2213' enabled='false'/>" + "<service name='bar' failoverLimit='3' enabled='true'/></ha>";
    ByteArrayInputStream inputStream = new ByteArrayInputStream(xml.getBytes());
    HaDescriptor descriptor = HaDescriptorManager.load(inputStream);
    assertNotNull(descriptor);
    assertEquals(1, descriptor.getEnabledServiceNames().size());
    HaServiceConfig config = descriptor.getServiceConfig("foo");
    assertNotNull(config);
    assertEquals("foo", config.getServiceName());
    assertEquals(42, config.getMaxFailoverAttempts());
    assertEquals(4000, config.getFailoverSleep());
    assertEquals(2, config.getMaxRetryAttempts());
    assertEquals(2213, config.getRetrySleep());
    assertFalse(config.isEnabled());
    config = descriptor.getServiceConfig("bar");
    assertTrue(config.isEnabled());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HaDescriptor(org.apache.knox.gateway.ha.provider.HaDescriptor) HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig) Test(org.junit.Test)

Example 9 with HaServiceConfig

use of org.apache.knox.gateway.ha.provider.HaServiceConfig in project knox by apache.

the class SOLRZookeeperURLManagerTest method testSOLRZookeeperURLManagerLoading.

@Test
public void testSOLRZookeeperURLManagerLoading() {
    HaServiceConfig config = new DefaultHaServiceConfig("SOLR");
    config.setEnabled(true);
    config.setZookeeperEnsemble(cluster.getConnectString());
    URLManager manager = URLManagerLoader.loadURLManager(config);
    Assert.assertNotNull(manager);
    Assert.assertTrue(manager instanceof SOLRZookeeperURLManager);
}
Also used : URLManager(org.apache.knox.gateway.ha.provider.URLManager) HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig) Test(org.junit.Test)

Example 10 with HaServiceConfig

use of org.apache.knox.gateway.ha.provider.HaServiceConfig 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)

Aggregations

HaServiceConfig (org.apache.knox.gateway.ha.provider.HaServiceConfig)20 Test (org.junit.Test)7 URLManager (org.apache.knox.gateway.ha.provider.URLManager)6 HaDescriptor (org.apache.knox.gateway.ha.provider.HaDescriptor)4 IOException (java.io.IOException)3 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)3 TestingCluster (org.apache.curator.test.TestingCluster)3 Before (org.junit.Before)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Transformer (javax.xml.transform.Transformer)1 TransformerException (javax.xml.transform.TransformerException)1 Service (org.apache.knox.gateway.topology.Service)1 Topology (org.apache.knox.gateway.topology.Topology)1 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)1