use of org.apache.hive.beeline.hs2connection.UserHS2ConnectionFileParser in project hive by apache.
the class TestUserHS2ConnectionFileParser method testGetLocation1.
/*
* Tests if LOCATION_1 is returned when file is present in the first directory in lookup order
*/
@Test
public void testGetLocation1() throws Exception {
createNewFile(LOCATION_1);
testLocations.add(LOCATION_1);
testLocations.add(LOCATION_2);
testLocations.add(LOCATION_3);
UserHS2ConnectionFileParser testHS2ConfigManager = new UserHS2ConnectionFileParser(testLocations);
Assert.assertTrue("File location " + LOCATION_1 + " was not returned", LOCATION_1.equals(testHS2ConfigManager.getFileLocation()));
}
use of org.apache.hive.beeline.hs2connection.UserHS2ConnectionFileParser in project hive by apache.
the class BeeLine method getDefaultConnectionUrl.
private String getDefaultConnectionUrl(CommandLine cl) throws BeelineConfFileParseException {
Properties mergedConnectionProperties = new Properties();
JdbcConnectionParams jdbcConnectionParams = null;
BeelineSiteParser beelineSiteParser = getUserBeelineSiteParser();
UserHS2ConnectionFileParser userHS2ConnFileParser = getUserHS2ConnFileParser();
Properties userConnectionProperties = new Properties();
if (!userHS2ConnFileParser.configExists() && !beelineSiteParser.configExists()) {
// or beeline-site.xml in the path
return null;
}
if (beelineSiteParser.configExists()) {
String urlFromCommandLineOption = cl.getOptionValue("u");
if (urlFromCommandLineOption != null) {
throw new BeelineSiteParseException("Not using beeline-site.xml since the user provided the url: " + urlFromCommandLineOption);
}
// Get the named url from user specific config file if present
Properties userNamedConnectionURLs = beelineSiteParser.getConnectionProperties();
if (!userNamedConnectionURLs.isEmpty()) {
String urlName = cl.getOptionValue("c");
String jdbcURL = HS2ConnectionFileUtils.getNamedUrl(userNamedConnectionURLs, urlName);
if (jdbcURL != null) {
try {
jdbcConnectionParams = Utils.extractURLComponents(jdbcURL, new Properties());
} catch (JdbcUriParseException e) {
throw new BeelineSiteParseException("Error in parsing jdbc url: " + jdbcURL + " from beeline-site.xml", e);
}
}
}
}
if (userHS2ConnFileParser.configExists()) {
// get the connection properties from user specific config file
userConnectionProperties = userHS2ConnFileParser.getConnectionProperties();
}
if (jdbcConnectionParams != null) {
String userName = cl.getOptionValue("n");
if (userName != null) {
jdbcConnectionParams.getSessionVars().put(JdbcConnectionParams.AUTH_USER, userName);
}
String password = cl.getOptionValue("p");
if (password != null) {
jdbcConnectionParams.getSessionVars().put(JdbcConnectionParams.AUTH_PASSWD, password);
}
String auth = cl.getOptionValue("a");
if (auth != null) {
jdbcConnectionParams.getSessionVars().put(JdbcConnectionParams.AUTH_TYPE, auth);
}
mergedConnectionProperties = HS2ConnectionFileUtils.mergeUserConnectionPropertiesAndBeelineSite(userConnectionProperties, jdbcConnectionParams);
} else {
mergedConnectionProperties = userConnectionProperties;
}
// load the HS2 connection url properties from hive-site.xml if it is present in the classpath
HS2ConnectionFileParser hiveSiteParser = getHiveSiteHS2ConnectionFileParser();
Properties hiveSiteConnectionProperties = hiveSiteParser.getConnectionProperties();
// add/override properties found from hive-site with user-specific properties
for (String key : mergedConnectionProperties.stringPropertyNames()) {
if (hiveSiteConnectionProperties.containsKey(key)) {
debug("Overriding connection url property " + key + " from user connection configuration file");
}
hiveSiteConnectionProperties.setProperty(key, mergedConnectionProperties.getProperty(key));
}
// return the url based on the aggregated connection properties
return HS2ConnectionFileUtils.getUrl(hiveSiteConnectionProperties);
}
use of org.apache.hive.beeline.hs2connection.UserHS2ConnectionFileParser in project hive by apache.
the class TestUserHS2ConnectionFileParser method testGetLocation3.
/*
* Tests if LOCATION_3 is returned when the first file is found is later in lookup order
*/
@Test
public void testGetLocation3() throws Exception {
createNewFile(LOCATION_3);
testLocations.add(LOCATION_1);
testLocations.add(LOCATION_2);
testLocations.add(LOCATION_3);
UserHS2ConnectionFileParser testHS2ConfigManager = new UserHS2ConnectionFileParser(testLocations);
Assert.assertTrue("File location " + LOCATION_3 + " was not returned", LOCATION_3.equals(testHS2ConfigManager.getFileLocation()));
}
use of org.apache.hive.beeline.hs2connection.UserHS2ConnectionFileParser in project hive by apache.
the class TestUserHS2ConnectionFileParser method testGetLocationOrder.
/*
* Tests if it returns the first file present in the lookup order when files are present in the
* lookup order
*/
@Test
public void testGetLocationOrder() throws Exception {
createNewFile(LOCATION_2);
createNewFile(LOCATION_3);
testLocations.add(LOCATION_1);
testLocations.add(LOCATION_2);
testLocations.add(LOCATION_3);
UserHS2ConnectionFileParser testHS2ConfigManager = new UserHS2ConnectionFileParser(testLocations);
Assert.assertTrue("File location " + LOCATION_2 + " was not returned", LOCATION_2.equals(testHS2ConfigManager.getFileLocation()));
}
use of org.apache.hive.beeline.hs2connection.UserHS2ConnectionFileParser in project hive by apache.
the class TestUserHS2ConnectionFileParser method testConfigLocationPathInEtc.
@Test
public void testConfigLocationPathInEtc() throws Exception {
UserHS2ConnectionFileParser testHS2ConfigManager = new UserHS2ConnectionFileParser();
Field locations = testHS2ConfigManager.getClass().getDeclaredField("locations");
locations.setAccessible(true);
Collection<String> locs = (List<String>) locations.get(testHS2ConfigManager);
Assert.assertTrue(locs.contains(UserHS2ConnectionFileParser.ETC_HIVE_CONF_LOCATION + File.separator + UserHS2ConnectionFileParser.DEFAULT_CONNECTION_CONFIG_FILE_NAME));
}
Aggregations