server

package
v1.9.6 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: MIT Imports: 49 Imported by: 0

Documentation

Index

Constants

View Source
const EnableTLS = false
View Source
const Insecure = true
View Source
const SkipTLSVerify = false

Variables

This section is empty.

Functions

func GenerateDiamondtWorkflowSpec added in v1.9.0

func GenerateDiamondtWorkflowSpec(colonyName string) *core.WorkflowSpec

func GenerateSingleWorkflowSpec added in v1.9.0

func GenerateSingleWorkflowSpec(colonyName string) *core.WorkflowSpec

func GenerateTreeWorkflowSpec added in v1.9.0

func GenerateTreeWorkflowSpec(colonyName string) *core.WorkflowSpec

func SetupTestEnv1 added in v1.9.0

func SetupTestEnv1(t *testing.T) (*TestEnv1, *client.ColoniesClient, *Server, string, chan bool)

func SetupTestEnv2 added in v1.9.0

func SetupTestEnv2(t *testing.T) (*TestEnv2, *client.ColoniesClient, *Server, string, chan bool)

func WaitForCluster

func WaitForCluster(t *testing.T, cluster []ServerInfo)

func WaitForProcessGraphs

func WaitForProcessGraphs(t *testing.T, c *client.ColoniesClient, colonyName string, generatorID string, executorPrvKey string, threshold int) int

func WaitForProcesses added in v1.9.0

func WaitForProcesses(t *testing.T, server *Server, processes []*core.Process, state int)

func WaitForServerToDie

func WaitForServerToDie(t *testing.T, s ServerInfo)

Types

type BackendFactory added in v1.9.0

type BackendFactory interface {
	CreateServer(config *ServerConfig, sharedResources *SharedResources) (ManagedServer, error)
	GetBackendType() BackendType
}

BackendFactory creates backend-specific servers

type BackendType added in v1.9.0

type BackendType string

BackendType represents different server backend types

const (
	GinBackendType BackendType = "gin"
)

type GenericServer added in v1.9.0

type GenericServer interface {
	// HTTP Response methods
	HandleHTTPError(c backends.Context, err error, errorCode int) bool
	SendHTTPReply(c backends.Context, payloadType string, jsonString string)
	SendEmptyHTTPReply(c backends.Context, payloadType string)

	// Server identity
	GetServerID() (string, error)

	// Security and validation
	Validator() security.Validator

	// Database access
	UserDB() database.UserDatabase
	ExecutorDB() database.ExecutorDatabase
	ColonyDB() database.ColonyDatabase
	SecurityDB() database.SecurityDatabase
	ProcessDB() database.ProcessDatabase
	ProcessGraphDB() database.ProcessGraphDatabase
	AttributeDB() database.AttributeDatabase
	FileDB() database.FileDatabase
	LogDB() database.LogDatabase
	FunctionDB() database.FunctionDatabase
	GeneratorDB() database.GeneratorDatabase
	CronDB() database.CronDatabase
	SnapshotDB() database.SnapshotDatabase
	BlueprintDB() database.BlueprintDatabase

	// Controllers
	ColonyController() controllers.ColoniesController
	ProcessController() interface {
		AddProcess(process *core.Process) (*core.Process, error)
		GetProcess(processID string) (*core.Process, error)
		GetProcesses(colonyName string, count int, state int) ([]*core.Process, error)
		FindProcesses(colonyName string, processType string, label string, initiatorID string, count int, state int) ([]*core.Process, error)
		GetProcessesByExecutorID(executorID string, count int, state int) ([]*core.Process, error)
		GetProcessesByProcessGraphID(processGraphID string, count int, state int) ([]*core.Process, error)
		RemoveProcess(processID string, state int) error
		RemoveAllProcesses(colonyName string, state int) error
		RemoveAllProcessesInProcessGraphs(colonyName string, state int) error
		RemoveAllProcessesInProcessGraphsByID(processGraphID string, state int) error
		SetProcessState(processID string, state int) error
		AssignProcess(colonyName string, executorID string) (*core.Process, error)
		UnassignProcess(processID string) (*core.Process, error)
		MarkSuccessful(processID string) (*core.Process, error)
		MarkFailed(processID string, errorMsg string) (*core.Process, error)
		CloseSuccessful(processID string, output []interface{}) (*core.Process, error)
		CloseFailed(processID string, errorMsg string) (*core.Process, error)
		SetOutput(processID string, output []interface{}) (*core.Process, error)
	}
	ExecutorController() interface {
		AddExecutor(executor *core.Executor) (*core.Executor, error)
		GetExecutor(executorID string) (*core.Executor, error)
		GetExecutorByName(colonyName string, executorName string) (*core.Executor, error)
		GetExecutors(colonyName string) ([]*core.Executor, error)
		GetExecutorsWithState(colonyName string, state int) ([]*core.Executor, error)
		RemoveExecutor(executorID string) error
		ApproveExecutor(executorID string) error
		RejectExecutor(executorID string) error
		ReportAllocation(executorID string, available bool, executorType string, nodes int, cpu string, memory string, storage string, gpu string, gpuCount int) error
	}
	GeneratorController() interface {
		AddGenerator(generator *core.Generator) (*core.Generator, error)
		GetGenerator(generatorID string) (*core.Generator, error)
		ResolveGenerator(colonyName string, generatorName string) (*core.Generator, error)
		GetGenerators(colonyName string, count int) ([]*core.Generator, error)
		PackGenerator(generatorID string, colonyName string, arg string) error
		RemoveGenerator(generatorID string) error
		GetGeneratorPeriod() int
	}
	CronController() interface {
		AddCron(cron *core.Cron) (*core.Cron, error)
		GetCron(cronID string) (*core.Cron, error)
		GetCrons(colonyName string, count int) ([]*core.Cron, error)
		GetCronByName(colonyName string, cronName string) (*core.Cron, error)
		RunCron(cronID string) (*core.Cron, error)
		RemoveCron(cronID string) error
		GetCronPeriod() int
	}
}

