/** * Returns a {@link MongoDbProvider} instance. */ public MongoDbProvider getMongoDbProvider() { if (mongoDbProvider == null) { mongoDbProvider = new MongoDbProvider(mongoDBHost, mongoDBPort, mongoDBdatabase); } return mongoDbProvider; }
/** * Returns the {@link DB} with the name that is specified in the properties * file. */ private DB getDatabase() { return getDatabaseForName(dbName); }
/** * Returns a {@link MongoDbDeltaStore} instance created from the settings in this * provider. */ public MongoDbDeltaStore provideMongoDbDeltaStore() { if (mongoDbDeltaStore == null) { mongoDbDeltaStore = new MongoDbDeltaStore(getDatabase()); } return mongoDbDeltaStore; }
/** * Initializes the MongoDB version of a {@link CertPathStoreTestBase}. */ public CertPathStoreTest() throws Exception { MongoDbProvider mongoDbProvider = new MongoDbProvider("127.0.0.1", "27017", "wiab_test"); this.database = mongoDbProvider.getDatabaseForName(TEST_DATABASE); certPathStore = new MongoDbStore(database); }
private void bindAttachmentStore() { if (attachmentStoreType.equalsIgnoreCase("disk")) { bind(AttachmentStore.class).to(FileAttachmentStore.class).in(Singleton.class); } else if (attachmentStoreType.equalsIgnoreCase("mongodb")) { MongoDbProvider mongoDbProvider = getMongoDbProvider(); bind(AttachmentStore.class).toInstance(mongoDbProvider.provideMongoDbStore()); } else { throw new RuntimeException("Invalid attachment store type: '" + attachmentStoreType + "'"); } }
/** * Return the {@link Mongo} instance that we are managing. */ private Mongo getMongo() { if (!isRunning) { start(); } return mongo; }
/** * Returns a {@link DB} instance for the database with the given name * * @param name the name of the database */ @VisibleForTesting DB getDatabaseForName(String name) { return getMongo().getDB(name); }
private void bindDeltaStore() { if (deltaStoreType.equalsIgnoreCase("memory")) { bind(DeltaStore.class).to(MemoryDeltaStore.class).in(Singleton.class); } else if (deltaStoreType.equalsIgnoreCase("file")) { bind(DeltaStore.class).to(FileDeltaStore.class).in(Singleton.class); } else if (deltaStoreType.equalsIgnoreCase("mongodb")) { MongoDbProvider mongoDbProvider = getMongoDbProvider(); bind(DeltaStore.class).toInstance(mongoDbProvider.provideMongoDbDeltaStore()); } else { throw new RuntimeException("Invalid delta store type: '" + deltaStoreType + "'"); } } }
/** * Starts the {@link Mongo} instance and explicitly checks whether it is * actually alive. * * @throws PersistenceStartException if we can't make a connection to MongoDb. */ private void start() { Preconditions.checkState(!isRunning(), "Can't start after a connection has been established"); String host = dbHost; int port = Integer.parseInt(dbPort); try { // New MongoDB Client, see http://docs.mongodb.org/manual/release-notes/drivers-write-concern/ mongo = new MongoClient(host, port); } catch (UnknownHostException e) { throw new PersistenceStartException("Unable to resolve the MongoDb hostname", e); } try { // Check to see if we are alive mongo.getDB(dbName).command("ping"); } catch (MongoException e) { throw new PersistenceStartException("Can't ping MongoDb", e); } isRunning = true; LOG.info("Started MongoDb persistence"); }
/** * Initializes the MongoDB version of a {@link AccountStoreTestBase}. */ public AccountStoreTest() throws Exception { MongoDbProvider mongoDbProvider = new MongoDbProvider("127.0.0.1", "27017", "wiab_test"); this.database = mongoDbProvider.getDatabaseForName(TEST_DATABASE); store = new MongoDbStore(database); }
private void bindAccountStore() { if (accountStoreType.equalsIgnoreCase("memory")) { bind(AccountStore.class).to(MemoryStore.class).in(Singleton.class); } else if (accountStoreType.equalsIgnoreCase("file")) { bind(AccountStore.class).to(FileAccountStore.class).in(Singleton.class); } else if (accountStoreType.equalsIgnoreCase("fake")) { bind(AccountStore.class).to(FakePermissiveAccountStore.class).in(Singleton.class); } else if (accountStoreType.equalsIgnoreCase("mongodb")) { MongoDbProvider mongoDbProvider = getMongoDbProvider(); bind(AccountStore.class).toInstance(mongoDbProvider.provideMongoDbStore()); } else { throw new RuntimeException("Invalid account store type: '" + accountStoreType + "'"); } }
/** * Initializes the MongoDB version of a {@link AttachmentStoreTestBase}. */ public AttachmentStoreTest() throws Exception { MongoDbProvider mongoDbProvider = new MongoDbProvider("127.0.0.1", "27017", "wiab_test"); this.database = mongoDbProvider.getDatabaseForName(TEST_DATABASE); store = new MongoDbStore(database); }
/** * Binds the CertPathStore implementation to the store specified in the * properties. */ private void bindCertPathStore() { if (signerInfoStoreType.equalsIgnoreCase("memory")) { bind(CertPathStore.class).to(MemoryStore.class).in(Singleton.class); } else if (signerInfoStoreType.equalsIgnoreCase("file")) { bind(CertPathStore.class).to(FileSignerInfoStore.class).in(Singleton.class); } else if (signerInfoStoreType.equalsIgnoreCase("mongodb")) { MongoDbProvider mongoDbProvider = getMongoDbProvider(); bind(CertPathStore.class).toInstance(mongoDbProvider.provideMongoDbStore()); } else { throw new RuntimeException( "Invalid certificate path store type: '" + signerInfoStoreType + "'"); } }
/** * Returns a {@link MongoDbStore} instance created from the settings in this * provider. */ public MongoDbStore provideMongoDbStore() { if (mongoDbStore == null) { mongoDbStore = new MongoDbStore(getDatabase()); } return mongoDbStore; }
/** * Initializes the MongoDB version of a {@link CertPathStoreTestBase}. */ public CertPathStoreTest() throws Exception { MongoDbProvider mongoDbProvider = new MongoDbProvider("127.0.0.1", "27017", "wiab_test"); this.database = mongoDbProvider.getDatabaseForName(TEST_DATABASE); certPathStore = new MongoDbStore(database); }
/** * Initializes the MongoDB version of a {@link AccountStoreTestBase}. */ public AccountStoreTest() throws Exception { MongoDbProvider mongoDbProvider = new MongoDbProvider("127.0.0.1", "27017", "wiab_test"); this.database = mongoDbProvider.getDatabaseForName(TEST_DATABASE); store = new MongoDbStore(database); }
/** * Initializes the MongoDB version of a {@link AttachmentStoreTestBase}. */ public AttachmentStoreTest() throws Exception { MongoDbProvider mongoDbProvider = new MongoDbProvider("127.0.0.1", "27017", "wiab_test"); this.database = mongoDbProvider.getDatabaseForName(TEST_DATABASE); store = new MongoDbStore(database); }