app

package
v0.0.0-...-da6e27a Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Copyright 2020 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2020 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2020 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2020 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2020 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2020 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLoggerNotInitialized  = errors.New("logger not initialized")
	ErrNotEnoughSpaceForLogs = errors.New("not enough space for storing logs")
)

error messages

View Source
var States = StateCollection{
	Authorize: &authorizeState{
		baseState{
			id: datastore.MenderStateAuthorize,
			t:  ToSync,
		},
	},
	AuthorizeWait: NewAuthorizeWaitState().(*authorizeWaitState),
	CheckWait:     NewCheckWaitState().(*checkWaitState),
	Final: &finalState{
		baseState{
			id: datastore.MenderStateDone,
			t:  ToNone,
		},
	},
	Init: &initState{
		baseState{
			id: datastore.MenderStateInit,
			t:  ToNone,
		},
	},
	Idle: &idleState{
		baseState{
			id: datastore.MenderStateIdle,
			t:  ToIdle,
		},
	},
	InventoryUpdate: &inventoryUpdateState{
		baseState{
			id: datastore.MenderStateInventoryUpdate,
			t:  ToSync,
		},
	},
	UpdateCheck: &updateCheckState{
		baseState{
			id: datastore.MenderStateUpdateCheck,
			t:  ToSync,
		},
	},
}

Exposed state variables.

Functions

func DoStandaloneCommit

func DoStandaloneCommit(device *dev.DeviceManager, stateExec statescript.Executor) error

func DoStandaloneInstall

func DoStandaloneInstall(device *dev.DeviceManager, updateURI string,
	clientConfig client.Config, vKey []byte,
	stateExec statescript.Executor) error

This will be run manually from command line ONLY

func DoStandaloneRollback

func DoStandaloneRollback(device *dev.DeviceManager, stateExec statescript.Executor) error

func Min

func Min(a, b int) int

func NewFatalError

func NewFatalError(err error) menderError

Create a new fatal error. Fatal errors will be reported back to the server.

func NewTransientError

func NewTransientError(err error) menderError

Create a new transient error. Transient errors will normally not be reported back to the server, unless they persist long enough for the client to give up.

func NewUpdateState

func NewUpdateState(id datastore.MenderState, t Transition, u *datastore.UpdateInfo) *updateState

func NewWaitState

func NewWaitState(id datastore.MenderState, t Transition) *waitState

func RemoveStateData

func RemoveStateData(store store.Store) error

func StateStatus

func StateStatus(m datastore.MenderState) string

Types

type AuthManager

type AuthManager interface {
	// returns true if authorization data is current and valid
	IsAuthorized() bool
	// returns device's authorization token
	AuthToken() (client.AuthToken, error)
	// removes authentication token
	RemoveAuthToken() error
	// check if device key is available
	HasKey() bool
	// generate device key (will overwrite an already existing key)
	GenerateKey() error

	client.AuthDataMessenger
}

func NewAuthManager

func NewAuthManager(conf AuthManagerConfig) AuthManager

type AuthManagerConfig

type AuthManagerConfig struct {
	AuthDataStore  store.Store            // authorization data store
	KeyStore       *store.Keystore        // key storage
	IdentitySource dev.IdentityDataGetter // provider of identity data
	TenantToken    []byte                 // tenant token
}

type Controller

type Controller interface {
	IsAuthorized() bool
	Authorize() menderError

	GetCurrentArtifactName() (string, error)
	GetUpdatePollInterval() time.Duration
	GetInventoryPollInterval() time.Duration
	GetRetryPollInterval() time.Duration

	CheckUpdate() (*datastore.UpdateInfo, menderError)
	FetchUpdate(url string) (io.ReadCloser, int64, error)

	NewStatusReportWrapper(updateId string,
		stateId datastore.MenderState) *client.StatusReportWrapper
	ReportUpdateStatus(update *datastore.UpdateInfo, status string) menderError
	UploadLog(update *datastore.UpdateInfo, logs []byte) menderError
	InventoryRefresh() error

	CheckScriptsCompatibility() error
	GetScriptExecutor() statescript.Executor

	ReadArtifactHeaders(from io.ReadCloser) (*installer.Installer, error)
	GetInstallers() []installer.PayloadUpdatePerformer

	RestoreInstallersFromTypeList(payloadTypes []string) error

	StateRunner
}

