midnight braindump
William Reade
william.reade at canonical.com
Tue Oct 2 22:15:43 UTC 2012
Hey all
I was just poking at Uniter.runHook(), and pondering how it really
*ought* to look, and I'm approaching a solution roughly like this (with
many details elided):
cmd/hook
type Context struct // once server.HookContext
func (*Context) NewCommand(string) (cmd.Command, error)
type RelationContext struct // interface? see later
// all hook tools: relation-set, config-get, etc
cmd/jujuc/server
type Server struct
// etc, but only the servery bits
worker/uniter/hook
type Env struct
func NewEnv(st *state.State, unitName, charmDir, toolsDir,
socketPath string) (*Env, error)
func (*Env) RunHook(Info, map[int]*hook.RelationContext)
In this formulation, a hook.Env draws together everything a hook needs
to execute. It runs a permanent jujuc server, which allows it to provide
the implementation of the hook tools, and is also responsible for
everything about the environment in which the hook process executes; it
also logs it and interprets its errors and so on.
This feels, in general, like an excellent move: it will simplify the
Uniter, and move the hook-env manipulation away from jujuc/server and
into a package with a better-fitting name.
I will, I think, soon propose a trivial move of the non-servery bits of
jujuc/server into cmd/hook, if nobody objects; and, soonish, a followup
that replaces much of Uniter.runHook, and parts of cmd/hook, with a
uniter/hook.Env type.
The map[int]*RelationContext can remain nil for now, and we should in
general be able to integrate the bits that understand relations
(cmd/hook) with a clean separation from the bits that don't yet
(Uniter); but this points to another interesting discussion we need to
have imminently:
I am feeling a strong pressure to move quite a lot of Relationer into
Uniter (EnterScope/LeaveScope, and StateDir manipulation) and the rest
into hook.Env (that is, everything RelationContext-manipulating --
possibly including moving much of the implementation of RelationContext
into Env too and turning hook.RelationContext into an interface with
Settings() and WriteSettings() (is it really just that? it might be,
near enough!)).
I don't think too much of the above is crack, but I would appreciate
feedback in case I am heading off into the weeds :).
Cheers
William
More information about the Juju-dev
mailing list