http.rst 15 KB

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