Search in sources :

Example 26 with GatewayConfigImpl

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

the class KnoxCLITest method testCreateMaster.

@Test
public void testCreateMaster() throws Exception {
    GatewayConfigImpl config = new GatewayConfigImpl();
    FileUtils.deleteQuietly(new File(config.getGatewaySecurityDir()));
    outContent.reset();
    String[] args = { "create-master", "--master", "master" };
    int rc = 0;
    KnoxCLI cli = new KnoxCLI();
    cli.setConf(config);
    rc = cli.run(args);
    assertEquals(0, rc);
    MasterService ms = cli.getGatewayServices().getService("MasterService");
    // assertTrue(ms.getClass().getName(), ms.getClass().getName().equals("kjdfhgjkhfdgjkh"));
    assertTrue(new String(ms.getMasterSecret()), "master".equals(new String(ms.getMasterSecret())));
    assertTrue(outContent.toString(), outContent.toString().contains("Master secret has been persisted to disk."));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GatewayConfigImpl(org.apache.knox.gateway.config.impl.GatewayConfigImpl) File(java.io.File) MasterService(org.apache.knox.gateway.services.security.MasterService) Test(org.junit.Test)

Example 27 with GatewayConfigImpl

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

the class KnoxCLITest method testRemoteConfigurationRegistryUploadDescriptor.

@Test
public void testRemoteConfigurationRegistryUploadDescriptor() throws Exception {
    outContent.reset();
    final String descriptorName = "my-topology.json";
    final String descriptorContent = testDescriptorContentJSON;
    final File testRoot = TestUtils.createTempDir(this.getClass().getName());
    try {
        final File testRegistry = new File(testRoot, "registryRoot");
        final File testDescriptor = new File(testRoot, descriptorName);
        final String[] args = { "upload-descriptor", testDescriptor.getAbsolutePath(), "--registry-client", "test_client", "--master", "master" };
        FileUtils.writeStringToFile(testDescriptor, descriptorContent);
        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);
        // Run the test command
        int rc = cli.run(args);
        // Validate the result
        assertEquals(0, rc);
        outContent.reset();
        final String[] listArgs = { "list-descriptors", "--registry-client", "test_client" };
        cli.run(listArgs);
        String outStr = outContent.toString().trim();
        assertTrue(outStr.startsWith("Descriptors"));
        assertTrue(outStr.endsWith(")\n" + descriptorName));
        File registryFile = new File(testRegistry, "knox/config/descriptors/" + descriptorName);
        assertTrue(registryFile.exists());
        assertEquals(FileUtils.readFileToString(registryFile), descriptorContent);
    } 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 28 with GatewayConfigImpl

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

the class KnoxCLITest method testRemoteConfigurationRegistryDeleteDescriptor.

@Test
public void testRemoteConfigurationRegistryDeleteDescriptor() throws Exception {
    outContent.reset();
    final String descriptorName = "my-topology.json";
    final String descriptorContent = testDescriptorContentJSON;
    final File testRoot = TestUtils.createTempDir(this.getClass().getName());
    try {
        final File testRegistry = new File(testRoot, "registryRoot");
        final File testDescriptor = new File(testRoot, descriptorName);
        final String[] createArgs = { "upload-descriptor", testDescriptor.getAbsolutePath(), "--registry-client", "test_client", "--master", "master" };
        FileUtils.writeStringToFile(testDescriptor, descriptorContent);
        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);
        // Run the test command
        int rc = cli.run(createArgs);
        // Validate the result
        assertEquals(0, rc);
        File registryFile = new File(testRegistry, "knox/config/descriptors/" + descriptorName);
        assertTrue(registryFile.exists());
        outContent.reset();
        // Delete the created provider config
        final String[] deleteArgs = { "delete-descriptor", descriptorName, "--registry-client", "test_client", "--master", "master" };
        rc = cli.run(deleteArgs);
        assertEquals(0, rc);
        assertFalse(registryFile.exists());
        // Try to delete a descriptor that does not exist
        rc = cli.run(new String[] { "delete-descriptor", "bogus.json", "--registry-client", "test_client", "--master", "master" });
        assertEquals(0, rc);
    } 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 29 with GatewayConfigImpl

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

the class KnoxCLITest method testSuccessfulAliasLifecycle.

@Test
public void testSuccessfulAliasLifecycle() throws Exception {
    outContent.reset();
    String[] args1 = { "create-alias", "alias1", "--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", "--master", "master" };
    rc = cli.run(args2);
    assertEquals(0, rc);
    assertTrue(outContent.toString(), outContent.toString().contains("alias1"));
    outContent.reset();
    String[] args4 = { "delete-alias", "alias1", "--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 30 with GatewayConfigImpl

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

the class KnoxCLITest method testListRemoteConfigurationRegistryClients.

@Test
public void testListRemoteConfigurationRegistryClients() throws Exception {
    outContent.reset();
    KnoxCLI cli = new KnoxCLI();
    String[] args = { "list-registry-clients", "--master", "master" };
    Configuration config = new GatewayConfigImpl();
    cli.setConf(config);
    // Test with no registry clients configured
    int rc = cli.run(args);
    assertEquals(0, rc);
    assertTrue(outContent.toString(), outContent.toString().isEmpty());
    // Test with a single client configured
    // Configure a client for the test local filesystem registry implementation
    config.set("gateway.remote.config.registry.test_client", "type=LocalFileSystem;address=/test1");
    cli.setConf(config);
    outContent.reset();
    rc = cli.run(args);
    assertEquals(0, rc);
    assertTrue(outContent.toString(), outContent.toString().contains("test_client"));
    // Configure another client for the test local filesystem registry implementation
    config.set("gateway.remote.config.registry.another_client", "type=LocalFileSystem;address=/test2");
    cli.setConf(config);
    outContent.reset();
    rc = cli.run(args);
    assertEquals(0, rc);
    assertTrue(outContent.toString(), outContent.toString().contains("test_client"));
    assertTrue(outContent.toString(), outContent.toString().contains("another_client"));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GatewayConfigImpl(org.apache.knox.gateway.config.impl.GatewayConfigImpl) 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