github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/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/clock" 8 "github.com/juju/errors" 9 "github.com/juju/worker/v3" 10 "github.com/juju/worker/v3/dependency" 11 12 apifanconfigurer "github.com/juju/juju/api/agent/fanconfigurer" 13 "github.com/juju/juju/api/base" 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 }