Documentation ¶
Overview ¶
******************************************************************************
- Copyright 2017 Dell Inc. *
- 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. *
- @microservice: core-data-go library
- @author: Ryan Comer, Dell
- @version: 0.5.0 ******************************************************************************
******************************************************************************
- Copyright 2017 Dell Inc. *
- 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. *
- @microservice: core-data-go library
- @author: Ryan Comer, Dell
- @version: 0.5.0 ******************************************************************************
******************************************************************************
- Copyright 2017 Dell Inc. *
- 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. *
- @microservice: core-data-go library
- @author: Ryan Comer, Dell
- @version: 0.5.0 ******************************************************************************
Index ¶
- Constants
- Variables
- type ByReadingCreationDate
- type DBClient
- type DBConfiguration
- type DatabaseType
- type MongoClient
- func (mc *MongoClient) AddEvent(e *models.Event) (bson.ObjectId, error)
- func (mc *MongoClient) AddReading(r models.Reading) (bson.ObjectId, error)
- func (mc *MongoClient) AddValueDescriptor(v models.ValueDescriptor) (bson.ObjectId, error)
- func (mc *MongoClient) DeleteEventById(id string) error
- func (mc *MongoClient) DeleteReadingById(id string) error
- func (mc *MongoClient) DeleteValueDescriptorById(id string) error
- func (mc *MongoClient) EventById(id string) (models.Event, error)
- func (mc *MongoClient) EventCount() (int, error)
- func (mc *MongoClient) EventCountByDeviceId(id string) (int, error)
- func (mc *MongoClient) Events() ([]models.Event, error)
- func (mc *MongoClient) EventsByCreationTime(startTime, endTime int64, limit int) ([]models.Event, error)
- func (mc *MongoClient) EventsForDevice(id string) ([]models.Event, error)
- func (mc *MongoClient) EventsForDeviceLimit(id string, limit int) ([]models.Event, error)
- func (mc *MongoClient) EventsOlderThanAge(age int64) ([]models.Event, error)
- func (mc *MongoClient) EventsPushed() ([]models.Event, error)
- func (mc *MongoClient) GetSessionCopy() *mgo.Session
- func (mc *MongoClient) ReadingById(id string) (models.Reading, error)
- func (mc *MongoClient) ReadingCount() (int, error)
- func (mc *MongoClient) Readings() ([]models.Reading, error)
- func (mc *MongoClient) ReadingsByCreationTime(start, end int64, limit int) ([]models.Reading, error)
- func (mc *MongoClient) ReadingsByDevice(id string, limit int) ([]models.Reading, error)
- func (mc *MongoClient) ReadingsByDeviceAndValueDescriptor(deviceId, valueDescriptor string, limit int) ([]models.Reading, error)
- func (mc *MongoClient) ReadingsByValueDescriptor(name string, limit int) ([]models.Reading, error)
- func (mc *MongoClient) ReadingsByValueDescriptorNames(names []string, limit int) ([]models.Reading, error)
- func (mc *MongoClient) ScrubAllEvents() error
- func (mc *MongoClient) UpdateEvent(e models.Event) error
- func (mc *MongoClient) UpdateReading(r models.Reading) error
- func (mc *MongoClient) UpdateValueDescriptor(v models.ValueDescriptor) error
- func (mc *MongoClient) ValueDescriptorById(id string) (models.ValueDescriptor, error)
- func (mc *MongoClient) ValueDescriptorByName(name string) (models.ValueDescriptor, error)
- func (mc *MongoClient) ValueDescriptors() ([]models.ValueDescriptor, error)
- func (mc *MongoClient) ValueDescriptorsByLabel(label string) ([]models.ValueDescriptor, error)
- func (mc *MongoClient) ValueDescriptorsByName(names []string) ([]models.ValueDescriptor, error)
- func (mc *MongoClient) ValueDescriptorsByType(t string) ([]models.ValueDescriptor, error)
- func (mc *MongoClient) ValueDescriptorsByUomLabel(uomLabel string) ([]models.ValueDescriptor, error)
- type MongoEvent
Constants ¶
const ( EVENTS_COLLECTION = "event" READINGS_COLLECTION = "reading" VALUE_DESCRIPTOR_COLLECTION = "valueDescriptor" )
Variables ¶
var ErrInvalidObjectId error = errors.New("Invalid object ID")
var ErrNotFound error = errors.New("Item not found")
var ErrNotUnique error = errors.New("Resource already exists")
var ErrUnsupportedDatabase error = errors.New("Unsuppored database type")
Functions ¶
This section is empty.
Types ¶
type ByReadingCreationDate ¶
Type used to sort the readings by creation date
func (ByReadingCreationDate) Len ¶
func (a ByReadingCreationDate) Len() int
func (ByReadingCreationDate) Less ¶
func (a ByReadingCreationDate) Less(i, j int) bool
func (ByReadingCreationDate) Swap ¶
func (a ByReadingCreationDate) Swap(i, j int)
type DBClient ¶
type DBClient interface { // ********************** EVENT FUNCTIONS ******************************* // Return all the events // UnexpectedError - failed to retrieve events from the database Events() ([]models.Event, error) // Add a new event // UnexpectedError - failed to add to database // NoValueDescriptor - no existing value descriptor for a reading in the event AddEvent(e *models.Event) (bson.ObjectId, error) // Update an event - do NOT update readings // UnexpectedError - problem updating in database // NotFound - no event with the ID was found UpdateEvent(e models.Event) error // Get an event by id EventById(id string) (models.Event, error) // Get the number of events in Core Data EventCount() (int, error) // Get the number of events in Core Data for the device specified by id EventCountByDeviceId(id string) (int, error) // Delete an event by ID and all of its readings // 404 - Event not found // 503 - Unexpected problems DeleteEventById(id string) error // Get a list of events based on the device id and limit EventsForDeviceLimit(id string, limit int) ([]models.Event, error) // Get a list of events based on the device id EventsForDevice(id string) ([]models.Event, error) // Return a list of events whos creation time is between startTime and endTime // Limit the number of results by limit EventsByCreationTime(startTime, endTime int64, limit int) ([]models.Event, error) // Return a list of readings for a device filtered by the value descriptor and limited by the limit // The readings are linked to the device through an event ReadingsByDeviceAndValueDescriptor(deviceId, valueDescriptor string, limit int) ([]models.Reading, error) // Get events that are older than a age EventsOlderThanAge(age int64) ([]models.Event, error) // Get events that have been pushed (pushed field is not 0) EventsPushed() ([]models.Event, error) ScrubAllEvents() error // ********************* READING FUNCTIONS ************************* // Return a list of readings sorted by reading id Readings() ([]models.Reading, error) // Post a new reading // Check if valuedescriptor exists in the database AddReading(r models.Reading) (bson.ObjectId, error) // Update a reading // 404 - reading cannot be found // 409 - Value descriptor doesn't exist // 503 - unknown issues UpdateReading(r models.Reading) error // Get a reading by ID ReadingById(id string) (models.Reading, error) // Get the number of readings in core data ReadingCount() (int, error) // Delete a reading by ID // 404 - can't find the reading with the given id DeleteReadingById(id string) error // Return a list of readings for the given device (id or name) // 404 - meta data checking enabled and can't find the device // Sort the list of readings on creation date ReadingsByDevice(id string, limit int) ([]models.Reading, error) // Return a list of readings for the given value descriptor // 413 - the number exceeds the current max limit ReadingsByValueDescriptor(name string, limit int) ([]models.Reading, error) // Return a list of readings whose name is in the list of value descriptor names ReadingsByValueDescriptorNames(names []string, limit int) ([]models.Reading, error) // Return a list of readings whos created time is between the start and end times ReadingsByCreationTime(start, end int64, limit int) ([]models.Reading, error) // ************************** VALUE DESCRIPTOR FUNCTIONS *************************** // Add a value descriptor // 409 - Formatting is bad or it is not unique // 503 - Unexpected // TODO: Check for valid printf formatting AddValueDescriptor(v models.ValueDescriptor) (bson.ObjectId, error) // Return a list of all the value descriptors // 513 Service Unavailable - database problems ValueDescriptors() ([]models.ValueDescriptor, error) // Update a value descriptor // First use the ID for identification, then the name // TODO: Check for the valid printf formatting // 404 not found if the value descriptor cannot be found by the identifiers UpdateValueDescriptor(v models.ValueDescriptor) error // Delete a value descriptor based on the ID DeleteValueDescriptorById(id string) error // Return a value descriptor based on the name ValueDescriptorByName(name string) (models.ValueDescriptor, error) // Return value descriptors based on the names ValueDescriptorsByName(names []string) ([]models.ValueDescriptor, error) // Return a value descriptor based on the id ValueDescriptorById(id string) (models.ValueDescriptor, error) // Return value descriptors based on the unit of measure label ValueDescriptorsByUomLabel(uomLabel string) ([]models.ValueDescriptor, error) // Return value descriptors based on the label ValueDescriptorsByLabel(label string) ([]models.ValueDescriptor, error) // Return a list of value descriptors based on their type ValueDescriptorsByType(t string) ([]models.ValueDescriptor, error) }
func NewDBClient ¶
func NewDBClient(config DBConfiguration) (DBClient, error)
Return the dbClient interface
type DBConfiguration ¶
type DatabaseType ¶
type DatabaseType int8 // Database type enum
const (
MONGO DatabaseType = iota
)
type MongoClient ¶
type MongoClient struct { Session *mgo.Session // Mongo database session Database *mgo.Database // Mongo database }
func (*MongoClient) AddEvent ¶
Add a new event UnexpectedError - failed to add to database NoValueDescriptor - no existing value descriptor for a reading in the event
func (*MongoClient) AddReading ¶
Post a new reading
func (*MongoClient) AddValueDescriptor ¶
func (mc *MongoClient) AddValueDescriptor(v models.ValueDescriptor) (bson.ObjectId, error)
Add a value descriptor 409 - Formatting is bad or it is not unique 503 - Unexpected TODO: Check for valid printf formatting
func (*MongoClient) DeleteEventById ¶
func (mc *MongoClient) DeleteEventById(id string) error
Delete an event by ID and all of its readings 404 - Event not found 503 - Unexpected problems
func (*MongoClient) DeleteReadingById ¶
func (mc *MongoClient) DeleteReadingById(id string) error
Delete a reading by ID 404 - can't find the reading with the given id
func (*MongoClient) DeleteValueDescriptorById ¶
func (mc *MongoClient) DeleteValueDescriptorById(id string) error
Delete the value descriptor based on the id Not found error if there isn't a value descriptor for the ID ValueDescriptorStillInUse if the value descriptor is still referenced by readings
func (*MongoClient) EventById ¶
func (mc *MongoClient) EventById(id string) (models.Event, error)
Get an event by id
func (*MongoClient) EventCount ¶
func (mc *MongoClient) EventCount() (int, error)
Get the number of events in Mongo
func (*MongoClient) EventCountByDeviceId ¶
func (mc *MongoClient) EventCountByDeviceId(id string) (int, error)
Get the number of events in Mongo for the device
func (*MongoClient) Events ¶
func (mc *MongoClient) Events() ([]models.Event, error)
Return all the events UnexpectedError - failed to retrieve events from the database Sort the events in descending order by ID
func (*MongoClient) EventsByCreationTime ¶
func (mc *MongoClient) EventsByCreationTime(startTime, endTime int64, limit int) ([]models.Event, error)
Return a list of events whos creation time is between startTime and endTime Limit the number of results by limit
func (*MongoClient) EventsForDevice ¶
func (mc *MongoClient) EventsForDevice(id string) ([]models.Event, error)
Get a list of events based on the device id
func (*MongoClient) EventsForDeviceLimit ¶
Get a list of events based on the device id and limit
func (*MongoClient) EventsOlderThanAge ¶
func (mc *MongoClient) EventsOlderThanAge(age int64) ([]models.Event, error)
Get Events that are older than the given age (defined by age = now - created)
func (*MongoClient) EventsPushed ¶
func (mc *MongoClient) EventsPushed() ([]models.Event, error)
Get all of the events that have been pushed
func (*MongoClient) GetSessionCopy ¶
func (mc *MongoClient) GetSessionCopy() *mgo.Session
Get a copy of the session
func (*MongoClient) ReadingById ¶
func (mc *MongoClient) ReadingById(id string) (models.Reading, error)
Get a reading by ID
func (*MongoClient) ReadingCount ¶
func (mc *MongoClient) ReadingCount() (int, error)
Get the count of readings in Mongo
func (*MongoClient) Readings ¶
func (mc *MongoClient) Readings() ([]models.Reading, error)
Return a list of readings sorted by reading id
func (*MongoClient) ReadingsByCreationTime ¶
func (mc *MongoClient) ReadingsByCreationTime(start, end int64, limit int) ([]models.Reading, error)
Return a list of readings whos creation time is in-between start and end Limit by the limit parameter
func (*MongoClient) ReadingsByDevice ¶
Return a list of readings for the given device (id or name) Sort the list of readings on creation date
func (*MongoClient) ReadingsByDeviceAndValueDescriptor ¶
func (mc *MongoClient) ReadingsByDeviceAndValueDescriptor(deviceId, valueDescriptor string, limit int) ([]models.Reading, error)
Return a list of readings for a device filtered by the value descriptor and limited by the limit The readings are linked to the device through an event
func (*MongoClient) ReadingsByValueDescriptor ¶
Return a list of readings for the given value descriptor Limit by the given limit
func (*MongoClient) ReadingsByValueDescriptorNames ¶
func (mc *MongoClient) ReadingsByValueDescriptorNames(names []string, limit int) ([]models.Reading, error)
Return a list of readings whose name is in the list of value descriptor names
func (*MongoClient) ScrubAllEvents ¶
func (mc *MongoClient) ScrubAllEvents() error
Delete all of the readings and all of the events
func (*MongoClient) UpdateEvent ¶
func (mc *MongoClient) UpdateEvent(e models.Event) error
Update an event - do NOT update readings UnexpectedError - problem updating in database NotFound - no event with the ID was found
func (*MongoClient) UpdateReading ¶
func (mc *MongoClient) UpdateReading(r models.Reading) error
Update a reading 404 - reading cannot be found 409 - Value descriptor doesn't exist 503 - unknown issues
func (*MongoClient) UpdateValueDescriptor ¶
func (mc *MongoClient) UpdateValueDescriptor(v models.ValueDescriptor) error
Update a value descriptor First use the ID for identification, then the name TODO: Check for the valid printf formatting 404 not found if the value descriptor cannot be found by the identifiers
func (*MongoClient) ValueDescriptorById ¶
func (mc *MongoClient) ValueDescriptorById(id string) (models.ValueDescriptor, error)
Return a value descriptor based on the id Return NotFoundError if there is no value descriptor for the id
func (*MongoClient) ValueDescriptorByName ¶
func (mc *MongoClient) ValueDescriptorByName(name string) (models.ValueDescriptor, error)
Return a value descriptor based on the name Can return null if no value descriptor is found
func (*MongoClient) ValueDescriptors ¶
func (mc *MongoClient) ValueDescriptors() ([]models.ValueDescriptor, error)
Return a list of all the value descriptors 513 Service Unavailable - database problems
func (*MongoClient) ValueDescriptorsByLabel ¶
func (mc *MongoClient) ValueDescriptorsByLabel(label string) ([]models.ValueDescriptor, error)
Return value descriptors based on if it has the label
func (*MongoClient) ValueDescriptorsByName ¶
func (mc *MongoClient) ValueDescriptorsByName(names []string) ([]models.ValueDescriptor, error)
Return all of the value descriptors based on the names
func (*MongoClient) ValueDescriptorsByType ¶
func (mc *MongoClient) ValueDescriptorsByType(t string) ([]models.ValueDescriptor, error)
Return value descriptors based on the type
func (*MongoClient) ValueDescriptorsByUomLabel ¶
func (mc *MongoClient) ValueDescriptorsByUomLabel(uomLabel string) ([]models.ValueDescriptor, error)
Return all the value descriptors that match the UOM label
type MongoEvent ¶
Struct that wraps an event to handle DBRefs
func (MongoEvent) GetBSON ¶
func (me MongoEvent) GetBSON() (interface{}, error)
Custom marshaling into mongo