Search in sources :

Example 6 with DefaultGatewayServices

use of org.apache.knox.gateway.services.DefaultGatewayServices in project knox by apache.

the class GatewayDeployFuncTest method setupGateway.

@Before
public void setupGateway() throws Exception {
    File targetDir = new File(System.getProperty("user.dir"), "target");
    File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
    gatewayDir.mkdirs();
    gatewayHome = gatewayDir;
    GatewayTestConfig testConfig = new GatewayTestConfig();
    config = testConfig;
    testConfig.setGatewayHomeDir(gatewayDir.getAbsolutePath());
    File topoDir = new File(testConfig.getGatewayTopologyDir());
    topoDir.mkdirs();
    File deployDir = new File(testConfig.getGatewayDeploymentDir());
    deployDir.mkdirs();
    DefaultGatewayServices srvcs = new DefaultGatewayServices();
    Map<String, String> options = new HashMap<>();
    options.put("persist-master", "false");
    options.put("master", "password");
    try {
        srvcs.init(testConfig, options);
    } catch (ServiceLifecycleException e) {
        // I18N not required.
        e.printStackTrace();
    }
    gateway = GatewayServer.startGateway(testConfig, srvcs);
    MatcherAssert.assertThat("Failed to start gateway.", gateway, notNullValue());
    LOG.info("Gateway port = " + gateway.getAddresses()[0].getPort());
    gatewayUrl = "http://localhost:" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath();
    clusterUrl = gatewayUrl + "/test-cluster";
}
Also used : HashMap(java.util.HashMap) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) Before(org.junit.Before)

Example 7 with DefaultGatewayServices

use of org.apache.knox.gateway.services.DefaultGatewayServices in project knox by apache.

the class GatewayLdapDynamicGroupFuncTest method setupGateway.

public static void setupGateway() throws IOException, Exception {
    File targetDir = new File(System.getProperty("user.dir"), "target");
    File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
    gatewayDir.mkdirs();
    GatewayTestConfig testConfig = new GatewayTestConfig();
    config = testConfig;
    testConfig.setGatewayHomeDir(gatewayDir.getAbsolutePath());
    File topoDir = new File(testConfig.getGatewayTopologyDir());
    topoDir.mkdirs();
    File deployDir = new File(testConfig.getGatewayDeploymentDir());
    deployDir.mkdirs();
    DefaultGatewayServices srvcs = new DefaultGatewayServices();
    Map<String, String> options = new HashMap<>();
    options.put("persist-master", "false");
    options.put("master", "password");
    try {
        srvcs.init(testConfig, options);
    } catch (ServiceLifecycleException e) {
        // I18N not required.
        e.printStackTrace();
    }
    /*
    System.setProperty(GatewayConfig.GATEWAY_HOME_VAR, gatewayDir.getAbsolutePath());
    System.err.println("GH 10: " + System.getProperty(GatewayConfig.GATEWAY_HOME_VAR));
    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
    System.setOut(new PrintStream(outContent));
    String[] argvals = {"create-alias", "ldcSystemPassword", "--value", "guest-password", "--master", "hadoop", "--cluster", "testdg-cluster"};
    KnoxCLI cli = new KnoxCLI();
    cli.setConf(new GatewayConfigImpl());
    cli.run(argvals);

    outContent.reset();
    String[] args1 = {"list-alias", "--cluster", "testdg-cluster", "--master", "hadoop"};
    cli = new KnoxCLI();
    cli.run(args1);
    System.err.println("ALIAS LIST: " + outContent.toString());

    AliasService as1 = cli.getGatewayServices().getService(GatewayServices.ALIAS_SERVICE);
    char[] passwordChars1 = as1.getPasswordFromAliasForCluster( "test-cluster", "ldcsystemPassword");
    System.err.println("ALIAS value1: " + new String(passwordChars1));
    */
    gateway = GatewayServer.startGateway(testConfig, srvcs);
    MatcherAssert.assertThat("Failed to start gateway.", gateway, notNullValue());
    LOG.info("Gateway port = " + gateway.getAddresses()[0].getPort());
    gatewayUrl = "http://localhost:" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath();
    clusterUrl = gatewayUrl + "/testdg-cluster";
    serviceUrl = clusterUrl + "/test-service-path/test-service-resource";
    // /*
    GatewayServices services = GatewayServer.getGatewayServices();
    AliasService aliasService = (AliasService) services.getService(GatewayServices.ALIAS_SERVICE);
    aliasService.addAliasForCluster("testdg-cluster", "ldcSystemPassword", "guest-password");
    // char[] password1 = aliasService.getPasswordFromAliasForCluster( "testdg-cluster", "ldcSystemPassword");
    // System.err.println("SETUP password 10: " + ((password1 == null) ? "NULL" : new String(password1)));
    File descriptor = new File(topoDir, "testdg-cluster.xml");
    FileOutputStream stream = new FileOutputStream(descriptor);
    createTopology().toStream(stream);
    stream.close();
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) AliasService(org.apache.knox.gateway.services.security.AliasService) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File)

