Exemple #1
0
    def Dispatch(self, request, context):
        sm = finite.eventstore(
            schema=request.schema,
            chain=request.chain,
            oid=request.id)

        # FIXME: convert command.actions to multiple format

        # KLUDGE just dispatch first action without setting multiple

        # FIXME: this seems to initalize the storage with a new oid every time
        # TODO: make this a param
        res = sm(request.action[0].action, roles=['*'], payload={})

        # res = ('94c6a5f7-2828-4038-bf7b-c2adfa8e6dfe', [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1], None)

        # TODO make assertion that state matches expected state
        print(res)

        state = event_pb2.State(
            id=request.id,
            schema=request.schema,
            state=res[1],
            head=res[0],
            created=None,  # FIXME add time
            updated=None)  # FIXME get state

        return event_pb2.EventStatus(state=state, code=0, message="hello")
Exemple #2
0
    def GetState(self, request, context):
        sm = finite.eventstore(
            schema=request.schema,
            chain=request.chain,
            oid=request.id)

        s = sm.state()

        state = event_pb2.State(
            id=request.id,
            schema=request.schema,
            chain=request.chain,
            state=s[1],
            head=s[0],
            created=None,
            updated=None)

        # FIXME
        # get current state
        if request.uuid is None:
            pass
        # get state at given event uuid
        else:
            pass

        return event_pb2.StateList(list=[state])
Exemple #3
0
    def GetEvent(self, request, context):
        sm = finite.eventstore(
            schema=request.schema,
            chain=request.chain,
            oid=request.id)

        # FIXME retrieve the event or list of events if uuid is not passed

        events = []
        if request.uuid is None:
            # get all events
            # FIXME:  add query
            pass
        else:
            # get single event
            e = sm.event(request.uuid)
            if e is None:
                raise Exception("Missing Event uuid: %s" % request.uuid)

            # TODO: add remaining fields
            event = event_pb2.Event(
                id=request.id,
                schema=request.schema,
                chain=request.chain,
                action=None,  # FIXME: add actions
                payload=None,
                state=e[2],
                ts=None,
                uuid=request.uuid,
                parent=e[0])

            events.append(event)

        return event_pb2.EventList(list=events)
Exemple #4
0
    def GetPlaceMap(self, request, context):
        sm = finite.eventstore(
            schema=request.schema,
            chain=request.chain,
            oid=request.id)

        place_defs = {}
        for label, place in sm.places.items():
            place_defs[label] = event_pb2.Place(
                offset=place['offset'],
                initial=place['initial'],
                capacity=place['capacity'])

        return event_pb2.PlaceMap(schema=request.schema, map=place_defs)
Exemple #5
0
    def GetMachine(self, request, context):
        sm = finite.eventstore(
            schema=request.schema,
            chain=request.chain,
            oid=request.id)

        txn_defs = {}
        for label, txn in sm.transitions.items():

            guard_defs = {}
            for condition, guard in txn['guards'].items():
                guard_defs[condition] = event_pb2.Guard(delta=guard)

            txn_defs[label] = event_pb2.Transition(
                delta=txn['delta'], role=txn['role'], guards=guard_defs)

        return event_pb2.Machine(
            schema=request.schema,
            initial=sm.initial_vector(),
            capacity=sm.capacity_vector(),
            transitions=txn_defs)
 def setUp(self):
     finite.initialize(Storage)
     self.m = finite.eventstore(schema='octoe',
                                chain='mychain',
                                oid="test_oid")