|
@@ -1,7 +1,7 @@
|
|
"""
|
|
"""
|
|
Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
|
|
Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
|
|
|
|
|
|
-Date: Thu Feb 09 11:35:15 2017
|
|
|
|
|
|
+Date: Thu Feb 9 12:19:07 2017
|
|
|
|
|
|
Model author: Yentl Van Tendeloo
|
|
Model author: Yentl Van Tendeloo
|
|
Model name: MvK Server
|
|
Model name: MvK Server
|
|
@@ -17,6 +17,8 @@ import sys
|
|
import json
|
|
import json
|
|
|
|
|
|
from modelverse_kernel.main import ModelverseKernel
|
|
from modelverse_kernel.main import ModelverseKernel
|
|
|
|
+sys.path.append("../../state")
|
|
|
|
+from modelverse_state.main import ModelverseState
|
|
|
|
|
|
# package "MvK Server"
|
|
# package "MvK Server"
|
|
|
|
|
|
@@ -37,12 +39,12 @@ class MvKController(RuntimeClassBase):
|
|
MvKController.user_defined_constructor(self, params)
|
|
MvKController.user_defined_constructor(self, params)
|
|
|
|
|
|
def user_defined_constructor(self, params):
|
|
def user_defined_constructor(self, params):
|
|
- self.mvk = None
|
|
|
|
self.users = []
|
|
self.users = []
|
|
self.user_statecharts = {"__hierarchy": None}
|
|
self.user_statecharts = {"__hierarchy": None}
|
|
self.input_queue = []
|
|
self.input_queue = []
|
|
self.user_queue = {}
|
|
self.user_queue = {}
|
|
self.source = None
|
|
self.source = None
|
|
|
|
+ self.root = None
|
|
|
|
|
|
self.params = params
|
|
self.params = params
|
|
|
|
|
|
@@ -56,68 +58,64 @@ class MvKController(RuntimeClassBase):
|
|
# state <root>
|
|
# state <root>
|
|
self.states[""] = State(0, self)
|
|
self.states[""] = State(0, self)
|
|
|
|
|
|
- # state /init
|
|
|
|
- self.states["/init"] = State(1, self)
|
|
|
|
- self.states["/init"].setEnter(self._init_enter)
|
|
|
|
-
|
|
|
|
- # state /get_root
|
|
|
|
- self.states["/get_root"] = State(2, self)
|
|
|
|
-
|
|
|
|
# state /init_server
|
|
# state /init_server
|
|
- self.states["/init_server"] = State(3, self)
|
|
|
|
|
|
+ self.states["/init_server"] = State(1, self)
|
|
self.states["/init_server"].setEnter(self._init_server_enter)
|
|
self.states["/init_server"].setEnter(self._init_server_enter)
|
|
|
|
|
|
# state /init_executor
|
|
# state /init_executor
|
|
- self.states["/init_executor"] = State(4, self)
|
|
|
|
|
|
+ self.states["/init_executor"] = State(2, self)
|
|
self.states["/init_executor"].setEnter(self._init_executor_enter)
|
|
self.states["/init_executor"].setEnter(self._init_executor_enter)
|
|
|
|
|
|
|
|
+ # state /read_root
|
|
|
|
+ self.states["/read_root"] = State(3, self)
|
|
|
|
+ self.states["/read_root"].setEnter(self._read_root_enter)
|
|
|
|
+
|
|
# state /running
|
|
# state /running
|
|
- self.states["/running"] = ParallelState(5, self)
|
|
|
|
|
|
+ self.states["/running"] = ParallelState(4, self)
|
|
|
|
|
|
# state /running/wait_for_requests
|
|
# state /running/wait_for_requests
|
|
- self.states["/running/wait_for_requests"] = State(6, self)
|
|
|
|
|
|
+ self.states["/running/wait_for_requests"] = State(5, self)
|
|
|
|
|
|
# state /running/wait_for_requests/wait
|
|
# state /running/wait_for_requests/wait
|
|
- self.states["/running/wait_for_requests/wait"] = State(7, self)
|
|
|
|
|
|
+ self.states["/running/wait_for_requests/wait"] = State(6, self)
|
|
|
|
|
|
# state /running/push
|
|
# state /running/push
|
|
- self.states["/running/push"] = State(8, self)
|
|
|
|
|
|
+ self.states["/running/push"] = State(7, self)
|
|
|
|
|
|
# state /running/push/wait
|
|
# state /running/push/wait
|
|
- self.states["/running/push/wait"] = State(9, self)
|
|
|
|
|
|
+ self.states["/running/push/wait"] = State(8, self)
|
|
|
|
|
|
# state /running/push/process
|
|
# state /running/push/process
|
|
- self.states["/running/push/process"] = State(10, self)
|
|
|
|
|
|
+ self.states["/running/push/process"] = State(9, self)
|
|
|
|
|
|
# state /running/find_users
|
|
# state /running/find_users
|
|
- self.states["/running/find_users"] = State(11, self)
|
|
|
|
|
|
+ self.states["/running/find_users"] = State(10, self)
|
|
|
|
|
|
# state /running/find_users/get_all_links
|
|
# state /running/find_users/get_all_links
|
|
- self.states["/running/find_users/get_all_links"] = State(12, self)
|
|
|
|
|
|
+ self.states["/running/find_users/get_all_links"] = State(11, self)
|
|
self.states["/running/find_users/get_all_links"].setEnter(self._running_find_users_get_all_links_enter)
|
|
self.states["/running/find_users/get_all_links"].setEnter(self._running_find_users_get_all_links_enter)
|
|
|
|
|
|
# state /running/find_users/retrieve_users
|
|
# state /running/find_users/retrieve_users
|
|
- self.states["/running/find_users/retrieve_users"] = State(13, self)
|
|
|
|
|
|
+ self.states["/running/find_users/retrieve_users"] = State(12, self)
|
|
|
|
|
|
# state /running/find_users/got_usernames
|
|
# state /running/find_users/got_usernames
|
|
- self.states["/running/find_users/got_usernames"] = State(14, self)
|
|
|
|
|
|
+ self.states["/running/find_users/got_usernames"] = State(13, self)
|
|
|
|
|
|
# state /running/find_users/process_users
|
|
# state /running/find_users/process_users
|
|
- self.states["/running/find_users/process_users"] = State(15, self)
|
|
|
|
|
|
+ self.states["/running/find_users/process_users"] = State(14, self)
|
|
|
|
|
|
# state /running/find_users/creating_user
|
|
# state /running/find_users/creating_user
|
|
- self.states["/running/find_users/creating_user"] = State(16, self)
|
|
|
|
|
|
+ self.states["/running/find_users/creating_user"] = State(15, self)
|
|
|
|
|
|
# state /running/find_users/wait
|
|
# state /running/find_users/wait
|
|
- self.states["/running/find_users/wait"] = State(17, self)
|
|
|
|
|
|
+ self.states["/running/find_users/wait"] = State(16, self)
|
|
self.states["/running/find_users/wait"].setEnter(self._running_find_users_wait_enter)
|
|
self.states["/running/find_users/wait"].setEnter(self._running_find_users_wait_enter)
|
|
self.states["/running/find_users/wait"].setExit(self._running_find_users_wait_exit)
|
|
self.states["/running/find_users/wait"].setExit(self._running_find_users_wait_exit)
|
|
|
|
|
|
# add children
|
|
# add children
|
|
- self.states[""].addChild(self.states["/init"])
|
|
|
|
- self.states[""].addChild(self.states["/get_root"])
|
|
|
|
self.states[""].addChild(self.states["/init_server"])
|
|
self.states[""].addChild(self.states["/init_server"])
|
|
self.states[""].addChild(self.states["/init_executor"])
|
|
self.states[""].addChild(self.states["/init_executor"])
|
|
|
|
+ self.states[""].addChild(self.states["/read_root"])
|
|
self.states[""].addChild(self.states["/running"])
|
|
self.states[""].addChild(self.states["/running"])
|
|
self.states["/running"].addChild(self.states["/running/wait_for_requests"])
|
|
self.states["/running"].addChild(self.states["/running/wait_for_requests"])
|
|
self.states["/running"].addChild(self.states["/running/push"])
|
|
self.states["/running"].addChild(self.states["/running/push"])
|
|
@@ -132,27 +130,11 @@ class MvKController(RuntimeClassBase):
|
|
self.states["/running/find_users"].addChild(self.states["/running/find_users/creating_user"])
|
|
self.states["/running/find_users"].addChild(self.states["/running/find_users/creating_user"])
|
|
self.states["/running/find_users"].addChild(self.states["/running/find_users/wait"])
|
|
self.states["/running/find_users"].addChild(self.states["/running/find_users/wait"])
|
|
self.states[""].fixTree()
|
|
self.states[""].fixTree()
|
|
- self.states[""].default_state = self.states["/init"]
|
|
|
|
|
|
+ self.states[""].default_state = self.states["/init_server"]
|
|
self.states["/running/wait_for_requests"].default_state = self.states["/running/wait_for_requests/wait"]
|
|
self.states["/running/wait_for_requests"].default_state = self.states["/running/wait_for_requests/wait"]
|
|
self.states["/running/push"].default_state = self.states["/running/push/wait"]
|
|
self.states["/running/push"].default_state = self.states["/running/push/wait"]
|
|
self.states["/running/find_users"].default_state = self.states["/running/find_users/get_all_links"]
|
|
self.states["/running/find_users"].default_state = self.states["/running/find_users/get_all_links"]
|
|
|
|
|
|
- # transition /init
|
|
|
|
- _init_0 = Transition(self, self.states["/init"], [self.states["/get_root"]])
|
|
|
|
- _init_0.setAction(self._init_0_exec)
|
|
|
|
- _init_0.setTrigger(Event("instance_created", None))
|
|
|
|
- self.states["/init"].addTransition(_init_0)
|
|
|
|
-
|
|
|
|
- # transition /get_root
|
|
|
|
- _get_root_0 = Transition(self, self.states["/get_root"], [self.states["/get_root"]])
|
|
|
|
- _get_root_0.setAction(self._get_root_0_exec)
|
|
|
|
- _get_root_0.setTrigger(Event("http_client_ready", None))
|
|
|
|
- self.states["/get_root"].addTransition(_get_root_0)
|
|
|
|
- _get_root_1 = Transition(self, self.states["/get_root"], [self.states["/init_server"]])
|
|
|
|
- _get_root_1.setAction(self._get_root_1_exec)
|
|
|
|
- _get_root_1.setTrigger(Event("HTTP_output", None))
|
|
|
|
- self.states["/get_root"].addTransition(_get_root_1)
|
|
|
|
-
|
|
|
|
# transition /init_server
|
|
# transition /init_server
|
|
_init_server_0 = Transition(self, self.states["/init_server"], [self.states["/init_executor"]])
|
|
_init_server_0 = Transition(self, self.states["/init_server"], [self.states["/init_executor"]])
|
|
_init_server_0.setAction(self._init_server_0_exec)
|
|
_init_server_0.setAction(self._init_server_0_exec)
|
|
@@ -160,11 +142,17 @@ class MvKController(RuntimeClassBase):
|
|
self.states["/init_server"].addTransition(_init_server_0)
|
|
self.states["/init_server"].addTransition(_init_server_0)
|
|
|
|
|
|
# transition /init_executor
|
|
# transition /init_executor
|
|
- _init_executor_0 = Transition(self, self.states["/init_executor"], [self.states["/running"]])
|
|
|
|
|
|
+ _init_executor_0 = Transition(self, self.states["/init_executor"], [self.states["/read_root"]])
|
|
_init_executor_0.setAction(self._init_executor_0_exec)
|
|
_init_executor_0.setAction(self._init_executor_0_exec)
|
|
_init_executor_0.setTrigger(Event("instance_created", None))
|
|
_init_executor_0.setTrigger(Event("instance_created", None))
|
|
self.states["/init_executor"].addTransition(_init_executor_0)
|
|
self.states["/init_executor"].addTransition(_init_executor_0)
|
|
|
|
|
|
|
|
+ # transition /read_root
|
|
|
|
+ _read_root_0 = Transition(self, self.states["/read_root"], [self.states["/running"]])
|
|
|
|
+ _read_root_0.setAction(self._read_root_0_exec)
|
|
|
|
+ _read_root_0.setTrigger(Event("raw_exec_reply", None))
|
|
|
|
+ self.states["/read_root"].addTransition(_read_root_0)
|
|
|
|
+
|
|
# transition /running/wait_for_requests/wait
|
|
# transition /running/wait_for_requests/wait
|
|
_running_wait_for_requests_wait_0 = Transition(self, self.states["/running/wait_for_requests/wait"], [self.states["/running/wait_for_requests/wait"]])
|
|
_running_wait_for_requests_wait_0 = Transition(self, self.states["/running/wait_for_requests/wait"], [self.states["/running/wait_for_requests/wait"]])
|
|
_running_wait_for_requests_wait_0.setAction(self._running_wait_for_requests_wait_0_exec)
|
|
_running_wait_for_requests_wait_0.setAction(self._running_wait_for_requests_wait_0_exec)
|
|
@@ -197,7 +185,7 @@ class MvKController(RuntimeClassBase):
|
|
# transition /running/find_users/get_all_links
|
|
# transition /running/find_users/get_all_links
|
|
_running_find_users_get_all_links_0 = Transition(self, self.states["/running/find_users/get_all_links"], [self.states["/running/find_users/retrieve_users"]])
|
|
_running_find_users_get_all_links_0 = Transition(self, self.states["/running/find_users/get_all_links"], [self.states["/running/find_users/retrieve_users"]])
|
|
_running_find_users_get_all_links_0.setAction(self._running_find_users_get_all_links_0_exec)
|
|
_running_find_users_get_all_links_0.setAction(self._running_find_users_get_all_links_0_exec)
|
|
- _running_find_users_get_all_links_0.setTrigger(Event("HTTP_output", None))
|
|
|
|
|
|
+ _running_find_users_get_all_links_0.setTrigger(Event("raw_exec_reply", None))
|
|
self.states["/running/find_users/get_all_links"].addTransition(_running_find_users_get_all_links_0)
|
|
self.states["/running/find_users/get_all_links"].addTransition(_running_find_users_get_all_links_0)
|
|
|
|
|
|
# transition /running/find_users/retrieve_users
|
|
# transition /running/find_users/retrieve_users
|
|
@@ -214,7 +202,7 @@ class MvKController(RuntimeClassBase):
|
|
# transition /running/find_users/got_usernames
|
|
# transition /running/find_users/got_usernames
|
|
_running_find_users_got_usernames_0 = Transition(self, self.states["/running/find_users/got_usernames"], [self.states["/running/find_users/process_users"]])
|
|
_running_find_users_got_usernames_0 = Transition(self, self.states["/running/find_users/got_usernames"], [self.states["/running/find_users/process_users"]])
|
|
_running_find_users_got_usernames_0.setAction(self._running_find_users_got_usernames_0_exec)
|
|
_running_find_users_got_usernames_0.setAction(self._running_find_users_got_usernames_0_exec)
|
|
- _running_find_users_got_usernames_0.setTrigger(Event("HTTP_output", None))
|
|
|
|
|
|
+ _running_find_users_got_usernames_0.setTrigger(Event("raw_exec_reply", None))
|
|
self.states["/running/find_users/got_usernames"].addTransition(_running_find_users_got_usernames_0)
|
|
self.states["/running/find_users/got_usernames"].addTransition(_running_find_users_got_usernames_0)
|
|
|
|
|
|
# transition /running/find_users/process_users
|
|
# transition /running/find_users/process_users
|
|
@@ -242,17 +230,17 @@ class MvKController(RuntimeClassBase):
|
|
_running_find_users_wait_1.setTrigger(Event("force_user_refresh", None))
|
|
_running_find_users_wait_1.setTrigger(Event("force_user_refresh", None))
|
|
self.states["/running/find_users/wait"].addTransition(_running_find_users_wait_1)
|
|
self.states["/running/find_users/wait"].addTransition(_running_find_users_wait_1)
|
|
|
|
|
|
- def _init_enter(self):
|
|
|
|
- self.big_step.outputEventOM(Event("create_instance", None, [self, 'to_mvs', 'LocalMvS', self.params]))
|
|
|
|
-
|
|
|
|
def _init_server_enter(self):
|
|
def _init_server_enter(self):
|
|
self.big_step.outputEventOM(Event("create_instance", None, [self, 'to_mvi', 'Server', '', 8001]))
|
|
self.big_step.outputEventOM(Event("create_instance", None, [self, 'to_mvi', 'Server', '', 8001]))
|
|
|
|
|
|
def _init_executor_enter(self):
|
|
def _init_executor_enter(self):
|
|
- self.big_step.outputEventOM(Event("create_instance", None, [self, 'executor', 'Executor', self.mvk]))
|
|
|
|
|
|
+ self.big_step.outputEventOM(Event("create_instance", None, [self, 'executor', 'Executor']))
|
|
|
|
+
|
|
|
|
+ def _read_root_enter(self):
|
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'executor', Event("raw_exec", None, [[['RR', []]], 'parent'])]))
|
|
|
|
|
|
def _running_find_users_get_all_links_enter(self):
|
|
def _running_find_users_get_all_links_enter(self):
|
|
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'to_mvs', Event("HTTP_input", None, ['requests=%s' % json.dumps([['RDK', [self.mvk.root]]]), 'parent'])]))
|
|
|
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'executor', Event("raw_exec", None, [[['RDK', [self.root]]], 'parent'])]))
|
|
|
|
|
|
def _running_find_users_wait_enter(self):
|
|
def _running_find_users_wait_enter(self):
|
|
self.addTimer(0, 1.0)
|
|
self.addTimer(0, 1.0)
|
|
@@ -260,19 +248,6 @@ class MvKController(RuntimeClassBase):
|
|
def _running_find_users_wait_exit(self):
|
|
def _running_find_users_wait_exit(self):
|
|
self.removeTimer(0)
|
|
self.removeTimer(0)
|
|
|
|
|
|
- def _init_0_exec(self, parameters):
|
|
|
|
- instancename = parameters[0]
|
|
|
|
- self.big_step.outputEventOM(Event("start_instance", None, [self, instancename]))
|
|
|
|
-
|
|
|
|
- def _get_root_0_exec(self, parameters):
|
|
|
|
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'to_mvs', Event("HTTP_input", None, ['requests=%s' % json.dumps([['RR', []]]), 'parent'])]))
|
|
|
|
-
|
|
|
|
- def _get_root_1_exec(self, parameters):
|
|
|
|
- data = parameters[0]
|
|
|
|
- self.mvk = ModelverseKernel(json.loads(data["data"])[0][0])
|
|
|
|
- self.mvk_next_op = "load_primitives"
|
|
|
|
- self.mvk_params = []
|
|
|
|
-
|
|
|
|
def _init_server_0_exec(self, parameters):
|
|
def _init_server_0_exec(self, parameters):
|
|
instancename = parameters[0]
|
|
instancename = parameters[0]
|
|
self.big_step.outputEventOM(Event("start_instance", None, [self, instancename]))
|
|
self.big_step.outputEventOM(Event("start_instance", None, [self, instancename]))
|
|
@@ -281,6 +256,10 @@ class MvKController(RuntimeClassBase):
|
|
instancename = parameters[0]
|
|
instancename = parameters[0]
|
|
self.big_step.outputEventOM(Event("start_instance", None, [self, instancename]))
|
|
self.big_step.outputEventOM(Event("start_instance", None, [self, instancename]))
|
|
|
|
|
|
|
|
+ def _read_root_0_exec(self, parameters):
|
|
|
|
+ data = parameters[0]
|
|
|
|
+ self.root = data[0][0]
|
|
|
|
+
|
|
def _running_wait_for_requests_wait_0_exec(self, parameters):
|
|
def _running_wait_for_requests_wait_0_exec(self, parameters):
|
|
source = parameters[0]
|
|
source = parameters[0]
|
|
data = parameters[1]
|
|
data = parameters[1]
|
|
@@ -325,10 +304,12 @@ class MvKController(RuntimeClassBase):
|
|
|
|
|
|
def _running_find_users_get_all_links_0_exec(self, parameters):
|
|
def _running_find_users_get_all_links_0_exec(self, parameters):
|
|
data = parameters[0]
|
|
data = parameters[0]
|
|
- self.users = json.loads(data["data"])[0][0]
|
|
|
|
|
|
+ print("Root: " + str(self.root))
|
|
|
|
+ print("Users: " + str(data))
|
|
|
|
+ self.users = data[0][0]
|
|
|
|
|
|
def _running_find_users_retrieve_users_0_exec(self, parameters):
|
|
def _running_find_users_retrieve_users_0_exec(self, parameters):
|
|
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'to_mvs', Event("HTTP_input", None, ['requests=%s' % json.dumps([['RV', [user]] for user in self.users]), 'parent'])]))
|
|
|
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'executor', Event("raw_exec", None, [[['RV', [user]] for user in self.users], 'parent'])]))
|
|
|
|
|
|
def _running_find_users_retrieve_users_0_guard(self, parameters):
|
|
def _running_find_users_retrieve_users_0_guard(self, parameters):
|
|
return self.users
|
|
return self.users
|
|
@@ -338,7 +319,8 @@ class MvKController(RuntimeClassBase):
|
|
|
|
|
|
def _running_find_users_got_usernames_0_exec(self, parameters):
|
|
def _running_find_users_got_usernames_0_exec(self, parameters):
|
|
data = parameters[0]
|
|
data = parameters[0]
|
|
- self.users = [v[0] for v in json.loads(data["data"]) if v[0] not in self.user_statecharts]
|
|
|
|
|
|
+ self.users = [v[0] for v in data if v[0] not in self.user_statecharts]
|
|
|
|
+ print("EXPANDED Users: " + str(data))
|
|
|
|
|
|
def _running_find_users_process_users_0_guard(self, parameters):
|
|
def _running_find_users_process_users_0_guard(self, parameters):
|
|
return not self.users
|
|
return not self.users
|
|
@@ -361,7 +343,7 @@ class MvKController(RuntimeClassBase):
|
|
|
|
|
|
def initializeStatechart(self):
|
|
def initializeStatechart(self):
|
|
# enter default state
|
|
# enter default state
|
|
- self.default_targets = self.states["/init"].getEffectiveTargetStates()
|
|
|
|
|
|
+ self.default_targets = self.states["/init_server"].getEffectiveTargetStates()
|
|
RuntimeClassBase.initializeStatechart(self)
|
|
RuntimeClassBase.initializeStatechart(self)
|
|
|
|
|
|
class Server(RuntimeClassBase):
|
|
class Server(RuntimeClassBase):
|
|
@@ -1084,111 +1066,6 @@ class HTTPClient(RuntimeClassBase):
|
|
self.default_targets = self.states["/init"].getEffectiveTargetStates()
|
|
self.default_targets = self.states["/init"].getEffectiveTargetStates()
|
|
RuntimeClassBase.initializeStatechart(self)
|
|
RuntimeClassBase.initializeStatechart(self)
|
|
|
|
|
|
-class LocalMvS(RuntimeClassBase):
|
|
|
|
- def __init__(self, controller, params):
|
|
|
|
- RuntimeClassBase.__init__(self, controller)
|
|
|
|
-
|
|
|
|
- self.semantics.big_step_maximality = StatechartSemantics.TakeMany
|
|
|
|
- self.semantics.internal_event_lifeline = StatechartSemantics.Queue
|
|
|
|
- self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
|
|
|
|
- self.semantics.priority = StatechartSemantics.SourceParent
|
|
|
|
- self.semantics.concurrency = StatechartSemantics.Single
|
|
|
|
-
|
|
|
|
- # build Statechart structure
|
|
|
|
- self.build_statechart_structure()
|
|
|
|
-
|
|
|
|
- # call user defined constructor
|
|
|
|
- LocalMvS.user_defined_constructor(self, params)
|
|
|
|
-
|
|
|
|
- def user_defined_constructor(self, params):
|
|
|
|
- self.queue = []
|
|
|
|
- self.destinations = []
|
|
|
|
- import sys
|
|
|
|
- sys.path.append("../../state")
|
|
|
|
- from modelverse_state.main import ModelverseState
|
|
|
|
- self.mvs = ModelverseState("../../bootstrap/bootstrap.m.gz")
|
|
|
|
- self.mvs_operations = {
|
|
|
|
- "CN": self.mvs.create_node,
|
|
|
|
- "CE": self.mvs.create_edge,
|
|
|
|
- "CNV": self.mvs.create_nodevalue,
|
|
|
|
- "CD": self.mvs.create_dict,
|
|
|
|
-
|
|
|
|
- "RV": self.mvs.read_value,
|
|
|
|
- "RO": self.mvs.read_outgoing,
|
|
|
|
- "RI": self.mvs.read_incoming,
|
|
|
|
- "RE": self.mvs.read_edge,
|
|
|
|
- "RD": self.mvs.read_dict,
|
|
|
|
- "RDN": self.mvs.read_dict_node,
|
|
|
|
- "RDNE": self.mvs.read_dict_node_edge,
|
|
|
|
- "RDE": self.mvs.read_dict_edge,
|
|
|
|
- "RRD": self.mvs.read_reverse_dict,
|
|
|
|
- "RR": self.mvs.read_root,
|
|
|
|
- "RDK": self.mvs.read_dict_keys,
|
|
|
|
-
|
|
|
|
- "DE": self.mvs.delete_edge,
|
|
|
|
- "DN": self.mvs.delete_node,
|
|
|
|
-
|
|
|
|
- "DUMP": self.mvs.dump_modelverse,
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- def user_defined_destructor(self):
|
|
|
|
- pass
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- # user defined method
|
|
|
|
- def process_message(self, operation_name, parameters):
|
|
|
|
- op = self.mvs_operations[operation_name]
|
|
|
|
- return op(*parameters)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- # builds Statechart structure
|
|
|
|
- def build_statechart_structure(self):
|
|
|
|
-
|
|
|
|
- # state <root>
|
|
|
|
- self.states[""] = State(0, self)
|
|
|
|
-
|
|
|
|
- # state /init
|
|
|
|
- self.states["/init"] = State(1, self)
|
|
|
|
-
|
|
|
|
- # state /running
|
|
|
|
- self.states["/running"] = State(2, self)
|
|
|
|
-
|
|
|
|
- # add children
|
|
|
|
- self.states[""].addChild(self.states["/init"])
|
|
|
|
- self.states[""].addChild(self.states["/running"])
|
|
|
|
- self.states[""].fixTree()
|
|
|
|
- self.states[""].default_state = self.states["/init"]
|
|
|
|
-
|
|
|
|
- # transition /init
|
|
|
|
- _init_0 = Transition(self, self.states["/init"], [self.states["/running"]])
|
|
|
|
- _init_0.setAction(self._init_0_exec)
|
|
|
|
- _init_0.setTrigger(None)
|
|
|
|
- self.states["/init"].addTransition(_init_0)
|
|
|
|
-
|
|
|
|
- # transition /running
|
|
|
|
- _running_0 = Transition(self, self.states["/running"], [self.states["/running"]])
|
|
|
|
- _running_0.setAction(self._running_0_exec)
|
|
|
|
- _running_0.setTrigger(Event("HTTP_input", None))
|
|
|
|
- self.states["/running"].addTransition(_running_0)
|
|
|
|
-
|
|
|
|
- def _init_0_exec(self, parameters):
|
|
|
|
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("http_client_ready", None, [])]))
|
|
|
|
-
|
|
|
|
- def _running_0_exec(self, parameters):
|
|
|
|
- data = parameters[0]
|
|
|
|
- destination = parameters[1]
|
|
|
|
- decoded_data = json.loads(data.split("=",1)[1])
|
|
|
|
- result = []
|
|
|
|
- for command, params in decoded_data:
|
|
|
|
- result.append(self.process_message(command, params))
|
|
|
|
- data = {"data": json.dumps(result)}
|
|
|
|
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, destination, Event("HTTP_output", None, [data])]))
|
|
|
|
-
|
|
|
|
- def initializeStatechart(self):
|
|
|
|
- # enter default state
|
|
|
|
- self.default_targets = self.states["/init"].getEffectiveTargetStates()
|
|
|
|
- RuntimeClassBase.initializeStatechart(self)
|
|
|
|
-
|
|
|
|
class UserStatechart(RuntimeClassBase):
|
|
class UserStatechart(RuntimeClassBase):
|
|
def __init__(self, controller, username):
|
|
def __init__(self, controller, username):
|
|
RuntimeClassBase.__init__(self, controller)
|
|
RuntimeClassBase.__init__(self, controller)
|
|
@@ -1207,6 +1084,7 @@ class UserStatechart(RuntimeClassBase):
|
|
|
|
|
|
def user_defined_constructor(self, username):
|
|
def user_defined_constructor(self, username):
|
|
self.username = username
|
|
self.username = username
|
|
|
|
+ print("INIT " + self.username)
|
|
|
|
|
|
self.output_queue = []
|
|
self.output_queue = []
|
|
self.source_execution = None
|
|
self.source_execution = None
|
|
@@ -1352,6 +1230,7 @@ class UserStatechart(RuntimeClassBase):
|
|
|
|
|
|
def _running_execution_init_enter(self):
|
|
def _running_execution_init_enter(self):
|
|
self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent/executor', Event("execute", None, [self.returnpath, self.username, 'execute_rule', [], self.request_id])]))
|
|
self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent/executor', Event("execute", None, [self.returnpath, self.username, 'execute_rule', [], self.request_id])]))
|
|
|
|
+ print("Raise execute event!")
|
|
self.outstanding_execution = self.request_id
|
|
self.outstanding_execution = self.request_id
|
|
self.request_id += 1
|
|
self.request_id += 1
|
|
|
|
|
|
@@ -1449,7 +1328,7 @@ class UserStatechart(RuntimeClassBase):
|
|
RuntimeClassBase.initializeStatechart(self)
|
|
RuntimeClassBase.initializeStatechart(self)
|
|
|
|
|
|
class Executor(RuntimeClassBase):
|
|
class Executor(RuntimeClassBase):
|
|
- def __init__(self, controller, mvk):
|
|
|
|
|
|
+ def __init__(self, controller):
|
|
RuntimeClassBase.__init__(self, controller)
|
|
RuntimeClassBase.__init__(self, controller)
|
|
|
|
|
|
self.semantics.big_step_maximality = StatechartSemantics.TakeMany
|
|
self.semantics.big_step_maximality = StatechartSemantics.TakeMany
|
|
@@ -1462,13 +1341,37 @@ class Executor(RuntimeClassBase):
|
|
self.build_statechart_structure()
|
|
self.build_statechart_structure()
|
|
|
|
|
|
# call user defined constructor
|
|
# call user defined constructor
|
|
- Executor.user_defined_constructor(self, mvk)
|
|
|
|
|
|
+ Executor.user_defined_constructor(self)
|
|
|
|
|
|
- def user_defined_constructor(self, mvk):
|
|
|
|
|
|
+ def user_defined_constructor(self):
|
|
|
|
+ self.mvs = ModelverseState("../../bootstrap/bootstrap.m.gz")
|
|
self.request_queue = [("", "", "load_primitives", [], None)]
|
|
self.request_queue = [("", "", "load_primitives", [], None)]
|
|
- self.mvk = mvk
|
|
|
|
|
|
+ self.mvs.GC = True
|
|
|
|
+ self.mvk = ModelverseKernel(self.mvs.read_root()[0])
|
|
self.first = True
|
|
self.first = True
|
|
self.mvs_response = None
|
|
self.mvs_response = None
|
|
|
|
+
|
|
|
|
+ self.mvs_operations = {
|
|
|
|
+ "CN": self.mvs.create_node,
|
|
|
|
+ "CE": self.mvs.create_edge,
|
|
|
|
+ "CNV": self.mvs.create_nodevalue,
|
|
|
|
+ "CD": self.mvs.create_dict,
|
|
|
|
+
|
|
|
|
+ "RV": self.mvs.read_value,
|
|
|
|
+ "RO": self.mvs.read_outgoing,
|
|
|
|
+ "RI": self.mvs.read_incoming,
|
|
|
|
+ "RE": self.mvs.read_edge,
|
|
|
|
+ "RD": self.mvs.read_dict,
|
|
|
|
+ "RDN": self.mvs.read_dict_node,
|
|
|
|
+ "RDNE": self.mvs.read_dict_node_edge,
|
|
|
|
+ "RDE": self.mvs.read_dict_edge,
|
|
|
|
+ "RRD": self.mvs.read_reverse_dict,
|
|
|
|
+ "RR": self.mvs.read_root,
|
|
|
|
+ "RDK": self.mvs.read_dict_keys,
|
|
|
|
+
|
|
|
|
+ "DE": self.mvs.delete_edge,
|
|
|
|
+ "DN": self.mvs.delete_node,
|
|
|
|
+ }
|
|
|
|
|
|
def user_defined_destructor(self):
|
|
def user_defined_destructor(self):
|
|
pass
|
|
pass
|
|
@@ -1483,41 +1386,50 @@ class Executor(RuntimeClassBase):
|
|
# state /init
|
|
# state /init
|
|
self.states["/init"] = ParallelState(1, self)
|
|
self.states["/init"] = ParallelState(1, self)
|
|
|
|
|
|
|
|
+ # state /init/raw_exec
|
|
|
|
+ self.states["/init/raw_exec"] = State(2, self)
|
|
|
|
+
|
|
|
|
+ # state /init/raw_exec/raw_exec
|
|
|
|
+ self.states["/init/raw_exec/raw_exec"] = State(3, self)
|
|
|
|
+
|
|
# state /init/queue
|
|
# state /init/queue
|
|
- self.states["/init/queue"] = State(2, self)
|
|
|
|
|
|
+ self.states["/init/queue"] = State(4, self)
|
|
|
|
|
|
# state /init/queue/queue
|
|
# state /init/queue/queue
|
|
- self.states["/init/queue/queue"] = State(3, self)
|
|
|
|
|
|
+ self.states["/init/queue/queue"] = State(5, self)
|
|
|
|
|
|
# state /init/execute
|
|
# state /init/execute
|
|
- self.states["/init/execute"] = State(4, self)
|
|
|
|
|
|
+ self.states["/init/execute"] = State(6, self)
|
|
|
|
|
|
# state /init/execute/idle
|
|
# state /init/execute/idle
|
|
- self.states["/init/execute/idle"] = State(5, self)
|
|
|
|
|
|
+ self.states["/init/execute/idle"] = State(7, self)
|
|
self.states["/init/execute/idle"].setEnter(self._init_execute_idle_enter)
|
|
self.states["/init/execute/idle"].setEnter(self._init_execute_idle_enter)
|
|
|
|
|
|
# state /init/execute/execution
|
|
# state /init/execute/execution
|
|
- self.states["/init/execute/execution"] = State(6, self)
|
|
|
|
|
|
+ self.states["/init/execute/execution"] = State(8, self)
|
|
self.states["/init/execute/execution"].setEnter(self._init_execute_execution_enter)
|
|
self.states["/init/execute/execution"].setEnter(self._init_execute_execution_enter)
|
|
|
|
|
|
- # state /init/execute/waiting_for_response
|
|
|
|
- self.states["/init/execute/waiting_for_response"] = State(7, self)
|
|
|
|
- self.states["/init/execute/waiting_for_response"].setEnter(self._init_execute_waiting_for_response_enter)
|
|
|
|
- self.states["/init/execute/waiting_for_response"].setExit(self._init_execute_waiting_for_response_exit)
|
|
|
|
-
|
|
|
|
# add children
|
|
# add children
|
|
self.states[""].addChild(self.states["/init"])
|
|
self.states[""].addChild(self.states["/init"])
|
|
|
|
+ self.states["/init"].addChild(self.states["/init/raw_exec"])
|
|
self.states["/init"].addChild(self.states["/init/queue"])
|
|
self.states["/init"].addChild(self.states["/init/queue"])
|
|
self.states["/init"].addChild(self.states["/init/execute"])
|
|
self.states["/init"].addChild(self.states["/init/execute"])
|
|
|
|
+ self.states["/init/raw_exec"].addChild(self.states["/init/raw_exec/raw_exec"])
|
|
self.states["/init/queue"].addChild(self.states["/init/queue/queue"])
|
|
self.states["/init/queue"].addChild(self.states["/init/queue/queue"])
|
|
self.states["/init/execute"].addChild(self.states["/init/execute/idle"])
|
|
self.states["/init/execute"].addChild(self.states["/init/execute/idle"])
|
|
self.states["/init/execute"].addChild(self.states["/init/execute/execution"])
|
|
self.states["/init/execute"].addChild(self.states["/init/execute/execution"])
|
|
- self.states["/init/execute"].addChild(self.states["/init/execute/waiting_for_response"])
|
|
|
|
self.states[""].fixTree()
|
|
self.states[""].fixTree()
|
|
self.states[""].default_state = self.states["/init"]
|
|
self.states[""].default_state = self.states["/init"]
|
|
|
|
+ self.states["/init/raw_exec"].default_state = self.states["/init/raw_exec/raw_exec"]
|
|
self.states["/init/queue"].default_state = self.states["/init/queue/queue"]
|
|
self.states["/init/queue"].default_state = self.states["/init/queue/queue"]
|
|
self.states["/init/execute"].default_state = self.states["/init/execute/idle"]
|
|
self.states["/init/execute"].default_state = self.states["/init/execute/idle"]
|
|
|
|
|
|
|
|
+ # transition /init/raw_exec/raw_exec
|
|
|
|
+ _init_raw_exec_raw_exec_0 = Transition(self, self.states["/init/raw_exec/raw_exec"], [self.states["/init/raw_exec/raw_exec"]])
|
|
|
|
+ _init_raw_exec_raw_exec_0.setAction(self._init_raw_exec_raw_exec_0_exec)
|
|
|
|
+ _init_raw_exec_raw_exec_0.setTrigger(Event("raw_exec", None))
|
|
|
|
+ self.states["/init/raw_exec/raw_exec"].addTransition(_init_raw_exec_raw_exec_0)
|
|
|
|
+
|
|
# transition /init/queue/queue
|
|
# transition /init/queue/queue
|
|
_init_queue_queue_0 = Transition(self, self.states["/init/queue/queue"], [self.states["/init/queue/queue"]])
|
|
_init_queue_queue_0 = Transition(self, self.states["/init/queue/queue"], [self.states["/init/queue/queue"]])
|
|
_init_queue_queue_0.setAction(self._init_queue_queue_0_exec)
|
|
_init_queue_queue_0.setAction(self._init_queue_queue_0_exec)
|
|
@@ -1534,47 +1446,27 @@ class Executor(RuntimeClassBase):
|
|
_init_execute_execution_0 = Transition(self, self.states["/init/execute/execution"], [self.states["/init/execute/idle"]])
|
|
_init_execute_execution_0 = Transition(self, self.states["/init/execute/execution"], [self.states["/init/execute/idle"]])
|
|
_init_execute_execution_0.setAction(self._init_execute_execution_0_exec)
|
|
_init_execute_execution_0.setAction(self._init_execute_execution_0_exec)
|
|
_init_execute_execution_0.setTrigger(None)
|
|
_init_execute_execution_0.setTrigger(None)
|
|
- _init_execute_execution_0.setGuard(self._init_execute_execution_0_guard)
|
|
|
|
self.states["/init/execute/execution"].addTransition(_init_execute_execution_0)
|
|
self.states["/init/execute/execution"].addTransition(_init_execute_execution_0)
|
|
- _init_execute_execution_1 = Transition(self, self.states["/init/execute/execution"], [self.states["/init/execute/waiting_for_response"]])
|
|
|
|
- _init_execute_execution_1.setAction(self._init_execute_execution_1_exec)
|
|
|
|
- _init_execute_execution_1.setTrigger(None)
|
|
|
|
- _init_execute_execution_1.setGuard(self._init_execute_execution_1_guard)
|
|
|
|
- self.states["/init/execute/execution"].addTransition(_init_execute_execution_1)
|
|
|
|
- _init_execute_execution_2 = Transition(self, self.states["/init/execute/execution"], [self.states["/init/execute/execution"]])
|
|
|
|
- _init_execute_execution_2.setAction(self._init_execute_execution_2_exec)
|
|
|
|
- _init_execute_execution_2.setTrigger(None)
|
|
|
|
- _init_execute_execution_2.setGuard(self._init_execute_execution_2_guard)
|
|
|
|
- self.states["/init/execute/execution"].addTransition(_init_execute_execution_2)
|
|
|
|
-
|
|
|
|
- # transition /init/execute/waiting_for_response
|
|
|
|
- _init_execute_waiting_for_response_0 = Transition(self, self.states["/init/execute/waiting_for_response"], [self.states["/init/execute/execution"]])
|
|
|
|
- _init_execute_waiting_for_response_0.setAction(self._init_execute_waiting_for_response_0_exec)
|
|
|
|
- _init_execute_waiting_for_response_0.setTrigger(Event("HTTP_output", None))
|
|
|
|
- self.states["/init/execute/waiting_for_response"].addTransition(_init_execute_waiting_for_response_0)
|
|
|
|
|
|
|
|
def _init_execute_idle_enter(self):
|
|
def _init_execute_idle_enter(self):
|
|
print 'in idle'
|
|
print 'in idle'
|
|
|
|
|
|
def _init_execute_execution_enter(self):
|
|
def _init_execute_execution_enter(self):
|
|
- try:
|
|
|
|
- _, username, operation, params, _ = self.request_queue[0]
|
|
|
|
- print 'executing %s %s' % (operation, params)
|
|
|
|
- self.mvs_commands = self.mvk.execute_yields(username, operation, params, self.mvs_response)
|
|
|
|
- except:
|
|
|
|
- import traceback
|
|
|
|
- traceback.print_exc()
|
|
|
|
- print("Exec error")
|
|
|
|
- #TODO for debugging
|
|
|
|
- sys.exit(0)
|
|
|
|
-
|
|
|
|
- self.mvs_commands = None
|
|
|
|
-
|
|
|
|
- def _init_execute_waiting_for_response_enter(self):
|
|
|
|
- print 'entering waiting_for_response'
|
|
|
|
-
|
|
|
|
- def _init_execute_waiting_for_response_exit(self):
|
|
|
|
- print 'leaving waiting_for_response'
|
|
|
|
|
|
+ _, username, operation, params, _ = self.request_queue[0]
|
|
|
|
+ reply = None
|
|
|
|
+ commands = []
|
|
|
|
+ print("Execute operation: " + operation)
|
|
|
|
+ while 1:
|
|
|
|
+ commands = self.mvk.execute_yields(username, operation, params, reply)
|
|
|
|
+ if commands is None:
|
|
|
|
+ break
|
|
|
|
+ reply = [self.mvs_operations[command[0]](*(command[1]))[0] for command in commands]
|
|
|
|
+
|
|
|
|
+ def _init_raw_exec_raw_exec_0_exec(self, parameters):
|
|
|
|
+ operations = parameters[0]
|
|
|
|
+ source = parameters[1]
|
|
|
|
+ reply = [self.mvs_operations[command[0]](*command[1]) for command in operations]
|
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, source, Event("raw_exec_reply", None, [reply])]))
|
|
|
|
|
|
def _init_queue_queue_0_exec(self, parameters):
|
|
def _init_queue_queue_0_exec(self, parameters):
|
|
returnpath = parameters[0]
|
|
returnpath = parameters[0]
|
|
@@ -1590,31 +1482,12 @@ class Executor(RuntimeClassBase):
|
|
|
|
|
|
def _init_execute_execution_0_exec(self, parameters):
|
|
def _init_execute_execution_0_exec(self, parameters):
|
|
returnpath, _, _, _, request_id = self.request_queue.pop(0)
|
|
returnpath, _, _, _, request_id = self.request_queue.pop(0)
|
|
- self.mvs_response = None
|
|
|
|
self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent' + returnpath, Event("executed", None, [self.mvk.returnvalue, self.mvk.success, request_id])]))
|
|
self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent' + returnpath, Event("executed", None, [self.mvk.returnvalue, self.mvk.success, request_id])]))
|
|
|
|
+ print("Executed action --> " + str(self.mvk.returnvalue))
|
|
self.mvk.returnvalue = None
|
|
self.mvk.returnvalue = None
|
|
self.mvk.success = True
|
|
self.mvk.success = True
|
|
self.first = True
|
|
self.first = True
|
|
|
|
|
|
- def _init_execute_execution_0_guard(self, parameters):
|
|
|
|
- return self.mvs_commands is None
|
|
|
|
-
|
|
|
|
- def _init_execute_execution_1_exec(self, parameters):
|
|
|
|
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent/to_mvs', Event("HTTP_input", None, ['requests=%s' % json.dumps(self.mvs_commands), 'parent/executor'])]))
|
|
|
|
-
|
|
|
|
- def _init_execute_execution_1_guard(self, parameters):
|
|
|
|
- return self.mvs_commands is not None and len(self.mvs_commands) > 0
|
|
|
|
-
|
|
|
|
- def _init_execute_execution_2_exec(self, parameters):
|
|
|
|
- self.mvs_response = []
|
|
|
|
-
|
|
|
|
- def _init_execute_execution_2_guard(self, parameters):
|
|
|
|
- return self.mvs_commands is not None and len(self.mvs_commands) == 0
|
|
|
|
-
|
|
|
|
- def _init_execute_waiting_for_response_0_exec(self, parameters):
|
|
|
|
- data = parameters[0]
|
|
|
|
- self.mvs_response = [v[0] for v in json.loads(data["data"])]
|
|
|
|
-
|
|
|
|
def initializeStatechart(self):
|
|
def initializeStatechart(self):
|
|
# enter default state
|
|
# enter default state
|
|
self.default_targets = self.states["/init"].getEffectiveTargetStates()
|
|
self.default_targets = self.states["/init"].getEffectiveTargetStates()
|
|
@@ -1645,16 +1518,12 @@ class ObjectManager(ObjectManagerBase):
|
|
instance = HTTPClient(self.controller, construct_params[0], construct_params[1])
|
|
instance = HTTPClient(self.controller, construct_params[0], construct_params[1])
|
|
instance.associations = {}
|
|
instance.associations = {}
|
|
instance.associations["parent"] = Association("MvKController", 1, 1)
|
|
instance.associations["parent"] = Association("MvKController", 1, 1)
|
|
- elif class_name == "LocalMvS":
|
|
|
|
- instance = LocalMvS(self.controller, construct_params[0])
|
|
|
|
- instance.associations = {}
|
|
|
|
- instance.associations["parent"] = Association("MvKController", 1, 1)
|
|
|
|
elif class_name == "UserStatechart":
|
|
elif class_name == "UserStatechart":
|
|
instance = UserStatechart(self.controller, construct_params[0])
|
|
instance = UserStatechart(self.controller, construct_params[0])
|
|
instance.associations = {}
|
|
instance.associations = {}
|
|
instance.associations["parent"] = Association("MvKController", 1, 1)
|
|
instance.associations["parent"] = Association("MvKController", 1, 1)
|
|
elif class_name == "Executor":
|
|
elif class_name == "Executor":
|
|
- instance = Executor(self.controller, construct_params[0])
|
|
|
|
|
|
+ instance = Executor(self.controller)
|
|
instance.associations = {}
|
|
instance.associations = {}
|
|
instance.associations["parent"] = Association("MvKController", 1, 1)
|
|
instance.associations["parent"] = Association("MvKController", 1, 1)
|
|
else:
|
|
else:
|