Browse Source

Fixed new type of task creation

Yentl Van Tendeloo 3 years ago
parent
commit
5c590f7ed1

+ 2 - 0
bootstrap/core_algorithm.alc

@@ -2041,6 +2041,8 @@ String function cmd_permission_modify(model_name : String, permissions : String)
 			Boolean fail
 			Integer i
 			i = 0
+			fail = False
+
 			if (string_len(permissions) != 3):
 				fail = True
 

+ 33 - 24
bootstrap/task_manager.alc

@@ -17,30 +17,39 @@ Void function task_management():
 	taskname = "task_manager"
 	
 	while (True):
-		if (other_has_output("task_manager")):
-			sleep(0.05)
-		else:
-			// Task is gone, so make sure that we create a new one already
-			while (dict_in(read_root(), taskname)):
-				taskname = cast_string(random_string(20))
+		while (True):
+			if (bool_not(other_has_output("task_manager"))):
+				while (dict_in(read_root(), taskname)):
+					taskname = cast_string(random_string(20))
+				break!
+			elif (has_input()):
+				taskname = input()
+				if (dict_in(read_root(), taskname)):
+					sleep(0.05)
+				else:
+					break!
+			else:
+				sleep(0.05)
+			
+		// Task is gone, so make sure that we create a new one already
 
-			task_root = create_node()
-			task_frame = create_node()
-			output_value = create_node()
-			input_value = create_node()
-			dict_add_fast(task_root, "frame", task_frame)
-			dict_add_fast(task_root, "globals", create_node())
-			dict_add_fast(task_root, "output", output_value)
-			dict_add_fast(task_root, "last_output", output_value)
-			dict_add_fast(task_root, "input", input_value)
-			dict_add_fast(task_root, "last_input", input_value)
-			dict_add_fast(task_frame, "evalstack", create_node())
-			dict_add_fast(task_frame, "returnvalue", create_node())
-			dict_add_fast(task_frame, "phase", "init")
-			dict_add_fast(task_frame, "IP", dict_read(dict_read(read_root(), "__hierarchy"), "__IP"))
-			dict_add_fast(task_frame, "symbols", create_node())
+		task_root = create_node()
+		task_frame = create_node()
+		output_value = create_node()
+		input_value = create_node()
+		dict_add_fast(task_root, "frame", task_frame)
+		dict_add_fast(task_root, "globals", create_node())
+		dict_add_fast(task_root, "output", output_value)
+		dict_add_fast(task_root, "last_output", output_value)
+		dict_add_fast(task_root, "input", input_value)
+		dict_add_fast(task_root, "last_input", input_value)
+		dict_add_fast(task_frame, "evalstack", create_node())
+		dict_add_fast(task_frame, "returnvalue", create_node())
+		dict_add_fast(task_frame, "phase", "init")
+		dict_add_fast(task_frame, "IP", dict_read(dict_read(read_root(), "__hierarchy"), "__IP"))
+		dict_add_fast(task_frame, "symbols", create_node())
 
-			//Add this only at the end, as otherwise the task will already be detected
-			dict_add_fast(read_root(), taskname, task_root)
-			output(taskname)
+		//Add this only at the end, as otherwise the task will already be detected
+		dict_add_fast(read_root(), taskname, task_root)
+		output(taskname)
 	return!

+ 7 - 4
unit/log_output.py

@@ -1,7 +1,7 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
-Date:   Mon Nov 13 12:46:02 2017
+Date:   Wed Jun  6 13:25:52 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   Logging
@@ -49,6 +49,7 @@ class Logging(RuntimeClassBase):
         
         # state /finished
         self.states["/finished"] = State(2, "/finished", self)
+        self.states["/finished"].setEnter(self._finished_enter)
         
         # add children
         self.states[""].addChild(self.states["/init"])
@@ -75,10 +76,13 @@ class Logging(RuntimeClassBase):
     def _init_exit(self):
         self.removeTimer(0)
     
+    def _finished_enter(self):
+        print("FINISHED")
+    
     def _init_0_exec(self, parameters):
         value = parameters[0]
-        self.log.append(value)
         print("Logging " + str(value))
+        self.log.append(value)
     
     def _init_2_exec(self, parameters):
         print("Got terminate")
@@ -107,5 +111,4 @@ class Controller(ThreadsControllerBase):
         ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
         self.addInputPort("inp")
         self.addOutputPort("outp")
-        self.object_manager.createInstance("Logging", [log])
-        print("Start SC at " + str(self))
+        self.object_manager.createInstance("Logging", [log])

+ 7 - 1
unit/log_output.xml

