Documentation
¶
Index ¶
Constants ¶
const ( // StatusPending means the thing has not started the update yet. StatusPending = "pending" // StatusDownloading means the thing is downloading the firmware. StatusDownloading = "downloading" // StatusInstalling means the thing is installing the firmware. StatusInstalling = "installing" // StatusSucceeded means the thing reported the target version. StatusSucceeded = "succeeded" // StatusFailed means the update failed, timed out or was superseded. StatusFailed = "failed" )
const ( // ErrMsgTimedOut is stored for a thing update without progress for its update's timeout. ErrMsgTimedOut = "timed out" // ErrMsgVersionMismatch is stored when a thing reports success with a different version. ErrMsgVersionMismatch = "version mismatch: reported %s" // ErrMsgSuperseded is stored for an active thing update replaced by a newer update. ErrMsgSuperseded = "superseded by update %s" )
const ( // UpdateStatusInProgress means at least one thing is still active. UpdateStatusInProgress = "in_progress" // UpdateStatusCompleted means no thing is active or failed. UpdateStatusCompleted = "completed" // UpdateStatusCompletedWithFailures means no thing is active and at least one failed. UpdateStatusCompletedWithFailures = "completed_with_failures" )
Variables ¶
var ( // ErrInvalidStatus indicates an unknown status. ErrInvalidStatus = errors.New("invalid OTA status") // ErrUpdateFinished indicates a status report for a thing update that already finished. ErrUpdateFinished = errors.New("OTA update already finished") // ErrMissingReportedVersion indicates a succeeded status report without the installed version. ErrMissingReportedVersion = errors.New("missing reported version") )
var ActiveStatuses = []string{StatusPending, StatusDownloading, StatusInstalling}
ActiveStatuses are the statuses of a thing update that is still running.
var ThingUpdateOrderFields = map[string]string{
"thing_id": "thing_id",
"updated_at": "updated_at",
"status": "status",
}
ThingUpdateOrderFields maps API order keys to SQL column expressions of the thing_updates table.
var UpdateOrderFields = map[string]string{
"id": "id",
"created_at": "created_at",
"version": "version",
"status": "status",
"targets": "targets",
"pending": "pending_count",
"downloading": "downloading_count",
"installing": "installing_count",
"succeeded": "succeeded_count",
"failed": "failed_count",
}
UpdateOrderFields maps API-facing order keys to SQL column expressions for the updates table.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
UpdateID string `json:"update_id"`
Version string `json:"version"`
FileName string `json:"file_name"`
URL string `json:"url"`
Size int64 `json:"size"`
Checksum string `json:"checksum"`
}
Command tells a thing which firmware to install and where to download it from.
type PageMetadata ¶
type PageMetadata struct {
Total uint64 `json:"total,omitempty"`
Offset uint64 `json:"offset,omitempty"`
Limit uint64 `json:"limit,omitempty"`
Order string `json:"order,omitempty"`
Dir string `json:"dir,omitempty"`
Status string `json:"status,omitempty"`
}
PageMetadata contains page metadata that helps navigation.
type Service ¶
type Service interface {
// CreateUpdate creates an update of the given things in the group and notifies them.
CreateUpdate(ctx context.Context, token, groupID string, u Update, thingIDs ...string) (Update, error)
// ListUpdatesByGroup retrieves a page of updates of the given group.
ListUpdatesByGroup(ctx context.Context, token, groupID string, pm PageMetadata) (UpdatesPage, error)
// ViewUpdate retrieves the update identified by the given ID.
ViewUpdate(ctx context.Context, token, id string) (Update, error)
// ListThingUpdates retrieves a page of thing updates of the given update.
ListThingUpdates(ctx context.Context, token, updateID string, pm PageMetadata) (ThingUpdatesPage, error)
// RetryFailed moves the update's failed things back to pending and notifies them again.
RetryFailed(ctx context.Context, token, updateID string) error
// RemoveUpdate removes the update identified by the given ID.
RemoveUpdate(ctx context.Context, token, id string) error
// ViewPending retrieves the command of the update that the thing with the key should apply.
ViewPending(ctx context.Context, key domain.ThingKey) (Command, error)
// ReportStatus records the progress of an update reported by the thing identified by the key.
ReportStatus(ctx context.Context, key domain.ThingKey, report StatusReport) error
// FailTimedOut marks thing updates without progress for their update's timeout as failed.
FailTimedOut(ctx context.Context) error
// RemoveThingUpdatesByThing removes thing updates of the given thing.
RemoveThingUpdatesByThing(ctx context.Context, thingID string) error
// RemoveUpdatesByGroup removes updates of the given group.
RemoveUpdatesByGroup(ctx context.Context, groupID string) error
consumers.MessageConsumer
}
Service specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics). All methods that accept a token parameter use it to identify and authorize the user performing the operation.
func New ¶
func New(things domain.ThingsClient, updates UpdateRepository, publisher messaging.CommandPublisher, idp uuid.IDProvider, firmwareURL string, logger logger.Logger) Service
New instantiates the OTA service implementation. firmwareURL is the public base URL things download firmware files from.
type StatusReport ¶
type StatusReport struct {
UpdateID string `json:"update_id"`
Status string `json:"status"`
Version string `json:"version,omitempty"`
Error string `json:"error,omitempty"`
}
StatusReport is a thing's report on the progress of an update.
type ThingUpdate ¶
type ThingUpdate struct {
UpdateID string
ThingID string
Status string
Error string
ReportedVersion string
UpdatedAt time.Time
}
ThingUpdate is the progress of one thing within an update.
type ThingUpdatesPage ¶
type ThingUpdatesPage struct {
Total uint64
ThingUpdates []ThingUpdate
}
ThingUpdatesPage contains a page of thing updates.
type Update ¶
type Update struct {
ID string
GroupID string
FileName string
Version string
FileSize int64
Checksum string
Description string
Timeout time.Duration
CreatedAt time.Time
Status string
Stats UpdateStats
}
Update is a firmware rollout to a set of things in one group.
type UpdateRepository ¶
type UpdateRepository interface {
// Save persists the update with a pending thing update for each given thing. Older active
// thing updates of the same things are marked failed as superseded in the same transaction.
Save(ctx context.Context, u Update, thingIDs ...string) error
// RetrieveByID retrieves the update with the given ID, including its status and stats.
RetrieveByID(ctx context.Context, id string) (Update, error)
// RetrieveByGroup retrieves a page of updates of the given group, including their status and
// stats, optionally filtered by status.
RetrieveByGroup(ctx context.Context, groupID string, pm PageMetadata) (UpdatesPage, error)
// Remove removes the update with the given ID and its thing updates.
Remove(ctx context.Context, id string) error
// RemoveByGroup removes all updates of the given group.
RemoveByGroup(ctx context.Context, groupID string) error
// RetrieveThingUpdates retrieves a page of thing updates of the given update.
RetrieveThingUpdates(ctx context.Context, updateID string, pm PageMetadata) (ThingUpdatesPage, error)
// RetrieveThingUpdate retrieves the thing update of the given update and thing.
RetrieveThingUpdate(ctx context.Context, updateID, thingID string) (ThingUpdate, error)
// RetrieveActiveThingUpdate retrieves the newest active thing update of the given thing.
RetrieveActiveThingUpdate(ctx context.Context, thingID string) (ThingUpdate, error)
// UpdateThingUpdate updates the progress of an active thing update.
UpdateThingUpdate(ctx context.Context, tu ThingUpdate) error
// RetrieveFailedThingIDs retrieves the IDs of the failed things of the given update.
RetrieveFailedThingIDs(ctx context.Context, updateID string) ([]string, error)
// RetryFailed moves the failed thing updates of the given update and things back to pending
// and returns the IDs of the affected things.
RetryFailed(ctx context.Context, updateID string, thingIDs []string) ([]string, error)
// FailTimedOut fails active thing updates without progress for their update's timeout.
FailTimedOut(ctx context.Context, now time.Time) error
// RemoveThingUpdatesByThing removes all thing updates of the given thing.
RemoveThingUpdatesByThing(ctx context.Context, thingID string) error
}
UpdateRepository specifies the persistence API for updates and their thing updates.
type UpdateStats ¶
type UpdateStats struct {
Targets uint64
Pending uint64
Downloading uint64
Installing uint64
Succeeded uint64
Failed uint64
}
UpdateStats counts the things of an update by status.
func (*UpdateStats) Add ¶
func (s *UpdateStats) Add(status string)
Add counts a thing with the given status.
func (*UpdateStats) Remove ¶
func (s *UpdateStats) Remove(status string)
Remove stops counting a thing with the given status.
func (UpdateStats) Status ¶
func (s UpdateStats) Status() string
Status returns the update status the stats add up to.
type UpdatesPage ¶
UpdatesPage contains a page of updates.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
|
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations. |
|
http
Package http contains implementation of kit service HTTP API.
|
Package http contains implementation of kit service HTTP API. |