source: branches/PublicaMundi_David_integration_01-devel/docs/services/howtos.txt @ 779

Last change on this file since 779 was 634, checked in by djay, 10 years ago

Integrate a basic SAGA-GIS support into the ZOO-Kernel.

  • Property svn:eol-style set to native
  • Property svn:keywords set to HeadURL Date Author Id Rev
  • Property svn:mime-type set to text/plain
File size: 10.2 KB
Line 
1.. _services-howtos:
2
3How To Setup ZOO Services
4=========================
5
6:Authors: Nicolas Bozon, Gérald Fenoy, Jeff McKenna, Luca Delucchi
7:Last Updated: $Date: 2015-04-24 14:57:59 +0000 (Fri, 24 Apr 2015) $
8
9ZOO Services are quite easy to create once you have installed the ZOO Kernel and have
10chosen code (in the language of your choice) to turn into a ZOO service. Here are some
11HelloWorlds in Python, PHP, Java  and JavaScript with links to their corresponding
12``.zcfg`` files.
13
14.. contents:: Table of Contents
15    :depth: 3
16    :backlinks: top
17
18Common informations
19----------------------
20
21A ZOO-Service is a couple composed of a ZCFG file and a
22ServiceProvider. This last depend of the programming language but
23should expose at least one function corresponding to the Service. This
24function take three arguments: the main configuration, inputs and
25outputs and return an integer:
26* 3 if the process run sucessfully
27* 4 in case any error occur. In such a case, programmer may add
28detailler message map
29
30Data structures for those arguments depend on the programming
31-UMRlanguage and is detailled below.
32
33.. Note:: The service has to **return 3 if the process run successfully instead it
34          return 4** if the process end with an error.
35
36Python
37------
38
39You'll find here information needed to deploy your own Python Services Provider.
40
41Python ZCFG requirements
42************************
43
44.. Note:: For each Service provided by your ZOO Python Services Provider, the ZCFG File
45          must be named the same as the Python module function name (also the case of
46          characters is important).
47
48The ZCFG file should contain the following :
49
50
51serviceType
52    Python
53serviceProvider
54    The name of the Python module to use as a ZOO Service Provider. For instance, if your
55    script, located in the same directory as your ZOO Kernel, was named ``my_module.py`` then
56    you should use ``my_module`` (the Python module name) for the serviceProvider value in ZCFG file.
57
58Python Data Structure used
59**************************
60The three parameters of the function are passed to the Python module as dictionaries.
61
62Following you'll find an example for each parameters
63
64Main configuration
65^^^^^^^^^^^^^^^^^^^^^
66Main configuration contains several informations, some of them are really useful to develop your service.
67Following an example ::
68
69  {
70  'main': {'lang': 'en-UK',
71           'language': 'en-US',
72           'encoding': 'utf-8',
73           'dataPath': '/var/www/tmp',
74           'tmpPath': '/var/www/tmp',
75           'version': '1.0.0',
76           'mapserverAddress': 'http://localhost/cgi-bin/mapserv',
77           'isSoap': 'false',
78           'tmpUrl': 'http://localhost/tmp/',
79           'serverAddress': 'http://localhost/zoo'
80          },
81  'identification': {'keywords': 'WPS,GIS',
82                     'abstract': 'WPS services for testing ZOO',
83                     'fees': 'None',
84                     'accessConstraints': 'none',
85                     'title': 'testing services'
86                    },
87  'lenv': {'status': '0',
88           'soap': 'false',
89           'cwd': '/usr/lib/cgi-bin',
90           'sid': '24709'
91          },
92  'env': {'DISPLAY': 'localhost:0'},
93  'provider': {'addressCountry': 'it',
94               'positionName': 'Developer',
95               'providerName': 'Name of provider',
96               'addressAdministrativeArea': 'False',
97               'phoneVoice': 'False',
98               'addressCity': 'City',
99               'providerSite': 'http://www.your.site',
100               'addressPostalCode': '38122',
101               'role': 'Developer',
102               'addressDeliveryPoint': 'False',
103               'phoneFacsimile': 'False',
104               'addressElectronicMailAddress': 'your@email.com',
105               'individualName': 'Your Name'
106              }
107  }
108
109Inputs
110^^^^^^^^^^^^
111The inputs are somethings like this ::
112
113  {
114  'variable_name': {'minOccurs': '1',
115                    'DataType': 'string',
116                    'value': 'this_is_the_value',
117                    'maxOccurs': '1',
118                    'inRequest': 'true'
119                   }
120  }
121
122The access to the value you have to require for the ``value`` parameter, something like this ::
123
124  yourVariable = inputs['variable_name']['value']
125
126Outputs
127^^^^^^^^^^^^^
128The outputs data as a structure really similar to the inputs one ::
129
130  {
131  'result': {'DataType': 'string',
132             'inRequest': 'true',
133            }
134  }
135
136There is no ``'value'`` parameter before you assign it ::
137
138  inputs['result']['value'] = yourOutputDataVariable
139
140The return statement has to be an integer: corresponding to the service status code.
141
142To add a message for the wrong result you can add the massage to ``conf["lenv"]["message"]``,
143for example:
144
145.. code-block:: python
146
147  conf["lenv"]["message"] = 'Your module return an error'
148
149Sample ZOO Python Services Provider
150***********************************
151
152The following code represents a simple ZOO Python Services Provider which provides only one
153Service, the HelloPy one.
154
155.. code-block:: python
156
157  import zoo
158  import sys
159  def HelloPy(conf,inputs,outputs):
160     outputs["Result"]["value"]="Hello "+inputs["a"]["value"]+" from Python World !"
161     return zoo.SERVICE_SUCCEEDED
162
163PHP
164---
165
166ZOO-API
167*******
168
169The ZOO-API for the PHP language is automatically available from your
170service code. Tthe following functions are defined in the ZOO-API:
171
172int zoo_SERVICE_SUCCEEDED()
173    return the value of SERVICE_SUCCEEDED
174int zoo_SERVICE_FAILED()
175    return the value of SERVICE_FAILED
176string zoo_Translate(string a)
177    return the translated string (using the "zoo-service" `textdomain
178    <http://www.gnu.org/software/libc/manual/html_node/Locating-gettext-catalog.html#index-textdomain>`__)
179
180void zoo_UpdateStatus(Array conf,string message,int pourcent)
181    update the status of the running service
182
183PHP ZCFG requirements
184**********************************
185
186The ZCFG file should contain the following :
187
188serviceType
189    PHP
190serviceProvider
191    The name of the php script (ie. service.php) to use as a ZOO Service Provider.
192
193PHP Data Structure used
194********************************
195
196The three parameters are passed to the PHP function as
197`Arrays <php.net/manual/language.types.array.php>`__.
198
199Sample ZOO PHP Services Provider
200******************************************
201
202.. code-block:: php
203
204  <?
205  function HelloPHP(&$main_conf,&$inputs,&$outputs){
206     $tmp="Hello ".$inputs[S][value]." from PHP world !";
207     $outputs["Result"]["value"]=zoo_Translate($tmp);
208     return zoo_SERVICE_SUCCEEDED();
209  }
210  ?>
211
212Java
213----
214
215Specifically for the Java support, you may add the following two
216sections to your ``main.cfg`` file:
217
218:[javaxx]:
219   This section is used to pass -XX:* parameters to the JVM  created by the
220   ZOO-Kernel to handle your ZOO-Service (see `ref. 1
221   <http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html#BehavioralOptions>`__
222   or `ref. 2
223   <http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html#PerformanceTuning>`__
224   for sample available).
225   For each map ``a = b`` available in the ``[javaxx]`` section, the
226   option ``-XX:a=b`` will be passed to the JVM. In case of a map ``a =
227   minus`` (respectively ``a=plus``) then the option ``-XX:-a``
228   (respectivelly ``-XX:+a``) will be passed.
229:[javax]:
230   The section is used to pass -X* options to the JVM (see
231   `ref. <http://docs.oracle.com/cd/E22289_01/html/821-1274/configuring-the-default-jvm-and-java-arguments.html>`__). For
232   each map ``a = b`` available in the ``[javax]`` section, the option
233   ``-Xab`` will be passed to the JVM (ie. set ``mx=2G`` to pass
234   ``-Xmx2G``).
235
236ZOO-API
237*******
238
239Before you build your first ZOO-Service implemented in Java, it is
240recommended that you first build the ZOO class of the Java ZOO-API.
241
242.. Note:: You should build ZOO-Kernel prior to follow this instructions.
243
244To build the ZOO.class of the ZOO-API for Java, use the following
245command:
246
247.. code-block:: guess
248
249  cd zoo-api/java
250  make
251  cp ZOO.class libZOO.so /usr/lib/cgi-bin
252
253.. Note:: running the previous commands will require that both
254          ``javac`` and ``javah`` are in your PATH.
255
256Java ZCFG requirements
257**********************************
258
259.. Note:: For each Service provided by your ZOO Java Services Provider
260          (your corresponding Java class), the ZCFG File should have
261          the name of the Java public method corresponding to the
262          service (case-sensitive).
263
264The ZCFG file should contain the following :
265
266serviceType
267    Java
268serviceProvider
269    The name of the Java class to use as a ZOO Service Provider. For instance, if your
270    java class, located in the same directory as your ZOO-Kernel, was
271    named ``HelloJava.class`` then you should use ``HelloJava``.
272
273Java Data Structure used
274********************************
275
276The three parameters are passed to the Java function as
277`java.util.HashMap <http://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html>`__.
278
279Sample ZOO Java Services Provider
280******************************************
281
282.. code-block:: java
283
284  import java.util.*;
285  public class HelloJava {
286    public static int HelloWorldJava(HashMap conf,HashMap inputs, HashMap outputs) {
287       HashMap hm1 = new HashMap();
288       hm1.put("dataType","string");
289       HashMap tmp=(HashMap)(inputs.get("S"));
290       java.lang.String v=tmp.get("value").toString();
291       hm1.put("value","Hello "+v+" from JAVA WOrld !");
292       outputs.put("Result",hm1);
293       System.err.println("Hello from JAVA WOrld !");
294       return ZOO.SERVICE_SUCCEEDED;
295    }
296  }
297
298Javascript
299----------
300
301ZOO API
302*********
303
304If you need to use :ref:`ZOO API <api>` in your service, you have first to copy ``zoo-api.js``
305and ``zoo-proj4js.js`` where your services are located (for example in Unix system probably in
306``/usr/lib/cgi-bin/``
307
308Javascript ZCFG requirements
309**********************************
310
311.. Note:: For each Service provided by your ZOO Javascript Services Provider, the ZCFG File
312          must be named the same as the Javascript function name (also the case of
313          characters is important).
314
315The ZCFG file should contain the following :
316
317serviceType
318    JS
319serviceProvider
320    The name of the JavaScript file to use as a ZOO Service Provider. For instance, if your
321    script, located in the same directory as your ZOO Kernel, was named ``my_module.js`` then
322    you should use ``my_module.js``.
323
324
325Javascript Data Structure used
326********************************
327
328The three parameters of the function are passed to the JavaScript function as Object.
329
330Sample ZOO Javascript Services Provider
331******************************************
332
333.. code-block:: javascript
334
335  function hellojs(conf,inputs,outputs){
336     outputs=new Array();
337     outputs={};
338     outputs["result"]["value"]="Hello "+inputs["S"]["value"]+" from JS World !";
339     return Array(3,outputs);
340  }
341
Note: See TracBrowser for help on using the repository browser.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png