use of org.apache.knox.gateway.services.ServiceLifecycleException in project knox by apache.
the class KnoxCliLdapFuncTestPositive method setupGateway.
public static void setupGateway() throws Exception {
File targetDir = new File(System.getProperty("user.dir"), "target");
File gatewayDir = new File(targetDir, "gateway-home-" + uuid);
gatewayDir.mkdirs();
GatewayTestConfig testConfig = new GatewayTestConfig();
config = testConfig;
testConfig.setGatewayHomeDir(gatewayDir.getAbsolutePath());
File topoDir = new File(testConfig.getGatewayTopologyDir());
topoDir.mkdirs();
File deployDir = new File(testConfig.getGatewayDeploymentDir());
deployDir.mkdirs();
createTopology(topoDir, "test-cluster.xml", true);
createTopology(topoDir, "bad-cluster.xml", false);
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<>();
options.put("persist-master", "false");
options.put("master", "password");
try {
srvcs.init(testConfig, options);
} catch (ServiceLifecycleException e) {
// I18N not required.
e.printStackTrace();
}
}
use of org.apache.knox.gateway.services.ServiceLifecycleException in project knox by apache.
the class KnoxCliSysBindTest method setupGateway.
public static void setupGateway() throws Exception {
File targetDir = new File(System.getProperty("user.dir"), "target");
File gatewayDir = new File(targetDir, "gateway-home-" + uuid);
gatewayDir.mkdirs();
GatewayTestConfig testConfig = new GatewayTestConfig();
config = testConfig;
testConfig.setGatewayHomeDir(gatewayDir.getAbsolutePath());
File topoDir = new File(testConfig.getGatewayTopologyDir());
topoDir.mkdirs();
File deployDir = new File(testConfig.getGatewayDeploymentDir());
deployDir.mkdirs();
writeTopology(topoDir, "test-cluster-1.xml", "guest", "guest-password", true);
writeTopology(topoDir, "test-cluster-2.xml", "sam", "sam-password", true);
writeTopology(topoDir, "test-cluster-3.xml", "admin2", "admin-password", true);
writeTopology(topoDir, "test-cluster-4.xml", "", "", false);
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<>();
options.put("persist-master", "false");
options.put("master", "password");
try {
srvcs.init(testConfig, options);
} catch (ServiceLifecycleException e) {
// I18N not required.
e.printStackTrace();
}
}
use of org.apache.knox.gateway.services.ServiceLifecycleException in project knox by apache.
the class DeploymentFactoryFuncTest method testDeploymentWithApplication.
@Test(timeout = MEDIUM_TIMEOUT)
public void testDeploymentWithApplication() throws Exception {
LOG_ENTER();
GatewayConfig config = new GatewayTestConfig();
File targetDir = new File(System.getProperty("user.dir"), "target");
File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
gatewayDir.mkdirs();
((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
File deployDir = new File(config.getGatewayDeploymentDir());
deployDir.mkdirs();
URL serviceUrl = TestUtils.getResourceUrl(DeploymentFactoryFuncTest.class, "test-apps/minimal-test-app/service.xml");
File serviceFile = new File(serviceUrl.toURI());
File appsDir = serviceFile.getParentFile().getParentFile();
((GatewayTestConfig) config).setGatewayApplicationsDir(appsDir.getAbsolutePath());
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<>();
options.put("persist-master", "false");
options.put("master", "password");
try {
DeploymentFactory.setGatewayServices(srvcs);
srvcs.init(config, options);
} catch (ServiceLifecycleException e) {
// I18N not required.
e.printStackTrace();
}
Topology topology = new Topology();
topology.setName("test-topology");
Application app;
app = new Application();
app.setName("minimal-test-app");
app.addUrl("/minimal-test-app-path");
topology.addApplication(app);
EnterpriseArchive archive = DeploymentFactory.createDeployment(config, topology);
assertThat(archive, notNullValue());
Document doc;
doc = XmlUtils.readXml(archive.get("META-INF/topology.xml").getAsset().openStream());
assertThat(doc, notNullValue());
doc = XmlUtils.readXml(archive.get("%2Fminimal-test-app-path/WEB-INF/gateway.xml").getAsset().openStream());
assertThat(doc, notNullValue());
// dump( doc );
assertThat(doc, hasXPath("/gateway/resource/pattern", equalTo("/**?**")));
assertThat(doc, hasXPath("/gateway/resource/filter[1]/role", equalTo("xforwardedheaders")));
assertThat(doc, hasXPath("/gateway/resource/filter[1]/name", equalTo("XForwardedHeaderFilter")));
assertThat(doc, hasXPath("/gateway/resource/filter[1]/class", equalTo(XForwardedHeaderFilter.class.getName())));
assertThat(doc, hasXPath("/gateway/resource/filter[2]/role", equalTo("rewrite")));
assertThat(doc, hasXPath("/gateway/resource/filter[2]/name", equalTo("url-rewrite")));
assertThat(doc, hasXPath("/gateway/resource/filter[2]/class", equalTo(UrlRewriteServletFilter.class.getName())));
LOG_EXIT();
}
use of org.apache.knox.gateway.services.ServiceLifecycleException in project knox by apache.
the class DeploymentFactoryFuncTest method testDeploymentWithServiceParams.
@Test(timeout = LONG_TIMEOUT)
public void testDeploymentWithServiceParams() throws Exception {
LOG_ENTER();
GatewayConfig config = new GatewayTestConfig();
File targetDir = new File(System.getProperty("user.dir"), "target");
File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
gatewayDir.mkdirs();
((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
File deployDir = new File(config.getGatewayDeploymentDir());
deployDir.mkdirs();
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<>();
options.put("persist-master", "false");
options.put("master", "password");
try {
DeploymentFactory.setGatewayServices(srvcs);
srvcs.init(config, options);
} catch (ServiceLifecycleException e) {
// I18N not required.
e.printStackTrace();
}
Service service;
Param param;
Topology topology = new Topology();
topology.setName("test-cluster");
service = new Service();
service.setRole("HIVE");
service.setUrls(Arrays.asList(new String[] { "http://hive-host:50001/" }));
param = new Param();
param.setName("someparam");
param.setValue("somevalue");
service.addParam(param);
topology.addService(service);
service = new Service();
service.setRole("WEBHBASE");
service.setUrls(Arrays.asList(new String[] { "http://hbase-host:50002/" }));
param = new Param();
param.setName("replayBufferSize");
param.setValue("33");
service.addParam(param);
topology.addService(service);
service = new Service();
service.setRole("OOZIE");
service.setUrls(Arrays.asList(new String[] { "http://hbase-host:50003/" }));
param = new Param();
param.setName("otherparam");
param.setValue("65");
service.addParam(param);
topology.addService(service);
EnterpriseArchive war = DeploymentFactory.createDeployment(config, topology);
Document doc = XmlUtils.readXml(war.get("%2F/WEB-INF/gateway.xml").getAsset().openStream());
// dump( doc );
Node resourceNode, filterNode, paramNode;
String value;
resourceNode = node(doc, "gateway/resource[role/text()='HIVE']");
assertThat(resourceNode, is(not(nullValue())));
filterNode = node(resourceNode, "filter[role/text()='dispatch']");
assertThat(filterNode, is(not(nullValue())));
paramNode = node(filterNode, "param[name/text()='someparam']");
value = value(paramNode, "value/text()");
assertThat(value, is("somevalue"));
resourceNode = node(doc, "gateway/resource[role/text()='WEBHBASE']");
assertThat(resourceNode, is(not(nullValue())));
filterNode = node(resourceNode, "filter[role/text()='dispatch']");
assertThat(filterNode, is(not(nullValue())));
paramNode = node(filterNode, "param[name/text()='replayBufferSize']");
value = value(paramNode, "value/text()");
assertThat(value, is("33"));
resourceNode = node(doc, "gateway/resource[role/text()='OOZIE']");
assertThat(resourceNode, is(not(nullValue())));
filterNode = node(resourceNode, "filter[role/text()='dispatch']");
assertThat(filterNode, is(not(nullValue())));
paramNode = node(filterNode, "param[name/text()='otherparam']");
value = value(paramNode, "value/text()");
assertThat(value, is("65"));
FileUtils.deleteQuietly(deployDir);
LOG_EXIT();
}
use of org.apache.knox.gateway.services.ServiceLifecycleException in project knox by apache.
the class DeploymentFactoryFuncTest method testWebXmlGeneration.
@Test(timeout = LONG_TIMEOUT)
public void testWebXmlGeneration() throws IOException, SAXException, ParserConfigurationException, URISyntaxException {
LOG_ENTER();
GatewayConfig config = new GatewayTestConfig();
File targetDir = new File(System.getProperty("user.dir"), "target");
File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
gatewayDir.mkdirs();
((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
File deployDir = new File(config.getGatewayDeploymentDir());
deployDir.mkdirs();
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<>();
options.put("persist-master", "false");
options.put("master", "password");
try {
DeploymentFactory.setGatewayServices(srvcs);
srvcs.init(config, options);
} catch (ServiceLifecycleException e) {
// I18N not required.
e.printStackTrace();
}
Topology topology = new Topology();
topology.setName("test-cluster");
Service service = new Service();
service.setRole("WEBHDFS");
service.addUrl("http://localhost:50070/webhdfs");
topology.addService(service);
Provider provider = new Provider();
provider.setRole("authentication");
provider.setName("ShiroProvider");
provider.setEnabled(true);
Param param = new Param();
param.setName("contextConfigLocation");
param.setValue("classpath:app-context-security.xml");
provider.addParam(param);
topology.addProvider(provider);
Provider asserter = new Provider();
asserter.setRole("identity-assertion");
asserter.setName("Default");
asserter.setEnabled(true);
topology.addProvider(asserter);
Provider authorizer = new Provider();
authorizer.setRole("authorization");
authorizer.setName("AclsAuthz");
authorizer.setEnabled(true);
topology.addProvider(authorizer);
Provider ha = new Provider();
ha.setRole("ha");
ha.setName("HaProvider");
ha.setEnabled(true);
topology.addProvider(ha);
for (int i = 0; i < 10; i++) {
createAndTestDeployment(config, topology);
}
LOG_EXIT();
}
Aggregations