# Extract JSON values from message # Check the message is a application/json if json_msg.get("Content-type") != "application/json": self.loginfo("do_fwd: weird content type: %s" % json_msg.get("Content-type")) continue # Extract the JSON structure try: json_report = json.loads(json_msg.get_payload()) except Exception, e: self.loginfo("do_fwd: can't decode json: %s" % str(e)); continue curi=NIname(uri) curi.validate_ni_url() metadata = NetInfMetaData(curi.get_canonical_ni_url()) self.loginfo("Metadata I got: %s" % str(json_report)) metadata.insert_resp_metadata(json_report) # if I've the role GET_RES and there's locators then # follow those now if ct_msg == None and self.check_role(GET_RES): self.loginfo("I'm a GET_RES type of node - going to try follow") self.loginfo("meta: %s" % str(json_report)) # check for locators locators = metadata.get_loclist() self.loginfo("locs: %s" % str(locators)) # try follow locators for loc in locators: self.loginfo("GET_RES following: %s" % loc)
try: if (metadata_str is None): new_entry = True # Don't need a real copy - reference will do old_metadata = metadata else: new_entry = False js = json.loads(metadata_str) except Exception, e: self.logerror(err_str + str(e)) if content_added: os.remove(cfn) raise sys.exc_info()[0](err_str + str(e)) if not new_entry: old_metadata = NetInfMetaData() old_metadata.set_json_val(js) if not old_metadata.merge_latest_details(metadata): err_str = "put_cache: Mismatched information in metadata update: %s" % \ ni_url self.logerror(err_str) if content_added: os.remove(cfn) raise ValueError(err_str) err_str = "put_cache: problem storing metadata record %s: " % mfk try: new_metadata_str = json.dumps(old_metadata.json_val()) except Exception, e: self.logerror(err_str + str(e)) if content_added:
# Check the message is a application/json if json_msg.get("Content-type") != "application/json": logger.info("do_fwd: weird content type: %s" % json_msg.get("Content-type")) continue # Extract the JSON structure try: json_report = json.loads(json_msg.get_payload()) except Exception, e: logger.info("do_fwd: can't decode json: %s" % str(e)); continue curi=NIname(uri) curi.validate_ni_url() metadata = NetInfMetaData(curi.get_canonical_ni_url()) logger.info("Metadata I got: %s" % str(json_report)) metadata.insert_resp_metadata(json_report) # will do json.loads again... # removed GET_RES handling present in do_get_fwd in nifwd.py / bengta # all good break out of loop break # make up stuff to return # print "do_fwd: success" if metadata is None: return False, metadata, fname return True,metadata,fname