Search in sources :

Example 11 with GatewayConfigImpl

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

the class KnoxCLITest method testForInvalidArgument.

@Test
public void testForInvalidArgument() throws Exception {
    outContent.reset();
    String[] args1 = { "--value", "testvalue1", "--master", "master" };
    KnoxCLI cli = new KnoxCLI();
    cli.setConf(new GatewayConfigImpl());
    int rc = cli.run(args1);
    assertEquals(-2, rc);
    assertTrue(outContent.toString().contains("ERROR: Invalid Command"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GatewayConfigImpl(org.apache.knox.gateway.config.impl.GatewayConfigImpl) Test(org.junit.Test)

Example 12 with GatewayConfigImpl

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

the class KnoxCLITest method testRemoteConfigurationRegistryUploadProviderConfig.

@Test
public void testRemoteConfigurationRegistryUploadProviderConfig() throws Exception {
    outContent.reset();
    final String providerConfigName = "my-provider-config.xml";
    final String providerConfigContent = "<gateway/>\n";
    final File testRoot = TestUtils.createTempDir(this.getClass().getName());
    try {
        final File testRegistry = new File(testRoot, "registryRoot");
        final File testProviderConfig = new File(testRoot, providerConfigName);
        final String[] args = { "upload-provider-config", testProviderConfig.getAbsolutePath(), "--registry-client", "test_client", "--master", "master" };
        FileUtils.writeStringToFile(testProviderConfig, providerConfigContent);
        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-provider-configs", "--registry-client", "test_client" };
        cli.run(listArgs);
        String outStr = outContent.toString().trim();
        assertTrue(outStr.startsWith("Provider Configurations"));
        assertTrue(outStr.endsWith(")\n" + providerConfigName));
        File registryFile = new File(testRegistry, "knox/config/shared-providers/" + providerConfigName);
        assertTrue(registryFile.exists());
        assertEquals(FileUtils.readFileToString(registryFile), providerConfigContent);
    } 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 13 with GatewayConfigImpl

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

the class KnoxCLITest method testRemoteConfigurationRegistryDeleteProviderConfig.

@Test
public void testRemoteConfigurationRegistryDeleteProviderConfig() throws Exception {
    outContent.reset();
    // Create a provider config
    final String providerConfigName = "my-provider-config.xml";
    final String providerConfigContent = "<gateway/>\n";
    final File testRoot = TestUtils.createTempDir(this.getClass().getName());
    try {
        final File testRegistry = new File(testRoot, "registryRoot");
        final File testProviderConfig = new File(testRoot, providerConfigName);
        final String[] createArgs = { "upload-provider-config", testProviderConfig.getAbsolutePath(), "--registry-client", "test_client", "--master", "master" };
        FileUtils.writeStringToFile(testProviderConfig, providerConfigContent);
        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/shared-providers/" + providerConfigName);
        assertTrue(registryFile.exists());
        outContent.reset();
        // Delete the created provider config
        final String[] deleteArgs = { "delete-provider-config", providerConfigName, "--registry-client", "test_client", "--master", "master" };
        rc = cli.run(deleteArgs);
        assertEquals(0, rc);
        assertFalse(registryFile.exists());
        // Try to delete a provider config that does not exist
        rc = cli.run(new String[] { "delete-provider-config", "imaginary-providers.xml", "--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 14 with GatewayConfigImpl

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

the class KnoxCLITest method testGatewayAndClusterStores.

@Test
public void testGatewayAndClusterStores() throws Exception {
    GatewayConfigImpl config = new GatewayConfigImpl();
    FileUtils.deleteQuietly(new File(config.getGatewaySecurityDir()));
    outContent.reset();
    String[] gwCreateArgs = { "create-alias", "alias1", "--value", "testvalue1", "--master", "master" };
    int rc = 0;
    KnoxCLI cli = new KnoxCLI();
    cli.setConf(config);
    rc = cli.run(gwCreateArgs);
    assertEquals(0, rc);
    assertTrue(outContent.toString(), outContent.toString().contains("alias1 has been successfully " + "created."));
    AliasService as = cli.getGatewayServices().getService(GatewayServices.ALIAS_SERVICE);
    outContent.reset();
    String[] clusterCreateArgs = { "create-alias", "alias2", "--value", "testvalue1", "--cluster", "test", "--master", "master" };
    cli = new KnoxCLI();
    cli.setConf(config);
    rc = cli.run(clusterCreateArgs);
    assertEquals(0, rc);
    assertTrue(outContent.toString(), outContent.toString().contains("alias2 has been successfully " + "created."));
    outContent.reset();
    String[] args2 = { "list-alias", "--master", "master" };
    cli = new KnoxCLI();
    rc = cli.run(args2);
    assertEquals(0, rc);
    assertFalse(outContent.toString(), outContent.toString().contains("alias2"));
    assertTrue(outContent.toString(), outContent.toString().contains("alias1"));
    char[] passwordChars = as.getPasswordFromAliasForCluster("test", "alias2");
    assertNotNull(passwordChars);
    assertTrue(new String(passwordChars), "testvalue1".equals(new String(passwordChars)));
    outContent.reset();
    String[] args1 = { "list-alias", "--cluster", "test", "--master", "master" };
    cli = new KnoxCLI();
    rc = cli.run(args1);
    assertEquals(0, rc);
    assertFalse(outContent.toString(), outContent.toString().contains("alias1"));
    assertTrue(outContent.toString(), outContent.toString().contains("alias2"));
    outContent.reset();
    String[] args4 = { "delete-alias", "alias1", "--master", "master" };
    cli = new KnoxCLI();
    rc = cli.run(args4);
    assertEquals(0, rc);
    assertTrue(outContent.toString(), outContent.toString().contains("alias1 has been successfully " + "deleted."));
    outContent.reset();
    String[] args5 = { "delete-alias", "alias2", "--cluster", "test", "--master", "master" };
    cli = new KnoxCLI();
    rc = cli.run(args5);
    assertEquals(0, rc);
    assertTrue(outContent.toString(), outContent.toString().contains("alias2 has been successfully " + "deleted."));
}
Also used : AliasService(org.apache.knox.gateway.services.security.AliasService) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GatewayConfigImpl(org.apache.knox.gateway.config.impl.GatewayConfigImpl) File(java.io.File) Test(org.junit.Test)

Example 15 with GatewayConfigImpl

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

the class GatewayGlobalConfigTest method testForUpdatedDeploymentDir.

@Test
public void testForUpdatedDeploymentDir() {
    String homeDirName = getHomeDirName("conf-demo/conf/gateway-site.xml");
    System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, homeDirName);
    System.setProperty(GatewayConfigImpl.GATEWAY_DATA_HOME_VAR, homeDirName);
    GatewayConfig config = new GatewayConfigImpl();
    assertTrue(("target/test").equalsIgnoreCase(config.getGatewayDeploymentDir()));
}
Also used : GatewayConfigImpl(org.apache.knox.gateway.config.impl.GatewayConfigImpl) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) 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