journalspace

package
v2.0.200+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package journalspace provides mechanisms for mapping a collection of JournalSpecs into a minimally-described hierarchical structure, and for mapping back again. This is principally useful for tooling over JournalSpecs, which must be written to (& read from) Etcd in fully-specified and explicit form (a representation which is great for implementors, but rather tedious for cluster operators to work with). Tooling can map JournalSpecs into a tree, allow the operator to apply edits in that hierarchical space, and then flatten resulting changes for storage back to Etcd.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	// JournalSpec of the Node, which may be partial and incomplete. Specs apply
	// hierarchically, where Nodes having zero-valued fields inherit those of
	// their parent, and parent Nodes may only have a subset of fields specified.
	// A Node is understood to be a "directory" Node if it ends in a slash '/',
	// and a literal or terminal Node otherwise.
	pb.JournalSpec `yaml:",omitempty,inline"`
	// Delete marks that a Node, and all Nodes which it parents, should be deleted.
	Delete bool `yaml:",omitempty"`
	// Revision of the Journal within Etcd. Non-zero for non-directory Nodes only.
	Revision int64 `yaml:",omitempty"`
	// Children of this Node. Directory Nodes must have one or more Children, and
	// non-directory terminal Nodes may not have any.
	Children []Node `yaml:",omitempty"`
}

Node represents a collection of JournalSpecs which are related by hierarchical path components, and which may share common portions of their journal specifications.

func ExtractTree

func ExtractTree(nodes []Node) Node

ExtractTree derives the tree from ordered []Nodes implied by their shared path "directories", or component prefixes. For example, journals:

  • root/foo/bar
  • root/foo/baz
  • root/bing

Will result in the tree:

  • root/
  • root/foo/
  • root/foo/bar
  • root/foo/baz
  • root/bing

func (*Node) Flatten

func (n *Node) Flatten() []Node

Flatten indirect and direct children of the Node into a Node slice, merging parent JournalSpecs into those of children at each descending level of the hierarchy.

func (*Node) HoistSpecs

func (n *Node) HoistSpecs()

HoistSpecs performs a bottom-up initialization of non-terminal "directory" Node JournalSpec fields. Specifically, at each recursive step a parent Node specification field is set if the value is shared by all of the Node's direct Children. The field is then zeroed at each child in turn. After hoisting, the overall repetition of JournalSpec fields in the tree is minimized, as every field which is already implied by a parent is zeroed.

func (Node) IsDir

func (n Node) IsDir() bool

IsDir returns whether the Node.JournalSpec.Name is empty or ends in a slash ('/').

func (*Node) Validate

func (n *Node) Validate() error

Validate returns an error if the Node hierarchy is not well formed. Note that Validate does *not* also Validate contained JournalSpecs, as partial or incomplete JournalSpecs are permitted within a Node hierarchy. They must be checked separately.

Jump to

Keyboard shortcuts

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