db

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const BuildsTable string = "builds"

BuildsTable contains name of the builds table

View Source
const NodesTable string = "nodes"

NodesTable contains name of the nodes table

View Source
const ServerTable string = "servers"

ServerTable contains name of the server table

View Source
const TestTable string = "testnets"

TestTable contains name of the testnet table

View Source
const Version = "2.2.3"

Variables

This section is empty.

Functions

func Check

func Check() error

func CheckAndUpdate

func CheckAndUpdate()

func DeleteMeta

func DeleteMeta(key string) error

func DeleteNode

func DeleteNode(id string) error

DeleteNode removes a node from the database (Deprecated)

func DeleteNodesByServer

func DeleteNodesByServer(id string) error

DeleteNodesByServer delete all nodes which have ever been on a given server.

func DeleteNodesByTestNet

func DeleteNodesByTestNet(id string) error

DeleteNodesByTestNet removes all nodes in a testnet from the database. (Deprecated)

func DeleteServer

func DeleteServer(id int) error

Delete a server by id

func DivideNodesByAbsMatch

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

func GetAllServers

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

Get all of the servers, indexed by name

func GetHostIPsByTestNet

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

Get the ips of the hosts for a testnet

func GetMeta

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

func GetMetaP

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

func GetUniqueServerIds

func GetUniqueServerIds(nodes []Node) []int

func InsertBuild

func InsertBuild(dd DeploymentDetails, testnetID string) error

InsertBuild inserts a build

func InsertLocalServers

func InsertLocalServers(db *sql.DB)

InsertLocalServers adds the default server(s) to the servers database, allowing immediate use of the application without having to register a server

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)

Insert a new server into the database

func InsertTestNet

func InsertTestNet(testnet TestNet) error

Insert a testnet into the database

func SetMeta

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

func SetVersion

func SetVersion(version string) error

func UpdateServer

func UpdateServer(id int, server Server) error

Update a server by id

func UpdateServerNodes

func UpdateServerNodes(id int, nodes int) error

Update the number of nodes a server has

func UpdateTestNet

func UpdateTestNet(id int, testnet TestNet) error

Update a testnet by id

func UpdateTestNetNodes

func UpdateTestNetNodes(id int, nodes int) error

Update the number of nodes in a testnet

Types

type DeploymentDetails

type DeploymentDetails struct {
	/*
	   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 []map[string]string    `json:"environments"`
	Files        []map[string]string    `json:"files"`
	Logs         []map[string]string    `json:"logs"`
	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 paramters based off testnet id

func GetLastBuildByKid

func GetLastBuildByKid(kid string) (DeploymentDetails, error)

GetBuildByTestnet gets the build paramters based off testnet id

func QueryBuilds

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

func (DeploymentDetails) GetJwt

func (this DeploymentDetails) GetJwt() string

func (DeploymentDetails) GetKid

func (this DeploymentDetails) GetKid() string

func (*DeploymentDetails) SetJwt

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

type Node

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

	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 in the testnet
	*/
	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"`
}

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)

func GetNodeByLocalId

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

func GetNodeByTestNetAndId

func GetNodeByTestNetAndId(testnet string, id string) (Node, error)

GetNode fetches a node by id

type Server

type Server struct {
	/*
	   Address of the server which is accessible from genesis
	*/
	Addr     string   `json:"addr"`
	Nodes    int      `json:"nodes"`
	Max      int      `json:"max"`
	Id       int      `json:"id"`
	SubnetID int      `json:"subnetID"`
	Ips      []string `json:"ips"`
}

func GetServer

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

Get a server by id

func GetServers

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

Get servers from their ids

func (Server) Validate

func (s Server) Validate() error

Ensure that a server object contains valid data

type TestNet

type TestNet struct {
	Id         string `json:"id"`
	Blockchain string `json:"blockchain"`
	Nodes      int    `json:"nodes"`
	Image      string `json:"image"`
	Ts         int64  `json:"timestamp"`
}

func GetAllTestNets

func GetAllTestNets() ([]TestNet, error)

Get all of the testnets

func GetTestNet

func GetTestNet(id string) (TestNet, error)

Get a testnet by id

Jump to

Keyboard shortcuts

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