control

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: GPL-3.0 Imports: 51 Imported by: 0

Documentation

Overview

Package control provides a set of Services (in the Supervisor terminology) that are started by the main sync process.

Index

Constants

View Source
const (
	TopicGlobal  = "cmd"
	TopicSyncAll = "sync"
	TopicSync_   = "sync-"
	TopicState   = "state"
	TopicStore_  = "store"
	TopicUpdate  = "update"
)
View Source
const (
	MessageHalt = iota
	MessageRestart
	MessageInterrupt
	MessagePause
	MessageResume
	MessageEnable
	MessageDisable
	MessageSyncLoop
	MessageResync
	MessageResyncDry
	MessagePublishState
	MessagePublishStore
	MessageRestartClean // Restart an clean snapshots
	MessageHaltClean    // Halt task and remove all configs
)

Variables

This section is empty.

Functions

func GetBus

func GetBus() *pubsub.PubSub

GetBus returns the global Bus

func MessageFromString

func MessageFromString(text string) (int, error)

MessageFromString converts string to MessageXXX integers

Types

type CommandMessage

type CommandMessage int

type FileStateStore added in v0.8.0

type FileStateStore struct {
	MemoryStateStore
	PreviousState model.TaskStatus
	FileError     error
	// contains filtered or unexported fields
}

FileStateStore extends MemoryStore by storing the Status inside a file that stays open. It is used at restart to check if the last processing state was Idle, otherwise something may have been stopped in the middle and we trigger a full resync.

func NewFileStateStore added in v0.8.0

func NewFileStateStore(config *config.Task, folderPath string) *FileStateStore

NewFileStateStore creates a FileStateStore with the state file in the target folder.

func (*FileStateStore) Close added in v0.8.0

func (f *FileStateStore) Close()

Close closes the state file

func (*FileStateStore) UpdateProcessStatus added in v0.8.0

func (f *FileStateStore) UpdateProcessStatus(processStatus model.Status, status ...model.TaskStatus) common.SyncState

UpdateProcessStatus stores the status in the state file

func (*FileStateStore) UpdateSyncStatus added in v0.8.0

func (f *FileStateStore) UpdateSyncStatus(s model.TaskStatus) common.SyncState

UpdateSyncStatus stores the status in the state file

type HttpServer

type HttpServer struct {
	WebSocket *melody.Melody
	LogSocket *melody.Melody
	// contains filtered or unexported fields
}

func NewHttpServer

func NewHttpServer() *HttpServer

NewHttpServer creates a supervisor service for spinning the http server.

func (*HttpServer) InitHandlers

func (h *HttpServer) InitHandlers()

InitHandlers initialize WebSocket handlers.

func (*HttpServer) ListenAuthorities added in v0.8.0

func (h *HttpServer) ListenAuthorities()

ListenAuthorities listens to a config watcher for transmitting Authority changes. It should be called as a goroutine.

func (*HttpServer) ListenStatus

func (h *HttpServer) ListenStatus()

ListenStatus is hooked to the general Bus to listen for SyncStates and UpdateMessages. It should be called as a goroutine

func (*HttpServer) Serve

func (h *HttpServer) Serve()

Serve implements supervisor service interface. It basically starts the http server.

func (*HttpServer) Stop

func (h *HttpServer) Stop()

Stop implements supervisor service interface.

func (*HttpServer) Sync

func (h *HttpServer) Sync() error

Sync implements the io.Writer method.

func (*HttpServer) Write

func (h *HttpServer) Write(p []byte) (n int, err error)

Write implements the io.Writer method (used by logs).

type MemoryStateStore

type MemoryStateStore struct {
	sync.Mutex
	// contains filtered or unexported fields
}

MemoryStateStore keeps all SyncStates in memory.

func NewMemoryStateStore

func NewMemoryStateStore(config *config.Task) *MemoryStateStore

NewMemoryStateStore creates a MemoryStateStore.

func (*MemoryStateStore) BothConnected

func (b *MemoryStateStore) BothConnected() bool

BothConnected returns true if both Endpoints have a connected status.

func (*MemoryStateStore) Close added in v0.8.0

func (b *MemoryStateStore) Close()

Close closes the state store

func (*MemoryStateStore) LastState

func (b *MemoryStateStore) LastState() common.SyncState

LastState returns the last known state of the task.

func (*MemoryStateStore) TouchLastOpsTime

func (b *MemoryStateStore) TouchLastOpsTime(t ...time.Time)

TouchLastOps updates the time of last known operation.

func (*MemoryStateStore) UpdateConnection

func (b *MemoryStateStore) UpdateConnection(c bool, i model.EndpointInfo) common.SyncState

UpdateConnection updates the connection status of one endpoint.

func (*MemoryStateStore) UpdateEndpointStats

UpdateEndpointStats updates the statistics about the root of one endpoint.

func (*MemoryStateStore) UpdateProcessStatus

func (b *MemoryStateStore) UpdateProcessStatus(processStatus model.Status, status ...model.TaskStatus) common.SyncState

UpdateProcessStatus updates the status of one endpoint. It is recognized based on its EndpointURI.

func (*MemoryStateStore) UpdateSyncStatus