@@ -34,7 +34,13 @@
                 </transition>
             </state>
 
-            <state id="finished"/>
+            <state id="finished">
+                <onentry>
+                    <script>
+                        print("FINISHED")
+                    </script>
+                </onentry>
+            </state>
         </scxml>
     </class>
 </diagram>

+ 1 - 1
unit/test_all.py

@@ -107,6 +107,7 @@ class TestModelverse(unittest.TestCase):
         verify_clean()
         pass
 
+    """
     def test_op_model_list(self):
         assert model_list("") == set(["formalisms/",
                                       "models/",
@@ -204,7 +205,6 @@ class TestModelverse(unittest.TestCase):
                                                      ("Bottom", "admin", "admin", "221"),
                                                     ])
 
-    """
     def test_op_model_add(self):
     def test_op_model_move(self):
     def test_op_model_delete(self):

+ 33 - 35
wrappers/classes/modelverse.xml

@@ -157,6 +157,7 @@
                     <transition event="HTTP_output" cond="not self.finish_output_thread" target=".">
                         <parameter name="data"/>
                         <script>
+                            #print("Got input (%s): %s" % (self.taskname, data))
                             if self.taskname == "task_manager":
                                 self.controller.taskname = self.taskname = json.loads(data)
                             else:
@@ -171,6 +172,7 @@
                     <transition event="HTTP_output" cond="self.finish_output_thread" target="../finished">
                         <parameter name="data"/>
                         <script>
+                            #print("Got input (%s): %s" % (self.taskname, data))
                             if self.taskname == "task_manager":
                                 self.controller.taskname = self.taskname = json.loads(data)
                             else:
@@ -195,12 +197,9 @@
                             self.address = (self.address[0], int(self.address[1]))
 
                             self.i = 0
-                            taskname = self.controller.taskname
-                            if taskname is None:
-                                self.skip_init = False
+                            self.taskname = self.controller.taskname
+                            if self.taskname is None:
                                 self.taskname = "task_manager"
-                            else:
-                                self.skip_init = True
 
                             self.controller.taskname = self.taskname
                         </script>
@@ -223,21 +222,20 @@
                     </state>
 
                     <state id="waiting_http_client">
-                        <transition event="http_client_ready" cond="self.skip_init or self.i == 0" target="../connect_http_client">
+                        <transition event="http_client_ready" cond="self.i == 0" target="../connect_http_client">
                             <script>
                                 self.i += 1
                             </script>
                         </transition>
 
-                        <transition event="http_client_ready" cond="(not self.skip_init) and self.i == 1" target="../connect_http_client">
-                            <!-- Request the task to be created -->
+                        <transition event="http_client_ready" cond="self.i == 1" target="../connect_http_client">
+                            <script>
+                                self.i += 1
+                            </script>
                             <raise event="HTTP_input" target="self.http_clients[1]">
                                 <parameter expr='urlencode({"op": "get_output", "taskname": self.taskname})'/>
                                 <parameter expr='"parent"'/>
                             </raise>
-                            <script>
-                                self.i += 1
-                            </script>
                         </transition>
 
                         <transition event="http_client_timeout" target="../../wait_for_action/disconnected">
@@ -730,9 +728,9 @@
                             </raise>
                         </onentry>
 
-                        <transition cond="self.expect_response_partial('Success: ', pop=False)" target="../../wait_for_action/history">
+                        <transition cond="self.expect_response('Success')" target="../../wait_for_action/history">
                             <raise event="result">
-                                <parameter expr="self.responses.pop(0)"/>
+                                <parameter expr="None"/>
                             </raise>
                         </transition>
                     </state>
@@ -744,9 +742,9 @@
                             </raise>
                         </onentry>
 
-                        <transition cond="self.expect_response_partial('Success: ', pop=False)" target="../../wait_for_action/history">
+                        <transition cond="self.expect_response('Success')" target="../../wait_for_action/history">
                             <raise event="result">
-                                <parameter expr="self.responses.pop(0)"/>
+                                <parameter expr="None"/>
                             </raise>
                         </transition>
                     </state>
@@ -758,9 +756,9 @@
                             </raise>
                         </onentry>
 
-                        <transition cond="self.expect_response_partial('Success: ', pop=False)" target="../../wait_for_action/history">
+                        <transition cond="self.expect_response('Success')" target="../../wait_for_action/history">
                             <raise event="result">
-                                <parameter expr="self.responses.pop(0)"/>
+                                <parameter expr="None"/>
                             </raise>
                         </transition>
                     </state>
@@ -772,9 +770,9 @@
                             </raise>
                         </onentry>
 
