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"));
}
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);
}
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"));
}
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"));
}
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);
}
Aggregations