def create(action_code, class_code): run = self.prep_runtime() actth = run.ACTION_THEORY permitted, errors = run.insert(action_code, target=actth) self.assertTrue(permitted, "Error in action policy: {}".format( runtime.iterstr(errors))) clsth = run.CLASSIFY_THEORY permitted, errors = run.insert(class_code, target=clsth) self.assertTrue(permitted, "Error in classifier policy: {}".format( runtime.iterstr(errors))) return run
def create(ac_code, class_code): run = self.prep_runtime() acth = run.ACCESSCONTROL_THEORY permitted, errors = run.insert(ac_code, target=acth) self.assertTrue( permitted, "Error in access control policy: {}".format( runtime.iterstr(errors))) clsth = run.CLASSIFY_THEORY permitted, errors = run.insert(class_code, target=clsth) self.assertTrue( permitted, "Error in classifier policy: {}".format( runtime.iterstr(errors))) return run
def create(self, action_code, class_code, theories=None): run = self.prep_runtime(theories=theories) actth = self.ACTION_THEORY permitted, errors = run.insert(action_code, target=actth) self.assertTrue( permitted, "Error in action policy: {}".format(runtime.iterstr(errors))) defth = self.DEFAULT_THEORY permitted, errors = run.insert(class_code, target=defth) self.assertTrue( permitted, "Error in classifier policy: {}".format(runtime.iterstr(errors))) return run
def receive_data_full(self, msg): """Handler for when dataservice publishes full table.""" self.log("received full data msg for %s: %s", msg.header['dataindex'], runtime.iterstr(msg.body.data)) literals = [] dataindex = msg.header['dataindex'] tablename = msg.replyTo + ":" + dataindex for row in msg.body.data: if not isinstance(row, tuple): raise ValueError("Tuple expected, received: %s" % row) # prefix tablename with data source literals.append(compile.Literal.create_from_table_tuple( tablename, row)) (permitted, changes) = self.initialize([tablename], literals) if not permitted: raise runtime.CongressRuntime( "Update not permitted." + '\n'.join(str(x) for x in changes)) else: self.log("full data msg for %s caused %d changes: %s", tablename, len(changes), runtime.iterstr(changes))
def receive_data_update(self, msg): """Handler for when dataservice publishes a delta.""" self.log("received update data msg for %s: %s", msg.header['dataindex'], runtime.iterstr(msg.body.data)) events = msg.body.data for event in events: assert compile.is_atom(event.formula), \ "receive_data_update received non-atom: " + str(event.formula) # prefix tablename with data source event.formula.table = msg.replyTo + ":" + event.formula.table (permitted, changes) = self.update(events) if not permitted: raise runtime.CongressRuntime( "Update not permitted." + '\n'.join(str(x) for x in changes)) else: dataindex = msg.header['dataindex'] tablename = msg.replyTo + ":" + dataindex self.log("update data msg for %s caused %d changes: %s", tablename, len(changes), runtime.iterstr(changes)) if tablename in self.theory['classification'].tablenames(): rows = self.theory['classification'].content([tablename]) self.log("current table: %s", runtime.iterstr(rows))
def receive_data_full(self, msg): """Handler for when dataservice publishes full table.""" self.log("received full data msg for %s: %s", msg.header['dataindex'], runtime.iterstr(msg.body.data)) literals = [] tablename = msg.header['dataindex'] service = msg.replyTo for row in msg.body.data: if not isinstance(row, tuple): raise ValueError("Tuple expected, received: %s" % row) # prefix tablename with data source literals.append( compile.Literal.create_from_table_tuple(tablename, row)) (permitted, changes) = self.initialize_tables([tablename], literals, target=service) if not permitted: raise runtime.CongressRuntime("Update not permitted." + '\n'.join(str(x) for x in changes)) else: self.log("full data msg for %s caused %d changes: %s", tablename, len(changes), runtime.iterstr(changes))
def receive_data_update(self, msg): """Handler for when dataservice publishes a delta.""" self.log("received update data msg for %s: %s", msg.header['dataindex'], runtime.iterstr(msg.body.data)) events = msg.body.data for event in events: assert compile.is_atom( event.formula), ("receive_data_update received non-atom: " + str(event.formula)) # prefix tablename with data source event.target = msg.replyTo (permitted, changes) = self.update(events) if not permitted: raise runtime.CongressRuntime("Update not permitted." + '\n'.join(str(x) for x in changes)) else: tablename = msg.header['dataindex'] service = msg.replyTo self.log("update data msg for %s from %s caused %d " "changes: %s", tablename, service, len(changes), runtime.iterstr(changes)) if tablename in self.theory[service].tablenames(): rows = self.theory[service].content([tablename]) self.log("current table: %s", runtime.iterstr(rows))
def prepush_processor(self, data, dataindex, type=None): """Called before push. Takes as input the DATA that the receiver needs and returns the payload for the message. If this is a regular publication message, make the payload just the delta; otherwise, make the payload the entire table. """ # This routine basically ignores DATA and sends a delta # of the self.prior_state and self.state, for the DATAINDEX # part of the state. self.log("prepush_processor: dataindex <%s> data: %s", dataindex, data) # if not a regular publication, just return the original data if type != 'pub': self.log("prepush_processor: returned original data") if type == 'sub': # Always want to send initialization of [] if data is None: return [] else: return data return data # grab deltas to_add = self.state_set_diff(self.state, self.prior_state, dataindex) to_del = self.state_set_diff(self.prior_state, self.state, dataindex) self.log("to_add: %s", to_add) self.log("to_del: %s", to_del) # create Events result = [] for row in to_add: formula = compile.Literal.create_from_table_tuple(dataindex, row) event = runtime.Event(formula=formula, insert=True) result.append(event) for row in to_del: formula = compile.Literal.create_from_table_tuple(dataindex, row) event = runtime.Event(formula=formula, insert=False) result.append(event) if len(result) == 0: # Policy engine expects an empty update to be an init msg # So if delta is empty, return None, which signals # the message should not be sent. result = None text = "None" else: text = runtime.iterstr(result) self.log("prepush_processor for <%s> returning with %s items", dataindex, text) return result
def prepush_processor(self, data, dataindex, type=None): """Takes as input the DATA that the receiver needs and returns the payload for the message. If this is a regular publication message, make the payload just the delta; otherwise, make the payload the entire table. """ # This routine basically ignores DATA and sends a delta # of the self.prior_state and self.state, for the DATAINDEX # part of the state. self.log("prepush_processor: dataindex <{}> data: {}".format( str(dataindex), str(data))) # if not a regular publication, just return the original data if type != 'pub': self.log("prepush_processor: returned original data") if type == 'sub': # Always want to send initialization of [] if data is None: return [] else: return data return data # grab deltas to_add = self.state_set_diff(self.state, self.prior_state, dataindex) to_del = self.state_set_diff(self.prior_state, self.state, dataindex) self.log("to_add: " + str(to_add)) self.log("to_del: " + str(to_del)) # create Events to_add = [runtime.Event( formula=compile.Literal.create_from_table_tuple( dataindex, x), insert=True) for x in to_add] to_del = [runtime.Event( formula=compile.Literal.create_from_table_tuple( dataindex, x), insert=False) for x in to_del] result = to_add + to_del if len(result) == 0: # Policy engine expects an empty update to be an init msg # So if delta is empty, return None, which signals # the message should not be sent. result = None text = "None" else: text = runtime.iterstr(result) self.log("prepush_processor for <{}> returning: {}".format(self.name, dataindex, text)) return result
def receive_policy_update(self, msg): self.log("received policy-update msg %s", runtime.iterstr(msg.body.data)) # update the policy and subscriptions to data tables. self.last_policy_change = self.process_policy_update(msg.body.data)
def receive_policy_update(self, msg): self.log("received policy-update msg %s", runtime.iterstr(msg.body.data)) # update the policy and subscriptions to data tables. self.last_policy_change = self.process_policy_update(msg.body.data)
def receive_policy_update(self, msg): self.log("received policy-update msg {}".format( runtime.iterstr(msg.body.data))) # update the policy and subscriptions to data tables. self.process_policy_update(msg.body.data)