type DeploymentHook

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

func NewDeploymentLogHook

func NewDeploymentLogHook(logManager *DeploymentLogManager) *DeploymentHook

func (DeploymentHook) Fire

func (dh DeploymentHook) Fire(entry *logrus.Entry) error

func (DeploymentHook) Levels

func (dh DeploymentHook) Levels() []logrus.Level

type DeploymentJSONFormatter

type DeploymentJSONFormatter struct {
	// TimestampFormat sets the format used for marshaling timestamps.
	TimestampFormat string
}

func (*DeploymentJSONFormatter) Format

func (f *DeploymentJSONFormatter) Format(entry *logrus.Entry) ([]byte, error)

type DeploymentLogManager

type DeploymentLogManager struct {
	// contains filtered or unexported fields
}
var DeploymentLogger *DeploymentLogManager

Global deploymentlogger

func NewDeploymentLogManager

func NewDeploymentLogManager(logDirLocation string) *DeploymentLogManager

func (*DeploymentLogManager) Disable

func (dlm *DeploymentLogManager) Disable() error

func (*DeploymentLogManager) Enable

func (dlm *DeploymentLogManager) Enable(deploymentID string) error

func (DeploymentLogManager) GetLogs

func (dlm DeploymentLogManager) GetLogs(deploymentID string) ([]byte, error)

GetLogs is returns logs as a JSON []byte string. Function is having the same signature as json.Marshal() ([]byte, error)

func (DeploymentLogManager) Rotate

func (dlm DeploymentLogManager) Rotate()

func (DeploymentLogManager) WriteLog

func (dlm DeploymentLogManager) WriteLog(log []byte) error

type FileLogger

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

func NewFileLogger

func NewFileLogger(name string) *FileLogger

NewFileLogger creates instance of file logger; it is initialized just before logging is started

func (*FileLogger) Deinit

func (fl *FileLogger) Deinit() error

func (*FileLogger) Write

func (fl *FileLogger) Write(log []byte) (int, error)

type Mender

type Mender struct {
	*dev.DeviceManager
	// contains filtered or unexported fields
}

func NewMender

func NewMender(config *conf.MenderConfig, pieces MenderPieces) (*Mender, error)

func (*Mender) Authorize

func (m *Mender) Authorize() menderError

func (*Mender) Bootstrap

func (m *Mender) Bootstrap() menderError

func (*Mender) CheckScriptsCompatibility

func (m *Mender) CheckScriptsCompatibility() error

func (*Mender) CheckUpdate

func (m *Mender) CheckUpdate() (*datastore.UpdateInfo, menderError)

Check if new update is available. In case of errors, returns nil and error that occurred. If no update is available *UpdateInfo is nil, otherwise it contains update information.

func (*Mender) FetchUpdate

func (m *Mender) FetchUpdate(url string) (io.ReadCloser, int64, error)

func (*Mender) ForceBootstrap

func (m *Mender) ForceBootstrap()

func (*Mender) GetCurrentState

func (m *Mender) GetCurrentState() State

func (*Mender) GetInventoryPollInterval

func (m *Mender) GetInventoryPollInterval() time.Duration

func (*Mender) GetRetryPollInterval

func (m *Mender) GetRetryPollInterval() time.Duration

func (*Mender) GetScriptExecutor

func (m *Mender) GetScriptExecutor() statescript.Executor

func (*Mender) GetUpdatePollInterval

func (m *Mender) GetUpdatePollInterval() time.Duration

func (*Mender) InventoryRefresh

func (m *Mender) InventoryRefresh() error

func (*Mender) IsAuthorized

func (m *Mender) IsAuthorized() bool

