func TagPath(from_node, tag_name string) (map[string]*big.Int, tree_lib.TreeError) { var ( err tree_lib.TreeError path = make(map[string]*big.Int) nodes_by_tagname []string ) err.From = tree_lib.FROM_TAG_PATH nodes_by_tagname, err = tree_db.GetNodesByTagName(tag_name) if !err.IsNull() { return nil, err } for _, n := range nodes_by_tagname { if check_node[n] { targets = append(targets, n) path[n], err = NodePath(from_node, n) if !err.IsNull() { return nil, err } } else { fmt.Println("there is no server with name ", n) fmt.Println("ignoring server ", n) } } return path, err }
func HandleListCommand(ev *tree_event.Event, cmd Command) { var ( info = make(map[string]node_info.NodeInfo) data []byte ev_data Command nodes []string nodes_in_group []string nodes_in_tag []string err tree_lib.TreeError infos Info ) err.From = tree_lib.FROM_HANDLE_LIST_COMMAND err.Err = ffjson.Unmarshal(ev.Data, &ev_data) if !err.IsNull() { tree_log.Error(err.From, err.Error()) return } err.Err = ffjson.Unmarshal(ev_data.Data, &infos) if !err.IsNull() { tree_log.Error(err.From, err.Error()) return } nodes = infos.Target for _, g := range infos.Group { nodes_in_group, err = tree_db.GetGroupNodes(g) if !err.IsNull() { tree_log.Error(err.From, err.Error()) return } for _, n := range nodes_in_group { nodes = append(nodes, n) } } for _, t := range infos.Tag { nodes_in_tag, err = tree_db.GetNodesByTagName(t) if !err.IsNull() { tree_log.Error(err.From, "getting Tags", err.Error()) return } for _, n := range nodes_in_tag { nodes = append(nodes, n) } } for _, n := range nodes { info[n], err = tree_db.GetNodeInfo(n) if !err.IsNull() { tree_log.Error(err.From, err.Error()) return } } cb_cmd := cmd cb_cmd.Data, err.Err = ffjson.Marshal(info) if !err.IsNull() { tree_log.Error(err.From, err.Error()) return } data, err.Err = ffjson.Marshal(cb_cmd) if !err.IsNull() { tree_log.Error(err.From, err.Error()) return } SendCommandCallback(ev, data) }