use of org.apache.hadoop.hive.metastore.api.DataConnector in project hive by apache.
the class TestHiveMetaStore method testRemoteDatabase.
@Test
public void testRemoteDatabase() throws Throwable {
final String connector_name1 = "test_connector1";
final String mysql_type = "mysql";
final String mysql_url = "jdbc:mysql://nightly1.apache.org:3306/hive1";
final String db_name = "mysql_remote";
final String db2 = "mysql_dup";
try {
DataConnector connector = new DataConnector(connector_name1, mysql_type, mysql_url);
Map<String, String> params = new HashMap<>();
params.put(AbstractJDBCConnectorProvider.JDBC_USERNAME, "hive");
params.put(AbstractJDBCConnectorProvider.JDBC_PASSWORD, "hive");
connector.setParameters(params);
client.createDataConnector(connector);
DataConnector dConn = client.getDataConnector(connector_name1);
new DatabaseBuilder().setName(db_name).setType(DatabaseType.REMOTE).setConnectorName(connector_name1).setRemoteDBName(db_name).create(client, conf);
Database db = client.getDatabase(db_name);
assertNotNull(db);
assertEquals(db.getType(), DatabaseType.REMOTE);
assertEquals(db.getConnector_name(), connector_name1);
assertEquals(db.getRemote_dbname(), db_name);
// new db in hive pointing to same remote db.
new DatabaseBuilder().setName(db2).setType(DatabaseType.REMOTE).setConnectorName(connector_name1).setRemoteDBName(db_name).create(client, conf);
db = client.getDatabase(db2);
assertNotNull(db);
assertEquals(db.getType(), DatabaseType.REMOTE);
assertEquals(db.getConnector_name(), connector_name1);
assertEquals(db.getRemote_dbname(), db_name);
client.dropDataConnector(connector_name1, false, false);
client.dropDatabase(db_name);
client.dropDatabase(db2);
} catch (Throwable e) {
System.err.println(StringUtils.stringifyException(e));
System.err.println("testRemoteDatabase() failed.");
throw e;
}
}
use of org.apache.hadoop.hive.metastore.api.DataConnector in project hive by apache.
the class ObjectStore method getDataConnector.
@Override
public DataConnector getDataConnector(String name) throws NoSuchObjectException {
MDataConnector mdc = null;
boolean commited = false;
try {
openTransaction();
mdc = getMDataConnector(name);
commited = commitTransaction();
} catch (NoSuchObjectException no) {
throw new NoSuchObjectException("Dataconnector named " + name + " does not exist:" + no.getCause());
} finally {
if (!commited) {
rollbackTransaction();
}
}
DataConnector connector = new DataConnector();
connector.setName(mdc.getName());
connector.setType(mdc.getType());
connector.setUrl(mdc.getUrl());
connector.setDescription(mdc.getDescription());
connector.setParameters(convertMap(mdc.getParameters()));
connector.setOwnerName(mdc.getOwnerName());
String type = org.apache.commons.lang3.StringUtils.defaultIfBlank(mdc.getOwnerType(), null);
PrincipalType principalType = (type == null) ? null : PrincipalType.valueOf(type);
connector.setOwnerType(principalType);
connector.setCreateTime(mdc.getCreateTime());
return connector;
}
Aggregations