List of usage examples for com.mongodb MongoClientOptions builder
public static Builder builder()
From source file:fr.gouv.vitam.mdbes.MainIngestMDBESFromFile.java
License:Open Source License
/** * @param args//from w ww . ja v a 2s . c o m */ public static void main(final String[] args) throws Exception { if (args.length < 6) { System.err.println("need: logfile host database escluster unicast files"); return; } final String networkHost = "192.168.56.102"; GlobalDatas.localNetworkAddress = networkHost; final String log4j = args[0]; PropertyConfigurator.configure(log4j); VitamLoggerFactory.setDefaultFactory(new LogbackLoggerFactory(VitamLogLevel.WARN)); LOGGER = VitamLoggerFactory.getInstance(MainIngestMDBESFromFile.class); // connect to the local database server if (args.length > 1) { host = args[1]; } if (args.length > 2) { database = args[2]; } if (args.length > 3) { esbase = args[3]; } if (args.length > 4) { unicast = args[4]; } if (args.length > 5) { model = args[5]; } if (args.length > 6) { ingest = new String[args.length - 6]; for (int i = 0; i < ingest.length; i++) { ingest[i] = args[6 + i]; } } LOGGER.warn("Start with " + ingest + ":" + host + ":" + database + ":" + esbase + ":" + unicast); MongoDbAccess dbvitam = null; try { final MongoClientOptions options = new MongoClientOptions.Builder().connectionsPerHost(10).build(); mongoClient = new MongoClient(host, options); mongoClient.setReadPreference(ReadPreference.primaryPreferred()); dbvitam = new MongoDbAccess(mongoClient, database, esbase, unicast, true); dbvitam.ensureIndex(); LOGGER.warn(dbvitam.toString()); MainIngestMDBESFromFile.loadt = new AtomicLong(0); MainIngestFile.cptMaip.set(0); runOnce(dbvitam); } catch (final Exception e) { System.err.println("ERROR: " + e.getMessage()); e.printStackTrace(); } finally { // release resources final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2); final ToClean toclean = new ToClean(dbvitam); scheduler.schedule(toclean, 1, TimeUnit.MILLISECONDS); final ToShutdown toShutdown = new ToShutdown(); scheduler.schedule(toShutdown, 5000, TimeUnit.MILLISECONDS); scheduler.awaitTermination(7000, TimeUnit.MILLISECONDS); System.exit(0); } }
From source file:fr.gouv.vitam.mdbes.MainIngestMDBFromFile.java
License:Open Source License
/** * @param args// w w w . j a va2 s . c om */ public static void main(final String[] args) throws Exception { if (args.length < 6) { System.err.println("need: logfile host database escluster unicast files"); return; } final String networkHost = "192.168.56.102"; GlobalDatas.localNetworkAddress = networkHost; final String log4j = args[0]; PropertyConfigurator.configure(log4j); VitamLoggerFactory.setDefaultFactory(new LogbackLoggerFactory(VitamLogLevel.WARN)); LOGGER = VitamLoggerFactory.getInstance(MainIngestMDBFromFile.class); // connect to the local database server if (args.length > 1) { host = args[1]; } if (args.length > 2) { database = args[2]; } if (args.length > 3) { esbase = args[3]; } if (args.length > 4) { unicast = args[4]; } if (args.length > 5) { ingest = new String[args.length - 5]; for (int i = 0; i < ingest.length; i++) { ingest[i] = args[5 + i]; } } LOGGER.warn("Start with " + ingest + ":" + host + ":" + database + ":" + esbase + ":" + unicast); MongoDbAccess dbvitam = null; try { final MongoClientOptions options = new MongoClientOptions.Builder().connectionsPerHost(4).build(); mongoClient = new MongoClient(host, options); mongoClient.setReadPreference(ReadPreference.primaryPreferred()); dbvitam = new MongoDbAccess(mongoClient, database, esbase, unicast, true); dbvitam.ensureIndex(); LOGGER.warn(dbvitam.toString()); MainIngestMDBFromFile.loadt = new AtomicLong(0); MainIngestFile.cptMaip.set(0); runOnce(dbvitam); } catch (final Exception e) { System.err.println("ERROR: " + e.getMessage()); e.printStackTrace(); } finally { // release resources final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2); final ToClean toclean = new ToClean(dbvitam); scheduler.schedule(toclean, 1, TimeUnit.MILLISECONDS); final ToShutdown toShutdown = new ToShutdown(); scheduler.schedule(toShutdown, 5000, TimeUnit.MILLISECONDS); scheduler.awaitTermination(7000, TimeUnit.MILLISECONDS); System.exit(0); } }
From source file:fr.gouv.vitam.mdbes.MainMapReduce.java
License:Open Source License
/** * @param args/*from ww w. ja v a2 s . c o m*/ * @throws Exception */ public static void main(String[] args) throws Exception { if (args.length < 4) { System.err.println( "need: logfile host database esbase unicast [map] [reduce] [output] [options-commaEqualities separated list]"); return; } final String log4j = args[0]; PropertyConfigurator.configure(log4j); VitamLoggerFactory.setDefaultFactory(new LogbackLoggerFactory(VitamLogLevel.DEBUG)); LOGGER = VitamLoggerFactory.getInstance(MainMapReduce.class); final String networkHost = "192.168.56.102"; GlobalDatas.localNetworkAddress = networkHost; // connect to the local database server if (args.length > 1) { host = args[1]; } if (args.length > 2) { database = args[2]; } if (args.length > 3) { esbase = args[3]; } if (args.length > 4) { unicast = args[4]; } if (args.length > 5) { map = args[5]; } if (args.length > 6) { reduce = args[6]; } if (args.length > 7) { output = args[7]; } if (args.length > 8) { options = args[8]; } // connect to the local database server MongoDbAccess dbvitam = null; try { final MongoClientOptions options = new MongoClientOptions.Builder().connectionsPerHost(MAXTHREAD) .build(); mongoClient = new MongoClient(host, options); mongoClient.setReadPreference(ReadPreference.primaryPreferred()); dbvitam = new MongoDbAccess(mongoClient, database, esbase, unicast, false); runOnce(dbvitam); } catch (Exception e) { LOGGER.error(e); } finally { // release resources dbvitam.close(); mongoClient.close(); } }
From source file:fr.gouv.vitam.mdbes.MainPrepareIngestFile.java
License:Open Source License
/** * Will save to a File and to ElasticSearch, then to MongoDB * * @param args/*from w w w . ja v a2s .c o m*/ * logfile eraze/noeraze host database escluster unicast start nbload file fileout limitdepth nbThread mongoimport * stopindex/xx * * <ol> * <li>logfile = Log4J configuration log file</li> * <li>noeraze/index = index will (re)create index, else nothing is done</li> * <li>host = MongoDB host</li> * <li>database = MongoDB database name as VitamLinks</li> * <li>escluster = ElasticSearch cluster name</li> * <li>unicast = ElasticSearch unicast servers list (as in "mdb001, mdb002, mdb003")</li> * <li>start = start index in the bench (will be for instance between 1-1000 start from 100)</li> * <li>nbload = number of iteration from start</li> * <li>file = ingest file</li> * <li>fileout = output saved</li> * <li>limitdepth = from which level the output is saved to the file and not to MongoDB</li> * <li>nbThread = number of thread (default 1)</li> * <li>mongoimport = optional command for import</li> * <li>stopindex/xx = shall we stop index during import in MongoDB</li> * </ol> */ public static void main(final String[] args) throws Exception { if (args.length < 6) { System.err.println( "need: logfile noeraze/index host database escluster unicast start nbload file fileout limitdepth mongoimport stopindex/xx nbThread"); // System.err.println("before was need: logfile nbload files eraze/noeraze start host escluster unicast fileout limitdepth mongoimport 0/1 (1=stop index)"); return; } final String log4j = args[0]; PropertyConfigurator.configure(log4j); VitamLoggerFactory.setDefaultFactory(new LogbackLoggerFactory(VitamLogLevel.WARN)); LOGGER = VitamLoggerFactory.getInstance(MainPrepareIngestFile.class); boolean reindex = false; if (args.length > 1) { reindex = args[1].equals("index"); } if (simulate) { reindex = false; } final String networkHost = "192.168.56.102"; GlobalDatas.localNetworkAddress = networkHost; // connect to the local database server if (args.length > 2) { host = args[2]; } if (args.length > 3) { database = args[3]; } if (args.length > 4) { esbase = args[4]; } if (args.length > 5) { unicast = args[5]; } int realnb = -1; if (args.length > 6) { startFrom = Integer.parseInt(args[6]); } if (args.length > 7) { realnb = Integer.parseInt(args[7]); } if (args.length > 8) { ingest = FileUtil.readFile(args[8]); } if (args.length > 9) { fileout = args[9]; } if (args.length > 10) { final int stoplevel = Integer.parseInt(args[10]); minleveltofile = stoplevel; } if (args.length > 11) { nbThread = Integer.parseInt(args[11]); } if (args.length > 12) { commandMongo = args[12]; } boolean stopindex = false; if (args.length > 13) { stopindex = args[13].equalsIgnoreCase("stopindex"); } LOGGER.debug("Start with " + reindex + ":" + host + ":" + database + ":" + esbase + ":" + unicast); if (args.length > 6) { LOGGER.debug("and " + startFrom + ":" + realnb + ":" + ingest + ":" + fileout + ":" + minleveltofile + ":" + nbThread + ":" + commandMongo + ":" + stopindex); } MongoDbAccess dbvitam = null; try { MAXTHREAD += nbThread; final MongoClientOptions options = new MongoClientOptions.Builder().connectionsPerHost(MAXTHREAD) .build(); mongoClient = new MongoClient(host, options); mongoClient.setReadPreference(ReadPreference.primaryPreferred()); dbvitam = new MongoDbAccess(mongoClient, database, esbase, unicast, reindex); // get a list of the collections in this database and print them out LOGGER.debug(dbvitam.toString()); if (realnb < 0) { return; } // drop all the data in it final ParserIngest parser = new ParserIngest(true); parser.parse(ingest); model = parser.getModel(); if (reindex) { LOGGER.debug("ensureIndex"); dbvitam.ensureIndex(); if (model != null) { LOGGER.debug("updateEsIndex"); dbvitam.updateEsIndex(model); } LOGGER.debug("end Index"); } LOGGER.warn(dbvitam.toString()); final int stepnb = realnb; nb = stepnb; loadt = new AtomicLong(0); cptMaip.set(0); runOnce(dbvitam); } catch (Exception e) { LOGGER.error(e); } finally { // release resources final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2); final ToClean toclean = new ToClean(dbvitam); scheduler.schedule(toclean, 1, TimeUnit.MILLISECONDS); final ToShutdown toShutdown = new ToShutdown(); scheduler.schedule(toShutdown, 5000, TimeUnit.MILLISECONDS); scheduler.awaitTermination(7000, TimeUnit.MILLISECONDS); System.exit(0); } }
From source file:fr.gouv.vitam.mdbes.MainQuery.java
License:Open Source License
/** * @param args/*w w w . j av a 2 s.c o m*/ * @throws Exception */ public static void main(String[] args) throws Exception { if (args.length < 6) { System.err.println("need: logfile host database esbase unicast type filequery"); return; } final String log4j = args[0]; PropertyConfigurator.configure(log4j); VitamLoggerFactory.setDefaultFactory(new LogbackLoggerFactory(VitamLogLevel.DEBUG)); LOGGER = VitamLoggerFactory.getInstance(MainQuery.class); final String networkHost = "192.168.56.102"; GlobalDatas.localNetworkAddress = networkHost; // connect to the local database server if (args.length > 1) { host = args[1]; } if (args.length > 2) { database = args[2]; } if (args.length > 3) { esbase = args[3]; } if (args.length > 4) { unicast = args[4]; } if (args.length > 5) { typeBase = args[5]; } if (args.length > 6) { request = FileUtil.readFile(args[6]); } // connect to the local database server MongoDbAccess dbvitam = null; try { final MongoClientOptions options = new MongoClientOptions.Builder().connectionsPerHost(MAXTHREAD) .build(); mongoClient = new MongoClient(host, options); mongoClient.setReadPreference(ReadPreference.primaryPreferred()); dbvitam = new MongoDbAccess(mongoClient, database, esbase, unicast, false); runOnce(dbvitam); } catch (Exception e) { LOGGER.error(e); } finally { // release resources dbvitam.close(); mongoClient.close(); } }
From source file:fr.gouv.vitam.mdbes.MainQueryBench.java
License:Open Source License
/** * @param args/* ww w . j ava2 s . co m*/ * @throws Exception */ public static void main(String[] args) throws Exception { if (args.length < 7) { System.err.println("need: logfile host database esbase unicast nbload filequeryDepth filequeryTree"); return; } final String log4j = args[0]; PropertyConfigurator.configure(log4j); VitamLoggerFactory.setDefaultFactory(new LogbackLoggerFactory(VitamLogLevel.WARN)); Properties systemProperties = System.getProperties(); systemProperties.put("net.spy.log.LoggerImpl", "net.spy.memcached.compat.log.SLF4JLogger"); System.setProperties(systemProperties); LOGGER = VitamLoggerFactory.getInstance(MainQueryBench.class); final String networkHost = "192.168.56.102"; GlobalDatas.localNetworkAddress = networkHost; // connect to the local database server if (args.length > 1) { host = args[1]; } if (args.length > 2) { database = args[2]; } if (args.length > 3) { esbase = args[3]; } if (args.length > 4) { unicast = args[4]; } nbload = 1; if (args.length > 5) { nbload = Integer.parseInt(args[5]); } if (args.length > 6) { fileDepth = FileUtil.readFile(args[6]); } if (args.length > 7) { fileTree = FileUtil.readFile(args[7]); } // connect to the local database server MongoDbAccess dbvitam = null; try { final MongoClientOptions options = new MongoClientOptions.Builder().connectionsPerHost(MAXTHREAD) .build(); mongoClient = new MongoClient(host, options); mongoClient.setReadPreference(ReadPreference.primaryPreferred()); dbvitam = new MongoDbAccess(mongoClient, database, esbase, unicast, false); List<URI> hosts = new ArrayList<URI>(); hosts.add(new URI("http://192.168.56.110:8091/pools")); LOGGER.warn(" USEMEMCACHED: " + GlobalDatas.USEMEMCACHED + " USELRUCACHE: " + GlobalDatas.USELRUCACHE + " USEREDIS: " + GlobalDatas.USEREDIS + " USECACHE: " + GlobalDatas.SAVERESULT); LOGGER.warn("Cache starting with: " + dbvitam.getCacheSize()); int nbt = 1; int nbloop = 2; if (GlobalDatas.SAVERESULT) { nbloop = 5; } for (int i = 0; i < nbloop; i++) { for (nbt = 1; nbt <= MAXTHREAD; nbt *= 2) { //for (nbt = 1; nbt <= maxThread; nbt += 2) { // for (; nbt <= maxThread; nbt += 100) { nbThread = nbt; MainQueryBench.tree.set(0); MainQueryBench.depthmax.set(0); MainQueryBench.cachetree.set(0); MainQueryBench.cachedepthmax.set(0); MainQueryBench.cachetreecount.set(0); MainQueryBench.cachedepthmaxcount.set(0); MainQueryBench.querydepthmaxcount.set(0); MainQueryBench.querytreecount.set(0); cptMaip.set(0); runOnce(dbvitam); } } } catch (Exception e) { LOGGER.error(e); } finally { // release resources dbvitam.close(); dbvitam.closeFinal(); mongoClient.close(); } }
From source file:fr.gouv.vitam.mdbes.MainSimpleRequest.java
License:Open Source License
/** * @param args/*from ww w. j a v a 2 s .c o m*/ * @throws Exception */ public static void main(String[] args) throws Exception { if (args.length < 6) { System.err.println("need: logfile host database esbase unicast type query"); return; } final String log4j = args[0]; PropertyConfigurator.configure(log4j); VitamLoggerFactory.setDefaultFactory(new LogbackLoggerFactory(VitamLogLevel.DEBUG)); LOGGER = VitamLoggerFactory.getInstance(MainSimpleRequest.class); final String networkHost = "192.168.56.102"; GlobalDatas.localNetworkAddress = networkHost; // connect to the local database server if (args.length > 1) { host = args[1]; } if (args.length > 2) { database = args[2]; } if (args.length > 3) { esbase = args[3]; } if (args.length > 4) { unicast = args[4]; } if (args.length > 5) { request = args[5]; } if (args.length > 6) { ids = args[6]; } // connect to the local database server MongoDbAccess dbvitam = null; try { final MongoClientOptions options = new MongoClientOptions.Builder().connectionsPerHost(MAXTHREAD) .build(); mongoClient = new MongoClient(host, options); mongoClient.setReadPreference(ReadPreference.primaryPreferred()); dbvitam = new MongoDbAccess(mongoClient, database, esbase, unicast, false); runOnce(dbvitam); } catch (Exception e) { LOGGER.error(e); } finally { // release resources dbvitam.close(); mongoClient.close(); } }
From source file:fr.gouv.vitam.mdbes.QueryBenchJavaSampler.java
License:Open Source License
@Override public void setupTest(JavaSamplerContext arg0) { // called when the test is startup but only for global argument, not specific ones for (ARG arg : ARG.values()) { if (arg0.containsParameter(arg.name())) { switch (arg) { case maxes: maxES = arg0.getIntParameter(arg.name()); GlobalDatas.limitES = maxES; break; case modelfile: modelfile = arg0.getParameter(arg.name()).trim(); try { modelQuery = FileUtil.readFile(modelfile); } catch (IOException e) { e.printStackTrace(); modelQuery = null;/* w w w .ja v a2s .c om*/ } break; case start: start = arg0.getIntParameter(arg.name()); current = start; break; case stop: stop = arg0.getIntParameter(arg.name()); break; case serie: serie = arg0.getParameter(arg.name()).trim(); default: break; } } } if (initialized) { queryBench = new QueryBench(false); try { queryBench.prepareParse(modelQuery); } catch (InvalidParseOperationException e) { e.printStackTrace(); } model = queryBench.getModel(); return; } // called when the test is startup but only for global argument, not specific ones for (ARG arg : ARG.values()) { if (arg0.containsParameter(arg.name())) { switch (arg) { case esclustername: esclustername = arg0.getParameter(arg.name()).trim(); break; case unicast: unicast = arg0.getParameter(arg.name()).trim(); ; break; case maxconn: maxconn = arg0.getIntParameter(arg.name()); break; case mongobase: mongobase = arg0.getParameter(arg.name()).trim(); break; case mongohost: mongohost = arg0.getParameter(arg.name()).trim(); break; default: break; } } } lock.lock(); try { if (modelQuery != null) { try { if (mongoClient == null) { options = new MongoClientOptions.Builder().connectionsPerHost(maxconn).build(); mongoClient = new MongoClient(mongohost, options); mongoClient.setReadPreference(ReadPreference.primaryPreferred()); } dbvitam = new MongoDbAccess(mongoClient, mongobase, esclustername, unicast, false); queryBench = new QueryBench(false); queryBench.prepareParse(modelQuery); model = queryBench.getModel(); initialized = true; } catch (UnknownHostException e) { e.printStackTrace(); } catch (InvalidParseOperationException e) { e.printStackTrace(); } catch (InvalidUuidOperationException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (!initialized) { if (dbvitam != null) { dbvitam.close(); dbvitam = null; } if (mongoClient != null) { mongoClient.close(); mongoClient = null; } } } } } finally { lock.unlock(); } }
From source file:fr.wseduc.gridfs.GridFSPersistor.java
License:Apache License
public void start() { super.start(); address = getOptionalStringConfig("address", "vertx.gridfspersistor"); host = getOptionalStringConfig("host", "localhost"); port = getOptionalIntConfig("port", 27017); dbName = getOptionalStringConfig("db_name", "default_db"); username = getOptionalStringConfig("username", null); password = getOptionalStringConfig("password", null); ReadPreference readPreference = ReadPreference .valueOf(getOptionalStringConfig("read_preference", "primary")); int poolSize = getOptionalIntConfig("pool_size", 10); boolean autoConnectRetry = getOptionalBooleanConfig("auto_connect_retry", true); int socketTimeout = getOptionalIntConfig("socket_timeout", 60000); boolean useSSL = getOptionalBooleanConfig("use_ssl", false); JsonArray seedsProperty = config.getArray("seeds"); bucket = getOptionalStringConfig("bucket", "fs"); try {//from w ww.j a v a2 s . c o m MongoClientOptions.Builder builder = new MongoClientOptions.Builder(); builder.connectionsPerHost(poolSize); builder.autoConnectRetry(autoConnectRetry); builder.socketTimeout(socketTimeout); builder.readPreference(readPreference); if (useSSL) { builder.socketFactory(SSLSocketFactory.getDefault()); } if (seedsProperty == null) { ServerAddress address = new ServerAddress(host, port); mongo = new MongoClient(address, builder.build()); } else { List<ServerAddress> seeds = makeSeeds(seedsProperty); mongo = new MongoClient(seeds, builder.build()); } db = mongo.getDB(dbName); if (username != null && password != null) { db.authenticate(username, password.toCharArray()); } } catch (UnknownHostException e) { logger.error("Failed to connect to mongo server", e); } eb.registerHandler(address, this); eb.registerHandler(address + ".json", new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> message) { String action = message.body().getString("action", ""); switch (action) { case "write": writeTo(message); break; default: sendError(message, "Invalid action"); } } }); }
From source file:fr.wseduc.resizer.GridFsFileAccess.java
License:Apache License
public GridFsFileAccess(String host, int port, String dbName, String username, String password, int poolSize) throws UnknownHostException { MongoClientOptions.Builder builder = new MongoClientOptions.Builder(); builder.connectionsPerHost(poolSize); ServerAddress address = new ServerAddress(host, port); mongo = new MongoClient(address, builder.build()); db = mongo.getDB(dbName);/*from w ww. j a va2s . c o m*/ if (username != null && password != null) { db.authenticate(username, password.toCharArray()); } }