-                        <transition cond="self.expect_response_partial('Success: ', pop=False)" target="../../wait_for_action/history">
+                        <transition cond="self.expect_response('Success')" target="../../wait_for_action/history">
                             <raise event="result">
-                                <parameter expr="self.responses.pop(0)"/>
+                                <parameter expr="None"/>
                             </raise>
                         </transition>
                     </state>
@@ -786,9 +784,9 @@
                             </raise>
                         </onentry>
 
-                        <transition cond="self.expect_response_partial('Success: ', pop=False)" target="../../wait_for_action/history">
+                        <transition cond="self.expect_response('Success')" target="../../wait_for_action/history">
                             <raise event="result">
-                                <parameter expr="self.responses.pop(0)"/>
+                                <parameter expr="None"/>
                             </raise>
                         </transition>
                     </state>
@@ -800,9 +798,9 @@
                             </raise>
                         </onentry>
 
-                        <transition cond="self.expect_response_partial('Success: ', pop=False)" target="../../wait_for_action/history">
+                        <transition cond="self.expect_response('Success')" target="../../wait_for_action/history">
                             <raise event="result">
-                                <parameter expr="self.responses.pop(0)"/>
+                                <parameter expr="None"/>
                             </raise>
                         </transition>
                     </state>
@@ -814,9 +812,9 @@
                             </raise>
                         </onentry>
 
-                        <transition cond="self.expect_response_partial('Success: ', pop=False)" target="../../wait_for_action/history">
+                        <transition cond="self.expect_response('Success')" target="../../wait_for_action/history">
                             <raise event="result">
-                                <parameter expr="self.responses.pop(0)"/>
+                                <parameter expr="None"/>
                             </raise>
                         </transition>
                     </state>
@@ -828,9 +826,9 @@
                             </raise>
                         </onentry>
 
-                        <transition cond="self.expect_response_partial('Success: ', pop=False)" target="../../wait_for_action/history">
+                        <transition cond="self.expect_response('Success')" target="../../wait_for_action/history">
                             <raise event="result">
-                                <parameter expr="self.responses.pop(0)"/>
+                                <parameter expr="None"/>
                             </raise>
                         </transition>
                     </state>
@@ -842,9 +840,9 @@
                             </raise>
                         </onentry>
 
-                        <transition cond="self.expect_response_partial('Success: ', pop=False)" target="../../wait_for_action/history">
+                        <transition cond="self.expect_response('Success')" target="../../wait_for_action/history">
                             <raise event="result">
-                                <parameter expr="self.responses.pop(0)"/>
+                                <parameter expr="None"/>
                             </raise>
                         </transition>
                     </state>
@@ -870,9 +868,9 @@
                             </raise>
                         </onentry>
 
-                        <transition cond="self.expect_response_partial('Success: ', pop=False)" target="../../wait_for_action/history">
+                        <transition cond="self.expect_response('Success')" target="../../wait_for_action/history">
                             <raise event="result">
-                                <parameter expr="self.responses.pop(0)"/>
+                                <parameter expr="None"/>
                             </raise>
                         </transition>
                     </state>
@@ -884,9 +882,9 @@
                             </raise>
                         </onentry>
 
-                        <transition cond="self.expect_response_partial('Success: ', pop=False)" target="../../wait_for_action/history">
+                        <transition cond="self.expect_response('Success')" target="../../wait_for_action/history">
                             <raise event="result">
-                                <parameter expr="self.responses.pop(0)"/>
+                                <parameter expr="None"/>
                             </raise>
                         </transition>
                     </state>
@@ -1461,7 +1459,7 @@
                         </raise>
                     </transition>
 
-                    <transition cond="self.expect_response_partial('No conformance relation can be found ', pop=False)" target="../wait_for_action/history">
+                    <transition cond="self.expect_response_partial('Conformance hierarchy unknown for: ', pop=False)" target="../wait_for_action/history">
                         <raise event="exception">
                             <parameter expr="'UnknownMetamodellingHierarchy'"/>
                             <parameter expr="'Metamodelling hierarchy could not be resolved or automatically inferred: there is no typing relation between your specified model and metamodel'"/>
@@ -2042,7 +2040,7 @@
 
                         <transition cond="self.expect_response('Model loaded, ready for commands!', pop=True)" target="../../wait_for_action/modelling/recognized/manual"/>
 
-                        <transition cond="self.expect_response_partial('No conformance relation can be found ', pop=False)" target="../../wait_for_action/megamodelling">
+                        <transition cond="self.expect_response_partial('Conformance hierarchy unknown for: ', pop=False)" target="../../wait_for_action/megamodelling">
                             <raise event="exception">
                                 <parameter expr="'UnknownMetamodellingHierarchy'"/>
                                 <parameter expr="'Conformance relation not found'"/>

