http.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. HTTP interface
  2. ==============
  3. If you want to use the Modelverse on an as of yet unsupported platform, you will have to make use of the HTTP interface directly.
  4. While it is possible to directly send HTTP requests, it is recommended to create a wrapper, similar to the Python wrapper mentioned before.
  5. Otherwise, many of the more complex operations (e.g., process enactment) will quickly result in problems.
  6. Now follows a detailed description of how the HTTP interface works.
  7. An explanation of the semantics of these operations can be found in the Python wrapper.
  8. An example implementation can be found in the Python wrapper, which should prove a valuable starting point for creating a new interface.
  9. Request and Reply format
  10. ------------------------
  11. HTTP requests to the Modelverse use the POST format, and should be directed at the location at which the Modelverse server is running.
  12. The request itself is a URL encoded form of the following dictionary: {"op": operation, "value": value, "taskname": taskname}.
  13. In this format, the operation is either *set_input* or *get_output*, with the logical meanings (see further).
  14. Value is only present if the operation is *set_input*, and contains a JSON serialized value to set as input.
  15. For multiple simultaneous requests, it is possible to not use a key *value*, but a key *data*.
  16. If the data key is present, this should contain a JSON serialized representation of multiple invocations.
  17. The semantics is identical, except that only a single HTTP request (and reply) is used.
  18. Finally, the taskname indicates the task to which the request is targetted.
  19. Tasknames are provided by the Modelverse when necessary.
  20. Fetching data from the Modelverse is done using the *get_output* operation, which is blocking until an output is present.
  21. Note that a timeout might occur if no output becomes available within the time specified as the HTTP output.
  22. This is not a problem, but should be handled.
  23. Output requests are handled in a FIFO manner, as multiple calls can be made for output simultaneously.
  24. Apart from the primitive types usually supported by JSON, action language primitives can also be sent.
  25. These are JSON serialized as a dictionary, with a single key *value* and its value being the string representation of the element.
  26. For example, an *If* construct is serialized as {"value":"If"}.
  27. The Modelverse understands this special case, but your interface should also be able to handle such data.
  28. Note that communication of these internal primitive types is extremely rare.
  29. The reply to this request is simple.
  30. For a *set_input* operation, the reply merely indicates that the input is put in the input queue of the task, and the content of the reply can be ignored.
  31. For a *get_output* operation, the reply contains a JSON serialized representation of the output data put in the Modelverse.
  32. This is always a primitive type of JSON, and will never be a list or dictionary.
  33. .. note::
  34. Communication over HTTP uses a POST request to allow for unlimited amounts of data to be transfered.
  35. Instead, the request parameters, normally part of the GET URL, are sent as data of the POST request.
  36. The Modelverse ignores GET requests.
  37. This nicely follows the REST standards, as all requests indeed alter the state of the Modelverse (contrary to GET requests).
  38. Examples
  39. ^^^^^^^^
  40. To send the integer 1 to the task with name abc in the Modelverse, send the following data in the POST request::
  41. op=set_input&value=1&taskname=abc
  42. To send the string def to the task with name xyz in the Modelverse, send the following data in the POST request::
  43. op=set_input&value="def"&taskname=xyz
  44. To send both the integer 1 and the string def to the task with name abc in the Modelverse, send either two seperate requests, or a single request::
  45. op=set_input&data=[1,"def"]&taskname=xyz
  46. To fetch the output value of a task xyz in the Modelverse, send the following HTTP request, which yields (possibly) the following answer::
  47. op=get_output&taskname=xyz
  48. "The output value is a string containing a JSON serialized value."
  49. Startup
  50. -------
  51. When starting up the Modelverse, only a simple task manager is running.
  52. A new task can be created by querying this task manager for a new taskname.
  53. This is done by fetching the output of the task manager as follows::
  54. op=get_output&taskname=task_manager
  55. The reply to this query contains the taskname that can be used in subsequent requests.
  56. For legacy purposes, it is also possible to send a new taskname to the task manager directly, which will subsequently be generated.
  57. This approach is deprecated, as it is easy to run into problems when two users request the same taskname.
  58. These problems are avoided when using the new approach.
  59. Additionally, the new approach allows the task manager to cache new tasks, such that they are available much sooner.
  60. Operations
  61. ----------
  62. Upon startup of a task, the communication starts in verbose mode to allow for interactive use.
  63. This means that initially, every sent input will result in one (or multiple) output values.
  64. For a wrapper this is cumbersome, as it creates a lot of HTTP requests, and therefore it can be disabled with the input *quiet*.
  65. A more detailed overview of all operations, their order and possible interleavings, and their possible responses, we refer to the SCCD model in *wrappers/classes/modelverse.xml*.
  66. The first two input values that are to be sent are the username and password, which can happen using the following request::
  67. op=set_input&data=["my username","my password"]&taskname=name_of_new_task
  68. Depending on the output values received, it can be determined whether this is a new or existing user.
  69. If this is a new user, a subsequent request should again send the password to confirm the password.
  70. If this is an existing user, the task continues and is now logged in.
  71. When logged in, there are three possible modes: megamodelling, modelling, and service.
  72. Apart from the responses mentioned here, several other responses are also possible, though these are exceptions.
  73. All ordinary responses to operations start with *Success:*, or merely *Success* if there is no value to output.
  74. Megamodelling
  75. ^^^^^^^^^^^^^
  76. In megamodelling mode, which is the first mode to be entered after login, users can modify the megamodel, containing the relation of all models in the Modelverse.
  77. It is in this mode that new models should be created, models should be deleted, or new transformations be defined.
  78. Additionally, as all user access control is modelled explicitly, this is also the mode in which user management is done.
  79. There are two operations to allow mode switching: *model_modify* and *service_register*.
  80. To go to modelling, send *model_modify*, followed by the name of the model you wish to open and the name of the metamodel that should be used.
  81. For example::
  82. op=set_input&data=["model_modify","formalisms/ProcessModel","formalisms/SimpleClassDiagrams"]&taskname=xyz
  83. To go to service mode, send *service_register*, followed by the name of the service that is to be registered.
  84. For example::
  85. op=set_input&data=["service_register","HUTN_compiler"]&taskname=xyz
  86. In megamodelling mode, the following simple operations are supported.
  87. For each request, the output normally starts with a *Success*, following the actual return value as a string.
  88. As all responses are strings, there is some encoding to them (e.g., split on newlines, split on colon, ...).
  89. Most are trivial to deserialize when the result comes in, and therefore we refer to the SCCD model.
  90. While operation and parameters are shown distinct in the table, the HTTP request merely sends them in exactly the same fashion.
  91. For example::
  92. op=set_input&data=["model_mode","formalisms/ProcessModel","formalisms/PM"]&taskname=xyz
  93. Some more complex operations are mentioned below these standard operations.
  94. ============================= ======================================
  95. operation parameters
  96. ============================= ======================================
  97. model_move model_name, new_location
  98. process_signature process_name
  99. transformation_between source_name, target_name
  100. model_render model_name, mapper_name, rendered_name
  101. model_rendered model_name, mapper_name
  102. verify model_name, metamodel_name
  103. model_delete model_name
  104. model_list location
  105. model_list_full location
  106. permission_modify model_name, permissions
  107. permission_owner model_name, owner
  108. permission_group model_name, group
  109. group_create group
  110. group_delete group
  111. group_owner_add group, user
  112. group_owner_delete group, user
  113. group_join group, user
  114. group_kick group, user
  115. group_list
  116. admin_promote user
  117. admin_demote user
  118. user_password user, password
  119. transformation_read_signature transformation_name
  120. verbose
  121. quiet
  122. folder_create location
  123. add_conformance model_name, metamodel_name
  124. model_types model_name
  125. AL_text location
  126. model_add metamodel_name, model_name, code
  127. ============================= ======================================
  128. More complex operations have multiple phases, as there is a modification step involved, or a preliminary check before the next piece of data can be forwarded.
  129. These operations are presented next.
  130. ========================= ===============================================
  131. operation parameters
  132. ========================= ===============================================
  133. model_overwrite model_name, metamodel_name
  134. transformation_add_MANUAL source_models\*, target_models\*, name
  135. transformation_add_AL source_models\*, target_models\*, name
  136. transformation_add_MT source_models\*, target_models\*, name
  137. transformation_execute activity_name, source_models\*, target_models\*
  138. process_execute process_name, model_bindings\*
  139. ========================= ===============================================
  140. Parameters marked with a \* are actually dictionaries, and should be sent as such.
  141. Since the Modelverse has no primitive notion of dictionaries, a dictionary is expanded as a sequence of key value pairs, terminated with an empty key.
  142. For example, the dictionary {"abc": "def", "ghi": "jkl"} is sent as five individual requests (or a single data request)::
  143. ...&data=["abc","def","ghi","jkl",""]&...
  144. For the model_overwrite operation, the Modelverse will first perform some checks as to whether the overwritten model can indeed be overwritten.
  145. If so, it will output the reply *Waiting for model constructors...*, after which the actual code may be sent.
  146. The operations starting with transformation_add are similar, but they have two phases.
  147. First, they output the name of the merged metamodel, ready to be RAMified.
  148. There is then the possibility to modify this metamodel before RAMification starts, by logging in using a different task, modifying the model, and storing the changes.
  149. As soon as all changes are made, any input will initiate RAMification.
  150. Second, the Modelverse will query for the code that specify the transformation.
  151. For manual operations, this query is not done.
  152. For AL, this query expects ActionLanguage code.
  153. For MT, this query expects a model conforming to the RAMified metamodel.
  154. Of course, these constructors can be passed an empty model, in which case the models have to be updated later on using model_modify.
  155. The transformation_execute operation and process_execute are special operations, in the sense that they (potentially) spawn other tasks.
  156. The output value of these operations is the name of a newly spawned task, on which execution should continue.
  157. These tasks might not be identical to other tasks, in the sense that they are purely able to communicate with the currently executing operation.
  158. This operation is rather complex, and we refer to the SCCD model for detailed information.
  159. The process_execute operation is similar, but instead of outputting only a single taskname, we output multiple, combined with the activity that spawned it.
  160. Modelling
  161. ^^^^^^^^^
  162. In modelling mode, a single model is opened and ready to be modified.
  163. There are several supported operations, most of which are simple to use.
  164. To switch back to megamodelling mode, send the *exit* input.
  165. ============================ =============================
  166. operation parameters
  167. ============================ =============================
  168. help
  169. instantiate_node type, element
  170. instantiate_edge type, element, source, target
  171. attr_add element, attribute, value
  172. attr_delete element, attribute
  173. attr_name element, attribute, name
  174. attr_type element, attribute, type
  175. attr_optional element, attribute, optional
  176. delete element
  177. list
  178. list_full
  179. JSON
  180. read_outgoing element, type
  181. read_incoming element, type
  182. read element
  183. read_attrs element
  184. read_defined_attrs element
  185. types
  186. retype element, type
  187. read_association_source element
  188. read_association_destination element
  189. connections_between element, element
  190. all_instances type
  191. define_attribute element, attribute, type
  192. undefine_attribute element, attribute
  193. ============================ =============================
  194. Some additional operations are again available that work in two phases.
  195. These operations are *attr_add_code* and *upload*, which first perform some checks and then wait for AL code or a model.
  196. Service
  197. ^^^^^^^
  198. In service mode, the Modelverse blocks until the input *service_stop* is received, and this task is used to process the service.