func (app *app) Setup(args []string) error { opts, err := ParseOptions(args) if err != nil { return bosherr.WrapError(err, "Parsing options") } config, err := app.loadConfig(opts.ConfigPath) if err != nil { return bosherr.WrapError(err, "Loading config") } dirProvider := boshdirs.NewDirectoriesProvider(opts.BaseDirectory) platformProvider := boshplatform.NewProvider(app.logger, dirProvider, config.Platform) app.platform, err = platformProvider.Get(opts.PlatformName) if err != nil { return bosherr.WrapError(err, "Getting platform") } infProvider := boshinf.NewProvider(app.logger, app.platform) app.infrastructure, err = infProvider.Get(opts.InfrastructureName) app.platform.SetDevicePathResolver(app.infrastructure.GetDevicePathResolver()) if err != nil { return bosherr.WrapError(err, "Getting infrastructure") } settingsServiceProvider := boshsettings.NewServiceProvider() boot := boshboot.New( app.infrastructure, app.platform, dirProvider, settingsServiceProvider, app.logger, ) settingsService, err := boot.Run() if err != nil { return bosherr.WrapError(err, "Running bootstrap") } mbusHandlerProvider := boshmbus.NewHandlerProvider(settingsService, app.logger) mbusHandler, err := mbusHandlerProvider.Get(app.platform, dirProvider) if err != nil { return bosherr.WrapError(err, "Getting mbus handler") } blobstoreProvider := boshblob.NewProvider(app.platform, dirProvider) blobstore, err := blobstoreProvider.Get(settingsService.GetBlobstore()) if err != nil { return bosherr.WrapError(err, "Getting blobstore") } monitClientProvider := boshmonit.NewProvider(app.platform, app.logger) monitClient, err := monitClientProvider.Get() if err != nil { return bosherr.WrapError(err, "Getting monit client") } jobSupervisorProvider := boshjobsuper.NewProvider( app.platform, monitClient, app.logger, dirProvider, mbusHandler, ) jobSupervisor, err := jobSupervisorProvider.Get(opts.JobSupervisor) if err != nil { return bosherr.WrapError(err, "Getting job supervisor") } notifier := boshnotif.NewNotifier(mbusHandler) applier, compiler := app.buildApplierAndCompiler(dirProvider, blobstore, jobSupervisor) uuidGen := boshuuid.NewGenerator() taskService := boshtask.NewAsyncTaskService(uuidGen, app.logger) taskManager := boshtask.NewManagerProvider().NewManager( app.logger, app.platform.GetFs(), dirProvider.BoshDir(), ) specFilePath := filepath.Join(dirProvider.BoshDir(), "spec.json") specService := boshas.NewConcreteV1Service( app.platform.GetFs(), app.platform, specFilePath, ) drainScriptProvider := boshdrain.NewConcreteDrainScriptProvider( app.platform.GetRunner(), app.platform.GetFs(), dirProvider, ) actionFactory := boshaction.NewFactory( settingsService, app.platform, blobstore, taskService, notifier, applier, compiler, jobSupervisor, specService, drainScriptProvider, app.logger, ) actionRunner := boshaction.NewRunner() actionDispatcher := boshagent.NewActionDispatcher( app.logger, taskService, taskManager, actionFactory, actionRunner, ) alertBuilder := boshalert.NewBuilder(settingsService, app.logger) alertSender := boshagent.NewAlertSender(mbusHandler, alertBuilder) app.agent = boshagent.New( app.logger, mbusHandler, app.platform, actionDispatcher, alertSender, jobSupervisor, specService, time.Minute, ) return nil }
func (app *app) Setup(args []string) (err error) { opts, err := ParseOptions(args) if err != nil { err = bosherr.WrapError(err, "Parsing options") return } dirProvider := boshdirs.NewDirectoriesProvider(opts.BaseDirectory) platformProvider := boshplatform.NewProvider(app.logger, dirProvider) app.platform, err = platformProvider.Get(opts.PlatformName) if err != nil { err = bosherr.WrapError(err, "Getting platform") return } infProvider := boshinf.NewProvider(app.logger, app.platform) app.infrastructure, err = infProvider.Get(opts.InfrastructureName) app.platform.SetDevicePathResolver(app.infrastructure.GetDevicePathResolver()) if err != nil { err = bosherr.WrapError(err, "Getting infrastructure") return } settingsServiceProvider := boshsettings.NewServiceProvider() boot := boshboot.New(app.infrastructure, app.platform, dirProvider, settingsServiceProvider) settingsService, err := boot.Run() if err != nil { err = bosherr.WrapError(err, "Running bootstrap") return } mbusHandlerProvider := boshmbus.NewHandlerProvider(settingsService, app.logger) mbusHandler, err := mbusHandlerProvider.Get(app.platform, dirProvider) if err != nil { err = bosherr.WrapError(err, "Getting mbus handler") return } blobstoreProvider := boshblob.NewProvider(app.platform, dirProvider) blobstore, err := blobstoreProvider.Get(settingsService.GetBlobstore()) if err != nil { err = bosherr.WrapError(err, "Getting blobstore") return } monitClientProvider := boshmonit.NewProvider(app.platform, app.logger) monitClient, err := monitClientProvider.Get() if err != nil { err = bosherr.WrapError(err, "Getting monit client") return } jobSupervisorProvider := boshjobsuper.NewProvider(app.platform, monitClient, app.logger, dirProvider) jobSupervisor, err := jobSupervisorProvider.Get(opts.JobSupervisor) if err != nil { err = bosherr.WrapError(err, "Getting job supervisor") return } notifier := boshnotif.NewNotifier(mbusHandler) installPath := dirProvider.DataDir() jobsBc := bc.NewFileBundleCollection(installPath, dirProvider.BaseDir(), "jobs", app.platform.GetFs()) jobApplier := ja.NewRenderedJobApplier( jobsBc, blobstore, app.platform.GetCompressor(), jobSupervisor, ) packagesBc := bc.NewFileBundleCollection(installPath, dirProvider.BaseDir(), "packages", app.platform.GetFs()) packageApplier := pa.NewConcretePackageApplier( packagesBc, blobstore, app.platform.GetCompressor(), ) applier := boshapplier.NewConcreteApplier(jobApplier, packageApplier, app.platform, jobSupervisor, dirProvider) compiler := boshcomp.NewConcreteCompiler( app.platform.GetCompressor(), blobstore, app.platform.GetFs(), app.platform.GetRunner(), dirProvider, packageApplier, packagesBc, ) uuidGen := boshuuid.NewGenerator() taskService := boshtask.NewAsyncTaskService(uuidGen, app.logger) taskManager := boshtask.NewManagerProvider().NewManager( app.logger, app.platform.GetFs(), dirProvider.BoshDir(), ) specFilePath := filepath.Join(dirProvider.BoshDir(), "spec.json") specService := boshas.NewConcreteV1Service(app.platform.GetFs(), specFilePath) drainScriptProvider := boshdrain.NewConcreteDrainScriptProvider(app.platform.GetRunner(), app.platform.GetFs(), dirProvider) actionFactory := boshaction.NewFactory( settingsService, app.platform, app.infrastructure, blobstore, taskService, notifier, applier, compiler, jobSupervisor, specService, drainScriptProvider, app.logger, ) actionRunner := boshaction.NewRunner() actionDispatcher := boshagent.NewActionDispatcher(app.logger, taskService, taskManager, actionFactory, actionRunner) alertBuilder := boshalert.NewBuilder(settingsService, app.logger) app.agent = boshagent.New( app.logger, mbusHandler, app.platform, actionDispatcher, alertBuilder, jobSupervisor, specService, time.Minute, ) return }