func (*Mender) NewStatusReportWrapper

func (m *Mender) NewStatusReportWrapper(updateId string,
	stateId datastore.MenderState) *client.StatusReportWrapper

func (*Mender) ReportUpdateStatus

func (m *Mender) ReportUpdateStatus(update *datastore.UpdateInfo, status string) menderError

func (*Mender) SetNextState

func (m *Mender) SetNextState(s State)

func (*Mender) TransitionState

func (m *Mender) TransitionState(to State, ctx *StateContext) (State, bool)

func (*Mender) UploadLog

func (m *Mender) UploadLog(update *datastore.UpdateInfo, logs []byte) menderError

type MenderAuthManager

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

func (*MenderAuthManager) AuthToken

func (m *MenderAuthManager) AuthToken() (client.AuthToken, error)

func (*MenderAuthManager) GenerateKey

func (m *MenderAuthManager) GenerateKey() error

func (*MenderAuthManager) HasKey

func (m *MenderAuthManager) HasKey() bool

func (*MenderAuthManager) IsAuthorized

func (m *MenderAuthManager) IsAuthorized() bool

func (*MenderAuthManager) MakeAuthRequest

func (m *MenderAuthManager) MakeAuthRequest() (*client.AuthRequest, error)

func (*MenderAuthManager) RecvAuthResponse

func (m *MenderAuthManager) RecvAuthResponse(data []byte) error

func (*MenderAuthManager) RemoveAuthToken

func (m *MenderAuthManager) RemoveAuthToken() error

type MenderDaemon

type MenderDaemon struct {
	Mender       Controller
	Sctx         StateContext
	Store        store.Store
	ForceToState chan State
	// contains filtered or unexported fields
}

func NewDaemon

func NewDaemon(mender Controller, store store.Store) *MenderDaemon

func (*MenderDaemon) Cleanup

func (d *MenderDaemon) Cleanup()

func (*MenderDaemon) Run

func (d *MenderDaemon) Run() error

func (*MenderDaemon) StopDaemon

func (d *MenderDaemon) StopDaemon()

type MenderError

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

func (*MenderError) Cause

func (m *MenderError) Cause() error

func (*MenderError) Error

func (m *MenderError) Error() string

func (*MenderError) IsFatal

func (m *MenderError) IsFatal() bool

type MenderPieces

type MenderPieces struct {
	DualRootfsDevice installer.DualRootfsDevice
	Store            store.Store
	AuthMgr          AuthManager
}

type State

type State interface {
	// Perform state action, returns next state and boolean flag indicating if
	// execution was cancelled or not
	Handle(ctx *StateContext, c Controller) (State, bool)
	HandleError(ctx *StateContext, c Controller, err menderError) (State, bool)
	// Cancel state action, returns true if action was cancelled
	Cancel() bool
	// Return numeric state ID
	Id() datastore.MenderState
	// Return transition
	Transition() Transition
	SetTransition(t Transition)
}

func NewAuthorizeWaitState

func NewAuthorizeWaitState() State

func NewCheckWaitState

func NewCheckWaitState() State

func NewErrorState

func NewErrorState(err menderError) State

func NewFetchStoreRetryState

func NewFetchStoreRetryState(from State, update *datastore.UpdateInfo,
	err error) State

func NewReportErrorState

func NewReportErrorState(update *datastore.UpdateInfo, status string) State

func NewUpdateAfterCommitState

func NewUpdateAfterCommitState(update *datastore.UpdateInfo) State

func NewUpdateAfterFirstCommitState

func NewUpdateAfterFirstCommitState(update *datastore.UpdateInfo) State

func NewUpdateAfterRebootState

func NewUpdateAfterRebootState(update *datastore.UpdateInfo) State

func NewUpdateAfterRollbackRebootState

func NewUpdateAfterRollbackRebootState(update *datastore.UpdateInfo) State

func NewUpdateAfterStoreState

func NewUpdateAfterStoreState(update *datastore.UpdateInfo) State

