use of org.apache.knox.gateway.topology.Topology in project knox by apache.
the class TopologyRulesModuleTest method testParseServiceParamsInAmbariFormat.
@Test
public void testParseServiceParamsInAmbariFormat() throws IOException, SAXException {
Digester digester = loader.newDigester();
String name = "org/apache/knox/gateway/topology/xml/service-param-topology-ambari-format.conf";
URL url = ClassLoader.getSystemResource(name);
assertThat("Failed to find URL for resource " + name, url, notNullValue());
File file = new File(url.getFile());
TopologyBuilder topologyBuilder = digester.parse(url);
Topology topology = topologyBuilder.build();
assertThat("Failed to parse resource " + name, topology, notNullValue());
topology.setTimestamp(file.lastModified());
assertThat(topology.getName(), is("test-topology-name"));
assertThat(topology.getTimestamp(), is(file.lastModified()));
assertThat(topology.getProviders().size(), is(1));
Provider provider = topology.getProviders().iterator().next();
assertThat(provider, notNullValue());
assertThat(provider.getRole(), is("test-provider-role"));
assertThat(provider.getName(), is("test-provider-name"));
assertThat(provider.isEnabled(), is(true));
assertThat(provider.getParams(), hasEntry(is("test-provider-param-name-1"), is("test-provider-param-value-1")));
assertThat(provider.getParams(), hasEntry(is("test-provider-param-name-2"), is("test-provider-param-value-2")));
assertThat(topology.getServices().size(), is(1));
Service service = topology.getServices().iterator().next();
assertThat(service, notNullValue());
assertThat(service.getRole(), is("test-service-role"));
assertThat(service.getUrls().size(), is(2));
assertThat(service.getUrls(), hasItem("test-service-scheme://test-service-host1:42/test-service-path"));
assertThat(service.getUrls(), hasItem("test-service-scheme://test-service-host2:42/test-service-path"));
assertThat(service.getName(), is("test-service-name"));
assertThat(service.getParams(), hasEntry(is("test-service-param-name-1"), is("test-service-param-value-1")));
assertThat(service.getParams(), hasEntry(is("test-service-param-name-2"), is("test-service-param-value-2")));
}
use of org.apache.knox.gateway.topology.Topology in project knox by apache.
the class TopologyRulesModuleTest method testParseSimpleTopologyXmlInKnoxFormat.
@Test
public void testParseSimpleTopologyXmlInKnoxFormat() throws IOException, SAXException, URISyntaxException {
Digester digester = loader.newDigester();
String name = "org/apache/knox/gateway/topology/xml/simple-topology-knox-format.xml";
URL url = ClassLoader.getSystemResource(name);
assertThat("Failed to find URL for resource " + name, url, notNullValue());
File file = new File(url.getFile());
TopologyBuilder topologyBuilder = digester.parse(url);
Topology topology = topologyBuilder.build();
assertThat("Failed to parse resource " + name, topology, notNullValue());
topology.setTimestamp(file.lastModified());
assertThat(topology.getName(), is("topology"));
assertThat(topology.getTimestamp(), is(file.lastModified()));
assertThat(topology.getServices().size(), is(3));
Service comp = topology.getServices().iterator().next();
assertThat(comp, notNullValue());
assertThat(comp.getRole(), is("WEBHDFS"));
assertThat(comp.getVersion().toString(), is("2.4.0"));
assertThat(comp.getUrls().size(), is(2));
assertThat(comp.getUrls(), hasItem("http://host1:80/webhdfs"));
assertThat(comp.getUrls(), hasItem("http://host2:80/webhdfs"));
Provider provider = topology.getProviders().iterator().next();
assertThat(provider, notNullValue());
assertThat(provider.isEnabled(), is(true));
assertThat(provider.getRole(), is("authentication"));
assertThat(provider.getParams().size(), is(5));
Service service = topology.getService("WEBHDFS", "webhdfs", new Version(2, 4, 0));
assertEquals(comp, service);
comp = topology.getService("RESOURCEMANAGER", null, new Version("2.5.0"));
assertThat(comp, notNullValue());
assertThat(comp.getRole(), is("RESOURCEMANAGER"));
assertThat(comp.getVersion().toString(), is("2.5.0"));
assertThat(comp.getUrl(), is("http://host1:8088/ws"));
comp = topology.getService("HIVE", "hive", null);
assertThat(comp, notNullValue());
assertThat(comp.getRole(), is("HIVE"));
assertThat(comp.getName(), is("hive"));
assertThat(comp.getUrl(), is("http://host2:10001/cliservice"));
}
use of org.apache.knox.gateway.topology.Topology in project knox by apache.
the class TopologyRulesModuleTest method testParseTopologyWithApplication.
@Test
public void testParseTopologyWithApplication() throws IOException, SAXException {
Digester digester = loader.newDigester();
String name = "topology-with-application.xml";
URL url = TestUtils.getResourceUrl(TopologyRulesModuleTest.class, name);
assertThat("Failed to find URL for resource " + name, url, notNullValue());
File file = new File(url.getFile());
TopologyBuilder topologyBuilder = digester.parse(url);
Topology topology = topologyBuilder.build();
assertThat("Failed to parse resource " + name, topology, notNullValue());
topology.setTimestamp(file.lastModified());
Application app = topology.getApplications().iterator().next();
assertThat("Failed to find application", app, notNullValue());
assertThat(app.getName(), is("test-app-name"));
assertThat(app.getUrl(), is("test-app-path"));
assertThat(app.getUrls().get(0), is("test-app-path"));
assertThat(app.getParams().get("test-param-name"), is("test-param-value"));
}
use of org.apache.knox.gateway.topology.Topology in project knox by apache.
the class DefaultTopologyServiceTest method testTopologiesUpdateFromProviderConfigChange.
/**
* KNOX-1014
*
* Test the lifecycle relationship between provider configuration files, simple descriptors, and topology files.
*
* N.B. This test depends on the DummyServiceDiscovery extension being configured:
* org.apache.knox.gateway.topology.discovery.test.extension.DummyServiceDiscovery
*/
@Test
public void testTopologiesUpdateFromProviderConfigChange() throws Exception {
File dir = createDir();
File topologyDir = new File(dir, "topologies");
topologyDir.mkdirs();
File descriptorsDir = new File(dir, "descriptors");
descriptorsDir.mkdirs();
File sharedProvidersDir = new File(dir, "shared-providers");
sharedProvidersDir.mkdirs();
try {
TestTopologyListener topoListener = new TestTopologyListener();
FileAlterationMonitor monitor = new FileAlterationMonitor(Long.MAX_VALUE);
TopologyService ts = new DefaultTopologyService();
Map<String, String> c = new HashMap<>();
GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
EasyMock.expect(config.getGatewayTopologyDir()).andReturn(topologyDir.getAbsolutePath()).anyTimes();
EasyMock.expect(config.getGatewayConfDir()).andReturn(descriptorsDir.getParentFile().getAbsolutePath()).anyTimes();
EasyMock.replay(config);
ts.init(config, c);
ts.addTopologyChangeListener(topoListener);
ts.reloadTopologies();
java.lang.reflect.Field dmField = ts.getClass().getDeclaredField("descriptorsMonitor");
dmField.setAccessible(true);
DefaultTopologyService.DescriptorsMonitor dm = (DefaultTopologyService.DescriptorsMonitor) dmField.get(ts);
// Write out the referenced provider configs first
createFile(sharedProvidersDir, "provider-config-one.xml", "org/apache/knox/gateway/topology/file/provider-config-one.xml", System.currentTimeMillis());
// Create the simple descriptor, which depends on provider-config-one.xml
File simpleDesc = createFile(descriptorsDir, "six.json", "org/apache/knox/gateway/topology/file/simple-descriptor-six.json", System.currentTimeMillis());
// "Notice" the simple descriptor change, and generate a topology based on it
dm.onFileChange(simpleDesc);
// Load the generated topology
ts.reloadTopologies();
Collection<Topology> topologies = ts.getTopologies();
assertThat(topologies.size(), is(1));
Iterator<Topology> iterator = topologies.iterator();
Topology topology = iterator.next();
assertFalse("The Shiro provider is disabled in provider-config-one.xml", topology.getProvider("authentication", "ShiroProvider").isEnabled());
// Overwrite the referenced provider configuration with a different ShiroProvider config, and check that the
// changes are propagated to the associated topology
File providerConfig = createFile(sharedProvidersDir, "provider-config-one.xml", "org/apache/knox/gateway/topology/file/ambari-cluster-policy.xml", System.currentTimeMillis());
// "Notice" the simple descriptor change as a result of the referenced config change
dm.onFileChange(simpleDesc);
// Load the generated topology
ts.reloadTopologies();
topologies = ts.getTopologies();
assertFalse(topologies.isEmpty());
topology = topologies.iterator().next();
assertTrue("The Shiro provider is enabled in ambari-cluster-policy.xml", topology.getProvider("authentication", "ShiroProvider").isEnabled());
// Delete the provider configuration, and make sure that the associated topology file is unaffected.
// The topology file should not be affected because the simple descriptor handling will fail to resolve the
// referenced provider configuration.
// Delete the file
providerConfig.delete();
// The provider config deletion will trigger a descriptor change notification
dm.onFileChange(simpleDesc);
ts.reloadTopologies();
topologies = ts.getTopologies();
assertFalse(topologies.isEmpty());
assertTrue("The Shiro provider is enabled in ambari-cluster-policy.xml", topology.getProvider("authentication", "ShiroProvider").isEnabled());
} finally {
FileUtils.deleteQuietly(dir);
}
}
use of org.apache.knox.gateway.topology.Topology in project knox by apache.
the class PropertyTopologyBuilderTest method testBuildSuccessfulForServiceProperty.
@Test(expected = IllegalArgumentException.class)
public void testBuildSuccessfulForServiceProperty() {
PropertyTopologyBuilder propertyTopologyBuilder = new PropertyTopologyBuilder();
propertyTopologyBuilder.addProperty(new Property("topology.gateway.service.WEBHDFS..url", "http://host:50070/webhdfs"));
Topology topology = propertyTopologyBuilder.build();
assertThat(topology, notNullValue());
}
Aggregations