fieldagent

package
v1.0.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: EPL-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeprovisionScopeAll   = "all"
	DeprovisionScopeLocal = "local"
)
View Source
const (
	ExecTypeStdin      byte = 0
	ExecTypeStdout     byte = 1
	ExecTypeStderr     byte = 2
	ExecTypeControl    byte = 3
	ExecTypeClose      byte = 4
	ExecTypeActivation byte = 5
)

ExecMessageType constants

View Source
const (
	LogTypeLogLine  byte = 6
	LogTypeLogStart byte = 7
	LogTypeLogStop  byte = 8
	LogTypeLogError byte = 9
)

LogMessageType constants

Variables

This section is empty.

Functions

func ReadFile

func ReadFile(filename string) (json.RawMessage, int64, error)

ReadFile reads data from a cache file and validates checksum

func ReadFileAsArray

func ReadFileAsArray(filename string) ([]map[string]any, int64, error)

ReadFileAsArray reads a cached file as a JSON array

func SaveFile

func SaveFile(data any, filename string) error

SaveFile saves data to a cache file with checksum

Types

type APIClient

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

APIClient handles all HTTP communication with the controller

func NewAPIClient

func NewAPIClient() (*APIClient, error)

NewAPIClient creates a new API client for controller communication

func (*APIClient) Delete

func (c *APIClient) Delete(ctx context.Context, command string) error

Delete performs a DELETE request

func (*APIClient) GetJSON

func (c *APIClient) GetJSON(ctx context.Context, command string, result any) error

GetJSON performs a GET request and unmarshals JSON response

func (*APIClient) PatchJSON

func (c *APIClient) PatchJSON(ctx context.Context, command string, body any) error

PatchJSON performs a PATCH request with JSON body

func (*APIClient) Ping

func (c *APIClient) Ping(ctx context.Context) (bool, error)

Ping pings the controller to check connectivity

func (*APIClient) PostJSON

func (c *APIClient) PostJSON(ctx context.Context, command string, body any, result any) error

PostJSON performs a POST request with JSON body

func (*APIClient) PutJSON

func (c *APIClient) PutJSON(ctx context.Context, command string, body any) error

PutJSON performs a PUT request with JSON body

func (*APIClient) Request

func (c *APIClient) Request(ctx context.Context, command string, requestType RequestType, queryParams map[string]string, body any) (map[string]any, error)

Request performs an HTTP request to the controller with retry logic

type CacheFile

type CacheFile struct {
	Checksum  string          `json:"checksum"`
	Timestamp int64           `json:"timestamp"`
	Data      json.RawMessage `json:"data"`
}

CacheFile represents a cached file with checksum and timestamp

type ConnectionState

type ConnectionState int

ConnectionState represents the WebSocket connection state

const (
	StateDisconnected ConnectionState = iota
	StateConnecting
	StateConnected
	StatePending // Connected but waiting for user
	StateActive  // Connected and paired with user
)

type ExecSessionCallback

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

ExecSessionCallback handles Docker exec session I/O and bridges it to WebSocket

func NewExecSessionCallback

func NewExecSessionCallback(microserviceUUID, execID string) *ExecSessionCallback

NewExecSessionCallback creates a new ExecSessionCallback

func (*ExecSessionCallback) Close

func (c *ExecSessionCallback) Close()

Close closes the exec session callback

func (*ExecSessionCallback) GetExecID

func (c *ExecSessionCallback) GetExecID() string

GetExecID returns the exec session ID

func (*ExecSessionCallback) GetStderrWriter

func (c *ExecSessionCallback) GetStderrWriter() io.Writer

GetStderrWriter returns the stderr writer for ProcessManager

func (*ExecSessionCallback) GetStdin

func (c *ExecSessionCallback) GetStdin() io.WriteCloser

GetStdin returns the stdin writer

func (*ExecSessionCallback) GetStdinReader

func (c *ExecSessionCallback) GetStdinReader() io.Reader

GetStdinReader returns the stdin reader for ProcessManager

func (*ExecSessionCallback) GetStdoutWriter

func (c *ExecSessionCallback) GetStdoutWriter() io.Writer

GetStdoutWriter returns the stdout writer for ProcessManager

func (*ExecSessionCallback) IsRunning

