Documentation
¶
Index ¶
- func CreateLogFile(filePath string, perm os.FileMode) (*os.File, error)
- func ReadFileAt(filepath string, offset int64) ([]byte, int64, error)
- func RegisterLoadDriver(d LoadDriver) error
- func RegisterNodeDriver(d NodeDriver) error
- func SetDeploymentError(repository DeploymentsRepository, deployment Deployment, msg string, ...) error
- func TailFile(filepath string, w io.Writer) error
- func UnregisterLoadDriver(id LoadDriverID) error
- func UnregisterNodeDriver(id NodeDriverID) error
- func UpdateDeploymentMetadata[T any](repo DeploymentsRepository, deploymentID DeploymentID, ...) error
- type Capabilities
- type Deployment
- type DeploymentID
- type DeploymentStatus
- type DeploymentStatusCode
- type DeploymentsRepository
- type Hash
- type HashableLoadConfig
- type Load
- type LoadChain
- type LoadConfig
- type LoadDriver
- type LoadDriverConfig
- type LoadDriverID
- type LoadDriverInfo
- type Mode
- type NewNodeDriverInfoOpts
- type Node
- type NodeConfig
- type NodeDriver
- type NodeDriverBuilder
- type NodeDriverConfig
- type NodeDriverID
- type NodeDriverInfo
- type NodeEntry
- type NodeStatus
- type NodeStatusCode
- type NodesRepository
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateLogFile ¶
Create a file and all the missing directories
func RegisterLoadDriver ¶
func RegisterLoadDriver(d LoadDriver) error
func RegisterNodeDriver ¶
func RegisterNodeDriver(d NodeDriver) error
func SetDeploymentError ¶
func SetDeploymentError(repository DeploymentsRepository, deployment Deployment, msg string, args ...any) error
func UnregisterLoadDriver ¶
func UnregisterLoadDriver(id LoadDriverID) error
func UnregisterNodeDriver ¶
func UnregisterNodeDriver(id NodeDriverID) error
func UpdateDeploymentMetadata ¶ added in v0.1.2
func UpdateDeploymentMetadata[T any](repo DeploymentsRepository, deploymentID DeploymentID, updateFn func(metadata *T) error) error
UpdateDeploymentMetadata is a generic helper that provides type-safe metadata updates. It handles the JSON marshal/unmarshal internally so callers get a typed pointer.
Types ¶
type Capabilities ¶ added in v0.1.2
type Deployment ¶
type Deployment struct {
ID DeploymentID
LoadName string
LoadDriver LoadDriver
Status DeploymentStatus
Metadata any
}
A deployment is the object created when a load has been loaded in the cluster Notice it doesn't reference Load but contains an immutable copy because a deployment cannot be modified directly, it must be updated from the DeploymentsRepository
type DeploymentID ¶
type DeploymentStatus ¶
type DeploymentStatus struct {
StatusCode DeploymentStatusCode `json:"status"`
Reason string `json:"reason"`
}
type DeploymentStatusCode ¶
type DeploymentStatusCode string
const ( DeploymentStatusNotReady DeploymentStatusCode = "not ready" DeploymentStatusReady DeploymentStatusCode = "ready" DeploymentStatusRunning DeploymentStatusCode = "running" DeploymentStatusStopped DeploymentStatusCode = "stopped" DeploymentStatusError DeploymentStatusCode = "error" )
type DeploymentsRepository ¶
type DeploymentsRepository interface {
Create(loadName string, driver LoadDriver, status DeploymentStatus, metadata any) (DeploymentID, error)
UpdateStatus(deploymentID DeploymentID, status DeploymentStatus) error
UpdateMetadata(deploymentID DeploymentID, updateFn func(metadata any) error) error
GetAll() ([]Deployment, error)
GetByLoad(loadName string) ([]Deployment, error)
GetByLoadAndStatus(loadName string, statusCode DeploymentStatusCode) ([]Deployment, error)
GetDeployment(deploymentID DeploymentID) (*Deployment, error)
DeleteByLoad(loadName string) error
DeleteDeployment(deploymentID uuid.UUID) error
}
Store interface for deployments All methods are related to the deployments of the self node
Notice all data is returned by an immutable copy because this repository might be stored in a distributed database so no memory references must be used
type HashableLoadConfig ¶
type HashableLoadConfig struct {
Name string `json:"name"`
Node string `json:"node"`
DependsOn []string `json:"depends_on"`
Driver LoadDriverID `json:"driver"`
DriverConfig any `json:"driver_config"`
}
type Load ¶
type Load struct {
Name string
Node *NodeConfig
DependsOn []*Load
Driver LoadDriver
StartChain LoadChain
StopChain LoadChain
}
func (*Load) GetDependencies ¶
func (*Load) MarshalJSON ¶
func (*Load) UnmarshalJSON ¶
type LoadConfig ¶
type LoadDriver ¶
type LoadDriver interface {
// GetLoadDriverID returns the unique identifier for this load driver.
GetLoadDriverID() LoadDriverID
// DriverInfo returns metadata describing the driver for internal factory use.
DriverInfo() LoadDriverInfo
// MarshalJSON serializes the driver into JSON.
MarshalJSON() ([]byte, error)
// UnmarshalJSON deserializes the driver from JSON.
UnmarshalJSON(data []byte) error
// Provision validates prerequisites and creates a deployment in "provisioned" status.
// It shall check load requirements but it won't check depending loads.
// This is invoked within the daemon and does not affect client behavior.
//
// Returns the deployment ID for the provisioned deployment.
Provision(node NodeDriver, repository DeploymentsRepository, loadName string) (DeploymentID, error)
// Deprovision removes a provisioned deployment with cleanup
// Only operates on deployments in "provisioned" status.
Deprovision(repository DeploymentsRepository, deployment Deployment) error
// Run starts the load execution for an existing provisioned deployment.
// This has no effect when called from the client.
//
// LoadDriver is responsible of the consistency of the DeploymentsRepository
Run(repository DeploymentsRepository, deployment Deployment) error
// Stop stops a running load execution within the daemon.
// This has no effect when called from the client.
//
// LoadDriver is responsible of the consistency of the DeploymentsRepository
Stop(repository DeploymentsRepository, deployment Deployment) error
// Kill stops immediately a running load execution within the daemon.
// This has no effect when called from the client.
//
// LoadDriver is responsible of the consistency of the DeploymentsRepository
Kill(repository DeploymentsRepository, deployment Deployment) error
// UpdateStatus update and returns current status based on internal drivers factors.
UpdateStatus(repository DeploymentsRepository, deployment Deployment) (DeploymentStatus, error)
// GetDriverConfig returns the configuration for this load driver.
GetDriverConfig() LoadDriverConfig
// Stream load stdout to writer
StreamStdout(repository DeploymentsRepository, deployment Deployment, w io.Writer) error
// Stream load stderr to writer
StreamStderr(repository DeploymentsRepository, deployment Deployment, w io.Writer) error
// Read load stdout from offset, returns bytes read and end position
ReadStdout(repository DeploymentsRepository, deployment Deployment, offset int64) ([]byte, int64, error)
// Read load stderr from offset, returns bytes read and end position
ReadStderr(repository DeploymentsRepository, deployment Deployment, offset int64) ([]byte, int64, error)
}
func BuildLoadDriver ¶
func BuildLoadDriver(d LoadDriverConfig) (LoadDriver, error)
type LoadDriverConfig ¶
type LoadDriverConfig struct {
Driver LoadDriverID `json:"driver"`
DriverConfig any `json:"driver_config"`
}
type LoadDriverID ¶
type LoadDriverID string
type LoadDriverInfo ¶
type LoadDriverInfo struct {
ID LoadDriverID
New func(config any) (LoadDriver, error)
}
type NewNodeDriverInfoOpts ¶ added in v0.1.2
type NewNodeDriverInfoOpts func(i *NodeDriverInfo) error
func WithRestartMode ¶ added in v0.1.2
func WithRestartMode(m Mode) NewNodeDriverInfoOpts
func WithShutdownMode ¶ added in v0.1.2
func WithShutdownMode(m Mode) NewNodeDriverInfoOpts
func WithStartupMode ¶ added in v0.1.2
func WithStartupMode(m Mode) NewNodeDriverInfoOpts
type Node ¶
type Node struct {
Name string
Url string
Driver NodeDriver
}
func NewNodeFromConfig ¶
func NewNodeFromConfig(config *NodeConfig) (*Node, error)
func (*Node) MarshalJSON ¶
func (*Node) UnmarshalJSON ¶
type NodeConfig ¶
type NodeConfig struct {
Name string `json:"name"`
Url string `json:"url"`
Driver NodeDriverID `json:"driver,omitempty"`
DriverConfig *any `json:"driver_config,omitempty"`
}
type NodeDriver ¶
type NodeDriver interface {
// GetNodeDriverID returns the unique identifier for this node driver.
GetNodeDriverID() NodeDriverID
// DriverInfo returns metadata describing the driver for internal factory use.
DriverInfo() (NodeDriverInfo, error)
// GetDriverConfig returns the configuration for this node driver.
GetDriverConfig() NodeDriverConfig
// GetCapabilities returns current node capabilities
GetCapabilities() (Capabilities, error)
// MarshalJSON serializes the driver into JSON.
MarshalJSON() ([]byte, error)
// UnmarshalJSON deserializes the driver from JSON.
UnmarshalJSON(data []byte) error
// Startup starts the node
//
// nodeName as nil for self-node
Startup(nodeName *string, repository NodesRepository) error
// Shutdown shuts down the node
// Message will be shown to users before shutdown on the time
// offset specified
//
// nodeName as nil for self-node
Shutdown(nodeName *string, message string, time uint32, repository NodesRepository) error
// Restart restarts the node
// Message will be shown to users before shutdown on the time
// offset specified
//
// nodeName as nil for self-node
Restart(nodeName *string, message string, time uint32, repository NodesRepository) error
// UpdateStatus update and returns current status based on internal drivers factors
//
// nodeName as nil for self-node
UpdateStatus(nodeName *string, repository NodesRepository) (NodeStatus, error)
// Provision validates self-node prerequisites and creates or replace the current
// database entry.
// Notice that nodes are nameless, provisioning is also the action of naming the self-node
// It shall check node requirements but it won't check depending nodes.
// This is invoked within the daemon and does not affect client behavior.
Provision(nodeName string, repository NodesRepository) error
// Deprovision cleanup and removes the self-node
// Only operates on deployments in "provisioned" status.
Deprovision(repository NodesRepository) error
}
func BuildNodeDriver ¶
func BuildNodeDriver(d NodeDriverConfig) (NodeDriver, error)
type NodeDriverBuilder ¶ added in v0.1.2
type NodeDriverBuilder func(config *any) (NodeDriver, error)
type NodeDriverConfig ¶
type NodeDriverConfig struct {
Driver NodeDriverID `json:"driver"`
DriverConfig *any `json:"driver_config"`
}
type NodeDriverID ¶
type NodeDriverID string
type NodeDriverInfo ¶
type NodeDriverInfo struct {
ID NodeDriverID
New NodeDriverBuilder
StartupMode Mode
ShutdownMode Mode
RestartMode Mode
}
func NewNodeDriverInfo ¶ added in v0.1.2
func NewNodeDriverInfo(id NodeDriverID, builder NodeDriverBuilder, opts ...NewNodeDriverInfoOpts) (NodeDriverInfo, error)
type NodeEntry ¶
type NodeEntry struct {
NodeName string
NodeDriver NodeDriver
Metadata any
}
type NodeStatus ¶
type NodeStatus struct {
StatusCode NodeStatusCode `json:"status"`
Reason string `json:"reason"`
}
type NodeStatusCode ¶ added in v0.1.2
type NodeStatusCode string
const ( NodeStatusOffline NodeStatusCode = "offline" NodeStatusOnline NodeStatusCode = "online" NodeStatusReady NodeStatusCode = "ready" NodeStatusError NodeStatusCode = "error" )
type NodesRepository ¶
type NodesRepository interface {
// SetSelf creates or updates the node for the caller
SetSelf(nodeName string, driver NodeDriver, metadata any) error
// GetSelf return nodeentry for the caller node
GetSelf() (NodeEntry, error)
// DeleteSelf caller node from repository
DeleteSelf() error
// Retrieve node entry by daemon ID
GetByDaemonId(daemonId string) (NodeEntry, error)
// SetGuestNode creates or update the guest node entry for the caller host node
SetGuestNode(guestNodeName string, guestDriver NodeDriver, metadata any) error
// GetGuestNode returns a guest node of the caller host node
GetGuestNode(guestNodeName string) (NodeEntry, error)
// DeleteGuestNode deletes the guest node entry for the caller host node
DeleteGuestNode(guestNodeName string, guestDriver NodeDriver, metadata any) error
}
Store interface for nodes
Notice all data is returned by an immutable copy because this repository might be stored in a distributed database so no memory references must be used