wrappers.rst 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. Wrappers
  2. ========
  3. Several wrappers can be defined for the Modelverse, as the Modelverse is merely a service running externally.
  4. To communicate effectively, and automatically, a programming language wrapper is recommended.
  5. Nonetheless, it is possible to communicatie manually as well.
  6. These are some of the implemented wrappers.
  7. Prompt
  8. ------
  9. The simplest wrapper is the prompt wrapper, which merely sends the input and output directly to the user.
  10. This wrapper has almost no code, but requires users to manually decide which content to send next.
  11. It has no built-in integration with any model or action language compilers.
  12. Nonetheless, it is an easy way to test out the raw communication protocol manually.
  13. Python
  14. ------
  15. The first real wrapper is the Python-based wrapper.
  16. It provides a set of functions for use by Python code.
  17. These functions wrap not only the interface, but also provides simple error handling through the use of Python exceptions and contains the model and action language compilers.
  18. An overview of all functions and associatied exceptions is provided below.
  19. All operations happen *synchronously*, meaning that they block until the Modelverse has performed the requested operation.
  20. Note that some functions are only applicable in a certain *context*.
  21. In practice, this means that you should first issue the *init* and *login* operations, as otherwise your connection with the Modelverse will not have started up yet.
  22. Functions
  23. ^^^^^^^^^
  24. .. function:: init(address_param="http://127.0.0.1:8001", timeout=20.0)
  25. Start up the connection to the Modelverse, residing at *address_param*.
  26. This connection is an XML/HTTPRequest and will start up a new task at the Modelverse.
  27. Retries for *timeout* seconds until giving up.
  28. The timeout includes all HTTP errors, and will therefore keep retrying even on failed attempts.
  29. As this request is synchronous, like all others, it will block until a connection has been established.
  30. .. function:: login(username, password)
  31. Explanation
  32. Logs in the currently active Modelverse connection to the specified *username* and *password*.
  33. If the user does not exist, it will create a new user with the specified password.
  34. If the user already exists, it will try to log in with the provided password.
  35. .. function:: model_add(model_name, metamodel_name, model_code=None)
  36. Explanation
  37. Upload a new model that can later be referred to as *model_name*, conforming to *metamodel_name*.
  38. The model itself is stored in the string *model_code*.
  39. This string is parsed using the HUTN compiler and subsequently sent to the Modelverse.
  40. When *model_code* is empty, an empty model is created.
  41. .. function:: upload_code(code)
  42. Upload a string of *code* in the Action Language formalism.
  43. This piece of code is compiled with the HUTN compiler and sent to the Modelverse directly.
  44. Makes the assumption that the **construct_function()** operation is currently running on the Modelverse, as otherwise the data will be misinterpreted.
  45. This is normally only useful in model transformations, where you want to upload a piece of code on-the-fly (e.g., adding a breakpoint in Action Language).
  46. .. function:: model_delete(model_name)
  47. Delete the model referred to by name *model_name*.
  48. This is a non-cascading delete, with almost no checks: model transformations depending on this model will likely become corrupted.
  49. .. function:: model_list()
  50. Returns a list of all models existing in the Modelverse, together with their type.
  51. .. function:: model_list_full()
  52. Returns a detailed list of all models existing in the Modelverse.
  53. This list includes information on permissions, owner, and group.
  54. .. function:: verify(model_name)
  55. Verify whether *model_name* conforms to its specified metamodel, as stored in the Modelverse.
  56. Returns either "OK" if the model conforms, or a string specifying the reason for non-conformance.
  57. .. function:: model_overwrite(model_name, new_model_code=None)
  58. Expl
  59. .. function:: user_logout()
  60. Expl
  61. .. function:: user_delete()
  62. Expl
  63. .. function:: model_render(model_name, mapper_name)
  64. Expl
  65. .. function:: transformation_between(source, target)
  66. Expl
  67. .. function:: transformation_add_MT(source_metamodels, target_metamodels, operation_name, code)
  68. Expl
  69. .. function:: transformation_add_AL(source_metamodels, target_metamodels, operation_name, code)
  70. Expl
  71. .. function:: transformation_add_MANUAL(source_metamodels, target_metamodels, operation_name)
  72. Expl
  73. .. function:: transformation_execute_AL(operation_name, input_models_dict, output_models_dict, callback=lambda i: None)
  74. Expl
  75. .. function:: transformation_execute_MANUAL(operation_name, input_models_dict, output_models_dict, callback=lambda i: None)
  76. Expl
  77. .. function:: transformation_execute_MT(operation_name, input_models_dict, output_models_dict, callback=lambda i: None)
  78. Expl
  79. .. function:: transformation_list()
  80. Expl
  81. .. function:: process_execute(process_name, prefix, callbacks)
  82. Expl
  83. .. function:: permission_modify()
  84. Expl
  85. .. function:: permission_owner()
  86. Expl
  87. .. function:: permission_group()
  88. Expl
  89. .. function:: group_create()
  90. Expl
  91. .. function:: group_delete()
  92. Expl
  93. .. function:: group_owner_add()
  94. Expl
  95. .. function:: group_owner_delete()
  96. Expl
  97. .. function:: group_join()
  98. Expl
  99. .. function:: group_kick()
  100. Expl
  101. .. function:: admin_promote()
  102. Expl
  103. .. function:: admin_demote()
  104. Expl
  105. .. function:: element_list(model_name)
  106. Expl
  107. .. function:: types(model_name)
  108. Expl
  109. .. function:: types_full(model_name)
  110. Expl
  111. .. function:: read(model_name, ID)
  112. Expl
  113. .. function:: read_attrs(model_name, ID)
  114. Expl
  115. .. function:: instantiate(model_name, typename, edge=None, ID="")
  116. Expl
  117. .. function:: delete_element(model_name, ID)
  118. Expl
  119. .. function:: attr_assign(model_name, ID, attr, value)
  120. Expl
  121. .. function:: attr_assign_code(model_name, ID, attr, code)
  122. Expl
  123. .. function:: attr_delete(model_name, ID, attr)
  124. Expl
  125. .. function:: read_outgoing(model_name, ID, typename)
  126. Expl
  127. .. function:: read_incoming(model_name, ID, typename)
  128. Expl
  129. .. function:: read_association_source(model_name, ID)
  130. Expl
  131. .. function:: read_association_destination(model_name, ID)
  132. Expl
  133. Exceptions
  134. ^^^^^^^^^^
  135. .. exception:: ModelverseException
  136. Expl
  137. .. exception:: UnknownError
  138. Expl
  139. .. exception:: UnknownIdentifier
  140. Expl
  141. .. exception:: UnknownType
  142. Expl
  143. .. exception:: NotAnAssociation
  144. Expl
  145. .. exception:: UnsupportedValue
  146. Expl
  147. .. exception:: CompilationError
  148. Expl
  149. .. exception:: NoSuchAttribute
  150. Expl
  151. .. exception:: UnknownModel
  152. Expl
  153. .. exception:: ConnectionError
  154. Expl
  155. .. exception:: ModelExists
  156. Expl
  157. .. exception:: PermissionDenied
  158. Expl
  159. .. exception:: InvalidMode
  160. Expl
  161. .. exception:: InterfaceMismatch
  162. Expl
  163. Custom
  164. ------
  165. Other wrappers can be made as desired, in whatever language required.
  166. This is due to the fact that the Modelverse communicates only through XML/HTTPRequests.
  167. As such, all languages that support this, can simply mimic the interface used by any of the implemented wrappers.