Beispiel #1
0
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)
		}
	}
}
Beispiel #2
0
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
}