model

package
v0.0.0-...-b206e69 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2019 License: Apache-2.0, Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

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 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.

Index

Constants

View Source
const (
	DeviceDeploymentStatusDownloading    = "downloading"
	DeviceDeploymentStatusInstalling     = "installing"
	DeviceDeploymentStatusRebooting      = "rebooting"
	DeviceDeploymentStatusPending        = "pending"
	DeviceDeploymentStatusSuccess        = "success"
	DeviceDeploymentStatusFailure        = "failure"
	DeviceDeploymentStatusNoArtifact     = "noartifact"
	DeviceDeploymentStatusAlreadyInst    = "already-installed"
	DeviceDeploymentStatusAborted        = "aborted"
	DeviceDeploymentStatusDecommissioned = "decommissioned"
)

Deployment statuses

View Source
const (
	LimitStorage = "storage"
)

Variables

View Source
var (
	ErrInvalidDeploymentLog = errors.New("invalid deployment log")
	ErrInvalidLogMessage    = errors.New("invalid log message")
)
View Source
var (
	ErrBadStatus = errors.New("unknown status value")
)
View Source
var (
	ErrFileStorageFileNotFound = errors.New("File not found")
)

Errors specific to interface

View Source
var (
	ErrInvalidDeviceID = errors.New("Invalid device ID")
)

Errors

View Source
var (
	ValidLimits = []string{LimitStorage}
)

Functions

func ActiveDeploymentStatuses

func ActiveDeploymentStatuses() []string

ActiveDeploymentStatuses lists statuses that represent deployment in active state (not finished).

func IsDeviceDeploymentStatusFinished

func IsDeviceDeploymentStatusFinished(status string) bool

func IsValidLimit

func IsValidLimit(name string) bool

Types

type ArtifactDeploymentInstructions

type ArtifactDeploymentInstructions struct {
	ArtifactName          string   `json:"artifact_name"`
	Source                Link     `json:"source"`
	DeviceTypesCompatible []string `json:"device_types_compatible"`
}

type ArtifactInfo

type ArtifactInfo struct {
	// Mender artifact format - the only possible value is "mender"
	//Format string `json:"format" valid:"string,equal("mender"),required"`
	Format string `json:"format" valid:"required"`

	// Mender artifact format version
	//Version uint `json:"version" valid:"uint,equal(1),required"`
	Version uint `json:"version" valid:"required"`
}

Structure with artifact version informations

type ArtifactUpdateTypeInfo

type ArtifactUpdateTypeInfo struct {
	Type string `json:"type" valid:"required"`
}

Type info structure

type Deployment

type Deployment struct {
	// User provided field set
	*DeploymentConstructor `valid:"required"`

	// Auto set on create, required
	Created *time.Time `json:"created" valid:"required"`

	// Finished deplyment time
	Finished *time.Time `json:"finished,omitempty" valid:"optional"`

	// Deployment id, required
	Id *string `json:"id" bson:"_id" valid:"uuidv4,required"`

	// List of artifact id's targeted for deployments, optional
	Artifacts []string `json:"artifacts,omitempty" bson:"artifacts"`

	// Aggregated device status counters.
	// Initialized with the "pending" counter set to total device count for deployment.
	// Individual counter incremented/decremented according to device status updates.
	Stats map[string]int `json:"-"`

	// Total number of devices targeted
	DeviceCount int `json:"device_count" bson:"-"`
}

func NewDeployment

func NewDeployment() (*Deployment, error)

NewDeployment creates new deployment object, sets create data by default.

func NewDeploymentFromConstructor

func NewDeploymentFromConstructor(constructor *DeploymentConstructor) (*Deployment, error)

NewDeploymentFromConstructor creates new Deployments object based on constructor data

func (*Deployment) GetStatus

func (d *Deployment) GetStatus() string

func (*Deployment) IsAborted

func (d *Deployment) IsAborted() bool

func (*Deployment) IsFinished

func (d *Deployment) IsFinished() bool

func (*Deployment) IsInProgress

func (d *Deployment) IsInProgress() bool

func (*Deployment) IsPending

func (d *Deployment) IsPending() bool

func (*Deployment) MarshalJSON

func (d *Deployment) MarshalJSON() ([]byte, error)

To be able to hide devices field, from API output provice custom marshaler

func (*Deployment) Validate

func (d *Deployment) Validate() error

Validate checkes structure according to valid tags

type DeploymentConstructor

type DeploymentConstructor struct {
	// Deployment name, required
	Name *string `json:"name,omitempty" valid:"length(1|4096),required"`

	// Artifact name to be installed required, associated with image
	ArtifactName *string `json:"artifact_name,omitempty" valid:"length(1|4096),required"`

	// List of device id's targeted for deployments, required
	Devices []string `json:"devices,omitempty" valid:"required" bson:"-"`
}

DeploymentConstructor represent input data needed for creating new Deployment (they differ in fields)

