github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/cmd/jujud/agent/engine/apiagent.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package engine 5 6 import ( 7 "github.com/juju/juju/agent" 8 "github.com/juju/juju/api/base" 9 "github.com/juju/juju/worker" 10 "github.com/juju/juju/worker/dependency" 11 ) 12 13 // Many manifolds completely depend on an agent and an API connection; this 14 // type configures them. 15 type AgentAPIManifoldConfig struct { 16 AgentName string 17 APICallerName string 18 } 19 20 // AgentAPIStartFunc encapsulates the behaviour that varies among AgentAPIManifolds. 21 type AgentAPIStartFunc func(agent.Agent, base.APICaller) (worker.Worker, error) 22 23 // AgentAPIManifold returns a dependency.Manifold that calls the supplied start 24 // func with the API and agent resources defined in the config (once those 25 // resources are present). 26 func AgentAPIManifold(config AgentAPIManifoldConfig, start AgentAPIStartFunc) dependency.Manifold { 27 return dependency.Manifold{ 28 Inputs: []string{ 29 config.AgentName, 30 config.APICallerName, 31 }, 32 Start: func(context dependency.Context) (worker.Worker, error) { 33 var agent agent.Agent 34 if err := context.Get(config.AgentName, &agent); err != nil { 35 return nil, err 36 } 37 var apiCaller base.APICaller 38 if err := context.Get(config.APICallerName, &apiCaller); err != nil { 39 return nil, err 40 } 41 return start(agent, apiCaller) 42 }, 43 } 44 }