def apply(self, transaction, context): self.log("Apply called") # unpack transaction info action, key, data = unpack_transaction(transaction) # get the current state state = get_state_data(key, context) if action == 'set': self.log(" Action is 'set'") # use protobuf data to create a DatabaseEntry and execute it entry = DatabaseEntry(data) try: self.apply_callback(entry.key()) except ValueError: self.log(" Database entry apply failed") # update the state updated_state = dict(state.items()) updated_state[key] = data set_state_data(key, updated_state, context) else: raise InternalError('Invalid function requested to be executed by CCellular Handler')
def build_payload(action, entry: DatabaseEntry): payload = { "verb": action, "key": entry.key(), "data": entry.get_serialized_message() } return cbor.dumps(payload)
def update_entry_and_report(self, entry: DatabaseEntry): self.update_entry(entry) self.report_update(entry.key())
def update_entry(self, entry: DatabaseEntry): self.db[entry.key()] = entry.get_serialized_message()
def _check_entry(entry: DatabaseEntry, imsi, max_known_sqn, vectors): return entry.key() == imsi and\ int(entry.get_max_known_sqn()) == int(max_known_sqn) and\ entry.get_vectors() == vectors
def update_entry(self, entry: DatabaseEntry): self.log("Updating entry: " + str(entry.to_dict())) result_id = MongoDBOperations.insert(self.collection, entry) if result_id != None: self.id_map[result_id] = entry.key()
def _insert_check(manager: DatabaseManager, entry: DatabaseEntry): manager.update_entry(entry) assert manager.get_entry(entry.key()).to_dict() == entry.to_dict()