示例#1
0
func node_init() {
	// Getting current node name
	current_node_byte, err := tree_db.Get(tree_db.DB_RANDOM, []byte("current_node"))
	err.From = tree_lib.FROM_NODE_INIT
	if !err.IsNull() {
		tree_log.Error(err.From, "Getting current node name from Random database, ", err.Error())
		return
	}
	current_node_name = string(current_node_byte)
	node_info.CurrentNodeInfo, err = tree_db.GetNodeInfo(current_node_name)
	if !err.IsNull() {
		tree_log.Error(err.From, "Getting current node info from Node database, ", err.Error())
		return
	}

	// Setting current Node Value field from string to big.Int
	node_info.CurrentNodeValue = nil // Setting to nil for garbage collection
	node_info.CurrentNodeValue = big.NewInt(node_info.CurrentNodeInfo.Value)

	for _, child := range node_info.CurrentNodeInfo.Childs {
		node_info.ChildsNodeInfo[child], err = tree_db.GetNodeInfo(child)
		if !err.IsNull() {
			tree_log.Error(err.From, fmt.Sprintf("Getting child (%s) node info from Node database, ", child), err.Error())
			return
		}
	}

	// Setting relations
	tree_db.SetRelations(current_node_name)

	node_info.ParentNodeInfo, err = tree_db.GetParentInfo(current_node_name)
	if !err.IsNull() {
		tree_log.Error(err.From, "Getting parent node info from Node database, ", err.Error())
		return
	}

	// Setting node values based on child list
	node_info.CalculateChildParentNodeValues()
}
示例#2
0
func DBFromConfig() {
	var (
		err        tree_lib.TreeError
		prev_prime = int64(1)
	)
	err.From = tree_lib.FROM_DB_FROM_CONFIG

	for n, nf := range GLOBAL_CONFIG.TreeNode {
		nf.Value = tree_lib.NextPrimeNumber(prev_prime)
		prev_prime = nf.Value
		err = tree_db.SetNodeInfo(n, nf)
		if !err.IsNull() {
			tree_log.Error(err.From, err.Error())
		}
	}

	// After having All nodes information now we can set related things for every node
	for n, _ := range GLOBAL_CONFIG.TreeNode {
		// Setting relations for every Node
		err = tree_db.SetRelations(n)
		if !err.IsNull() {
			tree_log.Error(err.From, err.Error())
		}

		// Setting Groups with node lists in Group database
		err = tree_db.AddNodeToHisGroups(n)
		if !err.IsNull() {
			tree_log.Error(err.From, err.Error())
		}

		// Setting Tags with node lists in Group database
		err = tree_db.AddNodeToHisTags(n)
		if !err.IsNull() {
			tree_log.Error(err.From, err.Error())
		}
	}

	// Setting Balancers
	for b, b_conf := range GLOBAL_CONFIG.Balancer {
		var b_data []byte
		b_data, err.Err = ffjson.Marshal(b_conf)
		if !err.IsNull() {
			tree_log.Error(err.From, "Error encoding balancer config", b, " -> ", err.Error())
			continue
		}
		err = tree_db.Set(tree_db.DB_BALANCER, []byte(b), b_data)
		if !err.IsNull() {
			tree_log.Error(err.From, "Error setting balancer config", b, " -> ", err.Error())
		}
	}

	// Setting Registry
	for r, r_conf := range GLOBAL_CONFIG.Registry {
		var r_data []byte
		r_data, err.Err = ffjson.Marshal(r_conf)
		if !err.IsNull() {
			tree_log.Error(err.From, "Error encoding registry config", r, " -> ", err.Error())
			continue
		}
		err = tree_db.Set(tree_db.DB_REGISTRY, []byte(r), r_data)
		if !err.IsNull() {
			tree_log.Error(err.From, "Error setting registry config", r, " -> ", err.Error())
		}
	}
}