示例#1
0
文件: analyzer.go 项目: Zhann/hm9000
func (analyzer *Analyzer) populateActualState() error {
	nodes, err := analyzer.fetchNodesUnderDir("/actual")
	if err != nil {
		return err
	}

	analyzer.runningByApp = make(map[string]int, 0)

	analyzer.actualStates = make([]models.InstanceHeartbeat, len(nodes))
	for i, node := range nodes {
		analyzer.actualStates[i], err = models.NewInstanceHeartbeatFromJSON(node.Value)
		if err != nil {
			return err
		}
		key := analyzer.actualStates[i].AppGuid + "-" + analyzer.actualStates[i].AppVersion
		value, ok := analyzer.runningByApp[key]
		if ok {
			analyzer.runningByApp[key] = value + 1
		} else {
			analyzer.runningByApp[key] = 1
		}
	}

	return nil
}
示例#2
0
文件: store.go 项目: Zhann/hm9000
func (store *RealStore) GetActualState() ([]models.InstanceHeartbeat, error) {
	nodes, err := store.fetchNodesUnderDir("/actual")
	if err != nil {
		return []models.InstanceHeartbeat{}, err
	}

	instanceHeartbeats := make([]models.InstanceHeartbeat, len(nodes))
	for i, node := range nodes {
		instanceHeartbeats[i], err = models.NewInstanceHeartbeatFromJSON(node.Value)
		if err != nil {
			return []models.InstanceHeartbeat{}, err
		}
	}

	return instanceHeartbeats, nil
}