github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/jujud/agent/util/apiagent.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package util 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 }