示例#1
0
文件: config.go 项目: grosser/zeus
func iteratePlan(tree *processtree.ProcessTree, plan map[string]interface{}, parent *processtree.SlaveNode) {
	for name, v := range plan {
		if subPlan, ok := v.(map[string]interface{}); ok {
			newNode := tree.NewSlaveNode(name, parent)
			if parent == nil {
				tree.Root = newNode
			} else {
				parent.Slaves = append(parent.Slaves, newNode)
			}
			iteratePlan(tree, subPlan, newNode)
		} else {
			var newNode *processtree.CommandNode
			if aliases, ok := v.([]interface{}); ok {
				strs := make([]string, len(aliases))
				for i, alias := range aliases {
					strs[i] = alias.(string)
				}
				newNode = tree.NewCommandNode(name, strs, parent)
			} else if v == nil {
				newNode = tree.NewCommandNode(name, nil, parent)
			} else {
				zerror.ErrorConfigFileInvalidFormat()
			}
			parent.Commands = append(parent.Commands, newNode)
		}
	}
}
示例#2
0
文件: config.go 项目: grosser/zeus
func BuildProcessTree() *processtree.ProcessTree {
	conf := parseConfig()
	tree := &processtree.ProcessTree{}
	tree.SlavesByName = make(map[string]*processtree.SlaveNode)
	tree.StateChanged = make(chan bool, 16)

	tree.ExecCommand = conf.Command

	plan, ok := conf.Plan.(map[string]interface{})
	if !ok {
		zerror.ErrorConfigFileInvalidFormat()
	}
	iteratePlan(tree, plan, nil)

	return tree
}