Programatically Adding/Updating Services and Service Tests
Prerequisites
- Python 2.5
- embrace_remote.py (EMBRACEremote.zip -- includes an example)
Adding/Updating Services and Service Tests
Services and service tests can be programmatically added to the EMBRACE registry by the Python script embrace_remote.py. When the script is executed without parameters it returns the following brief usage description:
In order to upload/change a service or service test, it is necessary to
- edit the EMBRACE username and password in the file embrace_remote.py,
- provide an XML file which describes the service or service test,
- in case files are attached to the service or service test, the path to the attachment has to be given as well, and
- implementations of service tests have to be archived and attached in a ZIP file.
The username and password are located within the script itself and not setable via command line options, because on a shared computer it would otherwise be possible for logged-in users to access this information by listing the currently running processes and their parameters. Since the username and password do not have to be repeatedly restated with each call to the script when being embedded within the script, it is possible to add/update a large amount of services and service tests by batch processing.
| Original embrace_remote.py | Customised embrace_remote.py |
|---|---|
| #!/usr/bin/python | #!/usr/bin/python |
| import os | import os |
| import sys | import sys |
| import urllib | import urllib |
| import urllib2 | import urllib2 |
| username = 'user' | username = 'mrexample' |
| password = 'secret' | |
| url = 'http://prints.cs.man.ac.uk:8081/add2drupal.php' | url = 'http://prints.cs.man.ac.uk:8081/add2drupal.php' |
| ... | ... |
The actual information about a service or service test is provided to the script in an XML file. Examples of XML files that describe a service and a service test are given below.
(service.xml in EMBRACEremote.zip)
| <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE service [ <!ELEMENT service (title,description,vocabulary,file,attachment?)> <!ELEMENT title (#PCDATA)> <!ELEMENT description (#PCDATA)> <!ELEMENT vocabulary (type,project,institution,tag*)> <!ELEMENT file (version,url,component?)> <!ELEMENT component (type,url)> <!ELEMENT version (#PCDATA)> <!ELEMENT url (#PCDATA)> <!ELEMENT type (#PCDATA)> <!ELEMENT project (#PCDATA)> <!ELEMENT institution (#PCDATA)> <!ELEMENT tag (#PCDATA)> <!ELEMENT attachment (#PCDATA)> ]> <service> <title> Service Title </title> <description> Description of the service. </description> <vocabulary> <type> Text mining </type> <project> EMBRACE </project> <institution> GENOSCOPE </institution> <tag> A Tag </tag> <tag> Another Tag </tag> </vocabulary> <file> <version> 0.1 </version> <url> http://www.your-address.ac.uk/your_service/index.html </url> <component> <type> WSDL </type> <url> http://www.your-address.ac.uk/component.wsdl </url> </component> </file> </service> |
|---|
Most of the entries are self-explanatory, for example, the <title> tag, there are some tags that need further explanation:
- <vocabulary> corresponds to the box with the same name when adding services. The service needs to be categorised by a type ('DNA sequencing', 'Text mining', etc) and it needs to be associated to a project ('BioSapiens', 'EMBRACE', etc) as well as an institution ('BIB', 'Bio-Rome', etc). Possible values for the type category and the project can be obtained from the manual submission form.
- <component> refers to the actual service that is described by the service entry in EMBRACE, where its type ('WSDL', 'REST', etc) and the URL to the service need to be provided. Again, possible values of possible service types can be obtained from the manual submission form.
(service_test.xml in EMBRACEremote.zip)
|
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE servicetest [ <!ELEMENT servicetest (service?,title,description,test,attachment?)> <!ELEMENT service (#PCDATA)> <!ELEMENT title (#PCDATA)> <!ELEMENT description (#PCDATA)> <!ELEMENT test (type,url?,attachment?,operation)> <!ELEMENT version (#PCDATA)> <!ELEMENT url (#PCDATA)> <!ELEMENT type (#PCDATA)> <!ELEMENT operation (#PCDATA)> <!ELEMENT attachment (#PCDATA)> ]> <servicetest> <service> Service Title </service> <title> Service Test Example </title> <description> Description of the service test. </description> <test> <type> Python </type> <url> http://www.your-address.ac.uk/ </url> <attachment> ex_test.zip </attachment> <operation> ex_test.py </operation> </test> </servicetest> |
|---|
Tags that need further explanation:
- <service> refers to the title of the service to which this service test belongs to. In other words, it refers to the contents of the <title> tag of a previously added service.
- <test> describes the actual test implementation, such as the test's type ('Python', 'Perl', etc), an optional URL where information about this test can be found, the name of the ZIP archive which contains the test implementation and the filename of the test's main executable within the ZIP archive.
A service or service test can now be specifying the path to the XML file and any additional uploads (such as ex_test.zip) as parameters to embrace_remote.py. A short status message will be printed when the script finishes, indicating the success or failure of the operation. For example:
Service ``Service Title'' successfully added...
host:~/Desktop/EMBRACEremote exuser$ embrace_remote.py service_test.xml ex_test.zip
Service test ``Service Test Example'' successfully added...
host:~/Desktop/EMBRACEremote exuser$
For sucessfully adding services and service tests, it is necessary to change the username and password in embrace_remote.py. For large batch processing, it is advisable to test the outcome of a view script runs manually in order to make sure the desired changes are made to the registry.
Updating Information of Existing Services and Service Tests
In case the service, which is identified by its title, already exists in the EMBRACE registry, it will be overwritten with the information provided in the XML file. This is also the case for service tests, which are identified by their title as well as the title of the service they belong to.
Using HTML in XML
It is not possible to use plain HTML formatting in the XML files, since the XML document is checked against its DTD. Any additional HTML tags, for example <em>, are violating the DTD, so that it is necessary to escape additional formatting code as follows:
<![CDATA[
In descriptions it is possible to highlight
text using a <strong>bold</strong> and
<em>italic</em> typefaces. Of course,
<em><strong>combinations</strong></em>
of typefaces are permitted too.
]]>
</description>
The description of the previous example will then be displayed in a web browser as:
In descriptions it is possible to highlight text using a bold and italic typefaces. Of course, combinations of typefaces are permitted too.
| Attachment | Size |
|---|---|
| EMBRACEremote.zip | 7.22 KB |