def getAllLastQualities(self): from virtualisation.wrapper.abstractwrapper import AbstractWrapper, AbstractComposedWrapper qualities = [] wrappers = self.rm.wrappers for wrapper in wrappers: if isinstance(wrapper, AbstractWrapper): if wrapper.qoiSystem.initialised: qualities.append(wrapper.qoiSystem.getLastQoI()) qualities[-1].uuid = wrapper.getSensorDescription().uuid else: resp = JOb() resp.uuid = wrapper.getSensorDescription().uuid resp.status = "Fail" resp.message = "Quality System not initialised for given uuid" qualities.append(resp) elif isinstance(wrapper, AbstractComposedWrapper): for aWrapper in wrapper.wrappers: if aWrapper.qoiSystem.initialised: qualities.append(aWrapper.qoiSystem.getLastQoI()) qualities[-1].uuid = aWrapper.getSensorDescription().uuid else: resp = JOb() resp.uuid = aWrapper.getSensorDescription().uuid resp.status = "Fail" resp.message = "Quality System not initialised for given uuid" qualities.append(resp) return JOb(qualities).dumps()
def data_timeframe(self, uuid): """ Returns the time frame (start and end date) for which data from the stream, identified by the UUID, is available. :param uuid: :return: """ resp = JOb() resp.uuid = uuid try: if ThreadedTriplestoreAdapter.triplestore: sd = self.rm.getSensorDescriptionByUUID(uuid) if sd: data = ThreadedTriplestoreAdapter.triplestore.getStreamMinMaxDate(sd.graphName, formatSensorID(sd)) resp.status = "Ok" resp.message = "" resp.data = data else: raise Exception("no stream with given uuid known") else: resp.status = "Fail" resp.message = "Triplestore not activated." except Exception as e: resp.status = "Fail" resp.message = e.message return resp.dumps()
def snapshot(self, uuid, start=None, end=None): """ Get previous observations :param uuid: The uuid of the wrapper :param start: The start date in the format %Y-%m-%dT%H:%M:%S :param end: The end date in the format %Y-%m-%dT%H:%M:%S :return: a JSON answer """ resp = JOb() resp.uuid = uuid try: from virtualisation.resourcemanagement.resourcemanagement import ResourceManagement if ResourceManagement.args.triplestore: sd = self.rm.getSensorDescriptionByUUID(uuid) if sd: data = ThreadedTriplestoreAdapter.triplestore.getObservationGraph(sd.graphName, formatSensorID(sd), start, end, False) resp.status = "Ok" resp.message = "" resp.data = data else: raise Exception("no stream with given uuid known") else: raise Exception("Triplestore not enabled in Resource Management") except Exception as e: resp.status = "Fail" resp.message = e.message return resp.dumps()
def get_static_stream_data(self, uuid): resp = JOb() resp.uuid = uuid if uuid in self.static_stream_data_cache: resp.status = "Ok" resp.message = "" resp.data = self.static_stream_data_cache[uuid] else: resp.status = "Fail" resp.message = "No sensor stream with uuid " + uuid + " known." return resp.dumps()
def deactivate_fault_recovery(self, uuid): """ Disable the fault recovery for a wrapper :param uuid: UUID identifying the wrapper :return: """ resp = JOb() resp.uuid = uuid w = self.rm.getWrapperByUUID(uuid) if w: w.deactivateFaultRecovery() resp.status = "Ok" resp.message = "" else: resp.status = "Fail" resp.message = "no stream with given uuid known" return resp.dumps()
def snapshot_last(self, uuid): """ Get previous observations :param uuid: The uuid of the wrapper :param start: The start date in the format %Y-%m-%dT%H:%M:%S :param end: The end date in the format %Y-%m-%dT%H:%M:%S :return: a JSON answer """ resp = JOb() resp.uuid = uuid if uuid in self.observation_cache: resp.status = "Ok" resp.message = "" resp.data = self.observation_cache[uuid] else: resp.status = "Fail" resp.message = "No observation with the UUID " + uuid + " cached." return resp.dumps()
def data_timeframe_sql(self, uuid): """ Returns the time frame (start and end date) for which data from the stream, identified by the UUID, is available. :param uuid: :return: """ resp = JOb() resp.uuid = uuid try: if self.rm.sql: data = self.rm.sql.data_timeframe(uuid) resp.status = "Ok" resp.message = "" resp.data = data else: resp.status = "Fail" resp.message = "SQL feature not activated." except Exception as e: resp.status = "Fail" resp.message = e.message return resp.dumps()
def getQualityValues(self, uuid=None, types=None, avg=None, minimum=None, maximum=None): if types: types = types.split(",") if uuid: uuid = uuid.split(",") else: #get all uuids from wrapper list from virtualisation.wrapper.abstractwrapper import AbstractWrapper, AbstractComposedWrapper uuid = [] wrappers = self.rm.wrappers for wrapper in wrappers: if isinstance(wrapper, AbstractWrapper): uuid.append(wrapper.getSensorDescription().uuid) elif isinstance(wrapper, AbstractComposedWrapper): for aWrapper in wrapper.wrappers: uuid.append(aWrapper.getSensorDescription().uuid) qualities = [] for _uuid in uuid: wrapper = self.rm.getWrapperByUUID(_uuid) message = "" if wrapper: if wrapper.qoiSystem.initialised: avgQualities = [] avgQualities.append(wrapper.qoiSystem.getLastQoI(types=types, avg=valueToBoolean(avg), minimum=valueToBoolean(minimum), maximum=valueToBoolean(maximum))) avgQualities[-1].uuid = wrapper.getSensorDescription().uuid qualities.extend(JOb(avgQualities)) else: message = "AVG Quality System not initialised for given uuid" else: message = "no stream with given uuid known" if message: resp = JOb() resp.uuid = _uuid resp.status = "Fail" resp.message = message qualities.append(resp) return JOb(qualities).dumps()
def snapshot_quality(self, uuid, start=None, end=None): """ Get previous quality annotations :param uuid: The uuid of the wrapper/stream :param start: The start date in the format %Y-%m-%dT%H:%M:%S :param end: The end date in the format %Y-%m-%dT%H:%M:%S :return: a JSON answer """ resp = JOb() resp.uuid = uuid resp.result = [] uuid = uuid.split(",") try: from virtualisation.resourcemanagement.resourcemanagement import ResourceManagement if ResourceManagement.args.triplestore: graphMap = {} working_uuids = [] for _id in uuid: sd = self.rm.getSensorDescriptionByUUID(_id) if sd is not None: if not graphMap.has_key(sd.graphName): graphMap[sd.graphName] = [formatSensorID(sd)] else: graphMap[sd.graphName].append(formatSensorID(sd)) working_uuids.append(_id) else: d = JOb() d.message = "Wrong UUID" resp.result.append(JOb({"uuid": _id, "error": d})) resp.status = "Ok" sortedReturn = {} for graph in graphMap: tmpData = ThreadedTriplestoreAdapter.triplestore.getLastQoIData_List(graph, graphMap[graph], start, end) if tmpData is None: raise Exception("Virtuoso Exception or no data for given start/end date") else: if len(tmpData["results"]["bindings"]) == 0: pass else: for key in tmpData["results"]["bindings"]: sensorUUID = key["sensor"]["value"].replace("http://ict-citypulse.eu/SensorID-", "") if sensorUUID in sortedReturn: sortedReturn[sensorUUID].append(key) else: sortedReturn[sensorUUID] = [] sortedReturn[sensorUUID].append(key) for _id in working_uuids: if _id in sortedReturn: data = [] for tmp in sortedReturn[_id]: d = JOb() d.time = tmp["resultTimeValue"]["value"] d.data = tmp data.append(d) data.sort(cmp=lambda x, y: cmp(x.time, y.time)) resp.result.append(JOb({"uuid": _id, "dataset": data})) else: d = JOb() d.message = "No data available" resp.result.append(JOb({"uuid": _id, "error": d})) resp.result.sort(cmp=lambda x, y: uuid.index(x.uuid) - uuid.index(y.uuid)) else: raise Exception("Triplestore not enabled in Resource Management") except Exception as e: resp.status = "Fail" resp.message = e.message return resp.dumps()