Merge branch 'master' of git.curoverse.com:arvados into 1968-monitor-disk-usage
[arvados.git] / doc / user / topics / tutorial-job1.html.textile.liquid
1 ---
2 layout: default
3 navsection: userguide
4 title: "Running a Crunch job on the command line"
5 ...
6
7 This tutorial introduces how to run individual Crunch jobs using the @arv@ command line tool.
8
9 *This tutorial assumes that you are "logged into an Arvados VM instance":{{site.baseurl}}/user/getting_started/ssh-access.html#login, and have a "working environment.":{{site.baseurl}}/user/getting_started/check-environment.html*
10
11 You will create a job to run the "hash" crunch script.  The "hash" script computes the md5 hash of each file in a collection.
12
13 h2. Jobs
14
15 Crunch pipelines consist of one or more jobs.  A "job" is a single run of a specific version of a crunch script with a specific input.  You an also run jobs individually.
16
17 A request to run a crunch job are is described using a JSON object.  For example:
18
19 <notextile>
20 <pre><code>~$ <span class="userinput">cat &gt;the_job &lt;&lt;EOF
21 {
22  "script": "hash",
23  "repository": "arvados",
24  "script_version": "master",
25  "script_parameters": {
26   "input": "c1bad4b39ca5a924e481008009d94e32+210"
27  }
28 }
29 EOF
30 </code></pre>
31 </notextile>
32
33 * @cat@ is a standard Unix utility that simply copies standard input to standard output
34 * @<<EOF@ tells the shell to direct the following lines into the standard input for @cat@ up until it sees the line @EOF@
35 * @>the_job@ redirects standard output to a file called @the_job@
36 * @"script"@ specifies the name of the script to run.  The script is searched for in the "crunch_scripts/" subdirectory of the @git@ checkout specified by @"script_version"@.
37 * @"repository"@ is the git repository to search for the script version.  You can access a list of available @git@ repositories on the Arvados workbench under "Compute %(rarr)&rarr;% Code repositories":https://{{site.arvados_workbench_host}}//repositories .
38 * @"script_version"@ specifies the version of the script that you wish to run.  This can be in the form of an explicit @git@ revision hash, a tag, or a branch (in which case it will take the HEAD of the specified branch).  Arvados logs the script version that was used in the run, enabling you to go back and re-run any past job with the guarantee that the exact same code will be used as was used in the previous run.
39 * @"script_parameters"@ are provided to the script.  In this case, the input is the locator for the collection that we inspected in the previous section.
40
41 Use @arv job create@ to actually submit the job.  It should print out a JSON object which describes the newly created job:
42
43 <notextile>
44 <pre><code>~$ <span class="userinput">arv job create --job "$(cat the_job)"</span>
45 {
46  "href":"https://qr1hi.arvadosapi.com/arvados/v1/jobs/qr1hi-8i9sb-1pm1t02dezhupss",
47  "kind":"arvados#job",
48  "etag":"ax3cn7w9whq2hdh983yxvq09p",
49  "uuid":"qr1hi-8i9sb-1pm1t02dezhupss",
50  "owner_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
51  "created_at":"2013-12-16T20:44:32Z",
52  "modified_by_client_uuid":"qr1hi-ozdt8-obw7foaks3qjyej",
53  "modified_by_user_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
54  "modified_at":"2013-12-16T20:44:32Z",
55  "updated_at":"2013-12-16T20:44:33Z",
56  "submit_id":null,
57  "priority":null,
58  "script":"hash",
59  "script_parameters":{
60   "input":"c1bad4b39ca5a924e481008009d94e32+210"
61  },
62  "script_version":"d9cd657b733d578ac0d2167dd75967aa4f22e0ac",
63  "cancelled_at":null,
64  "cancelled_by_client_uuid":null,
65  "cancelled_by_user_uuid":null,
66  "started_at":null,
67  "finished_at":null,
68  "output":null,
69  "success":null,
70  "running":null,
71  "is_locked_by_uuid":null,
72  "log":null,
73  "runtime_constraints":{},
74  "tasks_summary":{},
75  "dependencies":[
76   "c1bad4b39ca5a924e481008009d94e32+210"
77  ],
78  "log_stream_href":"https://qr1hi.arvadosapi.com/arvados/v1/jobs/qr1hi-8i9sb-1pm1t02dezhupss/log_tail_follow"
79 }
80 </code></pre>
81 </notextile>
82
83 The job is now queued and will start running as soon as it reaches the front of the queue.  Fields to pay attention to include:
84
85  * @"uuid"@ is the unique identifier for this specific job
86  * @"script_version"@ is the actual revision of the script used.  This is useful if the version was described using the "repository:branch" format.
87
88 h2. Monitor job progress
89
90 Go to the "Workbench dashboard":https://{{site.arvados_workbench_host}}.  Your job should be at the top of the "Recent jobs" table.  This table refreshes automatically.  When the job has completed successfully, it will show <span class="label label-success">finished</span> in the *Status* column.
91
92 On the command line, you can access log messages while the job runs using @arv job log_tail_follow@:
93
94 notextile. <pre><code>~$ <span class="userinput">arv job log_tail_follow --uuid qr1hi-8i9sb-xxxxxxxxxxxxxxx</span></code></pre>
95
96 This will print out the last several lines of the log for that job.
97
98 h2. Inspect the job output
99
100 On the "Workbench dashboard":https://{{site.arvados_workbench_host}}, look for the *Output* column of the *Recent jobs* table.  Click on the link under *Output* for your job to go to the files page with the job output.  The files page lists all the files that were output by the job.  Click on the link under the *files* column to view a file, or click on the download icon <span class="glyphicon glyphicon-download-alt"></span> to download the output file.
101
102 On the command line, you can use @arv job get@ to access a JSON object describing the output:
103
104 <notextile>
105 <pre><code>~$ <span class="userinput">arv job get --uuid qr1hi-8i9sb-xxxxxxxxxxxxxxx</span>
106 {
107  "href":"https://qr1hi.arvadosapi.com/arvados/v1/jobs/qr1hi-8i9sb-1pm1t02dezhupss",
108  "kind":"arvados#job",
109  "etag":"1bk98tdj0qipjy0rvrj03ta5r",
110  "uuid":"qr1hi-8i9sb-1pm1t02dezhupss",
111  "owner_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
112  "created_at":"2013-12-16T20:44:32Z",
113  "modified_by_client_uuid":null,
114  "modified_by_user_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
115  "modified_at":"2013-12-16T20:44:55Z",
116  "updated_at":"2013-12-16T20:44:55Z",
117  "submit_id":null,
118  "priority":null,
119  "script":"hash",
120  "script_parameters":{
121   "input":"c1bad4b39ca5a924e481008009d94e32+210"
122  },
123  "script_version":"d9cd657b733d578ac0d2167dd75967aa4f22e0ac",
124  "cancelled_at":null,
125  "cancelled_by_client_uuid":null,
126  "cancelled_by_user_uuid":null,
127  "started_at":"2013-12-16T20:44:36Z",
128  "finished_at":"2013-12-16T20:44:53Z",
129  "output":"dd755dbc8d49a67f4fe7dc843e4f10a6+54",
130  "success":true,
131  "running":false,
132  "is_locked_by_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
133  "log":"2afdc6c8b67372ffd22d8ce89d35411f+91",
134  "runtime_constraints":{},
135  "tasks_summary":{
136   "done":2,
137   "running":0,
138   "failed":0,
139   "todo":0
140  },
141  "dependencies":[
142   "c1bad4b39ca5a924e481008009d94e32+210"
143  ],
144  "log_stream_href":null
145 }
146 </code></pre>
147 </notextile>
148
149 * @"output"@ is the unique identifier for this specific job's output.  This is a Keep collection.  Because the output of Arvados jobs should be deterministic, the known expected output is <code>dd755dbc8d49a67f4fe7dc843e4f10a6+54</code>.
150
151 Now you can list the files in the collection:
152
153 <notextile>
154 <pre><code>~$ <span class="userinput">arv keep ls dd755dbc8d49a67f4fe7dc843e4f10a6+54</span>
155 md5sum.txt
156 </code></pre>
157 </notextile>
158
159 This collection consists of the @md5sum.txt@ file.  Use @arv keep get@ to show the contents of the @md5sum.txt@ file:
160
161 <notextile>
162 <pre><code>~$ <span class="userinput">arv keep get dd755dbc8d49a67f4fe7dc843e4f10a6+54/md5sum.txt</span>
163 44b8ae3fde7a8a88d2f7ebd237625b4f ./var-GS000016015-ASM.tsv.bz2
164 </code></pre>
165 </notextile>
166
167 This md5 hash matches the md5 hash which we computed earlier.
168
169 h2. The job log
170
171 When the job completes, you can access the job log.  On the workbench dashboard, this is the link under the *Log* column of the *Recent jobs* table.
172
173 On the command line, the keep identifier listed in the @"log"@ field from @arv job get@ specifies a collection.  You can list the files in the collection:
174
175 <notextile>
176 <pre><code>~$ <span class="userinput">arv keep ls xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+91</span>
177 qr1hi-8i9sb-xxxxxxxxxxxxxxx.log.txt
178 </code></pre>
179 </notextile>
180
181 The log collection consists of one log file named with the job id.  You can access it using @arv keep get@:
182
183 <notextile>
184 <pre><code>~$ <span class="userinput">arv keep get xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+91/qr1hi-8i9sb-xxxxxxxxxxxxxxx.log.txt</span>
185 2013-12-16_20:44:35 qr1hi-8i9sb-1pm1t02dezhupss 7575  check slurm allocation
186 2013-12-16_20:44:35 qr1hi-8i9sb-1pm1t02dezhupss 7575  node compute13 - 8 slots
187 2013-12-16_20:44:36 qr1hi-8i9sb-1pm1t02dezhupss 7575  start
188 2013-12-16_20:44:36 qr1hi-8i9sb-1pm1t02dezhupss 7575  Install revision d9cd657b733d578ac0d2167dd75967aa4f22e0ac
189 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  Clean-work-dir exited 0
190 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  Install exited 0
191 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  script hash
192 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  script_version d9cd657b733d578ac0d2167dd75967aa4f22e0ac
193 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  script_parameters {"input":"c1bad4b39ca5a924e481008009d94e32+210"}
194 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  runtime_constraints {"max_tasks_per_node":0}
195 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  start level 0
196 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 0 done, 0 running, 1 todo
197 2013-12-16_20:44:38 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 job_task qr1hi-ot0gb-23c1k3kwrf8da62
198 2013-12-16_20:44:38 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 child 7681 started on compute13.1
199
200 2013-12-16_20:44:38 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 0 done, 1 running, 0 todo
201 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 child 7681 on compute13.1 exit 0 signal 0 success=true
202 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 success in 1 seconds
203 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 output
204 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  wait for last 0 children to finish
205 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 1 done, 0 running, 1 todo
206 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  start level 1
207 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 1 done, 0 running, 1 todo
208 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 job_task qr1hi-ot0gb-iwr0o3unqothg28
209 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 child 7716 started on compute13.1
210 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 1 done, 1 running, 0 todo
211 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 child 7716 on compute13.1 exit 0 signal 0 success=true
212 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 success in 13 seconds
213 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 output dd755dbc8d49a67f4fe7dc843e4f10a6+54
214 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  wait for last 0 children to finish
215 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 2 done, 0 running, 0 todo
216 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  release job allocation
217 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  Freeze not implemented
218 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  collate
219 2013-12-16_20:44:53 qr1hi-8i9sb-1pm1t02dezhupss 7575  output dd755dbc8d49a67f4fe7dc843e4f10a6+54+K@qr1hi
220 2013-12-16_20:44:53 qr1hi-8i9sb-1pm1t02dezhupss 7575  finish
221 </code></pre>
222 </notextile>