本文整理汇总了Golang中tree_lib.TreeError.From方法的典型用法代码示例。如果您正苦于以下问题:Golang TreeError.From方法的具体用法?Golang TreeError.From怎么用?Golang TreeError.From使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree_lib.TreeError
的用法示例。
在下文中一共展示了TreeError.From方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: HandleDelete
func HandleDelete(cmd *cobra.Command, args []string) {
var (
node string
target []string
tag []string
group []string
container string
err tree_lib.TreeError
)
err.From = tree_lib.FROM_HANDLE_DELETE
node, err.Err = cmd.Flags().GetString("node")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
target, err.Err = cmd.Flags().GetStringSlice("target")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
container, err.Err = cmd.Flags().GetString("container")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
var (
docker_cmd = tree_docker.DockerCmd{}
)
docker_cmd.Content = make(map[string]string)
docker_cmd.Command = tree_docker.COMMAND_DOCKER_CONTAINER_DELETE
docker_cmd.Content["container"] = container
SendDockerCommand(docker_cmd, node, target, tag, group)
}
示例2: 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()
}
示例3: 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
}
示例4: 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
}
示例5: 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
}
示例6: HandleExecCommand
// Executing some commands using exec.Command functionality from Go in OS
func HandleExecCommand(e *tree_event.Event, api_cmd Command) {
var (
out = &WriterCallback{BufferMaxSize: 1024}
cmd_str = string(api_cmd.Data)
cmd_options = strings.Split(cmd_str, " ")
cmd = exec.Command(cmd_options[0], cmd_options[1:]...)
err tree_lib.TreeError
ev_data []byte
)
err.From = tree_lib.FROM_HANDLE_EXEC_COMMAND
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()
cmd.Stdout = out
cmd.Stderr = out
err.Err = cmd.Run()
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
}
}
示例7: 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
}
示例8: 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)
}
示例9: 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())
}
}
示例10: 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)
}
示例11: HandleNodeCommand
func HandleNodeCommand(cmd *cobra.Command, args []string) {
var (
name string
err tree_lib.TreeError
)
err.From = tree_lib.FROM_HANDLE_NODE_COMMAND
name, err.Err = cmd.Flags().GetString("set-name")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
}
// If we have set-name flag then we just setting current_node in database and exiting
if len(name) > 0 {
tree_db.Set(tree_db.DB_RANDOM, []byte("current_node"), []byte(name))
return
}
daemon := false
daemon, err.Err = cmd.Flags().GetBool("daemon")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
if daemon {
cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("%s node > %s 2>&1 &", os.Args[0], tree_log.LogFile))
err.Err = cmd.Run()
if !err.IsNull() {
log.Fatal(err.Err)
}
return
}
name, err.Err = cmd.Flags().GetString("name")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
if len(name) == 0 {
current_node_byte, err := tree_db.Get(tree_db.DB_RANDOM, []byte("current_node"))
if !err.IsNull() {
tree_log.Error(err.From, "Getting current node name from Random database, ", err.Error())
return
}
if len(current_node_byte) == 0 {
fmt.Println("Name is important for the first time run")
return
}
} else {
err = tree_node.SetCurrentNode(name)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
}
tree_node.Start()
}
示例12: SubscribeEvents
func (bs *BalancingService) SubscribeEvents() {
tree_event.ON(tree_event.ON_DOCKER_INIT, func(e *tree_event.Event) {
var err tree_lib.TreeError
err.From = tree_lib.FROM_SUBSCRIBE_EVENTS
if e.LocalVar == nil {
tree_log.Info(err.From, "Containers list is nil during INIT event")
return
}
for _, c := range e.LocalVar.([]docker.APIContainers) {
if port, ok := bs.DockerImages[c.Image]; ok {
var ci *docker.Container
ci, err.Err = tree_docker.DockerClient.InspectContainer(c.ID)
if !err.IsNull() {
continue
}
cont_addr := Address{IP: ci.NetworkSettings.IPAddress, Port: port}
err.Err = bs.AddDestination(cont_addr)
if !err.IsNull() {
return
}
containerAddressMap[c.ID] = cont_addr
}
}
})
tree_event.ON(tree_event.ON_DOCKER_CONTAINER_START, func(e *tree_event.Event) {
var err tree_lib.TreeError
if e.LocalVar == nil {
tree_log.Info(log_from_balancer, "Container Info is nil during container Start event")
return
}
ci := e.LocalVar.(*tree_docker.ContainerInfo)
if port, ok := bs.DockerImages[ci.Image]; ok {
cont_addr := Address{IP: ci.InspectContainer.NetworkSettings.IPAddress, Port: port}
err.Err = bs.AddDestination(cont_addr)
if !err.IsNull() {
return
}
containerAddressMap[ci.ID] = cont_addr
}
})
tree_event.ON(tree_event.ON_DOCKER_CONTAINER_STOP, func(e *tree_event.Event) {
if e.LocalVar == nil {
tree_log.Info(log_from_balancer, "Container ID is nil during container Stop event")
return
}
cont_id := e.LocalVar.(string)
if cont_addr, ok := containerAddressMap[cont_id]; ok {
bs.DeleteDestination(cont_addr)
delete(containerAddressMap, cont_id)
bs.CheckForStopEvent()
}
})
}
示例13: 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
}
示例14: HandleImageDelete
func HandleImageDelete(cmd *cobra.Command, args []string) {
var (
node string
target []string
tag []string
group []string
force bool
image string
err tree_lib.TreeError
)
err.From = tree_lib.FROM_HANDLE_IMAGE_DELETE
node, err.Err = cmd.Flags().GetString("node")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
target, err.Err = cmd.Flags().GetStringSlice("target")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
tag, err.Err = cmd.Flags().GetStringSlice("tag")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
group, err.Err = cmd.Flags().GetStringSlice("group")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
image, err.Err = cmd.Flags().GetString("image")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
force, err.Err = cmd.Flags().GetBool("force")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
var (
docker_cmd = tree_docker.DockerCmd{}
)
docker_cmd.Content = make(map[string]string)
docker_cmd.Command = tree_docker.COMMAND_DOCKER_IMAGE_DELETE
docker_cmd.Content["image"] = image
if force {
docker_cmd.Content["force"] = "yes"
} else {
docker_cmd.Content["force"] = "no"
}
SendDockerCommand(docker_cmd, node, target, tag, group)
}
示例15: 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)
}