Пример #1
0
func Assemble() ([]io.Closer, error) {
	requester := buildReceiver()
	closeables, err := assemble.BuildPipelines(DataStore, requester, func(response data.ParsedResponse) {
		//Do nothing. This is the last step and we do not need to do anything here,
		// just pull the chan clean
	})
	closeables = append(closeables, requester)
	if err != nil {
		return closeables, err
	}
	graphGenerator := &meshviewer.GraphGenerator{Store: DataStore}
	nodesGenerator := meshviewer.NewNodesJsonGenerator(DataStore)
	missingUpdate := &MissingUpdater{Store: DataStore, Requester: requester}
	DataStore.NotifyNodeOffline(missingUpdate.CheckNodeUnicast)
	nodesGenerator.UpdateNodesJson()
	graphGenerator.UpdateGraphJson()

	log.Printf("Setting up request timer")
	nodeinfoInterval := conf.Global.UInt("announced.interval.nodeinfo", 1800)
	statisticsInterval := conf.Global.UInt("announced.interval.statistics", 300)

	scheduler.NewJob(time.Second*time.Duration(nodeinfoInterval), func() {
		log.Debug("Querying Nodeinfos via Multicast")
		requester.Query("GET nodeinfo")
	}, true)
	time.Sleep(time.Second * 10)
	scheduler.NewJob(time.Second*time.Duration(statisticsInterval), func() {
		log.Debug("Querying statistics via Multicast")
		requester.Query("GET statistics")
		time.Sleep(time.Second * 25)
		log.Debug("Querying neighbours via Multicast")
		requester.Query("GET neighbours")
	}, true)

	scheduler.NewJob(time.Minute*1, func() {
		graphGenerator.UpdateGraphJson()
	}, false)

	scheduler.NewJob(time.Minute*1, func() {
		nodesGenerator.UpdateNodesJson()
	}, false)
	httpApi := &api.HttpApi{Store: DataStore}
	httpserver.StartHttpServerBlocking(httpApi, graphGenerator, nodesGenerator)
	return closeables, nil
}
Пример #2
0
func ExecuteCompletePipe(t *testing.T, store data.Nodeinfostore) {
	prometheus.Init()
	assert := assert.New(t)
	testReceiver := &TestDataReceiver{TestData: TestData}

	i := 0
	closeables, err := assemble.BuildPipelines(store, testReceiver, func(response data.ParsedResponse) {
		i = i + 1
	})
	assert.Nil(err)

	for i < len(TestData) {
		time.Sleep(time.Millisecond * 1)
	}

	for _, closable := range closeables {
		closable.Close()
	}

	assert.Equal(len(TestData), i)
}