@Override public ObjectMap getDatabaseStatus() { Document dbStatus = mongoManager.get(database, this.configuration).getServerStatus(); try { ObjectMap map = new ObjectMap(getDefaultObjectMapper().writeValueAsString(dbStatus)); return new ObjectMap("ok", map.getInt("ok", 0) > 0); } catch (JsonProcessingException e) { logger.error(e.getMessage(), e); return new ObjectMap(); } }
@Override public void installCatalogDB(Configuration configuration) throws CatalogException { // TODO: Check META object does not exist. Use {@link isCatalogDBReady} // TODO: Check all collections do not exists, or are empty // TODO: Catch DuplicatedKeyException while inserting META object MongoDataStore mongoDataStore = mongoManager.get(database, this.configuration); if (!mongoDataStore.getCollectionNames().isEmpty()) { throw new CatalogException("Database " + database + " already exists with the following collections: " + StringUtils.join(mongoDataStore.getCollectionNames()) + ".\nPlease, remove the database or choose a different one."); } COLLECTIONS_LIST.forEach(mongoDataStore::createCollection); metaDBAdaptor.createIndexes(); metaDBAdaptor.initializeMetaCollection(configuration); }
public MongoDataStore get(String database) { return get(database, builder().init().build()); }
public void clearStorageDB(String storageEngine, String dbName) { if (storageEngine.equalsIgnoreCase("MONGODB")) { logger.info("Cleaning MongoDB {}", dbName); MongoDataStoreManager mongoManager = new MongoDataStoreManager("localhost", 27017); MongoDataStore mongoDataStore = mongoManager.get(dbName); mongoManager.drop(dbName); } else { throw new UnsupportedOperationException(); } }
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()); } } }
public MongoDBVariantFileMetadataDBAdaptor(MongoCredentials credentials, String collectionName) throws UnknownHostException { // Mongo configuration mongoManager = new MongoDataStoreManager(credentials.getDataStoreServerAddresses()); MongoDBConfiguration mongoDBConfiguration = credentials.getMongoDBConfiguration(); db = mongoManager.get(credentials.getMongoDbName(), mongoDBConfiguration); this.collectionName = collectionName; variantFileMetadataConverter = new DocumentToVariantFileMetadataConverter(); }
MongoDataStore mongoDatastore = mongoDataStoreManager.get(database, mongoDBConfiguration);
MongoDataStore mongoDatastore = mongoDataStoreManager.get(database, mongoDBConfiguration);
@Override public boolean check() { try (MongoDataStoreManager mongoManager = new MongoDataStoreManager(getDataStoreServerAddresses())) { MongoDataStore db = mongoManager.get(getMongoDbName(), getMongoDBConfiguration()); MongoIterable<String> strings = db.getDb().listCollectionNames(); int count = 0; for (String string : strings) { count++; } return true; } catch (MongoException e) { //FIXME: Throw IllegalOpenCGACredentialsException ?? return false; } }
mongodbCredentials.getUser(), mongodbCredentials.getPassword()); mongoDataStore = mongoDataStoreManager.get(database, mongoDBConfiguration);
mongodbCredentials.getUser(), mongodbCredentials.getPassword()); mongoDataStore = mongoDataStoreManager.get(database, mongoDBConfiguration);
public VariantMongoDBAdaptor(MongoDataStoreManager mongoManager, MongoCredentials credentials, String variantsCollectionName, StudyConfigurationManager studyConfigurationManager, StorageConfiguration storageConfiguration) throws UnknownHostException { // MongoDB configuration this.closeConnection = false; this.credentials = credentials; this.mongoManager = mongoManager; db = mongoManager.get(credentials.getMongoDbName(), credentials.getMongoDBConfiguration()); collectionName = variantsCollectionName; variantsCollection = db.getCollection(collectionName); this.studyConfigurationManager = studyConfigurationManager; this.storageConfiguration = storageConfiguration; StorageEngineConfiguration storageEngineConfiguration = storageConfiguration.getStorageEngine(MongoDBVariantStorageEngine.STORAGE_ENGINE_ID); this.configuration = storageEngineConfiguration == null || storageEngineConfiguration.getVariant().getOptions() == null ? new ObjectMap() : storageEngineConfiguration.getVariant().getOptions(); queryParser = new VariantMongoDBQueryParser(studyConfigurationManager); NUMBER_INSTANCES.incrementAndGet(); }
@Override public StudyConfigurationManager getStudyConfigurationManager() throws StorageEngineException { ObjectMap options = getOptions(); if (studyConfigurationManager != null) { return studyConfigurationManager; } else if (!options.getString(FileStudyConfigurationAdaptor.STUDY_CONFIGURATION_PATH, "").isEmpty()) { return super.getStudyConfigurationManager(); } else { MongoDataStoreManager mongoDataStoreManager = getMongoDataStoreManager(); MongoDataStore db = mongoDataStoreManager.get( getMongoCredentials().getMongoDbName(), getMongoCredentials().getMongoDBConfiguration()); studyConfigurationManager = new StudyConfigurationManager(new MongoDBVariantStorageMetadataDBAdaptorFactory(db, options)); return studyConfigurationManager; } }
MongoDataStore db = mongoManager.get(catalogManager.getCatalogDatabase()); db.getDb().drop();
@Before public void setUp() throws Exception { clearDB(DB_NAME); MongoDataStoreManager mongoDataStoreManager = getMongoDataStoreManager(DB_NAME); collection = mongoDataStoreManager.get(DB_NAME).getCollection("locks"); mongoLock = new MongoLock(collection); }
default void clearDB(String dbName) throws Exception { MongoCredentials credentials = getVariantStorageEngine().getMongoCredentials(); logger.info("Cleaning MongoDB {}", credentials.getMongoDbName()); try (MongoDataStoreManager mongoManager = new MongoDataStoreManager(credentials.getDataStoreServerAddresses())) { mongoManager.get(credentials.getMongoDbName(), credentials.getMongoDBConfiguration()); mongoManager.drop(credentials.getMongoDbName()); } }
private long simulateStageError(StudyConfiguration studyConfiguration, VariantMongoDBAdaptor dbAdaptor) throws Exception { // Simulate stage error // 1) Set ERROR status on the StudyConfiguration StudyConfigurationManager scm = dbAdaptor.getStudyConfigurationManager(); studyConfiguration.copy(scm.getStudyConfiguration(studyConfiguration.getStudyId(), new QueryOptions()).first()); assertEquals(1, studyConfiguration.getBatches().size()); assertEquals(BatchFileOperation.Status.READY, studyConfiguration.getBatches().get(0).currentStatus()); TreeMap<Date, BatchFileOperation.Status> status = studyConfiguration.getBatches().get(0).getStatus(); status.remove(status.lastKey(), BatchFileOperation.Status.READY); studyConfiguration.getBatches().get(0).addStatus(BatchFileOperation.Status.ERROR); scm.updateStudyConfiguration(studyConfiguration, null); // 2) Remove from files collection MongoDataStore dataStore = getMongoDataStoreManager(DB_NAME).get(DB_NAME); MongoDBCollection files = dataStore.getCollection(MongoDBVariantOptions.COLLECTION_FILES.defaultValue()); System.out.println("Files delete count " + files.remove(new Document(), new QueryOptions()).first().getDeletedCount()); // 3) Clean some variants from the Stage collection. MongoDBCollection stage = dbAdaptor.getStageCollection(studyConfiguration.getStudyId()); long stageCount = stage.count().first(); System.out.println("stage count : " + stageCount); int i = 0; for (Document document : stage.find(new Document(), Projections.include("_id"), null).getResult()) { stage.remove(document, null).first().getDeletedCount(); i++; if (i >= stageCount / 2) { break; } } System.out.println("stage count : " + stage.count().first()); return stageCount; }
MongoDataStore db = mongoManager.get(database); db.getDb().drop();
@Before public void setUp() throws Exception { clearDB(DB_NAME); variantMap = HashMultimap.create(); MongoDataStoreManager mongoDataStoreManager = getMongoDataStoreManager(DB_NAME); collection = mongoDataStoreManager.get(DB_NAME).getCollection("stage"); MongoDBVariantStageLoader loader = new MongoDBVariantStageLoader(collection, 1, 1, false); MongoDBVariantStageConverterTask converterTask = new MongoDBVariantStageConverterTask(null); loader.open(); loader.pre(); writeVariant(converterTask, loader, "10:100:A:T"); writeVariant(converterTask, loader, "11:100:A:T"); writeVariant(converterTask, loader, "1:100:A:T"); writeVariant(converterTask, loader, "2:100:A:T"); writeVariant(converterTask, loader, "22:100:A:T"); writeVariant(converterTask, loader, "X:100:A:T"); loader.post(); loader.close(); }
MongoDataStore db = mongoManager.get(database); db.getDb().drop();