host

package
v0.0.0-...-1509d7a Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Overview

Package host provides to deploy node.

Index

Constants

This section is empty.

Variables

View Source
var (
	ContainerLabel             = "mitum-contest"
	ContainerLabelMongodb      = "mongodb"
	ContainerLabelNode         = "node"
	ContainerLabelNodeAlias    = ContainerLabel + "-node"
	ContainerLabelNodeType     = ContainerLabel + "-type"
	ContainerLabelNodeInitType = "init"
	ContainerLabelNodeRunType  = "run"

	DefaultNodeImage    = "debian:testing-slim"
	DefaultMongodbImage = "mongo"
)
View Source
var (
	ContextValueHosts      util.ContextKey = "hosts"
	ContextValueMongodb    util.ContextKey = "mongodb"
	ContextValueLogSaver   util.ContextKey = "log_saver"
	ContextValueLogWatcher util.ContextKey = "log_watcher"
)
View Source
var ContainerLogIgnoreError = util.NewError("failed to read container logs; ignored")
View Source
var ContestLogName = "contest"
View Source
var DefaultContainerCmdNodeInit = []string{
	"/runner", "node", "init",
	"--log", "log",
	"--log-level", "debug",
	"--log-format", "json",
	"/config.yml",
}
View Source
var DefaultContainerCmdNodeRun = []string{
	"/runner", "node", "run",
	"--log", "log",
	"--log-level", "debug",
	"--log-format", "json",
	"/config.yml",
}

Functions

func AvailablePort

func AvailablePort(network string, exclude []string) (string, error)

func ContainerInspect

func ContainerInspect(ctx context.Context, client *dockerClient.Client, id string) (dockerTypes.ContainerJSON, error)

func CustomNodesActionContainerCmd

func CustomNodesActionContainerCmd(args []string) []string

func LoadHostsContextValue

func LoadHostsContextValue(ctx context.Context, l **Hosts) error

func LoadLogSaverContextValue

func LoadLogSaverContextValue(ctx context.Context, l **LogSaver) error

func LoadLogWatcherContextValue

func LoadLogWatcherContextValue(ctx context.Context, l **LogWatcher) error

func LoadMongodbContextValue

func LoadMongodbContextValue(ctx context.Context, l **Mongodb) error

func MongodbContainerName

func MongodbContainerName() string

func NodeCustomContainerName

func NodeCustomContainerName(alias string) string

func NodeInitContainerName

func NodeInitContainerName(alias string) string

func NodeRunContainerName

func NodeRunContainerName(alias string) string

func PullImage

func PullImage(client *dockerClient.Client, image string, update bool) error

func PullImages

func PullImages(client *dockerClient.Client, images []string, update bool) error

func ReadContainerLogs

func ReadContainerLogs(
	ctx context.Context,
	client *dockerClient.Client,
	id string,
	options dockerTypes.ContainerLogsOptions,
	callback func(uint8, []byte),
) error

func RunWaitGroup

func RunWaitGroup(n int, callback func(int) error) error

func TraverseContainers

func TraverseContainers(
	ctx context.Context, client *dockerClient.Client, callback func(dockerTypes.Container,
	) (bool, error)) error

Types

type Action

type Action interface {
	Name() string
	Run(context.Context) error
}

type Condition

type Condition struct {
	*logging.Logging
	// contains filtered or unexported fields
}

func NewCondition

func NewCondition(ctx context.Context, q, storageURI, col string) (*Condition, error)

func (*Condition) Check

func (co *Condition) Check(
	ctx context.Context, vars *config.Vars, getStorage func(string) (*Mongodb, error),
) (interface{}, bool, error)

func (*Condition) Query

func (co *Condition) Query(vars *config.Vars) (bson.M, error)

func (*Condition) QueryString

func (co *Condition) QueryString() string

type ContestLogEntry

type ContestLogEntry struct {
	// contains filtered or unexported fields
}

func NewContestLogEntry

func NewContestLogEntry(msg []byte, isError bool) ContestLogEntry

func (ContestLogEntry) IsError

func (ls ContestLogEntry) IsError() bool

func (ContestLogEntry) Map

func (ls ContestLogEntry) Map() (map[string]interface{}, error)

func (ContestLogEntry) Msg

