utils

package
v1.1.0-rc.6 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: EPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NumberOfModules = 7

	ResourceConsumptionManager = 0
	ProcessManager             = 1
	StatusReporter             = 2
	EdgeletAPI                 = 3
	FieldAgent                 = 4
	ResourceManager            = 5
	GPSManager                 = 6
)

Module indices

View Source
const (
	KiB = 1024
	MiB = KiB * KiB
	GiB = KiB * KiB * KiB
)

Size constants

View Source
const (
	OSGroup                          = "edgelet"
	EdgeletDockerContainerNamePrefix = "edgelet_"
	MicroserviceFile                 = "microservices.json"
)

System constants

View Source
const (
	FieldAgentPingController                  = "FAPC"
	FieldAgentGetChangeList                   = "FACL"
	FieldAgentPostStatus                      = "FAPS"
	FieldAgentPostDiagnostic                  = "FAPD"
	StatusReporterSetStatusReporterSystemTime = "SRST"
	EdgeletAPIEvent                           = "LAPI"
	ResourceConsumptionManagerGetUsageData    = "RCUD"
	ProcessManagerContainersMonitor           = "PMCM"
	ProcessManagerCheckTasks                  = "PMCT"
	ResourceManagerGetUsageData               = "RMUD"
	EdgeletAPIControlWebSocketWorker          = "LACW"
	EdgeletAPIMessageWebSocketWorker          = "LAMW"
	ShutdownHook                              = "SDHK"
	SupervisorCheckEdgeletAPIStatus           = "SCLA"
	NetworkInterfaceManager                   = "INIM"
)

Event constants

View Source
const (
	MaxDiskConsumptionLimit = 100000.0
	PercentageCompletion    = 100.0
)

Limits

View Source
const (

	// PIDFileName is the exported name for the PID file
	PIDFileName = pidFileName
)

Variables

View Source
var (
	SNAP       = getEnvOrDefault("SNAP", "")
	SNAPCommon = getEnvOrDefault("SNAP_COMMON", "")
)

Environment variables

View Source
var (
	WindowsEdgeletPath   = getWindowsEdgeletBase()
	VarRun               = getVarRunPath()
	ConfigDir            = getConfigDir()
	EdgeletAPITokenPath  = ConfigDir + "edgelet-api"
	ConfigYAMLPath       = ConfigDir + "config.yaml"
	BackupConfigYAMLPath = ConfigDir + "config-bck.yaml"
)

Path constants

View Source
var (
	ErrInvalidSwitcherState = errors.New("invalid switcher state")
)

Functions

func ByteArrayToString

func ByteArrayToString(b []byte) string

ByteArrayToString returns a string representation of a byte array Example: []byte{1, 2, 3, 4} => "[1, 2, 3, 4]"

func BytesToInteger

func BytesToInteger(b []byte) int32

BytesToInteger converts a byte array to an integer (int32)

func BytesToLong

func BytesToLong(b []byte) int64

BytesToLong converts a byte array to a long (int64)

func BytesToShort

func BytesToShort(b []byte) int16

BytesToShort converts a byte array to a short (int16)

func BytesToString

func BytesToString(b []byte) string

BytesToString converts a byte array to a string (UTF-8)

func CopyOfRange

func CopyOfRange(src []byte, from, to int) []byte

CopyOfRange copies a range of bytes from src

func ExecuteCommand

func ExecuteCommand(command string) (string, string, error)

ExecuteCommand executes a shell command and returns the output

func ExecuteCommandSafe

func ExecuteCommandSafe(command string, timeoutSeconds int) (string, error)

ExecuteCommandSafe executes a command with timeout and safety checks

func GetConfigDir

func GetConfigDir() string

GetConfigDir returns the config directory (can be called dynamically) This allows recalculation of config path when SNAP_COMMON changes (e.g., in dev environment)

func IntegerToBytes

func IntegerToBytes(x int32) []byte

IntegerToBytes converts an integer (int32) to a byte array

func IsAnotherInstanceRunning

func IsAnotherInstanceRunning() bool

IsAnotherInstanceRunning checks if another instance of the daemon is running

func LongToBytes

func LongToBytes(x int64) []byte

LongToBytes converts a long (int64) to a byte array

func RemovePIDFile

func RemovePIDFile() error

RemovePIDFile removes the PID file

func ShortToBytes

func ShortToBytes(x int16) []byte

ShortToBytes converts a short (int16) to a byte array

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts a string to a byte array (UTF-8)

func WritePIDFile

func WritePIDFile() error

WritePIDFile writes the current process ID to a file

Types

type ConfigSwitcherState

type ConfigSwitcherState string

ConfigSwitcherState represents configuration profile state

const (
	ConfigSwitcherStateDefault     ConfigSwitcherState = "default"
	ConfigSwitcherStateDevelopment ConfigSwitcherState = "development"
	ConfigSwitcherStateProduction  ConfigSwitcherState = "production"
)

func ParseConfigSwitcherState

func ParseConfigSwitcherState(s string) (ConfigSwitcherState, error)

ParseConfigSwitcherState parses a string to ConfigSwitcherState

func (ConfigSwitcherState) FullValue

func (s ConfigSwitcherState) FullValue() string

FullValue returns the full value string for the state

type DockerStatus

type DockerStatus string

DockerStatus represents Docker daemon status

