Search in sources :

Example 1 with HaServiceConfig

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

the class HaDescriptorManager method store.

public static void store(HaDescriptor descriptor, Writer writer) throws IOException {
    try {
        Document document = XmlUtils.createDocument();
        Element root = document.createElement(ROOT_ELEMENT);
        document.appendChild(root);
        List<HaServiceConfig> serviceConfigs = descriptor.getServiceConfigs();
        if (serviceConfigs != null && !serviceConfigs.isEmpty()) {
            for (HaServiceConfig config : serviceConfigs) {
                Element serviceElement = document.createElement(SERVICE_ELEMENT);
                serviceElement.setAttribute(SERVICE_NAME_ATTRIBUTE, config.getServiceName());
                serviceElement.setAttribute(MAX_FAILOVER_ATTEMPTS, Integer.toString(config.getMaxFailoverAttempts()));
                serviceElement.setAttribute(FAILOVER_SLEEP, Integer.toString(config.getFailoverSleep()));
                serviceElement.setAttribute(MAX_RETRY_ATTEMPTS, Integer.toString(config.getMaxRetryAttempts()));
                serviceElement.setAttribute(RETRY_SLEEP, Integer.toString(config.getRetrySleep()));
                serviceElement.setAttribute(ENABLED_ATTRIBUTE, Boolean.toString(config.isEnabled()));
                if (config.getZookeeperEnsemble() != null) {
                    serviceElement.setAttribute(ZOOKEEPER_ENSEMBLE, config.getZookeeperEnsemble());
                }
                if (config.getZookeeperNamespace() != null) {
                    serviceElement.setAttribute(ZOOKEEPER_NAMESPACE, config.getZookeeperNamespace());
                }
                root.appendChild(serviceElement);
            }
        }
        Transformer t = XmlUtils.getTransformer(true, true, 2, false);
        XmlUtils.writeXml(document, writer, t);
    } catch (ParserConfigurationException e) {
        LOG.failedToWriteHaDescriptor(e);
        throw new IOException(e);
    } catch (TransformerException e) {
        LOG.failedToWriteHaDescriptor(e);
        throw new IOException(e);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig) TransformerException(javax.xml.transform.TransformerException)

Example 2 with HaServiceConfig

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

the class HaDescriptorManager method load.

public static HaDescriptor load(InputStream inputStream) throws IOException {
    HaDescriptor descriptor = HaDescriptorFactory.createDescriptor();
    try {
        Document document = XmlUtils.readXml(inputStream);
        NodeList nodeList = document.getElementsByTagName(SERVICE_ELEMENT);
        if (nodeList != null && nodeList.getLength() > 0) {
            for (int i = 0; i < nodeList.getLength(); i++) {
                Element element = (Element) nodeList.item(i);
                HaServiceConfig config = HaDescriptorFactory.createServiceConfig(element.getAttribute(SERVICE_NAME_ATTRIBUTE), element.getAttribute(ENABLED_ATTRIBUTE), element.getAttribute(MAX_FAILOVER_ATTEMPTS), element.getAttribute(FAILOVER_SLEEP), element.getAttribute(MAX_RETRY_ATTEMPTS), element.getAttribute(RETRY_SLEEP), element.getAttribute(ZOOKEEPER_ENSEMBLE), element.getAttribute(ZOOKEEPER_NAMESPACE));
                descriptor.addServiceConfig(config);
            }
        }
    } catch (ParserConfigurationException e) {
        LOG.failedToLoadHaDescriptor(e);
        throw new IOException(e);
    } catch (SAXException e) {
        LOG.failedToLoadHaDescriptor(e);
        throw new IOException(e);
    }
    return descriptor;
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) HaDescriptor(org.apache.knox.gateway.ha.provider.HaDescriptor) Document(org.w3c.dom.Document) HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig) SAXException(org.xml.sax.SAXException)

Example 3 with HaServiceConfig

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

the class AtlasZookeeperURLManagerTest method doTestAtlasZooKeeperURLManager.

private void doTestAtlasZooKeeperURLManager(final String serviceName, final boolean enabled, final String ensemble, final String namespace) {
    HaServiceConfig config = new DefaultHaServiceConfig(serviceName);
    config.setEnabled(enabled);
    config.setZookeeperEnsemble(ensemble);
    config.setZookeeperNamespace(namespace);
    URLManager manager = URLManagerLoader.loadURLManager(config);
    Assert.assertNotNull(manager);
    Assert.assertTrue(manager instanceof AtlasZookeeperURLManager);
}
Also used : URLManager(org.apache.knox.gateway.ha.provider.URLManager) HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig)

Example 4 with HaServiceConfig

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

the class HBaseZookeeperURLManagerTest method testHBaseZookeeperURLManagerLoading.

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

Example 5 with HaServiceConfig

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

the class HS2ZookeeperURLManagerTest method testHS2URLManagerLoading.

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

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