func (c *ExecSessionCallback) IsRunning() bool

IsRunning returns whether the callback is running

func (*ExecSessionCallback) OnActivation

func (c *ExecSessionCallback) OnActivation()

OnActivation is called when the exec session is activated

func (*ExecSessionCallback) OnComplete

func (c *ExecSessionCallback) OnComplete()

OnComplete is called when the exec session completes

func (*ExecSessionCallback) OnError

func (c *ExecSessionCallback) OnError(err error)

OnError is called when the exec session encounters an error

func (*ExecSessionCallback) SetExecID

func (c *ExecSessionCallback) SetExecID(execID string)

SetExecID sets the exec session ID

func (*ExecSessionCallback) SetOnCloseHandler

func (c *ExecSessionCallback) SetOnCloseHandler(handler func())

SetOnCloseHandler sets the handler for close events

func (*ExecSessionCallback) SetOnErrorHandler

func (c *ExecSessionCallback) SetOnErrorHandler(handler func([]byte))

SetOnErrorHandler sets the handler for error data

func (*ExecSessionCallback) SetOnInputHandler

func (c *ExecSessionCallback) SetOnInputHandler(handler func([]byte))

SetOnInputHandler sets the handler for input data

func (*ExecSessionCallback) SetOnOutputHandler

func (c *ExecSessionCallback) SetOnOutputHandler(handler func([]byte))

SetOnOutputHandler sets the handler for output data

func (*ExecSessionCallback) WriteInput

func (c *ExecSessionCallback) WriteInput(data []byte) error

WriteInput writes input data to stdin

type ExecSessionWebSocketHandler

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

ExecSessionWebSocketHandler manages the WebSocket connection for exec sessions

func GetExecSessionWebSocketHandler

func GetExecSessionWebSocketHandler(microserviceUUID string) *ExecSessionWebSocketHandler

GetExecSessionWebSocketHandler gets or creates an ExecSessionWebSocketHandler for a microservice

func (*ExecSessionWebSocketHandler) Connect

func (h *ExecSessionWebSocketHandler) Connect() error

Connect establishes the WebSocket connection to the controller

func (*ExecSessionWebSocketHandler) Disconnect

func (h *ExecSessionWebSocketHandler) Disconnect()

Disconnect closes the WebSocket connection

func (*ExecSessionWebSocketHandler) IsActive

func (h *ExecSessionWebSocketHandler) IsActive() bool

IsActive returns whether the exec session is active

func (*ExecSessionWebSocketHandler) IsConnected

func (h *ExecSessionWebSocketHandler) IsConnected() bool

IsConnected returns whether the WebSocket is connected

func (*ExecSessionWebSocketHandler) SendMessage

func (h *ExecSessionWebSocketHandler) SendMessage(msgType byte, data []byte) error

SendMessage sends a message to the controller

type FieldAgent

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

FieldAgent handles all communication with the fog controller

func GetInstance

func GetInstance() *FieldAgent

GetInstance returns the singleton FieldAgent instance

func (*FieldAgent) Clear

func (fa *FieldAgent) Clear()

Clear clears all microservice data

func (*FieldAgent) Deprovision

func (fa *FieldAgent) Deprovision(clearCredentials bool) error

Deprovision deprovisions the agent clearCredentials=true skip controller request

func (*FieldAgent) DeprovisionWithScope

func (fa *FieldAgent) DeprovisionWithScope(clearCredentials bool, scope string) error

DeprovisionWithScope deprovisions the agent and controls cleanup scope. scope=all removes managed+local workloads; scope=local preserves local workloads.

func (*FieldAgent) FindLatestMicroserviceByUUID

func (fa *FieldAgent) FindLatestMicroserviceByUUID(uuid string) *models.Microservice

FindLatestMicroserviceByUUID finds a microservice by UUID

func (*FieldAgent) GetActiveExecSession

func (fa *FieldAgent) GetActiveExecSession(microserviceUUID string) string

GetActiveExecSession returns the active exec session ID for a microservice

func (*FieldAgent) GetContainerConfig

func (fa *FieldAgent) GetContainerConfig(microserviceUUID string) (string, bool)

GetContainerConfig returns the container config string for a microservice UUID

func (*FieldAgent) GetCurrentMicroservices

