Project

General

Profile

Containers API » History » Version 12

Tom Clegg, 06/09/2015 08:24 PM

1 9 Tom Clegg
{{>TOC}}
2
3 2 Tom Clegg
h1. Jobs API (DRAFT)
4 1 Tom Clegg
5 11 Tom Clegg
A Job is a record of a computational process.
6
* Its goal is to capture, unambiguously, as much information as possible about the environment in which the process was run. For example, git trees, data collections, and docker images are stored as content addresses. This makes it possible to reason about the difference between two processes, and to replay a process at a different time and place.
7
* Clients can read Job records, but only the system can create or modify them.
8 1 Tom Clegg
9 11 Tom Clegg
A JobRequest is a client's expression of interest in knowing the outcome of a computational process.
10
* Typically, in this context the client's description of the process is less precise than a Job: a JobRequest describes job _constraints_ which can have different interpretations over time. For example, a JobRequest with a @{"kind":"git_tree","commit_range":"abc123..master",...}@ mount might be satisfiable by any of several different source trees, and this set of satisfying source trees can change when the repository's "master" branch is updated.
11
* The system is responsible for finding suitable Jobs and assigning them to JobRequests. (Currently this is expected to be done synchronously during the jobRequests.create and jobRequests.update transactions.)
12
* A JobRequest may indicate that it can _only_ be satisfied by a new Job record (i.e., existing results should not be reused). In this case creating a JobRequest amounts to a submission to the job queue. This is appropriate when the purpose of the JobRequest is to test whether a process is repeatable.
13
* A JobRequest may indicate that it _cannot_ be satisfied by a new Job record. This is an appropriate way to test whether a result is already available.
14 6 Tom Clegg
15 11 Tom Clegg
When the system has assigned a Job to a JobRequest, anyone with permission to read the JobRequest also has permission to read the Job.
16 1 Tom Clegg
17 9 Tom Clegg
h2. Use cases
18
19
h3. Preview
20
21
Tell me how you would satisfy job request X. Which pdh/commits would be used? Is the satisfying job already started? finished?
22
23
h3. Submit a previewed existing job
24
25
I'm happy with the already-running/finished job you showed me in "preview". Give me access to that job, its logs, and [when it finishes] its output.
26
27
h3. Submit a previewed new job
28
29
I'm happy with the new job the "preview" response proposed to run. Run that job.
30
31
h3. Submit a new job (disable reuse)
32
33
I don't want to use an already-running/finished job. Run a new job that satisfies my job request.
34
35
h3. Submit a new duplicate job (disable reuse)
36
37
I'm happy with the already-running/finished job you showed me in "preview". Run a new job exactly like that one.
38
39
h3. Select a job and associate it with my JobRequest
40
41
I'm not happy with the job you chose, but I know of another job that satisfies my request. Assuming I'm right about that, attach my JobRequest to the existing job of my choice.
42
43
h3. Just do the right thing without a preview
44
45
Satisfy job request X one way or another, and tell me the resulting job's UUID.
46
47 6 Tom Clegg
h2. JobRequest/Job life cycle
48
49
Illustrating job re-use and preview facility:
50
# Client CA creates a JobRequest JRA with priority=0.
51
# Server creates job JX and assigns JX to JRA, but does not try to run JX yet because max(priority)=0.
52
# Client CA presents JX to the user. "We haven't computed this result yet, so we'll have to run a new job. Is this OK?"
53
# Client CB creates a JobRequest JRB with priority=1.
54 1 Tom Clegg
# Server assigns JX to JRB and puts JX in the execution queue with priority=1.
55 6 Tom Clegg
# Client CA updates JRA with priority=2.
56
# Server updates JX with priority=2.
57
# Job JX starts.
58 11 Tom Clegg
# Client CA updates JRA with priority=0. (This is as close as we get to a "cancel" operation.)
59 6 Tom Clegg
# Server updates JX with priority=1. (JRB still wants this job to complete.)
60
# Job JX finishes.
61 1 Tom Clegg
# Clients CA and CB have permission to read JX (ever since JX was assigned to their respective JobRequests) as well as its progress indicators, output, and log.
62 5 Tom Clegg
63 1 Tom Clegg
h2. "JobRequest" schema
64
65
|Attribute|Type|Description|Discussion|Examples|
66 6 Tom Clegg
|uuid, owner_uuid, modified_by_client_uuid,  modified_by_user_uuid|string|Usual Arvados model attributes|||
67
|
68
|created_at, modified_at|datetime|Usual Arvados model attributes|||
69
|
70 1 Tom Clegg
|name|string|Unparsed|||
71
|
72
|description|text|Unparsed|||
73 6 Tom Clegg
|
74 11 Tom Clegg
|state|string|Once a request is committed, priority is the only attribute that can be modified.||@"Uncommitted"@
75
@"Committed"@|
76
|
77 12 Tom Clegg
|requesting_job_uuid|string|When the referenced job exits, the job request is automatically cancelled.|||
78
|
79 6 Tom Clegg
|job_uuid|uuid|The job that satisfies this job request.|
80 8 Tom Clegg
Can be null if a suitable job has not yet been found or queued.
81
Assigned by the system: cannot be modified directly by clients.
82
If null, it can be changed by the system at any time.
83
If not null, it can be reset to null by a client _if priority is zero_.||
84
|
85
|mounts|hash|Objects to attach to the container's filesystem and stdin/stdout.
86
Keys starting with a forward slash indicate objects mounted in the container's filesystem.
87
Other keys are given special meanings here.|
88
We use "stdin" instead of "/dev/stdin" because literally replacing /dev/stdin with a file would have a confusing effect on many unix programs. The stdin feature only affects the standard input of the first process started in the container; after that, the usual rules apply.|
89 1 Tom Clegg
<pre>{
90
 "/input/foo":{
91
  "kind":"collection",
92
  "portable_data_hash":"d41d8cd98f00b204e9800998ecf8427e+0"
93
 },
94 9 Tom Clegg
 "stdin":{
95 1 Tom Clegg
  "kind":"collection_file",
96
  "uuid":"zzzzz-4zz18-yyyyyyyyyyyyyyy",
97
  "path":"/foo.txt"
98 8 Tom Clegg
 },
99 9 Tom Clegg
 "stdout":{
100 1 Tom Clegg
  "kind":"regular_file",
101 9 Tom Clegg
  "path":"/tmp/a.out"
102 1 Tom Clegg
 }
103
}</pre>|
104 8 Tom Clegg
|
105 11 Tom Clegg
|runtime_constraints|hash|Restrict the job's access to compute resources and the outside world (in addition to its explicitly stated inputs and output).
106 10 Tom Clegg
Each key is the name of a capability, like "internet" or "API" or "clock". The corresponding value is @true@ (the capability must be available in the job's runtime environment) or @false@ (must not) or a value or an array of two numbers indicating an inclusive range. If a key is omitted, availability of the corresponding capability is acceptable but not necessary.|This is a generalized version of "enforce purity restrictions": it is not a claim that the job will be pure. Rather, it helps us control and track runtime restrictions, which can be helpful when reasoning about whether a given job was pure.
107 1 Tom Clegg
In the most basic implementation, no capabilities are defined, and the only acceptable value of this attribute is the empty hash.
108 10 Tom Clegg
(TC)Should this structure be extensible like mounts?|
109
<pre>
110
{
111
  "ram":12000000000,
112
  "vcpus":[1,null]
113
}</pre>|
114
|
115 1 Tom Clegg
|container_image|string|Docker image repository and tag, docker image hash, collection UUID, or collection PDH.|||
116
|
117
|environment|hash|environment variables and values that should be set in the container environment (docker run --env). This augments and (when conflicts exists) overrides environment variables given in the image's Dockerfile.|||
118
|
119 10 Tom Clegg
|cwd|string|initial working directory, given as an absolute path (in the container) or a path relative to the WORKDIR given in the image's Dockerfile. The default is @"."@.||<pre>"/tmp"</pre>|
120 8 Tom Clegg
|
121 10 Tom Clegg
|command|array of strings|Command to execute in the container. Default is the CMD given in the image's Dockerfile.|
122 1 Tom Clegg
To use a UNIX pipeline, like "echo foo &#124; tr f b", or to interpolate environment variables, make sure your container image has a shell, and use a command like @["sh","-c","echo $PATH &#124; wc"]@.||
123
|
124
|output_path|string|Path to a directory or file inside the container that should be preserved as job's output when it finishes.|This path _must_ be, or be inside, one of the mount targets.
125
For best performance, point output_path to a writable collection mount.||
126
|
127
|priority|number|Higher number means spend more resources (e.g., go ahead of other queued jobs, bring up more nodes).
128 11 Tom Clegg
Zero means a job should not be run on behalf of this request. (Clients are expected to submit JobRequests with zero priority in order to prevew the job that will be used to satisfy it.)
129
Priority is null if and only if @state="Uncommitted"@.||
130
null
131
@0@
132
@1000.5@
133
@-1@|
134 1 Tom Clegg
|
135 11 Tom Clegg
|expires_at|datetime|After this time, priority is considered to be zero. If the assigned job is running at that time, the job _may_ be cancelled to conserve resources.||
136
null
137
@2015-07-01T00:00:01Z@|
138
|
139
|filters|array|Additional constraints for satisfying the request, given in the same form as the @filters@ parameter accepted by the @jobs.list@ API.||
140
@["created_at","<","2015-07-01T00:00:01Z"]@|
141
|
142 1 Tom Clegg
143
h2. "Job" schema
144
145 9 Tom Clegg
|Attribute|Type|Description|Discussion|Examples|
146 1 Tom Clegg
|
147 9 Tom Clegg
|uuid, owner_uuid, created_at, modified_at, modified_by_client_uuid,  modified_by_user_uuid|string|Usual Arvados model attributes|||
148
|
149
|state|string|||
150
<pre>
151
"Queued"
152
"Running"
153
"Cancelled"
154 8 Tom Clegg
"Failed"
155 1 Tom Clegg
"Complete"
156
</pre>|
157
|
158
|started_at, finished_at, log||Same as current job|||
159 9 Tom Clegg
|
160 8 Tom Clegg
|environment|hash|Must be equal to a JobRequest's environment in order to satisfy the JobRequest.|(TC)We could offer a "resolve" process here like we do with mounts: e.g., hash values in the JobRequest environment could be resolved according to the given "kind". I propose we leave room for this feature but don't add it yet.||
161 9 Tom Clegg
|
162
|cwd, command, output_path|string|Must be equal to the corresponding values in a JobRequest in order to satisfy that JobRequest.|||
163
|
164
|mounts|hash|Must contain the same keys as the JobRequest being satisfied. Each value must be within the range of values described in the JobRequest _at the time the Job is assigned to the JobRequest._|||
165 1 Tom Clegg
|
166 11 Tom Clegg
|runtime_constraints|hash|Compute resources, and access to the outside world, that are/were available to the job. Generally this will contain additional keys that are not present in any corresponding JobRequests: for example, even if no JobRequests specified constraints on the number of CPU cores, the number of cores actually used will be recorded here.|
167
Permission/access types will change over time and it may be hard/impossible to translate old types to new. Such cases may cause old Jobs to be inelegible for assignment to new JobRequests.
168
(TC)Is it permissible for this to gain keys over time? For example, a job scheduler might not be able to predict how many CPU cores will be available until the job starts.||
169 9 Tom Clegg
|
170
|output|string|Portable data hash of the output collection.|||
171
|
172
|-pure-|-boolean-|-The job's output is thought to be dependent solely on its inputs, i.e., it is expected to produce identical output if repeated.-|
173
We want a feature along these lines, but "pure" seems to be a conclusion we can come to after examining various facts -- rather than a property of an individual job execution event -- and it probably needs something more subtle than a boolean.||
174
|
175 10 Tom Clegg
|container_image|string|Portable data hash of a collection containing the docker image used to run the job.|(TC) *If* docker image hashes can be verified efficiently, we can use the native docker image hash here instead of a collection PDH.||
176 8 Tom Clegg
|
177
|progress|number|A number between 0.0 and 1.0 describing the fraction of work done.|
178 10 Tom Clegg
If a job submits jobs of its own, it should update its own progress as the child jobs progress/finish.||
179 8 Tom Clegg
|
180 10 Tom Clegg
|priority|number|Priority assigned by the system, taking into account the priorities of all associated JobRequests.|||
181 8 Tom Clegg
182
h2. Mount types
183
184
The "mounts" hash is the primary mechanism for adding data to the container at runtime (beyond what is already in the container image).
185
186
Each value of the "mounts" hash is itself a hash, whose "kind" key determines the handler used to attach data to the container.
187
188
|Mount type|@kind@|Expected keys|Description|Examples|Discussion|
189
|
190 9 Tom Clegg
|Arvados data collection|@collection@|
191
@"portable_data_hash"@ _or_ @"uuid"@ _may_ be provided. If not provided, a new collection will be created. This is useful when @"writable":true@ and the job's @output_path@ is (or is a subdirectory of) this mount target.
192
@"writable"@ may be provided with a @true@ or @false@ to indicate the path must (or must not) be writable. If not specified, the system can choose.
193
@"path"@ may be provided, and defaults to @"/"@.|
194
At job startup, the target path will have the same directory structure as the given path within the collection. Even if the files/directories are writable in the container, modifications will _not_ be saved back to the original collections when the job ends.|
195 8 Tom Clegg
<pre>
196
{
197
 "kind":"collection",
198 9 Tom Clegg
 "uuid":"...",
199
 "path":"/foo.txt"
200 8 Tom Clegg
}
201 9 Tom Clegg
202 8 Tom Clegg
{
203 9 Tom Clegg
 "kind":"collection",
204 8 Tom Clegg
 "uuid":"..."
205
}
206
</pre>|
207
|
208
|Git tree|@git_tree@|
209 9 Tom Clegg
One of {@"git-url"@, @"repository_name"@, @"uuid"@} must be provided.
210
One of {@"commit"@, @"revisions"@} must be provided.
211 8 Tom Clegg
"path" may be provided. The default path is "/".|
212
At job startup, the target path will have the source tree indicated by the given revision. The @.git@ metadata directory _will not_ be available: typically the system will use @git-archive@ rather than @git-checkout@ to prepare the target directory.
213
If a value is given for @"revisions"@, it will be resolved to a set of commits (as desribed in the "ranges" section of git-revisions(1)) and the job request will be satisfiable by any commit in that set.
214 9 Tom Clegg
If a value is given for @"commit"@, it will be resolved to a single commit, and the tree resulting from that commit will be used.
215
@"path"@ can be used to select a subdirectory or a single file from the tree indicated by the selected commit.
216 8 Tom Clegg
Note that multiple commits can resolve to the same tree: for example, the file/directory given in @"path"@ might not have changed between commits A and B.|
217
<pre>
218
{
219 1 Tom Clegg
 "kind":"git_tree",
220 8 Tom Clegg
 "uuid":"zzzzz-s0uqq-xxxxxxxxxxxxxxx",
221
 "commit":"master"
222
}
223
224 1 Tom Clegg
{
225 9 Tom Clegg
 "kind":"git_tree",
226 5 Tom Clegg
 "uuid":"zzzzz-s0uqq-xxxxxxxxxxxxxxx",
227 1 Tom Clegg
 "commit_range":"bugfix^..master",
228 8 Tom Clegg
 "path":"/crunch_scripts/grep"
229 5 Tom Clegg
}
230 8 Tom Clegg
</pre>|The resolved mount (found in the Job record) will have only the "kind" key and a "blob" or "tree" key indicating the 40-character hash of the git tree/blob used.|
231 5 Tom Clegg
|
232 8 Tom Clegg
|Temporary directory|@tmp@|
233
@"capacity"@: capacity (in bytes) of the storage device|
234
At job startup, the target path will be empty. When the job finishes, the content will be discarded. This will be backed by a memory-based filesystem where possible.|
235
<pre>
236 2 Tom Clegg
{
237 8 Tom Clegg
 "kind":"tmp",
238 11 Tom Clegg
 "capacity":10000000000
239 8 Tom Clegg
}
240
</pre>||
241 12 Tom Clegg
|
242
|Keep|@keep@|
243
Expose all readable collections via arv-mount.|
244
<pre>
245
{
246
 "kind":"keep"
247
}
248
</pre>|Requires suitable runtime constraints.|
249 2 Tom Clegg
|
250 8 Tom Clegg
251 1 Tom Clegg
252
h2. Permissions
253
254
Users own JobRequests but the system owns Jobs.  Users get permission to read Jobs by virtue of linked JobRequests.
255
256
h2. API methods
257
258
Changes from the usual REST APIs:
259
260
h3. arvados.v1.job_requests.create and .update
261
262
These methods can fail when objects referenced in the "mounts" hash do not exist, or the acting user has insufficient permission on them.
263 8 Tom Clegg
264 11 Tom Clegg
If @state="Uncommitted"@:
265
* has null @priority@.
266
* can have its @job_uuid@ reset to null by a client.
267
* can have its @job_uuid@ set to a non-null value by a system process.
268 2 Tom Clegg
269 11 Tom Clegg
If @state="Committed"@:
270
* has non-null @priority@.
271
* cannot be modified, except that its @priority@ can be changed to another non-null value.
272 8 Tom Clegg
273 11 Tom Clegg
h3. arvados.v1.job_requests.cancel
274 8 Tom Clegg
275 11 Tom Clegg
Set @priority@ to zero.
276 8 Tom Clegg
277 11 Tom Clegg
h3. arvados.v1.job_requests.satisfy
278
279
Find or create a suitable job, and update @job_uuid@.
280
281
Return an error if @job_uuid@ is not null.
282
283
Q: Can this be requested during create? Create+satisfy is a common operation so having a way to do it in a single API call might be a worthwhile convenience.
284
285
Q: Better name?
286
287 1 Tom Clegg
h3. arvados.v1.jobs.create and .update
288
289
These methods are not callable except by system processes.
290
291
h3. arvados.v1.jobs.progress
292
293
This method permits specific types of updates while a job is running: update progress, record success/failure.
294
295
Q: [How] can a client submitting job B indicate it shouldn't run unless/until job A succeeds?
296
297
h2. Debugging
298
299
Q: Need any infrastructure debug-logging controls in this API?
300
301
Q: Need any job debug-logging controls in this API? Or just use environment vars?
302
303
h2. Scheduling and running jobs
304
305
Q: When/how should we implement a hooks for futures/promises: e.g., "run job Y when jobs X0, X1, and X2 have finished"?
306 11 Tom Clegg
307
h2. Accounting
308
309
A complete design for resource accounting and quota is out of scope here, but we do assert here that the API makes it feasible to retain accounting data.
310
311
It should be possible to retrieve, for a given job, a complete set of resource allocation intervals, each one including:
312
* interval start time
313
* interval end time (presented as null or now if the interval hasn't ended yet)
314
* user uuid
315
* job request id
316
* job request priority
317
* job state