open-nomad/client/allocrunnerv2/taskrunner
Michael Schurter 960f3be76c client: expose task state to client
The interesting decision in this commit was to expose AR's state and not
a fully materialized Allocation struct. AR.clientAlloc builds an Alloc
that contains the task state, so I considered simply memoizing and
exposing that method.

However, that would lead to AR having two awkwardly similar methods:
 - Alloc() - which returns the server-sent alloc
 - ClientAlloc() - which returns the fully materialized client alloc

Since ClientAlloc() could be memoized it would be just as cheap to call
as Alloc(), so why not replace Alloc() entirely?

Replacing Alloc() entirely would require Update() to immediately
materialize the task states on server-sent Allocs as there may have been
local task state changes since the server received an Alloc update.

This quickly becomes difficult to reason about: should Update hooks use
the TaskStates? Are state changes caused by TR Update hooks immediately
reflected in the Alloc? Should AR persist its copy of the Alloc? If so,
are its TaskStates canonical or the TaskStates on TR?

So! Forget that. Let's separate the static Allocation from the dynamic
AR & TR state!

 - AR.Alloc() is for static Allocation access (often for the Job)
 - AR.AllocState() is for the dynamic AR & TR runtime state (deployment
   status, task states, etc).

If code needs to know the status of a task: AllocState()
If code needs to know the names of tasks: Alloc()

It should be very easy for a developer to reason about which method they
should call and what they can do with the return values.
2018-10-16 16:56:55 -07:00
..
interfaces Remove SetState from interface 2018-10-16 16:53:29 -07:00
state wip 2018-10-16 16:53:29 -07:00
template Implement lifecycle hooks on the task runner 2018-10-16 16:53:29 -07:00
artifact_hook.go artifacts: don't emit event when there's no artifacts 2018-10-16 16:53:30 -07:00
errors.go Implement lifecycle hooks on the task runner 2018-10-16 16:53:29 -07:00
handleproxy.go tr: remove unneeded lock; chan synchronizes access 2018-10-16 16:56:55 -07:00
handleproxy_test.go tr: fix shutdown/destroy/WaitResult handling 2018-10-16 16:56:55 -07:00
lifecycle.go tr: fix shutdown/destroy/WaitResult handling 2018-10-16 16:56:55 -07:00
logmon_hook.go executor v2 (#4656) 2018-10-16 16:53:31 -07:00
logmon_hook_test.go executor v2 (#4656) 2018-10-16 16:53:31 -07:00
service_hook.go tr: implement stats collection hook 2018-10-16 16:53:31 -07:00
shutdown_delay_hook.go Implement lifecycle hooks on the task runner 2018-10-16 16:53:29 -07:00
stats_hook.go tr: add comments and cleanup call signature 2018-10-16 16:53:31 -07:00
stats_hook_test.go tr: implement stats collection hook 2018-10-16 16:53:31 -07:00
task_dir_hook.go Remove SetState from interface 2018-10-16 16:53:29 -07:00
task_runner.go client: expose task state to client 2018-10-16 16:56:55 -07:00
task_runner_getters.go tr: fix shutdown/destroy/WaitResult handling 2018-10-16 16:56:55 -07:00
task_runner_hooks.go tr: fix shutdown/destroy/WaitResult handling 2018-10-16 16:56:55 -07:00
template_hook.go Implement lifecycle hooks on the task runner 2018-10-16 16:53:29 -07:00
validate_hook.go tr: add validate task hook 2018-10-16 16:53:29 -07:00
validate_hook_test.go tr: add validate task hook 2018-10-16 16:53:29 -07:00
vault_hook.go Implement alloc updates in arv2 2018-10-16 16:53:30 -07:00