コード例 #1
0
ファイル: main.go プロジェクト: tantive/node-informant
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
ファイル: boltstore.go プロジェクト: tantive/node-informant
// NewBoltStore creates a new BoltStore where the database file is located at
// the given path. If the file does not exist it will be created. If there is
// already a bolt database at the given path this BoltStore will contain its data.
func NewBoltStore(path string) (*BoltStore, error) {
	db, err := bolt.Open(path, 0600, nil)
	if err != nil {
		return nil, err
	}
	store := &BoltStore{db: db}
	err = db.Update(func(tx *bolt.Tx) error {
		for _, bucketName := range AllBucketNames {
			_, err := tx.CreateBucketIfNotExists([]byte(bucketName))
			if err != nil {
				return err
			}
		}
		return nil
	})
	if err != nil {
		return nil, err
	}
	store.gwOfflineHandler = make([]func(string), 0, 10)
	store.expiredNodesHandler = make([]func(string), 0, 10)
	store.onlineStatusJob = scheduler.NewJob(time.Minute*1, store.calculateOnlineStatus, false)
	store.expireNodesJob = scheduler.NewJob(time.Hour*24, store.expireUnreachableNodes, false)
	return store, nil
}