Beispiel #1
0
    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')
Beispiel #2
0
def build_payload(action, entry: DatabaseEntry):
    payload = {
        "verb": action,
        "key": entry.key(),
        "data": entry.get_serialized_message()
    }

    return cbor.dumps(payload)
Beispiel #3
0
 def update_entry_and_report(self, entry: DatabaseEntry):
     self.update_entry(entry)
     self.report_update(entry.key())
Beispiel #4
0
 def update_entry(self, entry: DatabaseEntry):
     self.db[entry.key()] = entry.get_serialized_message()
Beispiel #5
0
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
Beispiel #6
0
 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()
Beispiel #7
0
def _insert_check(manager: DatabaseManager, entry: DatabaseEntry):
    manager.update_entry(entry)
    assert manager.get_entry(entry.key()).to_dict() == entry.to_dict()