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
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)
def handle(self, replacement_rd3): # assign doc_id if need. ResourceDataModelValidator.assign_id(replacement_rd3) # validate the rd3 to be published. ResourceDataModelValidator.validate_model(replacement_rd3) # check to see if it's a replacement if replacement_rd3 is not None and _REPLACES in replacement_rd3: replacement_rd3_info = get_verification_info(replacement_rd3) if replacement_rd3_info is not None: graveyard = [] existing_gravestones = [] for orig_doc_id in replacement_rd3[_REPLACES]: try: orig_doc = self.db[orig_doc_id] orig_doc_info = get_verification_info(orig_doc) except couchdb.http.ResourceNotFound as rne: orig_doc = None orig_doc_info = None if orig_doc is not None and orig_doc["doc_type"] == "tombstone": permitted = True existing_gravestones.append(orig_doc) else: # verify that tombstones permitted = self._check_if_permitted(replacement_rd3, replacement_rd3_info, orig_doc, orig_doc_info) log.debug("handle: permitted? {0}".format(permitted)) if permitted: tombstone = self._make_tombstone(replacement_rd3, replacement_rd3_info, orig_doc_id, orig_doc) graveyard.append(tombstone) else: log.debug("Replacement resource not permitted to be saved.") # this should save unless a permit plugin has thrown an exception to disallow saving result = ResourceDataModelValidator.save(replacement_rd3, skip_validation=True) if self._has_graveyard_permit(replacement_rd3, replacement_rd3_info, graveyard, existing_gravestones): for tombstone in graveyard: try: self.db[tombstone["_id"]] = tombstone except: # if this is already a tombstone, then it's okay - first wins TombstoneValidator.validate_model(self.db[tombstone["_id"]]) # else: # # import pdb; pdb.set_trace() # raise SpecValidationException("Node policy does not permit this resource published.") return result # we get here because it's not a replacement. return ResourceDataModelValidator.save(replacement_rd3, skip_validation=True)
def checkResourceData(doc): ResourceDataModelValidator.validate_model(doc)
def handle(self, replacement_rd3): # assign doc_id if need. ResourceDataModelValidator.assign_id(replacement_rd3) # validate the rd3 to be published. ResourceDataModelValidator.validate_model(replacement_rd3) # check to see if it's a replacement if replacement_rd3 is not None and _REPLACES in replacement_rd3: replacement_rd3_info = get_verification_info(replacement_rd3) if replacement_rd3_info is not None: graveyard = [] existing_gravestones = [] for orig_doc_id in replacement_rd3[_REPLACES]: try: orig_doc = self.db[orig_doc_id] orig_doc_info = get_verification_info(dict(orig_doc)) except couchdb.http.ResourceNotFound as rne: orig_doc = None orig_doc_info = None if orig_doc is not None and orig_doc[ "doc_type"] == "tombstone": permitted = True existing_gravestones.append(orig_doc) else: # verify that tombstones permitted = self._check_if_permitted( replacement_rd3, replacement_rd3_info, orig_doc, orig_doc_info) log.debug("handle: permitted? {0}".format(permitted)) if permitted: tombstone = self._make_tombstone( replacement_rd3, replacement_rd3_info, orig_doc_id, orig_doc) graveyard.append(tombstone) else: log.debug( "Replacement resource not permitted to be saved.") # this should save unless a permit plugin has thrown an exception to disallow saving result = ResourceDataModelValidator.save(replacement_rd3, skip_validation=True) if self._has_graveyard_permit(replacement_rd3, replacement_rd3_info, graveyard, existing_gravestones): for tombstone in graveyard: try: self.db[tombstone["_id"]] = tombstone except: # if this is already a tombstone, then it's okay - first wins TombstoneValidator.validate_model( self.db[tombstone["_id"]]) # else: # # import pdb; pdb.set_trace() # raise SpecValidationException("Node policy does not permit this resource published.") return result # we get here because it's not a replacement. return ResourceDataModelValidator.save(replacement_rd3, skip_validation=True)