func (h HTTPSHandler) putBlob(w http.ResponseWriter, r *http.Request) { _, blobID := path.Split(r.URL.Path) blobManager := blobstore.NewBlobManager(h.fs, h.dirProvider.MicroStore()) err := blobManager.Write(blobID, r.Body) if err != nil { w.WriteHeader(500) if _, wErr := w.Write([]byte(err.Error())); wErr != nil { h.logger.Error("https_handler", "Failed to write response body: %s", wErr.Error()) } return } w.WriteHeader(201) }
func (h HTTPSHandler) getBlob(w http.ResponseWriter, r *http.Request) { _, blobID := path.Split(r.URL.Path) blobManager := blobstore.NewBlobManager(h.fs, h.dirProvider.MicroStore()) file, err, statusCode := blobManager.Fetch(blobID) if err != nil { h.logger.Error("https_handler", "Failed to fetch blob: %s", err.Error()) w.WriteHeader(statusCode) } else { defer func() { _ = file.Close() }() reader := bufio.NewReader(file) if _, wErr := io.Copy(w, reader); wErr != nil { h.logger.Error("https_handler", "Failed to write response body: %s", wErr.Error()) } } }
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") } app.digestProvider = boshcrypto.NewDigestProvider(app.fs) app.dirProvider = boshdirs.NewProvider(opts.BaseDirectory) app.logStemcellInfo() statsCollector := boshsigar.NewSigarStatsCollector(&sigar.ConcreteSigar{}) state, err := boshplatform.NewBootstrapState(app.fs, filepath.Join(app.dirProvider.BoshDir(), "agent_state.json")) if err != nil { return bosherr.WrapError(err, "Loading state") } timeService := clock.NewClock() platformProvider := boshplatform.NewProvider(app.logger, app.dirProvider, statsCollector, app.fs, config.Platform, state, timeService) app.platform, err = platformProvider.Get(opts.PlatformName) if err != nil { return bosherr.WrapError(err, "Getting platform") } settingsSourceFactory := boshinf.NewSettingsSourceFactory(config.Infrastructure.Settings, app.platform, app.logger) settingsSource, err := settingsSourceFactory.New() if err != nil { return bosherr.WrapError(err, "Getting Settings Source") } settingsService := boshsettings.NewService( app.platform.GetFs(), filepath.Join(app.dirProvider.BoshDir(), "settings.json"), settingsSource, app.platform, app.logger, ) boot := boshagent.NewBootstrap( app.platform, app.dirProvider, settingsService, app.logger, ) if err = boot.Run(); err != nil { return bosherr.WrapError(err, "Running bootstrap") } mbusHandlerProvider := boshmbus.NewHandlerProvider(settingsService, app.logger) mbusHandler, err := mbusHandlerProvider.Get(app.platform, app.dirProvider) if err != nil { return bosherr.WrapError(err, "Getting mbus handler") } blobManager := boshblob.NewBlobManager(app.platform.GetFs(), app.dirProvider.BlobsDir()) blobstore, err := app.setupBlobstore(settingsService.GetSettings().Blobstore, blobManager) 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, app.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(app.dirProvider, blobstore, jobSupervisor) uuidGen := boshuuid.NewGenerator() taskService := boshtask.NewAsyncTaskService(uuidGen, app.logger) taskManager := boshtask.NewManagerProvider().NewManager( app.logger, app.platform.GetFs(), app.dirProvider.BoshDir(), ) specFilePath := filepath.Join(app.dirProvider.BoshDir(), "spec.json") specService := boshas.NewConcreteV1Service( app.platform.GetFs(), specFilePath, ) jobScriptProvider := boshscript.NewConcreteJobScriptProvider( app.platform.GetRunner(), app.platform.GetFs(), app.platform.GetDirProvider(), timeService, app.logger, ) actionFactory := boshaction.NewFactory( settingsService, app.platform, blobstore, blobManager, taskService, notifier, applier, compiler, jobSupervisor, specService, jobScriptProvider, app.logger, ) actionRunner := boshaction.NewRunner() actionDispatcher := boshagent.NewActionDispatcher( app.logger, taskService, taskManager, actionFactory, actionRunner, ) syslogServer := boshsyslog.NewServer(33331, net.Listen, app.logger) app.agent = boshagent.New( app.logger, mbusHandler, app.platform, actionDispatcher, jobSupervisor, specService, syslogServer, time.Second*30, settingsService, uuidGen, timeService, ) return nil }