func (*DeploymentConstructor) Validate

func (c *DeploymentConstructor) Validate() error

Validate checkes structure according to valid tags TODO: Add custom validator to check devices array content (such us UUID formatting)

type DeploymentInstructions

type DeploymentInstructions struct {
	ID       string                         `json:"id"`
	Artifact ArtifactDeploymentInstructions `json:"artifact"`
}

type DeploymentLog

type DeploymentLog struct {
	// skip these 2 field when (un)marshalling to/from JSON
	DeviceID     string `json:"-" valid:"required"`
	DeploymentID string `json:"-" valid:"uuidv4,required"`

	Messages []LogMessage `json:"messages" valid:"required"`
}

func (*DeploymentLog) UnmarshalJSON

func (d *DeploymentLog) UnmarshalJSON(raw []byte) error

func (DeploymentLog) Validate

func (d DeploymentLog) Validate() error

type DeviceDeployment

type DeviceDeployment struct {
	// Internal field of initial creation of deployment
	Created *time.Time `json:"created" valid:"required"`

	// Update finish time
	Finished *time.Time `json:"finished,omitempty" valid:"-"`

	// Status
	Status *string `json:"status" valid:"required"`

	// Device id
	DeviceId *string `json:"id" valid:"required"`

	// Deployment id
	DeploymentId *string `json:"-" valid:"uuidv4,required"`

	// ID
	Id *string `json:"-" bson:"_id" valid:"uuidv4,required"`

	// Assigned software image
	Image *SoftwareImage `json:"-" valid:"-"`

	// Target device type
	DeviceType *string `json:"device_type,omitempty" valid:"-"`

	// Presence of deployment log
	IsLogAvailable bool `json:"log" valid:"-" bson:"log"`

	// Device reported substate
	SubState *string `json:"substate,omitempty" valid:"-" bson:"substate"`
}

func NewDeviceDeployment

func NewDeviceDeployment(deviceId, deploymentId string) (*DeviceDeployment, error)

func (*DeviceDeployment) Validate

func (d *DeviceDeployment) Validate() error

type DeviceDeploymentStatus

type DeviceDeploymentStatus struct {
	// status reported by device
	Status string `valid:"required"`
	// substate reported by device
	SubState *string
	// finish time
	FinishTime *time.Time
}

DeviceDeploymentStatus is a helper type for reporting status changes through the layers

type FileStorage

type FileStorage interface {
	Delete(ctx context.Context, objectId string) error
	Exists(ctx context.Context, objectId string) (bool, error)
	LastModified(ctx context.Context, objectId string) (time.Time, error)
	PutRequest(ctx context.Context, objectId string,
		duration time.Duration) (*Link, error)
	GetRequest(ctx context.Context, objectId string,
		duration time.Duration, responseContentType string) (*Link, error)
	UploadArtifact(ctx context.Context, objectId string,
		artifactSize int64, artifact io.Reader, contentType string) error
	SyncArtifact(ctx context.Context, objectId string, uri string) (int64, error)
}

FileStorage allows to store and manage large files

type GetRequester

type GetRequester interface {
	GetRequest(ctx context.Context, objectId string,
		duration time.Duration, responseContentType string) (*Link, error)
}

Responsible for providing GET method requests to requested artifact

type InstalledDeviceDeployment

type InstalledDeviceDeployment struct {
	Artifact   string `valid:"required"`
	DeviceType string `valid:"required"`
}

InstalledDeviceDeployment describes a deployment currently installed on the device, usually reported by a device

func (*InstalledDeviceDeployment) Validate

func (i *InstalledDeviceDeployment) Validate() error

type Limit

type Limit struct {
	Name  string `bson:"_id"`
	Value uint64 `bson:"value" json:"value"`
}

func (Limit) IsLess

func (l Limit) IsLess(what uint64) bool
type Link struct {
	Uri    string    `json:"uri"`
	Expire time.Time `json:"expire,omitempty"`
}
func NewLink(uri string, expire time.Time) *Link

type LogMessage

type LogMessage struct {
	Timestamp *time.Time `json:"timestamp" valid:"required"`
	Level     string     `json:"level" valid:"required"`
	Message   string     `json:"message" valid:"required"`
}

func (LogMessage) String

func (l LogMessage) String() string

func (*LogMessage) UnmarshalJSON

func (l *LogMessage) UnmarshalJSON(raw []byte) error

func (LogMessage) Validate

func (l LogMessage) Validate() error

type MultipartUploadMsg

type MultipartUploadMsg struct {
	// user metadata constructor
	MetaConstructor *SoftwareImageMetaConstructor
	// size of the artifact file
	ArtifactSize int64
	// reader pointing to the beginning of the artifact data
	ArtifactReader io.Reader

	// Uri that can be used to fetch the artifact
	ArtifactURI string

	// JSON file with artifact metadata.
	ArtifactMetadata *SoftwareImageMetaArtifactConstructor
}

