Documentation ¶
Overview ¶
Package twins contains the domain concept definitions needed to support Magistrala twins service functionality. Twin is a digital representation of a real world data system consisting of data producers and consumers. It stores the sequence of attribute based definitions of a data system and refers to a time series of definition based states that store the system historical data.
Index ¶
Constants ¶
const (
SubtopicWildcard = ">"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attribute ¶
type Attribute struct { Name string `json:"name"` Channel string `json:"channel"` Subtopic string `json:"subtopic"` PersistState bool `json:"persist_state"` }
Attribute stores individual attribute data.
type Definition ¶
type Definition struct { ID int `json:"id"` Created time.Time `json:"created"` Attributes []Attribute `json:"attributes"` Delta int64 `json:"delta"` }
Definition stores entity's attributes.
type Page ¶
type Page struct { PageMetadata Twins []Twin }
Page contains page related metadata as well as a list of twins that belong to this page.
type PageMetadata ¶
PageMetadata contains page metadata that helps navigation.
type Service ¶
type Service interface { // AddTwin adds new twin related to user identified by the provided key. AddTwin(ctx context.Context, token string, twin Twin, def Definition) (tw Twin, err error) // UpdateTwin updates twin identified by the provided Twin that // belongs to the user identified by the provided key. UpdateTwin(ctx context.Context, token string, twin Twin, def Definition) (err error) // ViewTwin retrieves data about twin with the provided // ID belonging to the user identified by the provided key. ViewTwin(ctx context.Context, token, twinID string) (tw Twin, err error) // RemoveTwin removes the twin identified with the provided ID, that // belongs to the user identified by the provided key. RemoveTwin(ctx context.Context, token, twinID string) (err error) // ListTwins retrieves data about subset of twins that belongs to the // user identified by the provided key. ListTwins(ctx context.Context, token string, offset uint64, limit uint64, name string, metadata Metadata) (Page, error) // ListStates retrieves data about subset of states that belongs to the // twin identified by the id. ListStates(ctx context.Context, token string, offset uint64, limit uint64, twinID string) (StatesPage, error) // SaveStates persists states into database SaveStates(ctx context.Context, msg *messaging.Message) error }
Service specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics).
func New ¶
func New(publisher messaging.Publisher, auth magistrala.AuthServiceClient, twins TwinRepository, tcache TwinCache, sr StateRepository, idp magistrala.IDProvider, chann string, logger *slog.Logger) Service
New instantiates the twins service implementation.
type State ¶
type State struct { TwinID string ID int64 Definition int Created time.Time Payload map[string]interface{} }
State stores actual snapshot of entity's values.
type StateRepository ¶
type StateRepository interface { // Save persists the state Save(ctx context.Context, state State) error // Update updates the state Update(ctx context.Context, state State) error // Count returns the number of states related to state Count(ctx context.Context, twin Twin) (int64, error) // RetrieveAll retrieves the subset of states related to twin specified by id RetrieveAll(ctx context.Context, offset uint64, limit uint64, twinID string) (StatesPage, error) // RetrieveLast retrieves the last saved state RetrieveLast(ctx context.Context, twinID string) (State, error) }
StateRepository specifies a state persistence API.
type StatesPage ¶
type StatesPage struct { PageMetadata States []State }
StatesPage contains page related metadata as well as a list of twins that belong to this page.
type Twin ¶
type Twin struct { Owner string ID string Name string Created time.Time Updated time.Time Revision int Definitions []Definition Metadata Metadata }
Twin is a Magistrala data system representation. Each twin is owned by a single user, and is assigned with the unique identifier.
type TwinCache ¶
type TwinCache interface { // Save stores twin ID as element of channel-subtopic keyed set and vice versa. Save(ctx context.Context, twin Twin) error // SaveIDs stores twin IDs as elements of channel-subtopic keyed set and vice versa. SaveIDs(ctx context.Context, channel, subtopic string, twinIDs []string) error // Update updates update twin id and channel-subtopic attributes mapping Update(ctx context.Context, twin Twin) error // ID returns twin IDs for given attribute. IDs(ctx context.Context, channel, subtopic string) ([]string, error) // Removes twin from cache based on twin id. Remove(ctx context.Context, twinID string) error }
TwinCache contains twin caching interface.
type TwinRepository ¶
type TwinRepository interface { // Save persists the twin Save(ctx context.Context, twin Twin) (string, error) // Update performs an update to the existing twin. A non-nil error is // returned to indicate operation failure. Update(ctx context.Context, twin Twin) error // RetrieveByID retrieves the twin having the provided identifier. RetrieveByID(ctx context.Context, twinID string) (Twin, error) // RetrieveByAttribute retrieves twin ids whose definition contains // the attribute with given channel and subtopic RetrieveByAttribute(ctx context.Context, channel, subtopic string) ([]string, error) // RetrieveAll retrieves the subset of twins owned by the specified user. RetrieveAll(ctx context.Context, owner string, offset, limit uint64, name string, metadata Metadata) (Page, error) // Remove removes the twin having the provided identifier. Remove(ctx context.Context, twinID string) error }
TwinRepository specifies a twin persistence API.
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. |
Package events provides the domain concept definitions needed to support twins clients events functionality.
|
Package events provides the domain concept definitions needed to support twins clients events functionality. |
Package mocks contains mocks for testing purposes.
|
Package mocks contains mocks for testing purposes. |
Package mongodb contains repository implementations using MongoDB as the underlying database.
|
Package mongodb contains repository implementations using MongoDB as the underlying database. |
Package tracing contains middlewares that will add spans to existing traces.
|
Package tracing contains middlewares that will add spans to existing traces. |