Example 8 with DefaultGatewayServices

use of org.apache.knox.gateway.services.DefaultGatewayServices in project knox by apache.

the class GatewayLdapGroupFuncTest method setupGateway.

public static void setupGateway() throws Exception {
    File targetDir = new File(System.getProperty("user.dir"), "target");
    File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
    gatewayDir.mkdirs();
    GatewayTestConfig testConfig = new GatewayTestConfig();
    config = testConfig;
    testConfig.setGatewayHomeDir(gatewayDir.getAbsolutePath());
    File topoDir = new File(testConfig.getGatewayTopologyDir());
    topoDir.mkdirs();
    File deployDir = new File(testConfig.getGatewayDeploymentDir());
    deployDir.mkdirs();
    DefaultGatewayServices srvcs = new DefaultGatewayServices();
    Map<String, String> options = new HashMap<>();
    options.put("persist-master", "true");
    options.put("master", "hadoop");
    try {
        srvcs.init(testConfig, options);
    } catch (ServiceLifecycleException e) {
        // I18N not required.
        e.printStackTrace();
    }
    /*
    System.setProperty(GatewayConfig.GATEWAY_HOME_VAR, gatewayDir.getAbsolutePath());
    System.err.println("GH 10: " + System.getProperty(GatewayConfig.GATEWAY_HOME_VAR));
    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
    System.setOut(new PrintStream(outContent));
    String[] argvals = {"create-alias", "ldcSystemPassword", "--value", "guest-password", "--master", "hadoop", "--cluster", "test-cluster"};
    KnoxCLI cli = new KnoxCLI();
    cli.setConf(new GatewayConfigImpl());
    cli.run(argvals);

    outContent.reset();
    String[] args1 = {"list-alias", "--cluster", "test-cluster", "--master", "hadoop"};
    cli = new KnoxCLI();
    cli.run(args1);
    System.err.println("ALIAS LIST: " + outContent.toString());

    AliasService as1 = cli.getGatewayServices().getService(GatewayServices.ALIAS_SERVICE);
    char[] passwordChars1 = as1.getPasswordFromAliasForCluster( "test-cluster", "ldcsystemPassword");
    System.err.println("ALIAS value1: " + new String(passwordChars1));
    */
    gateway = GatewayServer.startGateway(testConfig, srvcs);
    MatcherAssert.assertThat("Failed to start gateway.", gateway, notNullValue());
    LOG.info("Gateway port = " + gateway.getAddresses()[0].getPort());
    gatewayUrl = "http://localhost:" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath();
    clusterUrl = gatewayUrl + "/test-cluster";
    serviceUrl = clusterUrl + "/test-service-path/test-service-resource";
    // /*
    GatewayServices services = GatewayServer.getGatewayServices();
    AliasService aliasService = (AliasService) services.getService(GatewayServices.ALIAS_SERVICE);
    aliasService.addAliasForCluster("test-cluster", "ldcSystemPassword", "guest-password");
    // char[] password1 = aliasService.getPasswordFromAliasForCluster( "test-cluster", "ldcSystemPassword");
    // System.err.println("SETUP password 10: " + ((password1 == null) ? "NULL" : new String(password1)));
    File descriptor = new File(topoDir, "test-cluster.xml");
    FileOutputStream stream = new FileOutputStream(descriptor);
    createTopology().toStream(stream);
    stream.close();
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) AliasService(org.apache.knox.gateway.services.security.AliasService) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File)

Example 9 with DefaultGatewayServices

use of org.apache.knox.gateway.services.DefaultGatewayServices in project knox by apache.

the class GatewayLocalServiceFuncTest method setupGateway.

