private void initializeConfigServer(IMongodConfig config) throws Exception { if (!config.isConfigServer()) { throw new Exception( "Mongo configuration is not a defined for a config server."); } MongodStarter starter = MongodStarter.getDefaultInstance(); MongodExecutable mongodExe = starter.prepare(config); MongodProcess process = mongodExe.start(); mongodProcessList.add(process); }
if (!mongoConfig.replication().getReplSetName().equals(replicaName)) { throw new Exception( "Replica set name must match in mongo configuration"); .connectTimeout(10) .build(); MongoClient mongo = new MongoClient(new ServerAddress(mongoConfigList.get(0).net() .getServerAddress().getHostName(), mongoConfigList.get(0).net() .getPort()), mo); DB mongoAdminDB = mongo.getDB(ADMIN_DATABASE_NAME); DBObject host = new BasicDBObject(); host.put("_id", i++); host.put("host", mongoConfig.net().getServerAddress().getHostName() + ":" + mongoConfig.net().getPort()); members.add(host);
if (config.params() != null && !config.params().isEmpty()) { for (Object key : config.params().keySet()) { ret.addAll(asList(format("--setParameter"), format("%s=%s", key, config.params().get(key)))); if (config.args() != null && !config.args().isEmpty()) { for (String key : config.args().keySet()) { ret.add(key); String val = config.args().get(key); if (val != null && !val.isEmpty()) { ret.add(val); if (config.cmdOptions().auth()) { ret.add("--auth"); } else { ret.add("--noauth"); if (config.cmdOptions().useNoPrealloc()) { ret.add("--noprealloc"); if (config.cmdOptions().useSmallFiles()) { ret.add("--smallfiles"); if (config.cmdOptions().useNoJournal() && !config.isConfigServer()) { ret.add("--nojournal"); if (config.cmdOptions().master()) { ret.add("--master"); if (config.version().enabled(Feature.STORAGE_ENGINE)) {
@Override protected void onBeforeProcess(IRuntimeConfig runtimeConfig) throws IOException { super.onBeforeProcess(runtimeConfig); IMongodConfig config = getConfig(); File tmpDbDir; if (config.replication().getDatabaseDir() != null) { tmpDbDir = Files.createOrCheckDir(config.replication().getDatabaseDir()); } else { tmpDbDir = Files.createTempDir(PropertyOrPlatformTempDir.defaultInstance(),"embedmongo-db"); dbDirIsTemp = true; } this.dbDir = tmpDbDir; }
public Net net() { return mongodConfig.net(); }
if (!mongoConfig.replication().getReplSetName().equals(replicaName)) { throw new Exception( "Replica set name must match in mongo configuration"); .connectTimeout(10) .build(); MongoClient mongo = new MongoClient(new ServerAddress(mongoConfigList.get(0).net() .getServerAddress().getHostName(), mongoConfigList.get(0).net() .getPort()), mo); DB mongoAdminDB = mongo.getDB(ADMIN_DATABASE_NAME); DBObject host = new BasicDBObject(); host.put("_id", i++); host.put("host", mongoConfig.net().getServerAddress().getHostName() + ":" + mongoConfig.net().getPort()); members.add(host);
private void initializeConfigServer(IMongodConfig config) throws Exception { if (!config.isConfigServer()) { throw new Exception( "Mongo configuration is not a defined for a config server."); } MongodStarter starter = MongodStarter.getDefaultInstance(); MongodExecutable mongodExe = starter.prepare(config); MongodProcess process = mongodExe.start(); mongodProcessList.add(process); }
public Net net() { return mongodConfig.net(); }
/** * @return A new Mongo client that is connected to the embedded MongoDB Server. * @throws UnknownHostException The hostname used was unknown. * @throws MongoException Couldn't create the client. */ public MongoClient newMongoClient() throws UnknownHostException, MongoException { return new MongoClient(new ServerAddress(mongodProcess.getConfig().net().getServerAddress(), mongodProcess.getConfig().net().getPort())); }
/** * @return A new Mongo client that is connected to the embedded MongoDB Server. * @throws UnknownHostException The hostname used was unknown. * @throws MongoException Couldn't create the client. */ public MongoClient newMongoClient() throws UnknownHostException, MongoException { return new MongoClient(new ServerAddress(mongodProcess.getConfig().net().getServerAddress(), mongodProcess.getConfig().net().getPort())); }
/** * @return The embedded Mongo DB's hostname. * @throws UnknownHostException The host couldn't be presented as a String. */ public String getMongoHostname() throws UnknownHostException { return EmbeddedMongoSingleton.getMongodConfig().net().getServerAddress().getHostAddress(); }
/** * @return The embedded Mongo DB's port. */ public int getMongoPort() { return EmbeddedMongoSingleton.getMongodConfig().net().getPort(); } }
@Configuration @EnableAutoConfiguration(exclude = { EmbeddedMongoAutoConfiguration.class }) public class MongoConfiguration { @Autowired private Environment environment; @Autowired private MongoProperties properties; @Autowired(required = false) private MongoClientOptions options; @Autowired private IMongodConfig mongoConfig; @Bean public MongoClient mongo() throws Exception { properties.setPort(mongoConfig.net().getPort()); return properties.createMongoClient(this.options, this.environment); } }
/** * @return the port on which the db listens. */ public int getPort() { return mongodProcess.getConfig().net().getPort(); }
/** * @return the IP on which the db was bound. */ public String getBindIp() { return mongodProcess.getConfig().net().getBindIp(); }