func (fa *FieldAgent) GetCurrentMicroservices() []*models.Microservice

GetCurrentMicroservices returns the current microservices (same as latest for now)

func (*FieldAgent) GetExecCallback

func (fa *FieldAgent) GetExecCallback(microserviceUUID string) *ExecSessionCallback

GetExecCallback gets the exec callback for a microservice

func (*FieldAgent) GetLatestMicroservices

func (fa *FieldAgent) GetLatestMicroservices() []*models.Microservice

GetLatestMicroservices returns the latest microservices from the controller

func (*FieldAgent) GetModuleIndex

func (fa *FieldAgent) GetModuleIndex() int

GetModuleIndex returns the module index

func (*FieldAgent) GetName

func (fa *FieldAgent) GetName() string

GetName returns the module name

func (*FieldAgent) GetRegistry

func (fa *FieldAgent) GetRegistry(id int) *models.Registry

GetRegistry returns a registry by ID

func (*FieldAgent) HandleExecSessionClose

func (fa *FieldAgent) HandleExecSessionClose(microserviceUUID, execID string) error

HandleExecSessionClose handles closing an exec session

func (*FieldAgent) HandleExecSessions

func (fa *FieldAgent) HandleExecSessions(microservices []*models.Microservice)

HandleExecSessions handles exec session changes for microservices

func (*FieldAgent) InstanceGPSConfigUpdated

func (fa *FieldAgent) InstanceGPSConfigUpdated() error

InstanceGPSConfigUpdated sends dedicated GPS config updates to the controller.

func (*FieldAgent) IsControllerConnected

func (fa *FieldAgent) IsControllerConnected(fromFile bool) bool

IsControllerConnected checks if the controller is connected

func (*FieldAgent) NotProvisioned

func (fa *FieldAgent) NotProvisioned() bool

NotProvisioned checks if the agent is not provisioned

func (*FieldAgent) PostStatusHelper

func (fa *FieldAgent) PostStatusHelper()

PostStatusHelper posts the fog status to the controller Exported for use by Edge Guard to immediately notify controller of hardware changes

func (*FieldAgent) Provision

func (fa *FieldAgent) Provision(key string) error

Provision provisions the agent with the controller

func (*FieldAgent) RemoveActiveExecSession

func (fa *FieldAgent) RemoveActiveExecSession(microserviceUUID string)

RemoveActiveExecSession removes the active exec session for a microservice

func (*FieldAgent) RemoveExecCallback

func (fa *FieldAgent) RemoveExecCallback(microserviceUUID string)

RemoveExecCallback removes the exec callback for a microservice

func (*FieldAgent) SendHWInfoFromHalToController

func (fa *FieldAgent) SendHWInfoFromHalToController()

SendHWInfoFromHalToController sends hardware information from HAL to the controller

func (*FieldAgent) SendUSBInfoFromHalToController

func (fa *FieldAgent) SendUSBInfoFromHalToController()

SendUSBInfoFromHalToController sends USB information from HAL to the controller

func (*FieldAgent) SetActiveExecSession

func (fa *FieldAgent) SetActiveExecSession(microserviceUUID, execID string)

SetActiveExecSession sets the active exec session ID for a microservice

func (*FieldAgent) SetControllerStatus

func (fa *FieldAgent) SetControllerStatus(status models.ControllerStatus)

SetControllerStatus updates the agent controller connection status.

func (*FieldAgent) SetCurrentMicroservices

func (fa *FieldAgent) SetCurrentMicroservices(microservices []*models.Microservice)

SetCurrentMicroservices sets the current microservices

func (*FieldAgent) SetExecCallback

func (fa *FieldAgent) SetExecCallback(microserviceUUID string, callback *ExecSessionCallback)

SetExecCallback sets the exec callback for a microservice

func (*FieldAgent) SetOnConfigsUpdate

func (fa *FieldAgent) SetOnConfigsUpdate(callback func(map[string]string) error)

SetOnConfigsUpdate sets the callback for configs updates

func (*FieldAgent) SetOnMicroservicesUpdate

func (fa *FieldAgent) SetOnMicroservicesUpdate(callback func([]*models.Microservice) error)

SetOnMicroservicesUpdate sets the callback for microservices updates

