|
55 | 55 | import org.apache.hadoop.hive.common.io.QTestFetchConverter; |
56 | 56 | import org.apache.hadoop.hive.conf.HiveConf; |
57 | 57 | import org.apache.hadoop.hive.conf.HiveConf.ConfVars; |
| 58 | +import org.apache.hadoop.hive.metastore.api.Database; |
| 59 | +import org.apache.hadoop.hive.metastore.api.DatabaseType; |
| 60 | +import org.apache.hadoop.hive.metastore.api.GetDatabaseObjectsRequest; |
| 61 | +import org.apache.hadoop.hive.metastore.api.GetDatabaseObjectsResponse; |
58 | 62 | import org.apache.hadoop.hive.ql.metadata.HiveMetaStoreClientWithLocalCache; |
59 | 63 | import org.apache.hadoop.hive.metastore.conf.MetastoreConf; |
60 | 64 | import org.apache.hadoop.hive.ql.QTestMiniClusters.FsType; |
@@ -355,6 +359,31 @@ public void clearUDFsCreatedDuringTests() throws Exception { |
355 | 359 | } |
356 | 360 | } |
357 | 361 |
|
| 362 | + public void clearConnectorsCreatedInTests() throws Exception { |
| 363 | + if (System.getenv(QTEST_LEAVE_FILES) != null) { |
| 364 | + return; |
| 365 | + } |
| 366 | + conf.set("hive.metastore.filter.hook", "org.apache.hadoop.hive.metastore.DefaultMetaStoreFilterHookImpl"); |
| 367 | + db = Hive.get(conf); |
| 368 | + |
| 369 | + GetDatabaseObjectsRequest request = new GetDatabaseObjectsRequest(); |
| 370 | + request.setPattern("*"); |
| 371 | + GetDatabaseObjectsResponse response = db.getMSC().get_databases_req(request); |
| 372 | + if (response != null && response.getDatabasesSize() > 0) { |
| 373 | + for (Database database : response.getDatabases()) { |
| 374 | + if (database.getType() == DatabaseType.REMOTE) { |
| 375 | + db.dropDatabase(database.getName(), true, true); |
| 376 | + } |
| 377 | + } |
| 378 | + } |
| 379 | + List<String> connectors = db.getAllDataConnectorNames(); |
| 380 | + if (connectors != null) { |
| 381 | + for (String connectorName : connectors) { |
| 382 | + db.dropDataConnector(connectorName, true); |
| 383 | + } |
| 384 | + } |
| 385 | + } |
| 386 | + |
358 | 387 | /** |
359 | 388 | * Clear out any side effects of running tests |
360 | 389 | */ |
@@ -482,6 +511,7 @@ public void clearTestSideEffects() throws Exception { |
482 | 511 | Utilities.clearWorkMap(conf); |
483 | 512 | NotificationEventPoll.shutdown(); |
484 | 513 | QueryResultsCache.cleanupInstance(); |
| 514 | + clearConnectorsCreatedInTests(); |
485 | 515 | clearTablesCreatedDuringTests(); |
486 | 516 | clearUDFsCreatedDuringTests(); |
487 | 517 | clearKeysCreatedInTests(); |
|
0 commit comments