func (ls ContestLogEntry) Msg() []byte

func (ContestLogEntry) Write

func (ls ContestLogEntry) Write(w io.Writer) error

type Host

type Host interface {
	Host() string
	DockerClient() *dockerClient.Client
	BaseDir() string
	Connect() error
	Close(context.Context) error
	Clean(context.Context, bool, bool) error
	Prepare(string, *config.Vars) (map[string]interface{}, error)
	AvailablePort(string, string) (string, error)
	Nodes() map[string]*Node
	MongodbContainerID() string
	MongodbURI() string
	ShellExec(context.Context, string, []string) (io.ReadCloser, io.ReadCloser, error)
}

type Hosts

type Hosts struct {
	sync.RWMutex
	*logging.Logging
	// contains filtered or unexported fields
}

func NewHosts

func NewHosts(lo *LogSaver) *Hosts

func (*Hosts) AddHost

func (hs *Hosts) AddHost(h Host) error

func (*Hosts) Close

func (hs *Hosts) Close() error

func (*Hosts) LenHosts

func (hs *Hosts) LenHosts() int

func (*Hosts) LenNodes

func (hs *Hosts) LenNodes() int

func (*Hosts) NodeExists

func (hs *Hosts) NodeExists(alias string) bool

func (*Hosts) TraverseHosts

func (hs *Hosts) TraverseHosts(callback func(h Host) (bool, error)) error

func (*Hosts) TraverseNodes

func (hs *Hosts) TraverseNodes(callback func(node *Node) (bool, error)) error

type LocalHost

type LocalHost struct {
	sync.RWMutex
	*logging.Logging
	// contains filtered or unexported fields
}

func NewLocalHost

func NewLocalHost(
	design config.DesignHost,
	vars *config.Vars,
	nodeDesigns map[string]string,
	runner,
	baseDir string,
) *LocalHost

func (*LocalHost) AvailablePort

func (ho *LocalHost) AvailablePort(_, network string) (string, error)

func (*LocalHost) BaseDir

func (ho *LocalHost) BaseDir() string

func (*LocalHost) Clean

func (ho *LocalHost) Clean(ctx context.Context, dryrun, force bool) error

Clean cleans the stopped containers. If the containers are still running, returns error.

func (*LocalHost) Close

func (ho *LocalHost) Close(ctx context.Context) error

func (*LocalHost) Connect

func (ho *LocalHost) Connect() error

func (*LocalHost) DockerClient

func (ho *LocalHost) DockerClient() *dockerClient.Client

func (*LocalHost) Host

func (ho *LocalHost) Host() string

func (*LocalHost) MongodbContainerID

func (ho *LocalHost) MongodbContainerID() string

func (*LocalHost) MongodbURI

func (ho *LocalHost) MongodbURI() string

func (*LocalHost) Nodes

func (ho *LocalHost) Nodes() map[string]*Node

func (*LocalHost) Prepare

func (ho *LocalHost) Prepare(common string, vars *config.Vars) (map[string]interface{}, error)

func (*LocalHost) ShellExec

func (*LocalHost) ShellExec(ctx context.Context, name string, args []string) (io.ReadCloser, io.ReadCloser, error)

type LogEntry

type LogEntry interface {
	Msg() []byte
	IsError() bool
	Write(io.Writer) error
	Map() (map[string]interface{}, error)
}

type LogEntryBSON

type LogEntryBSON struct {
	// contains filtered or unexported fields
}

func NewLogEntryBSON

func NewLogEntryBSON(l LogEntry) LogEntryBSON

func (LogEntryBSON) MarshalBSON

func (lo LogEntryBSON) MarshalBSON() ([]byte, error)

type LogSaver

type LogSaver struct {
	*logging.Logging
	*util.ContextDaemon
	// contains filtered or unexported fields
}

func NewLogSaver

func NewLogSaver(
	mg *Mongodb,
	logDir string,
	nodes []string,
	exitChan chan error,
	exitOnError bool,
) (*LogSaver, error)

func (*LogSaver) LogEntryChan

func (ls *LogSaver) LogEntryChan() chan<- LogEntry

func (*LogSaver) Stop

func (ls *LogSaver) Stop() error

type LogWatcher

