def __init__(self, args): L(args.log) self.config = JOb(file(os.path.join(os.path.dirname(__file__), "..", "config.json"), "rb")) self.status = JSONObject() self.status.running = False self.wrappers = [] ResourceManagement.args = args ResourceManagement.config = self.config self.clock = None self.annotator = GenericAnnotation() self.stoppedClock = False # init triplestore if args.triplestore: ThreadedTriplestoreAdapter.triplestore = TripleStoreFactory.getTripleStore( self.config.triplestore.driver, self.config.triplestore ) # dump the graph with the static annotations StaticAnnotator.dumpGraph() if args.aggregate: # self.aggregator = AggregatorFactory.make(self.config.aggregationmethod, self.config.aggregation_configuration) # self.aggregator = AggregatorFactory.make() # TODO self.aggregator = GenericAggregator() self.aggregationQueue = QueueThread(handler=self.aggregateHandler) self.receiverQueue = QueueThread(handler=self.receiveHandler) # establish connection to the message bus if args.messagebus: threading.Thread(name="messageBusConnector", target=self.start_messagebus, args=(args,)).start() else: self.messageBusQueue = None if args.eventannotation: self.eventWrapper = GenericEventWrapper(self.messageBusQueue) else: self.eventWrapper = None if args.gdi: from CityPulseGdi.eu.citypulse.uaso.gdi.CityPulseGDInterface import CityPulseGDInterface self.gdiInterface = CityPulseGDInterface(self.config.gdi_db) # self.gdiInterface.removeAllSensorStreams() else: self.gdiInterface = None self.averageStreamQuality = None if args.sql: self.sql = SQL(self.config.gdi_db, self) else: self.sql = None self.startInterface() self.autodeploy()
def addWrapper(self, wrapper): # TODO: this should not be here if ResourceManagement.args.cleartriplestore: self.deleteGraphs(wrapper) sd = wrapper.getSensorDescription() try: if isinstance(sd, list): for _sd in sd: try: _sd.test() if ResourceManagement.args.aggregate: self.aggregator.wrapper_added(_sd) if self.gdiInterface: self.gdiInterface.registerSensorStreamFromWKT( _sd.uuid, _sd.sensorID, _sd.sensorType, _sd.location, _sd.location_epsg or 4326 ) # if self.sql: # self.sql.create_table(_sd) L.i("added wrapper with ID", _sd.sensorID) except Exception as ex: L.e("Error deploying wrapper:", str(ex)) else: try: sd.test() if ResourceManagement.args.aggregate: self.aggregator.wrapper_added(sd) if self.gdiInterface: self.gdiInterface.registerSensorStreamFromWKT( sd.uuid, sd.sensorID, sd.sensorType, sd.location, sd.location_epsg or 4326 ) # if self.sql: # self.sql.create_table(sd) L.i("added wrapper with ID", sd.sensorID) except Exception as ex: L.e("Error deploying wrapper:", str(ex)) if ResourceManagement.args.triplestore or ResourceManagement.args.messagebus: # StaticAnnotator.staticAnnotationSensor(wrapper, self.config, self.messageBusQueue, self.rabbitmqchannel) StaticAnnotator.threadedStaticAnnotationSensor(wrapper, self.config, self.messageBusQueue, self.ui.api) if ResourceManagement.args.messagebus: wrapper.setMessageBusQueue(self.messageBusQueue) self.wrappers.append(wrapper) except Exception as ex: L.e(self.__class__.__name__, "Error in addWrapper:", str(ex))