Beispiel #1
0
 def handleDocument(newDoc):
     should_delete = True
     try:
         # newDoc['node_timestamp'] = h.nowToISO8601Zformat()
         ResourceDataModelValidator.set_timestamps(newDoc)
         del newDoc["_rev"]
         self.repl_helper.handle(newDoc)
         # rd = ResourceDataModel(newDoc)
         # rd.save(log_exceptions=False)
     except SpecValidationException as e:
         log.error("SpecValidationException: %s, %s", newDoc['_id'],
                   str(e))
     except couchdb.ResourceConflict as rc:
         log.error("Document conflicts", exc_info=1)
     except Exception as ex:
         should_delete = False  # don't delete something unexpected happend
         log.error("Unable to save %s", newDoc['_id'], exc_info=ex)
     if should_delete:
         try:
             del database[newDoc['_id']]
         except Exception as ex:
             log.error("Error when deleting", exc_info=ex)
     try:
         del self.threads[threadName(newDoc)]
     except:
         pass
 def handleDocument(newDoc):
     should_delete = True
     try:
         # newDoc['node_timestamp'] = h.nowToISO8601Zformat()
         ResourceDataModelValidator.set_timestamps(newDoc)
         del newDoc["_rev"]
         self.repl_helper.handle(newDoc)
         # rd = ResourceDataModel(newDoc)
         # rd.save(log_exceptions=False)
     except SpecValidationException as e:
         log.error("SpecValidationException: %s, %s",newDoc['_id'],str(e))
     except couchdb.ResourceConflict as rc:
         log.error("Document conflicts", exc_info=1)
     except Exception as ex:
         should_delete = False  # don't delete something unexpected happend
         log.error("Unable to save %s", newDoc['_id'], exc_info=ex)
     if should_delete:
         try:
             del database[newDoc['_id']]
         except Exception as ex:
             log.error("Error when deleting", exc_info=ex)
     try:
         del self.threads[threadName(newDoc)]
     except:
         pass
    def _publish(self, resourceData):
        if isinstance(resourceData,unicode):
            resourceData = json.loads(resourceData)
            
        result={self.__OK: True}

        try:
            # Set the envelop data timestaps.
            resourceData = ResourceDataModelValidator.set_timestamps(resourceData)

            #Check if the envelop get filtered out
            isFilteredOut, reason = self._isResourceDataFilteredOut(resourceData)
            if isFilteredOut:
                result[self.__ERROR] = reason
            else:
                resourceData["publishing_node"] = LRNode.nodeDescription.node_id
                result = self.repl_helper.handle(resourceData)
                # ResourceDataModelValidator.save(resourceData)
                result[ResourceDataModelValidator.DOC_ID] = resourceData[ResourceDataModelValidator.DOC_ID]

                 
        except SpecValidationException as ex:
            log.exception(ex)
            result[self.__ERROR]  = "\n"+pprint.pformat(str(ex), indent=4)
        except Exception as ex:
            log.exception(ex)
            result[self.__ERROR]  = str(ex)
            
        if result.has_key(self.__ERROR):
            result[self.__OK] = False
        
        return result
Beispiel #4
0
    def _publish(self, resourceData):
        if isinstance(resourceData, unicode):
            resourceData = json.loads(resourceData)

        result = {self.__OK: True}

        try:
            # Set the envelop data timestaps.
            resourceData = ResourceDataModelValidator.set_timestamps(
                resourceData)

            #Check if the envelop get filtered out
            isFilteredOut, reason = self._isResourceDataFilteredOut(
                resourceData)
            if isFilteredOut:
                result[self.__ERROR] = reason
            else:
                resourceData[
                    "publishing_node"] = LRNode.nodeDescription.node_id
                result = self.repl_helper.handle(resourceData)
                # ResourceDataModelValidator.save(resourceData)
                result[ResourceDataModelValidator.DOC_ID] = resourceData[
                    ResourceDataModelValidator.DOC_ID]

        except SpecValidationException as ex:
            log.exception(ex)
            result[self.__ERROR] = "\n" + pprint.pformat(str(ex), indent=4)
        except Exception as ex:
            log.exception(ex)
            result[self.__ERROR] = str(ex)

        if result.has_key(self.__ERROR):
            result[self.__OK] = False

        return result
 def handleDocument(newDoc):
     should_delete = True
     try:
         # newDoc['node_timestamp'] = h.nowToISO8601Zformat()
         ResourceDataModelValidator.set_timestamps(newDoc)
         del newDoc["_rev"]
         self.repl_helper.handle(newDoc)
         # rd = ResourceDataModel(newDoc)
         # rd.save(log_exceptions=False)
     except SpecValidationException as e:
         log.error(newDoc["_id"] + str(e))
     except ResourceConflict as ex:
         log.exception(ex)
     except Exception as ex:
         should_delete = False  # don't delete something unexpected happend
         log.error(ex)
     if should_delete:
         try:
             del database[newDoc["_id"]]
         except Exception as ex:
             log.error(ex)