func (b *MemoryStateStore) UpdateSyncStatus(s model.TaskStatus) common.SyncState

UpdateSyncStatus updates the internal status.

func (*MemoryStateStore) UpdateWatcherActivity

func (b *MemoryStateStore) UpdateWatcherActivity(a bool, i model.EndpointInfo) common.SyncState

UpdateWatcherActivity updates the watcher status of one endpoint.

type PatchesRequest

type PatchesRequest struct {
	SyncUUID string `uri:"uuid" binding:"required"`
	Offset   int    `uri:"offset" binding:"numeric"`
	Limit    int    `uri:"limit"`
}

type PatchesResponse

type PatchesResponse struct {
	Patches []merger.Patch
}

type Profiler

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

Profiler is a supervisor service for serving internal golang pprof debugs on 6060

func (*Profiler) Serve

func (p *Profiler) Serve()

Serve implements supervisor service interface.

func (*Profiler) Stop

func (p *Profiler) Stop()

Stop implements supervisor service interface.

type Scheduler

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

Scheduler is a supervisor service emitting various commands on a timely manner.

func NewScheduler

func NewScheduler(tasks []*config.Task) *Scheduler

NewScheduler creates a scheduler and register the schedules from the tasks configs.

func (*Scheduler) Serve

func (s *Scheduler) Serve()

Serve implements supervisor service interface.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop implements supervisor service interface.

type SpawnedService added in v0.8.0

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

SpawnedService is a supervisor service for launching a command and automatically restarting if it fails.

func NewSpawnedService added in v0.8.0

func NewSpawnedService(name string, args []string) *SpawnedService

NewSpawnedService creates a SpawnedService

func (*SpawnedService) Serve added in v0.8.0

func (c *SpawnedService) Serve()

Serve implements supervisor service interface.

func (*SpawnedService) Stop added in v0.8.0

func (c *SpawnedService) Stop()

Stop implements supervisor service interface.

type StateStore

type StateStore interface {
	LastState() common.SyncState
	BothConnected() bool
	TouchLastOpsTime(t ...time.Time)
	Close()

	UpdateConnection(c bool, i model.EndpointInfo) common.SyncState
	UpdateWatcherActivity(a bool, i model.EndpointInfo) common.SyncState
	UpdateEndpointStats(s *model.EndpointRootStat, i model.EndpointInfo) common.SyncState

	UpdateSyncStatus(s model.TaskStatus) common.SyncState
	UpdateProcessStatus(processStatus model.Status, status ...model.TaskStatus) common.SyncState
}

StateStore is used to maintain the states of the sync tasks

type StdInner

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

StdInner is a supervisor service for scanning StdIn

func (*StdInner) Serve

func (s *StdInner) Serve()

Serve implements supervisor service interface.

func (*StdInner) Stop

func (s *StdInner) Stop()

Stop implements supervisor service interface.

type Supervisor

type Supervisor struct {
	sync.Mutex
	*suture.Supervisor
	// contains filtered or unexported fields
}

Supervisor is a service manager for starting syncs and other services and restarting them if necessary

func NewSupervisor

func NewSupervisor(noUi bool) *Supervisor

NewSupervisor creates a new Supervisor

func (*Supervisor) Serve

func (s *Supervisor) Serve() error

Serve starts all services and start listening to config and bus The call is blocking until all services are stopped

type Syncer

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

Syncer is a supervisor service wrapping a sync task.

func NewSyncer

func NewSyncer(conf *config.Task) (syncer *Syncer)

NewSyncer creates a new running sync task.

func (*Syncer) Serve

func (s *Syncer) Serve()

Serve implements supervisor interface.

func (*Syncer) Stop

func (s *Syncer) Stop()

Stop implements supervisor interface.

type TreeRequest

type TreeRequest struct {
	EndpointURI string
	Path        string
	// contains filtered or unexported fields
}

type TreeResponse

type TreeResponse struct {
	Node     *tree.Node
	Children []*tree.Node
}

TreeResponse is a fake protobuf used for marshaling responses to tree requests.

func (*TreeResponse) MarshalJSON

func (l *TreeResponse) MarshalJSON() ([]byte, error)

MarshalJSON manually marshal protobuf to JSON

type Updater

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

Updater is a supervisor service for checking for available updates

func NewUpdater

func NewUpdater() *Updater

NewUpdater creates a new Updater service

func (*Updater) ApplyUpdate

func (u *Updater) ApplyUpdate(ctx context.Context, p *update.Package, dryRun bool, busTopic string)

ApplyUpdate uses the info of an update.Package to download the binary and replace the current running binary. A restart is necessary afterward. The dryRun option will download the binary and just put it in the /tmp folder

func (*Updater) LoadUpdates

func (u *Updater) LoadUpdates(ctx context.Context, busTopic string) (packages []*update.Package, outErr error)

LoadUpdates will post a Json query to the update server to detect if there are any updates available

func (*Updater) Serve

func (u *Updater) Serve()

Serve implements supervisor interface.

func (*Updater) Stop

func (u *Updater) Stop()

Stop implements supervisor interface.

Jump to

Keyboard shortcuts

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