GenericServer defines the interface that handlers can use to interact with the server This interface abstracts away the HTTP backend implementation

type GinBackendFactory added in v1.9.0

type GinBackendFactory struct{}

GinBackendFactory creates gin managed servers

func NewGinBackendFactory added in v1.9.0

func NewGinBackendFactory() *GinBackendFactory

NewGinBackendFactory creates a new gin backend factory

func (*GinBackendFactory) CreateServer added in v1.9.0

func (gbf *GinBackendFactory) CreateServer(config *ServerConfig, sharedResources *SharedResources) (ManagedServer, error)

CreateServer creates a new gin managed server

func (*GinBackendFactory) GetBackendType added in v1.9.0

func (gbf *GinBackendFactory) GetBackendType() BackendType

GetBackendType returns the backend type this factory creates

type GinManagedServer added in v1.9.0

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

GinManagedServer wraps the existing Server to make it compatible with ServerManager

func NewGinManagedServer added in v1.9.0

func NewGinManagedServer(config *ServerConfig, sharedResources *SharedResources) (*GinManagedServer, error)

NewGinManagedServer creates a new gin managed server

func (*GinManagedServer) GetAddr added in v1.9.0

func (gms *GinManagedServer) GetAddr() string

GetAddr returns the server address

func (*GinManagedServer) GetBackendType added in v1.9.0

func (gms *GinManagedServer) GetBackendType() BackendType

GetBackendType returns the backend type

func (*GinManagedServer) GetPort added in v1.9.0

func (gms *GinManagedServer) GetPort() int

GetPort returns the server port

func (*GinManagedServer) GetServer added in v1.9.0

func (gms *GinManagedServer) GetServer() *Server

GetServer returns the underlying server (for compatibility)

func (*GinManagedServer) HealthCheck added in v1.9.0

func (gms *GinManagedServer) HealthCheck() error

HealthCheck performs a health check on the server

func (*GinManagedServer) IsRunning added in v1.9.0

func (gms *GinManagedServer) IsRunning() bool

IsRunning returns whether the server is running

func (*GinManagedServer) Start added in v1.9.0

func (gms *GinManagedServer) Start() error

Start starts the gin server

func (*GinManagedServer) Stop added in v1.9.0

func (gms *GinManagedServer) Stop(ctx context.Context) error

Stop stops the gin server gracefully

type HTTPBackendFactory added in v1.9.0