type LogWatcher struct {
	sync.RWMutex

	*logging.Logging
	*util.ContextDaemon
	// contains filtered or unexported fields
}

func NewLogWatcher

func NewLogWatcher(mg *Mongodb, sqs []*Sequence, exitChan chan error, vars *config.Vars) (*LogWatcher, error)

func (*LogWatcher) Current

func (lw *LogWatcher) Current() (*Sequence, bool)

func (*LogWatcher) Stop

func (lw *LogWatcher) Stop() error

type Mongodb

type Mongodb struct {
	// contains filtered or unexported fields
}

func NewMongodb

func NewMongodb(cs connstring.ConnString) *Mongodb

func NewMongodbFromString

func NewMongodbFromString(uri string) (*Mongodb, error)

func (*Mongodb) AddLogEntries

func (mg *Mongodb) AddLogEntries(ctx context.Context, entries []LogEntry) error

func (*Mongodb) Close

func (mg *Mongodb) Close(ctx context.Context) error

func (*Mongodb) Connect

func (mg *Mongodb) Connect(ctx context.Context) error

func (*Mongodb) Find

func (mg *Mongodb) Find(ctx context.Context, col string, query bson.M) (map[string]interface{}, bool, error)

func (*Mongodb) Initialize

func (mg *Mongodb) Initialize(ctx context.Context) error

type Node

type Node struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewNode

func NewNode(alias string, host Host) (*Node, error)

func (*Node) Alias

func (no *Node) Alias() string

func (*Node) ConfigData

func (no *Node) ConfigData() []byte

func (*Node) ConfigFile

func (no *Node) ConfigFile() string

func (*Node) ConfigMap

func (no *Node) ConfigMap() map[string]interface{}

func (*Node) Host

func (no *Node) Host() Host

func (*Node) LogFile

func (no *Node) LogFile() string

func (*Node) PortMap

func (no *Node) PortMap() nat.PortMap

func (*Node) Prepare

func (no *Node) Prepare(commonDesign, design string, vars *config.Vars) (map[string]interface{}, error)

type NodeExistedMsg

type NodeExistedMsg struct {
	StatusCode int64  `json:"status_code"`
	Msg        string `json:"m"`
	Err        error  `json:"error"`
}

func (NodeExistedMsg) MarshalJSON

func (msg NodeExistedMsg) MarshalJSON() ([]byte, error)

type NodeLogEntry

type NodeLogEntry struct {
	// contains filtered or unexported fields
}

func NewNodeLogEntry

func NewNodeLogEntry(node string, msg []byte, isError bool) (NodeLogEntry, error)

func NewNodeLogEntryWithInterface

func NewNodeLogEntryWithInterface(node string, i interface{}, isError bool) (NodeLogEntry, error)

func (NodeLogEntry) IsError

func (ls NodeLogEntry) IsError() bool

func (NodeLogEntry) Map

func (ls NodeLogEntry) Map() (map[string]interface{}, error)

func (NodeLogEntry) Msg

func (ls NodeLogEntry) Msg() []byte

func (NodeLogEntry) Node

func (ls NodeLogEntry) Node() string

func (NodeLogEntry) Write

func (ls NodeLogEntry) Write(w io.Writer) error

type NodeStderrError

type NodeStderrError struct {
	Err  []byte
	Node string
}

func NewNodeStderrError

func NewNodeStderrError(node string, b []byte) NodeStderrError

func (NodeStderrError) Error

func (e NodeStderrError) Error() string

func (NodeStderrError) String

func (e NodeStderrError) String() string

type NullAction

type NullAction struct{}

func (NullAction) Name

func (NullAction) Name() string

func (NullAction) Run

type Sequence

type Sequence struct {
	// contains filtered or unexported fields
}

func NewSequence

func NewSequence(condition *Condition, action Action, register config.DesignRegister) (*Sequence, error)

func (*Sequence) Action

func (sq *Sequence) Action() Action

func (*Sequence) Condition

func (sq *Sequence) Condition() *Condition

func (*Sequence) Register

func (sq *Sequence) Register() config.DesignRegister

func (*Sequence) SetRegister

func (sq *Sequence) SetRegister(vars *config.Vars, record interface{})

Jump to

Keyboard shortcuts

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