Documentation ¶
Index ¶
- Constants
- type AccessMode
- type AutoUploadable
- func (u *AutoUploadable) Connect(mqttClient MQTT.Client, edgeCfg *EdgeConfiguration)
- func (u *AutoUploadable) Disconnect()
- func (u *AutoUploadable) UpdateProperty(featureID string, value interface{})
- func (u *AutoUploadable) UploadFiles(correlationID string, files []string, options map[string]string)
- type AutoUploadableState
- type BrokerConfig
- type Duration
- type EdgeClient
- type EdgeConfiguration
- type EdgeConnector
- type ErrorCode
- type ErrorResponse
- type FileUpload
- func (fu *FileUpload) Connect(client MQTT.Client, edgeCfg *EdgeConfiguration)
- func (fu *FileUpload) Disconnect()
- func (fu *FileUpload) DoTrigger(correlationID string, options map[string]string) error
- func (fu *FileUpload) HandleOperation(operation string, payload []byte) *ErrorResponse
- func (fu *FileUpload) OnTick()
- type MultiUpload
- type PeriodicExecutor
- type SingleUpload
- type StatusEventsConsumer
- type Upload
- type UploadCustomizer
- type UploadStatus
- type UploadStatusListener
- type UploadableConfig
- type Uploads
- func (us *Uploads) AddMulti(correlationID string, paths []string, deleteUploaded bool, useChecksum bool, ...) []string
- func (us *Uploads) AddSingle(parent *MultiUpload, correlationID string, filePath string)
- func (us *Uploads) Get(correlationID string) Upload
- func (us *Uploads) Remove(correlationID string)
- func (us *Uploads) Stop(timeout time.Duration)
- type Xtime
Constants ¶
const ( ModeNA = iota ModeStrict ModeLax ModeScoped )
Allowed values for AccessMode
const ( ModeNameStrict = "strict" ModeNameLax = "lax" ModeNameScoped = "scoped" )
AccessMode names
const ( StatePending = "PENDING" StateUploading = "UPLOADING" StatePaused = "PAUSED" StateSuccess = "SUCCESS" StateFailed = "FAILED" StateCanceled = "CANCELED" )
Constants for AutoUploadable 'state' property values
const InfoPrefix = "info."
InfoPrefix is used to prefix properties in start options, which should be included (with the prefix removed) in the upload status 'info' property.
const StorageProvider = "storage.provider"
StorageProvider hold the name of the storage provider 'start' operation option
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessMode ¶
type AccessMode int
AccessMode type, for restricting files allowed to be dynamically requested for upload
func (AccessMode) MarshalJSON ¶
func (m AccessMode) MarshalJSON() ([]byte, error)
MarshalJSON marshals AccessMode as JSON
func (*AccessMode) Set ¶
func (m *AccessMode) Set(v string) error
Set implements flag.Value Set method
func (AccessMode) String ¶
func (m AccessMode) String() string
String returns string representation of AccessMode
func (*AccessMode) UnmarshalJSON ¶
func (m *AccessMode) UnmarshalJSON(b []byte) error
UnmarshalJSON un-marshals AccessMode from JSON
type AutoUploadable ¶
type AutoUploadable struct {
// contains filtered or unexported fields
}
AutoUploadable feature implementation. Implements all required communication with the backend. Customized with UploadCustomizer
func NewAutoUploadable ¶
func NewAutoUploadable(uploadableCfg *UploadableConfig, handler UploadCustomizer, definitions ...string) (*AutoUploadable, error)
NewAutoUploadable constructs AutoUploadable from the provided configurations
func (*AutoUploadable) Connect ¶
func (u *AutoUploadable) Connect(mqttClient MQTT.Client, edgeCfg *EdgeConfiguration)
Connect AutoUploadable to the Ditto endpoint
func (*AutoUploadable) Disconnect ¶
func (u *AutoUploadable) Disconnect()
Disconnect AutoUploadable from the Ditto endpoint and clean up used resources
func (*AutoUploadable) UpdateProperty ¶
func (u *AutoUploadable) UpdateProperty(featureID string, value interface{})
UpdateProperty sends Ditto message for value update of the given property
func (*AutoUploadable) UploadFiles ¶
func (u *AutoUploadable) UploadFiles(correlationID string, files []string, options map[string]string)
UploadFiles starts the upload of the given files, by sending an upload request with the specified correlation ID and options.
type AutoUploadableState ¶
type AutoUploadableState struct { Active bool `json:"active"` StartTime *time.Time `json:"startTime"` EndTime *time.Time `json:"endTime"` }
AutoUploadableState is used for serializing the state property of the AutoUploadable feature
type BrokerConfig ¶
type BrokerConfig struct { Broker string `json:"broker,omitempty" def:"tcp://localhost:1883" descr:"Local MQTT broker address"` Username string `json:"username,omitempty" descr:"Username for authorized local client"` Password string `json:"password,omitempty" descr:"Password for authorized local client"` CaCert string `json:"caCert,omitempty" descr:"A PEM encoded CA certificates 'file' for MQTT broker connection"` Cert string `json:"cert,omitempty" descr:"A PEM encoded certificate 'file' for MQTT broker connection"` Key string `json:"key,omitempty" descr:"A PEM encoded unencrypted private key 'file' for MQTT broker connection"` }
BrokerConfig contains address and credentials for the MQTT broker
type Duration ¶
Duration is custom type of type time.Duration in order to add json unmarshal support
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON unmarshal duration type
type EdgeClient ¶
type EdgeClient interface { Connect(client MQTT.Client, cfg *EdgeConfiguration) Disconnect() }
EdgeClient receives notifications of Edge Thing configuration changes from EdgeConnector
type EdgeConfiguration ¶
type EdgeConfiguration struct { DeviceID string `json:"deviceId"` TenantID string `json:"tenantId"` PolicyID string `json:"policyId"` }
EdgeConfiguration represents local Edge Thing configuration - its device, tenant and policy identifiers.
type EdgeConnector ¶
type EdgeConnector struct {
// contains filtered or unexported fields
}
EdgeConnector listens for Edge Thing configuration changes and notifies the corresponding EdgeClient
func NewEdgeConnector ¶
func NewEdgeConnector(cfg *BrokerConfig, ecl EdgeClient) (*EdgeConnector, error)
NewEdgeConnector create EdgeConnector with the given BrokerConfig for the given EdgeClient
type ErrorCode ¶
type ErrorCode string
ErrorCode for Ditto error response
const ( ErrorCodeParameterInvalid ErrorCode = "messages:parameter.invalid" ErrorCodeExecutionFailed = "messages:execution.failed" )
Error code constants
type ErrorResponse ¶
type ErrorResponse struct { Status int `json:"status"` ErrorCode ErrorCode `json:"error"` Message string `json:"message"` }
ErrorResponse is returned from operations handling functions
func (*ErrorResponse) Error ¶
func (e *ErrorResponse) Error() string
type FileUpload ¶
type FileUpload struct {
// contains filtered or unexported fields
}
FileUpload uses the AutoUploadable feature to implement generic file upload. AutoUploadable ss performing all communication with the backend, FileUpload only specifies the files to be uploaded.
func NewFileUpload ¶
func NewFileUpload(filesGlob string, mode AccessMode, uploadableCfg *UploadableConfig) (*FileUpload, error)
NewFileUpload construct FileUpload from the provided configurations
func (*FileUpload) Connect ¶
func (fu *FileUpload) Connect(client MQTT.Client, edgeCfg *EdgeConfiguration)
Connect connects the FileUpload feature to the Ditto endpoint
func (*FileUpload) Disconnect ¶
func (fu *FileUpload) Disconnect()
Disconnect disconnects the FileUpload feature to the Ditto endpoint
func (*FileUpload) DoTrigger ¶
func (fu *FileUpload) DoTrigger(correlationID string, options map[string]string) error
DoTrigger triggers file upload operation. Can be invoked from the backend or from periodic upload tick
func (*FileUpload) HandleOperation ¶
func (fu *FileUpload) HandleOperation(operation string, payload []byte) *ErrorResponse
HandleOperation is invoked from the base AutoUploadable feature to handle unknown operations. FileUpload returns error, because it does not add any new operations to the AutoUploadable feature
func (*FileUpload) OnTick ¶
func (fu *FileUpload) OnTick()
OnTick triggers periodic file uploads. Invoked from the periodic executor in AutoUploadable
type MultiUpload ¶
type MultiUpload struct {
// contains filtered or unexported fields
}
MultiUpload represents a multi-file upload.
type PeriodicExecutor ¶
type PeriodicExecutor struct {
// contains filtered or unexported fields
}
PeriodicExecutor can be used to periodically executed given task in specified time frame.
func NewPeriodicExecutor ¶
func NewPeriodicExecutor(from *time.Time, to *time.Time, period time.Duration, task func()) *PeriodicExecutor
NewPeriodicExecutor constructs a PeriodicExecutor for given time frame (from, to). The task function will be invoked at the specified period.
The executor starts invoking the task when from time is reached. If from is nil of in the past, the executor starts right away. The execution continues till the to time is reached, unless to is nil. In that case execution continues until the Stop is invoked
func (*PeriodicExecutor) Stop ¶
func (e *PeriodicExecutor) Stop()
Stop stops periodic execution and cleans used resources.
type SingleUpload ¶
type SingleUpload struct {
// contains filtered or unexported fields
}
SingleUpload represents a single file upload
func (*SingleUpload) String ¶
func (u *SingleUpload) String() string
type StatusEventsConsumer ¶
type StatusEventsConsumer struct {
// contains filtered or unexported fields
}
StatusEventsConsumer uses a bounded cyclic events queue, safe for concurrent use. When capacity is reached, oldest events in the queue are replaced by newer ones.
func NewStatusEventsConsumer ¶
func NewStatusEventsConsumer(size int) *StatusEventsConsumer
NewStatusEventsConsumer constructs a new StatusEventsConsumer with the given size.
func (*StatusEventsConsumer) Add ¶
func (q *StatusEventsConsumer) Add(e interface{})
Add new event to the queue.
func (*StatusEventsConsumer) Start ¶
func (q *StatusEventsConsumer) Start(consume func(e interface{}))
Start event delivery loop.
type Upload ¶
type Upload interface {
// contains filtered or unexported methods
}
Upload represents single or multi-file upload
type UploadCustomizer ¶
type UploadCustomizer interface { // DoTrigger is responsible for starting file uploads (by calling UploadFiles). // Called when trigger operation is invoked from the backend. DoTrigger(correlationID string, options map[string]string) error // HandleOperation is called when unknown operation is invoked from the backend. // Used when extending AutoUploadable with new operations HandleOperation(operation string, payload []byte) *ErrorResponse // OnTick is called by the periodic executor. Handles AutoUploadable period tasks. OnTick() }
UploadCustomizer is used to customize AutoUploadable behavior.
type UploadStatus ¶
type UploadStatus struct { CorrelationID string `json:"correlationId"` State string `json:"state"` StartTime time.Time `json:"startTime"` EndTime time.Time `json:"endTime"` StatusCode string `json:"statusCode"` Message string `json:"message"` Progress int `json:"progress"` Info map[string]string `json:"info"` }
UploadStatus is used for serializing the 'status' property of the AutoUploadable feature
type UploadStatusListener ¶
type UploadStatusListener interface {
// contains filtered or unexported methods
}
UploadStatusListener is notified on changes in uploads status
type UploadableConfig ¶
type UploadableConfig struct { FeatureID string `` /* 265-byte string literal not displayed */ Context string `` /* 128-byte string literal not displayed */ Type string `json:"type,omitempty" def:"file" descr:"Type of the files, uploaded by {feature} feature."` Period Duration `` /* 243-byte string literal not displayed */ Active bool `json:"active,omitempty" def:"false" descr:"Activate periodic {actions}"` ActiveFrom Xtime `` /* 236-byte string literal not displayed */ ActiveTill Xtime `` /* 222-byte string literal not displayed */ Delete bool `json:"delete,omitempty" def:"false" descr:"Delete successfully uploaded files"` Checksum bool `` /* 162-byte string literal not displayed */ SingleUpload bool `` /* 180-byte string literal not displayed */ StopTimeout Duration `` /* 306-byte string literal not displayed */ ServerCert string `` /* 240-byte string literal not displayed */ }
UploadableConfig contains configuration for the AutoUploadable feature
func (*UploadableConfig) Validate ¶
func (cfg *UploadableConfig) Validate()
Validate checks configuration validity
type Uploads ¶
type Uploads struct {
// contains filtered or unexported fields
}
Uploads maps correlation IDs to Upload instances
func (*Uploads) AddMulti ¶
func (us *Uploads) AddMulti(correlationID string, paths []string, deleteUploaded bool, useChecksum bool, serverCert string, listener UploadStatusListener) []string
AddMulti is used to add an upload, containing multiple files. The provided listener will be notified on the upload progress. If deleteUploaded is true, files will be deleted after successful upload.
func (*Uploads) AddSingle ¶
func (us *Uploads) AddSingle(parent *MultiUpload, correlationID string, filePath string)
AddSingle adds single file upload to a MultiUpload
func (*Uploads) Get ¶
Get returns the upload with the given correlation ID or nil, if the correlation ID is unknown
type Xtime ¶
Xtime is custom stuct, containing a time.Time in order to add json unmarshal support
func (*Xtime) UnmarshalJSON ¶
UnmarshalJSON unmarshal Xtime type