/** * Gets the prepared queries web target. * * @param client the client * @return the prepared queries web target */ private WebTarget getPreparedQueriesWebTarget(Client client) { return client.target(connection.getLensConnectionParams().getBaseConnectionUrl()) .path(connection.getLensConnectionParams().getQueryResourcePath()).path("preparedqueries"); }
/** * Builds the. * * @return the lens connection */ public LensConnection build() { LensConnectionParams params = new LensConnectionParams(); if (baseUrl != null && !baseUrl.isEmpty()) { params.setBaseUrl(baseUrl); } if (database != null && !database.isEmpty()) { params.setDbName(database); } if (user != null && !user.isEmpty()) { params.getSessionVars().put("user.name", user); } if (password != null && !password.isEmpty()) { params.getSessionVars().put("user.pass", password); } return new LensConnection(params); }
public WebTarget getLogWebTarget(Client client) { return client.target(params.getBaseConnectionUrl()).path(params.getLogResourcePath()); }
/** * Gets the session web target. * * @param client the client * @return the session web target */ private WebTarget getSessionWebTarget(Client client) { return client.target(params.getBaseConnectionUrl()).path(params.getSessionResourcePath()); }
/** * Gets the metastore web target. * * @param client the client * @return the metastore web target */ private WebTarget getMetastoreWebTarget(Client client) { return client.target(params.getBaseConnectionUrl()).path(params.getMetastoreResourcePath()); }
/** * Test jdbc with custom host and port and db. */ @Test public void testJDBCWithCustomHostAndPortAndDB() { String uri = "jdbc:lens://myhost:9000/mydb"; LensConnectionParams params = JDBCUtils.parseUrl(uri); Assert.assertEquals(params.getBaseConnectionUrl(), "http://myhost:9000/lensapi", "The base url should be http://myhost:9000/lensapi"); Assert.assertEquals(params.getDbName(), "mydb", "The database should be mydb"); Assert.assertTrue(params.getSessionVars().isEmpty(), "Session Variable list should be empty"); Assert.assertTrue(params.getLensConfs().isEmpty(), "The conf list should be empty"); Assert.assertTrue(params.getLensVars().isEmpty(), "The lens var list should be empty"); } }
LensConnectionParams params = new LensConnectionParams(); Matcher sessMatcher = pattern.matcher(sessVars); while (sessMatcher.find()) { params.getSessionVars().put(sessMatcher.group(1), sessMatcher.group(2)); params.setDbName(dbName); Matcher confMatcher = pattern.matcher(confStr); while (confMatcher.find()) { params.getLensConfs().put(confMatcher.group(1), confMatcher.group(2)); Matcher varMatcher = pattern.matcher(varStr); while (varMatcher.find()) { params.getLensVars().put(varMatcher.group(1), varMatcher.group(2)); baseUriBuilder.port(jdbcUri.getPort()); params.setBaseUrl(baseUriBuilder.build().toString()); return params;
protected WebTarget getMLWebTarget() { Client client = connection.buildClient(); LensConnectionParams connParams = connection.getLensConnectionParams(); String baseURI = connParams.getBaseConnectionUrl(); String mlURI = connParams.getConf().get(LENS_ML_RESOURCE_PATH, DEFAULT_ML_RESOURCE_PATH); return client.target(baseURI).path(mlURI); }
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("username").build(), params.getUser())); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("password").build(), password)); String database = params.getDbName(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("database").build(), database)); params.getSessionConf(), MediaType.APPLICATION_XML_TYPE)); try { Response response = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE)); log.debug("Successfully switched to database {}", params.getDbName()); open.set(true);
public Client buildClient() { ClientBuilder cb = getClientBuilder(params.getConf()); for (Class<?> aClass : params.getRequestFilters()) { cb.register(aClass); } Client client = cb.build(); //Set Timeouts LensClientConfig config = params.getConf(); client.property(ClientProperties.CONNECT_TIMEOUT, config.getInt(CONNECTION_TIMEOUT_MILLIS, DEFAULT_CONNECTION_TIMEOUT_MILLIS)); client.property(ClientProperties.READ_TIMEOUT, config.getInt(READ_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS)); return client; }
/** * Parses the url for property info. * * @param url the url * @param info the info * @return the properties * @throws SQLException the SQL exception */ static Properties parseUrlForPropertyInfo(String url, Properties info) throws SQLException { Properties urlProperties = (info != null) ? new Properties(info) : new Properties(); if (url == null || !url.startsWith(URL_PREFIX)) { throw new SQLException("Invalid connection url :" + url); } LensConnectionParams params = parseUrl(url); // urlProperties.put(HOST_PROPERTY_KEY, params.getHost()); // urlProperties.put(PORT_PROPERTY_KEY, params.getPort()); urlProperties.put(DB_PROPERTY_KEY, params.getDbName()); return urlProperties; }
private void connectToLensServer() { log.debug("Connecting to lens server {}", new LensConnectionParams(conf)); connection = new LensConnection(new LensConnectionParams(conf)); connection.open(password); log.debug("Successfully connected to server {}", connection); pathValidator = new PathValidator(connection.getLensConnectionParams().getSessionConf()); Preconditions.checkNotNull(pathValidator, "Error in initializing Path Validator."); }
public Configuration getConf() { return connection.getLensConnectionParams().getConf(); }
public void closeConnection() { log.debug("Closing lens connection: {}", new LensConnectionParams(conf)); this.connection.close(); }
/** * Test defaults with configuration variables. */ @Test public void testDefaultsWithConfigurationVariables() { String uri = "jdbc:lens:///;username=johndoe;password=blah?conf1=blah1;conf2=blah2#var1=123;var2=456"; LensConnectionParams params = JDBCUtils.parseUrl(uri); Assert.assertEquals(LensClientConfig.DEFAULT_DBNAME_VALUE, params.getDbName(), "The database should be default database"); Assert.assertEquals(LensClientConfig.DEFAULT_SERVER_BASE_URL, params.getBaseConnectionUrl(), "The base url should be default"); Map<String, String> sessionVars = params.getSessionVars(); Assert.assertEquals(2, sessionVars.size(), "You should have two session variable"); Assert.assertEquals("johndoe", sessionVars.get("username"), "The username should be johndoe"); Assert.assertEquals("blah", sessionVars.get("password"), "The password should be blah"); Map<String, String> lensConf = params.getLensConfs(); Assert.assertEquals(2, lensConf.size(), "You should have two configuration variables"); Assert.assertEquals("blah1", lensConf.get("conf1"), "The value for conf1 should be blah1"); Assert.assertEquals("blah2", lensConf.get("conf2"), "The value for conf2 should be blah2"); Map<String, String> lensVars = params.getLensVars(); Assert.assertEquals(2, lensVars.size(), "You should have two lens variables"); Assert.assertEquals("123", lensVars.get("var1"), "The value for var1 should be 123"); Assert.assertEquals("456", lensVars.get("var2"), "The value for var2 should be 456"); }
LensConnectionParams params = new LensConnectionParams(); Matcher sessMatcher = pattern.matcher(sessVars); while (sessMatcher.find()) { params.getSessionVars().put(sessMatcher.group(1), sessMatcher.group(2)); params.setDbName(dbName); Matcher confMatcher = pattern.matcher(confStr); while (confMatcher.find()) { params.getLensConfs().put(confMatcher.group(1), confMatcher.group(2)); Matcher varMatcher = pattern.matcher(varStr); while (varMatcher.find()) { params.getLensVars().put(varMatcher.group(1), varMatcher.group(2)); baseUriBuilder.port(jdbcUri.getPort()); params.setBaseUrl(baseUriBuilder.build().toString()); return params;
/** * Gets the metastore web target. * * @param client the client * @return the metastore web target */ private WebTarget getMetastoreWebTarget(Client client) { return client.target(params.getBaseConnectionUrl()).path(params.getMetastoreResourcePath()); }
/** * Gets the session web target. * * @param client the client * @return the session web target */ private WebTarget getSessionWebTarget(Client client) { return client.target(params.getBaseConnectionUrl()).path(params.getSessionResourcePath()); }
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("username").build(), params.getUser())); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("password").build(), password)); String database = params.getDbName(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("database").build(), database)); params.getSessionConf(), MediaType.APPLICATION_XML_TYPE)); try { Response response = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE)); log.debug("Successfully switched to database {}", params.getDbName()); open.set(true);
public Client buildClient() { ClientBuilder cb = ClientBuilder.newBuilder().register(MultiPartFeature.class).register(MoxyJsonFeature.class) .register(MoxyJsonConfigurationContextResolver.class); for (Class<?> aClass : params.getRequestFilters()) { cb.register(aClass); } Client client = cb.build(); //Set Timeouts LensClientConfig config = params.getConf(); client.property(ClientProperties.CONNECT_TIMEOUT, config.getInt(CONNECTION_TIMEOUT_MILLIS, DEFAULT_CONNECTION_TIMEOUT_MILLIS)); client.property(ClientProperties.READ_TIMEOUT, config.getInt(READ_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS)); return client; }