def get(self, schema, key, *args): """ return event stream """ m = bitwrap_io.open(schema) oid = m.storage.encode_key(key) with m.storage.db.cursor() as txn: self.write(m.storage.db.events.list(oid))
def jsonrpc_transform(self, msg): """ execute a state machine transformation""" self.set_header('Access-Control-Allow-Methods', 'POST, OPTIONS') msg['ip'] = self.request.remote_ip msg['endpoint'] = self.request.host return bitwrap_io.open(msg['schema'])(**msg)
def get(self, schema, key, *args): """ get event by eventid """ m = bitwrap_io.open(schema) eventid = m.storage.encode_key(key) with m.storage.db.cursor() as txn: evt = m.storage.db.events.get(eventid) self.write(evt)
def transform(event): """ perform a state machine transformation """ msg = json.loads(event['body']) _s = msg['params'][0]['schema'] err = None m = bitwrap_io.open(_s) preview = msg['method'] != 'transform' res = m.session(msg['params'][0]).commit(dry_run=preview) if (not preview) and (not res['id']): err = -1 res['schema'] = _s return success({"result": res, "error": err, "id": msg['id']})
def query(event): """ query the eventstore """ _p = event['pathParameters'] _s = _p['schema'] m = bitwrap_io.open(_s) s = StorageFactory(backend='mysql')(_s, m) with s.db.cursor() as txn: if 'headid' in _p: head = s.db.state.head(_p["headid"]) return success(s.db.events.get(head)) elif 'eventid' in _p: evt = s.db.events.get(_p["eventid"]) return success(evt) elif 'streamid' in _p: return success(s.db.events.list(_p["streamid"])) else: return success(m.machine.net.data)
def jsonrpc_preview(self, msg): """ preview a state machine transformation""" self.set_header('Access-Control-Allow-Methods', 'POST, OPTIONS') return bitwrap_io.open(msg['schema']).preview(**msg)
def eventstore(schema): """ open eventstore on bitwrap storage """ return bitwrap_io.open(schema, **SETTINGS)