protected MongoClient createMongoClient(ServerAddress sa, Optional<MongoCredential> credentials) { if (!credentials.isPresent()) { getMonitor().debug("Connecting to Mongo without authentication"); return new MongoClient(sa); } else { getMonitor() .debug( "Connecting to Mongo with authentication as user '{}'", credentials.get().getUserName()); return new MongoClient(sa, Arrays.asList(credentials.get())); } }
protected MongoClient createMongoClient(ServerAddress sa, Optional<MongoCredential> credentials) { if (!credentials.isPresent()) { getMonitor().debug("Connecting to Mongo without authentication"); return new MongoClient(sa); } else { getMonitor() .debug( "Connecting to Mongo with authentication as user '{}'", credentials.get().getUserName()); return new MongoClient(sa, Arrays.asList(credentials.get())); } }
@Override protected void doDestroy() { getMonitor().debug("Disconnecting from Mongo"); m.close(); db = null; m = null; }
@Override protected void doDestroy() { getMonitor().debug("Disconnecting from Mongo"); m.close(); db = null; m = null; }
@Override protected boolean doInitialize( ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { mongoPort = ConfigUtils.stringToInteger(mongoPortString, 27017); try { connectToMongo(mongoHost, mongoPort, mongoDb, mongoUser, mongoPass); } catch (BaleenException be) { throw new ResourceInitializationException(be); } getMonitor().info("Initialised shared Mongo resource"); return true; }
@Override protected boolean doInitialize( ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { mongoPort = ConfigUtils.stringToInteger(mongoPortString, 27017); try { connectToMongo(mongoHost, mongoPort, mongoDb, mongoUser, mongoPass); } catch (BaleenException be) { throw new ResourceInitializationException(be); } getMonitor().info("Initialised shared Mongo resource"); return true; }
private void connectToMongo( String host, int port, String database, String username, String password) throws BaleenException { try { // Connect to Mongo ServerAddress sa = new ServerAddress(host, port); Optional<MongoCredential> cred = createCredentials(username, password, database); m = createMongoClient(sa, cred); getMonitor().debug("Getting Mongo Database '{}'", db); db = m.getDatabase(database); } catch (Exception e) { throw new BaleenException("Unable to connect to Mongo", e); } }
private void connectToMongo( String host, int port, String database, String username, String password) throws BaleenException { try { // Connect to Mongo ServerAddress sa = new ServerAddress(host, port); Optional<MongoCredential> cred = createCredentials(username, password, database); m = createMongoClient(sa, cred); getMonitor().debug("Getting Mongo Database '{}'", db); db = m.getDatabase(database); } catch (Exception e) { throw new BaleenException("Unable to connect to Mongo", e); } }