MultipartUploadMsg is a structure with fields extracted from the mulitpart/form-data form send in the artifact upload request

type NewTenantReq

type NewTenantReq struct {
	TenantId string `json:"tenant_id"`
}

func ParseNewTenantReq

func ParseNewTenantReq(source io.Reader) (*NewTenantReq, error)

type Query

type Query struct {
	// match deployments by text by looking at deployment name and artifact name
	SearchText string

	// deployment status
	Status StatusQuery
	Limit  int
	Skip   int
	// only return deployments between timestamp range
	CreatedAfter  *time.Time
	CreatedBefore *time.Time
}

Deployment lookup query

type Release

type Release struct {
	Name      string
	Artifacts []SoftwareImage
}

type ReleaseFilter

type ReleaseFilter struct {
	Name string `json:"name"`
}

type SoftwareImage

type SoftwareImage struct {
	// User provided field set
	SoftwareImageMetaConstructor `bson:"meta"`

	// Field set provided with yocto image
	SoftwareImageMetaArtifactConstructor `bson:"meta_artifact"`

	// Image ID
	Id string `json:"id" bson:"_id" valid:"uuidv4,required"`

	// Artifact total size
	Size int64 `json:"size" bson:"size" valid:"-"`

	// Last modification time, including image upload time
	Modified *time.Time `json:"modified" valid:"-"`
}

SoftwareImage YOCTO image with user application

func NewSoftwareImage

func NewSoftwareImage(
	id string,
	metaConstructor *SoftwareImageMetaConstructor,
	metaArtifactConstructor *SoftwareImageMetaArtifactConstructor,
	artifactSize int64) *SoftwareImage

NewSoftwareImage creates new software image object.

func (*SoftwareImage) SetModified

func (s *SoftwareImage) SetModified(time time.Time)

SetModified set last modification time for the image.

func (*SoftwareImage) Validate

func (s *SoftwareImage) Validate() error

Validate checkes structure according to valid tags.

type SoftwareImageMetaArtifactConstructor

type SoftwareImageMetaArtifactConstructor struct {
	// artifact_name from artifact file
	Name string `json:"name" bson:"name" valid:"length(1|4096),required"`

	// Compatible device types for the application
	DeviceTypesCompatible []string `json:"device_types_compatible" bson:"device_types_compatible" valid:"length(1|4096),required"`

	// Artifact version info
	Info *ArtifactInfo `json:"info"`

	// Flag that indicates if artifact is signed or not
	Signed bool `json:"signed" bson:"signed"`

	// List of updates
	Updates []Update `json:"updates" valid:"-"`
}

Information provided with YOCTO image

func NewSoftwareImageMetaArtifactConstructor

func NewSoftwareImageMetaArtifactConstructor() *SoftwareImageMetaArtifactConstructor

func (*SoftwareImageMetaArtifactConstructor) Validate

Validate checkes structure according to valid tags.

type SoftwareImageMetaConstructor

type SoftwareImageMetaConstructor struct {
	// Image description
	Description string `json:"description,omitempty" valid:"length(1|4096),optional"`
}

Informations provided by the user

func NewSoftwareImageMetaConstructor

func NewSoftwareImageMetaConstructor() *SoftwareImageMetaConstructor

Creates new, empty SoftwareImageMetaConstructor

func (*SoftwareImageMetaConstructor) Validate

func (s *SoftwareImageMetaConstructor) Validate() error

Validate checkes structure according to valid tags.

type Stats

type Stats map[string]int

Deployment statistics wrapper, each value carries a count of deployments aggregated by state.

func NewDeviceDeploymentStats

func NewDeviceDeploymentStats() Stats

type StatusQuery

type StatusQuery int
const (
	StatusQueryAny StatusQuery = iota
	StatusQueryPending
	StatusQueryInProgress
	StatusQueryFinished
	StatusQueryAborted
)

type StatusReport

type StatusReport struct {
	Status   string
	SubState *string `json:"substate" valid:"length(0|200)"`
}

func (*StatusReport) UnmarshalJSON

func (s *StatusReport) UnmarshalJSON(raw []byte) error

type Update

type Update struct {
	TypeInfo ArtifactUpdateTypeInfo `json:"type_info" valid:"required"`
	Files    []UpdateFile           `json:"files"`
	MetaData interface{}            `json:"meta_data,omitempty" valid:"optional"`
}

Update structure

type UpdateFile

type UpdateFile struct {
	// Image name
	Name string `json:"name" valid:"required"`

	// Image file checksum
	Checksum string `json:"checksum" valid:"optional"`

	// Image size
	Size int64 `json:"size" valid:"optional"`

	// Date build
	Date *time.Time `json:"date" valid:"optional"`
}

Update file structure

Jump to

Keyboard shortcuts

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