Documentation ¶
Index ¶
- Constants
- Variables
- func GetIndexOfObjectToBeInstalled(aii activeinactive.Interface, um *metadata.UpdateMetadata) (int, error)
- func StateToString(status UpdateHubState) string
- type BaseState
- type CancellableState
- type Controller
- type Daemon
- type DownloadedState
- type DownloadingState
- func (state *DownloadingState) Cancel(ok bool, nextState State) bool
- func (state *DownloadingState) Handle(uh *UpdateHub) (State, bool)
- func (state *DownloadingState) ID() UpdateHubState
- func (state *DownloadingState) ToMap() map[string]interface{}
- func (state *DownloadingState) UpdateMetadata() *metadata.UpdateMetadata
- type ErrorState
- type ExitState
- type FirmwareSettings
- type IdleState
- type InstalledState
- type InstallingState
- type NetworkSettings
- type PersistentPollingSettings
- type PersistentSettings
- type PersistentUpdateSettings
- type PollState
- type PollingSettings
- type ProbeState
- type ProgressTracker
- type ProgressTrackerImpl
- type RebootingState
- type ReportableState
- type Settings
- type Sha256Checker
- type Sha256CheckerImpl
- type State
- type StorageSettings
- type TransitionFlow
- type UpdateHub
- func (uh *UpdateHub) Cancel(nextState State)
- func (uh *UpdateHub) DownloadUpdate(apiClient *client.ApiClient, updateMetadata *metadata.UpdateMetadata, ...) error
- func (uh *UpdateHub) GetState() State
- func (uh *UpdateHub) InstallUpdate(updateMetadata *metadata.UpdateMetadata, progressChan chan<- int) error
- func (uh *UpdateHub) ProbeUpdate(apiClient *client.ApiClient, retries int) (*metadata.UpdateMetadata, []byte, time.Duration, error)
- func (uh *UpdateHub) ProcessCurrentState() State
- func (uh *UpdateHub) ReportCurrentState() error
- func (uh *UpdateHub) SetState(state State)
- func (uh *UpdateHub) Start()
- type UpdateHubError
- type UpdateHubErrorReporter
- type UpdateHubState
- type UpdateSettings
Constants ¶
const ( // The system settings are the settings configured in the client-side and will be read-only SystemSettingsPath = "/etc/updatehub.conf" // The state change callback is executed twice each state // change. Once before the state handling and once after. Ex.: // <stateChangeCallbackPath> enter downloading // <stateChangeCallbackPath> leave downloading StateChangeCallbackPath = "/usr/share/updatehub/state-change-callback" // The error callback is executed whenever a error state is // handled. Ex.: // <errorCallbackPath> 'error_message' ErrorCallbackPath = "/usr/share/updatehub/error-callback" // The validate callback is executed whenever a successful // installation is booted. ValidateCallbackPath = "/usr/share/updatehub/validate-callback" // The rollback callback is executed whenever the agent boots // after an errored installation boot RollbackCallbackPath = "/usr/share/updatehub/rollback-callback" )
const ( // UpdateHubDummyState is a dummy state UpdateHubDummyState = iota // UpdateHubStateIdle is set when the agent is in the "idle" mode UpdateHubStateIdle // UpdateHubStatePoll is set when the agent is in the "polling" mode UpdateHubStatePoll // UpdateHubStateProbe is set when the agent is running a // "probeUpdate" procedure UpdateHubStateProbe // UpdateHubStateDownloading is set when the agent is downloading // an update UpdateHubStateDownloading // UpdateHubStateDownloaded is set when the agent finished // downloading an update UpdateHubStateDownloaded // UpdateHubStateInstalling is set when the agent is starting an // update installation UpdateHubStateInstalling // UpdateHubStateInstalled is set when the agent finished // installing an update UpdateHubStateInstalled // UpdateHubStateExit is set when the daemon is about to quit UpdateHubStateExit // UpdateHubStateError is set when an error occured on the agent UpdateHubStateError // UpdateHubStateRebooting is set when an error occured on the agent UpdateHubStateRebooting )
const ( // TransitionFlowUnchanged indicates that transition flow will remain unchanged TransitionFlowUnchanged = iota // TransitionFlowCancelled indicates that transition flow will be cancelled TransitionFlowCancelled // TransitionFlowPostponed indicates that transition flow will be postponed TransitionFlowPostponed )
Variables ¶
var DefaultSettings = Settings{ PollingSettings: PollingSettings{ PollingInterval: defaultPollingInterval, PollingEnabled: true, PersistentPollingSettings: PersistentPollingSettings{ LastPoll: (time.Time{}).UTC(), FirstPoll: (time.Time{}).UTC(), ExtraPollingInterval: 0, PollingRetries: 0, ProbeASAP: false, }, }, StorageSettings: StorageSettings{ ReadOnly: false, RuntimeSettingsPath: "/var/lib/updatehub.conf", }, UpdateSettings: UpdateSettings{ DownloadDir: "/tmp", SupportedInstallModes: []string{"dry-run", "copy", "flash", "imxkobs", "raw", "tarball", "ubifs"}, PersistentUpdateSettings: PersistentUpdateSettings{ UpgradeToInstallation: -1, }, }, NetworkSettings: NetworkSettings{ ServerAddress: defaultServerAddress, ListenSocket: "tcp://localhost:8080", }, FirmwareSettings: FirmwareSettings{ FirmwareMetadataPath: "/usr/share/updatehub", }, }
var ErrSha256sum = errors.New("sha256sum's don't match")
Functions ¶
func GetIndexOfObjectToBeInstalled ¶
func GetIndexOfObjectToBeInstalled(aii activeinactive.Interface, um *metadata.UpdateMetadata) (int, error)
GetIndexOfObjectToBeInstalled selects which object will be installed from the update metadata
func StateToString ¶
func StateToString(status UpdateHubState) string
StateToString converts a "UpdateHubState" to string
Types ¶
type BaseState ¶
type BaseState struct {
// contains filtered or unexported fields
}
BaseState is the state from which all others must do composition
type CancellableState ¶
type CancellableState struct { BaseState // contains filtered or unexported fields }
func (*CancellableState) NextState ¶
func (cs *CancellableState) NextState() State
func (*CancellableState) Stop ¶
func (cs *CancellableState) Stop()
func (*CancellableState) Wait ¶
func (cs *CancellableState) Wait()
type Controller ¶
type DownloadedState ¶
type DownloadedState struct { BaseState ReportableState // contains filtered or unexported fields }
DownloadedState is the State interface implementation for the UpdateHubStateDownloaded
func NewDownloadedState ¶
func NewDownloadedState(apiClient *client.ApiClient, updateMetadata *metadata.UpdateMetadata) *DownloadedState
NewDownloadedState creates a new DownloadedState
func (*DownloadedState) Handle ¶
func (state *DownloadedState) Handle(uh *UpdateHub) (State, bool)
Handle for DownloadedState just returns a new installing state
func (*DownloadedState) ID ¶
func (state *DownloadedState) ID() UpdateHubState
ID returns the state id
func (*DownloadedState) UpdateMetadata ¶
func (state *DownloadedState) UpdateMetadata() *metadata.UpdateMetadata
UpdateMetadata is the ReportableState interface implementation
type DownloadingState ¶
type DownloadingState struct { BaseState CancellableState ReportableState ProgressTracker // contains filtered or unexported fields }
DownloadingState is the State interface implementation for the UpdateHubStateDownloading
func NewDownloadingState ¶
func NewDownloadingState(apiClient *client.ApiClient, updateMetadata *metadata.UpdateMetadata, pti ProgressTracker) *DownloadingState
NewDownloadingState creates a new DownloadingState from a metadata.UpdateMetadata
func (*DownloadingState) Cancel ¶
func (state *DownloadingState) Cancel(ok bool, nextState State) bool
Cancel cancels a state if it is cancellable
func (*DownloadingState) Handle ¶
func (state *DownloadingState) Handle(uh *UpdateHub) (State, bool)
Handle for DownloadingState starts the objects downloads. It goes to the installing state if successfull. It goes back to the error state otherwise.
func (*DownloadingState) ID ¶
func (state *DownloadingState) ID() UpdateHubState
ID returns the state id
func (*DownloadingState) ToMap ¶
func (state *DownloadingState) ToMap() map[string]interface{}
ToMap is for the State interface implementation
func (*DownloadingState) UpdateMetadata ¶
func (state *DownloadingState) UpdateMetadata() *metadata.UpdateMetadata
UpdateMetadata is the ReportableState interface implementation
type ErrorState ¶
type ErrorState struct { BaseState ReportableState // contains filtered or unexported fields }
ErrorState is the State interface implementation for the UpdateHubStateError
func (*ErrorState) Handle ¶
func (state *ErrorState) Handle(uh *UpdateHub) (State, bool)
Handle for ErrorState calls "panic" if the error is fatal or triggers a poll state otherwise
func (*ErrorState) ToMap ¶
func (state *ErrorState) ToMap() map[string]interface{}
ToMap is for the State interface implementation
func (*ErrorState) UpdateMetadata ¶
func (state *ErrorState) UpdateMetadata() *metadata.UpdateMetadata
UpdateMetadata is the ReportableState interface implementation
type ExitState ¶
type ExitState struct { BaseState // contains filtered or unexported fields }
ExitState is the final state of the state machine
type FirmwareSettings ¶
type FirmwareSettings struct {
FirmwareMetadataPath string `ini:"MetadataPath" json:"metadata-path"`
}
type IdleState ¶
type IdleState struct { BaseState CancellableState }
IdleState is the State interface implementation for the UpdateHubStateIdle
type InstalledState ¶
type InstalledState struct { BaseState ReportableState // contains filtered or unexported fields }
InstalledState is the State interface implementation for the UpdateHubStateInstalled
func NewInstalledState ¶
func NewInstalledState(apiClient *client.ApiClient, updateMetadata *metadata.UpdateMetadata) *InstalledState
NewInstalledState creates a new InstalledState
func (*InstalledState) Handle ¶
func (state *InstalledState) Handle(uh *UpdateHub) (State, bool)
Handle for InstalledState implements the installation process itself
func (*InstalledState) ID ¶
func (state *InstalledState) ID() UpdateHubState
ID returns the state id
func (*InstalledState) UpdateMetadata ¶
func (state *InstalledState) UpdateMetadata() *metadata.UpdateMetadata
UpdateMetadata is the ReportableState interface implementation
type InstallingState ¶
type InstallingState struct { BaseState ReportableState ProgressTracker FileSystemBackend afero.Fs // contains filtered or unexported fields }
InstallingState is the State interface implementation for the UpdateHubStateInstalling
func NewInstallingState ¶
func NewInstallingState( apiClient *client.ApiClient, updateMetadata *metadata.UpdateMetadata, pti ProgressTracker, fsb afero.Fs) *InstallingState
NewInstallingState creates a new InstallingState
func (*InstallingState) Handle ¶
func (state *InstallingState) Handle(uh *UpdateHub) (State, bool)
Handle for InstallingState implements the installation process itself
func (*InstallingState) ID ¶
func (state *InstallingState) ID() UpdateHubState
ID returns the state id
func (*InstallingState) ToMap ¶
func (state *InstallingState) ToMap() map[string]interface{}
ToMap is for the State interface implementation
func (*InstallingState) UpdateMetadata ¶
func (state *InstallingState) UpdateMetadata() *metadata.UpdateMetadata
UpdateMetadata is the ReportableState interface implementation
type NetworkSettings ¶
type PersistentPollingSettings ¶
type PersistentPollingSettings struct { LastPoll time.Time `ini:"LastPoll" json:"last-poll"` FirstPoll time.Time `ini:"FirstPoll" json:"first-poll"` ExtraPollingInterval time.Duration `ini:"ExtraInterval" json:"extra-interval"` PollingRetries int `ini:"Retries" json:"retries"` ProbeASAP bool `ini:"ProbeASAP" json:"probe-asap"` }
type PersistentSettings ¶
type PersistentSettings struct { PersistentPollingSettings `ini:"Polling"` PersistentUpdateSettings `ini:"Update"` }
type PersistentUpdateSettings ¶
type PersistentUpdateSettings struct {
UpgradeToInstallation int `ini:"UpgradeToInstallation" json:"upgrade-to-installation"`
}
type PollState ¶
type PollState struct { BaseState CancellableState // contains filtered or unexported fields }
PollState is the State interface implementation for the UpdateHubStatePoll
func NewPollState ¶
NewPollState creates a new PollState
type PollingSettings ¶
type PollingSettings struct { PollingInterval time.Duration `ini:"Interval,omitempty" json:"interval,omitempty"` PollingEnabled bool `ini:"Enabled,omitempty" json:"enabled,omitempty"` PersistentPollingSettings `ini:"Polling"` }
type ProbeState ¶
type ProbeState struct { BaseState CancellableState ProbeResponseReady chan bool // contains filtered or unexported fields }
ProbeState is the State interface implementation for the UpdateHubStateProbe
func NewProbeState ¶
func NewProbeState(apiClient *client.ApiClient) *ProbeState
NewProbeState creates a new ProbeState
func (*ProbeState) Cancel ¶
func (state *ProbeState) Cancel(ok bool, nextState State) bool
Cancel cancels a state if it is cancellable
func (*ProbeState) Handle ¶
func (state *ProbeState) Handle(uh *UpdateHub) (State, bool)
Handle for ProbeState executes a ProbeUpdate procedure and proceed to download the update if there is one. It goes back to the polling state otherwise.
func (*ProbeState) ProbeResponse ¶
func (state *ProbeState) ProbeResponse() (*metadata.UpdateMetadata, time.Duration)
type ProgressTracker ¶
ProgressTracker will define which way the progress is kept
type ProgressTrackerImpl ¶
type ProgressTrackerImpl struct {
// contains filtered or unexported fields
}
ProgressTrackerImpl is for the ProgressTracker interface implementation
func (*ProgressTrackerImpl) GetProgress ¶
func (pti *ProgressTrackerImpl) GetProgress() int
GetProgress is for the ProgressTracker interface implementation
func (*ProgressTrackerImpl) SetProgress ¶
func (pti *ProgressTrackerImpl) SetProgress(progress int)
SetProgress is for the ProgressTracker interface implementation
type RebootingState ¶
type RebootingState struct { BaseState ReportableState // contains filtered or unexported fields }
RebootingState is the State interface implementation for the UpdateHubStateRebooting
func NewRebootingState ¶
func NewRebootingState(apiClient *client.ApiClient, updateMetadata *metadata.UpdateMetadata) *RebootingState
NewRebootingState creates a new RebootingState
func (*RebootingState) Handle ¶
func (state *RebootingState) Handle(uh *UpdateHub) (State, bool)
Handle for RebootingState implements the installation process itself
func (*RebootingState) ID ¶
func (state *RebootingState) ID() UpdateHubState
ID returns the state id
func (*RebootingState) UpdateMetadata ¶
func (state *RebootingState) UpdateMetadata() *metadata.UpdateMetadata
UpdateMetadata is the ReportableState interface implementation
type ReportableState ¶
type ReportableState interface {
UpdateMetadata() *metadata.UpdateMetadata
}
ReportableState interface describes the necessary operations for a State to be reportable
type Settings ¶
type Settings struct { PollingSettings `ini:"Polling" json:"polling"` StorageSettings `ini:"Storage" json:"storage"` UpdateSettings `ini:"Update" json:"update"` NetworkSettings `ini:"Network" json:"network"` FirmwareSettings `ini:"Firmware" json:"firmware"` }
type Sha256Checker ¶
type Sha256CheckerImpl ¶
type Sha256CheckerImpl struct { }
func (*Sha256CheckerImpl) CheckDownloadedObjectSha256sum ¶
type State ¶
type State interface { ID() UpdateHubState Handle(*UpdateHub) (State, bool) // Handle implements the behavior when the State is set Cancel(bool, State) bool ToMap() map[string]interface{} ApiClient() *client.ApiClient }
State interface describes the necessary operations for a State
func NewErrorState ¶
func NewErrorState(apiClient *client.ApiClient, updateMetadata *metadata.UpdateMetadata, err UpdateHubErrorReporter) State
NewErrorState creates a new ErrorState from a UpdateHubErrorReporter
type StorageSettings ¶
type TransitionFlow ¶
type TransitionFlow int
TransitionFlow indicates the transition flow of state change callback
func DetermineTransitionFlow ¶
func DetermineTransitionFlow(output []byte) (TransitionFlow, interface{})
DetermineTransitionFlow determines transition flow for state change callback
type UpdateHub ¶
type UpdateHub struct { Controller CopyBackend copy.Interface `json:"-"` Version string Settings *Settings Store afero.Fs FirmwareMetadata metadata.FirmwareMetadata PublicKey *rsa.PublicKey TimeStep time.Duration Updater client.Updater Reporter client.Reporter IgnoreProbeASAP bool ActiveInactiveBackend activeinactive.Interface StateChangeCallbackPath string ErrorCallbackPath string ValidateCallbackPath string RollbackCallbackPath string InstallIfDifferentBackend installifdifferent.Interface Sha256Checker utils.Rebooter utils.CmdLineExecuter DefaultApiClient *client.ApiClient // contains filtered or unexported fields }
func NewUpdateHub ¶
func NewUpdateHub( gitversion string, stateChangeCallbackPath string, errorCallbackPath string, validateCallbackPath string, rollbackCallbackPath string, fs afero.Fs, fm metadata.FirmwareMetadata, pubKey *rsa.PublicKey, initialState State, settings *Settings, DefaultApiClient *client.ApiClient) *UpdateHub
func (*UpdateHub) DownloadUpdate ¶
func (uh *UpdateHub) DownloadUpdate(apiClient *client.ApiClient, updateMetadata *metadata.UpdateMetadata, cancel <-chan bool, progressChan chan<- int) error
it is recommended to use a buffered channel for "progressChan" to ensure no progress event is lost
func (*UpdateHub) InstallUpdate ¶
func (uh *UpdateHub) InstallUpdate(updateMetadata *metadata.UpdateMetadata, progressChan chan<- int) error
it is recommended to use a buffered channel for "progressChan" to ensure no progress event is lost
func (*UpdateHub) ProbeUpdate ¶
func (*UpdateHub) ProcessCurrentState ¶
func (*UpdateHub) ReportCurrentState ¶
type UpdateHubError ¶
type UpdateHubError struct {
// contains filtered or unexported fields
}
func (*UpdateHubError) Cause ¶
func (e *UpdateHubError) Cause() error
func (*UpdateHubError) Error ¶
func (e *UpdateHubError) Error() string
func (*UpdateHubError) IsFatal ¶
func (e *UpdateHubError) IsFatal() bool
type UpdateHubErrorReporter ¶
func NewFatalError ¶
func NewFatalError(err error) UpdateHubErrorReporter
func NewTransientError ¶
func NewTransientError(err error) UpdateHubErrorReporter
type UpdateHubState ¶
type UpdateHubState int
UpdateHubState holds the possible states for the agent
type UpdateSettings ¶
type UpdateSettings struct { DownloadDir string `ini:"DownloadDir" json:"download-dir"` SupportedInstallModes []string `ini:"SupportedInstallModes" json:"supported-install-modes"` PersistentUpdateSettings `ini:"Update"` }