Search in sources :

Example 6 with CLIConnectionConfig

use of io.cdap.cdap.cli.CLIConnectionConfig in project cdap by cdapio.

the class InstanceURIParserTest method testParseInstanceURI.

@Test
public void testParseInstanceURI() {
    NamespaceId someNamespace = new NamespaceId("nsx");
    InstanceURIParser parser = new InstanceURIParser(null);
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", null, false, ""), parser.parseInstanceURI("somehost", null));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", null, false, ""), parser.parseInstanceURI("http://somehost", null));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", null, true, ""), parser.parseInstanceURI("https://somehost", ""));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, false, ""), parser.parseInstanceURI("somehost:1234", ""));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, false, ""), parser.parseInstanceURI("http://somehost:1234", null));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, true, ""), parser.parseInstanceURI("https://somehost:1234", null));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", null, false, "api/"), parser.parseInstanceURI("somehost/api/", ""));
    Assert.assertEquals(new CLIConnectionConfig(someNamespace, "somehost", 1234, false, ""), parser.parseInstanceURI("http://somehost:1234", "nsx"));
    Assert.assertEquals(new CLIConnectionConfig(someNamespace, "somehost", null, true, "api/"), parser.parseInstanceURI("https://somehost/api", "nsx"));
}
Also used : CLIConnectionConfig(io.cdap.cdap.cli.CLIConnectionConfig) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 7 with CLIConnectionConfig

use of io.cdap.cdap.cli.CLIConnectionConfig in project cdap by cdapio.

the class InstanceURIParser method parseInstanceURI.

public CLIConnectionConfig parseInstanceURI(String uriString, String namespaceString) {
    uriString = addScheme(uriString);
    // Having '/' at the end of the path helps java.net.URI to recognise this as a valid URI path
    if (uriString.length() > 0 && !uriString.endsWith("/")) {
        uriString = String.format("%s/", uriString);
    }
    URI uri = URI.create(uriString);
    NamespaceId namespace = (namespaceString == null || namespaceString.isEmpty()) ? NamespaceId.DEFAULT : new NamespaceId(namespaceString);
    String apiPath = uri.getPath();
    if (apiPath != null && apiPath.startsWith("/")) {
        apiPath = apiPath.substring(1);
    }
    ConnectionConfig config = ConnectionConfig.builder().setHostname(uri.getHost()).setPort(uri.getPort() == -1 ? null : uri.getPort()).setSSLEnabled("https".equals(uri.getScheme())).setApiPath(apiPath).build();
    return new CLIConnectionConfig(config, namespace, null);
}
Also used : CLIConnectionConfig(io.cdap.cdap.cli.CLIConnectionConfig) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) URI(java.net.URI) ConnectionConfig(io.cdap.cdap.client.config.ConnectionConfig) CLIConnectionConfig(io.cdap.cdap.cli.CLIConnectionConfig)

Example 8 with CLIConnectionConfig

use of io.cdap.cdap.cli.CLIConnectionConfig in project cdap by caskdata.

the class InstanceURIParserTest method testParse.

@Test
public void testParse() {
    CConfiguration cConf = CConfiguration.create();
    int defaultSSLPort = cConf.getInt(Constants.Router.ROUTER_SSL_PORT);
    int defaultPort = cConf.getInt(Constants.Router.ROUTER_PORT);
    NamespaceId someNamespace = new NamespaceId("nsx");
    InstanceURIParser parser = new InstanceURIParser(cConf);
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", defaultPort, false), parser.parse("somehost"));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", defaultPort, false), parser.parse("http://somehost"));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", defaultSSLPort, true), parser.parse("https://somehost"));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, false), parser.parse("somehost:1234"));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, false), parser.parse("http://somehost:1234"));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, true), parser.parse("https://somehost:1234"));
    Assert.assertEquals(new CLIConnectionConfig(someNamespace, "somehost", 1234, false), parser.parse("somehost:1234/nsx"));
    Assert.assertEquals(new CLIConnectionConfig(someNamespace, "somehost", 1234, false), parser.parse("http://somehost:1234/nsx"));
    Assert.assertEquals(new CLIConnectionConfig(someNamespace, "somehost", 1234, true), parser.parse("https://somehost:1234/nsx"));
}
Also used : CLIConnectionConfig(io.cdap.cdap.cli.CLIConnectionConfig) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Test(org.junit.Test)

Example 9 with CLIConnectionConfig

use of io.cdap.cdap.cli.CLIConnectionConfig in project cdap by caskdata.

the class InstanceURIParserTest method testParseInstanceURI.

@Test
public void testParseInstanceURI() {
    NamespaceId someNamespace = new NamespaceId("nsx");
    InstanceURIParser parser = new InstanceURIParser(null);
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", null, false, ""), parser.parseInstanceURI("somehost", null));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", null, false, ""), parser.parseInstanceURI("http://somehost", null));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", null, true, ""), parser.parseInstanceURI("https://somehost", ""));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, false, ""), parser.parseInstanceURI("somehost:1234", ""));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, false, ""), parser.parseInstanceURI("http://somehost:1234", null));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, true, ""), parser.parseInstanceURI("https://somehost:1234", null));
    Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", null, false, "api/"), parser.parseInstanceURI("somehost/api/", ""));
    Assert.assertEquals(new CLIConnectionConfig(someNamespace, "somehost", 1234, false, ""), parser.parseInstanceURI("http://somehost:1234", "nsx"));
    Assert.assertEquals(new CLIConnectionConfig(someNamespace, "somehost", null, true, "api/"), parser.parseInstanceURI("https://somehost/api", "nsx"));
}
Also used : CLIConnectionConfig(io.cdap.cdap.cli.CLIConnectionConfig) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 10 with CLIConnectionConfig

use of io.cdap.cdap.cli.CLIConnectionConfig in project cdap by caskdata.

the class InstanceURIParser method parse.

public CLIConnectionConfig parse(String uriString) {
    uriString = addScheme(uriString);
    URI uri = URI.create(uriString);
    NamespaceId namespace = (uri.getPath() == null || uri.getPath().isEmpty() || "/".equals(uri.getPath())) ? NamespaceId.DEFAULT : new NamespaceId(uri.getPath().substring(1));
    String hostname = uri.getHost();
    boolean sslEnabled = "https".equals(uri.getScheme());
    int port = uri.getPort();
    if (port == -1) {
        port = sslEnabled ? cConf.getInt(Constants.Router.ROUTER_SSL_PORT) : cConf.getInt(Constants.Router.ROUTER_PORT);
    }
    ConnectionConfig config = ConnectionConfig.builder().setHostname(hostname).setPort(port).setSSLEnabled(sslEnabled).build();
    return new CLIConnectionConfig(config, namespace, null);
}
Also used : CLIConnectionConfig(io.cdap.cdap.cli.CLIConnectionConfig) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) URI(java.net.URI) ConnectionConfig(io.cdap.cdap.client.config.ConnectionConfig) CLIConnectionConfig(io.cdap.cdap.cli.CLIConnectionConfig)

Aggregations

CLIConnectionConfig (io.cdap.cdap.cli.CLIConnectionConfig)14 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)8 Test (org.junit.Test)6 ConnectionConfig (io.cdap.cdap.client.config.ConnectionConfig)4 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)4 URI (java.net.URI)4