func (*FieldAgent) SetOnRegistriesUpdate

func (fa *FieldAgent) SetOnRegistriesUpdate(callback func([]*models.Registry) error)

SetOnRegistriesUpdate sets the callback for registries updates

func (*FieldAgent) SetProcessManager

func (fa *FieldAgent) SetProcessManager(pm *processmanager.ProcessManager)

SetProcessManager sets the ProcessManager reference

func (*FieldAgent) Start

func (fa *FieldAgent) Start() error

Start starts the FieldAgent and all background workers

func (*FieldAgent) Stop

func (fa *FieldAgent) Stop() error

Stop stops the FieldAgent and all background workers

func (*FieldAgent) Update

func (fa *FieldAgent) Update() error

Update updates the FieldAgent when configuration changes. Workers are NOT restarted — they use dynamic timers that re-read config on every tick, so they pick up new frequencies automatically. NewAPIClient() is moved into the background goroutine so the SIGHUP handler goroutine is never blocked by DNS resolution for the new controller URL.

type LogConnectionState

type LogConnectionState int

LogConnectionState represents the WebSocket connection state

const (
	LogStateDisconnected LogConnectionState = iota
	LogStateConnecting
	LogStateConnected
	LogStatePending // Connected but waiting for LOG_START
	LogStateActive  // Connected and streaming logs
)

type LogSession

type LogSession struct {
	SessionID        string `json:"sessionId"`
	MicroserviceUUID string `json:"microserviceUuid,omitempty"`
	IofogUUID        string `json:"iofogUuid,omitempty"`
	Status           string `json:"status"` // ACTIVE, PENDING, etc.
}

LogSession represents a log session from the controller

type LogSessionInfo

type LogSessionInfo struct {
	Session     *LogSession
	ContainerID string
	IsStreaming bool
}

LogSessionInfo tracks information about an active log session

type LogSessionManager

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

LogSessionManager manages active log sessions

func GetLogSessionManager

func GetLogSessionManager() *LogSessionManager

GetLogSessionManager returns the singleton LogSessionManager instance.

func (*LogSessionManager) FetchLogSessions

func (lsm *LogSessionManager) FetchLogSessions(ctx context.Context) ([]*LogSession, error)

FetchLogSessions fetches log sessions from the controller

func (*LogSessionManager) HandleLogSessions

func (lsm *LogSessionManager) HandleLogSessions(fetchedSessions []*LogSession)

HandleLogSessions handles fetched log sessions from controller

func (*LogSessionManager) SetEngine

func (lsm *LogSessionManager) SetEngine(e engine.ContainerEngine)

SetEngine sets the ContainerEngine used to look up containers and tail their logs. Must be called before log session streaming starts (from supervisor after engine init).

func (*LogSessionManager) SetProcessManager

func (lsm *LogSessionManager) SetProcessManager(pm *processmanager.ProcessManager)

SetProcessManager sets the ProcessManager instance (called by supervisor).

func (*LogSessionManager) StartLogStreamingOnActivation

func (lsm *LogSessionManager) StartLogStreamingOnActivation(sessionID string, tailConfigMap map[string]any)

StartLogStreamingOnActivation starts log streaming when WebSocket becomes active This method is called from LogSessionWebSocketHandler when it receives LOG_START

func (*LogSessionManager) StartWorker

func (lsm *LogSessionManager) StartWorker(ctx context.Context)

StartWorker starts the background worker that periodically fetches and handles log sessions

func (*LogSessionManager) StopLogSession

func (lsm *LogSessionManager) StopLogSession(sessionID string)

StopLogSession stops a log session (thread-safe)

type LogSessionWebSocketHandler

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

LogSessionWebSocketHandler manages the WebSocket connection for log sessions

func GetLogSessionWebSocketHandler

func GetLogSessionWebSocketHandler(sessionID, microserviceUUID, iofogUUID string, isMicroserviceLog bool) *LogSessionWebSocketHandler

GetLogSessionWebSocketHandler gets or creates a LogSessionWebSocketHandler for a session

func (*LogSessionWebSocketHandler) Connect

func (h *LogSessionWebSocketHandler) Connect() error

Connect establishes the WebSocket connection to the controller

func (*LogSessionWebSocketHandler) Disconnect

