Search in sources :

Example 1 with RemoteConfigurationRegistryClientService

use of org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService 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();
    }
}
Also used : AliasService(org.apache.knox.gateway.services.security.AliasService) ZooKeeperClientServiceProvider(org.apache.knox.gateway.service.config.remote.zk.ZooKeeperClientServiceProvider) RemoteConfigurationRegistryClientService(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService) File(java.io.File) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 2 with RemoteConfigurationRegistryClientService

use of org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService in project knox by apache.

the class KnoxCLITest method testRemoteConfigurationRegistryClientService.

@Test
public void testRemoteConfigurationRegistryClientService() throws Exception {
    outContent.reset();
    KnoxCLI cli = new KnoxCLI();
    Configuration config = new GatewayConfigImpl();
    // Configure a client for the test local filesystem registry implementation
    config.set("gateway.remote.config.registry.test_client", "type=LocalFileSystem;address=/test");
    cli.setConf(config);
    // This is only to get the gateway services initialized
    cli.run(new String[] { "version" });
    RemoteConfigurationRegistryClientService service = cli.getGatewayServices().getService(GatewayServices.REMOTE_REGISTRY_CLIENT_SERVICE);
    assertNotNull(service);
    RemoteConfigurationRegistryClient client = service.get("test_client");
    assertNotNull(client);
    assertNull(service.get("bogus"));
}
Also used : RemoteConfigurationRegistryClient(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient) Configuration(org.apache.hadoop.conf.Configuration) RemoteConfigurationRegistryClientService(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService) GatewayConfigImpl(org.apache.knox.gateway.config.impl.GatewayConfigImpl) Test(org.junit.Test)

Example 3 with RemoteConfigurationRegistryClientService

use of org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService in project knox by apache.

the class CLIGatewayServices method init.

public void init(GatewayConfig config, Map<String, String> options) throws ServiceLifecycleException {
    ms = new CLIMasterService();
    ms.init(config, options);
    services.put("MasterService", ms);
    ks = new DefaultKeystoreService();
    ks.setMasterService(ms);
    ks.init(config, options);
    services.put(KEYSTORE_SERVICE, ks);
    DefaultAliasService alias = new DefaultAliasService();
    alias.setKeystoreService(ks);
    alias.init(config, options);
    services.put(ALIAS_SERVICE, alias);
    DefaultCryptoService crypto = new DefaultCryptoService();
    crypto.setKeystoreService(ks);
    crypto.setAliasService(alias);
    crypto.init(config, options);
    services.put(CRYPTO_SERVICE, crypto);
    DefaultTopologyService tops = new DefaultTopologyService();
    tops.init(config, options);
    services.put(TOPOLOGY_SERVICE, tops);
    RemoteConfigurationRegistryClientService registryClientService = RemoteConfigurationRegistryClientServiceFactory.newInstance(config);
    registryClientService.setAliasService(alias);
    registryClientService.init(config, options);
    services.put(REMOTE_REGISTRY_CLIENT_SERVICE, registryClientService);
}
Also used : DefaultKeystoreService(org.apache.knox.gateway.services.security.impl.DefaultKeystoreService) DefaultAliasService(org.apache.knox.gateway.services.security.impl.DefaultAliasService) DefaultTopologyService(org.apache.knox.gateway.services.topology.impl.DefaultTopologyService) RemoteConfigurationRegistryClientService(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService) DefaultCryptoService(org.apache.knox.gateway.services.security.impl.DefaultCryptoService) CLIMasterService(org.apache.knox.gateway.services.security.impl.CLIMasterService)

Example 4 with RemoteConfigurationRegistryClientService

use of org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService in project knox by apache.

the class DefaultGatewayServices method start.

public void start() throws ServiceLifecycleException {
    ms.start();
    ks.start();
    DefaultAliasService alias = (DefaultAliasService) services.get(ALIAS_SERVICE);
    alias.start();
    SSLService ssl = (SSLService) services.get(SSL_SERVICE);
    ssl.start();
    ServerInfoService sis = (ServerInfoService) services.get(SERVER_INFO_SERVICE);
    sis.start();
    RemoteConfigurationRegistryClientService clientService = (RemoteConfigurationRegistryClientService) services.get(REMOTE_REGISTRY_CLIENT_SERVICE);
    clientService.start();
    (services.get(CLUSTER_CONFIGURATION_MONITOR_SERVICE)).start();
    DefaultTopologyService tops = (DefaultTopologyService) services.get(TOPOLOGY_SERVICE);
    tops.start();
    DefaultMetricsService metricsService = (DefaultMetricsService) services.get(METRICS_SERVICE);
    metricsService.start();
}
Also used : DefaultAliasService(org.apache.knox.gateway.services.security.impl.DefaultAliasService) DefaultTopologyService(org.apache.knox.gateway.services.topology.impl.DefaultTopologyService) DefaultMetricsService(org.apache.knox.gateway.services.metrics.impl.DefaultMetricsService) RemoteConfigurationRegistryClientService(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService) JettySSLService(org.apache.knox.gateway.services.security.impl.JettySSLService) SSLService(org.apache.knox.gateway.services.security.SSLService)

