db

package
v1.8.5 Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package db manages persistent state and keeps track of previous and current builds.

Index

Constants

View Source
const BuildsTable = "builds"

BuildsTable contains name of the builds table

View Source
const NodesTable = "nodes"

NodesTable contains name of the nodes table

View Source
const ServerTable = "servers"

ServerTable contains name of the server table

View Source
const Version = "2.2.4"

Version represents the database version, upon change of this constant, the database will be purged

Variables

This section is empty.

Functions

func DeleteMeta

func DeleteMeta(key string) error

DeleteMeta deletes the value stored at key

func DeleteServer

func DeleteServer(id int) error

DeleteServer deletes a server by id

func DivideNodesByAbsMatch

func DivideNodesByAbsMatch(nodes []Node, nodeNums []int) ([]Node, []Node, error)

DivideNodesByAbsMatch spits the given nodes into nodes which have their absnum in the given nodeNums and those who don't

func GetAllServers

func GetAllServers() (map[string]Server, error)

GetAllServers gets all of the servers, indexed by name

func GetHostIPsByTestNet

func GetHostIPsByTestNet(id int) ([]string, error)

GetHostIPsByTestNet gets the ips of the hosts for a testnet

func GetMeta

func GetMeta(key string) (interface{}, error)

GetMeta returns the value stored at key as interface

func GetMetaP

func GetMetaP(key string, v interface{}) error

GetMetaP fetches the value of key and returns it to v, v should be a pointer

func GetUniqueServerIDs added in v1.6.5

func GetUniqueServerIDs(nodes []Node) []int

GetUniqueServerIDs extracts the unique server ids from a slice of Node

func InsertBuild

func InsertBuild(dd DeploymentDetails, testnetID string) error

InsertBuild inserts a build

func InsertNode

func InsertNode(node Node) (int, error)

InsertNode inserts a node into the database

func InsertServer

func InsertServer(name string, server Server) (int, error)

InsertServer inserts a new server into the database

func SetMeta

func SetMeta(key string, value interface{}) error

SetMeta stores a key value pair in the sql-lite database as json

func UpdateServer

func UpdateServer(id int, server Server) error

UpdateServer updates a server by id

func UpdateServerNodes

func UpdateServerNodes(id int, nodes int) error

UpdateServerNodes update the number of nodes a server has

Types

type DeploymentDetails

type DeploymentDetails struct {
	// ID will be included when it is queried from the database.
	ID string `json:"id,omitempty"`

	/*
	   Servers: The ids of the servers to build on
	*/
	Servers []int `json:"servers"`
	/*
	   Blockchain: The blockchain to build.
	*/
	Blockchain string `json:"blockchain"`
	/*
	   Nodes:  The number of nodes to build
	*/
	Nodes int `json:"nodes"`
	/*
	   Image: The docker image to build off of
	*/
	Images []string `json:"images"`
	/*
	   Params: The blockchain specific parameters
	*/
	Params map[string]interface{} `json:"params"`
	/*
	   Resources: The resources per node
	*/
	Resources []util.Resources `json:"resources"`
	/*
		Environments is the environment variables to be passed to each node.
		If it doesn't exist for a node, it defaults first to index 0.
	*/
	Environments []map[string]string `json:"environments"`
	/*
		Custom files for each node
	*/
	Files []map[string]string `json:"files"`
	/*
		Logs to keep track of for each node
	*/
	Logs []map[string]string `json:"logs"`

	/*
		Fairly Arbitrary extras for when additional customizations are added.
	*/
	Extras map[string]interface{} `json:"extras"`
	// contains filtered or unexported fields
}

DeploymentDetails represents the data for the construction of a testnet.

func GetAllBuilds

func GetAllBuilds() ([]DeploymentDetails, error)

GetAllBuilds gets all of the builds done by a user

func GetBuildByTestnet

func GetBuildByTestnet(id string) (DeploymentDetails, error)

GetBuildByTestnet gets the build parameters based off testnet id

func GetLastBuildByKid

func GetLastBuildByKid(kid string) (DeploymentDetails, error)

GetLastBuildByKid gets the build parameters based off kid

func QueryBuilds

func QueryBuilds(query string) ([]DeploymentDetails, error)

QueryBuilds fetches DeploymentDetails based on the given SQL select query

func (DeploymentDetails) GetJwt

func (dd DeploymentDetails) GetJwt() string

GetJwt gets the jwt of the creator of this build

func (DeploymentDetails) GetKid

func (dd DeploymentDetails) GetKid() string

GetKid gets the kid of the jwt of the creator of this build

func (*DeploymentDetails) SetJwt

func (dd *DeploymentDetails) SetJwt(jwt string) error

SetJwt stores the callers jwt

type Node

