List of usage examples for com.mongodb BasicDBObject toString
@SuppressWarnings("deprecation") public String toString()
Returns a JSON serialization of this object
The output will look like: {"a":1, "b":["x","y","z"]} }
From source file:com.owly.srv.RemoteBasicStatMongoDAOImpl.java
License:Apache License
public ArrayList<BasicStat> getMetricDetails(ShortRemoteServerId shortRemoteServer, String typeOfStat, String typeOfMetric, Integer minutesToCheck, Integer numerOfMetrics, long repeatInterval, double value_inteporlation) { getLogger().info("MONGODB : Get a metric in a period of time vbased in minutes"); GregorianCalendar cal = new GregorianCalendar(); Date nowDate = cal.getTime(); cal.add(Calendar.MINUTE, -minutesToCheck); Date beforeDate = cal.getTime(); SimpleDateFormat dtformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); getLogger().info("MONGODB : Get a metric in a period of time starting : " + dtformat.format(beforeDate) + " and ending : " + dtformat.format(nowDate)); //Create a List BasicStat Object ArrayList<BasicStat> ListMetrics = new ArrayList<BasicStat>(); //Create the query BasicDBObject query = new BasicDBObject("NameServer", shortRemoteServer.getName()) .append("ServerIP", shortRemoteServer.getNodeIPAddress()).append("StatType", typeOfStat) .append("StatDate", new BasicDBObject("$gt", beforeDate).append("$lt", nowDate)); getLogger().debug("MONGODB : query =" + query.toString()); //Create the selector BasicDBObject obj = new BasicDBObject("Metrics." + typeOfMetric, true).append("StatDate", true) .append("_id", false); getLogger().debug("MONGODB : selector =" + obj.toString()); //Create the ordeby BasicDBObject orderBy = new BasicDBObject("StatDate", -1); DBCursor cursor = remoteStatCollection.find(query, obj).sort(orderBy); while (cursor.hasNext()) { DBObject cur = cursor.next();/* w w w .ja v a 2 s . c o m*/ BasicStat basicStat = new BasicStat(); //logger.debug("MONGODB : query result"+cur.toString()); //logger.debug("MONGODB : query result"+((BSONObject)cur.get("Metrics")).get(typeOfMetric)); basicStat.setValue((String) ((BSONObject) cur.get("Metrics")).get(typeOfMetric).toString()); basicStat.setDate((Date) cur.get("StatDate")); // Add this object into the list. ListMetrics.add(basicStat); } //Execute the interpolation of data //Execute the interpolation of data ArrayList<BasicStat> AddZerosListMetrics = new ArrayList<BasicStat>(); AddZerosListMetrics = addValuesToList(ListMetrics, repeatInterval, value_inteporlation); Integer numberMetricsCollected = AddZerosListMetrics.size(); getLogger().debug("Number of metricis collected = " + numberMetricsCollected + " and number of metrics to return = " + numerOfMetrics); if (numerOfMetrics < numberMetricsCollected) { // New List of metrics with number of metrics selected in numerOfMetrics //Create a List BasicStat Object ArrayList<BasicStat> AvgListMetrics = new ArrayList<BasicStat>(); double gapBetweenMetrics = (double) numberMetricsCollected / (double) numerOfMetrics; // Number of metrics in the original List between two metrics to exported to the new Genereated List. getLogger().debug("gapBetweenMetrics = " + gapBetweenMetrics); //Initialize first value getLogger().debug("We need to create a new List with Avg"); //getLogger().debug("initialize firts value = " + AddZerosListMetrics.get(0)); AvgListMetrics.add(0, AddZerosListMetrics.get(0)); for (int j = 1; j < numerOfMetrics - 1; j++) { //getLogger().debug("Previous metrics is = "+ (int)Math.round((j-1)*gapBetweenMetrics) + ";Next metric to get = " + (int)Math.round(j*gapBetweenMetrics)); ArrayList<BasicStat> tmpListMetrics = new ArrayList<BasicStat>(); for (int k = ((int) Math.round((j - 1) * gapBetweenMetrics)) + 1; k <= ((int) Math.round(j * gapBetweenMetrics)); k++) { //getLogger().debug("Adding this indexes to the tmp List ="+k); tmpListMetrics.add(AddZerosListMetrics.get(k)); } BasicStat AvgMetric = new BasicStat(); AvgMetric.setAvgBasicStatList(tmpListMetrics); //getLogger().debug("Avg generated is = "+AvgMetric.toString()); AvgListMetrics.add(j, AvgMetric); } //Last value //getLogger().debug("Last metric to get = " + (numberMetricsCollected -1)); AvgListMetrics.add(numerOfMetrics - 1, AddZerosListMetrics.get(numberMetricsCollected - 1)); //Result with Avg getLogger().debug("MONGODB : List obtained" + AvgListMetrics.toString()); cursor.close(); getLogger().info("MONGODB : List obtained"); return AvgListMetrics; } else { getLogger().debug("MONGODB : List obtained" + AddZerosListMetrics.toString()); cursor.close(); getLogger().info("MONGODB : List obtained"); return AddZerosListMetrics; } }
From source file:com.owly.srv.RemoteBasicStatMongoDAOImpl.java
License:Apache License
public ArrayList<BasicStat> getMetricDetails(ShortRemoteServerId shortRemoteServer, String typeOfStat, String typeOfMetric, Date startDate, Date endDate) { getLogger().info("MONGODB : get info of type of stats for an specific server"); getLogger().info(/*from ww w . ja v a 2s . c om*/ "MONGODB : Get a metric in a period of time starting : " + startDate + " and ending : " + endDate); //Create a List BasicStat Object ArrayList<BasicStat> ListMetrics = new ArrayList<BasicStat>(); //Create the query BasicDBObject query = new BasicDBObject("NameServer", shortRemoteServer.getName()) .append("ServerIP", shortRemoteServer.getNodeIPAddress()).append("StatType", typeOfStat) .append("StatDate", new BasicDBObject("$gt", startDate).append("$lt", endDate)); getLogger().debug("MONGODB : query =" + query.toString()); //Create the selector BasicDBObject obj = new BasicDBObject("Metrics." + typeOfMetric, true).append("StatDate", true) .append("_id", false); getLogger().debug("MONGODB : selector =" + obj.toString()); //Create the ordeby BasicDBObject orderBy = new BasicDBObject("StatDate", -1); DBCursor cursor = remoteStatCollection.find(query, obj).sort(orderBy); while (cursor.hasNext()) { DBObject cur = cursor.next(); BasicStat basicStat = new BasicStat(); //logger.debug("MONGODB : query result"+cur.toString()); //logger.debug("MONGODB : query result"+((BSONObject)cur.get("Metrics")).get(typeOfMetric)); basicStat.setValue((String) ((BSONObject) cur.get("Metrics")).get(typeOfMetric).toString()); basicStat.setDate((Date) cur.get("StatDate")); // Add this object into the list. ListMetrics.add(basicStat); } getLogger().debug("MONGODB : List obtained" + ListMetrics.toString()); cursor.close(); getLogger().info("MONGODB : List obtained"); return ListMetrics; }
From source file:com.owly.srv.RemoteBasicStatMongoDAOImpl.java
License:Apache License
public ArrayList<BasicStat> getMetricDetails(ShortRemoteServerId shortRemoteServer, String typeOfStat, String typeOfMetric, Date startDate, Date endDate, Integer numerOfMetrics, long repeatInterval, double value_inteporlation) { getLogger().info("MONGODB : get info of type of stats for an specific server"); getLogger().info(// w w w . j av a2 s . c o m "MONGODB : Get a metric in a period of time starting : " + startDate + " and ending : " + endDate); //Create a List BasicStat Object ArrayList<BasicStat> ListMetrics = new ArrayList<BasicStat>(); //Create the query BasicDBObject query = new BasicDBObject("NameServer", shortRemoteServer.getName()) .append("ServerIP", shortRemoteServer.getNodeIPAddress()).append("StatType", typeOfStat) .append("StatDate", new BasicDBObject("$gt", startDate).append("$lt", endDate)); getLogger().debug("MONGODB : query =" + query.toString()); //Create the selector BasicDBObject obj = new BasicDBObject("Metrics." + typeOfMetric, true).append("StatDate", true) .append("_id", false); getLogger().debug("MONGODB : selector =" + obj.toString()); //Create the ordeby BasicDBObject orderBy = new BasicDBObject("StatDate", -1); DBCursor cursor = remoteStatCollection.find(query, obj).sort(orderBy); while (cursor.hasNext()) { DBObject cur = cursor.next(); BasicStat basicStat = new BasicStat(); //logger.debug("MONGODB : query result"+cur.toString()); //logger.debug("MONGODB : query result"+((BSONObject)cur.get("Metrics")).get(typeOfMetric)); basicStat.setValue((String) ((BSONObject) cur.get("Metrics")).get(typeOfMetric).toString()); basicStat.setDate((Date) cur.get("StatDate")); // Add this object into the list. ListMetrics.add(basicStat); } //Execute the interpolation of data ArrayList<BasicStat> AddZerosListMetrics = new ArrayList<BasicStat>(); AddZerosListMetrics = addValuesToList(ListMetrics, repeatInterval, value_inteporlation); Integer numberMetricsCollected = AddZerosListMetrics.size(); getLogger().debug("Number of metricis collected = " + numberMetricsCollected + " and number of metrics to return = " + numerOfMetrics); if (numerOfMetrics < numberMetricsCollected) { // New List of metrics with number of metrics selected in numerOfMetrics //Create a List BasicStat Object ArrayList<BasicStat> AvgListMetrics = new ArrayList<BasicStat>(); double gapBetweenMetrics = (double) numberMetricsCollected / (double) numerOfMetrics; // Number of metrics in the original List between two metrics to exported to the new Genereated List. getLogger().debug("gapBetweenMetrics = " + gapBetweenMetrics); //Initialize first value getLogger().debug("We need to create a new List with Avg"); //getLogger().debug("initialize firts value = " + AddZerosListMetrics.get(0)); AvgListMetrics.add(0, AddZerosListMetrics.get(0)); for (int j = 1; j < numerOfMetrics - 1; j++) { //getLogger().debug("Previous metrics is = "+ (int)Math.round((j-1)*gapBetweenMetrics) + ";Next metric to get = " + (int)Math.round(j*gapBetweenMetrics)); ArrayList<BasicStat> tmpListMetrics = new ArrayList<BasicStat>(); for (int k = ((int) Math.round((j - 1) * gapBetweenMetrics)) + 1; k <= ((int) Math.round(j * gapBetweenMetrics)); k++) { //getLogger().debug("Adding this indexes to the tmp List ="+k); tmpListMetrics.add(AddZerosListMetrics.get(k)); } BasicStat AvgMetric = new BasicStat(); AvgMetric.setAvgBasicStatList(tmpListMetrics); //getLogger().debug("Avg generated is = "+AvgMetric.toString()); AvgListMetrics.add(j, AvgMetric); } //Last value //getLogger().debug("Last metric to get = " + (numberMetricsCollected -1)); AvgListMetrics.add(numerOfMetrics - 1, AddZerosListMetrics.get(numberMetricsCollected - 1)); //Result with Avg getLogger().debug("MONGODB : List obtained" + AvgListMetrics.toString()); cursor.close(); getLogger().info("MONGODB : List obtained"); return AvgListMetrics; } else { getLogger().debug("MONGODB : List obtained" + AddZerosListMetrics.toString()); cursor.close(); getLogger().info("MONGODB : List obtained"); return AddZerosListMetrics; } }
From source file:com.owly.srv.RemoteBasicStatMongoDAOImpl.java
License:Apache License
public boolean isThereMetricDetails(ShortRemoteServerId shortRemoteServer, String typeOfStat, String typeOfMetric, Integer minutesToCheck) { getLogger().info("MONGODB : Get availability of metrics in a period of time vbased in minutes"); GregorianCalendar cal = new GregorianCalendar(); Date nowDate = cal.getTime(); cal.add(Calendar.MINUTE, -minutesToCheck); Date beforeDate = cal.getTime(); SimpleDateFormat dtformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); getLogger().info("MONGODB : Get a metric in a period of time starting : " + dtformat.format(beforeDate) + " and ending : " + dtformat.format(nowDate)); //Create the query BasicDBObject query = new BasicDBObject("NameServer", shortRemoteServer.getName()) .append("ServerIP", shortRemoteServer.getNodeIPAddress()).append("StatType", typeOfStat) .append("StatDate", new BasicDBObject("$gt", beforeDate).append("$lt", nowDate)); getLogger().debug("MONGODB : query =" + query.toString()); //Create the selector BasicDBObject obj = new BasicDBObject("Metrics." + typeOfMetric, true).append("StatDate", true) .append("_id", false); getLogger().debug("MONGODB : selector =" + obj.toString()); int nb_metrics = remoteStatCollection.find(query, obj).count(); if (nb_metrics > 0) { getLogger().info("MONGODB : Metrics exist in this period of time"); return true; } else {/*from w w w .ja v a 2s .co m*/ getLogger().info("MONGODB : Metrics do not exist in this period of time"); return false; } }
From source file:com.owly.srv.RemoteBasicStatMongoDAOImpl.java
License:Apache License
public boolean isThereMetricDetails(ArrayList<ShortRemoteServerId> listShortRemoteServerId, String typeOfStat, String typeOfMetric, Integer minutesToCheck) { getLogger().info("MONGODB : Get availability of metrics in a period of time vbased in minutes"); GregorianCalendar cal = new GregorianCalendar(); Date nowDate = cal.getTime(); cal.add(Calendar.MINUTE, -minutesToCheck); Date beforeDate = cal.getTime(); SimpleDateFormat dtformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); getLogger().info("MONGODB : Get a metric in a period of time starting : " + dtformat.format(beforeDate) + " and ending : " + dtformat.format(nowDate)); //Varaibles to generat a query with or clause BasicDBObject query = new BasicDBObject(); BasicDBList or = new BasicDBList(); //Check all severs that arrive to the method and generate the or clause Iterator<ShortRemoteServerId> iterator = listShortRemoteServerId.iterator(); while (iterator.hasNext()) { ShortRemoteServerId shortRmt = iterator.next(); BasicDBObject clause = new BasicDBObject("ServerIP", shortRmt.getNodeIPAddress()).append("NameServer", shortRmt.getName());//from w w w . java 2 s . co m or.add(clause); } query = new BasicDBObject("$or", or).append("StatType", typeOfStat).append("StatDate", new BasicDBObject("$gt", beforeDate).append("$lt", nowDate)); getLogger().debug("MONGODB : query =" + query.toString()); //Create the selector BasicDBObject obj = new BasicDBObject("Metrics." + typeOfMetric, true).append("StatDate", true) .append("_id", false); getLogger().debug("MONGODB : selector =" + obj.toString()); int nb_metrics = remoteStatCollection.find(query, obj).count(); if (nb_metrics > 0) { getLogger().info("MONGODB : Metrics exist in this period of time"); return true; } else { getLogger().info("MONGODB : Metrics do not exist in this period of time"); return false; } }
From source file:com.owly.srv.RemoteBasicStatMongoDAOImpl.java
License:Apache License
public boolean isThereMetricDetails(ShortRemoteServerId shortRemoteServer, String typeOfStat, String typeOfMetric, Date startDate, Date endDate) { getLogger().info("MONGODB : get info of type of stats for an specific server"); getLogger().info(//from ww w .ja v a 2 s . c o m "MONGODB : Get a metric in a period of time starting : " + startDate + " and ending : " + endDate); //Create the query BasicDBObject query = new BasicDBObject("NameServer", shortRemoteServer.getName()) .append("ServerIP", shortRemoteServer.getNodeIPAddress()).append("StatType", typeOfStat) .append("StatDate", new BasicDBObject("$gt", startDate).append("$lt", endDate)); getLogger().debug("MONGODB : query =" + query.toString()); //Create the selector BasicDBObject obj = new BasicDBObject("Metrics." + typeOfMetric, true).append("StatDate", true) .append("_id", false); getLogger().debug("MONGODB : selector =" + obj.toString()); int nb_metrics = remoteStatCollection.find(query, obj).count(); if (nb_metrics > 0) { getLogger().info("MONGODB : Metrics exist in this period of time"); return true; } else { getLogger().info("MONGODB : Metrics do not exist in this period of time"); return false; } }
From source file:com.owly.srv.RemoteBasicStatMongoDAOImpl.java
License:Apache License
public boolean isThereMetricDetails(ArrayList<ShortRemoteServerId> listShortRemoteServerId, String typeOfStat, String typeOfMetric, Date startDate, Date endDate) { getLogger().info("MONGODB : get info of type of stats for an specific server"); getLogger().info(// w w w .ja va 2s . c o m "MONGODB : Get a metric in a period of time starting : " + startDate + " and ending : " + endDate); //Varaibles to generat a query with or clause BasicDBObject query = new BasicDBObject(); BasicDBList or = new BasicDBList(); //Check all severs that arrive to the method and generate the or clause Iterator<ShortRemoteServerId> iterator = listShortRemoteServerId.iterator(); while (iterator.hasNext()) { ShortRemoteServerId shortRmt = iterator.next(); BasicDBObject clause = new BasicDBObject("ServerIP", shortRmt.getNodeIPAddress()).append("NameServer", shortRmt.getName()); or.add(clause); } query = new BasicDBObject("$or", or).append("StatType", typeOfStat).append("StatDate", new BasicDBObject("$gt", startDate).append("$lt", endDate)); getLogger().debug("MONGODB : query =" + query.toString()); //Create the selector BasicDBObject obj = new BasicDBObject("Metrics." + typeOfMetric, true).append("StatDate", true) .append("_id", false); getLogger().debug("MONGODB : selector =" + obj.toString()); int nb_metrics = remoteStatCollection.find(query, obj).count(); if (nb_metrics > 0) { getLogger().info("MONGODB : Metrics exist in this period of time"); return true; } else { getLogger().info("MONGODB : Metrics do not exist in this period of time"); return false; } }
From source file:com.owly.srv.RemoteServerMongoDAOImpl.java
License:Apache License
public void deleteRemoteServer(String nameServer, String ipSrv) { logger.info("MONGODB : Drop a remote server based in keys NAme, and IP"); BasicDBObject obj = new BasicDBObject("Name", nameServer).append("NodeIPAddress", ipSrv); Integer numberRecords = remoteSrvCfgCollection.find(obj).count(); if (numberRecords == 1) { logger.info("MONGODB : Data to drop : " + obj.toString()); remoteSrvCfgCollection.remove(obj); logger.info("MONGODB : Remove Server executed"); } else {/*www . j av a2 s . c o m*/ logger.info("MONGODB : Nothing to delete"); } }
From source file:com.owly.srv.RemoteServerMongoDAOImpl.java
License:Apache License
public void insertRemoteServer(RemoteServer remoteServer) { logger.info("MONGODB : Insert Remote Server configuration in DataBase"); BasicDBObject obj = new BasicDBObject("Name", remoteServer.getName()) .append("NodeIPAddress", remoteServer.getNodeIPAddress()) .append("SrvType", remoteServer.getSrvType()).append("ClientPort", remoteServer.getClientPort()) .append("ListTypeOfStats", remoteServer.getListTypeOfStats()) .append("ServerStatus", remoteServer.getServerStatus()).append("Enabled", remoteServer.isEnabled()); logger.info("MONGODB : Data to insert : " + obj.toString()); remoteSrvCfgCollection.insert(obj);//from ww w . j a v a2 s. c o m logger.info("MONGODB : Configuration of Remote Server inserted"); }
From source file:com.owly.srv.RemoteServerMongoDAOImpl.java
License:Apache License
public RemoteServer getRemoteServerbyIP(String IP) { RemoteServer remoteServer = new RemoteServer(); BasicDBObject query = new BasicDBObject("NodeIPAddress", IP); logger.info("MONGODB : findOne for : " + query.toString()); DBObject res = remoteSrvCfgCollection.findOne(query); logger.info("Remote Server obtained in DB : " + res.toString()); remoteServer.setName((String) res.get("Name")); remoteServer.setNodeIPAddress((String) res.get("NodeIPAddress")); remoteServer.setSrvType((String) res.get("SrvType")); remoteServer.setClientPort((Integer) res.get("ClientPort")); remoteServer.setListTypeOfStats((ArrayList<String>) res.get("ListTypeOfStats")); remoteServer.setServerStatus((Boolean) res.get("ServerStatus")); remoteServer.setEnabled((Boolean) res.get("Enabled")); logger.info("Remote Server obtained is : " + remoteServer.toString()); return remoteServer; }