Search in sources :

Example 6 with GatewayConfigImpl

use of org.apache.knox.gateway.config.impl.GatewayConfigImpl 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 7 with GatewayConfigImpl

use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.

the class KnoxCLITest method testRemoteConfigurationRegistryGetACLs.

@Test
public void testRemoteConfigurationRegistryGetACLs() throws Exception {
    outContent.reset();
    final File testRoot = TestUtils.createTempDir(this.getClass().getName());
    try {
        final File testRegistry = new File(testRoot, "registryRoot");
        final String providerConfigName = "my-provider-config.xml";
        final String providerConfigContent = "<gateway/>\n";
        final File testProviderConfig = new File(testRoot, providerConfigName);
        final String[] uploadArgs = { "upload-provider-config", testProviderConfig.getAbsolutePath(), "--registry-client", "test_client", "--master", "master" };
        FileUtils.writeStringToFile(testProviderConfig, providerConfigContent);
        final String[] args = { "get-registry-acl", "/knox/config/shared-providers", "--registry-client", "test_client", "--master", "master" };
        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=" + testRegistry);
        cli.setConf(config);
        int rc = cli.run(uploadArgs);
        assertEquals(0, rc);
        // Run the test command
        rc = cli.run(args);
        // Validate the result
        assertEquals(0, rc);
        String result = outContent.toString();
        assertEquals(result, 3, result.split("\n").length);
    } finally {
        FileUtils.forceDelete(testRoot);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) GatewayConfigImpl(org.apache.knox.gateway.config.impl.GatewayConfigImpl) Test(org.junit.Test)

Example 8 with GatewayConfigImpl

use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.

the class KnoxCLITest method testDeleteOfNonExistAliasFromUserDefinedCluster.

@Test
public void testDeleteOfNonExistAliasFromUserDefinedCluster() throws Exception {
    KnoxCLI cli = new KnoxCLI();
    cli.setConf(new GatewayConfigImpl());
    try {
        int rc = 0;
        outContent.reset();
        String[] args1 = { "create-alias", "alias1", "--cluster", "cluster1", "--value", "testvalue1", "--master", "master" };
        cli.run(args1);
        // Delete invalid alias from the cluster
        outContent.reset();
        String[] args2 = { "delete-alias", "alias2", "--cluster", "cluster1", "--master", "master" };
        rc = cli.run(args2);
        assertEquals(0, rc);
        assertTrue(outContent.toString().contains("No such alias exists in the cluster."));
    } finally {
        outContent.reset();
        String[] args1 = { "delete-alias", "alias1", "--cluster", "cluster1", "--master", "master" };
        cli.run(args1);
    }
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GatewayConfigImpl(org.apache.knox.gateway.config.impl.GatewayConfigImpl) Test(org.junit.Test)

Example 9 with GatewayConfigImpl

use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.

the class KnoxCLITest method testListAndDeleteOfAliasForValidClusterName.

@Test
public void testListAndDeleteOfAliasForValidClusterName() throws Exception {
    outContent.reset();
    String[] args1 = { "create-alias", "alias1", "--cluster", "cluster1", "--value", "testvalue1", "--master", "master" };
    int rc = 0;
    KnoxCLI cli = new KnoxCLI();
    cli.setConf(new GatewayConfigImpl());
    rc = cli.run(args1);
    assertEquals(0, rc);
    assertTrue(outContent.toString(), outContent.toString().contains("alias1 has been successfully " + "created."));
    outContent.reset();
    String[] args2 = { "list-alias", "--cluster", "cluster1", "--master", "master" };
    rc = cli.run(args2);
    assertEquals(0, rc);
    System.out.println(outContent.toString());
    assertTrue(outContent.toString(), outContent.toString().contains("alias1"));
    outContent.reset();
    String[] args4 = { "delete-alias", "alias1", "--cluster", "cluster1", "--master", "master" };
    rc = cli.run(args4);
    assertEquals(0, rc);
    assertTrue(outContent.toString(), outContent.toString().contains("alias1 has been successfully " + "deleted."));
    outContent.reset();
    rc = cli.run(args2);
    assertEquals(0, rc);
    assertFalse(outContent.toString(), outContent.toString().contains("alias1"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GatewayConfigImpl(org.apache.knox.gateway.config.impl.GatewayConfigImpl) Test(org.junit.Test)

Example 10 with GatewayConfigImpl

use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.

the class KnoxCLITest method testCreateSelfSignedCert.

@Test
public void testCreateSelfSignedCert() throws Exception {
    GatewayConfigImpl config = new GatewayConfigImpl();
    FileUtils.deleteQuietly(new File(config.getGatewaySecurityDir()));
    createTestMaster();
    outContent.reset();
    KnoxCLI cli = new KnoxCLI();
    cli.setConf(config);
    String[] gwCreateArgs = { "create-cert", "--hostname", "hostname1", "--master", "master" };
    int rc = 0;
    rc = cli.run(gwCreateArgs);
    assertEquals(0, rc);
    assertTrue(outContent.toString(), outContent.toString().contains("gateway-identity has been successfully " + "created."));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GatewayConfigImpl(org.apache.knox.gateway.config.impl.GatewayConfigImpl) File(java.io.File) Test(org.junit.Test)

Aggregations

GatewayConfigImpl (org.apache.knox.gateway.config.impl.GatewayConfigImpl)45 Test (org.junit.Test)42 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)20 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)19 File (java.io.File)13 Configuration (org.apache.hadoop.conf.Configuration)10 MasterService (org.apache.knox.gateway.services.security.MasterService)3 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)2 InstrumentationProvider (org.apache.knox.gateway.services.metrics.InstrumentationProvider)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1