Example #1
0
func NewProvider(
	platform boshplatform.Platform,
	client boshmonit.Client,
	logger boshlog.Logger,
	dirProvider boshdir.DirectoriesProvider,
	handler boshhandler.Handler,
) (p provider) {
	monitJobSupervisor := NewMonitJobSupervisor(
		platform.GetFs(),
		platform.GetRunner(),
		client,
		logger,
		dirProvider,
		2825,
		MonitReloadOptions{
			MaxTries:               3,
			MaxCheckTries:          6,
			DelayBetweenCheckTries: 5 * time.Second,
		},
	)

	p.supervisors = map[string]JobSupervisor{
		"monit":      monitJobSupervisor,
		"dummy":      newDummyJobSupervisor(),
		"dummy-nats": NewDummyNatsJobSupervisor(handler),
	}

	return
}
Example #2
0
func NewFactory(
	settings boshsettings.Service,
	platform boshplatform.Platform,
	blobstore boshblob.Blobstore,
	taskService boshtask.Service,
	applier boshappl.Applier,
) (factory Factory) {

	fs := platform.GetFs()
	compressor := platform.GetCompressor()

	factory = concreteFactory{
		availableActions: map[string]Action{
			"apply":        newApply(applier, fs, platform),
			"drain":        newDrain(),
			"fetch_logs":   newLogs(compressor, blobstore),
			"get_task":     newGetTask(taskService),
			"get_state":    newGetState(settings, fs),
			"list_disk":    newListDisk(settings, platform),
			"migrate_disk": newMigrateDisk(settings, platform),
			"mount_disk":   newMountDisk(settings, platform),
			"ping":         newPing(),
			"ssh":          newSsh(settings, platform),
			"start":        newStart(),
			"stop":         newStop(),
			"unmount_disk": newUnmountDisk(settings, platform),
		},
	}
	return
}
Example #3
0
func (p Provider) createAwsInfrastructure(metadataHost string, resolver dnsResolver,
	platform boshplatform.Platform) (inf Infrastructure) {

	devicePathResolver := boshdpresolv.NewAwsDevicePathResolver(500*time.Millisecond, platform.GetFs())
	inf = NewAwsInfrastructure(metadataHost, resolver, platform, devicePathResolver)
	return
}
Example #4
0
func New(inf boshinf.Infrastructure, platform boshplatform.Platform, dirProvider boshdir.DirectoriesProvider) (b bootstrap) {
	b.infrastructure = inf
	b.platform = platform
	b.dirProvider = dirProvider
	b.fs = platform.GetFs()
	return
}
Example #5
0
func (p MbusHandlerProvider) Get(
	platform boshplatform.Platform,
	dirProvider boshdir.DirectoriesProvider,
) (handler boshhandler.Handler, err error) {
	if p.handler != nil {
		handler = p.handler
		return
	}

	mbusURL, err := url.Parse(p.settings.GetMbusURL())
	if err != nil {
		err = bosherr.WrapError(err, "Parsing handler URL")
		return
	}

	switch mbusURL.Scheme {
	case "nats":
		handler = NewNatsHandler(p.settings, p.logger, yagnats.NewClient())
	case "https":
		handler = micro.NewHTTPSHandler(mbusURL, p.logger, platform.GetFs(), dirProvider)
	default:
		err = bosherr.New("Message Bus Handler with scheme %s could not be found", mbusURL.Scheme)
	}

	p.handler = handler

	return
}
Example #6
0
func NewProvider(logger boshlog.Logger, platform boshplatform.Platform) (p Provider) {
	digDnsResolver := NewDigDnsResolver(logger)

	p.infrastructures = map[string]Infrastructure{
		"aws":     p.createAwsInfrastructure("http://169.254.169.254", digDnsResolver, platform),
		"dummy":   p.createDummyInfrastructure(platform.GetFs(), platform.GetDirProvider(), platform),
		"vsphere": p.createVsphereInfrastructure(platform, logger),
	}
	return
}
Example #7
0
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
}
Example #8
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
}
Example #9
0
func New(
	inf boshinf.Infrastructure,
	platform boshplatform.Platform,
	dirProvider boshdir.DirectoriesProvider,
	settingsServiceProvider boshsettings.ServiceProvider,
) (b bootstrap) {
	b.fs = platform.GetFs()
	b.infrastructure = inf
	b.platform = platform
	b.dirProvider = dirProvider
	b.settingsServiceProvider = settingsServiceProvider
	return
}
Example #10
0
func getDiskStats(platform boshplatform.Platform, devicePath string) (stats boshmbus.DiskStats) {
	diskStats, err := platform.GetDiskStats(devicePath)
	if err != nil {
		return
	}

	percent := float64(diskStats.Used) / float64(diskStats.Total) * 100
	inodePercent := float64(diskStats.InodeUsed) / float64(diskStats.InodeTotal) * 100

	stats.Percent = fmt.Sprintf("%.0f", percent)
	stats.InodePercent = fmt.Sprintf("%.0f", inodePercent)

	return
}
Example #11
0
func NewProvider(
	platform boshplatform.Platform,
	client boshmonit.Client,
	logger boshlog.Logger,
	dirProvider boshdir.DirectoriesProvider,
) (p provider) {

	p.supervisors = map[string]JobSupervisor{
		"monit": NewMonitJobSupervisor(platform.GetFs(), platform.GetRunner(), client, logger, dirProvider),
		"dummy": newDummyJobSupervisor(),
	}

	return
}
Example #12
0
func NewProvider(
	platform boshplatform.Platform,
	client boshmonit.Client,
	logger boshlog.Logger,
	dirProvider boshdir.DirectoriesProvider,
	handler boshhandler.Handler,
) (p provider) {
	p.supervisors = map[string]JobSupervisor{
		"monit":      NewMonitJobSupervisor(platform.GetFs(), platform.GetRunner(), client, logger, dirProvider, 2825, 5*time.Second),
		"dummy":      newDummyJobSupervisor(),
		"dummy-nats": NewDummyNatsJobSupervisor(handler),
	}

	return
}
Example #13
0
func updateWithSwapStats(platform boshplatform.Platform, hb boshmbus.Heartbeat) (updatedHb boshmbus.Heartbeat) {
	updatedHb = hb
	swapStats, err := platform.GetSwapStats()
	if err != nil {
		return
	}

	percent := float64(swapStats.Used) / float64(swapStats.Total) * 100
	kb := swapStats.Used / 1024

	updatedHb.Vitals.UsedSwap = boshmbus.MemStats{
		Percent: fmt.Sprintf("%.0f", percent),
		Kb:      fmt.Sprintf("%d", kb),
	}
	return
}
Example #14
0
func updateWithCpuLoad(platform boshplatform.Platform, hb boshmbus.Heartbeat) (updatedHb boshmbus.Heartbeat) {
	updatedHb = hb

	load, err := platform.GetCpuLoad()
	if err != nil {
		return
	}

	one := fmt.Sprintf("%.2f", load.One)
	five := fmt.Sprintf("%.2f", load.Five)
	fifteen := fmt.Sprintf("%.2f", load.Fifteen)

	updatedHb.Vitals.CpuLoad = []string{one, five, fifteen}

	return
}
Example #15
0
func updateWithCpuStats(platform boshplatform.Platform, hb boshmbus.Heartbeat) (updatedHb boshmbus.Heartbeat) {
	updatedHb = hb
	cpuStats, err := platform.GetCpuStats()
	if err != nil {
		return
	}

	user := float64(cpuStats.User) / float64(cpuStats.Total) * 100
	sys := float64(cpuStats.Sys) / float64(cpuStats.Total) * 100
	wait := float64(cpuStats.Wait) / float64(cpuStats.Total) * 100

	updatedHb.Vitals.Cpu = boshmbus.CpuStats{
		User: fmt.Sprintf("%.1f", user),
		Sys:  fmt.Sprintf("%.1f", sys),
		Wait: fmt.Sprintf("%.1f", wait),
	}
	return
}
Example #16
0
func NewProvider(logger boshlog.Logger, platform boshplatform.Platform) (p Provider) {
	metadataService := NewConcreteMetadataService(
		"http://169.254.169.254",
		NewDigDNSResolver(logger),
	)

	// Currently useServerNameAsID boolean setting is hard coded below
	// because we do not support arbitrary infrastructure configurations
	awsRegistry := NewConcreteRegistry(metadataService, false)
	openstackRegistry := NewConcreteRegistry(metadataService, true)

	fs := platform.GetFs()
	dirProvider := platform.GetDirProvider()

	mappedDevicePathResolver := boshdpresolv.NewMappedDevicePathResolver(500*time.Millisecond, fs)
	vsphereDevicePathResolver := boshdpresolv.NewVsphereDevicePathResolver(500*time.Millisecond, fs)
	dummyDevicePathResolver := boshdpresolv.NewDummyDevicePathResolver()

	awsInfrastructure := NewAwsInfrastructure(
		metadataService,
		awsRegistry,
		platform,
		mappedDevicePathResolver,
		logger,
	)

	openstackInfrastructure := NewOpenstackInfrastructure(
		metadataService,
		openstackRegistry,
		platform,
		mappedDevicePathResolver,
		logger,
	)

	p.infrastructures = map[string]Infrastructure{
		"aws":       awsInfrastructure,
		"openstack": openstackInfrastructure,
		"dummy":     NewDummyInfrastructure(fs, dirProvider, platform, dummyDevicePathResolver),
		"warden":    NewWardenInfrastructure(dirProvider, platform, dummyDevicePathResolver),
		"vsphere":   NewVsphereInfrastructure(platform, vsphereDevicePathResolver, logger),
	}
	return
}
Example #17
0
func NewFactory(
	settings boshsettings.Service,
	platform boshplatform.Platform,
	blobstore boshblob.Blobstore,
	taskService boshtask.Service,
	notifier boshnotif.Notifier,
	applier boshappl.Applier,
	compiler boshcomp.Compiler,
	jobSupervisor boshjobsuper.JobSupervisor,
	specService boshas.V1Service,
	drainScriptProvider boshdrain.DrainScriptProvider,
) (factory Factory) {
	compressor := platform.GetCompressor()
	copier := platform.GetCopier()
	dirProvider := platform.GetDirProvider()
	vitalsService := platform.GetVitalsService()
	ntpService := boshntp.NewConcreteService(platform.GetFs(), dirProvider)

	factory = concreteFactory{
		availableActions: map[string]Action{
			"apply":        NewApply(applier, specService),
			"drain":        NewDrain(notifier, specService, drainScriptProvider),
			"fetch_logs":   NewLogs(compressor, copier, blobstore, dirProvider),
			"get_task":     NewGetTask(taskService),
			"get_state":    NewGetState(settings, specService, jobSupervisor, vitalsService, ntpService),
			"list_disk":    NewListDisk(settings, platform),
			"migrate_disk": NewMigrateDisk(platform, dirProvider),
			"mount_disk":   NewMountDisk(settings, platform, dirProvider),
			"ping":         NewPing(),
			"prepare_network_change": NewPrepareNetworkChange(platform),
			"ssh":                NewSsh(settings, platform, dirProvider),
			"start":              NewStart(jobSupervisor),
			"stop":               NewStop(jobSupervisor),
			"unmount_disk":       NewUnmountDisk(settings, platform),
			"compile_package":    NewCompilePackage(compiler),
			"release_apply_spec": NewReleaseApplySpec(platform),
		},
	}
	return
}
Example #18
0
func NewFactory(
	settings boshsettings.Service,
	platform boshplatform.Platform,
	blobstore boshblob.Blobstore,
	taskService boshtask.Service,
	notifier boshnotif.Notifier,
	applier boshappl.Applier,
	compiler boshcomp.Compiler,
	monitor boshmon.Monitor,
	specService boshas.V1Service,
	dirProvider boshdirs.DirectoriesProvider,
	drainScriptProvider boshdrain.DrainScriptProvider,
) (factory Factory) {
	compressor := platform.GetCompressor()

	factory = concreteFactory{
		availableActions: map[string]Action{
			"apply":        newApply(applier, specService),
			"drain":        newDrain(notifier, specService, drainScriptProvider),
			"fetch_logs":   newLogs(compressor, blobstore, dirProvider),
			"get_task":     newGetTask(taskService),
			"get_state":    newGetState(settings, specService, monitor),
			"list_disk":    newListDisk(settings, platform),
			"migrate_disk": newMigrateDisk(settings, platform, dirProvider),
			"mount_disk":   newMountDisk(settings, platform, dirProvider),
			"ping":         newPing(),
			"prepare_network_change": newPrepareNetworkChange(),
			"ssh":             newSsh(settings, platform, dirProvider),
			"start":           newStart(monitor),
			"stop":            newStop(monitor),
			"unmount_disk":    newUnmountDisk(settings, platform),
			"compile_package": newCompilePackage(compiler),
		},
	}
	return
}
Example #19
0
func NewPrepareNetworkChange(platform boshplatform.Platform) (prepareAction PrepareNetworkChangeAction) {
	prepareAction.fs = platform.GetFs()
	prepareAction.waitToKillAgentInterval = 1 * time.Second
	return
}
func NewFactory(
	settingsService boshsettings.Service,
	platform boshplatform.Platform,
	blobstore boshblob.Blobstore,
	taskService boshtask.Service,
	notifier boshnotif.Notifier,
	applier boshappl.Applier,
	compiler boshcomp.Compiler,
	jobSupervisor boshjobsuper.JobSupervisor,
	specService boshas.V1Service,
	drainScriptProvider boshdrain.DrainScriptProvider,
	logger boshlog.Logger,
) (factory Factory) {
	compressor := platform.GetCompressor()
	copier := platform.GetCopier()
	dirProvider := platform.GetDirProvider()
	vitalsService := platform.GetVitalsService()
	ntpService := boshntp.NewConcreteService(platform.GetFs(), dirProvider)

	factory = concreteFactory{
		availableActions: map[string]Action{
			// Task management
			"ping":        NewPing(),
			"get_task":    NewGetTask(taskService),
			"cancel_task": NewCancelTask(taskService),

			// VM admin
			"ssh":        NewSSH(settingsService, platform, dirProvider),
			"fetch_logs": NewFetchLogs(compressor, copier, blobstore, dirProvider),

			// Job management
			"prepare":    NewPrepare(applier),
			"apply":      NewApply(applier, specService, settingsService),
			"start":      NewStart(jobSupervisor),
			"stop":       NewStop(jobSupervisor),
			"drain":      NewDrain(notifier, specService, drainScriptProvider, jobSupervisor),
			"get_state":  NewGetState(settingsService, specService, jobSupervisor, vitalsService, ntpService),
			"run_errand": NewRunErrand(specService, dirProvider.JobsDir(), platform.GetRunner(), logger),

			// Compilation
			"compile_package":    NewCompilePackage(compiler),
			"release_apply_spec": NewReleaseApplySpec(platform),

			// Disk management
			"list_disk":    NewListDisk(settingsService, platform, logger),
			"migrate_disk": NewMigrateDisk(platform, dirProvider),
			"mount_disk":   NewMountDisk(settingsService, platform, platform, dirProvider),
			"unmount_disk": NewUnmountDisk(settingsService, platform),

			// Networking
			"prepare_network_change":     NewPrepareNetworkChange(platform.GetFs(), settingsService),
			"prepare_configure_networks": NewPrepareConfigureNetworks(platform, settingsService),
			"configure_networks":         NewConfigureNetworks(),
		},
	}
	return
}
Example #21
0
func New(inf boshinf.Infrastructure, platform boshplatform.Platform) (b bootstrap) {
	b.infrastructure = inf
	b.platform = platform
	b.fs = platform.GetFs()
	return
}
Example #22
0
func (p Provider) createVsphereInfrastructure(platform boshplatform.Platform, logger boshlog.Logger) (inf Infrastructure) {
	devicePathResolver := boshdevicepathresolver.NewVsphereDevicePathResolver(500*time.Millisecond, platform.GetFs())
	inf = NewVsphereInfrastructure(platform, devicePathResolver, logger)
	return
}
Example #23
0
func (p Provider) createDummyInfrastructure(fs boshsys.FileSystem, dirProvider boshdir.DirectoriesProvider,
	platform boshplatform.Platform) (inf Infrastructure) {
	devicePathResolver := boshdevicepathresolver.NewDummyDevicePathResolver(1*time.Millisecond, platform.GetFs())
	inf = NewDummyInfrastructure(fs, dirProvider, platform, devicePathResolver)
	return
}