コード例 #1
0
ファイル: bulk_app_state_test.go プロジェクト: cgrotz/hm9000
func makeHandlerAndStore(conf HandlerConf) (http.Handler, store.Store, error) {
	config, _ := config.DefaultConfig()

	store := store.NewStore(config, conf.StoreAdapter, fakelogger.NewFakeLogger())

	handler, err := handlers.New(conf.Logger, store, conf.TimeProvider)
	return handler, store, err
}
コード例 #2
0
func connectToStore(l logger.Logger, conf *config.Config) (store.Store, metricsaccountant.UsageTracker) {
	if conf.StoreType == "etcd" || conf.StoreType == "ZooKeeper" {
		adapter, workerPool := connectToStoreAdapter(l, conf)
		return store.NewStore(conf, adapter, l), workerPool
	} else {
		l.Error(fmt.Sprintf("Unknown store type %s.  Choose one of 'etcd' or 'ZooKeeper'", conf.StoreType), fmt.Errorf("Unkown store type"))
		os.Exit(1)
	}

	return nil, nil
}
コード例 #3
0
func (coordinator *MCATCoordinator) PrepForNextTest() (*CLIRunner, *Simulator, *startstoplistener.StartStopListener) {
	coordinator.StoreRunner.Reset()
	coordinator.startStopListener.Reset()
	coordinator.StateServer.Reset()

	if coordinator.currentCLIRunner != nil {
		coordinator.currentCLIRunner.Cleanup()
	}
	coordinator.currentCLIRunner = NewCLIRunner(coordinator.StoreRunner.NodeURLS(), coordinator.DesiredStateServerBaseUrl, coordinator.NatsPort, coordinator.MetricsServerPort, coordinator.Verbose)
	store := storepackage.NewStore(coordinator.Conf, coordinator.StoreAdapter, fakelogger.NewFakeLogger())
	simulator := NewSimulator(coordinator.Conf, coordinator.StoreRunner, store, coordinator.StateServer, coordinator.currentCLIRunner, coordinator.MessageBus)

	return coordinator.currentCLIRunner, simulator, coordinator.startStopListener
}
コード例 #4
0
func main() {
	cmdsToStop = []*exec.Cmd{}

	registerSignalHandler()
	nats = natsrunner.NewNATSRunner(4222)
	nats.Start()

	fakeCC := desiredstateserver.NewDesiredStateServer()
	go fakeCC.SpinUp(6001)

	// etcd = storerunner.NewETCDClusterRunner(4001, 1)
	// etcd.Start()
	conf, _ := config.FromFile("./config.json")
	adapter := storeadapter.NewETCDStoreAdapter(conf.StoreURLs, workerpool.NewWorkerPool(30))
	adapter.Connect()
	store = storepackage.NewStore(conf, adapter, fakelogger.NewFakeLogger())

	r := rand.New(rand.NewSource(time.Now().Unix()))
	num, err := strconv.Atoi(os.Args[1])
	if err != nil {
		panic(err)
	}

	sim := simulator.New(num, 10, r, nats.MessageBus, fakeCC)
	//start all the HM components (make them pipe to stdout)
	start("listen", false)
	start("fetch_desired", true)
	start("analyze", true)
	start("send", true)
	start("serve_metrics", false)
	start("serve_api", false)
	time.Sleep(time.Second)
	go Tick(sim)
	go Fetch()
	select {}
}
コード例 #5
0
func connectToStore(l logger.Logger, conf *config.Config) (store.Store, metricsaccountant.UsageTracker) {
	adapter, workerPool := connectToStoreAdapter(l, conf)
	return store.NewStore(conf, adapter, l), workerPool
}
コード例 #6
0
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"time"
)

var _ = Describe("Metrics Accountant", func() {
	var store storepackage.Store
	var accountant MetricsAccountant
	var fakeStoreAdapter *fakestoreadapter.FakeStoreAdapter

	conf, _ := config.DefaultConfig()

	BeforeEach(func() {
		fakeStoreAdapter = fakestoreadapter.New()
		store = storepackage.NewStore(conf, fakeStoreAdapter, fakelogger.NewFakeLogger())
		accountant = New(store)
	})

	Describe("Getting Metrics", func() {
		Context("when the store is empty", func() {
			It("should return a map of 0s", func() {
				metrics, err := accountant.GetMetrics()
				Ω(err).ShouldNot(HaveOccurred())
				Ω(metrics).Should(Equal(map[string]float64{
					"StartCrashed":                            0,
					"StartMissing":                            0,
					"StartEvacuating":                         0,
					"StopExtra":                               0,
					"StopDuplicate":                           0,
					"StopEvacuationComplete":                  0,
コード例 #7
0
ファイル: common.go プロジェクト: nagyistge/hm9000
func connectToStoreAndTrack(l logger.Logger, conf *config.Config) (store.Store, metricsaccountant.UsageTracker) {
	tracker := newUsageTracker(conf.StoreMaxConcurrentRequests)
	adapter := connectToStoreAdapter(l, conf)
	return store.NewStore(conf, adapter, l), tracker
}
コード例 #8
0
ファイル: common.go プロジェクト: nagyistge/hm9000
func connectToStore(l logger.Logger, conf *config.Config) store.Store {
	adapter := connectToStoreAdapter(l, conf)
	return store.NewStore(conf, adapter, l)
}
コード例 #9
0
		resultChan chan desiredstatefetcher.DesiredStateFetcherResult
	)

	BeforeEach(func() {
		resultChan = make(chan desiredstatefetcher.DesiredStateFetcherResult, 1)
		a1 = app.NewApp()
		a2 = app.NewApp()
		a3 = app.NewApp()

		stateServer.SetDesiredState([]models.DesiredAppState{
			a1.DesiredState(0),
			a2.DesiredState(0),
			a3.DesiredState(0),
		})

		fetcher = desiredstatefetcher.New(conf, natsRunner.MessageBus, store.NewStore(conf, storeAdapter), httpclient.NewHttpClient(), &timeprovider.RealTimeProvider{})
		fetcher.Fetch(resultChan)
	})

	It("requests for the first set of data from the CC and stores the response", func() {
		var node storeadapter.StoreNode
		var err error
		Eventually(func() error {
			node, err = storeAdapter.Get("/desired/" + a1.AppGuid + "-" + a1.AppVersion)
			return err
		}, 1, 0.1).ShouldNot(HaveOccured())

		Ω(node.TTL).Should(BeNumerically("<=", 10*60))
		Ω(node.TTL).Should(BeNumerically(">=", 10*60-1))

		Ω(node.Value).Should(Equal(a1.DesiredState(0).ToJson()))