예제 #1
0
    def render_GET(self, request):
        tupleSelectorStr = request.args[b'tupleSelector'][0].decode()

        request.responseHeaders.setRawHeaders('content-type', ['text/csv'])
        logger.info("Received download request for events.")
        logger.debug("Download request received with TupleSelector = %s.",
                     tupleSelectorStr)

        def good(data):
            request.write(data.encode())
            request.finish()
            logger.info("Finished download of events")

        def bad(failure):
            request.setResponseCode(500)
            e = failure.value
            logger.exception(e)

            request.finish()

        d = runPyInPg(logger,
                      self._dbSessionCreator,
                      self._loadInPg,
                      EventDBEventTupleProvider._importTuples,
                      tupleSelectorStr=tupleSelectorStr)

        d.addCallbacks(good, bad)

        def closedError(failure):
            logger.error("Got closedError %s" % failure)

        request.notifyFinish().addErrback(closedError)

        return NOT_DONE_YET
    def deleteEvents(self, modelSetKey: str, eventKeys: List[str]) -> Deferred:
        count = yield runPyInPg(logger,
                                self._dbSessionCreator,
                                EventDBImportEventsInPgTask.deleteEvents,
                                None,
                                modelSetKey,
                                eventKeys)

        self._statusController.status.removedEvents += count
        self._statusController.status.lastActivity = datetime.now(pytz.utc)
        self._statusController.notify()
    def updateAlarmFlags(self, modelSetKey: str, eventKeys: List[str],
                         alarmFlag: bool) -> Deferred:
        count = yield runPyInPg(logger,
                                self._dbSessionCreator,
                                EventDBImportEventsInPgTask.updateAlarmFlags,
                                None,
                                modelSetKey,
                                eventKeys,
                                alarmFlag)

        self._statusController.status.updatedAlarmFlags += count
        self._statusController.status.lastActivity = datetime.now(pytz.utc)
        self._statusController.notify()
    def replaceProperties(self, modelSetKey: str,
                          propertiesEncodedPayload: str) -> Deferred:
        yield runPyInPg(logger,
                        self._dbSessionCreator,
                        EventDBImportPropertiesInPgTask.replaceProperties,
                        None,
                        modelSetKey,
                        propertiesEncodedPayload)

        tupleSelector = TupleSelector(EventDBPropertyTable.tupleName(), {})
        self._tupleObservable.notifyOfTupleUpdate(tupleSelector)

        tupleSelector = TupleSelector(EventDBPropertyTuple.tupleName(), {})
        self._tupleObservable.notifyOfTupleUpdate(tupleSelector)
 def makeVortexMsg(self, filt: dict, tupleSelector: TupleSelector) -> Deferred:
     # Uncomment this to print the SQL being created
     #
     # criterias = tupleSelector..get('criteria', [])
     # newestDateTime = tupleSelector..get('newestDateTime')
     # oldestDateTime = tupleSelector..get('oldestDateTime')
     #
     # sql = self._makeSql(criterias, 0, newestDateTime, oldestDateTime)
     # logger.info(sql)
     logger.debug(tupleSelector.toJsonStr())
     return (yield runPyInPg(logger,
                             self._dbSessionCreator,
                             self._loadInPg,
                             self._importTuples,
                             filt=filt,
                             tupleSelectorStr=tupleSelector.toJsonStr())).encode()
    def importEvents(self, modelSetKey: str,
                     eventsEncodedPayload: str) -> Deferred:
        count, maxDate, minDate = yield runPyInPg(logger,
                                                  self._dbSessionCreator,
                                                  EventDBImportEventsInPgTask.importEvents,
                                                  None,
                                                  modelSetKey,
                                                  eventsEncodedPayload)

        # Notify anyone watching the events that new ones have arrived.
        if count:
            self._tupleObservable \
                .notifyOfTupleUpdate(NewEventsTupleSelector(minDate, maxDate))

        self._statusController.status.addedEvents += count
        self._statusController.status.lastActivity = datetime.now(pytz.utc)
        self._statusController.notify()