List of usage examples for com.mongodb MongoException MongoException
public MongoException(final String msg)
From source file:me.lightspeed7.mongofs.gridfs.GridFSInputFile.java
License:Apache License
/** * This method first calls saveChunks(long) if the file data has not been saved yet. Then it persists the file entry to GridFS. * //www . ja v a 2 s . com * @param chunkSize * Size of chunks for file in bytes. * @throws MongoException */ public void save(final int chunkSize) { if (outputStream != null) { throw new MongoException("cannot mix OutputStream and regular save()"); } // note that chunkSize only changes chunkSize in case we actually save chunks // otherwise there is a risk file and chunks are not compatible if (!savedChunks) { try { saveChunks(chunkSize); } catch (IOException ioe) { throw new MongoException("couldn't save chunks", ioe); } } super.save(); }
From source file:me.lightspeed7.mongofs.gridfs.GridFSInputFile.java
License:Apache License
/** * Saves all data into chunks from configured {@link java.io.InputStream} input stream to GridFS. A non-default chunk size can be * specified. This method does NOT save the file object itself, one must call save() to do so. * //from w w w .ja v a 2 s .com * @param chunkSize * Size of chunks for file in bytes. * @return Number of the next chunk. * @throws IOException * on problems reading the new entry's {@link java.io.InputStream}. * @throws MongoException */ public int saveChunks(final int chunkSize) throws IOException { if (outputStream != null) { throw new MongoException("Cannot mix OutputStream and regular save()"); } if (savedChunks) { throw new MongoException("Chunks already saved!"); } if (chunkSize <= 0) { throw new MongoException("chunkSize must be greater than zero"); } if (this.chunkSize != chunkSize) { this.chunkSize = chunkSize; } // new stuff this.outputStream = generateOutputStream(fs.getChunksCollection()); try { new BytesCopier(inputStream, this.outputStream, this.closeStreamOnPersist).transfer(false); } finally { this.outputStream.close(); } // only write data, do not write file, in case one wants to change metadata return (int) this.getAsLong(MongoFileConstants.chunkCount.name()); }
From source file:net.cit.tetrad.rrd.dao.MongoStatusToMonitorImpl.java
License:Open Source License
public Map<String, Object> readMongoStatus(Mongo mongo, Device device, String command, String databaseName) throws MongoException, Exception { Map<String, Object> deviceStatus = new HashMap<String, Object>(); try {//from w w w .j a v a2s .c o m DB db = mongo.getDB(databaseName); CommandResult commandResult = db.command(command); deviceStatus = JasonUtil.getEntryValue(commandResult, "", deviceStatus); } catch (DataAccessResourceFailureException e) { e.printStackTrace(); throw new MongoException(e.getMessage()); } catch (MongoException e) { // alarm ? e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw e; } finally { } return deviceStatus; }
From source file:net.cit.tetrad.rrd.dao.MongoStatusToMonitorImpl.java
License:Open Source License
public List<Object> readMongoShards(Mongo mongo, String collection, String databaseName) throws MongoException, Exception { List<Object> dboLst = new ArrayList<Object>(); try {/*from w ww. j a v a2 s.co m*/ DB db = mongo.getDB(databaseName); DBCollection dbcollection = db.getCollectionFromString(collection); DBCursor cr = dbcollection.find(); Iterator<DBObject> it = cr.iterator(); DBObject dbo; while (it.hasNext()) { dbo = it.next(); Map<String, Object> deviceStatus = new HashMap<String, Object>(); deviceStatus = JasonUtil.getEntryValue(dbo, "", deviceStatus); dboLst.add(deviceStatus); } } catch (DataAccessResourceFailureException e) { e.printStackTrace(); throw new MongoException(e.getMessage()); } catch (MongoException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw e; } finally { } return dboLst; }
From source file:net.cit.tetrad.rrd.dao.MongoStatusToMonitorImpl.java
License:Open Source License
public List<Object> readMongoChunksGrp(Mongo mongo, String collName, List<Object> dboLst) throws MongoException, Exception { try {//from w ww . j a va 2s . co m DB db = mongo.getDB("config"); DBCollection dbcollection = db.getCollectionFromString("chunks"); DBObject dbo = dbcollection.group(new BasicDBObject("shard", true), new BasicDBObject("ns", collName), new BasicDBObject("nChunks", 0), "function (doc, out) {out.nChunks++;}"); Iterator<String> keys = dbo.keySet().iterator(); BasicDBObject getDbo; while (keys.hasNext()) { String key = keys.next(); getDbo = (BasicDBObject) dbo.get(key); getDbo.put("collName", collName); dboLst.add(getDbo); } } catch (DataAccessResourceFailureException e) { e.printStackTrace(); throw new MongoException(e.getMessage()); } catch (MongoException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw e; } finally { } return dboLst; }
From source file:net.cit.tetrad.rrd.dao.MongoStatusToMonitorImpl.java
License:Open Source License
public Set<String> readMongoCollectionName(Mongo mongo, String dbName) throws MongoException, Exception { Set<String> collNameLst = null; try {// w ww . ja v a 2s .c om DB db = mongo.getDB(dbName); collNameLst = db.getCollectionNames(); } catch (DataAccessResourceFailureException e) { e.printStackTrace(); throw new MongoException(e.getMessage()); } catch (MongoException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw e; } finally { } return collNameLst; }
From source file:net.cit.tetrad.rrd.dao.MongoStatusToMonitorImpl.java
License:Open Source License
public CommandResult getCommandResult(Mongo mongo, Device device, String command, String databaseName) throws MongoException, Exception { CommandResult commandResult = null;/*from w w w.j av a2 s . c om*/ try { DB db = mongo.getDB(databaseName); commandResult = db.command(command); } catch (DataAccessResourceFailureException e) { e.printStackTrace(); throw new MongoException(e.getMessage()); } catch (MongoException e) { // alarm ? e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw e; } finally { } return commandResult; }
From source file:net.cit.tetrad.rrd.dao.MongoStatusToMonitorImpl.java
License:Open Source License
public String getAllServerStatus(Mongo mongo, Device device, String command, String databaseName) throws MongoException, Exception { String objtoString;//from w ww . j a v a2 s. c o m try { DB db = mongo.getDB(databaseName); CommandResult commandResult = db.command(command); objtoString = commandResult.toString(); } catch (DataAccessResourceFailureException e) { e.printStackTrace(); throw new MongoException(e.getMessage()); } catch (MongoException e) { // alarm ? e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw e; } finally { } return objtoString; }
From source file:net.cit.tetrad.rrd.service.TetradRrdDbServiceImpl.java
License:Open Source License
/** * ? rrdDb? ?./*from w ww.j a v a 2s.co m*/ * @param device */ public void insertTetradRrdDb(Mongo mongo, Device device) throws FileNotFoundException { logger.info("====================================="); logger.info("start insrt rrd, Device Id : " + device.getIdx()); logger.debug("ip : " + device.getIp() + ", port : " + device.getPort()); Map<String, Object> dbStatusFromMongo = new HashMap<String, Object>(); // ? ???? status Map<String, Object> serverStatusFromMongo = new HashMap<String, Object>(); // ? ?? status List<DbStatus> dbInfos = new ArrayList<DbStatus>(); double dbObjects = 0; double dbAvgObjSize = 0; double dbDataSize = 0; double dbStorageSize = 0; double dbNumExtents = 0; double dbCount = 0; double dbIndexes = 0; double dbIndexSize = 0; double dbFileSize = 0; double dbNsSizeMB = 0; double dbSumTimeLocked_r = 0; double dbSumTimeLocked_w = 0; try { CommandResult serverResult = mongoStatusToMonitor.getCommandResult(mongo, device, SERVER_STATUS_COMMAND, "admin"); try { // ?? ??? ? List<String> dbNames = mongo.getDatabaseNames(); Pattern patt = Pattern.compile(Config.DBNAME_PATTERN); for (String databaseName : dbNames) { // ? DB RrdDB ? Mongodb? insert Matcher m = patt.matcher(databaseName); if (!m.matches()) { continue; } // ? ???? RrdDb ?? dbStatusFromMongo = insertTetradRrdDb(mongo, device, databaseName, serverResult); DbStatus dbstats = new DbStatus(); BeanUtils.populate(dbstats, dbStatusFromMongo); dbstats.setDb(databaseName); dbstats.setGroupCode(device.getGroupCode()); dbstats.setDeviceCode(device.getIdx()); dbstats.setType(device.getType()); dbCount++; dbObjects += dbstats.getObjects(); dbAvgObjSize += dbstats.getAvgObjSize(); dbDataSize += dbstats.getDataSize(); dbStorageSize += dbstats.getStorageSize(); dbNumExtents += dbstats.getNumExtents(); dbIndexes += dbstats.getIndexes(); dbIndexSize += dbstats.getIndexSize(); dbFileSize += dbstats.getFileSize(); dbNsSizeMB += dbstats.getNsSizeMB(); dbSumTimeLocked_r += dbstats.getLocks_timeLockedMicros_r(); dbSumTimeLocked_w += dbstats.getLocks_timeLockedMicros_w(); daoForMongo.insertDbStatusInfo(dbstats); dbInfos.add(dbstats); } } catch (MongoException e) { e.printStackTrace(); logger.error(e, e); ReInitializeMongoInMemory.reInit(device, e.toString()); } catch (Exception e) { e.printStackTrace(); logger.error(e, e); } try { // ? ? ? DBObject locks = (DBObject) serverResult.get("locks"); serverResult.remove("locks"); JasonUtil.getEntryValue(serverResult, "", serverStatusFromMongo); if (locks != null) { DBObject systemLock = (DBObject) locks.get("."); JasonUtil.getEntryValue(systemLock, "locks_", serverStatusFromMongo); } // ??? ? ? ? . int groupCode = device.getGroupCode(); String uid = device.getUid(); String type = device.getType(); String key = groupCode + "_" + uid + "_" + type; String regtime = TimestampUtil.readCurrentTime(); serverStatusFromMongo.put(SERVERSTATUS_ID, key); serverStatusFromMongo.put(SERVERSTATUS_REGTIME, regtime); serverStatusFromMongo.put(DEVICE_GROUPCODE, device.getGroupCode()); serverStatusFromMongo.put(DEVICECODE, device.getIdx()); serverStatusFromMongo.put(SERVERSTATUS_TYPE, device.getType()); serverStatusFromMongo.put(SERVERSTATUS_IP, device.getIp()); serverStatusFromMongo.put(SERVERSTATUS_PORT, device.getPort()); serverStatusFromMongo.put(SERVERSTATUS_DBOBJECTS, dbObjects); serverStatusFromMongo.put(SERVERSTATUS_DBAVGOBJSIZE, dbAvgObjSize); serverStatusFromMongo.put(SERVERSTATUS_DBDATASIZE, dbDataSize); serverStatusFromMongo.put(SERVERSTATUS_DBSTORAGESIZE, dbStorageSize); serverStatusFromMongo.put(SERVERSTATUS_DBNUMEXTENTS, dbNumExtents); serverStatusFromMongo.put(SERVERSTATUS_DBCOUNT, dbCount); serverStatusFromMongo.put(SERVERSTATUS_DBINDEXES, dbIndexes); serverStatusFromMongo.put(SERVERSTATUS_DBINDEXSIZE, dbIndexSize); serverStatusFromMongo.put(SERVERSTATUS_DBFILESIZE, dbFileSize); serverStatusFromMongo.put(SERVERSTATUS_DBNSSIZEMB, dbNsSizeMB); serverStatusFromMongo.put(SERVERSTATUS_DIFF_DBDATASIZE, dbDataSize); serverStatusFromMongo.put(SERVERSTATUS_DIFF_DBINDEXSIZE, dbIndexSize); serverStatusFromMongo.put(SERVERSTATUS_DBSUMLOCKSLOCKED_R, dbSumTimeLocked_r); serverStatusFromMongo.put(SERVERSTATUS_DBSUMLOCKSLOCKED_W, dbSumTimeLocked_w); InitialRrdService rrdSvc = new InitialRrdService(); rrdSvc.setDataValues(serverStatusFromMongo); rrdSvc.executeServerStatus(device); daoForMongo.setGloballLockPageFaults(serverStatusFromMongo); daoForMongo.setOpcounter(serverStatusFromMongo); // main dashboard ? ?? ServerStatus serverStatusInfo = new ServerStatus(); BeanUtils.populate(serverStatusInfo, serverStatusFromMongo); // main dashboard ? ? ?? serverStatusInfo.setDbInfos(dbInfos); serverStatusInfo.setError(1); daoForMongo.insertServerStatusInfo(serverStatusInfo); // ? ?? String detailKey = key + "_" + regtime; serverStatusInfo.setId(detailKey); daoForMongo.insertDetailServerStatusInfo(serverStatusInfo); // main dashboard / ?? criticalOperation.settingAlarm(device, serverStatusFromMongo); } catch (Exception e) { e.printStackTrace(); logger.error(e, e); } exportXmlIfNecessary(device); } catch (MongoException e) { e.printStackTrace(); logger.error(e, e); insertConnectionTimeoutError(device); } catch (FileNotFoundException e) { e.printStackTrace(); logger.error(e, e); throw e; } catch (Exception e) { e.printStackTrace(); logger.error(e, e); if (mongo == null) { insertConnectionTimeoutError(device); throw new MongoException("Mongo Object is null"); } } logger.info("end insrt rrd"); }
From source file:net.luminis.useradmin.mongodb.MongoDBRepositoryStore.java
License:Apache License
/** * Returns the current database collection. * //from w ww . j a v a2 s . c o m * @return the database collection to work with, cannot be <code>null</code>. * @throws MongoException in case no connection to MongoDB exists. */ private DBCollection getCollection() { DB db = m_mongoDB.getDB(); if (db == null) { throw new MongoException("No connection to MongoDB?!"); } String collName = m_collectionNameRef.get(); if (collName == null) { throw new MongoException("No database collection name?!"); } return db.getCollection(collName); }