use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class DefaultHttpClientFactory method getMaxConnections.
private int getMaxConnections(FilterConfig filterConfig) {
int maxConnections = 32;
GatewayConfig config = (GatewayConfig) filterConfig.getServletContext().getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
if (config != null) {
maxConnections = config.getHttpClientMaxConnections();
}
String str = filterConfig.getInitParameter("httpclient.maxConnections");
if (str != null) {
try {
maxConnections = Integer.parseInt(str);
} catch (NumberFormatException e) {
// Ignore it and use the default.
}
}
return maxConnections;
}
use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class AmbariServiceDiscoveryTest method testBulkClusterDiscovery.
@Test
public void testBulkClusterDiscovery() throws Exception {
final String discoveryAddress = "http://ambarihost:8080";
final String clusterName = "anotherCluster";
ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName);
GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
EasyMock.replay(gc);
ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
EasyMock.expect(sdc.getAddress()).andReturn(discoveryAddress).anyTimes();
EasyMock.expect(sdc.getUser()).andReturn(null).anyTimes();
EasyMock.replay(sdc);
Map<String, ServiceDiscovery.Cluster> clusters = sd.discover(gc, sdc);
assertNotNull(clusters);
assertEquals(1, clusters.size());
ServiceDiscovery.Cluster cluster = clusters.get(clusterName);
assertNotNull(cluster);
assertEquals(clusterName, cluster.getName());
assertTrue(AmbariCluster.class.isAssignableFrom(cluster.getClass()));
assertEquals(6, ((AmbariCluster) cluster).getComponents().size());
// printServiceURLs(cluster, "NAMENODE", "WEBHCAT", "OOZIE", "RESOURCEMANAGER");
}
use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class UrlRewriteRuleProcessorHolder method initialize.
public void initialize(UrlRewriteEnvironment environment, UrlRewriteRuleDescriptor descriptor) throws Exception {
super.initialize(environment, descriptor);
ruleName = descriptor.name();
// if a scope is set in the rewrite file, use that
if (descriptor.scope() != null) {
scope = descriptor.scope();
} else {
// by convention the name of the rules start with ROLENAME/servicename/direction
// use the first part of the name to determine the scope, therefore setting the scope of a rule to
// be local to that service
int slashIndex = ruleName.indexOf('/');
if (slashIndex > 0) {
scope = ruleName.substring(0, slashIndex);
}
// check config to see if the is an override configuration for a given service to have all its rules set to global
GatewayConfig gatewayConfig = environment.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
if (gatewayConfig != null) {
List<String> globalRulesServices = gatewayConfig.getGlobalRulesServices();
if (globalRulesServices.contains(scope)) {
scope = ScopedMatcher.GLOBAL_SCOPE;
}
}
}
}
use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class ZooKeeperConfigurationMonitorTest method testZooKeeperConfigMonitor.
@Test
public void testZooKeeperConfigMonitor() throws Exception {
String configMonitorName = "remoteConfigMonitorClient";
// Setup the base GatewayConfig mock
gc = EasyMock.createNiceMock(GatewayConfig.class);
EasyMock.expect(gc.getGatewayProvidersConfigDir()).andReturn(providersDir.getAbsolutePath()).anyTimes();
EasyMock.expect(gc.getGatewayDescriptorsDir()).andReturn(descriptorsDir.getAbsolutePath()).anyTimes();
EasyMock.expect(gc.getRemoteRegistryConfigurationNames()).andReturn(Collections.singletonList(configMonitorName)).anyTimes();
final String registryConfig = GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString();
EasyMock.expect(gc.getRemoteRegistryConfiguration(configMonitorName)).andReturn(registryConfig).anyTimes();
EasyMock.expect(gc.getRemoteConfigurationMonitorClientName()).andReturn(configMonitorName).anyTimes();
EasyMock.replay(gc);
AliasService aliasService = EasyMock.createNiceMock(AliasService.class);
EasyMock.replay(aliasService);
RemoteConfigurationRegistryClientService clientService = (new ZooKeeperClientServiceProvider()).newInstance();
clientService.setAliasService(aliasService);
clientService.init(gc, Collections.emptyMap());
clientService.start();
DefaultRemoteConfigurationMonitor cm = new DefaultRemoteConfigurationMonitor(gc, clientService);
// Create a provider configuration in the test ZK, prior to starting the monitor, to make sure that the monitor
// will download existing entries upon starting.
final String preExistingProviderConfig = getProviderPath("pre-existing-providers.xml");
client.create().withMode(CreateMode.PERSISTENT).forPath(preExistingProviderConfig, TEST_PROVIDERS_CONFIG_1.getBytes());
File preExistingProviderConfigLocalFile = new File(providersDir, "pre-existing-providers.xml");
assertFalse("This file should not exist locally prior to monitor starting.", preExistingProviderConfigLocalFile.exists());
try {
cm.start();
} catch (Exception e) {
fail("Failed to start monitor: " + e.getMessage());
}
assertTrue("This file should exist locally immediately after monitor starting.", preExistingProviderConfigLocalFile.exists());
try {
final String pc_one_znode = getProviderPath("providers-config1.xml");
final File pc_one = new File(providersDir, "providers-config1.xml");
final String pc_two_znode = getProviderPath("providers-config2.xml");
final File pc_two = new File(providersDir, "providers-config2.xml");
client.create().withMode(CreateMode.PERSISTENT).forPath(pc_one_znode, TEST_PROVIDERS_CONFIG_1.getBytes());
Thread.sleep(100);
assertTrue(pc_one.exists());
assertEquals(TEST_PROVIDERS_CONFIG_1, FileUtils.readFileToString(pc_one));
client.create().withMode(CreateMode.PERSISTENT).forPath(getProviderPath("providers-config2.xml"), TEST_PROVIDERS_CONFIG_2.getBytes());
Thread.sleep(100);
assertTrue(pc_two.exists());
assertEquals(TEST_PROVIDERS_CONFIG_2, FileUtils.readFileToString(pc_two));
client.setData().forPath(pc_two_znode, TEST_PROVIDERS_CONFIG_1.getBytes());
Thread.sleep(100);
assertTrue(pc_two.exists());
assertEquals(TEST_PROVIDERS_CONFIG_1, FileUtils.readFileToString(pc_two));
client.delete().forPath(pc_two_znode);
Thread.sleep(100);
assertFalse(pc_two.exists());
client.delete().forPath(pc_one_znode);
Thread.sleep(100);
assertFalse(pc_one.exists());
final String desc_one_znode = getDescriptorPath("test1.json");
final String desc_two_znode = getDescriptorPath("test2.json");
final String desc_three_znode = getDescriptorPath("test3.json");
final File desc_one = new File(descriptorsDir, "test1.json");
final File desc_two = new File(descriptorsDir, "test2.json");
final File desc_three = new File(descriptorsDir, "test3.json");
client.create().withMode(CreateMode.PERSISTENT).forPath(desc_one_znode, TEST_DESCRIPTOR_1.getBytes());
Thread.sleep(100);
assertTrue(desc_one.exists());
assertEquals(TEST_DESCRIPTOR_1, FileUtils.readFileToString(desc_one));
client.create().withMode(CreateMode.PERSISTENT).forPath(desc_two_znode, TEST_DESCRIPTOR_1.getBytes());
Thread.sleep(100);
assertTrue(desc_two.exists());
assertEquals(TEST_DESCRIPTOR_1, FileUtils.readFileToString(desc_two));
client.setData().forPath(desc_two_znode, TEST_DESCRIPTOR_2.getBytes());
Thread.sleep(100);
assertTrue(desc_two.exists());
assertEquals(TEST_DESCRIPTOR_2, FileUtils.readFileToString(desc_two));
client.create().withMode(CreateMode.PERSISTENT).forPath(desc_three_znode, TEST_DESCRIPTOR_1.getBytes());
Thread.sleep(100);
assertTrue(desc_three.exists());
assertEquals(TEST_DESCRIPTOR_1, FileUtils.readFileToString(desc_three));
client.delete().forPath(desc_two_znode);
Thread.sleep(100);
assertFalse("Expected test2.json to have been deleted.", desc_two.exists());
client.delete().forPath(desc_three_znode);
Thread.sleep(100);
assertFalse(desc_three.exists());
client.delete().forPath(desc_one_znode);
Thread.sleep(100);
assertFalse(desc_one.exists());
} finally {
cm.stop();
}
}
use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class SimpleDescriptorHandlerTest method testMissingProviderConfigReference.
/**
* KNOX-1216
*/
@Test
public void testMissingProviderConfigReference() throws Exception {
// Prepare a mock SimpleDescriptor
final Map<String, List<String>> serviceURLs = new HashMap<>();
serviceURLs.put("NAMENODE", null);
serviceURLs.put("JOBTRACKER", null);
serviceURLs.put("WEBHDFS", null);
serviceURLs.put("WEBHCAT", null);
serviceURLs.put("OOZIE", null);
serviceURLs.put("WEBHBASE", null);
serviceURLs.put("HIVE", null);
serviceURLs.put("RESOURCEMANAGER", null);
serviceURLs.put("AMBARIUI", Collections.singletonList("http://c6401.ambari.apache.org:8080"));
File destDir = new File(System.getProperty("java.io.tmpdir")).getCanonicalFile();
GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
EasyMock.replay(gc);
// Mock out the simple descriptor
SimpleDescriptor testDescriptor = EasyMock.createNiceMock(SimpleDescriptor.class);
EasyMock.expect(testDescriptor.getName()).andReturn("mysimpledescriptor").anyTimes();
EasyMock.expect(testDescriptor.getDiscoveryUser()).andReturn(null).anyTimes();
EasyMock.expect(testDescriptor.getProviderConfig()).andReturn(null).anyTimes();
List<SimpleDescriptor.Service> serviceMocks = new ArrayList<>();
for (String serviceName : serviceURLs.keySet()) {
SimpleDescriptor.Service svc = EasyMock.createNiceMock(SimpleDescriptor.Service.class);
EasyMock.expect(svc.getName()).andReturn(serviceName).anyTimes();
EasyMock.expect(svc.getVersion()).andReturn("WEBHDFS".equals(serviceName) ? "2.4.0" : null).anyTimes();
EasyMock.expect(svc.getURLs()).andReturn(serviceURLs.get(serviceName)).anyTimes();
EasyMock.replay(svc);
serviceMocks.add(svc);
}
EasyMock.expect(testDescriptor.getServices()).andReturn(serviceMocks).anyTimes();
EasyMock.replay(testDescriptor);
try {
// Invoke the simple descriptor handler
SimpleDescriptorHandler.handle(gc, testDescriptor, destDir, destDir);
fail("Expected an IllegalArgumentException because the provider configuration reference is missing.");
} catch (IllegalArgumentException e) {
// Expected
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception for missing provider configuration reference: " + e.getClass().getName() + " : " + e.getMessage());
}
}
Aggregations