func NewUpdateCleanupState

func NewUpdateCleanupState(update *datastore.UpdateInfo, status string) State

func NewUpdateCommitState

func NewUpdateCommitState(update *datastore.UpdateInfo) State

func NewUpdateErrorState

func NewUpdateErrorState(err menderError, update *datastore.UpdateInfo) State

func NewUpdateFetchState

func NewUpdateFetchState(update *datastore.UpdateInfo) State

func NewUpdateInstallState

func NewUpdateInstallState(update *datastore.UpdateInfo) State

func NewUpdatePreCommitStatusReportRetryState

func NewUpdatePreCommitStatusReportRetryState(returnToState State, reportTries int) State

func NewUpdateRebootState

func NewUpdateRebootState(update *datastore.UpdateInfo) State

func NewUpdateRollbackRebootState

func NewUpdateRollbackRebootState(update *datastore.UpdateInfo) State

func NewUpdateRollbackState

func NewUpdateRollbackState(update *datastore.UpdateInfo) State

func NewUpdateStatusReportRetryState

func NewUpdateStatusReportRetryState(reportState State,
	update *datastore.UpdateInfo, status string, tries int) State

func NewUpdateStatusReportState

func NewUpdateStatusReportState(update *datastore.UpdateInfo, status string) State

func NewUpdateStoreState

func NewUpdateStoreState(in io.ReadCloser, update *datastore.UpdateInfo) State

func NewUpdateVerifyRebootState

func NewUpdateVerifyRebootState(update *datastore.UpdateInfo) State

func NewUpdateVerifyRollbackRebootState

func NewUpdateVerifyRollbackRebootState(update *datastore.UpdateInfo) State

type StateCollection

type StateCollection struct {
	Authorize       *authorizeState
	AuthorizeWait   *authorizeWaitState
	CheckWait       *checkWaitState
	Final           *finalState
	Idle            *idleState
	Init            *initState
	InventoryUpdate *inventoryUpdateState
	UpdateCheck     *updateCheckState
}

type StateContext

type StateContext struct {
	// data store access
	Rebooter   installer.Rebooter
	Store      store.Store
	WakeupChan chan bool
	// contains filtered or unexported fields
}

StateContext carrying over data that may be used by all state handlers

type StateRunner

type StateRunner interface {
	// Set runner's state to 's'
	SetNextState(s State)
	// Obtain runner's state
	GetCurrentState() State
	// Run the currently set state with this context
	TransitionState(next State, ctx *StateContext) (State, bool)
}

type Transition

type Transition int
const (
	// no transition is happening
	ToNone Transition = iota
	// initial transition
	ToIdle
	ToSync
	ToError
	ToDownload_Enter
	ToDownload_Leave
	ToArtifactInstall
	// should have Enter and Error actions
	ToArtifactReboot_Enter
	// should have Leave action only
	ToArtifactReboot_Leave
	ToArtifactCommit_Enter
	ToArtifactCommit_Leave
	ToArtifactRollback
	// should have Enter and Error actions
	ToArtifactRollbackReboot_Enter
	// should have Leave action only
	ToArtifactRollbackReboot_Leave
	ToArtifactFailure
)

Transition in and out of state script states. Note in particular that update module specific states are not included here.

func (Transition) Enter

func (t Transition) Enter(exec statescript.Executor, report *client.StatusReportWrapper, store store.Store) error

Transition implements statescript.Launcher interface

func (Transition) Error

func (Transition) IsToError

func (t Transition) IsToError() bool

func (Transition) Leave

func (t Transition) Leave(exec statescript.Executor, report *client.StatusReportWrapper, store store.Store) error

func (Transition) String

func (t Transition) String() string

type UpdateState

type UpdateState interface {
	State
	Update() *datastore.UpdateInfo
}

type WaitState

type WaitState interface {
	Cancel() bool
	Wake() bool
	Wait(next, same State, wait time.Duration, wakeup chan bool) (State, bool)
}

Jump to

Keyboard shortcuts

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