type HTTPBackendFactory struct{}

HTTPBackendFactory creates HTTP managed servers

func NewHTTPBackendFactory added in v1.9.0

func NewHTTPBackendFactory() *HTTPBackendFactory

NewHTTPBackendFactory creates a new HTTP backend factory

func (*HTTPBackendFactory) CreateServer added in v1.9.0

func (hbf *HTTPBackendFactory) CreateServer(config *ServerConfig, sharedResources *SharedResources) (ManagedServer, error)

CreateServer creates a new HTTP managed server

func (*HTTPBackendFactory) GetBackendType added in v1.9.0

func (hbf *HTTPBackendFactory) GetBackendType() BackendType

GetBackendType returns the backend type this factory creates

type HTTPManagedServer added in v1.9.0

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

HTTPManagedServer wraps the existing Server to make it compatible with ServerManager

func NewHTTPManagedServer added in v1.9.0

func NewHTTPManagedServer(config *ServerConfig, sharedResources *SharedResources) (*HTTPManagedServer, error)

NewHTTPManagedServer creates a new HTTP managed server

func (*HTTPManagedServer) GetAddr added in v1.9.0

func (hms *HTTPManagedServer) GetAddr() string

GetAddr returns the server address

func (*HTTPManagedServer) GetBackendType added in v1.9.0

func (hms *HTTPManagedServer) GetBackendType() BackendType

GetBackendType returns the backend type

func (*HTTPManagedServer) GetPort added in v1.9.0

func (hms *HTTPManagedServer) GetPort() int

GetPort returns the server port

func (*HTTPManagedServer) GetServer added in v1.9.0

func (hms *HTTPManagedServer) GetServer() *Server

GetServer returns the underlying server (for compatibility)

func (*HTTPManagedServer) HealthCheck added in v1.9.0

func (hms *HTTPManagedServer) HealthCheck() error

HealthCheck performs a health check on the server

func (*HTTPManagedServer) IsRunning added in v1.9.0

func (hms *HTTPManagedServer) IsRunning() bool

IsRunning returns whether the server is running

func (*HTTPManagedServer) Start added in v1.9.0

func (hms *HTTPManagedServer) Start() error

Start starts the HTTP server

func (*HTTPManagedServer) Stop added in v1.9.0

func (hms *HTTPManagedServer) Stop(ctx context.Context) error

Stop stops the HTTP server gracefully

type ManagedServer added in v1.9.0

type ManagedServer interface {
	// Lifecycle management
	Start() error
	Stop(ctx context.Context) error

	// Server info
	GetBackendType() BackendType
	GetPort() int
	GetAddr() string
	IsRunning() bool

	// Health checks
	HealthCheck() error
}

ManagedServer represents a server instance managed by ServerManager

type Server added in v1.9.0

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

func CreateServer added in v1.9.0

func CreateServer(db database.Database,
	port int,
	tls bool,
	tlsPrivateKeyPath string,
	tlsCertPath string,
	thisNode cluster.Node,
	clusterConfig cluster.Config,
	etcdDataPath string,
	generatorPeriod int,
	cronPeriod int,
	exclusiveAssign bool,
	allowExecutorReregister bool,
	retention bool,
	retentionPolicy int64,
	retentionPeriod int) *Server

func PrepareTests added in v1.5.0

func PrepareTests(t *testing.T) (*client.ColoniesClient, *Server, string, chan bool)

func (*Server) FileDB added in v1.9.0

func (server *Server) FileDB() database.FileDatabase

func (*Server) HandleHTTPError added in v1.9.0

func (server *Server) HandleHTTPError(c backends.Context, err error, errorCode int) bool

func (*Server) SendEmptyHTTPReply added in v1.9.0

func (server *Server) SendEmptyHTTPReply(c backends.Context, payloadType string)

func (*Server) SendHTTPReply added in v1.9.0

func (server *Server) SendHTTPReply(c backends.Context, payloadType string, jsonString string)

func (*Server) ServeForever added in v1.9.0

func (server *Server) ServeForever() error

func (*Server) SetAllowExecutorReregister added in v1.9.0

func (server *Server) SetAllowExecutorReregister(allow bool)

func (*Server) Shutdown added in v1.9.0

