Project

General

Profile

Lib-gdal » History » Version 1

Herve Caumont, 2013-06-19 18:05

1 1 Herve Caumont
h1. GDAL Simple job
2
3
h2. Introduction
4
5
This simple job will demonstrate a few things about a typical sandbox usage:
6
* installing software packages
7
* configuration of a simple application taking geotiff files available on a remote FTP site and convert them to a chosen format (e.g. PNG) 
8
9
h2. Pre-requisites
10
11
To follow this simple tutorial you need:
12
* a running sandbox
13
* access to the sandbox 
14
less than 30 minutes of time 
15
16
h2. Step 1: install gdal on the sandbox
17
18
The installation of gdal is done via yum(Yellowdog Updater Modified)
19
20
Run the command below on your sandbox:
21
22
<pre>
23
[user@sb ~]$ sudo yum -y install gdal
24
</pre>
25
26
h2. Step 2: create the simplejob
27
28
!src/logo.png!
29
30
The simple job will require a folder under /application:
31
32
<pre>
33
[user@sb ~] cd /application
34
[user@sb application] mkdir simplejob
35
[user@sb application] cd simplejob
36
</pre>
37
38
h3. Create the wrapper file which handles the input parameters 
39
40
<pre>
41
[user@sb simplejob] vi run
42
</pre>
43
44
Note: You can use any editor you like
45
46
h3. Paste the code below in the run file:
47
48
<pre>
49
#!/bin/bash
50
51
# Project:       ${project.name}
52
# Author:        $Author: stripodi $ (Terradue Srl)
53
# Last update:   $Date: 2011-09-08 12:01:58 +0200 (Thu, 08 Sep 2011) $
54
# Element:       ${project.name}
55
# Context:       services/${project.artifactId}
56
# Version:       ${project.version} (${implementation.build})
57
# Description:   ${project.description}
58
#
59
# This document is the property of Terradue and contains information directly
60
# resulting from knowledge and experience of Terradue.
61
# Any changes to this code is forbidden without written consent from Terradue Srl
62
#
63
# Contact: info@terradue.com
64
# 2012-02-10 - NEST in jobConfig upgraded to version 4B-1.1
65
66
# source the ciop functions (e.g. ciop-log)
67
source ${ciop_job_include}
68
69
# define the exit codes
70
SUCCESS=0
71
ERR_NOINPUT=1
72
ERR_NOPARAMS=2
73
ERR_GDAL=4
74
75
# add a trap to exit gracefully
76
function cleanExit ()
77
{
78
   local retval=$?
79
   local msg=""
80
   case "$retval" in
81
     $SUCCESS)      msg="Processing successfully concluded";;
82
     $ERR_NOPARAMS) msg="Outout format not defined";;
83
     $ERR_GDAL)    msg="Graph processing of job ${JOBNAME} failed (exit code $res)";;
84
     *)             msg="Unknown error";;
85
   esac
86
   [ "$retval" != "0" ] && ciop-log "ERROR" "Error $retval - $msg, processing aborted" || ciop-log "INFO" "$msg"
87
   exit $retval
88
}
89
trap cleanExit EXIT
90
91
# retrieve the parameters value from workflow or job default value
92
format=`ciop-getparam format`
93
94
# run a check on the format value
95
[ -z "$format" ] && exit $ERR_NOPARAMS
96
97
# loop through all geotiff URLs passed as stdin
98
while read inputfile 
99
do
100
	# report activity in log
101
	ciop-log "INFO" "Retrieving $inputfile from storage"
102
103
	# retrieve the remote geotiff product to the local temporary folder
104
	retrieved=`ciop-copy -o $TMPDIR $inputfile`
105
	
106
	# check if the file was retrieved
107
	[ "$?" == "0" -a -e "$retrieved" ] || exit $ERR_NOINPUT
108
	
109
	# report activity
110
	ciop-log "INFO" "Retrieved $retrieved"
111
	
112
	# invoke gdal to convert the geotiff into selected format
113
	gdal_translate -of $format $retrieved $OUTPUTDIR/`basename $retrieved`	
114
115
	# check error code
116
	[ "$?" != "0" ] && exit $ERR_GDAL || ciop-log "INFO" "Processed $inputfile"
117
done
118
119
exit 0
120
</pre>
121
122
h3. Create the application descriptor 
123
124
Go up one level to /application
125
126
<pre>
127
[user@sb ~] cd /application
128
[user@sb application] vi application.xml
129
</pre>
130
131
Paste the XML content:
132
133
<pre>
134
<?xml version="1.0" encoding="UTF-8"?>
135
<application id="example"> <!-- you can type any id you want --> 
136
	<jobTemplates>
137
		<jobTemplate id="gdalformatconv"> <!-- this is the job name -->
138
			<streamingExecutable>/application/simplejob/run</streamingExecutable> <!-- this is the wrapper script --> 
139
			<defaultParameters>							
