/** * take a result object, obtain from it service id get this service from data store update its * fields * * @param result */ public static PsService update(Session session, PsServiceResult result) { int serviceId = result.getService_id(); PsService service = PsDataStore.getService(session, serviceId); if (service != null) { service.setRunning(false); Date prevCheckTime = result.getTime(); service.setPrevCheckTime(prevCheckTime); int checkInterval = service.getCheckInterval(); Date nextCheckTime = new Date(prevCheckTime.getTime() + (long) checkInterval * Timer.ONE_SECOND); service.setNextCheckTime(nextCheckTime); PsRecentServiceResult recentResult = PsServiceResult2RecentServiceResult.copy(session, result); service.setResult(recentResult); session.save(result); } return service; }
/** * Convert perfsonar service to Json object according to specified detail level * * @param service * @return */ public static JSONObject toJson(PsService service, String detailLevel) { JSONObject json = new JSONObject(); if (service != null) { json.put(PsService.ID, int2String(service.getId())); json.put(PsService.NAME, service.getName()); if (!PsApi.DETAIL_LEVEL_LOW.equals(detailLevel)) { json.put(PsService.TYPE, service.getType()); json.put(PsService.DESCRIPTION, service.getDescription()); // add service parameters if (service.getParameters() != null) { JSONObject serviceParameters = serviceParametersAsJson(service); json.put(PsService.PARAMETERS, serviceParameters); } json.put(PsService.CHECK_INTERVAL, new Integer(service.getCheckInterval())); json.put(PsService.RUNNING, service.isRunning()); json.put( PsService.PREV_CHECK_TIME, IsoDateConverter.dateToString(service.getPrevCheckTime())); json.put( PsService.NEXT_CHECK_TIME, IsoDateConverter.dateToString(service.getNextCheckTime())); json.put(PsService.RUNNING_SINCE, IsoDateConverter.dateToString(service.getRunningSince())); json.put(PsService.TIMEOUT, service.getTimeout()); // add result PsRecentServiceResult result = service.getResult(); JSONObject jsonResult = toJson(result); json.put(PsService.RESULT, jsonResult); } } return json; }