func (server *Server) Shutdown()

func (*Server) WSController added in v1.9.0

func (server *Server) WSController() WSController

WSController returns the WebSocket controller for realtime subscriptions

type ServerAdapter added in v1.9.0

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

ServerAdapter implements interfaces needed by handler packages

func NewServerAdapter added in v1.9.0

func NewServerAdapter(server *Server) *ServerAdapter

func (*ServerAdapter) AllowExecutorReregister added in v1.9.0

func (s *ServerAdapter) AllowExecutorReregister() bool

func (*ServerAdapter) AttributeController added in v1.9.0

func (s *ServerAdapter) AttributeController() attributehandlers.Controller

func (*ServerAdapter) BlueprintDB added in v1.9.3

func (s *ServerAdapter) BlueprintDB() database.BlueprintDatabase

func (*ServerAdapter) ChannelRouter added in v1.9.6

func (s *ServerAdapter) ChannelRouter() *channel.Router

ChannelRouter returns the channel router for channel operations

func (*ServerAdapter) ColonyDB added in v1.9.0

func (s *ServerAdapter) ColonyDB() database.ColonyDatabase

func (*ServerAdapter) Controller added in v1.9.0

func (s *ServerAdapter) Controller() colony.Controller

func (*ServerAdapter) CronController added in v1.9.0

func (s *ServerAdapter) CronController() interface {
	AddCron(cron *core.Cron) (*core.Cron, error)
	GetCron(cronID string) (*core.Cron, error)
	GetCrons(colonyName string, count int) ([]*core.Cron, error)
	GetCronByName(colonyName string, cronName string) (*core.Cron, error)
	RunCron(cronID string) (*core.Cron, error)
	RemoveCron(cronID string) error
	GetCronPeriod() int
}

CronController returns the server's controller interface for cron operations

func (*ServerAdapter) ExclusiveAssign added in v1.9.0

func (s *ServerAdapter) ExclusiveAssign() bool

func (*ServerAdapter) ExecutorController added in v1.9.0

func (s *ServerAdapter) ExecutorController() executor.Controller

func (*ServerAdapter) ExecutorDB added in v1.9.0

func (s *ServerAdapter) ExecutorDB() database.ExecutorDatabase

Executor handler interface methods

func (*ServerAdapter) FileDB added in v1.9.0

func (s *ServerAdapter) FileDB() database.FileDatabase

func (*ServerAdapter) FunctionController added in v1.9.0

func (s *ServerAdapter) FunctionController() functionhandlers.Controller

func (*ServerAdapter) FunctionDB added in v1.9.0

func (s *ServerAdapter) FunctionDB() database.FunctionDatabase

func (*ServerAdapter) GenerateRPCErrorMsg added in v1.9.0

func (s *ServerAdapter) GenerateRPCErrorMsg(err error, errorCode int) (*rpc.RPCReplyMsg, error)

func (*ServerAdapter) GeneratorController added in v1.9.0

func (s *ServerAdapter) GeneratorController() generatorhandlers.Controller

func (*ServerAdapter) GeneratorDB added in v1.9.0

func (s *ServerAdapter) GeneratorDB() database.GeneratorDatabase

func (*ServerAdapter) GetColonyDB added in v1.9.0

func (s *ServerAdapter) GetColonyDB() database.ColonyDatabase

func (*ServerAdapter) GetController added in v1.9.0

func (s *ServerAdapter) GetController() interface {
	AddColony(colony *core.Colony) (*core.Colony, error)
	RemoveColony(colonyName string) error
	GetColonies() ([]*core.Colony, error)
	GetColony(colonyName string) (*core.Colony, error)
	GetColonyStatistics(colonyName string) (*core.Statistics, error)
}

Controller access for handlers

func (*ServerAdapter) GetLocationDB added in v1.9.6

func (s *ServerAdapter) GetLocationDB() database.LocationDatabase

func (*ServerAdapter) GetSecurityDB added in v1.9.0

func (s *ServerAdapter) GetSecurityDB() database.SecurityDatabase

func (*ServerAdapter) GetServerID added in v1.9.0

func (s *ServerAdapter) GetServerID() (string, error)

func (*ServerAdapter) GetUserDB added in v1.9.0