func (h *LogSessionWebSocketHandler) Disconnect()

Disconnect closes the WebSocket connection

func (*LogSessionWebSocketHandler) IsActive

func (h *LogSessionWebSocketHandler) IsActive() bool

IsActive returns whether the log session is active

func (*LogSessionWebSocketHandler) IsConnected

func (h *LogSessionWebSocketHandler) IsConnected() bool

IsConnected returns whether the WebSocket is connected

func (*LogSessionWebSocketHandler) SendMessage

func (h *LogSessionWebSocketHandler) SendMessage(msgType byte, data []byte) error

SendMessage sends a log message to the controller

func (*LogSessionWebSocketHandler) SetLogSessionManager

func (h *LogSessionWebSocketHandler) SetLogSessionManager(lsm *LogSessionManager)

SetLogSessionManager sets the LogSessionManager reference

type Orchestrator

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

Orchestrator wraps APIClient with additional methods

func NewOrchestrator

func NewOrchestrator(apiClient *APIClient) *Orchestrator

NewOrchestrator creates a new Orchestrator instance

func (*Orchestrator) GetControllerCert

func (o *Orchestrator) GetControllerCert(ctx context.Context) (string, error)

GetControllerCert gets the controller certificate from the controller Note: This uses an insecure connection to get the certificate when current cert is invalid

func (*Orchestrator) GetJSON

func (o *Orchestrator) GetJSON(ctx context.Context, command string, result any) error

GetJSON performs a GET request and returns JSON

func (*Orchestrator) Ping

func (o *Orchestrator) Ping(ctx context.Context) (bool, error)

Ping pings the IOFog controller

func (*Orchestrator) Provision

func (o *Orchestrator) Provision(ctx context.Context, key string) (map[string]any, error)

Provision does provisioning with the given key

func (*Orchestrator) Request

func (o *Orchestrator) Request(ctx context.Context, command string, requestType RequestType, queryParams map[string]string, body any) (map[string]any, error)

Request performs an HTTP request (wrapper around APIClient.Request)

func (*Orchestrator) Update

func (o *Orchestrator) Update() error

Update updates the orchestrator configuration

type RequestType

type RequestType string

RequestType represents HTTP request types

const (
	GET    RequestType = "GET"
	POST   RequestType = "POST"
	PUT    RequestType = "PUT"
	PATCH  RequestType = "PATCH"
	DELETE RequestType = "DELETE"
)

type State

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

State represents the current state of the FieldAgent

func NewState

func NewState() *State

NewState creates a new State instance

func (*State) GetControllerStatus

func (s *State) GetControllerStatus() models.ControllerStatus

GetControllerStatus returns the controller status

func (*State) GetLastCommandTime

func (s *State) GetLastCommandTime() int64

GetLastCommandTime returns the last command time

func (*State) GetLastGetChangesList

func (s *State) GetLastGetChangesList() int64

GetLastGetChangesList returns the last time changes were retrieved

func (*State) IsConnected

func (s *State) IsConnected() bool

IsConnected returns whether we're connected to the controller

func (*State) IsControllerVerified

func (s *State) IsControllerVerified() bool

IsControllerVerified returns whether the controller is verified

func (*State) IsInitialization

func (s *State) IsInitialization() bool

IsInitialization returns whether we're in initialization phase

func (*State) SetConnected

func (s *State) SetConnected(connected bool)

SetConnected sets the connected status

func (*State) SetControllerStatus

func (s *State) SetControllerStatus(status models.ControllerStatus)

SetControllerStatus sets the controller status

func (*State) SetControllerVerified

func (s *State) SetControllerVerified(verified bool)

SetControllerVerified sets the controller verified flag

func (*State) SetInitialization

func (s *State) SetInitialization(init bool)

SetInitialization sets the initialization flag

func (*State) SetLastCommandTime

func (s *State) SetLastCommandTime(timestamp int64)

SetLastCommandTime sets the last command time

func (*State) SetLastGetChangesList

func (s *State) SetLastGetChangesList(timestamp int64)

SetLastGetChangesList sets the last time changes were retrieved

func (*State) UpdateLastCommandTime

func (s *State) UpdateLastCommandTime()

UpdateLastCommandTime updates the last command time to current time

Jump to

Keyboard shortcuts

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