Getting Started #23468/HEAD / v60 |
In this chapter we'll develop, deploy, and exercise a simple CSIP temperature conversion service. The service will receive a value in Celsius and will provide it in Fahrenheit, a truly simple operation. We will go through the steps from creating the source, compiling the service package, deploying it and executing the service with example data. To simplify this process, Docker engine is used to develop and execute a CSIP service in this chapter. Docker (https://docker.com) is a lightweight, container-based virtualization environment, which is available for all operating systems. CSIP Docker images are available on DockerHub (https://hub.docker.com). Instead of installing and configuring several software packages, we use two Docker image that are already setup and ready to be used. The following sections will use the First, let's install Docker. The Docker engine is supported on Linux, Cloud, Windows, and OS X. Install Docker according to the installations instructions found on: https://docs.docker.com/engine/installation. Once installed you should be able to execute the $ docker -v Docker version 1.10.3, build 20f81dd The CSIP Docker images was created with this version of docker, however it should work with earlier versions. First, we need a workspace that stores the source files and also the compiled packages. Create the workspace $ mkdir -p $HOME/work/java/m/conv
We also created the folder The source code of the temperature conversion service is shown below. It will be stored as $ cat > $HOME/work/java/m/conv/V1_0.java << END package m.conv; import javax.ws.rs.Path; import oms3.annotations.*; import csip.annotations.*; @Name("Temperature conversion.") @Path("m/conv/1.0") @Resource(type = ResourceType.OMS_COMP) public class V1_0 extends csip.ModelDataService { @Description("Temperature in C") @Unit("C") @In public double temp_c = 45.2; @Description("Temperature in F") @Unit("F") @Out public double temp_f; @Execute public void run() { temp_f = temp_c * 9 / 5 + 32; } } END
The service is using the JAX-RS, CSIP, and OMS3 API to mostly describe the service resources and elements with annotations and implement the conversion code. The The service must subclass DockerHub stores the image The $ sudo docker run --rm -it -v $HOME/work:/work olafdavid/csip_dev
Now, we should have our service package available for deployment. $ ls $HOME/work/dist csip.war The default package name is ' The created service package can now be deployed to an application server. Of course, we are using Docker again. This time it is a different, vanilla Tomcat 8 image. The $ sudo docker run -d --name csip_rt -p 8080:8080 tomcat:8-jre8
Next, we need to deploy our war file to the running container. Docker provides a copy ( $ sudo docker cp $HOME/work/dist/csip.war csip_rt:/usr/local/tomcat/webapps The Let's check if the $ curl http://localhost:8080/csip [{ "name": "Temperature conversion.", "description": "Temperature conversion.", "url": "http://localhost:8080/csip/m/conv/1.0" }]
Our temperature conversion service descriptor is returned, the only one in this package. Name and description are obtained "on-the-fly" from CSIP annotations in the service and the service URL is provided, too. If the package contains more than one service endpoint, they would all be listed in this JSON array. Now we like to know how to call the conversion service. The service parameter and input signature can be queried by invoking a $ curl http://localhost:8080/csip/m/conv/1.0 { "metainfo": {}, "parameter": [{ "name": "temp_c", "value": "45.2", "unit": "C", "description": "Temperature in C" }] } This call returns a JSON template that shows a valid service request for our conversion service. Where does this information come from? Now, service source annotations come to play. CSIP and OMS3 introspect the service annotations and construct an example JSON input payload. You recognize the mapping between the JSON elements and the annotations in the service source. CSIP services are self-describing. The Web Processing Services (WPS) multi-level approach of cataloging services and service signature exploration is also used in CSIP as seen in this little example. Those steps are optional but help to check the service availability. Now we are ready get to the third level, finally executing the service. We can simply store the request template by redirecting the curl output of the previous command to a file ' $ curl -s http://localhost:8080/csip/m/conv/1.0 >req.json
Since we have captured a valid request, we can just change the temperature input value in $ sed -i 's/45.2/5.123/' req.json
A CSIP service will always be invoked with a $ curl -X POST -H "content-type:application/json" \ -d @req.json http://localhost:8080/csip/m/conv/1.0 { "metainfo": { "status": "Finished", "suid": "63eff3f9-ebeb-11e5-bb63-658e82f5a7a4", "tstamp": "2016-03-16 20:53:13", "service_url": "http://localhost:8080/csip-example/m/conv/1.0", "request_ip": "127.0.0.1", "csip.version": "$version: 2.1.1 a0d47e2e9e7d 2016-03-16 $", "cpu_time": 12, "expiration_date": "2016-03-16 20:53:33" }, "parameter": [{ "name": "temp_c", "value": "5.123", "unit": "C", "description": "Temperature in C" }], "result": [{ "name": "temp_f", "value": "41.2214", "unit": "F", "description": "Temperature in F" }] } Since this is all RESTful, the response JSON contains the input parameter as well as the result, the converted temperature. CSIP also used the annotations of the the A client may now parse this JSON response and extract the result value for Once we are done with testing, the service can be shut down. $ sudo docker stop csip_rt This will stop the running container and the deployed service with it. The container still exists and can be restarted later with the conversion service intact ( Finally, removing the service container from the system is done by executing the $ sudo docker rm csip_rt This brief tutorial demonstrated the development, deployment and use of a simple CSIP service. Docker helped making this a painless experience, mostly with respect to the build process. For serious CSIP development, one might want to setup their own software stack on a development machine and download and install the required software. Temperature conversion is a simple one-line equation. This example shows the concise approach of combined annotations in JAX-RS, CSIP, and OMS3 to easily put together a modeling service. CSIP is designed from the ground up to serve complex models in a scalable setup. It was tested on hundreds of service nodes. It takes into account failover and supports responsiveness of applications by providing asynchronous access to services of long running models. CSIP is currently being used to serve (legacy) models for erosion, water quantity, water quality, rangeland hydrology, curve number hydrology, water supply forecasting, watershed delineation, detrended kriging, natural resource analysis and assessment, and more . CSIP services are also providing data for soils, climate, and agricultural land management information, etc. A comprehensive listing of available CSIP services can be found under https://alm.engr.colostate.edu/cb/project/csip. [1] Using different images for development and deployment makes good use of the 'separation of concerns' principle and follows best practices for isolating aspects. Development environments always differ from deployment infrastructures. Other tools such as Fig or Ansible may be used later for real world deployment. |
CSIP Navigation Bar
News- Feb 2017: CSIP & Kubernetes...- Dec 2016: CSIP at AGU ... - more ...
Releases
- Released Packages
Help
- Report a bug New Users Olaf David |