+ 2 - 1
wrappers/modelverse.py

@@ -211,7 +211,8 @@ def init(address_param="127.0.0.1:8001", timeout=60.0, taskname=None):
 
     INPUT("init", [address_param, timeout])
     controller.address = address_param
-    return OUTPUT()
+    OUTPUT()
+    return
 
 def login(username, password):
     controller.username = username

+ 32 - 33
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
-Date:   Wed Jun  6 11:45:45 2018
+Date:   Wed Jun  6 14:51:29 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
@@ -1933,12 +1933,9 @@ class Modelverse(RuntimeClassBase):
         self.address = (self.address[0], int(self.address[1]))
         
         self.i = 0
-        taskname = self.controller.taskname
-        if taskname is None:
-            self.skip_init = False
+        self.taskname = self.controller.taskname
+        if self.taskname is None:
             self.taskname = "task_manager"
-        else:
-            self.skip_init = True
         
         self.controller.taskname = self.taskname
     
@@ -2251,7 +2248,7 @@ class Modelverse(RuntimeClassBase):
         self.responses.pop(0)
     
     def _initialized_behaviour_operations_15_guard(self, parameters):
-        return self.expect_response_partial('No conformance relation can be found ', pop=False)
+        return self.expect_response_partial('Conformance hierarchy unknown for: ', pop=False)
     
     def _initialized_behaviour_operations_16_exec(self, parameters):
         #print("Unknown Error: " + self.responses[0])
@@ -2443,6 +2440,7 @@ class Modelverse(RuntimeClassBase):
     
     def _initialized_http_mapper_init_2_exec(self, parameters):
         data = parameters[0]
+        #print("Got input (%s): %s" % (self.taskname, data))
         if self.taskname == "task_manager":
             self.controller.taskname = self.taskname = json.loads(data)
         else:
@@ -2455,6 +2453,7 @@ class Modelverse(RuntimeClassBase):
     
     def _initialized_http_mapper_init_3_exec(self, parameters):
         data = parameters[0]
+        #print("Got input (%s): %s" % (self.taskname, data))
         if self.taskname == "task_manager":
             self.controller.taskname = self.taskname = json.loads(data)
         else:
@@ -2481,14 +2480,14 @@ class Modelverse(RuntimeClassBase):
         self.i += 1
     
     def _initialized_behaviour_init_waiting_http_client_0_guard(self, parameters):
-        return self.skip_init or self.i == 0
+        return self.i == 0
     
     def _initialized_behaviour_init_waiting_http_client_1_exec(self, parameters):
-        self.big_step.outputEventOM(Event("narrow_cast", None, [self, self.http_clients[1], Event("HTTP_input", None, [urlencode({"op": "get_output", "taskname": self.taskname}), "parent"])]))
         self.i += 1
+        self.big_step.outputEventOM(Event("narrow_cast", None, [self, self.http_clients[1], Event("HTTP_input", None, [urlencode({"op": "get_output", "taskname": self.taskname}), "parent"])]))
     
     def _initialized_behaviour_init_waiting_http_client_1_guard(self, parameters):
-        return (not self.skip_init) and self.i == 1
+        return self.i == 1
     
     def _initialized_behaviour_init_waiting_http_client_2_exec(self, parameters):
         self.raiseInternalEvent(Event("exception", None, ['NetworkException', 'Connection timeout']))
@@ -2743,58 +2742,58 @@ class Modelverse(RuntimeClassBase):
         return self.expect_response('Success', pop=True)
     
     def _initialized_behaviour_operations_permission_modify_0_exec(self, parameters):
-        self.raiseInternalEvent(Event("result", None, [self.responses.pop(0)]))
+        self.raiseInternalEvent(Event("result", None, [None]))
     
     def _initialized_behaviour_operations_permission_modify_0_guard(self, parameters):
-        return self.expect_response_partial('Success: ', pop=False)
+        return self.expect_response('Success')
     
     def _initialized_behaviour_operations_permission_owner_0_exec(self, parameters):
-        self.raiseInternalEvent(Event("result", None, [self.responses.pop(0)]))
+        self.raiseInternalEvent(Event("result", None, [None]))
     
     def _initialized_behaviour_operations_permission_owner_0_guard(self, parameters):
-        return self.expect_response_partial('Success: ', pop=False)
+        return self.expect_response('Success')
     
     def _initialized_behaviour_operations_permission_group_0_exec(self, parameters):