public static void setupGateway() throws Exception {
    File targetDir = new File(System.getProperty("user.dir"), "target");
    File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
    gatewayDir.mkdirs();
    GatewayTestConfig testConfig = new GatewayTestConfig();
    config = testConfig;
    testConfig.setGatewayHomeDir(gatewayDir.getAbsolutePath());
    File topoDir = new File(testConfig.getGatewayTopologyDir());
    topoDir.mkdirs();
    File deployDir = new File(testConfig.getGatewayDeploymentDir());
    deployDir.mkdirs();
    File descriptor = new File(topoDir, "cluster.xml");
    FileOutputStream stream = new FileOutputStream(descriptor);
    createTopology().toStream(stream);
    stream.close();
    DefaultGatewayServices srvcs = new DefaultGatewayServices();
    Map<String, String> options = new HashMap<>();
    options.put("persist-master", "false");
    options.put("master", "password");
    try {
        srvcs.init(testConfig, options);
    } catch (ServiceLifecycleException e) {
        // I18N not required.
        e.printStackTrace();
    }
    gateway = GatewayServer.startGateway(testConfig, srvcs);
    MatcherAssert.assertThat("Failed to start gateway.", gateway, notNullValue());
    LOG.info("Gateway port = " + gateway.getAddresses()[0].getPort());
    gatewayUrl = "http://localhost:" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath();
    clusterUrl = gatewayUrl + "/cluster";
}
Also used : HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File)

Example 10 with DefaultGatewayServices

use of org.apache.knox.gateway.services.DefaultGatewayServices in project knox by apache.

the class Knox242FuncTest method setupGateway.

public static void setupGateway() throws IOException, Exception {
    File targetDir = new File(System.getProperty("user.dir"), "target");
    File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
    gatewayDir.mkdirs();
    GatewayTestConfig testConfig = new GatewayTestConfig();
    config = testConfig;
    testConfig.setGatewayHomeDir(gatewayDir.getAbsolutePath());
    File topoDir = new File(testConfig.getGatewayTopologyDir());
    topoDir.mkdirs();
    File deployDir = new File(testConfig.getGatewayDeploymentDir());
    deployDir.mkdirs();
    DefaultGatewayServices srvcs = new DefaultGatewayServices();
    Map<String, String> options = new HashMap<>();
    options.put("persist-master", "false");
    options.put("master", "password");
    try {
        srvcs.init(testConfig, options);
    } catch (ServiceLifecycleException e) {
        // I18N not required.
        e.printStackTrace();
    }
    gateway = GatewayServer.startGateway(testConfig, srvcs);
    MatcherAssert.assertThat("Failed to start gateway.", gateway, notNullValue());
    LOG.info("Gateway port = " + gateway.getAddresses()[0].getPort());
    gatewayUrl = "http://localhost:" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath();
    clusterUrl = gatewayUrl + "/testdg-cluster";
    serviceUrl = clusterUrl + "/test-service-path/test-service-resource";
    GatewayServices services = GatewayServer.getGatewayServices();
    AliasService aliasService = (AliasService) services.getService(GatewayServices.ALIAS_SERVICE);
    aliasService.addAliasForCluster("testdg-cluster", "ldcSystemPassword", "guest-password");
    // char[] password1 = aliasService.getPasswordFromAliasForCluster( "testdg-cluster", "ldcSystemPassword");
    // System.err.println("SETUP password 10: " + ((password1 == null) ? "NULL" : new String(password1)));
    File descriptor = new File(topoDir, "testdg-cluster.xml");
    FileOutputStream stream = new FileOutputStream(descriptor);
    createTopology().toStream(stream);
    stream.close();
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) AliasService(org.apache.knox.gateway.services.security.AliasService) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File)

Aggregations

DefaultGatewayServices (org.apache.knox.gateway.services.DefaultGatewayServices)30 ServiceLifecycleException (org.apache.knox.gateway.services.ServiceLifecycleException)30 HashMap (java.util.HashMap)29 File (java.io.File)26 FileOutputStream (java.io.FileOutputStream)14 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)11 GatewayTestConfig (org.apache.knox.gateway.GatewayTestConfig)8 Topology (org.apache.knox.gateway.topology.Topology)8 Test (org.junit.Test)8 Service (org.apache.knox.gateway.topology.Service)7 Param (org.apache.knox.gateway.topology.Param)6 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)6 Document (org.w3c.dom.Document)6 URL (java.net.URL)5 Provider (org.apache.knox.gateway.topology.Provider)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 Properties (java.util.Properties)4 GatewayServices (org.apache.knox.gateway.services.GatewayServices)4 AliasService (org.apache.knox.gateway.services.security.AliasService)4 TopologyService (org.apache.knox.gateway.services.topology.TopologyService)3