예제 #1
0
파일: provider.go 프로젝트: Jane4PKU/bosh
func NewProvider(
	platform boshplatform.Platform,
	dirProvider boshdir.DirectoriesProvider,
) (p Provider) {
	p.uuidGen = boshuuid.NewGenerator()
	p.platform = platform
	p.dirProvider = dirProvider
	return
}
예제 #2
0
func basicDeps() (boshlog.Logger, boshsys.FileSystem, boshsys.CmdRunner, boshuuid.Generator) {
	logger := boshlog.NewWriterLogger(boshlog.LevelDebug, os.Stderr, os.Stderr)

	fs := boshsys.NewOsFileSystem(logger)

	runner := boshsys.NewExecCmdRunner(logger)

	uuidGen := boshuuid.NewGenerator()

	return logger, fs, runner, uuidGen
}
예제 #3
0
파일: provider.go 프로젝트: nicregez/bosh
func NewProvider(platform boshplatform.Platform) (p provider) {
	fs := platform.GetFs()
	runner := platform.GetRunner()
	uuidGen := boshuuid.NewGenerator()

	p.blobstores = map[boshsettings.BlobstoreType]Blobstore{
		boshsettings.BlobstoreTypeS3:    newS3Blobstore(fs, runner, uuidGen),
		boshsettings.BlobstoreTypeDummy: newDummyBlobstore(),
	}
	return
}
예제 #4
0
func NewProvider(platform boshplatform.Platform) (p provider) {
	fs := platform.GetFs()
	runner := platform.GetRunner()
	uuidGen := boshuuid.NewGenerator()
	s3cliConfigPath := filepath.Join(boshsettings.VCAP_ETC_DIR, "s3cli")

	p.blobstores = map[boshsettings.BlobstoreType]Blobstore{
		boshsettings.BlobstoreTypeDav:   newDummyBlobstore(),
		boshsettings.BlobstoreTypeDummy: newDummyBlobstore(),
		boshsettings.BlobstoreTypeS3:    newS3Blobstore(fs, runner, uuidGen, s3cliConfigPath),
	}
	return
}
func buildPkg(bc *fakebc.FakeBundleCollection) (models.Package, *fakebc.FakeBundle) {
	uuidGen := boshuuid.NewGenerator()
	uuid, err := uuidGen.Generate()
	Expect(err).ToNot(HaveOccurred())

	pkg := models.Package{
		Name:    "fake-package-name" + uuid,
		Version: "fake-package-name",
		Source: models.Source{
			Sha1:        "fake-blob-sha1",
			BlobstoreID: "fake-blobstore-id",
		},
	}

	bundle := bc.FakeGet(pkg)

	return pkg, bundle
}
예제 #6
0
func buildJob(bc *fakebc.FakeBundleCollection) (models.Job, *fakebc.FakeBundle) {
	uuidGen := boshuuid.NewGenerator()
	uuid, err := uuidGen.Generate()
	Expect(err).ToNot(HaveOccurred())

	job := models.Job{
		Name:    "fake-job-name" + uuid,
		Version: "fake-job-version",
		Source: models.Source{
			Sha1:          "fake-blob-sha1",
			BlobstoreID:   "fake-blobstore-id",
			PathInArchive: "fake-path-in-archive",
		},
	}

	bundle := bc.FakeGet(job)

	return job, bundle
}
예제 #7
0
func TestGetS3(t *testing.T) {
	platform, provider := buildProvider()
	options := map[string]string{
		"access_key_id":     "some-access-key",
		"secret_access_key": "some-secret-key",
		"bucket_name":       "some-bucket",
	}
	blobstore, err := provider.Get(boshsettings.Blobstore{
		Type:    boshsettings.BlobstoreTypeS3,
		Options: options,
	})
	assert.NoError(t, err)

	expectedBlobstore := newS3Blobstore(platform.GetFs(), platform.GetRunner(), boshuuid.NewGenerator())
	expectedBlobstore, err = expectedBlobstore.ApplyOptions(options)

	assert.NoError(t, err)
	assert.Equal(t, blobstore, expectedBlobstore)
}
예제 #8
0
func TestGetS3(t *testing.T) {
	platform, provider := buildProvider()
	options := map[string]string{
		"access_key_id":     "some-access-key",
		"secret_access_key": "some-secret-key",
		"bucket_name":       "some-bucket",
	}
	blobstore, err := provider.Get(boshsettings.Blobstore{
		Type:    boshsettings.BlobstoreTypeS3,
		Options: options,
	})
	assert.NoError(t, err)

	expectedS3ConfigPath := filepath.Join(boshsettings.VCAP_ETC_DIR, "s3cli")
	expectedBlobstore := newS3Blobstore(platform.GetFs(), platform.GetRunner(), boshuuid.NewGenerator(), expectedS3ConfigPath)
	expectedBlobstore = NewSha1Verifiable(expectedBlobstore)
	expectedBlobstore, err = expectedBlobstore.ApplyOptions(options)

	assert.NoError(t, err)
	assert.Equal(t, blobstore, expectedBlobstore)
}
예제 #9
0
파일: app.go 프로젝트: Jane4PKU/bosh
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
}
예제 #10
0
func TestGetExternalWhenExternalCommandInPath(t *testing.T) {
	platform, provider := buildProvider()
	options := map[string]string{
		"key": "value",
	}

	platform.Runner.CommandExistsValue = true
	blobstore, err := provider.Get(boshsettings.Blobstore{
		Type:    "fake-external-type",
		Options: options,
	})
	assert.NoError(t, err)

	expectedExternalConfigPath := "/var/vcap/bosh/etc/blobstore-fake-external-type.json"
	expectedBlobstore := NewExternalBlobstore("fake-external-type", options, platform.GetFs(), platform.GetRunner(), boshuuid.NewGenerator(), expectedExternalConfigPath)
	expectedBlobstore = NewSha1Verifiable(expectedBlobstore)
	err = expectedBlobstore.Validate()

	assert.NoError(t, err)
	assert.Equal(t, blobstore, expectedBlobstore)
}
예제 #11
0
파일: app.go 프로젝트: velankanisys/bosh
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
}
func buildPackage() models.Package {
	uuidGen := boshuuid.NewGenerator()
	uuid, err := uuidGen.Generate()
	Expect(err).ToNot(HaveOccurred())
	return models.Package{Name: "fake-package-name" + uuid, Version: "fake-package-name"}
}
func buildJob() models.Job {
	uuidGen := boshuuid.NewGenerator()
	uuid, err := uuidGen.Generate()
	Expect(err).ToNot(HaveOccurred())
	return models.Job{Name: "fake-job-name" + uuid, Version: "fake-version-name"}
}
예제 #14
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("get dummy", func() {
			_, provider := buildProvider()
			blobstore, err := provider.Get(boshsettings.Blobstore{
				Type: boshsettings.BlobstoreTypeDummy,
			})
			assert.NoError(GinkgoT(), err)
			assert.NotNil(GinkgoT(), blobstore)
		})
		It("get external when external command in path", func() {

			platform, provider := buildProvider()
			options := map[string]string{
				"key": "value",
			}

			platform.Runner.CommandExistsValue = true
			blobstore, err := provider.Get(boshsettings.Blobstore{
				Type:    "fake-external-type",
				Options: options,
			})
			assert.NoError(GinkgoT(), err)

			expectedExternalConfigPath := "/var/vcap/bosh/etc/blobstore-fake-external-type.json"
			expectedBlobstore := NewExternalBlobstore("fake-external-type", options, platform.GetFs(), platform.GetRunner(), boshuuid.NewGenerator(), expectedExternalConfigPath)
			expectedBlobstore = NewSha1Verifiable(expectedBlobstore)
			err = expectedBlobstore.Validate()

			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), blobstore, expectedBlobstore)
		})
		It("get external errs when external command not in path", func() {

			platform, provider := buildProvider()
			options := map[string]string{
				"key": "value",
			}

			platform.Runner.CommandExistsValue = false
			_, err := provider.Get(boshsettings.Blobstore{
				Type:    "fake-external-type",
				Options: options,
			})
			assert.Error(GinkgoT(), err)
		})
	})
}
예제 #15
0
		})

		It("get external when external command in path", func() {
			options := map[string]interface{}{
				"key": "value",
			}

			platform.Runner.CommandExistsValue = true
			blobstore, err := provider.Get(boshsettings.Blobstore{
				Type:    "fake-external-type",
				Options: options,
			})
			Expect(err).ToNot(HaveOccurred())

			expectedExternalConfigPath := "/var/vcap/bosh/etc/blobstore-fake-external-type.json"
			expectedBlobstore := NewExternalBlobstore("fake-external-type", options, platform.GetFs(), platform.GetRunner(), boshuuid.NewGenerator(), expectedExternalConfigPath)
			expectedBlobstore = NewSha1Verifiable(expectedBlobstore)
			err = expectedBlobstore.Validate()

			Expect(err).ToNot(HaveOccurred())
			Expect(blobstore).To(Equal(expectedBlobstore))
		})

		It("get external errs when external command not in path", func() {
			options := map[string]interface{}{
				"key": "value",
			}

			platform.Runner.CommandExistsValue = false
			_, err := provider.Get(boshsettings.Blobstore{
				Type:    "fake-external-type",
예제 #16
0
			options := map[string]interface{}{"key": "value"}

			platform.Runner.CommandExistsValue = true

			blobstore, err := provider.Get(boshsettings.Blobstore{
				Type:    "fake-external-type",
				Options: options,
			})
			Expect(err).ToNot(HaveOccurred())

			expectedBlobstore := NewExternalBlobstore(
				"fake-external-type",
				options,
				platform.GetFs(),
				platform.GetRunner(),
				boshuuid.NewGenerator(),
				"/var/vcap/bosh/etc/blobstore-fake-external-type.json",
			)
			expectedBlobstore = NewSHA1VerifiableBlobstore(expectedBlobstore)
			expectedBlobstore = NewRetryableBlobstore(expectedBlobstore, 3, logger)
			Expect(blobstore).To(Equal(expectedBlobstore))

			err = expectedBlobstore.Validate()
			Expect(err).ToNot(HaveOccurred())
		})

		It("get external errs when external command not in path", func() {
			options := map[string]interface{}{"key": "value"}

			platform.Runner.CommandExistsValue = false