github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/fanconfigurer/manifold.go (about) 1 // Copyright 2017 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package fanconfigurer 5 6 import ( 7 "github.com/juju/errors" 8 "gopkg.in/juju/worker.v1" 9 "gopkg.in/juju/worker.v1/dependency" 10 11 "github.com/juju/clock" 12 "github.com/juju/juju/api/base" 13 apifanconfigurer "github.com/juju/juju/api/fanconfigurer" 14 ) 15 16 // ManifoldConfig defines the names of the manifolds on which a 17 // Manifold will depend. 18 type ManifoldConfig struct { 19 // These are the dependency resource names. 20 APICallerName string 21 Clock clock.Clock 22 } 23 24 // Manifold returns a dependency manifold that runs a fan configurer 25 // worker, using the resource names defined in the supplied config. 26 func Manifold(config ManifoldConfig) dependency.Manifold { 27 return dependency.Manifold{ 28 Inputs: []string{ 29 config.APICallerName, 30 }, 31 Output: func(in worker.Worker, out interface{}) error { 32 inWorker, _ := in.(*FanConfigurer) 33 if inWorker == nil { 34 return errors.Errorf("in should be a %T; got %T", inWorker, in) 35 } 36 switch outPointer := out.(type) { 37 case *bool: 38 *outPointer = true 39 default: 40 return errors.Errorf("out should be *bool; got %T", out) 41 } 42 return nil 43 }, 44 Start: func(context dependency.Context) (worker.Worker, error) { 45 var apiCaller base.APICaller 46 if err := context.Get(config.APICallerName, &apiCaller); err != nil { 47 return nil, errors.Trace(err) 48 } 49 50 facade := apifanconfigurer.NewFacade(apiCaller) 51 52 fanconfigurer, err := NewFanConfigurer(FanConfigurerConfig{ 53 Facade: facade, 54 }, config.Clock) 55 return fanconfigurer, errors.Annotate(err, "creating fanconfigurer orchestrator") 56 }, 57 } 58 }