140
				<parameter id="format">PNG</parameter> <!-- this sets the default value for parameter format -->
141
			</defaultParameters>
142
		</jobTemplate>
143
	</jobTemplates>
144
	<workflow id="workflow">	<!-- Sample workflow -->
145
		<workflowVersion>1.0</workflowVersion>
146
		<workflowDescription>My simple workflow</workflowDescription> <!-- provide a description to the workflow -->
147
		<node id="gdal"> 		<!-- workflow node unique id -->
148
			<job id="gdalformatconv"></job>		<!-- job defined above -->
149
			<sources>
150
				<source refid="file:urls" >/home/fbrito/geotiff.urls</source> <!-- the geotiff URLs are provided on an ASCII file, set your username value -->
151
			</sources>
152
			<parameters></parameters>
153
		</node>
154
	</workflow>
155
</application>
156
</pre>
157
158
Create the URLs files in your home directory 
159
160
<pre>
161
[user@sb application] cd 
162
[user@sb ~] vi geotiff.urls
163
</pre>
164
165
Add a few URLs:
166
167
<pre>
168
ftp://ftp.remotesensing.org/pub/geotiff/samples/spot/chicago/SP27GTIF.TIF
169
ftp://ftp.remotesensing.org/pub/geotiff/samples/spot/chicago/UTM2GTIF.TIF
170
</pre>
171
172
h2. Step 3: execute the job
173
174
h3. Execute the simple job
175
176
Optionally list the nodes you can execute:
177
178
<pre>
179
[user@sb ~] ciop-simjob -n
180
</pre>
181
182
This will return:
183
<pre>
184
gdal
185
</pre>
186
187
Process it!
188
189
<pre> 
190
[user@sb ~] ciop-simjob gdal
191
</pre>
192
193
The job is executed and a tracking URL is provided to follow the progress and access the execution logs. Open the URL on a browser
194
195
TBC
196
197
h3. Check the gdal node results
198
199
The generated files are published on a local filesystem:
200
201
<pre>
202
[user@sb ~] cd /share/tmp/TBC
203
</pre>
204
205
There should be two image files in the file format defined by default: PNG
206
207
h3. Define another file format to test the node
208
209
Edit the application.xml file and add the line:
210
211
<pre>
212
<parameter id="format">JPEG</parameter>
213
</pre>
214
215
To obtain:
216
217
<pre>
218
<?xml version="1.0" encoding="UTF-8"?>
219
<application id="example">
220
	<jobTemplates>
221
		<jobTemplate id="gdalformatconv">
222
			<streamingExecutable>/application/simplejob/run</streamingExecutable>
223
			<defaultParameters>							
224
				<parameter id="format">PNG</parameter>
225
			</defaultParameters>
226
		</jobTemplate>
227
	</jobTemplates>
228
	<workflow id="workflow">							<!-- Sample workflow -->
229
		<workflowVersion>1.0</workflowVersion>
230
		<workflowDescription>My simple workflow</workflowDescription>
231
		<node id="gdal">							<!-- workflow node unique id -->
232
			<job id="gdalformatconv"></job>					<!-- job defined above -->
233
			<sources>
234
				<source refid="file:urls" >/home/fbrito/geotiff.urls</source>
235
			</sources>
236
			<parameters>
237
				<parameter id="format">JPEG</parameter>
238
			</parameters>
239
		</node>
240
	</workflow>
241
</application>
242
</pre>
243
244
Run the job again this time using the ciop-simjob flag to delete the previous run results:
245
246
<pre> 
247
[user@sb ~] ciop-simjob -f gdal
248
</pre>
249
250
The generated files are published on a local filesystem:
251
252
<pre>
253
[user@sb ~] cd /share/tmp/TBC
254
</pre>
255
256
There should be two image files in the file format defined at workflow level: JPEG
257
258
h3. Run the application as a workflow
259
260
Our workflow has a single job but it's still a workflow!
261
262
You can trigger the workflow with:
263
264
<pre>
265
[user@sb ~] ciop-simwf
266
</pre>
267
268
You can track the workflow execution on the shell. Wait for the workflow conclusion.
269
270
Use the command below to get the latest workflow run:
271
<pre>
272
[user@sb ~] ciop-simwf -l
273
0000000-130405042430716-oozie-oozi-W
274
</pre>
275
276
Use the value returned above to check the workflow results:
277
278
<pre>
279
[user@sb ~] ll tmp/sandbox/run/0000000-130405042430716-oozie-oozi-W/gdal/output
280
</pre>
281
282
You can optionally delete the generated results:
283
284
285
286
h2. Conclusion
287
288
With this simple job you have learned:
289
* how to install packages to run your application using yum
290
* how to create a job template in your sanbox
291
* how to write the job wrapper script
292
* how to define the application descriptor
293
* how to execute the job with the default parameter
294
* how to execute the job with the parameter value definition 
295
* how to execute the workflow
296
* how to check the generated results