-        self.raiseInternalEvent(Event("result", None, [self.responses.pop(0)]))
+        self.raiseInternalEvent(Event("result", None, [None]))
     
     def _initialized_behaviour_operations_permission_group_0_guard(self, parameters):
-        return self.expect_response_partial('Success: ', pop=False)
+        return self.expect_response('Success')
     
     def _initialized_behaviour_operations_group_create_0_exec(self, parameters):
-        self.raiseInternalEvent(Event("result", None, [self.responses.pop(0)]))
+        self.raiseInternalEvent(Event("result", None, [None]))
     
     def _initialized_behaviour_operations_group_create_0_guard(self, parameters):
-        return self.expect_response_partial('Success: ', pop=False)
+        return self.expect_response('Success')
     
     def _initialized_behaviour_operations_group_delete_0_exec(self, parameters):
-        self.raiseInternalEvent(Event("result", None, [self.responses.pop(0)]))
+        self.raiseInternalEvent(Event("result", None, [None]))
     
     def _initialized_behaviour_operations_group_delete_0_guard(self, parameters):
-        return self.expect_response_partial('Success: ', pop=False)
+        return self.expect_response('Success')
     
     def _initialized_behaviour_operations_group_owner_add_0_exec(self, parameters):
-        self.raiseInternalEvent(Event("result", None, [self.responses.pop(0)]))
+        self.raiseInternalEvent(Event("result", None, [None]))
     
     def _initialized_behaviour_operations_group_owner_add_0_guard(self, parameters):
-        return self.expect_response_partial('Success: ', pop=False)
+        return self.expect_response('Success')
     
     def _initialized_behaviour_operations_group_owner_delete_0_exec(self, parameters):
-        self.raiseInternalEvent(Event("result", None, [self.responses.pop(0)]))
+        self.raiseInternalEvent(Event("result", None, [None]))
     
     def _initialized_behaviour_operations_group_owner_delete_0_guard(self, parameters):
-        return self.expect_response_partial('Success: ', pop=False)
+        return self.expect_response('Success')
     
     def _initialized_behaviour_operations_group_join_0_exec(self, parameters):
-        self.raiseInternalEvent(Event("result", None, [self.responses.pop(0)]))
+        self.raiseInternalEvent(Event("result", None, [None]))
     
     def _initialized_behaviour_operations_group_join_0_guard(self, parameters):
-        return self.expect_response_partial('Success: ', pop=False)
+        return self.expect_response('Success')
     
     def _initialized_behaviour_operations_group_kick_0_exec(self, parameters):
-        self.raiseInternalEvent(Event("result", None, [self.responses.pop(0)]))
+        self.raiseInternalEvent(Event("result", None, [None]))
     
     def _initialized_behaviour_operations_group_kick_0_guard(self, parameters):
-        return self.expect_response_partial('Success: ', pop=False)
+        return self.expect_response('Success')
     
     def _initialized_behaviour_operations_group_list_0_exec(self, parameters):
         self.raiseInternalEvent(Event("result", None, [set(self.split_response(self.responses.pop(0)))]))
@@ -2803,16 +2802,16 @@ class Modelverse(RuntimeClassBase):
         return self.expect_response_partial('Success: ', pop=False)
     
     def _initialized_behaviour_operations_admin_promote_0_exec(self, parameters):
-        self.raiseInternalEvent(Event("result", None, [self.responses.pop(0)]))
+        self.raiseInternalEvent(Event("result", None, [None]))
     
     def _initialized_behaviour_operations_admin_promote_0_guard(self, parameters):
-        return self.expect_response_partial('Success: ', pop=False)
+        return self.expect_response('Success')
     
     def _initialized_behaviour_operations_admin_demote_0_exec(self, parameters):
-        self.raiseInternalEvent(Event("result", None, [self.responses.pop(0)]))
+        self.raiseInternalEvent(Event("result", None, [None]))
     
     def _initialized_behaviour_operations_admin_demote_0_guard(self, parameters):
-        return self.expect_response_partial('Success: ', pop=False)
+        return self.expect_response('Success')
     
     def _initialized_behaviour_operations_conformance_delete_0_exec(self, parameters):
         self.raiseInternalEvent(Event("result", None, [None]))
@@ -3374,7 +3373,7 @@ class Modelverse(RuntimeClassBase):
         self.actions.pop(0)
     
     def _initialized_behaviour_going_manual_OK_1_guard(self, parameters):
-        return self.expect_response_partial('No conformance relation can be found ', pop=False)
+        return self.expect_response_partial('Conformance hierarchy unknown for: ', pop=False)
     
     def _initialized_behaviour_leaving_manual_0_guard(self, parameters):
         return self.expect_response('Success', pop=True)