type Node struct {
	// ID is the UUID of the node
	ID string `json:"id"`

	//AbsoluteNum is the number of the node in the testnet
	AbsoluteNum int `json:"absNum"`

	// TestNetId is the id of the testnet to which the node belongs to
	TestNetID string `json:"testnetId"`

	// Server is the id of the server on which the node resides
	Server int `json:"server"`

	// LocalID is the number of the node on the server it resides
	LocalID int `json:"localId"`

	// IP is the ip address of the node
	IP string `json:"ip"`

	// Label is the string given to the node by the build process
	Label string `json:"label"`

	// Image is the docker image used to build this node
	Image string `json:"image"`

	// Blockchain is the blockchain type of this node
	Blockchain string `json:"blockchain"`
}

Node represents a node within the network

func GetAllNodes

func GetAllNodes() ([]Node, error)

GetAllNodes gets every node that has ever existed.

func GetAllNodesByServer

func GetAllNodesByServer(serverID int) ([]Node, error)

GetAllNodesByServer gets all nodes that have ever existed on a server

func GetAllNodesByTestNet

func GetAllNodesByTestNet(testID string) ([]Node, error)

GetAllNodesByTestNet gets all the nodes which are in the given testnet

func GetNode

func GetNode(id string) (Node, error)

GetNode fetches a node by id

func GetNodeByAbsNum

func GetNodeByAbsNum(nodes []Node, absNum int) (Node, error)

GetNodeByAbsNum finds a node based on its absolute node number

func GetNodeByLocalID added in v1.6.5

func GetNodeByLocalID(nodes []Node, localID int) (Node, error)

GetNodeByLocalID looks up a node by its localID

func (Node) GetAbsoluteNumber added in v1.7.1

func (n Node) GetAbsoluteNumber() int

GetAbsoluteNumber gets the absolute number of the node in the testnet

func (Node) GetIP added in v1.7.1

func (n Node) GetIP() string

GetIP gets the ip address of this node

func (Node) GetNodeName added in v1.7.1

func (n Node) GetNodeName() string

GetNodeName gets the whiteblock name of this node

func (Node) GetRelativeNumber added in v1.7.1

func (n Node) GetRelativeNumber() int

GetRelativeNumber gets the local id of the node

func (Node) GetServerID added in v1.7.1

func (n Node) GetServerID() int

GetServerID gets the id of the server on which this node resides

func (Node) GetTestNetID added in v1.7.1

func (n Node) GetTestNetID() string

GetTestNetID gets the id of the testnet this node is a part of

type Server

type Server struct {
	// Addr is the address of the server which is accessible by genesis
	Addr string `json:"addr"`
	// Nodes is the number of nodes currently on this server
	Nodes int `json:"nodes"`
	// Max is the maximum number of nodes that server supports
	Max int `json:"max"`
	// ID is the ID of the server
	ID int `json:"id"`
	// SubnetID is the number used in the IP scheme for nodes on this server
	SubnetID int      `json:"subnetID"`
	Ips      []string //To be removed
}

Server represents a server on which genesis can build

func GetServer

func GetServer(id int) (Server, string, error)

GetServer gets a server by its id

func GetServers

func GetServers(ids []int) ([]Server, error)

GetServers gets servers from their ids

func (Server) Validate

func (s Server) Validate() error

Validate ensures that the server object contains valid data

type SideCar added in v1.7.1

type SideCar struct {
	ID string `json:"id"`

	NodeID string `json:"nodeID"`

	AbsoluteNodeNum int `json:"absNum"`

	// TestNetID is the id of the testnet to which the node belongs to
	TestnetID string `json:"testnetID"`

	// Server is the id of the server on which the node resides
	Server int `json:"server"`

	//LocalID is the number of the node in the testnet
	LocalID int `json:"localID"`

	NetworkIndex int `json:"networkIndex"`

	// IP is the ip address of the node
	IP string `json:"ip"`

	// Image is the docker image on which the sidecar was built
	Image string `json:"image"`

	// Type is the type of sidecar
	Type string `json:"type"`
}

SideCar represents a supporting node within the network

func (SideCar) GetAbsoluteNumber added in v1.7.1

func (n SideCar) GetAbsoluteNumber() int

GetAbsoluteNumber gets the absolute node number of the corresponding ndoe

func (SideCar) GetIP added in v1.7.1

func (n SideCar) GetIP() string

GetIP gets the ip address of this side car

func (SideCar) GetNodeName added in v1.7.1

func (n SideCar) GetNodeName() string

GetNodeName gets the whiteblock name of this side car

func (SideCar) GetRelativeNumber added in v1.7.1

func (n SideCar) GetRelativeNumber() int

GetRelativeNumber gets the local id of the corresponding node

func (SideCar) GetServerID added in v1.7.1

func (n SideCar) GetServerID() int

GetServerID gets the id of the server this side car resides on

func (SideCar) GetTestNetID added in v1.7.1

func (n SideCar) GetTestNetID() string

GetTestNetID gets the id of the testnet this side car is a part of

Jump to

Keyboard shortcuts

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