List of usage examples for com.mongodb BasicDBList BasicDBList
BasicDBList
From source file:nl.vu.psy.relic.persistence.mongo.MongoMapper.java
License:Open Source License
public static DBObject resolverDescriptorToDBObject(ResolverDescriptor r) { DBObject result = new BasicDBObject(); DBObject resolverDescriptor = new BasicDBObject(); resolverDescriptor.put("identifier", r.getIdentifier()); resolverDescriptor.put("environment", r.getEnvironment()); BasicDBList properties = new BasicDBList(); for (Object s : r.getProperties().keySet()) { BasicDBObject prop = new BasicDBObject(); String key = (String) s; prop.put(key, r.getProperty(key)); properties.add(prop);// w w w . jav a2 s. c o m } resolverDescriptor.put("properties", properties); result.put("resolver", resolverDescriptor); return result; }
From source file:nl.vu.psy.rite.persistence.mongo.MongoInfoMapper.java
License:Open Source License
public static DBObject clientInfoToDBObject(ClientInfo ro, boolean listWorkingDir, boolean outputFiles) { DBObject result = new BasicDBObject(); DBObject innerFields = new BasicDBObject(); innerFields.put("clientid", ro.getClientId()); innerFields.put("clientstart", TimeStamp.dateToString(ro.getClientStart())); innerFields.put("clienthost", ro.getClientHost()); innerFields.put("workingdirectory", ro.getWorkingDirectory().getAbsolutePath()); BasicDBList fileList = new BasicDBList(); if (listWorkingDir) { String[] list = ro.getWorkingDirectory().list(); if (list != null) { for (String f : list) { fileList.add(f);/*ww w . ja v a 2s . co m*/ } } else { fileList.add( "File.list() returned null for directory " + ro.getWorkingDirectory().getAbsolutePath()); } } else { fileList.add("Listing is turned off."); } innerFields.put("directorylisting", fileList); innerFields.put("recipeid", ro.getRecipeId()); innerFields.put("recipestart", TimeStamp.dateToString(ro.getRecipeStart())); innerFields.put("recipeend", TimeStamp.dateToString(ro.getRecipeEnd())); if (outputFiles) { innerFields.put("stdout", fileToString(ro.getStandardOut())); innerFields.put("stderr", fileToString(ro.getStandardError())); } else { innerFields.put("stdout", "Listing is turned off."); innerFields.put("stderr", "Listing is turned off."); } innerFields.put("recipefailed", ro.hasRecipeFailed()); result.put("clientinfo", innerFields); return result; }
From source file:nl.vu.psy.rite.persistence.mongo.MongoRecipeMapper.java
License:Open Source License
public static DBObject recipeToDBObject(Recipe r) { DBObject result = new BasicDBObject(); result.put("recipe", r.getIdentifier()); result.put("clientid", r.getClientId()); result.put("timestamp", TimeStamp.dateToString(r.getTimeStamp())); result.put("timeout", r.getTimeout()); result.put("completed", r.hasCompleted()); result.put("failed", r.hasFailed()); result.put("resetontimeout", r.resetOnTimeout()); result.put("resetonfailure", r.resetOnFailure()); BasicDBList steps = new BasicDBList(); for (Step s : r) { steps.add(stepToDBObject(s));//from ww w . ja va 2 s. c o m } result.put("steps", steps); return result; }
From source file:nl.vu.psy.rite.persistence.mongo.MongoRecipeMapper.java
License:Open Source License
private static DBObject stepToDBObject(Step s) { DBObject result = new BasicDBObject(); result.put("step", s.getIdentifier()); BasicDBList operations = new BasicDBList(); for (Operation o : s) { operations.add(operationToDBObject(o)); }/*ww w . j av a 2 s.c o m*/ result.put("operations", operations); return result; }
From source file:org.alfresco.bm.api.AbstractRestResource.java
License:Open Source License
/** * Find and mask property values.//from ww w . j ava 2 s . c om * <p/> * Properties will be searched for deeply. * * @param obj the object to modify */ public static DBObject maskValues(DBObject dbObject) { if (dbObject instanceof BasicDBList) { BasicDBList objListOrig = (BasicDBList) dbObject; // Copy entries to a new list BasicDBList newObjList = new BasicDBList(); for (Object origListObjT : objListOrig) { DBObject origListObj = (DBObject) origListObjT; // Mask any values DBObject newListObj = maskValues(origListObj); newObjList.add(newListObj); } // Done return newObjList; } else if (dbObject.containsField(FIELD_MASK)) { boolean mask = Boolean.parseBoolean((String) dbObject.get(FIELD_MASK)); if (mask) { DBObject newObj = copyDBObject(dbObject); // We have a copy to play with newObj.put(FIELD_DEFAULT, MASK); if (dbObject.get(FIELD_VALUE) != null) { newObj.put(FIELD_VALUE, MASK); } return newObj; } else { return dbObject; } } else if (dbObject.containsField(FIELD_PROPERTIES)) { // There are properties BasicDBList propsObj = (BasicDBList) dbObject.get(FIELD_PROPERTIES); BasicDBList newPropsObj = (BasicDBList) maskValues(propsObj); // Copy DBObject newObj = copyDBObject(dbObject); newObj.put(FIELD_PROPERTIES, newPropsObj); // Done return newObj; } else { // Not a list and does not contain the mask field return dbObject; } }
From source file:org.alfresco.bm.api.v1.ResultsRestAPI.java
License:Open Source License
@GET @Path("/eventNames") @Produces(MediaType.APPLICATION_JSON)/*from ww w . jav a 2s . c om*/ public String getEventResultEventNames() { final BasicDBList events = new BasicDBList(); // always add the "all events" name in the first position events.add(ALL_EVENT_NAMES); // distinct get all recorded event names from Mongo List<String> eventNames = getResultService().getEventNames(); for (String eventName : eventNames) { events.add(eventName); } return JSON.serialize(events); }
From source file:org.alfresco.bm.api.v1.ResultsRestAPI.java
License:Open Source License
@GET @Path("/allEventsFilterName") @Produces(MediaType.APPLICATION_JSON)//ww w .j a v a2 s .co m public String getAllEventsFilterName() { final BasicDBList events = new BasicDBList(); events.add(ALL_EVENT_NAMES); return JSON.serialize(events); }
From source file:org.alfresco.bm.api.v1.ResultsRestAPI.java
License:Open Source License
/** * Retrieve an approximate number of results, allowing for a smoothing factor * (<a href=http://en.wikipedia.org/wiki/Moving_average#Simple_moving_average>Simple Moving Average</a>) - * the number of data results to including in the moving average. * //from w w w .ja v a 2 s .co m * @param fromTime the approximate time to start from * @param timeUnit the units of the 'reportPeriod' (default SECONDS). See {@link TimeUnit}. * @param reportPeriod how often a result should be output. This is expressed as a multiple of the 'timeUnit'. * @param smoothing the number of results to include in the Simple Moving Average calculations * @param chartOnly <tt>true</tt> to filter out results that are not of interest in performance charts * * @return JSON representing the event start time (x-axis) and the smoothed average execution time * along with data such as the events per second, failures per second, etc. */ @GET @Path("/ts") @Produces(MediaType.APPLICATION_JSON) public String getTimeSeriesResults(@DefaultValue("0") @QueryParam("fromTime") long fromTime, @DefaultValue("SECONDS") @QueryParam("timeUnit") String timeUnit, @DefaultValue("1") @QueryParam("reportPeriod") long reportPeriod, @DefaultValue("1") @QueryParam("smoothing") int smoothing, @DefaultValue("true") @QueryParam("chartOnly") boolean chartOnly) { if (logger.isDebugEnabled()) { logger.debug("Inbound: " + "[test:" + test + ",fromTime:" + fromTime + ",timeUnit:" + timeUnit + ",reportPeriod:" + reportPeriod + ",smoothing:" + smoothing + ",chartOnly:" + chartOnly + "]"); } if (reportPeriod < 1) { throwAndLogException(Status.BAD_REQUEST, "'reportPeriod' must be 1 or more."); } if (smoothing < 1) { throwAndLogException(Status.BAD_REQUEST, "'smoothing' must be 1 or more."); } TimeUnit timeUnitEnum = null; try { timeUnitEnum = TimeUnit.valueOf(timeUnit.toUpperCase()); } catch (Exception e) { // Invalid time unit throwAndLogException(Status.BAD_REQUEST, e); } final ResultService resultService = getResultService(); // Calculate the window size long reportPeriodMs = timeUnitEnum.toMillis(reportPeriod); long windowSize = reportPeriodMs * smoothing; // This is just too convenient an API final BasicDBList events = new BasicDBList(); ResultHandler handler = new ResultHandler() { @Override public boolean processResult(long fromTime, long toTime, Map<String, DescriptiveStatistics> statsByEventName, Map<String, Integer> failuresByEventName) throws Throwable { for (Map.Entry<String, DescriptiveStatistics> entry : statsByEventName.entrySet()) { String eventName = entry.getKey(); DescriptiveStatistics stats = entry.getValue(); Integer failures = failuresByEventName.get(eventName); if (failures == null) { logger.error("Found null failure count: " + entry); // Do nothing with it and stop return false; } // Per second double numPerSec = (double) stats.getN() / ((double) (toTime - fromTime) / 1000.0); double failuresPerSec = (double) failures / ((double) (toTime - fromTime) / 1000.0); // Push into an object DBObject eventObj = BasicDBObjectBuilder.start().add("time", toTime).add("name", eventName) .add("mean", stats.getMean()).add("min", stats.getMin()).add("max", stats.getMax()) .add("stdDev", stats.getStandardDeviation()).add("num", stats.getN()) .add("numPerSec", numPerSec).add("fail", failures).add("failPerSec", failuresPerSec) .get(); // Add the object to the list of events events.add(eventObj); } // Go for the next result return true; } }; try { // Get all the results resultService.getResults(handler, fromTime, windowSize, reportPeriodMs, chartOnly); // Muster into JSON String json = events.toString(); // Done if (logger.isDebugEnabled()) { int jsonLen = json.length(); if (jsonLen < 500) { logger.debug("Outbound: " + json); } else { logger.debug("Outbound: " + json.substring(0, 250) + " ... " + json.substring(jsonLen - 250, jsonLen)); } } return json; } catch (WebApplicationException e) { throw e; } catch (Exception e) { throwAndLogException(Status.INTERNAL_SERVER_ERROR, e); return null; } }
From source file:org.alfresco.bm.api.v1.ResultsRestAPI.java
License:Open Source License
@GET @Path("/eventResults") @Produces(MediaType.APPLICATION_JSON)//from w w w . j ava2 s . com public String getEventResults( @DefaultValue(ALL_EVENT_NAMES) @QueryParam("filterEventName") String filterEventName, @DefaultValue("All") @QueryParam("filterSuccess") String filterSuccess, @DefaultValue("0") @QueryParam("skipResults") int skipResults, @DefaultValue("10") @QueryParam("numberOfResults") int numberOfResults) { EventResultFilter filter = getFilter(filterSuccess); final ResultService resultService = getResultService(); String nameFilterString = filterEventName.equals(ALL_EVENT_NAMES) ? "" : filterEventName; // get event details List<EventDetails> details = resultService.getEventDetails(filter, nameFilterString, skipResults, numberOfResults); // serialize back .... BasicDBList retList = new BasicDBList(); for (EventDetails detail : details) { retList.add(detail.toDBObject()); } return JSON.serialize(retList); }
From source file:org.alfresco.bm.test.mongo.MongoTestDAO.java
License:Open Source License
/** * Retrieve the data for given test/*from w ww . j a va 2 s . c o m*/ * * @param testObjId * the ID of the test * @param includeProperties * <tt>true</tt> to flesh out the properties * @return the test object or <tt>null</tt> if not found */ public DBObject getTest(ObjectId testObjId, boolean includeProperties) { DBObject queryObj = QueryBuilder.start(FIELD_ID).is(testObjId).get(); BasicDBObjectBuilder fieldsObjBuilder = BasicDBObjectBuilder.start(FIELD_NAME, 1).add(FIELD_VERSION, true) .add(FIELD_DESCRIPTION, true).add(FIELD_RELEASE, true).add(FIELD_SCHEMA, true); DBObject fieldsObj = fieldsObjBuilder.get(); DBObject testObj = tests.findOne(queryObj, fieldsObj); if (testObj == null) { // The test run no longer exists logger.warn("Test not found. Returning null test: " + testObjId); return null; } BasicDBList propsList = new BasicDBList(); if (includeProperties) { // Get the associated test definition String test = (String) testObj.get(FIELD_NAME); String release = (String) testObj.get(FIELD_RELEASE); Integer schema = (Integer) testObj.get(FIELD_SCHEMA); TestDefEntry testDefEntry = getTestDefCached(release, schema); if (testDefEntry == null) { // Again, we don't bother trying to resolve this logger.warn("Test definition not found for test: " + testObj); logger.warn("Deleting test without a test definition: " + testObj); this.deleteTest(test); return null; } else { // Start with the properties from the test definition Map<String, DBObject> propsMap = new HashMap<String, DBObject>(testDefEntry.testDefPropsMap); // Fetch the properties for the test DBCursor testPropsCursor = getTestPropertiesRaw(testObjId, null); // Combine MongoTestDAO.mergeProperties(propsMap, testPropsCursor); // Turn into a map and add back into the object propsList = MongoTestDAO.getPropertyList(propsMap); testObj.put(FIELD_PROPERTIES, propsList); } } // Done if (logger.isDebugEnabled()) { logger.debug("Found test: " + testObj); } return testObj; }