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