private void clearCatalog() throws URISyntaxException { List<DataStoreServerAddress> dataStoreServerAddresses = new LinkedList<>(); for (String hostPort : configuration.getCatalog().getDatabase().getHosts()) { if (hostPort.contains(":")) { String[] split = hostPort.split(":"); Integer port = Integer.valueOf(split[1]); dataStoreServerAddresses.add(new DataStoreServerAddress(split[0], port)); } else { dataStoreServerAddresses.add(new DataStoreServerAddress(hostPort, 27017)); } } MongoDataStoreManager mongoManager = new MongoDataStoreManager(dataStoreServerAddresses); // MongoDataStore db = mongoManager.get(catalogConfiguration.getDatabase().getDatabase()); MongoDataStore db = mongoManager.get(getCatalogDatabase()); db.getDb().drop(); // mongoManager.close(catalogConfiguration.getDatabase().getDatabase()); mongoManager.close(getCatalogDatabase()); Path rootdir = Paths.get(UriUtils.createDirectoryUri(configuration.getDataDir())); deleteFolderTree(rootdir.toFile()); if (!configuration.getTempJobsDir().isEmpty()) { Path jobsDir = Paths.get(UriUtils.createDirectoryUri(configuration.getTempJobsDir())); if (jobsDir.toFile().exists()) { deleteFolderTree(jobsDir.toFile()); } } }
MongoDataStore db = mongoManager.get(catalogManager.getCatalogDatabase()); db.getDb().drop(); mongoManager.close(catalogManager.getCatalogDatabase());
/** * Populates the database with dummy data. * * @param configuration Catalog configuration file. * @param force Used in the case where a database already exists with the same name. When force = true, it will override it. * @throws CatalogException when there is already a database with the same name and force is false. * @throws URISyntaxException when there is a problem parsing the URI read from the configuration file. */ public static void createDemoDatabase(Configuration configuration, boolean force) throws CatalogException, URISyntaxException { CatalogManager catalogManager = new CatalogManager(configuration); if (catalogManager.existsCatalogDB()) { if (force) { catalogManager.deleteCatalogDB(force); } else { // throw new CatalogException("A database called " + catalogConfiguration.getDatabase().getDatabase() + " already exists"); throw new CatalogException("A database called " + catalogManager.getCatalogDatabase() + " already exists"); } } catalogManager.installCatalogDB(configuration.getAdmin().getSecretKey(), configuration.getAdmin().getPassword()); try { populateDatabase(catalogManager); } catch (IOException e) { throw new CatalogException(e.getMessage()); } }