Project

General

Profile

Containers API » History » Version 20

Tom Clegg, 12/02/2015 09:28 PM

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