node

package
v0.0.0-...-1fc07e7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RootNode is the root node name.
	RootNode = "loda"
	// PoolNode is the global pool node.
	PoolNode = "pool"
	// NodeDeli join node to ns.
	// e.g The global pool node is the the leaf child of root node, its ns is pool.loda.
	NodeDeli = "."

	// NodeDataBucketID is the bucketID to save node data.
	NodeDataBucketID = "loda"
	// NodeDataKey is the node data key.
	NodeDataKey = "node"

	// NsFormat
	NsFormat = "ns"
	// IDFormat
	IDFormat = "id"
	// NotMatchMachine is defaul not match machine.
	NotMatchMachine = "^$"
)
View Source
const (
	// Leaf node type
	Leaf = iota // leaf type of node
	// NonLeaf node type
	NonLeaf
	// Root type of node
	Root
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Inf

type Inf interface {
	// GetNodeByNS return the node by ns.
	// e.g return root node if get ns "loda".
	GetNodeByNS(ns string) (*Node, error)

	// LeafChildIDs return leaf child node ID list of the ns.
	LeafChildIDs(ns string) ([]string, error)

	// GetNodeIDByNS return the NS of the node ID.
	GetNodeIDByNS(ns string) (string, error)

	// GetNodeNSByID returh the node ID of the ns.
	GetNodeNSByID(id string) (string, error)

	// AllNodes return the root node.
	AllNodes() (*Node, error)
}

Inf is the interface node have.

func NewNode

func NewNode(cluster cluster.Inf) Inf

return a node interface object.

type Node

type Node struct {
	NodeProperty
	Children []*Node `json:"children"`
}

Node is the item of tree, it has machine match stregy and resource.

func (*Node) AllowResource

func (n *Node) AllowResource(resType string) bool

AllowResource checks if the node could be set a resource. Leaf node could set/get resource; NonLeaf node could be only set/get template resource.

If check fail, the node is NonLeaf and resType not template, maybe need get/set at its leaf child node.

func (*Node) Exist

func (n *Node) Exist(ns string) bool

Exist check the ns is exist already or not.

func (*Node) GetByID

func (n *Node) GetByID(nodeID string) (*Node, string, error)

GetByID return exact node and ns which with nodeid.

func (*Node) GetByNS

func (n *Node) GetByNS(ns string) (*Node, error)

GetByNS return exact node by nodename.

func (*Node) IsLeaf

func (n *Node) IsLeaf() bool

IsLeaf return the node is leaf or not.

func (*Node) LeafChildIDs

func (n *Node) LeafChildIDs() ([]string, error)

LeafChildIDs return the leaf id list of this Node.

func (*Node) LeafMachineReg

func (n *Node) LeafMachineReg() (map[string]string, error)

LeafMachineReg return the ns-MachineReg Map.

func (*Node) LeafNs

func (n *Node) LeafNs() ([]string, error)

LeafNs return all leaf child ns.

func (*Node) MarshalJSON

func (j *Node) MarshalJSON() ([]byte, error)

MarshalJSON marshal bytes to json - template

func (*Node) MarshalJSONBuf

func (j *Node) MarshalJSONBuf(buf fflib.EncodingBuffer) error

MarshalJSONBuf marshal buff to json - template

func (*Node) RemoveChildNode

func (n *Node) RemoveChildNode(childID string) error

RemoveChildNode remove the child by node ID.

func (*Node) UnmarshalJSON

func (j *Node) UnmarshalJSON(input []byte) error

UnmarshalJSON umarshall json - template of ffjson

func (*Node) UnmarshalJSONFFLexer

func (j *Node) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error

UnmarshalJSONFFLexer fast json unmarshall - template ffjson

func (*Node) Update

func (n *Node) Update(name, comment, machineMatchStrategy string)

Update update node machineMatchStrategy property.

func (*Node) Walk

func (n *Node) Walk(walkFun WalkfFun) (map[string]string, error)

Walk the node.

type NodeProperty

type NodeProperty struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Comment string `json:"comment"`
	Type    int    `json:"type"`

	// regexp of machine in one node,
	// used to auto add a machine into nodes
	MachineReg string `json:"machinereg"`
}

NodeProperty is node should has.

func (*NodeProperty) MarshalJSON

func (j *NodeProperty) MarshalJSON() ([]byte, error)

MarshalJSON marshal bytes to json - template

func (*NodeProperty) MarshalJSONBuf

func (j *NodeProperty) MarshalJSONBuf(buf fflib.EncodingBuffer) error

MarshalJSONBuf marshal buff to json - template

func (*NodeProperty) UnmarshalJSON

func (j *NodeProperty) UnmarshalJSON(input []byte) error

UnmarshalJSON umarshall json - template of ffjson

func (*NodeProperty) UnmarshalJSONFFLexer

func (j *NodeProperty) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error

UnmarshalJSONFFLexer fast json unmarshall - template ffjson

type WalkfFun

type WalkfFun func(node *Node, childReturn map[string]string) (map[string]string, error)

WalkfFun is the type of the function for each node visited by Walk. The node argument is the node the walkFunc will process. The childReturn argument will pass the nodes's childNode return.

If an error was returned, processing stops.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL