Jelajahi Sumber

Fix various bugs and errors in the SCCD model

Yentl Van Tendeloo 8 tahun lalu
induk
melakukan
df35fd2649

+ 6 - 5
bootstrap/core_algorithm.alc

@@ -975,7 +975,7 @@ String function cmd_help():
 
 	return result!
 
-String function cmd_model_add(type : String, name : String):
+String function cmd_model_add(type : String, name : String, code : String):
 	// Model addition operation, which uses model upload commands of the compiler
 	String location
 	String type_id
@@ -998,8 +998,7 @@ String function cmd_model_add(type : String, name : String):
 						if (element_eq(mm, read_root())):
 							return "Type is not typed by formalisms/SimpleClassDiagrams: " + type!
 
-						output("Waiting for model constructors...")
-						new_model = compile_model(input(), mm)
+						new_model = compile_model(code, mm)
 
 						if (element_eq(new_model, read_root())):
 							return "Compilation error"!
@@ -1330,7 +1329,6 @@ String function cmd_model_modify(model_name : String, metamodel_name : String):
 				new_model = get_full_model(model_id, get_entry_id(metamodel_name))
 				if (element_eq(new_model, read_root())):
 					return "No conformance relation can be found between these models"!
-				output("Success")
 				modify(new_model, allow_write(current_user_id, model_id))
 				if (allow_write(current_user_id, model_id)):
 					// Overwrite the modified model
@@ -1396,6 +1394,7 @@ String function cmd_model_list(location : String):
 
 String function cmd_model_list_full(location : String):
 	// List all models with full info
+	log("Start up model_full_list with location: " + cast_v2s(location))
 	if (get_entry_id(location) != ""):
 		if (allow_read(current_user_id, get_entry_id(location))):
 			Element models
@@ -2074,10 +2073,11 @@ Void function user_function_skip_init(user_id : String):
 
 	while (True):
 		cmd = input()
+		log("Got command: " + cast_v2s(cmd))
 		if (cmd == "help"):
 			output(cmd_help())
 		elif (cmd == "model_add"):
-			output(cmd_model_add(single_input("Model type?"), single_input("Model name?")))
+			output(cmd_model_add(single_input("Model type?"), single_input("Model name?"), single_input("Model textual representation?")))
 		elif (cmd == "process_execute"):
 			output(cmd_process_execute(single_input("Process to execute?"), single_input("Model prefix to use?")))
 		elif (cmd == "transformation_between"):
@@ -2099,6 +2099,7 @@ Void function user_function_skip_init(user_id : String):
 		elif (cmd == "model_list"):
 			output(cmd_model_list(single_input("Location?")))
 		elif (cmd == "model_list_full"):
+			log("Start model_list_full")
 			output(cmd_model_list_full(single_input("Location?")))
 		elif (cmd == "transformation_add_MANUAL"):
 			output(cmd_transformation_add_MANUAL(dict_input("Source model names?"), dict_input("Target model names?"), single_input("Operation name?")))

+ 0 - 2
bootstrap/mini_modify.alc

@@ -423,8 +423,6 @@ Element function modify(model : Element, write : Boolean):
 			output(cmd_read_incoming(model, single_input("Name?"), single_input("Type?")))
 		elif (cmd == "read"):
 			output(cmd_read(model, single_input("Name?")))
-		elif (cmd == "verify"):
-			output("Success: " + conformance_scd(model))
 		elif (cmd == "types"):
 			output(cmd_types(model))
 		elif (cmd == "retype"):

+ 1 - 1
scripts/HUTN_service.py

@@ -4,7 +4,7 @@ import sys
 sys.path.append(COMPILER_PATH)
 sys.path.append("wrappers")
 from hutn_compiler.compiler import main as do_compile
-from modelverse import *
+from modelverse_coded import *
 import os
 
 import time

+ 1 - 1
scripts/run_local_modelverse.py

@@ -10,7 +10,7 @@ else:
 
 # Start up the HUTN compilation service already
 try:
-    #hutn = subprocess.Popen([sys.executable, "scripts/HUTN_service.py", "127.0.0.1:%s" % port])
+    hutn = subprocess.Popen([sys.executable, "scripts/HUTN_service.py", "127.0.0.1:%s" % port])
 
     os.chdir("hybrid_server")
     subprocess.check_call([sys.executable, "-m", "sccd.compiler.sccdc", "-p", "threads", "server.xml"])

+ 2 - 1
unit/test_all.py

@@ -134,7 +134,8 @@ class TestModelverse(unittest.TestCase):
 
         # Check that an instantiate of "A" fails
         try:
-            instantiate("test/my_empty", "A")
+            res = instantiate("test/my_empty", "A")
+            print("RESULT: " + str(res))
             assert False
         except UnknownIdentifier:
             assert verify("test/Empty", "formalisms/SimpleClassDiagrams") == "OK"

+ 105 - 50
wrappers/classes/modelverse.xml

@@ -26,7 +26,7 @@
 
     <method name="expect_response">
         <parameter name="expected"/>
-        <parameter name="pop" default="False"/>
+        <parameter name="pop" default="True"/>
         <body>
             if self.responses and self.responses[0] == expected:
                 if pop:
@@ -55,7 +55,7 @@
         <parameter name="expected"/>
         <body>
             if isinstance(expected, list):
-                return self.actions[context] and expected in self.actions[context][0]["name"]
+                return self.actions[context] and self.actions[context][0]["name"] in expected
             else:
                 return self.actions[context] and self.actions[context][0]["name"] == expected
         </body>
@@ -66,10 +66,12 @@
             self.actions = {None: []}
             self.responses = []
             self.http_clients = []
+            self.context = None
+            self.registered_metamodel = {}
         </body>
     </constructor>
 
-    <scxml initial="init">
+    <scxml initial="init" priority="source_child">
         <state id="init">
             <onentry>
                 <raise scope="cd" event="create_instance">
@@ -140,6 +142,7 @@
                             <parameter expr='"parent"'/>
                         </raise>
                         <script>
+                            print("Got input from HTTP: " + str(data))
                             self.responses.append(json.loads(data))
                         </script>
                     </transition>
@@ -273,21 +276,14 @@
                         <state id="send_metadata">
                             <onentry>
                                 <raise event="request">
-                                    <parameter expr="['model_add', self.parameters[1], self.parameters[0]]"/>
-                                </raise>
-                            </onentry>
-
-                            <transition cond="self.expect_response('Waiting for model constructors...')" target="../send_model"/>
-                        </state>
-
-                        <state id="send_model">
-                            <onentry>
-                                <raise event="request">
-                                    <parameter expr="self.parameters[2]"/>
+                                    <parameter expr="['model_add', self.parameters[1], self.parameters[0], self.parameters[2]]"/>
                                 </raise>
                             </onentry>
 
                             <transition cond="self.expect_response('Success')" target="../../../wait_for_action/history">
+                                <script>
+                                    self.registered_metamodel[self.parameters[0]] = self.parameters[1]
+                                </script>
                                 <raise event="result">
                                     <parameter expr="None"/>
                                 </raise>
@@ -317,8 +313,15 @@
                         </onentry>
 
                         <transition cond="self.expect_response_partial('Success: ', pop=False)" target="../../wait_for_action/history">
+                            <script>
+                                response = self.split_response(self.responses.pop(0))
+                                result = set()
+                                for res in response:
+                                    i = res.split(" ", 3)
+                                    result.add((i[3], i[1], i[2], i[0]))
+                            </script>
                             <raise event="result">
-                                <parameter expr="set(self.split_response(self.responses.pop(0)))"/>
+                                <parameter expr="result"/>
                             </raise>
                         </transition>
                     </state>
@@ -332,7 +335,7 @@
 
                         <transition cond="self.expect_response_partial('Success: ', pop=False)" target="../../wait_for_action/history">
                             <raise event="result">
-                                <parameter expr="self.split_response(self.responses.pop(0))"/>
+                                <parameter expr="self.split_response(self.responses.pop(0))[0]"/>
                             </raise>
                         </transition>
                     </state>
@@ -454,7 +457,7 @@
                         </state>
 
                         <state id="edit_metamodel">
-                            <transition cond="self.expect_response('Model loaded, ready for commands!')" target="../../../wait_for_action/modelling/recognized_operation/scripted"/>
+                            <transition cond="self.expect_response('Model loaded, ready for commands!')" target="../../../going_scripted"/>
                             <transition cond="self.expect_response('Waiting for model constructors...')" target="../send_model"/>
                         </state>
 
@@ -471,6 +474,12 @@
                                 </raise>
                             </transition>
                         </state>
+
+                        <transition cond="self.expect_response_partial('', pop=False)" target="../../wait_for_action/history">
+                            <script>
+                                print("UNKNOWN RESPONSE received: " + str(self.responses.pop(0)))
+                            </script>
+                        </transition>
                     </state>
 
                     <state id="transformation_add_AL" initial="send_metadata">
@@ -494,7 +503,7 @@
                         </state>
 
                         <state id="edit_metamodel">
-                            <transition cond="self.expect_response('Model loaded, ready for commands!')" target="../../../wait_for_action/modelling/recognized_operation/scripted"/>
+                            <transition cond="self.expect_response('Model loaded, ready for commands!')" target="../../../going_scripted"/>
                             <transition cond="self.expect_response('Waiting for code constructors...')" target="../send_model"/>
                         </state>
 
@@ -534,7 +543,7 @@
                         </state>
 
                         <state id="edit_metamodel">
-                            <transition cond="self.expect_response('Model loaded, ready for commands!')" target="../../../wait_for_action/modelling/recognized_operation/scripted"/>
+                            <transition cond="self.expect_response('Model loaded, ready for commands!')" target="../../../going_scripted"/>
                             <transition cond="self.expect_response('Success')" target="../../../wait_for_action/megamodelling">
                                 <raise event="result">
                                     <parameter expr="None"/>
@@ -575,7 +584,7 @@
                                 </raise>
                             </transition>
 
-                            <transition cond="self.expect_action(self.context, 'data_input', pop=False)" target=".">
+                            <transition cond="self.expect_action(self.context, 'data_input')" target=".">
                                 <raise event="request">
                                     <parameter expr="self.actions[self.context].pop(0)['parameters']"/>
                                 </raise>
@@ -615,7 +624,7 @@
                                 </raise>
                             </transition>
 
-                            <transition cond="self.expect_action(self.context, 'data_input', pop=False)" target=".">
+                            <transition cond="self.expect_action(self.context, 'data_input')" target=".">
                                 <raise event="request">
                                     <parameter expr="self.actions[self.context].pop(0)['parameters']"/>
                                 </raise>
@@ -644,7 +653,7 @@
                         </state>
 
                         <state id="edit_model">
-                            <transition cond="self.expect_response('Model loaded, ready for commands!')" target="../../../wait_for_action/modelling/recognized_operation/scripted"/>
+                            <transition cond="self.expect_response('Model loaded, ready for commands!')" target="../../../going_scripted"/>
                             <transition cond="self.expect_response('Success')" target="../../../wait_for_action/megamodelling">
                                 <raise event="result">
                                     <parameter expr="None"/>
@@ -1162,6 +1171,17 @@
                             </raise>
                         </transition>
                     </state>
+
+                    <transition cond="self.expect_response_partial('Element not found: ', pop=False)" target="../wait_for_action/history">
+                        <raise event="exception">
+                            <parameter expr="'UnknownIdentifier'"/>
+                            <parameter expr="'Element could not be found'"/>
+                        </raise>
+
+                        <script>
+                            self.responses.pop(0)
+                        </script>
+                    </transition>
                 </state>
 
                 <state id="wait_for_action" initial="disconnected">
@@ -1203,7 +1223,6 @@
                         <transition cond="self.expect_action(None, 'model_list_full')" target="../../operations/model_list_full">
                             <script>
                                 self.load_action(None)
-                                print("MLF")
                             </script>
                         </transition>
 
@@ -1397,37 +1416,31 @@
                             </script>
                         </transition>
 
-                        <transition cond="self.expect_action(None, ['element_list', 'element_list_nice', 'types', 'types_full', 'read_info', 'read_attrs', 'instantiate', 'delete_element', 'attr_assign', 'attr_assign_code', 'attr_delete', 'read_outgoing', 'read_incoming', 'read_association_source', 'read_association_destination', 'connections_between', 'define_attribute', 'all_instances'], pop=False)" target="../modelling/recognized_operation/manual"/>
+                        <transition cond="self.expect_action(None, ['element_list', 'element_list_nice', 'types', 'types_full', 'read_info', 'read_attrs', 'instantiate', 'delete_element', 'attr_assign', 'attr_assign_code', 'attr_delete', 'read_outgoing', 'read_incoming', 'read_association_source', 'read_association_destination', 'connections_between', 'define_attribute', 'all_instances'])" target="../../going_manual"/>
                     </state>
 
-                    <state id="modelling" initial="recognized_operation">
-                        <onexit>
-                            <raise event="request">
-                                <parameter expr="'exit'"/>
-                            </raise>
-                        </onexit>
+                    <state id="modelling">
+                        <onentry>
+                            <script>
+                                print("Start modelling!")
+                                print("Context: " + str(self.context))
+                                print("actions: " + str(self.actions[self.context]))
+                            </script>
+                        </onentry>
 
-                        <state id="recognized_operation" initial="manual">
+                        <state id="recognized" initial="manual">
                             <state id="manual">
-                                <onentry>
-                                    self.context = None
-                                    self.current_model = self.actions[None][0].parameters[0]
-                                </onentry>
-
-                                <transition cond="self.expect_action(self.context, 'exit')" target="../../../megamodelling"/>
+                                <transition cond="self.expect_action(self.context, 'exit')" target="../../../../leaving_modelling"/>
 
-                                <transition cond="self.actions[self.context] and self.actions[0].parameters != self.current_model" target="../../../megamodelling">
+                                <transition cond="self.actions[self.context] and self.actions[self.context][0]['parameters'][0] != self.current_model" target="../../../../leaving_modelling">
                                     <script>
                                         print("Sudden switch between two models: perform context switch!")
+                                        print("Requested operation for " + str(self.actions[self.context][0]['parameters'][0]))
                                     </script>
                                 </transition>
                             </state>
 
                             <state id="scripted">
-                                <onentry>
-                                    self.current_model = None
-                                </onentry>
-
                                 <transition cond="self.expect_action(self.context, 'exit')" target="../../../../operations/history"/>
                             </state>
 
@@ -1540,20 +1553,20 @@
                             </transition>
                         </state>
 
-                        <transition cond="self.context is not None and self.actions[self.context]" target=".">
+                        <transition cond="self.context is not None and self.actions[self.context]" target="../history">
                             <script>
-                                print("Got unexpected operation: " + str(self.actions[self.context][0]))
+                                print("Got unexpected operation: " + str(self.actions[self.context].pop(0)))
                             </script>
 
-                            <raise event="error">
+                            <raise event="exception">
                                 <parameter expr="'IllegalContextOperation'"/>
                                 <parameter expr="'Operation not allowed in a context!'"/>
                             </raise>
                         </transition>
 
-                        <transition cond="self.context is None and self.action[None]" target="../megamodelling">
+                        <transition cond="self.context is None and self.actions[None]" target="../../leaving_modelling">
                             <script>
-                                print("Got megamodelling operation in model: transferring")
+                                print("Got megamodelling operation in model (%s) : transferring" % self.actions[None][0])
                             </script>
                         </transition>
                     </state>
@@ -1562,17 +1575,59 @@
 
                     <history id="history" type="deep"/>
 
-                    <transition cond="self.unexpected_action(None)" target=".">
+                    <transition cond="self.actions[None]" target="history">
                         <script>
-                            print("Got unknown operation: " + str(self.actions[self.context][0]))
+                            print("Got unknown operation: " + str(self.actions[None].pop(0)))
                         </script>
 
-                        <raise event="error">
+                        <raise event="exception">
                             <parameter expr="'UnknownOperation'"/>
                             <parameter expr="'Operation is unknown'"/>
                         </raise>
                     </transition>
                 </state>
+
+                <state id="going_manual">
+                    <onentry>
+                        <script>
+                            self.context = None
+                            self.current_model = self.actions[None][0]["parameters"][0]
+                            print("Setting current model to " + str(self.current_model))
+                        </script>
+
+                        <raise event="request">
+                            <parameter expr="['model_modify', self.current_model, self.registered_metamodel[self.current_model]]"/>
+                        </raise>
+                    </onentry>
+
+                    <transition cond="self.expect_response('Model loaded, ready for commands!', pop=True)" target="../wait_for_action/modelling/recognized/manual">
+                        <script>
+                            print("Going to manual!")
+                        </script>
+                    </transition>
+                </state>
+
+                <state id="going_scripted">
+                    <onentry>
+                        <script>
+                            self.current_model = None
+                            print("Setting current model to " + str(self.current_model))
+                        </script>
+                    </onentry>
+
+                    <transition cond="self.expect_response('Model loaded, ready for commands!', pop=True)" target="../wait_for_action/modelling/recognized/scripted"/>
+                </state>
+
+                <state id="leaving_modelling">
+                    <onentry>
+                        <raise event="request">
+                            <parameter expr="'exit'"/>
+                        </raise>
+                    </onentry>
+
+                    <transition cond="self.expect_response('Success', pop=True)" target="../wait_for_action/megamodelling"/>
+                </state>
+
             </state>
 
             <state id="queue">

+ 47 - 1
wrappers/modelverse.py

@@ -7,6 +7,43 @@ socket2event.boot_translation_service(controller)
 
 ID = 0
 
+# Exceptions
+class ModelverseException(Exception):
+    pass
+
+class UnknownError(ModelverseException):
+    pass
+
+class UnknownIdentifier(ModelverseException):
+    pass
+
+class CompilationError(ModelverseException):
+    pass
+
+class NoSuchAttribute(ModelverseException):
+    pass
+
+class UnknownModel(ModelverseException):
+    pass
+
+class ConnectionError(ModelverseException):
+    pass
+
+class ModelExists(ModelverseException):
+    pass
+
+class PermissionDenied(ModelverseException):
+    pass
+
+class InvalidMode(ModelverseException):
+    pass
+
+class InterfaceMismatch(ModelverseException):
+    pass
+
+class UnknownMetamodellingHierarchy(ModelverseException):
+    pass
+
 def run_controller():
     try:
         controller.start()
@@ -20,11 +57,19 @@ def _next_ID():
 
 def INPUT(action, context, parameters):
     print("Executing " + str(action))
+    print("Parameters: " + str(parameters))
     controller.addInput(Event("action", "action_in", [action, _next_ID(), context, parameters]))
 
 def OUTPUT():
     response = responses.fetch(-1)
-    return response.parameters[1]
+    print("Got response with name: " + str(response.name))
+    if response.name == "result":
+        print("Value: " + str(response.parameters[1]))
+        return response.parameters[1]
+    elif response.name == "exception":
+        print("Exception: " + str(response.parameters))
+        if response.parameters[1] == "UnknownIdentifier":
+            raise UnknownIdentifier()
 
 def init(address_param="127.0.0.1:8001", timeout=20.0):
     INPUT("init", None, [address_param, timeout])
@@ -209,6 +254,7 @@ def read_attrs(model_name, ID, context=None):
     return OUTPUT()
 
 def instantiate(model_name, typename, edge=None, ID="", context=None):
+    print("DOING INSTANTIATE")
     INPUT("instantiate", context, [model_name, typename, edge, ID])
     return OUTPUT()
 

File diff ditekan karena terlalu besar
+ 364 - 292
wrappers/modelverse_SCCD.py