func (s *ServerAdapter) GetUserDB() database.UserDatabase

User handler interface methods

func (*ServerAdapter) GetValidator added in v1.9.0

func (s *ServerAdapter) GetValidator() security.Validator

func (*ServerAdapter) HandleHTTPError added in v1.9.0

func (s *ServerAdapter) HandleHTTPError(c backends.Context, err error, errorCode int) bool

func (*ServerAdapter) LocationDB added in v1.9.6

func (s *ServerAdapter) LocationDB() database.LocationDatabase

func (*ServerAdapter) LogDB added in v1.9.0

func (s *ServerAdapter) LogDB() database.LogDatabase

func (*ServerAdapter) LogProcessController added in v1.9.0

func (s *ServerAdapter) LogProcessController() loghandlers.Controller

func (*ServerAdapter) ParseSignature added in v1.9.0

func (s *ServerAdapter) ParseSignature(payload string, signature string) (string, error)

func (*ServerAdapter) ProcessController added in v1.9.0

func (s *ServerAdapter) ProcessController() process.Controller

func (*ServerAdapter) ProcessDB added in v1.9.0

func (s *ServerAdapter) ProcessDB() database.ProcessDatabase

Process handler interface methods

func (*ServerAdapter) ProcessgraphController added in v1.9.0

func (s *ServerAdapter) ProcessgraphController() processgraph.Controller

func (*ServerAdapter) ProcessgraphServer added in v1.9.0

func (s *ServerAdapter) ProcessgraphServer() processgraph.Server

func (*ServerAdapter) ProcessgraphValidator added in v1.9.0

func (s *ServerAdapter) ProcessgraphValidator() processgraph.Validator

func (*ServerAdapter) RealtimeHandler added in v1.9.0

func (s *ServerAdapter) RealtimeHandler() realtimehandlers.RealtimeHandler

func (*ServerAdapter) SecurityDB added in v1.9.0

func (s *ServerAdapter) SecurityDB() database.SecurityDatabase

func (*ServerAdapter) SendEmptyHTTPReply added in v1.9.0

func (s *ServerAdapter) SendEmptyHTTPReply(c backends.Context, payloadType string)

func (*ServerAdapter) SendHTTPReply added in v1.9.0

func (s *ServerAdapter) SendHTTPReply(c backends.Context, payloadType string, jsonString string)

func (*ServerAdapter) ServerController added in v1.9.0

func (s *ServerAdapter) ServerController() serverhandlers.Controller

func (*ServerAdapter) ServerServer added in v1.9.0

func (s *ServerAdapter) ServerServer() serverhandlers.Server

func (*ServerAdapter) ServerValidator added in v1.9.0

func (s *ServerAdapter) ServerValidator() serverhandlers.Validator

func (*ServerAdapter) SetAllowExecutorReregister added in v1.9.0

func (s *ServerAdapter) SetAllowExecutorReregister(allow bool)

func (*ServerAdapter) SnapshotDB added in v1.9.0

func (s *ServerAdapter) SnapshotDB() database.SnapshotDatabase

func (*ServerAdapter) TLS added in v1.9.0

func (s *ServerAdapter) TLS() bool

func (*ServerAdapter) TriggerReconciliationForReconciler added in v1.9.6

func (s *ServerAdapter) TriggerReconciliationForReconciler(colonyName, executorType, locationName string) error

TriggerReconciliationForReconciler submits reconcile processes for all blueprints that match the given reconciler's executor type and location. This is called when a new reconciler registers to immediately reconcile any pending blueprints.

func (*ServerAdapter) UserDB added in v1.9.0

func (s *ServerAdapter) UserDB() database.UserDatabase

func (*ServerAdapter) Validator added in v1.9.0

func (s *ServerAdapter) Validator() security.Validator

func (*ServerAdapter) WSController added in v1.9.0

func (s *ServerAdapter) WSController() gin.WSController

func (*ServerAdapter) WSControllerCompat added in v1.9.0

func (s *ServerAdapter) WSControllerCompat() WSController

type ServerConfig added in v1.9.0

