Sfoglia il codice sorgente

Fixed model operations for named input/output models

Yentl Van Tendeloo 8 anni fa
parent
commit
5bd60dcec3

+ 17 - 21
bootstrap/core_algorithm.alc

@@ -499,7 +499,7 @@ Boolean function pm_finished(worklist : Element, pm : String):
 
 	return False!
 
-Element function execute_operation(operation_id : String, input_models : Element, output_metamodels : Element, tracability_model : Element):
+Element function execute_operation(operation_id : String, input_models : Element, output_models : Element, tracability_model : Element):
 	// Operations are always in-place and uses only a single metamodel
 	// Therefore, we must:
 	//		1) Find merged metamodel
@@ -586,10 +586,10 @@ Element function execute_operation(operation_id : String, input_models : Element
 
 		if (result):
 			model_tuples = create_node()
-			keys = dict_keys(output_metamodels)
+			keys = dict_keys(output_models)
 			while (read_nr_out(keys) > 0):
 				key = set_pop(keys)
-				set_add(model_tuples, create_tuple(key, get_full_model(get_model_id(output_metamodels[key]))))
+				set_add(model_tuples, create_tuple(key, get_full_model(get_model_id(output_models[key]))))
 
 			result = model_split(merged_model, model_tuples, tracability)
 
@@ -997,6 +997,7 @@ String function cmd_transformation_execute(user_id : String, transformation_name
 	String assoc_name
 
 	transformation_id = get_model_id(transformation_name)
+	log("Executing " + transformation_name)
 	if (transformation_id != ""):
 		if (allow_read(user_id, transformation_id)):
 			if (is_nominal_instance(core, transformation_id, "Transformation")):
@@ -1042,11 +1043,12 @@ String function cmd_transformation_execute(user_id : String, transformation_name
 
 					if (get_model_id(target_model_name) == ""):
 						// Doesn't exist yet, so we can easily create
+						dict_add(output_map, assoc_name, read_attribute(core, readAssociationDestination(core, target), "name"))
 						dict_add(outputs, assoc_name, target_model_name)
-						dict_add(output_map, assoc_name, read_attribute(core, readAssociationDestination(core, target), "type"))
 					else:
 						// Already exists, so we need to check for write access
 						if (allow_write(user_id, get_model_id(target_model_name))):
+							dict_add(output_map, assoc_name, read_attribute(core, readAssociationDestination(core, target), "name"))
 							dict_add(outputs, assoc_name, target_model_name)
 						else:
 							return "Permission denied to model: " + target_model_name!
@@ -1058,7 +1060,7 @@ String function cmd_transformation_execute(user_id : String, transformation_name
 				else:
 					output("Success: ready for MT execution")
 
-				result = execute_operation(transformation_id, inputs, outputs, read_root())
+				result = execute_operation(transformation_id, inputs, output_map, read_root())
 
 				// Now write out the models again
 				if (element_eq(result, read_root())):
@@ -1069,11 +1071,11 @@ String function cmd_transformation_execute(user_id : String, transformation_name
 					while (read_nr_out(keys) > 0):
 						key = set_pop(keys)
 						
-						if (get_model_id(output_map[key]) == ""):
+						if (get_model_id(outputs[key]) == ""):
 							// New model
-							model_create(result[key], output_map[key], user_id, get_model_id(key), "Model")
+							model_create(result[key], outputs[key], user_id, get_model_id(key), "Model")
 						else:
-							model_overwrite(result[key], get_model_id(output_map[key]))
+							model_overwrite(result[key], get_model_id(outputs[key]))
 
 					return "Success"!
 			else:
@@ -1298,7 +1300,6 @@ String function cmd_transformation_add_AL(user_id : String, source_models : Elem
 	return transformation_add(user_id, source_models, target_models, operation_name, "actionlanguage")!
 
 String function transformation_add(user_id : String, source_models : Element, target_models : Element, operation_name : String, operation_type : String):
-	log("1")
 	// Add a manual transformation model
 	String model_id
 	Element models
@@ -1322,7 +1323,9 @@ String function transformation_add(user_id : String, source_models : Element, ta
 	type_id = ""
 	old_type_id = ""
 
-	log("2")
+	if (bool_and(read_nr_out(source_models) == 0, read_nr_out(target_models) == 0)):
+		return "Cannot create transformation without input or output"!
+
 	keys = dict_keys(source_models)
 	while (read_nr_out(keys) > 0):
 		key = set_pop(keys)
@@ -1346,7 +1349,6 @@ String function transformation_add(user_id : String, source_models : Element, ta
 		else:
 			return "Model not found: " + name!
 
-	log("3")
 	keys = dict_keys(target_models)
 	while (read_nr_out(keys) > 0):
 		key = set_pop(keys)
@@ -1369,24 +1371,20 @@ String function transformation_add(user_id : String, source_models : Element, ta
 				return "Permission denied to model: " + name!
 		else:
 			return "Model not found: " + name!
-	log("4")
 
 	if (get_model_id(operation_name) == ""):
 		if (operation_type == "manual"):
-			log("5")
 			// Finished with all information, now create the model itself!
 			model_create(instantiate_model(get_full_model(get_model_id("ManualOperation"))), operation_name, user_id, get_model_id("ManualOperation"), "ManualOperation")
 			model_id = get_model_id(operation_name)
 
 		elif (operation_type == "actionlanguage"):
-			log("6")
 			// Finished with all information, now create the model itself!
 			output("Waiting for code constructors...")
 			add_code_model(get_full_model(get_model_id("ActionLanguage")), "AL/" + operation_name, construct_function())
 			model_create(import_node("AL/" + operation_name), operation_name, user_id, get_model_id("ActionLanguage"), "ActionLanguage")
 			model_id = get_model_id(operation_name)
 
-		log("7")
 		// Write out a merged metamodel containing all these models: this is the MM for the manual operation
 		// New location is available, so write
 		merged_formalism = model_fuse(set_copy(all_formalisms))
@@ -1398,7 +1396,6 @@ String function transformation_add(user_id : String, source_models : Element, ta
 			source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
 			tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
 			instantiate_attribute(core, tracability_link, "type", "merged")
-		log("8")
 
 		tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
 		instantiate_attribute(core, tracability_link, "type", "operatesOn")
@@ -1407,7 +1404,6 @@ String function transformation_add(user_id : String, source_models : Element, ta
 		String link
 		String dst
 
-		log("9")
 		keys = dict_keys(source)
 		while (read_nr_out(keys) > 0):
 			key = set_pop(keys)
@@ -1420,7 +1416,6 @@ String function transformation_add(user_id : String, source_models : Element, ta
 			link = instantiate_link(core, "transformOutput", "", model_id, target[key])
 			instantiate_attribute(core, link, "name", key)
 			
-		log("10")
 		return "Success"!
 	else:
 		return "Model exists: " + operation_name!
@@ -1514,6 +1509,7 @@ String function cmd_transformation_add_MT(user_id : String, RAMified_metamodel_n
 
 				keys = dict_keys(target)
 				while (read_nr_out(keys) > 0):
+					key = set_pop(keys)
 					dst = target[key]
 					link = instantiate_link(core, "transformOutput", "", model_id, dst)
 					instantiate_attribute(core, link, "name", key)
@@ -1866,11 +1862,11 @@ Void function user_function_skip_init(user_id : String):
 		elif (cmd == "transformation_RAMify"):
 			output(cmd_transformation_RAMify(user_id, single_input("Metamodel name?"), single_input("Target metamodel name?")))
 		elif (cmd == "transformation_add_MANUAL"):
-			output(cmd_transformation_add_MANUAL(user_id, set_input("Source model names?"), set_input("Target model names?"), single_input("Operation name?")))
+			output(cmd_transformation_add_MANUAL(user_id, dict_input("Source model names?"), dict_input("Target model names?"), single_input("Operation name?")))
 		elif (cmd == "transformation_add_AL"):
-			output(cmd_transformation_add_AL(user_id, set_input("Source model names?"), set_input("Target model names?"), single_input("Operation name?")))
+			output(cmd_transformation_add_AL(user_id, dict_input("Source model names?"), dict_input("Target model names?"), single_input("Operation name?")))
 		elif (cmd == "transformation_add_MT"):
-			output(cmd_transformation_add_MT(user_id, single_input("RAMified metamodel name?"), set_input("Source model names?"), set_input("Target models?"), single_input("Operation name?")))
+			output(cmd_transformation_add_MT(user_id, single_input("RAMified metamodel name?"), dict_input("Source model names?"), dict_input("Target models?"), single_input("Operation name?")))
 		elif (cmd == "transformation_list"):
 			output(cmd_transformation_list())
 		elif (cmd == "transformation_list_full"):

+ 4 - 0
bootstrap/model_management.alc

@@ -19,6 +19,10 @@ Element function model_fuse(models : Element):
 	Element reverse
 
 	// Read out some data first
+	if (read_nr_out(models) == 0):
+		log("Cannot fuse empty set of models!")
+		return read_root()!
+
 	tagged_model = set_pop(models)
 	set_add(models, tagged_model)
 	new_model = instantiate_model(tagged_model[1]["metamodel"])

+ 2 - 1
hybrid_server/classes/task.xml

@@ -38,7 +38,8 @@
                         break
                     reply = [mvs_operations[command[0]](*(command[1])) for command in commands]
             except:
-                print("ERROR: " + str(self.mvk.debug_info.get(taskname, "Unknown taskname")))
+                import traceback
+                print(traceback.format_exc())
                 #TODO delete self, as the task has crashed!
                 return False
             return True

+ 1 - 1
kernel/modelverse_kernel/main.py

@@ -68,7 +68,7 @@ class ModelverseKernel(object):
         # To enable tracing in the JIT (for debugging purposes), uncomment
         # the line below:
         #
-        #     self.jit.enable_tracing()
+        # self.jit.enable_tracing()
         #
         # To make the JIT print JIT successes and errors to the command-line,
         # uncomment the line below:

+ 1 - 7
wrappers/modelverse.py

@@ -534,13 +534,7 @@ def transformation_execute_MT(operation_name, input_models_dict, output_models_d
     global mode
     _goto_mode(MODE_MODELLING)
 
-    mv_dict_rep = []
-    for key, value in input_models_dict.items():
-        mv_dict_rep += [key, value]
-    mv_dict_rep += [""]
-    for key, value in output_models_dict.items():
-        mv_dict_rep += [key, value]
-    mv_dict_rep += [""]
+    mv_dict_rep = _dict_to_list(input_models_dict) + [""] + _dict_to_list(output_models_dict) + [""]
 
     _input(["transformation_execute", operation_name] + mv_dict_rep)
     _handle_output("Success: ready for MT execution")

+ 2 - 2
wrappers/test.py

@@ -52,7 +52,7 @@ except ModelExists:
 # Add the action language code to transform between them
 print("Add AL model")
 try:
-    transformation_add_AL(["PetriNet"], ["ReachabilityGraph"], "analyseReachability", open("models/reachability.alc", "r").read())
+    transformation_add_AL({"PetriNet": "PetriNet"}, {"ReachabilityGraph": "ReachabilityGraph"}, "analyseReachability", open("models/reachability.alc", "r").read())
 except ModelExists:
     pass
 
@@ -64,7 +64,7 @@ except ModelExists:
     pass
 
 try:
-    transformation_add_MT("RAMified_ReachabilityGraph", ["ReachabilityGraph"], [], "printReachability", open("models/reachabilitygraph_print.mvc").read())
+    transformation_add_MT("RAMified_ReachabilityGraph", {"ReachabilityGraph": "ReachabilityGraph"}, {}, "printReachability", open("models/reachabilitygraph_print.mvc").read())
 except ModelExists:
     pass