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);
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations