当前位置: 首页>>代码示例>>Golang>>正文


Golang tree_lib.TreeError类代码示例

本文整理汇总了Golang中tree_lib.TreeError的典型用法代码示例。如果您正苦于以下问题:Golang TreeError类的具体用法?Golang TreeError怎么用?Golang TreeError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TreeError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: SendToConn

func SendToConn(data []byte, conn *net.TCPConn, path *big.Int) {
	// making variable for combining send data
	var (
		err           tree_lib.TreeError
		path_len_data = make([]byte, 4)
		msg_len_data  = make([]byte, 4)
		path_data     = path.Bytes()
		path_len      = uint32(len(path_data))
		buf           = bytes.Buffer{}
	)

	err.From = tree_lib.FROM_SEND_TO_CONN

	binary.LittleEndian.PutUint32(path_len_data, path_len)
	binary.LittleEndian.PutUint32(msg_len_data, path_len+uint32(len(data))+uint32(4))

	buf.Write(msg_len_data)
	buf.Write(path_len_data)
	buf.Write(path_data)
	buf.Write(data)

	if conn != nil {
		_, err.Err = conn.Write(buf.Bytes())
		if !err.IsNull() {
			tree_log.Error(err.From, fmt.Sprintf("Error sending data to path [%s]", path.String()), err.Error())
		}
	}

	buf.Reset()
}
开发者ID:treescale,项目名称:treescale,代码行数:30,代码来源:network.go

示例2: API_INIT

// Init API node for connection to targets
func API_INIT(targets ...string) bool {
	var err tree_lib.TreeError
	err.From = tree_lib.FROM_API_INIT
	if len(targets) == 0 {
		tree_log.Error(err.From, "For running API client you need to specify target node(s) to connect")
		return false
	}
	for _, n := range targets {
		node_info.ChildsNodeInfo[n], err = tree_db.GetNodeInfo(n)
		if !err.IsNull() {
			tree_log.Error(err.From, fmt.Sprintf("Unable Getting target (%s) node info from Node database, ", n), err.Error())
			return false
		}
	}

	rand.Seed(time.Now().UnixNano())
	node_info.CurrentNodeInfo = node_info.NodeInfo{
		Name:   fmt.Sprintf("%s|%s", API_NAME_PREFIX, tree_lib.RandomString(10)),
		Childs: targets,
		// Getting next prime number based on Unix Timestamp nanoseconds and
		// TODO: Think about making this in a different way
		Value: tree_lib.NextPrimeNumber((1 * rand.Int63n(100)) + int64(100)),
	}

	node_info.CurrentNodeValue = big.NewInt(node_info.CurrentNodeInfo.Value)

	// Setting node values based on child list
	node_info.CalculateChildParentNodeValues()

	// After we have child information lets connect to them
	node_info.ChildsConnectionUpdate()

	return true
}
开发者ID:treescale,项目名称:treescale,代码行数:35,代码来源:api_node.go

示例3: HandleTriggerCustomEvent

func HandleTriggerCustomEvent(e *tree_event.Event, api_cmd Command) {
	var (
		out        = &WriterCallback{BufferMaxSize: 1024}
		event_name = string(api_cmd.Data)
		err        tree_lib.TreeError
		ev_data    []byte
	)
	err.From = tree_lib.FROM_TRIGGER_CUSTOM_EVENT
	out.OutCallback = func(data []byte, ended bool) {
		cb_cmd := api_cmd
		cb_cmd.Ended = ended
		cb_cmd.Data = data
		ev_data, err.Err = ffjson.Marshal(cb_cmd)
		if !err.IsNull() {
			tree_log.Error(err.From, err.Error())
			return
		}
		SendCommandCallback(e, ev_data)
	}
	defer out.End()
	err = custom_event.Trigger(event_name, out)
	if !err.IsNull() {
		tree_log.Error(err.From, err.Error())
	}
}
开发者ID:treescale,项目名称:treescale,代码行数:25,代码来源:handle_event.go

示例4: GetParentInfo

func GetParentInfo(node string) (node_info.NodeInfo, tree_lib.TreeError) {
	var (
		err   tree_lib.TreeError
		pname string
	)
	err.From = tree_lib.FROM_GET_PARENT_INFO

	err = ForEach(DB_NODE, func(key []byte, val []byte) error {
		n := node_info.NodeInfo{}
		err := ffjson.Unmarshal(val, &n)
		if err != nil {
			return err
		}

		if _, ok := tree_lib.ArrayContains(n.Childs, node); ok {
			pname = n.Name
			return errors.New("Just Err for break")
		}

		return nil
	})

	if len(pname) == 0 {
		return node_info.NodeInfo{}, tree_lib.TreeError{}
	}

	// Node relations first element should be parent node
	return GetNodeInfo(pname)
}
开发者ID:treescale,项目名称:treescale,代码行数:29,代码来源:node_db.go

示例5: HandleContainerCommand

func HandleContainerCommand(ev *tree_event.Event, cmd Command) {
	var (
		out        = &WriterCallback{BufferMaxSize: 1024}
		docker_cmd = tree_docker.DockerCmd{}
		err        tree_lib.TreeError
		ev_data    []byte
	)
	err.From = tree_lib.FROM_HANDLE_CONTAINER_COMMAND
	err.Err = ffjson.Unmarshal(cmd.Data, &docker_cmd)
	if !err.IsNull() {
		tree_log.Error(err.From, "unable to unmarshal command data as a docker command -> ", err.Error())
		return
	}
	out.OutCallback = func(data []byte, ended bool) {
		cb_cmd := cmd
		cb_cmd.Ended = ended
		cb_cmd.Data = data
		ev_data, err.Err = ffjson.Marshal(cb_cmd)
		if !err.IsNull() {
			tree_log.Error(err.From, err.Error())
			return
		}
		SendCommandCallback(ev, ev_data)
	}

	defer out.End()

	tree_docker.ContainerCommands(&docker_cmd, out)
}
开发者ID:treescale,项目名称:treescale,代码行数:29,代码来源:handle_container.go

示例6: triggerInitEvent

func triggerInitEvent() tree_lib.TreeError {
	var (
		err             tree_lib.TreeError
		dock_containers []docker.APIContainers
	)
	err.From = tree_lib.FROM_TRIGGER_INIT_EVENT
	dock_containers, err.Err = DockerClient.ListContainers(docker.ListContainersOptions{All: false})
	if !err.IsNull() {
		return err
	}

	// Triggering event with currently running Docker containers inside
	tree_event.Trigger(&tree_event.Event{Name: tree_event.ON_DOCKER_INIT, LocalVar: dock_containers})
	return err
}
开发者ID:treescale,项目名称:treescale,代码行数:15,代码来源:docker.go

示例7: HandleApiCommand

func HandleApiCommand(cmd_data []byte, api_out io.Writer) {
	var (
		err tree_lib.TreeError
		cmd DockerCmd
	)
	err.From = tree_lib.FROM_HANDLE_API_COMMAND
	err.Err = ffjson.Unmarshal(cmd_data, &cmd)
	if !err.IsNull() {
		writeOutput(api_out, true, fmt.Sprintf("--- Unable to parse Container command data: %s", string(cmd_data)), map[string]string{})
		return
	}

	ContainerCommands(&cmd, api_out)
	fmt.Println(string(cmd_data))
}
开发者ID:treescale,项目名称:treescale,代码行数:15,代码来源:commands.go

示例8: RestoreFromConfigDump

func RestoreFromConfigDump(cmd *cobra.Command, args []string) {
	var (
		dump_file string
		err       tree_lib.TreeError
	)
	err.From = tree_lib.FROM_RESTORE_FROM_CONFIG_DUMP
	dump_file, err.Err = cmd.Flags().GetString("file")
	if !err.IsNull() {
		tree_log.Error(err.From, err.Error())
		return
	}

	err = tree_db.LoadFromDumpPath(dump_file)
	if !err.IsNull() {
		tree_log.Error(err.From, err.Error())
		return
	}
}
开发者ID:treescale,项目名称:treescale,代码行数:18,代码来源:config.go

示例9: SendDockerCommand

func SendDockerCommand(cmd tree_docker.DockerCmd, node string, target []string, tag []string, group []string) {
	var err tree_lib.TreeError
	if !tree_api.API_INIT(node) {
		fmt.Println("Unable to init api client")
		fmt.Println("Exiting ...")
		return
	}
	err.From = tree_lib.FROM_SEND_DOCKER_COMMAND
	var (
		api_cmd = tree_api.Command{}
		wait    = make(chan bool)
	)

	api_cmd.ID = tree_lib.RandomString(20)
	api_cmd.Data, err.Err = ffjson.Marshal(cmd)
	if !err.IsNull() {
		tree_log.Error(err.From, err.Error())
		return
	}
	api_cmd.CommandType = tree_api.COMMAND_CONTAINER

	tree_event.ON(tree_event.ON_CHILD_CONNECTED, func(ev *tree_event.Event) {
		path := &tree_graph.Path{From: node, Nodes: target, Groups: group, Tags: tag}
		tree_api.SendCommand(&api_cmd, path, func(e *tree_event.Event, c tree_api.Command) bool {
			fmt.Println(string(c.Data))
			fmt.Println(c.Ended)
			if c.Ended {
				return false
			}
			return true
		})
		wait <- true
	})
	<-wait
}
开发者ID:treescale,项目名称:treescale,代码行数:35,代码来源:api.go

示例10: GroupPath

func GroupPath(from_node, group_name string) (map[string]*big.Int, tree_lib.TreeError) {
	var (
		path           = make(map[string]*big.Int)
		err            tree_lib.TreeError
		nodes_in_group []string
	)
	err.From = tree_lib.FROM_GROUP_PATH
	nodes_in_group, err = tree_db.GetGroupNodes(group_name)
	if !err.IsNull() {
		return nil, err
	}
	for _, n := range nodes_in_group {
		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
}
开发者ID:treescale,项目名称:treescale,代码行数:25,代码来源:get_path.go

示例11: TagPath

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
}
开发者ID:treescale,项目名称:treescale,代码行数:25,代码来源:get_path.go

示例12: callEvent

func callEvent(event *docker.APIEvents) tree_lib.TreeError {
	var err tree_lib.TreeError
	err.From = tree_lib.FROM_CALL_EVENT
	switch event.Status {
	case "start", "unpouse":
		{
			var (
				dock_inspect *docker.Container
			)
			dock_inspect, err.Err = DockerClient.InspectContainer(event.ID)
			if !err.IsNull() {
				return err
			}
			ci := ContainerInfo{InspectContainer: dock_inspect, ID: event.ID, Image: dock_inspect.Config.Image}
			tree_event.Trigger(&tree_event.Event{Name: tree_event.ON_DOCKER_CONTAINER_START, LocalVar: &ci})
		}
	case "die", "kill", "pause":
		{
			// Sending only Container ID if it stopped
			// Sometimes Docker API not giving all info about container after stopping it
			tree_event.Trigger(&tree_event.Event{Name: tree_event.ON_DOCKER_CONTAINER_STOP, LocalVar: event.ID})
		}
	case "pull", "tag":
		{
			var (
				inspect *docker.Image
			)
			inspect, err.Err = DockerClient.InspectImage(event.ID)
			if !err.IsNull() {
				return err
			}
			im := ImageInfo{ID: inspect.ID, Name: event.ID, Inspect: inspect}
			tree_event.Trigger(&tree_event.Event{Name: tree_event.ON_DOCKER_IMAGE_CREATE, LocalVar: &im})
		}
	case "untag", "delete":
		{
			var (
				inspect *docker.Image
			)
			inspect, err.Err = DockerClient.InspectImage(event.ID)
			if !err.IsNull() {
				return err
			}
			im := ImageInfo{ID: inspect.ID, Name: event.ID, Inspect: inspect}
			tree_event.Trigger(&tree_event.Event{Name: tree_event.ON_DOCKER_IMAGE_DELETE, LocalVar: &im})
		}
	}
	return err
}
开发者ID:treescale,项目名称:treescale,代码行数:49,代码来源:docker.go

示例13: TriggerFromData

func TriggerFromData(data []byte) {
	var (
		e   = new(Event)
		err tree_lib.TreeError
	)
	err.From = tree_lib.FROM_TRIGGER_FROM_DATA
	err.Err = ffjson.Unmarshal(data, e)
	if !err.IsNull() {
		tree_log.Error(log_from_event, err.Error())
		return
	}
	Trigger(e)
}
开发者ID:treescale,项目名称:treescale,代码行数:13,代码来源:event.go

示例14: SetParent

func SetParent(name string) bool {
	var err tree_lib.TreeError
	err.From = tree_lib.FROM_SET_PARENT
	node_info.ParentNodeInfo, err = tree_db.GetNodeInfo(name)
	if !err.IsNull() {
		tree_log.Error(err.From, "Getting parent node info from Node database, ", err.Error())
		return false
	}
	return true
}
开发者ID:treescale,项目名称:treescale,代码行数:10,代码来源:node.go

示例15: UpdateNodeChange

func UpdateNodeChange(info node_info.NodeInfo) {
	var (
		ev  = &tree_event.Event{}
		err tree_lib.TreeError
	)
	err.From = tree_lib.FROM_UPDATE_NODE_CHANGE
	ev.Data, err.Err = ffjson.Marshal(info)
	if !err.IsNull() {
		tree_log.Error(err.From, err.Error())
		return
	}
	path := &tree_graph.Path{From: node_info.CurrentNodeInfo.Name, Nodes: []string{"*"}}
	ev.Name = tree_event.ON_UPDATE_NODE_INFO
	tree_event.Trigger(ev)
	tree_event.Emit(ev, path)
}
开发者ID:treescale,项目名称:treescale,代码行数:16,代码来源:handle_info.go


注:本文中的tree_lib.TreeError类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。