const (
	DockerStatusNotPresent DockerStatus = "NOT_PRESENT"
	DockerStatusRunning    DockerStatus = "RUNNING"
	DockerStatusStopped    DockerStatus = "STOPPED"
)

type Either

type Either[T any] interface {
	IsLeft() bool
	IsRight() bool
	Left() error
	Right() T
}

Either represents a value that can be either Left (error) or Right (success)

type HTTPClient

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

HTTPClient is a wrapper around http.Client with retry logic and JWT support

func NewHTTPClient

func NewHTTPClient(baseURL string) *HTTPClient

NewHTTPClient creates a new HTTP client

func (*HTTPClient) Delete

func (c *HTTPClient) Delete(ctx context.Context, path string) (*http.Response, error)

Delete performs a DELETE request with retry logic

func (*HTTPClient) Get

func (c *HTTPClient) Get(ctx context.Context, path string) (*http.Response, error)

Get performs a GET request with retry logic

func (*HTTPClient) GetJSON

func (c *HTTPClient) GetJSON(ctx context.Context, path string, result any) error

GetJSON performs a GET request and unmarshals the JSON response

func (*HTTPClient) Ping

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

Ping performs a ping request to check connectivity

func (*HTTPClient) Post

func (c *HTTPClient) Post(ctx context.Context, path string, body any) (*http.Response, error)

Post performs a POST request with retry logic

func (*HTTPClient) PostJSON

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

PostJSON performs a POST request with JSON body and unmarshals the JSON response

func (*HTTPClient) Put

func (c *HTTPClient) Put(ctx context.Context, path string, body any) (*http.Response, error)

Put performs a PUT request with retry logic

func (*HTTPClient) SetControllerCert

func (c *HTTPClient) SetControllerCert(cert *x509.Certificate) error

SetControllerCert sets the controller certificate for TLS

func (*HTTPClient) SetJWTToken

func (c *HTTPClient) SetJWTToken(token string)

SetJWTToken sets the JWT token for authentication

type Left

type Left[T any] struct {
	// contains filtered or unexported fields
}

Left represents an error value

func NewLeft

func NewLeft[T any](err error) *Left[T]

NewLeft creates a new Left value

func (*Left[T]) IsLeft

func (l *Left[T]) IsLeft() bool

IsLeft returns true

func (*Left[T]) IsRight

func (l *Left[T]) IsRight() bool

IsRight returns false

func (*Left[T]) Left

func (l *Left[T]) Left() error

Left returns the error

func (*Left[T]) Right

func (l *Left[T]) Right() T

Right panics (Left has no right value)

type LinkStatus

type LinkStatus string

LinkStatus represents link status

const (
	LinkStatusFailedVerification LinkStatus = "FAILED_VERIFICATION"
	LinkStatusFailedLogin        LinkStatus = "FAILED_LOGIN"
	LinkStatusConnected          LinkStatus = "CONNECTED"
)

type LocalLogHandler

type LocalLogHandler interface {
	OnLogLine(sessionID, iofogUUID, line string)
	OnComplete(sessionID string)
	OnError(sessionID string, err error)
}

LocalLogHandler is the interface for handling log lines

type LocalLogReader

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

LocalLogReader reads and streams agent self logs from local log files

func NewLocalLogReader

func NewLocalLogReader(sessionID, iofogUUID, logDirectory string, tailConfig *TailConfig, handler LocalLogHandler) *LocalLogReader

NewLocalLogReader creates a new LocalLogReader

func (*LocalLogReader) IsRunning

func (llr *LocalLogReader) IsRunning() bool

IsRunning returns whether the reader is running

func (*LocalLogReader) Start

func (llr *LocalLogReader) Start()

Start starts reading logs

func (*LocalLogReader) Stop

func (llr *LocalLogReader) Stop()

Stop stops reading logs

type ModulesStatus

type ModulesStatus string

ModulesStatus represents the status of a module

const (
	ModulesStatusStarting ModulesStatus = "STARTING"
	ModulesStatusRunning  ModulesStatus = "RUNNING"
	ModulesStatusStopped  ModulesStatus = "STOPPED"
	ModulesStatusWarning  ModulesStatus = "WARNING"
)

type Pair

type Pair[A, B any] struct {
	First  A
	Second B
}

Pair represents a pair of values

func NewPair

func NewPair[A, B any](first A, second B) *Pair[A, B]

NewPair creates a new Pair

type Right[T any] struct {
	// contains filtered or unexported fields
}

Right represents a success value

func NewRight

func NewRight[T any](value T) *Right[T]

NewRight creates a new Right value

func (*Right[T]) IsLeft

func (r *Right[T]) IsLeft() bool

IsLeft returns false

func (*Right[T]) IsRight

func (r *Right[T]) IsRight() bool

IsRight returns true

func (*Right[T]) Left

func (r *Right[T]) Left() error

Left panics (Right has no left value)

func (*Right[T]) Right

func (r *Right[T]) Right() T

Right returns the value

type TailConfig

type TailConfig struct {
	Follow bool   `json:"follow"`
	Lines  int    `json:"lines"`
	Since  string `json:"since,omitempty"`
	Until  string `json:"until,omitempty"`
}

TailConfig represents configuration for tailing logs

type Unit

type Unit struct{}

Unit represents a unit type (void)

func NewUnit

func NewUnit() Unit

NewUnit creates a new Unit

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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