Example 5 with RemoteConfigurationRegistryClientService

use of org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService in project knox by apache.

the class RemoteConfigurationRegistryClientServiceTest method testMultipleUnsecuredZooKeeperWithSimpleRegistryConfig.

/**
 * Test multiple configurations for an unsecured remote registry.
 */
@Test
public void testMultipleUnsecuredZooKeeperWithSimpleRegistryConfig() throws Exception {
    final String REGISTRY_CLIENT_NAME_1 = "zkclient1";
    final String REGISTRY_CLIENT_NAME_2 = "zkclient2";
    final String PRINCIPAL = null;
    final String PWD = null;
    final String CRED_ALIAS = null;
    // Configure and start a secure ZK cluster
    TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD);
    try {
        // Create the setup client for the test cluster, and initialize the test znodes
        CuratorFramework setupClient = initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
        // Mock configuration
        GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
        final String registryConfigValue1 = GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString();
        EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME_1)).andReturn(registryConfigValue1).anyTimes();
        final String registryConfigValue2 = GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString();
        EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME_2)).andReturn(registryConfigValue2).anyTimes();
        EasyMock.expect(config.getRemoteRegistryConfigurationNames()).andReturn(Arrays.asList(REGISTRY_CLIENT_NAME_1, REGISTRY_CLIENT_NAME_2)).anyTimes();
        EasyMock.replay(config);
        // Create the client service instance
        RemoteConfigurationRegistryClientService clientService = RemoteConfigurationRegistryClientServiceFactory.newInstance(config);
        assertEquals("Wrong registry client service type.", clientService.getClass(), CuratorClientService.class);
        clientService.setAliasService(null);
        clientService.init(config, null);
        clientService.start();
        RemoteConfigurationRegistryClient client1 = clientService.get(REGISTRY_CLIENT_NAME_1);
        assertNotNull(client1);
        RemoteConfigurationRegistryClient client2 = clientService.get(REGISTRY_CLIENT_NAME_2);
        assertNotNull(client2);
        doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME_1, clientService, false);
        doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME_2, clientService, false);
    } finally {
        zkCluster.stop();
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TestingCluster(org.apache.curator.test.TestingCluster) RemoteConfigurationRegistryClient(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient) RemoteConfigurationRegistryClientService(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Aggregations

RemoteConfigurationRegistryClientService (org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService)11 Test (org.junit.Test)6 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)5 AliasService (org.apache.knox.gateway.services.security.AliasService)5 ZooKeeperClientServiceProvider (org.apache.knox.gateway.service.config.remote.zk.ZooKeeperClientServiceProvider)4 DefaultAliasService (org.apache.knox.gateway.services.security.impl.DefaultAliasService)3 DefaultTopologyService (org.apache.knox.gateway.services.topology.impl.DefaultTopologyService)3 ACL (org.apache.zookeeper.data.ACL)3 File (java.io.File)2 RemoteConfigurationRegistryClient (org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient)2 DefaultMetricsService (org.apache.knox.gateway.services.metrics.impl.DefaultMetricsService)2 DefaultCryptoService (org.apache.knox.gateway.services.security.impl.DefaultCryptoService)2 DefaultKeystoreService (org.apache.knox.gateway.services.security.impl.DefaultKeystoreService)2 JettySSLService (org.apache.knox.gateway.services.security.impl.JettySSLService)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 TestingCluster (org.apache.curator.test.TestingCluster)1 Configuration (org.apache.hadoop.conf.Configuration)1 GatewayConfigImpl (org.apache.knox.gateway.config.impl.GatewayConfigImpl)1 DefaultHostMapperService (org.apache.knox.gateway.services.hostmap.impl.DefaultHostMapperService)1 DefaultServiceDefinitionRegistry (org.apache.knox.gateway.services.registry.impl.DefaultServiceDefinitionRegistry)1