type ServerConfig struct {
	BackendType             BackendType
	Port                    int
	TLS                     bool
	TLSPrivateKeyPath       string
	TLSCertPath             string
	ExclusiveAssign         bool
	AllowExecutorReregister bool
	Retention               bool
	RetentionPolicy         int64
	RetentionPeriod         int
	Enabled                 bool
}

ServerConfig holds configuration for a managed server

type ServerInfo

type ServerInfo struct {
	ServerID     string
	ServerPrvKey string
	Server       *Server
	Node         cluster.Node
	Done         chan struct{}
}

func StartCluster

func StartCluster(t *testing.T, db database.Database, size int) []ServerInfo

func StartClusterDistributed added in v1.9.6

func StartClusterDistributed(t *testing.T, db database.Database, size int) []ServerInfo

StartClusterDistributed creates a cluster with ExclusiveAssign=false for testing distributed assignment

type ServerManager added in v1.9.0

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

ServerManager manages multiple server backends

func NewServerManager added in v1.9.0

func NewServerManager(
	db database.Database,
	thisNode cluster.Node,
	clusterConfig cluster.Config,
	etcdDataPath string,
	generatorPeriod int,
	cronPeriod int,
) *ServerManager

NewServerManager creates a new ServerManager

func (*ServerManager) AddServerConfig added in v1.9.0

func (sm *ServerManager) AddServerConfig(config *ServerConfig) error

AddServerConfig adds configuration for a server backend

func (*ServerManager) GetRunningServers added in v1.9.0

func (sm *ServerManager) GetRunningServers() map[BackendType]ManagedServer

GetRunningServers returns all currently running servers

func (*ServerManager) GetServer added in v1.9.0

func (sm *ServerManager) GetServer(backendType BackendType) (ManagedServer, bool)

GetServer returns a managed server by backend type

func (*ServerManager) GetStatus added in v1.9.0

func (sm *ServerManager) GetStatus() map[BackendType]ServerStatus

GetStatus returns status information about all servers

func (*ServerManager) IsRunning added in v1.9.0

func (sm *ServerManager) IsRunning() bool

IsRunning returns whether the server manager is running

func (*ServerManager) RegisterBackendFactory added in v1.9.0

func (sm *ServerManager) RegisterBackendFactory(factory BackendFactory) error

RegisterBackendFactory registers a factory for creating backend servers

func (*ServerManager) StartAll added in v1.9.0

func (sm *ServerManager) StartAll() error

StartAll starts all configured and enabled servers

func (*ServerManager) StopAll added in v1.9.0

func (sm *ServerManager) StopAll(timeout time.Duration) error

StopAll stops all running servers gracefully

type ServerStatus added in v1.9.0

type ServerStatus struct {
	BackendType BackendType
	Running     bool
	Port        int
	Addr        string
	HealthError error
}

ServerStatus represents the status of a managed server

type SharedResources added in v1.9.0

type SharedResources struct {
	DB              database.Database
	ThisNode        cluster.Node
	ClusterConfig   cluster.Config
	EtcdDataPath    string
	GeneratorPeriod int
	CronPeriod      int
	Controller      controllers.Controller // Shared controller to avoid etcd port conflicts
	BaseServer      *Server                // Shared base server for handler registration
}

SharedResources contains blueprints shared between all server backends

type TestEnv1 added in v1.9.0

type TestEnv1 struct {
	Colony1PrvKey   string
	Colony1Name     string
	Colony1ID       string
	Colony2PrvKey   string
	Colony2Name     string
	Colony2ID       string
	Executor1PrvKey string
	Executor1Name   string
	Executor1ID     string
	Executor2PrvKey string
	Executor2Name   string
	Executor2ID     string
}

type TestEnv2 added in v1.9.0

type TestEnv2 struct {
	ColonyID       string
	ColonyName     string
	Colony         *core.Colony
	ColonyPrvKey   string
	ExecutorName   string
	ExecutorID     string
	Executor       *core.Executor
	ExecutorPrvKey string
}

type WSController added in v1.9.0

type WSController interface {
	SubscribeProcesses(executorID string, subscription *backends.RealtimeSubscription) error
	SubscribeProcess(executorID string, subscription *backends.RealtimeSubscription) error
}

WSController interface for WebSocket subscription management

Jump to

Keyboard shortcuts

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