Esempio n. 1
0
func Initialize(logger lager.Logger, config Configuration, clock clock.Clock) (executor.Client, grouper.Members, error) {
	gardenClient := GardenClient.New(GardenConnection.New(config.GardenNetwork, config.GardenAddr))
	err := waitForGarden(logger, gardenClient, clock)
	if err != nil {
		return nil, nil, err
	}

	containersFetcher := &executorContainers{
		gardenClient: gardenClient,
		owner:        config.ContainerOwnerName,
	}

	destroyContainers(gardenClient, containersFetcher, logger)

	workDir := setupWorkDir(logger, config.TempDir)

	transformer := initializeTransformer(
		logger,
		config.CachePath,
		workDir,
		config.MaxCacheSizeInBytes,
		uint(config.MaxConcurrentDownloads),
		maxConcurrentUploads,
		config.SkipCertVerify,
		config.ExportNetworkEnvVars,
		clock,
	)

	hub := event.NewHub()

	gardenStore, err := gardenstore.NewGardenStore(
		gardenClient,
		config.ContainerOwnerName,
		config.ContainerMaxCpuShares,
		config.ContainerInodeLimit,
		config.HealthyMonitoringInterval,
		config.UnhealthyMonitoringInterval,
		transformer,
		clock,
		hub,
		config.HealthCheckWorkPoolSize,
	)
	if err != nil {
		return nil, grouper.Members{}, err
	}

	allocationStore := allocationstore.NewAllocationStore(clock, hub)

	workPoolSettings := executor.WorkPoolSettings{
		CreateWorkPoolSize:  config.CreateWorkPoolSize,
		DeleteWorkPoolSize:  config.DeleteWorkPoolSize,
		ReadWorkPoolSize:    config.ReadWorkPoolSize,
		MetricsWorkPoolSize: config.MetricsWorkPoolSize,
	}

	depotClientProvider, err := depot.NewClientProvider(
		fetchCapacity(logger, gardenClient, config),
		allocationStore,
		gardenStore,
		hub,
		keyed_lock.NewLockManager(),
		workPoolSettings,
	)
	if err != nil {
		return nil, grouper.Members{}, err
	}

	metricsLogger := logger.Session("metrics-reporter")
	containerMetricsLogger := logger.Session("container-metrics-reporter")

	return depotClientProvider.WithLogger(logger),
		grouper.Members{
			{"metrics-reporter", &metrics.Reporter{
				ExecutorSource: depotClientProvider.WithLogger(metricsLogger),
				Interval:       metricsReportInterval,
				Logger:         metricsLogger,
			}},
			{"hub-closer", closeHub(hub)},
			{"registry-pruner", allocationStore.RegistryPruner(logger, config.RegistryPruningInterval)},
			{"container-metrics-reporter", containermetrics.NewStatsReporter(
				containerMetricsLogger,
				containerMetricsReportInterval,
				clock,
				depotClientProvider.WithLogger(containerMetricsLogger),
			)},
		},
		nil
}
Esempio n. 2
0
		resources = executor.ExecutorResources{
			MemoryMB:   1024,
			DiskMB:     1024,
			Containers: 3,
		}

		lockManager = &fakelockmanager.FakeLockManager{}
		workPoolSettings := executor.WorkPoolSettings{
			CreateWorkPoolSize:  5,
			DeleteWorkPoolSize:  5,
			ReadWorkPoolSize:    5,
			MetricsWorkPoolSize: 5,
		}

		d, err := depot.NewClientProvider(resources, allocationStore, gardenStore, eventHub, lockManager, workPoolSettings)
		Expect(err).NotTo(HaveOccurred())

		depotClient = d.WithLogger(logger)
	})

	Describe("AllocateContainers", func() {
		Context("when allocating a single valid container within executor resource limits", func() {
			var requests []executor.AllocationRequest
			BeforeEach(func() {
				requests = []executor.AllocationRequest{
					newAllocationRequest("guid-1", 512, 512),
				}
			})

			It("should allocate the container", func() {