repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
getEventsLimit
func (mc MongoClient) getEventsLimit(q bson.M, limit int) (me []models.Event, err error) { s := mc.getSessionCopy() defer s.Close() // Check if limit is 0 if limit == 0 { return []models.Event{}, nil } err = s.DB(mc.database.Name).C(db.EventsCollection).Find(q).Sort("-modified").Limit(limit).All(&me) if err != nil { return []models.Event{}, errorMap(err) } return }
go
func (mc MongoClient) getEventsLimit(q bson.M, limit int) (me []models.Event, err error) { s := mc.getSessionCopy() defer s.Close() // Check if limit is 0 if limit == 0 { return []models.Event{}, nil } err = s.DB(mc.database.Name).C(db.EventsCollection).Find(q).Sort("-modified").Limit(limit).All(&me) if err != nil { return []models.Event{}, errorMap(err) } return }
[ "func", "(", "mc", "MongoClient", ")", "getEventsLimit", "(", "q", "bson", ".", "M", ",", "limit", "int", ")", "(", "me", "[", "]", "models", ".", "Event", ",", "err", "error", ")", "{", "s", ":=", "mc", ".", "getSessionCopy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n\n", "// Check if limit is 0", "if", "limit", "==", "0", "{", "return", "[", "]", "models", ".", "Event", "{", "}", ",", "nil", "\n", "}", "\n\n", "err", "=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "EventsCollection", ")", ".", "Find", "(", "q", ")", ".", "Sort", "(", "\"", "\"", ")", ".", "Limit", "(", "limit", ")", ".", "All", "(", "&", "me", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "models", ".", "Event", "{", "}", ",", "errorMap", "(", "err", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Get events with a limit // Sort the list before applying the limit so we can return the most recent events
[ "Get", "events", "with", "a", "limit", "Sort", "the", "list", "before", "applying", "the", "limit", "so", "we", "can", "return", "the", "most", "recent", "events" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L215-L229
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
Readings
func (mc MongoClient) Readings() ([]contract.Reading, error) { readings, err := mc.getReadings(nil) if err != nil { return []contract.Reading{}, err } mapped := make([]contract.Reading, 0) for _, r := range readings { mapped = append(mapped, r.ToContract()) } return mapped, nil }
go
func (mc MongoClient) Readings() ([]contract.Reading, error) { readings, err := mc.getReadings(nil) if err != nil { return []contract.Reading{}, err } mapped := make([]contract.Reading, 0) for _, r := range readings { mapped = append(mapped, r.ToContract()) } return mapped, nil }
[ "func", "(", "mc", "MongoClient", ")", "Readings", "(", ")", "(", "[", "]", "contract", ".", "Reading", ",", "error", ")", "{", "readings", ",", "err", ":=", "mc", ".", "getReadings", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "contract", ".", "Reading", "{", "}", ",", "err", "\n", "}", "\n\n", "mapped", ":=", "make", "(", "[", "]", "contract", ".", "Reading", ",", "0", ")", "\n", "for", "_", ",", "r", ":=", "range", "readings", "{", "mapped", "=", "append", "(", "mapped", ",", "r", ".", "ToContract", "(", ")", ")", "\n", "}", "\n", "return", "mapped", ",", "nil", "\n", "}" ]
// Return a list of readings sorted by reading id
[ "Return", "a", "list", "of", "readings", "sorted", "by", "reading", "id" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L260-L271
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
AddReading
func (mc MongoClient) AddReading(r contract.Reading) (string, error) { s := mc.getSessionCopy() defer s.Close() var mapped models.Reading id, err := mapped.FromContract(r) if err != nil { return "", err } mapped.TimestampForAdd() err = s.DB(mc.database.Name).C(db.ReadingsCollection).Insert(&mapped) if err != nil { return "", errorMap(err) } return id, err }
go
func (mc MongoClient) AddReading(r contract.Reading) (string, error) { s := mc.getSessionCopy() defer s.Close() var mapped models.Reading id, err := mapped.FromContract(r) if err != nil { return "", err } mapped.TimestampForAdd() err = s.DB(mc.database.Name).C(db.ReadingsCollection).Insert(&mapped) if err != nil { return "", errorMap(err) } return id, err }
[ "func", "(", "mc", "MongoClient", ")", "AddReading", "(", "r", "contract", ".", "Reading", ")", "(", "string", ",", "error", ")", "{", "s", ":=", "mc", ".", "getSessionCopy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n\n", "var", "mapped", "models", ".", "Reading", "\n", "id", ",", "err", ":=", "mapped", ".", "FromContract", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "mapped", ".", "TimestampForAdd", "(", ")", "\n\n", "err", "=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "ReadingsCollection", ")", ".", "Insert", "(", "&", "mapped", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errorMap", "(", "err", ")", "\n", "}", "\n", "return", "id", ",", "err", "\n", "}" ]
// Post a new reading
[ "Post", "a", "new", "reading" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L274-L291
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
ReadingCount
func (mc MongoClient) ReadingCount() (int, error) { s := mc.getSessionCopy() defer s.Close() count, err := s.DB(mc.database.Name).C(db.ReadingsCollection).Find(bson.M{}).Count() if err != nil { return 0, errorMap(err) } return count, nil }
go
func (mc MongoClient) ReadingCount() (int, error) { s := mc.getSessionCopy() defer s.Close() count, err := s.DB(mc.database.Name).C(db.ReadingsCollection).Find(bson.M{}).Count() if err != nil { return 0, errorMap(err) } return count, nil }
[ "func", "(", "mc", "MongoClient", ")", "ReadingCount", "(", ")", "(", "int", ",", "error", ")", "{", "s", ":=", "mc", ".", "getSessionCopy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n\n", "count", ",", "err", ":=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "ReadingsCollection", ")", ".", "Find", "(", "bson", ".", "M", "{", "}", ")", ".", "Count", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "errorMap", "(", "err", ")", "\n", "}", "\n", "return", "count", ",", "nil", "\n", "}" ]
// Get the count of readings in Mongo
[ "Get", "the", "count", "of", "readings", "in", "Mongo" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L335-L344
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
ReadingsByValueDescriptor
func (mc MongoClient) ReadingsByValueDescriptor(name string, limit int) ([]contract.Reading, error) { return mapReadings(mc.getReadingsLimit(bson.M{"name": name}, limit)) }
go
func (mc MongoClient) ReadingsByValueDescriptor(name string, limit int) ([]contract.Reading, error) { return mapReadings(mc.getReadingsLimit(bson.M{"name": name}, limit)) }
[ "func", "(", "mc", "MongoClient", ")", "ReadingsByValueDescriptor", "(", "name", "string", ",", "limit", "int", ")", "(", "[", "]", "contract", ".", "Reading", ",", "error", ")", "{", "return", "mapReadings", "(", "mc", ".", "getReadingsLimit", "(", "bson", ".", "M", "{", "\"", "\"", ":", "name", "}", ",", "limit", ")", ")", "\n", "}" ]
// Return a list of readings for the given value descriptor // Limit by the given limit
[ "Return", "a", "list", "of", "readings", "for", "the", "given", "value", "descriptor", "Limit", "by", "the", "given", "limit" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L360-L362
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
ReadingsByValueDescriptorNames
func (mc MongoClient) ReadingsByValueDescriptorNames(names []string, limit int) ([]contract.Reading, error) { return mapReadings(mc.getReadingsLimit(bson.M{"name": bson.M{"$in": names}}, limit)) }
go
func (mc MongoClient) ReadingsByValueDescriptorNames(names []string, limit int) ([]contract.Reading, error) { return mapReadings(mc.getReadingsLimit(bson.M{"name": bson.M{"$in": names}}, limit)) }
[ "func", "(", "mc", "MongoClient", ")", "ReadingsByValueDescriptorNames", "(", "names", "[", "]", "string", ",", "limit", "int", ")", "(", "[", "]", "contract", ".", "Reading", ",", "error", ")", "{", "return", "mapReadings", "(", "mc", ".", "getReadingsLimit", "(", "bson", ".", "M", "{", "\"", "\"", ":", "bson", ".", "M", "{", "\"", "\"", ":", "names", "}", "}", ",", "limit", ")", ")", "\n", "}" ]
// Return a list of readings whose name is in the list of value descriptor names
[ "Return", "a", "list", "of", "readings", "whose", "name", "is", "in", "the", "list", "of", "value", "descriptor", "names" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L365-L367
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
ReadingsByCreationTime
func (mc MongoClient) ReadingsByCreationTime(start, end int64, limit int) ([]contract.Reading, error) { return mapReadings(mc.getReadingsLimit(bson.M{"created": bson.M{"$gte": start, "$lte": end}}, limit)) }
go
func (mc MongoClient) ReadingsByCreationTime(start, end int64, limit int) ([]contract.Reading, error) { return mapReadings(mc.getReadingsLimit(bson.M{"created": bson.M{"$gte": start, "$lte": end}}, limit)) }
[ "func", "(", "mc", "MongoClient", ")", "ReadingsByCreationTime", "(", "start", ",", "end", "int64", ",", "limit", "int", ")", "(", "[", "]", "contract", ".", "Reading", ",", "error", ")", "{", "return", "mapReadings", "(", "mc", ".", "getReadingsLimit", "(", "bson", ".", "M", "{", "\"", "\"", ":", "bson", ".", "M", "{", "\"", "\"", ":", "start", ",", "\"", "\"", ":", "end", "}", "}", ",", "limit", ")", ")", "\n", "}" ]
// Return a list of readings whose creation time is in-between start and end // Limit by the limit parameter
[ "Return", "a", "list", "of", "readings", "whose", "creation", "time", "is", "in", "-", "between", "start", "and", "end", "Limit", "by", "the", "limit", "parameter" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L371-L373
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
getReadingsLimit
func (mc MongoClient) getReadingsLimit(q bson.M, limit int) ([]models.Reading, error) { s := mc.getSessionCopy() defer s.Close() // Check if limit is 0 if limit == 0 { return []models.Reading{}, nil } var readings []models.Reading if err := s.DB(mc.database.Name).C(db.ReadingsCollection).Find(q).Sort("-modified").Limit(limit).All(&readings); err != nil { return []models.Reading{}, errorMap(err) } return readings, nil }
go
func (mc MongoClient) getReadingsLimit(q bson.M, limit int) ([]models.Reading, error) { s := mc.getSessionCopy() defer s.Close() // Check if limit is 0 if limit == 0 { return []models.Reading{}, nil } var readings []models.Reading if err := s.DB(mc.database.Name).C(db.ReadingsCollection).Find(q).Sort("-modified").Limit(limit).All(&readings); err != nil { return []models.Reading{}, errorMap(err) } return readings, nil }
[ "func", "(", "mc", "MongoClient", ")", "getReadingsLimit", "(", "q", "bson", ".", "M", ",", "limit", "int", ")", "(", "[", "]", "models", ".", "Reading", ",", "error", ")", "{", "s", ":=", "mc", ".", "getSessionCopy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n\n", "// Check if limit is 0", "if", "limit", "==", "0", "{", "return", "[", "]", "models", ".", "Reading", "{", "}", ",", "nil", "\n", "}", "\n\n", "var", "readings", "[", "]", "models", ".", "Reading", "\n", "if", "err", ":=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "ReadingsCollection", ")", ".", "Find", "(", "q", ")", ".", "Sort", "(", "\"", "\"", ")", ".", "Limit", "(", "limit", ")", ".", "All", "(", "&", "readings", ")", ";", "err", "!=", "nil", "{", "return", "[", "]", "models", ".", "Reading", "{", "}", ",", "errorMap", "(", "err", ")", "\n", "}", "\n", "return", "readings", ",", "nil", "\n", "}" ]
// Return a list of readings that match. // Sort the list before applying the limit so we can return the most recent readings
[ "Return", "a", "list", "of", "readings", "that", "match", ".", "Sort", "the", "list", "before", "applying", "the", "limit", "so", "we", "can", "return", "the", "most", "recent", "readings" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L383-L397
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
getReading
func (mc MongoClient) getReading(q bson.M) (models.Reading, error) { s := mc.getSessionCopy() defer s.Close() var res models.Reading if err := s.DB(mc.database.Name).C(db.ReadingsCollection).Find(q).One(&res); err != nil { return models.Reading{}, errorMap(err) } return res, nil }
go
func (mc MongoClient) getReading(q bson.M) (models.Reading, error) { s := mc.getSessionCopy() defer s.Close() var res models.Reading if err := s.DB(mc.database.Name).C(db.ReadingsCollection).Find(q).One(&res); err != nil { return models.Reading{}, errorMap(err) } return res, nil }
[ "func", "(", "mc", "MongoClient", ")", "getReading", "(", "q", "bson", ".", "M", ")", "(", "models", ".", "Reading", ",", "error", ")", "{", "s", ":=", "mc", ".", "getSessionCopy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n\n", "var", "res", "models", ".", "Reading", "\n", "if", "err", ":=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "ReadingsCollection", ")", ".", "Find", "(", "q", ")", ".", "One", "(", "&", "res", ")", ";", "err", "!=", "nil", "{", "return", "models", ".", "Reading", "{", "}", ",", "errorMap", "(", "err", ")", "\n", "}", "\n", "return", "res", ",", "nil", "\n", "}" ]
// Get a reading from the database with the passed query
[ "Get", "a", "reading", "from", "the", "database", "with", "the", "passed", "query" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L412-L421
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
DeleteValueDescriptorById
func (mc MongoClient) DeleteValueDescriptorById(id string) error { return mc.deleteById(db.ValueDescriptorCollection, id) }
go
func (mc MongoClient) DeleteValueDescriptorById(id string) error { return mc.deleteById(db.ValueDescriptorCollection, id) }
[ "func", "(", "mc", "MongoClient", ")", "DeleteValueDescriptorById", "(", "id", "string", ")", "error", "{", "return", "mc", ".", "deleteById", "(", "db", ".", "ValueDescriptorCollection", ",", "id", ")", "\n", "}" ]
// 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
[ "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" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L496-L498
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
ValueDescriptorByName
func (mc MongoClient) ValueDescriptorByName(name string) (contract.ValueDescriptor, error) { mvd, err := mc.getValueDescriptor(bson.M{"name": name}) if err != nil { return contract.ValueDescriptor{}, err } return mvd.ToContract(), nil }
go
func (mc MongoClient) ValueDescriptorByName(name string) (contract.ValueDescriptor, error) { mvd, err := mc.getValueDescriptor(bson.M{"name": name}) if err != nil { return contract.ValueDescriptor{}, err } return mvd.ToContract(), nil }
[ "func", "(", "mc", "MongoClient", ")", "ValueDescriptorByName", "(", "name", "string", ")", "(", "contract", ".", "ValueDescriptor", ",", "error", ")", "{", "mvd", ",", "err", ":=", "mc", ".", "getValueDescriptor", "(", "bson", ".", "M", "{", "\"", "\"", ":", "name", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "contract", ".", "ValueDescriptor", "{", "}", ",", "err", "\n", "}", "\n", "return", "mvd", ".", "ToContract", "(", ")", ",", "nil", "\n", "}" ]
// Return a value descriptor based on the name // Can return null if no value descriptor is found
[ "Return", "a", "value", "descriptor", "based", "on", "the", "name", "Can", "return", "null", "if", "no", "value", "descriptor", "is", "found" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L502-L508
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
ValueDescriptorsByName
func (mc MongoClient) ValueDescriptorsByName(names []string) ([]contract.ValueDescriptor, error) { vList := make([]contract.ValueDescriptor, 0) for _, name := range names { v, err := mc.ValueDescriptorByName(name) if err != nil && err != db.ErrNotFound { return []contract.ValueDescriptor{}, err } if err == nil { vList = append(vList, v) } } return vList, nil }
go
func (mc MongoClient) ValueDescriptorsByName(names []string) ([]contract.ValueDescriptor, error) { vList := make([]contract.ValueDescriptor, 0) for _, name := range names { v, err := mc.ValueDescriptorByName(name) if err != nil && err != db.ErrNotFound { return []contract.ValueDescriptor{}, err } if err == nil { vList = append(vList, v) } } return vList, nil }
[ "func", "(", "mc", "MongoClient", ")", "ValueDescriptorsByName", "(", "names", "[", "]", "string", ")", "(", "[", "]", "contract", ".", "ValueDescriptor", ",", "error", ")", "{", "vList", ":=", "make", "(", "[", "]", "contract", ".", "ValueDescriptor", ",", "0", ")", "\n", "for", "_", ",", "name", ":=", "range", "names", "{", "v", ",", "err", ":=", "mc", ".", "ValueDescriptorByName", "(", "name", ")", "\n", "if", "err", "!=", "nil", "&&", "err", "!=", "db", ".", "ErrNotFound", "{", "return", "[", "]", "contract", ".", "ValueDescriptor", "{", "}", ",", "err", "\n", "}", "\n", "if", "err", "==", "nil", "{", "vList", "=", "append", "(", "vList", ",", "v", ")", "\n", "}", "\n", "}", "\n\n", "return", "vList", ",", "nil", "\n", "}" ]
// Return all of the value descriptors based on the names
[ "Return", "all", "of", "the", "value", "descriptors", "based", "on", "the", "names" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L511-L524
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
ValueDescriptorById
func (mc MongoClient) ValueDescriptorById(id string) (contract.ValueDescriptor, error) { query, err := idToBsonM(id) if err != nil { return contract.ValueDescriptor{}, err } mvd, err := mc.getValueDescriptor(query) if err != nil { return contract.ValueDescriptor{}, err } return mvd.ToContract(), nil }
go
func (mc MongoClient) ValueDescriptorById(id string) (contract.ValueDescriptor, error) { query, err := idToBsonM(id) if err != nil { return contract.ValueDescriptor{}, err } mvd, err := mc.getValueDescriptor(query) if err != nil { return contract.ValueDescriptor{}, err } return mvd.ToContract(), nil }
[ "func", "(", "mc", "MongoClient", ")", "ValueDescriptorById", "(", "id", "string", ")", "(", "contract", ".", "ValueDescriptor", ",", "error", ")", "{", "query", ",", "err", ":=", "idToBsonM", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "contract", ".", "ValueDescriptor", "{", "}", ",", "err", "\n", "}", "\n\n", "mvd", ",", "err", ":=", "mc", ".", "getValueDescriptor", "(", "query", ")", "\n", "if", "err", "!=", "nil", "{", "return", "contract", ".", "ValueDescriptor", "{", "}", ",", "err", "\n", "}", "\n", "return", "mvd", ".", "ToContract", "(", ")", ",", "nil", "\n", "}" ]
// Return a value descriptor based on the id // Return NotFoundError if there is no value descriptor for the id
[ "Return", "a", "value", "descriptor", "based", "on", "the", "id", "Return", "NotFoundError", "if", "there", "is", "no", "value", "descriptor", "for", "the", "id" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L528-L539
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
ValueDescriptorsByUomLabel
func (mc MongoClient) ValueDescriptorsByUomLabel(uomLabel string) ([]contract.ValueDescriptor, error) { return mapValueDescriptors(mc.getValueDescriptors(bson.M{"uomLabel": uomLabel})) }
go
func (mc MongoClient) ValueDescriptorsByUomLabel(uomLabel string) ([]contract.ValueDescriptor, error) { return mapValueDescriptors(mc.getValueDescriptors(bson.M{"uomLabel": uomLabel})) }
[ "func", "(", "mc", "MongoClient", ")", "ValueDescriptorsByUomLabel", "(", "uomLabel", "string", ")", "(", "[", "]", "contract", ".", "ValueDescriptor", ",", "error", ")", "{", "return", "mapValueDescriptors", "(", "mc", ".", "getValueDescriptors", "(", "bson", ".", "M", "{", "\"", "\"", ":", "uomLabel", "}", ")", ")", "\n", "}" ]
// Return all the value descriptors that match the UOM label
[ "Return", "all", "the", "value", "descriptors", "that", "match", "the", "UOM", "label" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L542-L544
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
ValueDescriptorsByLabel
func (mc MongoClient) ValueDescriptorsByLabel(label string) ([]contract.ValueDescriptor, error) { return mapValueDescriptors(mc.getValueDescriptors(bson.M{"labels": label})) }
go
func (mc MongoClient) ValueDescriptorsByLabel(label string) ([]contract.ValueDescriptor, error) { return mapValueDescriptors(mc.getValueDescriptors(bson.M{"labels": label})) }
[ "func", "(", "mc", "MongoClient", ")", "ValueDescriptorsByLabel", "(", "label", "string", ")", "(", "[", "]", "contract", ".", "ValueDescriptor", ",", "error", ")", "{", "return", "mapValueDescriptors", "(", "mc", ".", "getValueDescriptors", "(", "bson", ".", "M", "{", "\"", "\"", ":", "label", "}", ")", ")", "\n", "}" ]
// Return value descriptors based on if it has the label
[ "Return", "value", "descriptors", "based", "on", "if", "it", "has", "the", "label" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L547-L549
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
ValueDescriptorsByType
func (mc MongoClient) ValueDescriptorsByType(t string) ([]contract.ValueDescriptor, error) { return mapValueDescriptors(mc.getValueDescriptors(bson.M{"type": t})) }
go
func (mc MongoClient) ValueDescriptorsByType(t string) ([]contract.ValueDescriptor, error) { return mapValueDescriptors(mc.getValueDescriptors(bson.M{"type": t})) }
[ "func", "(", "mc", "MongoClient", ")", "ValueDescriptorsByType", "(", "t", "string", ")", "(", "[", "]", "contract", ".", "ValueDescriptor", ",", "error", ")", "{", "return", "mapValueDescriptors", "(", "mc", ".", "getValueDescriptors", "(", "bson", ".", "M", "{", "\"", "\"", ":", "t", "}", ")", ")", "\n", "}" ]
// Return value descriptors based on the type
[ "Return", "value", "descriptors", "based", "on", "the", "type" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L552-L554
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
ScrubAllValueDescriptors
func (mc MongoClient) ScrubAllValueDescriptors() error { s := mc.getSessionCopy() defer s.Close() if _, err := s.DB(mc.database.Name).C(db.ValueDescriptorCollection).RemoveAll(nil); err != nil { return errorMap(err) } return nil }
go
func (mc MongoClient) ScrubAllValueDescriptors() error { s := mc.getSessionCopy() defer s.Close() if _, err := s.DB(mc.database.Name).C(db.ValueDescriptorCollection).RemoveAll(nil); err != nil { return errorMap(err) } return nil }
[ "func", "(", "mc", "MongoClient", ")", "ScrubAllValueDescriptors", "(", ")", "error", "{", "s", ":=", "mc", ".", "getSessionCopy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n\n", "if", "_", ",", "err", ":=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "ValueDescriptorCollection", ")", ".", "RemoveAll", "(", "nil", ")", ";", "err", "!=", "nil", "{", "return", "errorMap", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Delete all of the value descriptors
[ "Delete", "all", "of", "the", "value", "descriptors" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L557-L565
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
getValueDescriptors
func (mc MongoClient) getValueDescriptors(q bson.M) ([]models.ValueDescriptor, error) { s := mc.getSessionCopy() defer s.Close() var v []models.ValueDescriptor if err := s.DB(mc.database.Name).C(db.ValueDescriptorCollection).Find(q).All(&v); err != nil { return []models.ValueDescriptor{}, errorMap(err) } return v, nil }
go
func (mc MongoClient) getValueDescriptors(q bson.M) ([]models.ValueDescriptor, error) { s := mc.getSessionCopy() defer s.Close() var v []models.ValueDescriptor if err := s.DB(mc.database.Name).C(db.ValueDescriptorCollection).Find(q).All(&v); err != nil { return []models.ValueDescriptor{}, errorMap(err) } return v, nil }
[ "func", "(", "mc", "MongoClient", ")", "getValueDescriptors", "(", "q", "bson", ".", "M", ")", "(", "[", "]", "models", ".", "ValueDescriptor", ",", "error", ")", "{", "s", ":=", "mc", ".", "getSessionCopy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n\n", "var", "v", "[", "]", "models", ".", "ValueDescriptor", "\n", "if", "err", ":=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "ValueDescriptorCollection", ")", ".", "Find", "(", "q", ")", ".", "All", "(", "&", "v", ")", ";", "err", "!=", "nil", "{", "return", "[", "]", "models", ".", "ValueDescriptor", "{", "}", ",", "errorMap", "(", "err", ")", "\n", "}", "\n", "return", "v", ",", "nil", "\n", "}" ]
// Get value descriptors based on the query
[ "Get", "value", "descriptors", "based", "on", "the", "query" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L568-L577
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/data.go
getValueDescriptor
func (mc MongoClient) getValueDescriptor(q bson.M) (models.ValueDescriptor, error) { s := mc.getSessionCopy() defer s.Close() var m models.ValueDescriptor if err := s.DB(mc.database.Name).C(db.ValueDescriptorCollection).Find(q).One(&m); err != nil { return models.ValueDescriptor{}, errorMap(err) } return m, nil }
go
func (mc MongoClient) getValueDescriptor(q bson.M) (models.ValueDescriptor, error) { s := mc.getSessionCopy() defer s.Close() var m models.ValueDescriptor if err := s.DB(mc.database.Name).C(db.ValueDescriptorCollection).Find(q).One(&m); err != nil { return models.ValueDescriptor{}, errorMap(err) } return m, nil }
[ "func", "(", "mc", "MongoClient", ")", "getValueDescriptor", "(", "q", "bson", ".", "M", ")", "(", "models", ".", "ValueDescriptor", ",", "error", ")", "{", "s", ":=", "mc", ".", "getSessionCopy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n\n", "var", "m", "models", ".", "ValueDescriptor", "\n", "if", "err", ":=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "ValueDescriptorCollection", ")", ".", "Find", "(", "q", ")", ".", "One", "(", "&", "m", ")", ";", "err", "!=", "nil", "{", "return", "models", ".", "ValueDescriptor", "{", "}", ",", "errorMap", "(", "err", ")", "\n", "}", "\n", "return", "m", ",", "nil", "\n", "}" ]
// Get a value descriptor based on the query
[ "Get", "a", "value", "descriptor", "based", "on", "the", "query" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/data.go#L592-L601
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/notifications.go
GetSubscriptions
func (mc MongoClient) GetSubscriptions() ([]contract.Subscription, error) { return mc.getSubscriptions(bson.M{}) }
go
func (mc MongoClient) GetSubscriptions() ([]contract.Subscription, error) { return mc.getSubscriptions(bson.M{}) }
[ "func", "(", "mc", "MongoClient", ")", "GetSubscriptions", "(", ")", "(", "[", "]", "contract", ".", "Subscription", ",", "error", ")", "{", "return", "mc", ".", "getSubscriptions", "(", "bson", ".", "M", "{", "}", ")", "\n", "}" ]
// Return all the subscriptions // UnexpectedError - failed to retrieve subscriptions from the database
[ "Return", "all", "the", "subscriptions", "UnexpectedError", "-", "failed", "to", "retrieve", "subscriptions", "from", "the", "database" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/notifications.go#L288-L290
train
edgexfoundry/edgex-go
internal/export/client/server.go
encode
func encode(i interface{}, w http.ResponseWriter) { w.Header().Add("Content-Type", "application/json") enc := json.NewEncoder(w) err := enc.Encode(i) // Problems encoding if err != nil { LoggingClient.Error("Error encoding the data: " + err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } }
go
func encode(i interface{}, w http.ResponseWriter) { w.Header().Add("Content-Type", "application/json") enc := json.NewEncoder(w) err := enc.Encode(i) // Problems encoding if err != nil { LoggingClient.Error("Error encoding the data: " + err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } }
[ "func", "encode", "(", "i", "interface", "{", "}", ",", "w", "http", ".", "ResponseWriter", ")", "{", "w", ".", "Header", "(", ")", ".", "Add", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "enc", ":=", "json", ".", "NewEncoder", "(", "w", ")", "\n", "err", ":=", "enc", ".", "Encode", "(", "i", ")", "\n", "// Problems encoding", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n", "}" ]
// Helper function for encoding things for returning from REST calls
[ "Helper", "function", "for", "encoding", "things", "for", "returning", "from", "REST", "calls" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/export/client/server.go#L32-L43
train
edgexfoundry/edgex-go
internal/core/metadata/rest_provisionwatcher.go
deleteProvisionWatcher
func deleteProvisionWatcher(pw models.ProvisionWatcher, w http.ResponseWriter) error { if err := dbClient.DeleteProvisionWatcherById(pw.Id); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } if err := notifyProvisionWatcherAssociates(pw, http.MethodDelete); err != nil { LoggingClient.Error("Problem notifying associated device services to provision watcher: " + err.Error()) } return nil }
go
func deleteProvisionWatcher(pw models.ProvisionWatcher, w http.ResponseWriter) error { if err := dbClient.DeleteProvisionWatcherById(pw.Id); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } if err := notifyProvisionWatcherAssociates(pw, http.MethodDelete); err != nil { LoggingClient.Error("Problem notifying associated device services to provision watcher: " + err.Error()) } return nil }
[ "func", "deleteProvisionWatcher", "(", "pw", "models", ".", "ProvisionWatcher", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "if", "err", ":=", "dbClient", ".", "DeleteProvisionWatcherById", "(", "pw", ".", "Id", ")", ";", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "notifyProvisionWatcherAssociates", "(", "pw", ",", "http", ".", "MethodDelete", ")", ";", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Delete the provision watcher
[ "Delete", "the", "provision", "watcher" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_provisionwatcher.go#L104-L115
train
edgexfoundry/edgex-go
internal/core/metadata/rest_provisionwatcher.go
restUpdateProvisionWatcher
func restUpdateProvisionWatcher(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() var from models.ProvisionWatcher if err := json.NewDecoder(r.Body).Decode(&from); err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusServiceUnavailable) return } // Check if the provision watcher exists // Try by ID to, err := dbClient.GetProvisionWatcherById(from.Id) if err != nil { // Try by name if to, err = dbClient.GetProvisionWatcherByName(from.Name); err != nil { if err == db.ErrNotFound { http.Error(w, "Provision watcher not found", http.StatusNotFound) LoggingClient.Error("Provision watcher not found: " + err.Error()) } else { LoggingClient.Error("Problem getting provision watcher: " + err.Error()) http.Error(w, err.Error(), http.StatusServiceUnavailable) } return } } if err := updateProvisionWatcherFields(from, &to, w); err != nil { LoggingClient.Error("Problem updating provision watcher: " + err.Error()) return } if err := dbClient.UpdateProvisionWatcher(to); err != nil { LoggingClient.Error("Problem updating provision watcher: " + err.Error()) http.Error(w, err.Error(), http.StatusServiceUnavailable) return } // Notify Associates if err := notifyProvisionWatcherAssociates(to, http.MethodPut); err != nil { LoggingClient.Error("Problem notifying associated device services for provision watcher: " + err.Error()) } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write([]byte("true")) }
go
func restUpdateProvisionWatcher(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() var from models.ProvisionWatcher if err := json.NewDecoder(r.Body).Decode(&from); err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusServiceUnavailable) return } // Check if the provision watcher exists // Try by ID to, err := dbClient.GetProvisionWatcherById(from.Id) if err != nil { // Try by name if to, err = dbClient.GetProvisionWatcherByName(from.Name); err != nil { if err == db.ErrNotFound { http.Error(w, "Provision watcher not found", http.StatusNotFound) LoggingClient.Error("Provision watcher not found: " + err.Error()) } else { LoggingClient.Error("Problem getting provision watcher: " + err.Error()) http.Error(w, err.Error(), http.StatusServiceUnavailable) } return } } if err := updateProvisionWatcherFields(from, &to, w); err != nil { LoggingClient.Error("Problem updating provision watcher: " + err.Error()) return } if err := dbClient.UpdateProvisionWatcher(to); err != nil { LoggingClient.Error("Problem updating provision watcher: " + err.Error()) http.Error(w, err.Error(), http.StatusServiceUnavailable) return } // Notify Associates if err := notifyProvisionWatcherAssociates(to, http.MethodPut); err != nil { LoggingClient.Error("Problem notifying associated device services for provision watcher: " + err.Error()) } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write([]byte("true")) }
[ "func", "restUpdateProvisionWatcher", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "defer", "r", ".", "Body", ".", "Close", "(", ")", "\n", "var", "from", "models", ".", "ProvisionWatcher", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "r", ".", "Body", ")", ".", "Decode", "(", "&", "from", ")", ";", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "\n", "}", "\n\n", "// Check if the provision watcher exists", "// Try by ID", "to", ",", "err", ":=", "dbClient", ".", "GetProvisionWatcherById", "(", "from", ".", "Id", ")", "\n", "if", "err", "!=", "nil", "{", "// Try by name", "if", "to", ",", "err", "=", "dbClient", ".", "GetProvisionWatcherByName", "(", "from", ".", "Name", ")", ";", "err", "!=", "nil", "{", "if", "err", "==", "db", ".", "ErrNotFound", "{", "http", ".", "Error", "(", "w", ",", "\"", "\"", ",", "http", ".", "StatusNotFound", ")", "\n", "LoggingClient", ".", "Error", "(", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "}", "else", "{", "LoggingClient", ".", "Error", "(", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "}", "\n", "return", "\n", "}", "\n", "}", "\n\n", "if", "err", ":=", "updateProvisionWatcherFields", "(", "from", ",", "&", "to", ",", "w", ")", ";", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n\n", "if", "err", ":=", "dbClient", ".", "UpdateProvisionWatcher", "(", "to", ")", ";", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "\n", "}", "\n\n", "// Notify Associates", "if", "err", ":=", "notifyProvisionWatcherAssociates", "(", "to", ",", "http", ".", "MethodPut", ")", ";", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "w", ".", "WriteHeader", "(", "http", ".", "StatusOK", ")", "\n", "w", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\"", ")", ")", "\n", "}" ]
// Update the provision watcher object // ID is used first for identification, then name // The service and profile cannot be updated
[ "Update", "the", "provision", "watcher", "object", "ID", "is", "used", "first", "for", "identification", "then", "name", "The", "service", "and", "profile", "cannot", "be", "updated" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_provisionwatcher.go#L385-L429
train
edgexfoundry/edgex-go
internal/core/metadata/rest_provisionwatcher.go
updateProvisionWatcherFields
func updateProvisionWatcherFields(from models.ProvisionWatcher, to *models.ProvisionWatcher, w http.ResponseWriter) error { if from.Identifiers != nil { to.Identifiers = from.Identifiers } if from.Origin != 0 { to.Origin = from.Origin } if from.Name != "" { // Check that the name is unique checkPW, err := dbClient.GetProvisionWatcherByName(from.Name) if err != nil { if err != db.ErrNotFound { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } } // Found one, compare the IDs to see if its another provision watcher if err != db.ErrNotFound { if checkPW.Id != to.Id { err = errors.New("Duplicate name for the provision watcher") http.Error(w, err.Error(), http.StatusConflict) return err } } to.Name = from.Name } return nil }
go
func updateProvisionWatcherFields(from models.ProvisionWatcher, to *models.ProvisionWatcher, w http.ResponseWriter) error { if from.Identifiers != nil { to.Identifiers = from.Identifiers } if from.Origin != 0 { to.Origin = from.Origin } if from.Name != "" { // Check that the name is unique checkPW, err := dbClient.GetProvisionWatcherByName(from.Name) if err != nil { if err != db.ErrNotFound { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } } // Found one, compare the IDs to see if its another provision watcher if err != db.ErrNotFound { if checkPW.Id != to.Id { err = errors.New("Duplicate name for the provision watcher") http.Error(w, err.Error(), http.StatusConflict) return err } } to.Name = from.Name } return nil }
[ "func", "updateProvisionWatcherFields", "(", "from", "models", ".", "ProvisionWatcher", ",", "to", "*", "models", ".", "ProvisionWatcher", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "if", "from", ".", "Identifiers", "!=", "nil", "{", "to", ".", "Identifiers", "=", "from", ".", "Identifiers", "\n", "}", "\n", "if", "from", ".", "Origin", "!=", "0", "{", "to", ".", "Origin", "=", "from", ".", "Origin", "\n", "}", "\n", "if", "from", ".", "Name", "!=", "\"", "\"", "{", "// Check that the name is unique", "checkPW", ",", "err", ":=", "dbClient", ".", "GetProvisionWatcherByName", "(", "from", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "!=", "db", ".", "ErrNotFound", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "// Found one, compare the IDs to see if its another provision watcher", "if", "err", "!=", "db", ".", "ErrNotFound", "{", "if", "checkPW", ".", "Id", "!=", "to", ".", "Id", "{", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusConflict", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "to", ".", "Name", "=", "from", ".", "Name", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Update the relevant fields of the provision watcher
[ "Update", "the", "relevant", "fields", "of", "the", "provision", "watcher" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_provisionwatcher.go#L432-L460
train
edgexfoundry/edgex-go
internal/core/metadata/rest_provisionwatcher.go
notifyProvisionWatcherAssociates
func notifyProvisionWatcherAssociates(pw models.ProvisionWatcher, action string) error { // Get the device service for the provision watcher ds, err := dbClient.GetDeviceServiceById(pw.Service.Id) if err != nil { return err } // Notify the service if err = notifyAssociates([]models.DeviceService{ds}, pw.Id, action, models.PROVISIONWATCHER); err != nil { return err } return nil }
go
func notifyProvisionWatcherAssociates(pw models.ProvisionWatcher, action string) error { // Get the device service for the provision watcher ds, err := dbClient.GetDeviceServiceById(pw.Service.Id) if err != nil { return err } // Notify the service if err = notifyAssociates([]models.DeviceService{ds}, pw.Id, action, models.PROVISIONWATCHER); err != nil { return err } return nil }
[ "func", "notifyProvisionWatcherAssociates", "(", "pw", "models", ".", "ProvisionWatcher", ",", "action", "string", ")", "error", "{", "// Get the device service for the provision watcher", "ds", ",", "err", ":=", "dbClient", ".", "GetDeviceServiceById", "(", "pw", ".", "Service", ".", "Id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Notify the service", "if", "err", "=", "notifyAssociates", "(", "[", "]", "models", ".", "DeviceService", "{", "ds", "}", ",", "pw", ".", "Id", ",", "action", ",", "models", ".", "PROVISIONWATCHER", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Notify the associated device services for the provision watcher
[ "Notify", "the", "associated", "device", "services", "for", "the", "provision", "watcher" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_provisionwatcher.go#L463-L476
train
edgexfoundry/edgex-go
internal/core/data/device.go
updateDeviceLastReportedConnected
func updateDeviceLastReportedConnected(device string) { // Config set to skip update last reported if !Configuration.Writable.DeviceUpdateLastConnected { LoggingClient.Debug("Skipping update of device connected/reported times for: " + device) return } d, err := mdc.CheckForDevice(device, context.Background()) if err != nil { LoggingClient.Error("Error getting device " + device + ": " + err.Error()) return } // Couldn't find device if len(d.Name) == 0 { LoggingClient.Error("Error updating device connected/reported times. Unknown device with identifier of: " + device) return } t := db.MakeTimestamp() // Found device, now update lastReported //Use of context.Background because this function is invoked asynchronously from a channel err = mdc.UpdateLastConnectedByName(d.Name, t, context.Background()) if err != nil { LoggingClient.Error("Problems updating last connected value for device: " + d.Name) return } err = mdc.UpdateLastReportedByName(d.Name, t, context.Background()) if err != nil { LoggingClient.Error("Problems updating last reported value for device: " + d.Name) } return }
go
func updateDeviceLastReportedConnected(device string) { // Config set to skip update last reported if !Configuration.Writable.DeviceUpdateLastConnected { LoggingClient.Debug("Skipping update of device connected/reported times for: " + device) return } d, err := mdc.CheckForDevice(device, context.Background()) if err != nil { LoggingClient.Error("Error getting device " + device + ": " + err.Error()) return } // Couldn't find device if len(d.Name) == 0 { LoggingClient.Error("Error updating device connected/reported times. Unknown device with identifier of: " + device) return } t := db.MakeTimestamp() // Found device, now update lastReported //Use of context.Background because this function is invoked asynchronously from a channel err = mdc.UpdateLastConnectedByName(d.Name, t, context.Background()) if err != nil { LoggingClient.Error("Problems updating last connected value for device: " + d.Name) return } err = mdc.UpdateLastReportedByName(d.Name, t, context.Background()) if err != nil { LoggingClient.Error("Problems updating last reported value for device: " + d.Name) } return }
[ "func", "updateDeviceLastReportedConnected", "(", "device", "string", ")", "{", "// Config set to skip update last reported", "if", "!", "Configuration", ".", "Writable", ".", "DeviceUpdateLastConnected", "{", "LoggingClient", ".", "Debug", "(", "\"", "\"", "+", "device", ")", "\n", "return", "\n", "}", "\n\n", "d", ",", "err", ":=", "mdc", ".", "CheckForDevice", "(", "device", ",", "context", ".", "Background", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "\"", "\"", "+", "device", "+", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n\n", "// Couldn't find device", "if", "len", "(", "d", ".", "Name", ")", "==", "0", "{", "LoggingClient", ".", "Error", "(", "\"", "\"", "+", "device", ")", "\n", "return", "\n", "}", "\n\n", "t", ":=", "db", ".", "MakeTimestamp", "(", ")", "\n", "// Found device, now update lastReported", "//Use of context.Background because this function is invoked asynchronously from a channel", "err", "=", "mdc", ".", "UpdateLastConnectedByName", "(", "d", ".", "Name", ",", "t", ",", "context", ".", "Background", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "\"", "\"", "+", "d", ".", "Name", ")", "\n", "return", "\n", "}", "\n", "err", "=", "mdc", ".", "UpdateLastReportedByName", "(", "d", ".", "Name", ",", "t", ",", "context", ".", "Background", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "\"", "\"", "+", "d", ".", "Name", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Update when the device was last reported connected
[ "Update", "when", "the", "device", "was", "last", "reported", "connected" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/data/device.go#L23-L55
train
edgexfoundry/edgex-go
internal/core/data/device.go
updateDeviceServiceLastReportedConnected
func updateDeviceServiceLastReportedConnected(device string) { if !Configuration.Writable.ServiceUpdateLastConnected { LoggingClient.Debug("Skipping update of device service connected/reported times for: " + device) return } t := db.MakeTimestamp() // Get the device d, err := mdc.CheckForDevice(device, context.Background()) if err != nil { LoggingClient.Error("Error getting device " + device + ": " + err.Error()) return } // Couldn't find device if len(d.Name) == 0 { LoggingClient.Error("Error updating device connected/reported times. Unknown device with identifier of: " + device) return } // Get the device service s := d.Service if &s == nil { LoggingClient.Error("Error updating device service connected/reported times. Unknown device service in device: " + d.Name) return } //Use of context.Background because this function is invoked asynchronously from a channel msc.UpdateLastConnected(s.Id, t, context.Background()) msc.UpdateLastReported(s.Id, t, context.Background()) }
go
func updateDeviceServiceLastReportedConnected(device string) { if !Configuration.Writable.ServiceUpdateLastConnected { LoggingClient.Debug("Skipping update of device service connected/reported times for: " + device) return } t := db.MakeTimestamp() // Get the device d, err := mdc.CheckForDevice(device, context.Background()) if err != nil { LoggingClient.Error("Error getting device " + device + ": " + err.Error()) return } // Couldn't find device if len(d.Name) == 0 { LoggingClient.Error("Error updating device connected/reported times. Unknown device with identifier of: " + device) return } // Get the device service s := d.Service if &s == nil { LoggingClient.Error("Error updating device service connected/reported times. Unknown device service in device: " + d.Name) return } //Use of context.Background because this function is invoked asynchronously from a channel msc.UpdateLastConnected(s.Id, t, context.Background()) msc.UpdateLastReported(s.Id, t, context.Background()) }
[ "func", "updateDeviceServiceLastReportedConnected", "(", "device", "string", ")", "{", "if", "!", "Configuration", ".", "Writable", ".", "ServiceUpdateLastConnected", "{", "LoggingClient", ".", "Debug", "(", "\"", "\"", "+", "device", ")", "\n", "return", "\n", "}", "\n\n", "t", ":=", "db", ".", "MakeTimestamp", "(", ")", "\n\n", "// Get the device", "d", ",", "err", ":=", "mdc", ".", "CheckForDevice", "(", "device", ",", "context", ".", "Background", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "\"", "\"", "+", "device", "+", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n\n", "// Couldn't find device", "if", "len", "(", "d", ".", "Name", ")", "==", "0", "{", "LoggingClient", ".", "Error", "(", "\"", "\"", "+", "device", ")", "\n", "return", "\n", "}", "\n\n", "// Get the device service", "s", ":=", "d", ".", "Service", "\n", "if", "&", "s", "==", "nil", "{", "LoggingClient", ".", "Error", "(", "\"", "\"", "+", "d", ".", "Name", ")", "\n", "return", "\n", "}", "\n\n", "//Use of context.Background because this function is invoked asynchronously from a channel", "msc", ".", "UpdateLastConnected", "(", "s", ".", "Id", ",", "t", ",", "context", ".", "Background", "(", ")", ")", "\n", "msc", ".", "UpdateLastReported", "(", "s", ".", "Id", ",", "t", ",", "context", ".", "Background", "(", ")", ")", "\n", "}" ]
// Update when the device service was last reported connected
[ "Update", "when", "the", "device", "service", "was", "last", "reported", "connected" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/data/device.go#L58-L89
train
edgexfoundry/edgex-go
internal/pkg/db/redis/queries.go
getObjectsByRangeFilter
func getObjectsByRangeFilter(conn redis.Conn, key string, filter string, start, end int) (objects [][]byte, err error) { ids, err := redis.Values(conn.Do("ZRANGE", key, start, end)) if err != nil && err != redis.ErrNil { return nil, err } // https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating fids := ids[:0] if len(ids) > 0 { for _, id := range ids { err := conn.Send("ZSCORE", filter, id) if err != nil { return nil, err } } scores, err := redis.Strings(conn.Do("")) if err != nil { return nil, err } for i, score := range scores { if score != "" { fids = append(fids, ids[i]) } } objects, err = redis.ByteSlices(conn.Do("MGET", fids...)) if err != nil { return nil, err } } return objects, nil }
go
func getObjectsByRangeFilter(conn redis.Conn, key string, filter string, start, end int) (objects [][]byte, err error) { ids, err := redis.Values(conn.Do("ZRANGE", key, start, end)) if err != nil && err != redis.ErrNil { return nil, err } // https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating fids := ids[:0] if len(ids) > 0 { for _, id := range ids { err := conn.Send("ZSCORE", filter, id) if err != nil { return nil, err } } scores, err := redis.Strings(conn.Do("")) if err != nil { return nil, err } for i, score := range scores { if score != "" { fids = append(fids, ids[i]) } } objects, err = redis.ByteSlices(conn.Do("MGET", fids...)) if err != nil { return nil, err } } return objects, nil }
[ "func", "getObjectsByRangeFilter", "(", "conn", "redis", ".", "Conn", ",", "key", "string", ",", "filter", "string", ",", "start", ",", "end", "int", ")", "(", "objects", "[", "]", "[", "]", "byte", ",", "err", "error", ")", "{", "ids", ",", "err", ":=", "redis", ".", "Values", "(", "conn", ".", "Do", "(", "\"", "\"", ",", "key", ",", "start", ",", "end", ")", ")", "\n", "if", "err", "!=", "nil", "&&", "err", "!=", "redis", ".", "ErrNil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating", "fids", ":=", "ids", "[", ":", "0", "]", "\n", "if", "len", "(", "ids", ")", ">", "0", "{", "for", "_", ",", "id", ":=", "range", "ids", "{", "err", ":=", "conn", ".", "Send", "(", "\"", "\"", ",", "filter", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "scores", ",", "err", ":=", "redis", ".", "Strings", "(", "conn", ".", "Do", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "for", "i", ",", "score", ":=", "range", "scores", "{", "if", "score", "!=", "\"", "\"", "{", "fids", "=", "append", "(", "fids", ",", "ids", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n\n", "objects", ",", "err", "=", "redis", ".", "ByteSlices", "(", "conn", ".", "Do", "(", "\"", "\"", ",", "fids", "...", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "objects", ",", "nil", "\n", "}" ]
// Return objects by a score from a zset // if limit is 0, all are returned // if end is negative, it is considered as positive infinity
[ "Return", "objects", "by", "a", "score", "from", "a", "zset", "if", "limit", "is", "0", "all", "are", "returned", "if", "end", "is", "negative", "it", "is", "considered", "as", "positive", "infinity" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/queries.go#L132-L164
train
edgexfoundry/edgex-go
internal/pkg/db/redis/queries.go
addObject
func addObject(data []byte, adder models.Adder, id string, conn redis.Conn) { _ = conn.Send("SET", id, data) for _, cmd := range adder.Add() { switch cmd.Command { case "ZADD": _ = conn.Send(cmd.Command, cmd.Hash, cmd.Rank, cmd.Key) case "SADD": _ = conn.Send(cmd.Command, cmd.Hash, cmd.Key) case "HSET": _ = conn.Send(cmd.Command, cmd.Hash, cmd.Key, cmd.Value) } } }
go
func addObject(data []byte, adder models.Adder, id string, conn redis.Conn) { _ = conn.Send("SET", id, data) for _, cmd := range adder.Add() { switch cmd.Command { case "ZADD": _ = conn.Send(cmd.Command, cmd.Hash, cmd.Rank, cmd.Key) case "SADD": _ = conn.Send(cmd.Command, cmd.Hash, cmd.Key) case "HSET": _ = conn.Send(cmd.Command, cmd.Hash, cmd.Key, cmd.Value) } } }
[ "func", "addObject", "(", "data", "[", "]", "byte", ",", "adder", "models", ".", "Adder", ",", "id", "string", ",", "conn", "redis", ".", "Conn", ")", "{", "_", "=", "conn", ".", "Send", "(", "\"", "\"", ",", "id", ",", "data", ")", "\n\n", "for", "_", ",", "cmd", ":=", "range", "adder", ".", "Add", "(", ")", "{", "switch", "cmd", ".", "Command", "{", "case", "\"", "\"", ":", "_", "=", "conn", ".", "Send", "(", "cmd", ".", "Command", ",", "cmd", ".", "Hash", ",", "cmd", ".", "Rank", ",", "cmd", ".", "Key", ")", "\n", "case", "\"", "\"", ":", "_", "=", "conn", ".", "Send", "(", "cmd", ".", "Command", ",", "cmd", ".", "Hash", ",", "cmd", ".", "Key", ")", "\n", "case", "\"", "\"", ":", "_", "=", "conn", ".", "Send", "(", "cmd", ".", "Command", ",", "cmd", ".", "Hash", ",", "cmd", ".", "Key", ",", "cmd", ".", "Value", ")", "\n", "}", "\n", "}", "\n", "}" ]
// addObject is responsible for setting the object's primary record and then sending the appropriate // follow-on commands as provided by the caller. // Transactions are managed outside of this function.
[ "addObject", "is", "responsible", "for", "setting", "the", "object", "s", "primary", "record", "and", "then", "sending", "the", "appropriate", "follow", "-", "on", "commands", "as", "provided", "by", "the", "caller", ".", "Transactions", "are", "managed", "outside", "of", "this", "function", "." ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/queries.go#L196-L209
train
edgexfoundry/edgex-go
internal/pkg/db/redis/queries.go
deleteObject
func deleteObject(remover models.Remover, id string, conn redis.Conn) { _ = conn.Send("DEL", id) for _, cmd := range remover.Remove() { switch cmd.Command { case "ZREM": case "SREM": case "HDEL": _ = conn.Send(cmd.Command, cmd.Hash, cmd.Key) } } }
go
func deleteObject(remover models.Remover, id string, conn redis.Conn) { _ = conn.Send("DEL", id) for _, cmd := range remover.Remove() { switch cmd.Command { case "ZREM": case "SREM": case "HDEL": _ = conn.Send(cmd.Command, cmd.Hash, cmd.Key) } } }
[ "func", "deleteObject", "(", "remover", "models", ".", "Remover", ",", "id", "string", ",", "conn", "redis", ".", "Conn", ")", "{", "_", "=", "conn", ".", "Send", "(", "\"", "\"", ",", "id", ")", "\n\n", "for", "_", ",", "cmd", ":=", "range", "remover", ".", "Remove", "(", ")", "{", "switch", "cmd", ".", "Command", "{", "case", "\"", "\"", ":", "case", "\"", "\"", ":", "case", "\"", "\"", ":", "_", "=", "conn", ".", "Send", "(", "cmd", ".", "Command", ",", "cmd", ".", "Hash", ",", "cmd", ".", "Key", ")", "\n", "}", "\n", "}", "\n", "}" ]
// deleteObject is responsible for removing the object's primary record and then sending the appropriate // follow-on commands as provided by the caller. // // Transactions are managed outside of this function.
[ "deleteObject", "is", "responsible", "for", "removing", "the", "object", "s", "primary", "record", "and", "then", "sending", "the", "appropriate", "follow", "-", "on", "commands", "as", "provided", "by", "the", "caller", ".", "Transactions", "are", "managed", "outside", "of", "this", "function", "." ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/queries.go#L215-L226
train
edgexfoundry/edgex-go
internal/core/command/get.go
NewGetCommand
func NewGetCommand(device contract.Device, command contract.Command, context context.Context, httpCaller internal.HttpCaller) (Executor, error) { url := device.Service.Addressable.GetBaseURL() + strings.Replace(command.Get.Action.Path, DEVICEIDURLPARAM, device.Id, -1) request, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return serviceCommand{}, err } correlationID := context.Value(clients.CorrelationHeader) if correlationID != nil { request.Header.Set(clients.CorrelationHeader, correlationID.(string)) } return serviceCommand{ Device: device, HttpCaller: httpCaller, Request: request, }, nil }
go
func NewGetCommand(device contract.Device, command contract.Command, context context.Context, httpCaller internal.HttpCaller) (Executor, error) { url := device.Service.Addressable.GetBaseURL() + strings.Replace(command.Get.Action.Path, DEVICEIDURLPARAM, device.Id, -1) request, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return serviceCommand{}, err } correlationID := context.Value(clients.CorrelationHeader) if correlationID != nil { request.Header.Set(clients.CorrelationHeader, correlationID.(string)) } return serviceCommand{ Device: device, HttpCaller: httpCaller, Request: request, }, nil }
[ "func", "NewGetCommand", "(", "device", "contract", ".", "Device", ",", "command", "contract", ".", "Command", ",", "context", "context", ".", "Context", ",", "httpCaller", "internal", ".", "HttpCaller", ")", "(", "Executor", ",", "error", ")", "{", "url", ":=", "device", ".", "Service", ".", "Addressable", ".", "GetBaseURL", "(", ")", "+", "strings", ".", "Replace", "(", "command", ".", "Get", ".", "Action", ".", "Path", ",", "DEVICEIDURLPARAM", ",", "device", ".", "Id", ",", "-", "1", ")", "\n", "request", ",", "err", ":=", "http", ".", "NewRequest", "(", "http", ".", "MethodGet", ",", "url", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "serviceCommand", "{", "}", ",", "err", "\n", "}", "\n\n", "correlationID", ":=", "context", ".", "Value", "(", "clients", ".", "CorrelationHeader", ")", "\n", "if", "correlationID", "!=", "nil", "{", "request", ".", "Header", ".", "Set", "(", "clients", ".", "CorrelationHeader", ",", "correlationID", ".", "(", "string", ")", ")", "\n", "}", "\n\n", "return", "serviceCommand", "{", "Device", ":", "device", ",", "HttpCaller", ":", "httpCaller", ",", "Request", ":", "request", ",", "}", ",", "nil", "\n", "}" ]
// NewGetCommand creates and Executor which can be used to execute the GET related command.
[ "NewGetCommand", "creates", "and", "Executor", "which", "can", "be", "used", "to", "execute", "the", "GET", "related", "command", "." ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/command/get.go#L26-L43
train
edgexfoundry/edgex-go
internal/export/distro/httpsender.go
newHTTPSender
func newHTTPSender(addr contract.Addressable) sender { sender := httpSender{ url: addr.Protocol + "://" + addr.Address + ":" + strconv.Itoa(addr.Port) + addr.Path, method: addr.HTTPMethod, } return sender }
go
func newHTTPSender(addr contract.Addressable) sender { sender := httpSender{ url: addr.Protocol + "://" + addr.Address + ":" + strconv.Itoa(addr.Port) + addr.Path, method: addr.HTTPMethod, } return sender }
[ "func", "newHTTPSender", "(", "addr", "contract", ".", "Addressable", ")", "sender", "{", "sender", ":=", "httpSender", "{", "url", ":", "addr", ".", "Protocol", "+", "\"", "\"", "+", "addr", ".", "Address", "+", "\"", "\"", "+", "strconv", ".", "Itoa", "(", "addr", ".", "Port", ")", "+", "addr", ".", "Path", ",", "method", ":", "addr", ".", "HTTPMethod", ",", "}", "\n", "return", "sender", "\n", "}" ]
// newHTTPSender - create http sender
[ "newHTTPSender", "-", "create", "http", "sender" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/export/distro/httpsender.go#L34-L41
train
edgexfoundry/edgex-go
internal/export/distro/httpsender.go
Send
func (sender httpSender) Send(data []byte, event *models.Event) bool { switch sender.method { case http.MethodPost: ctx := context.WithValue(context.Background(), clients.CorrelationHeader, event.CorrelationId) req, err := http.NewRequest(http.MethodPost, sender.url, bytes.NewReader(data)) if err != nil { return false } req.Header.Set("Content-Type", mimeTypeJSON) c := clients.NewCorrelatedRequest(req, ctx) client := &http.Client{} begin := time.Now() response, err := client.Do(c.Request) if err != nil { LoggingClient.Error(err.Error(), clients.CorrelationHeader, event.CorrelationId, internal.LogDurationKey, time.Since(begin).String()) return false } defer response.Body.Close() LoggingClient.Info(fmt.Sprintf("Response: %s", response.Status), clients.CorrelationHeader, event.CorrelationId, internal.LogDurationKey, time.Since(begin).String()) default: LoggingClient.Info(fmt.Sprintf("Unsupported method: %s", sender.method)) return false } LoggingClient.Info(fmt.Sprintf("Sent data: %X", data)) return true }
go
func (sender httpSender) Send(data []byte, event *models.Event) bool { switch sender.method { case http.MethodPost: ctx := context.WithValue(context.Background(), clients.CorrelationHeader, event.CorrelationId) req, err := http.NewRequest(http.MethodPost, sender.url, bytes.NewReader(data)) if err != nil { return false } req.Header.Set("Content-Type", mimeTypeJSON) c := clients.NewCorrelatedRequest(req, ctx) client := &http.Client{} begin := time.Now() response, err := client.Do(c.Request) if err != nil { LoggingClient.Error(err.Error(), clients.CorrelationHeader, event.CorrelationId, internal.LogDurationKey, time.Since(begin).String()) return false } defer response.Body.Close() LoggingClient.Info(fmt.Sprintf("Response: %s", response.Status), clients.CorrelationHeader, event.CorrelationId, internal.LogDurationKey, time.Since(begin).String()) default: LoggingClient.Info(fmt.Sprintf("Unsupported method: %s", sender.method)) return false } LoggingClient.Info(fmt.Sprintf("Sent data: %X", data)) return true }
[ "func", "(", "sender", "httpSender", ")", "Send", "(", "data", "[", "]", "byte", ",", "event", "*", "models", ".", "Event", ")", "bool", "{", "switch", "sender", ".", "method", "{", "case", "http", ".", "MethodPost", ":", "ctx", ":=", "context", ".", "WithValue", "(", "context", ".", "Background", "(", ")", ",", "clients", ".", "CorrelationHeader", ",", "event", ".", "CorrelationId", ")", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "http", ".", "MethodPost", ",", "sender", ".", "url", ",", "bytes", ".", "NewReader", "(", "data", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "mimeTypeJSON", ")", "\n\n", "c", ":=", "clients", ".", "NewCorrelatedRequest", "(", "req", ",", "ctx", ")", "\n", "client", ":=", "&", "http", ".", "Client", "{", "}", "\n", "begin", ":=", "time", ".", "Now", "(", ")", "\n", "response", ",", "err", ":=", "client", ".", "Do", "(", "c", ".", "Request", ")", "\n", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ",", "clients", ".", "CorrelationHeader", ",", "event", ".", "CorrelationId", ",", "internal", ".", "LogDurationKey", ",", "time", ".", "Since", "(", "begin", ")", ".", "String", "(", ")", ")", "\n", "return", "false", "\n", "}", "\n", "defer", "response", ".", "Body", ".", "Close", "(", ")", "\n", "LoggingClient", ".", "Info", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "response", ".", "Status", ")", ",", "clients", ".", "CorrelationHeader", ",", "event", ".", "CorrelationId", ",", "internal", ".", "LogDurationKey", ",", "time", ".", "Since", "(", "begin", ")", ".", "String", "(", ")", ")", "\n", "default", ":", "LoggingClient", ".", "Info", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "sender", ".", "method", ")", ")", "\n", "return", "false", "\n", "}", "\n\n", "LoggingClient", ".", "Info", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "data", ")", ")", "\n", "return", "true", "\n", "}" ]
// Send will send the optionally filtered, compressed, encypted contract.Event via HTTP POST // The model.Event is provided in order to obtain the necessary correlation-id.
[ "Send", "will", "send", "the", "optionally", "filtered", "compressed", "encypted", "contract", ".", "Event", "via", "HTTP", "POST", "The", "model", ".", "Event", "is", "provided", "in", "order", "to", "obtain", "the", "necessary", "correlation", "-", "id", "." ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/export/distro/httpsender.go#L45-L73
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/client.go
NewClient
func NewClient(config db.Configuration) (MongoClient, error) { m := MongoClient{} // Create the dial info for the Mongo session connectionString := config.Host + ":" + strconv.Itoa(config.Port) mongoDBDialInfo := &mgo.DialInfo{ Addrs: []string{connectionString}, Timeout: time.Duration(config.Timeout) * time.Millisecond, Database: config.DatabaseName, Username: config.Username, Password: config.Password, } session, err := mgo.DialWithInfo(mongoDBDialInfo) if err != nil { return m, err } m.session = session m.database = session.DB(config.DatabaseName) currentMongoClient = m // Set the singleton return m, nil }
go
func NewClient(config db.Configuration) (MongoClient, error) { m := MongoClient{} // Create the dial info for the Mongo session connectionString := config.Host + ":" + strconv.Itoa(config.Port) mongoDBDialInfo := &mgo.DialInfo{ Addrs: []string{connectionString}, Timeout: time.Duration(config.Timeout) * time.Millisecond, Database: config.DatabaseName, Username: config.Username, Password: config.Password, } session, err := mgo.DialWithInfo(mongoDBDialInfo) if err != nil { return m, err } m.session = session m.database = session.DB(config.DatabaseName) currentMongoClient = m // Set the singleton return m, nil }
[ "func", "NewClient", "(", "config", "db", ".", "Configuration", ")", "(", "MongoClient", ",", "error", ")", "{", "m", ":=", "MongoClient", "{", "}", "\n\n", "// Create the dial info for the Mongo session", "connectionString", ":=", "config", ".", "Host", "+", "\"", "\"", "+", "strconv", ".", "Itoa", "(", "config", ".", "Port", ")", "\n", "mongoDBDialInfo", ":=", "&", "mgo", ".", "DialInfo", "{", "Addrs", ":", "[", "]", "string", "{", "connectionString", "}", ",", "Timeout", ":", "time", ".", "Duration", "(", "config", ".", "Timeout", ")", "*", "time", ".", "Millisecond", ",", "Database", ":", "config", ".", "DatabaseName", ",", "Username", ":", "config", ".", "Username", ",", "Password", ":", "config", ".", "Password", ",", "}", "\n", "session", ",", "err", ":=", "mgo", ".", "DialWithInfo", "(", "mongoDBDialInfo", ")", "\n", "if", "err", "!=", "nil", "{", "return", "m", ",", "err", "\n", "}", "\n\n", "m", ".", "session", "=", "session", "\n", "m", ".", "database", "=", "session", ".", "DB", "(", "config", ".", "DatabaseName", ")", "\n\n", "currentMongoClient", "=", "m", "// Set the singleton", "\n", "return", "m", ",", "nil", "\n", "}" ]
// Return a pointer to the MongoClient
[ "Return", "a", "pointer", "to", "the", "MongoClient" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/client.go#L32-L54
train
edgexfoundry/edgex-go
internal/support/logging/types.go
SetLogLevel
func (l privLogger) SetLogLevel(logLevel string) error { if logger.IsValidLogLevel(logLevel) == true { *l.logLevel = logLevel return nil } return types.ErrNotFound{} }
go
func (l privLogger) SetLogLevel(logLevel string) error { if logger.IsValidLogLevel(logLevel) == true { *l.logLevel = logLevel return nil } return types.ErrNotFound{} }
[ "func", "(", "l", "privLogger", ")", "SetLogLevel", "(", "logLevel", "string", ")", "error", "{", "if", "logger", ".", "IsValidLogLevel", "(", "logLevel", ")", "==", "true", "{", "*", "l", ".", "logLevel", "=", "logLevel", "\n", "return", "nil", "\n", "}", "\n", "return", "types", ".", "ErrNotFound", "{", "}", "\n", "}" ]
// SetLogLevel sets logger log level
[ "SetLogLevel", "sets", "logger", "log", "level" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/support/logging/types.go#L105-L111
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/metadata.go
GetDeviceProfilesByCommandId
func (mc MongoClient) GetDeviceProfilesByCommandId(id string) ([]contract.DeviceProfile, error) { command, err := mc.getCommandById(id) if err != nil { return []contract.DeviceProfile{}, err } dps, err := mc.getDeviceProfiles(bson.M{"commands.$id": command.Id}) if err != nil { return []contract.DeviceProfile{}, err } return dps, nil }
go
func (mc MongoClient) GetDeviceProfilesByCommandId(id string) ([]contract.DeviceProfile, error) { command, err := mc.getCommandById(id) if err != nil { return []contract.DeviceProfile{}, err } dps, err := mc.getDeviceProfiles(bson.M{"commands.$id": command.Id}) if err != nil { return []contract.DeviceProfile{}, err } return dps, nil }
[ "func", "(", "mc", "MongoClient", ")", "GetDeviceProfilesByCommandId", "(", "id", "string", ")", "(", "[", "]", "contract", ".", "DeviceProfile", ",", "error", ")", "{", "command", ",", "err", ":=", "mc", ".", "getCommandById", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "contract", ".", "DeviceProfile", "{", "}", ",", "err", "\n", "}", "\n\n", "dps", ",", "err", ":=", "mc", ".", "getDeviceProfiles", "(", "bson", ".", "M", "{", "\"", "\"", ":", "command", ".", "Id", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "contract", ".", "DeviceProfile", "{", "}", ",", "err", "\n", "}", "\n", "return", "dps", ",", "nil", "\n", "}" ]
// Get the device profiles that are currently using the command
[ "Get", "the", "device", "profiles", "that", "are", "currently", "using", "the", "command" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/metadata.go#L393-L404
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/metadata.go
DeleteCommandById
func (mc MongoClient) DeleteCommandById(id string) error { s := mc.session.Copy() defer s.Close() col := s.DB(mc.database.Name).C(db.Command) // Check if the command is still in use findParameters, err := idToBsonM(id) if err != nil { return err } query := bson.M{"commands": bson.M{"$elemMatch": findParameters}} count, err := s.DB(mc.database.Name).C(db.DeviceProfile).Find(query).Count() if err != nil { return errorMap(err) } if count > 0 { return db.ErrCommandStillInUse } // remove the command n, v, err := idToQueryParameters(id) if err != nil { return err } return errorMap(col.Remove(bson.D{{Name: n, Value: v}})) }
go
func (mc MongoClient) DeleteCommandById(id string) error { s := mc.session.Copy() defer s.Close() col := s.DB(mc.database.Name).C(db.Command) // Check if the command is still in use findParameters, err := idToBsonM(id) if err != nil { return err } query := bson.M{"commands": bson.M{"$elemMatch": findParameters}} count, err := s.DB(mc.database.Name).C(db.DeviceProfile).Find(query).Count() if err != nil { return errorMap(err) } if count > 0 { return db.ErrCommandStillInUse } // remove the command n, v, err := idToQueryParameters(id) if err != nil { return err } return errorMap(col.Remove(bson.D{{Name: n, Value: v}})) }
[ "func", "(", "mc", "MongoClient", ")", "DeleteCommandById", "(", "id", "string", ")", "error", "{", "s", ":=", "mc", ".", "session", ".", "Copy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n", "col", ":=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "Command", ")", "\n\n", "// Check if the command is still in use", "findParameters", ",", "err", ":=", "idToBsonM", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "query", ":=", "bson", ".", "M", "{", "\"", "\"", ":", "bson", ".", "M", "{", "\"", "\"", ":", "findParameters", "}", "}", "\n", "count", ",", "err", ":=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "DeviceProfile", ")", ".", "Find", "(", "query", ")", ".", "Count", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errorMap", "(", "err", ")", "\n", "}", "\n", "if", "count", ">", "0", "{", "return", "db", ".", "ErrCommandStillInUse", "\n", "}", "\n\n", "// remove the command", "n", ",", "v", ",", "err", ":=", "idToQueryParameters", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "errorMap", "(", "col", ".", "Remove", "(", "bson", ".", "D", "{", "{", "Name", ":", "n", ",", "Value", ":", "v", "}", "}", ")", ")", "\n", "}" ]
// Delete the command by ID // Check if the command is still in use by device profiles
[ "Delete", "the", "command", "by", "ID", "Check", "if", "the", "command", "is", "still", "in", "use", "by", "device", "profiles" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/metadata.go#L999-L1024
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/metadata.go
ScrubMetadata
func (mc MongoClient) ScrubMetadata() error { s := mc.session.Copy() defer s.Close() _, err := s.DB(mc.database.Name).C(db.Addressable).RemoveAll(nil) if err != nil { return errorMap(err) } _, err = s.DB(mc.database.Name).C(db.DeviceService).RemoveAll(nil) if err != nil { return errorMap(err) } _, err = s.DB(mc.database.Name).C(db.DeviceProfile).RemoveAll(nil) if err != nil { return errorMap(err) } _, err = s.DB(mc.database.Name).C(db.DeviceReport).RemoveAll(nil) if err != nil { return errorMap(err) } _, err = s.DB(mc.database.Name).C(db.Device).RemoveAll(nil) if err != nil { return errorMap(err) } _, err = s.DB(mc.database.Name).C(db.ProvisionWatcher).RemoveAll(nil) if err != nil { return errorMap(err) } return nil }
go
func (mc MongoClient) ScrubMetadata() error { s := mc.session.Copy() defer s.Close() _, err := s.DB(mc.database.Name).C(db.Addressable).RemoveAll(nil) if err != nil { return errorMap(err) } _, err = s.DB(mc.database.Name).C(db.DeviceService).RemoveAll(nil) if err != nil { return errorMap(err) } _, err = s.DB(mc.database.Name).C(db.DeviceProfile).RemoveAll(nil) if err != nil { return errorMap(err) } _, err = s.DB(mc.database.Name).C(db.DeviceReport).RemoveAll(nil) if err != nil { return errorMap(err) } _, err = s.DB(mc.database.Name).C(db.Device).RemoveAll(nil) if err != nil { return errorMap(err) } _, err = s.DB(mc.database.Name).C(db.ProvisionWatcher).RemoveAll(nil) if err != nil { return errorMap(err) } return nil }
[ "func", "(", "mc", "MongoClient", ")", "ScrubMetadata", "(", ")", "error", "{", "s", ":=", "mc", ".", "session", ".", "Copy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n\n", "_", ",", "err", ":=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "Addressable", ")", ".", "RemoveAll", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errorMap", "(", "err", ")", "\n", "}", "\n", "_", ",", "err", "=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "DeviceService", ")", ".", "RemoveAll", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errorMap", "(", "err", ")", "\n", "}", "\n", "_", ",", "err", "=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "DeviceProfile", ")", ".", "RemoveAll", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errorMap", "(", "err", ")", "\n", "}", "\n", "_", ",", "err", "=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "DeviceReport", ")", ".", "RemoveAll", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errorMap", "(", "err", ")", "\n", "}", "\n", "_", ",", "err", "=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "Device", ")", ".", "RemoveAll", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errorMap", "(", "err", ")", "\n", "}", "\n", "_", ",", "err", "=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "ProvisionWatcher", ")", ".", "RemoveAll", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errorMap", "(", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Scrub all metadata
[ "Scrub", "all", "metadata" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/metadata.go#L1042-L1072
train
edgexfoundry/edgex-go
internal/pkg/db/redis/notifications.go
GetNotifications
func (c Client) GetNotifications() (n []contract.Notification, err error) { conn := c.Pool.Get() defer conn.Close() objects, err := getObjectsByRange(conn, db.Notification, 0, -1) if err != nil { return nil, err } n, err = unmarshalNotifications(objects) if err != nil { return n, err } return n, nil }
go
func (c Client) GetNotifications() (n []contract.Notification, err error) { conn := c.Pool.Get() defer conn.Close() objects, err := getObjectsByRange(conn, db.Notification, 0, -1) if err != nil { return nil, err } n, err = unmarshalNotifications(objects) if err != nil { return n, err } return n, nil }
[ "func", "(", "c", "Client", ")", "GetNotifications", "(", ")", "(", "n", "[", "]", "contract", ".", "Notification", ",", "err", "error", ")", "{", "conn", ":=", "c", ".", "Pool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "objects", ",", "err", ":=", "getObjectsByRange", "(", "conn", ",", "db", ".", "Notification", ",", "0", ",", "-", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "n", ",", "err", "=", "unmarshalNotifications", "(", "objects", ")", "\n", "if", "err", "!=", "nil", "{", "return", "n", ",", "err", "\n", "}", "\n\n", "return", "n", ",", "nil", "\n", "}" ]
// Get all notifications
[ "Get", "all", "notifications" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/notifications.go#L51-L66
train
edgexfoundry/edgex-go
internal/pkg/db/redis/notifications.go
DeleteNotificationsOld
func (c Client) DeleteNotificationsOld(age int) error { conn := c.Pool.Get() defer conn.Close() currentTime := db.MakeTimestamp() end := int64(int(currentTime) - age) objects, err := getObjectsByScore(conn, db.Notification+":modified", 0, end, 0) for _, object := range objects { if len(object) > 0 { var n contract.Notification err := unmarshalObject(object, &n) if err != nil { return err } // Delete processed notification if n.Status != contract.Processed { continue } err = deleteNotification(conn, n.ID) if err != nil { return err } } } return err }
go
func (c Client) DeleteNotificationsOld(age int) error { conn := c.Pool.Get() defer conn.Close() currentTime := db.MakeTimestamp() end := int64(int(currentTime) - age) objects, err := getObjectsByScore(conn, db.Notification+":modified", 0, end, 0) for _, object := range objects { if len(object) > 0 { var n contract.Notification err := unmarshalObject(object, &n) if err != nil { return err } // Delete processed notification if n.Status != contract.Processed { continue } err = deleteNotification(conn, n.ID) if err != nil { return err } } } return err }
[ "func", "(", "c", "Client", ")", "DeleteNotificationsOld", "(", "age", "int", ")", "error", "{", "conn", ":=", "c", ".", "Pool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "currentTime", ":=", "db", ".", "MakeTimestamp", "(", ")", "\n", "end", ":=", "int64", "(", "int", "(", "currentTime", ")", "-", "age", ")", "\n\n", "objects", ",", "err", ":=", "getObjectsByScore", "(", "conn", ",", "db", ".", "Notification", "+", "\"", "\"", ",", "0", ",", "end", ",", "0", ")", "\n\n", "for", "_", ",", "object", ":=", "range", "objects", "{", "if", "len", "(", "object", ")", ">", "0", "{", "var", "n", "contract", ".", "Notification", "\n", "err", ":=", "unmarshalObject", "(", "object", ",", "&", "n", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// Delete processed notification", "if", "n", ".", "Status", "!=", "contract", ".", "Processed", "{", "continue", "\n", "}", "\n", "err", "=", "deleteNotification", "(", "conn", ",", "n", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}" ]
// DeleteNotificationsOld remove all the notifications that are older than the given age
[ "DeleteNotificationsOld", "remove", "all", "the", "notifications", "that", "are", "older", "than", "the", "given", "age" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/notifications.go#L265-L292
train
edgexfoundry/edgex-go
internal/pkg/db/redis/notifications.go
DeleteTransmission
func (c Client) DeleteTransmission(age int64, status contract.TransmissionStatus) error { conn := c.Pool.Get() defer conn.Close() currentTime := db.MakeTimestamp() end := currentTime - age objects, err := getObjectsByRangeFilter(conn, db.Transmission+":modified", db.Transmission+":status:"+fmt.Sprintf("%s", status), 0, int(end)) if err != nil { return err } transmissions, err := unmarshalTransmissions(objects) if err != nil { return err } for _, transmission := range transmissions { err = deleteTransmission(conn, transmission.ID) if err != nil { return err } } return err }
go
func (c Client) DeleteTransmission(age int64, status contract.TransmissionStatus) error { conn := c.Pool.Get() defer conn.Close() currentTime := db.MakeTimestamp() end := currentTime - age objects, err := getObjectsByRangeFilter(conn, db.Transmission+":modified", db.Transmission+":status:"+fmt.Sprintf("%s", status), 0, int(end)) if err != nil { return err } transmissions, err := unmarshalTransmissions(objects) if err != nil { return err } for _, transmission := range transmissions { err = deleteTransmission(conn, transmission.ID) if err != nil { return err } } return err }
[ "func", "(", "c", "Client", ")", "DeleteTransmission", "(", "age", "int64", ",", "status", "contract", ".", "TransmissionStatus", ")", "error", "{", "conn", ":=", "c", ".", "Pool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "currentTime", ":=", "db", ".", "MakeTimestamp", "(", ")", "\n", "end", ":=", "currentTime", "-", "age", "\n\n", "objects", ",", "err", ":=", "getObjectsByRangeFilter", "(", "conn", ",", "db", ".", "Transmission", "+", "\"", "\"", ",", "db", ".", "Transmission", "+", "\"", "\"", "+", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "status", ")", ",", "0", ",", "int", "(", "end", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "transmissions", ",", "err", ":=", "unmarshalTransmissions", "(", "objects", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "for", "_", ",", "transmission", ":=", "range", "transmissions", "{", "err", "=", "deleteTransmission", "(", "conn", ",", "transmission", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}" ]
// DeleteTransmission delete old transmission with specified status
[ "DeleteTransmission", "delete", "old", "transmission", "with", "specified", "status" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/notifications.go#L572-L595
train
edgexfoundry/edgex-go
internal/pkg/db/redis/notifications.go
Cleanup
func (c Client) Cleanup() error { //conn := c.Pool.Get() //defer conn.Close() // //cols := []string{ // db.Transmission, db.Notification, //} // //for _, col := range cols { // err := unlinkCollection(conn, col) // if err != nil { // return err // } //} err := c.CleanupOld(0) if err != nil { return err } return nil }
go
func (c Client) Cleanup() error { //conn := c.Pool.Get() //defer conn.Close() // //cols := []string{ // db.Transmission, db.Notification, //} // //for _, col := range cols { // err := unlinkCollection(conn, col) // if err != nil { // return err // } //} err := c.CleanupOld(0) if err != nil { return err } return nil }
[ "func", "(", "c", "Client", ")", "Cleanup", "(", ")", "error", "{", "//conn := c.Pool.Get()", "//defer conn.Close()", "//", "//cols := []string{", "//\tdb.Transmission, db.Notification,", "//}", "//", "//for _, col := range cols {", "//\terr := unlinkCollection(conn, col)", "//\tif err != nil {", "//\t\treturn err", "//\t}", "//}", "err", ":=", "c", ".", "CleanupOld", "(", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Cleanup delete all notifications and associated transmissions
[ "Cleanup", "delete", "all", "notifications", "and", "associated", "transmissions" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/notifications.go#L598-L617
train
edgexfoundry/edgex-go
internal/pkg/db/redis/notifications.go
CleanupOld
func (c Client) CleanupOld(age int) error { conn := c.Pool.Get() defer conn.Close() currentTime := db.MakeTimestamp() end := currentTime - int64(age) objects, err := getObjectsByScore(conn, db.Notification+":created", 0, end, -1) if err != nil { return err } notifications, err := unmarshalNotifications(objects) if err != nil { return err } for _, notification := range notifications { err = c.DeleteNotificationById(notification.ID) if err != nil { return err } transmissions, err := c.GetTransmissionsByNotificationSlug(notification.Slug, -1) if err != nil { return err } for _, transmission := range transmissions { err = deleteTransmission(conn, transmission.ID) if err != nil { return err } } } return nil }
go
func (c Client) CleanupOld(age int) error { conn := c.Pool.Get() defer conn.Close() currentTime := db.MakeTimestamp() end := currentTime - int64(age) objects, err := getObjectsByScore(conn, db.Notification+":created", 0, end, -1) if err != nil { return err } notifications, err := unmarshalNotifications(objects) if err != nil { return err } for _, notification := range notifications { err = c.DeleteNotificationById(notification.ID) if err != nil { return err } transmissions, err := c.GetTransmissionsByNotificationSlug(notification.Slug, -1) if err != nil { return err } for _, transmission := range transmissions { err = deleteTransmission(conn, transmission.ID) if err != nil { return err } } } return nil }
[ "func", "(", "c", "Client", ")", "CleanupOld", "(", "age", "int", ")", "error", "{", "conn", ":=", "c", ".", "Pool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "currentTime", ":=", "db", ".", "MakeTimestamp", "(", ")", "\n", "end", ":=", "currentTime", "-", "int64", "(", "age", ")", "\n", "objects", ",", "err", ":=", "getObjectsByScore", "(", "conn", ",", "db", ".", "Notification", "+", "\"", "\"", ",", "0", ",", "end", ",", "-", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "notifications", ",", "err", ":=", "unmarshalNotifications", "(", "objects", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "for", "_", ",", "notification", ":=", "range", "notifications", "{", "err", "=", "c", ".", "DeleteNotificationById", "(", "notification", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "transmissions", ",", "err", ":=", "c", ".", "GetTransmissionsByNotificationSlug", "(", "notification", ".", "Slug", ",", "-", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "transmission", ":=", "range", "transmissions", "{", "err", "=", "deleteTransmission", "(", "conn", ",", "transmission", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Cleanup delete old notifications and associated transmissions
[ "Cleanup", "delete", "old", "notifications", "and", "associated", "transmissions" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/notifications.go#L620-L654
train
edgexfoundry/edgex-go
internal/seed/config/populate.go
ImportProperties
func ImportProperties(root string) error { err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { if err != nil { return err } // Skip directories & unacceptable property extension if info.IsDir() || !isAcceptablePropertyExtensions(info.Name()) { return nil } dir, file := filepath.Split(path) appKey := parseDirectoryName(dir) LoggingClient.Debug(fmt.Sprintf("dir: %s file: %s", appKey, file)) props, err := readPropertiesFile(path) if err != nil { return err } registryConfig := types.Config{ Host: Configuration.Registry.Host, Port: Configuration.Registry.Port, Type: Configuration.Registry.Type, Stem: Configuration.GlobalPrefix + "/", ServiceKey: appKey, } Registry, err = registry.NewRegistryClient(registryConfig) for key := range props { if err := Registry.PutConfigurationValue(key, []byte(props[key])); err != nil { return err } } return nil }) if err != nil { return err } return nil }
go
func ImportProperties(root string) error { err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { if err != nil { return err } // Skip directories & unacceptable property extension if info.IsDir() || !isAcceptablePropertyExtensions(info.Name()) { return nil } dir, file := filepath.Split(path) appKey := parseDirectoryName(dir) LoggingClient.Debug(fmt.Sprintf("dir: %s file: %s", appKey, file)) props, err := readPropertiesFile(path) if err != nil { return err } registryConfig := types.Config{ Host: Configuration.Registry.Host, Port: Configuration.Registry.Port, Type: Configuration.Registry.Type, Stem: Configuration.GlobalPrefix + "/", ServiceKey: appKey, } Registry, err = registry.NewRegistryClient(registryConfig) for key := range props { if err := Registry.PutConfigurationValue(key, []byte(props[key])); err != nil { return err } } return nil }) if err != nil { return err } return nil }
[ "func", "ImportProperties", "(", "root", "string", ")", "error", "{", "err", ":=", "filepath", ".", "Walk", "(", "root", ",", "func", "(", "path", "string", ",", "info", "os", ".", "FileInfo", ",", "err", "error", ")", "error", "{", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Skip directories & unacceptable property extension", "if", "info", ".", "IsDir", "(", ")", "||", "!", "isAcceptablePropertyExtensions", "(", "info", ".", "Name", "(", ")", ")", "{", "return", "nil", "\n", "}", "\n\n", "dir", ",", "file", ":=", "filepath", ".", "Split", "(", "path", ")", "\n", "appKey", ":=", "parseDirectoryName", "(", "dir", ")", "\n", "LoggingClient", ".", "Debug", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "appKey", ",", "file", ")", ")", "\n", "props", ",", "err", ":=", "readPropertiesFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "registryConfig", ":=", "types", ".", "Config", "{", "Host", ":", "Configuration", ".", "Registry", ".", "Host", ",", "Port", ":", "Configuration", ".", "Registry", ".", "Port", ",", "Type", ":", "Configuration", ".", "Registry", ".", "Type", ",", "Stem", ":", "Configuration", ".", "GlobalPrefix", "+", "\"", "\"", ",", "ServiceKey", ":", "appKey", ",", "}", "\n\n", "Registry", ",", "err", "=", "registry", ".", "NewRegistryClient", "(", "registryConfig", ")", "\n", "for", "key", ":=", "range", "props", "{", "if", "err", ":=", "Registry", ".", "PutConfigurationValue", "(", "key", ",", "[", "]", "byte", "(", "props", "[", "key", "]", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Import properties files for support of legacy Java services.
[ "Import", "properties", "files", "for", "support", "of", "legacy", "Java", "services", "." ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/seed/config/populate.go#L34-L74
train
edgexfoundry/edgex-go
internal/seed/config/populate.go
listDirectories
func listDirectories() [9]string { var names = [9]string{internal.CoreMetaDataServiceKey, internal.CoreCommandServiceKey, internal.CoreDataServiceKey, internal.ExportDistroServiceKey, internal.ExportClientServiceKey, internal.SupportLoggingServiceKey, internal.SupportSchedulerServiceKey, internal.SupportNotificationsServiceKey, internal.SystemManagementAgentServiceKey} for i, name := range names { names[i] = strings.Replace(name, internal.ServiceKeyPrefix, "", 1) } return names }
go
func listDirectories() [9]string { var names = [9]string{internal.CoreMetaDataServiceKey, internal.CoreCommandServiceKey, internal.CoreDataServiceKey, internal.ExportDistroServiceKey, internal.ExportClientServiceKey, internal.SupportLoggingServiceKey, internal.SupportSchedulerServiceKey, internal.SupportNotificationsServiceKey, internal.SystemManagementAgentServiceKey} for i, name := range names { names[i] = strings.Replace(name, internal.ServiceKeyPrefix, "", 1) } return names }
[ "func", "listDirectories", "(", ")", "[", "9", "]", "string", "{", "var", "names", "=", "[", "9", "]", "string", "{", "internal", ".", "CoreMetaDataServiceKey", ",", "internal", ".", "CoreCommandServiceKey", ",", "internal", ".", "CoreDataServiceKey", ",", "internal", ".", "ExportDistroServiceKey", ",", "internal", ".", "ExportClientServiceKey", ",", "internal", ".", "SupportLoggingServiceKey", ",", "internal", ".", "SupportSchedulerServiceKey", ",", "internal", ".", "SupportNotificationsServiceKey", ",", "internal", ".", "SystemManagementAgentServiceKey", "}", "\n\n", "for", "i", ",", "name", ":=", "range", "names", "{", "names", "[", "i", "]", "=", "strings", ".", "Replace", "(", "name", ",", "internal", ".", "ServiceKeyPrefix", ",", "\"", "\"", ",", "1", ")", "\n", "}", "\n\n", "return", "names", "\n", "}" ]
// As services are converted to utilize V2 types, add them to this list and remove from the one above.
[ "As", "services", "are", "converted", "to", "utilize", "V2", "types", "add", "them", "to", "this", "list", "and", "remove", "from", "the", "one", "above", "." ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/seed/config/populate.go#L134-L144
train
edgexfoundry/edgex-go
internal/seed/config/populate.go
readPropertiesFile
func readPropertiesFile(filePath string) (map[string]string, error) { props, err := properties.LoadFile(filePath, properties.UTF8) if err != nil { return nil, err } return props.Map(), nil }
go
func readPropertiesFile(filePath string) (map[string]string, error) { props, err := properties.LoadFile(filePath, properties.UTF8) if err != nil { return nil, err } return props.Map(), nil }
[ "func", "readPropertiesFile", "(", "filePath", "string", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "props", ",", "err", ":=", "properties", ".", "LoadFile", "(", "filePath", ",", "properties", ".", "UTF8", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "props", ".", "Map", "(", ")", ",", "nil", "\n", "}" ]
// Parse a properties file to a map.
[ "Parse", "a", "properties", "file", "to", "a", "map", "." ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/seed/config/populate.go#L189-L196
train
edgexfoundry/edgex-go
internal/seed/config/populate.go
traverse
func traverse(path string, j interface{}) ([]*pair, error) { kvs := make([]*pair, 0) pathPre := "" if path != "" { pathPre = path + "/" } switch j.(type) { case []interface{}: for sk, sv := range j.([]interface{}) { skvs, err := traverse(pathPre+strconv.Itoa(sk), sv) if err != nil { return nil, err } kvs = append(kvs, skvs...) } case map[string]interface{}: for sk, sv := range j.(map[string]interface{}) { skvs, err := traverse(pathPre+sk, sv) if err != nil { return nil, err } kvs = append(kvs, skvs...) } case int: kvs = append(kvs, &pair{Key: path, Value: strconv.Itoa(j.(int))}) case int64: var y int = int(j.(int64)) kvs = append(kvs, &pair{Key: path, Value: strconv.Itoa(y)}) case float64: kvs = append(kvs, &pair{Key: path, Value: strconv.FormatFloat(j.(float64), 'f', -1, 64)}) case bool: kvs = append(kvs, &pair{Key: path, Value: strconv.FormatBool(j.(bool))}) case nil: kvs = append(kvs, &pair{Key: path, Value: ""}) default: kvs = append(kvs, &pair{Key: path, Value: j.(string)}) } return kvs, nil }
go
func traverse(path string, j interface{}) ([]*pair, error) { kvs := make([]*pair, 0) pathPre := "" if path != "" { pathPre = path + "/" } switch j.(type) { case []interface{}: for sk, sv := range j.([]interface{}) { skvs, err := traverse(pathPre+strconv.Itoa(sk), sv) if err != nil { return nil, err } kvs = append(kvs, skvs...) } case map[string]interface{}: for sk, sv := range j.(map[string]interface{}) { skvs, err := traverse(pathPre+sk, sv) if err != nil { return nil, err } kvs = append(kvs, skvs...) } case int: kvs = append(kvs, &pair{Key: path, Value: strconv.Itoa(j.(int))}) case int64: var y int = int(j.(int64)) kvs = append(kvs, &pair{Key: path, Value: strconv.Itoa(y)}) case float64: kvs = append(kvs, &pair{Key: path, Value: strconv.FormatFloat(j.(float64), 'f', -1, 64)}) case bool: kvs = append(kvs, &pair{Key: path, Value: strconv.FormatBool(j.(bool))}) case nil: kvs = append(kvs, &pair{Key: path, Value: ""}) default: kvs = append(kvs, &pair{Key: path, Value: j.(string)}) } return kvs, nil }
[ "func", "traverse", "(", "path", "string", ",", "j", "interface", "{", "}", ")", "(", "[", "]", "*", "pair", ",", "error", ")", "{", "kvs", ":=", "make", "(", "[", "]", "*", "pair", ",", "0", ")", "\n\n", "pathPre", ":=", "\"", "\"", "\n", "if", "path", "!=", "\"", "\"", "{", "pathPre", "=", "path", "+", "\"", "\"", "\n", "}", "\n\n", "switch", "j", ".", "(", "type", ")", "{", "case", "[", "]", "interface", "{", "}", ":", "for", "sk", ",", "sv", ":=", "range", "j", ".", "(", "[", "]", "interface", "{", "}", ")", "{", "skvs", ",", "err", ":=", "traverse", "(", "pathPre", "+", "strconv", ".", "Itoa", "(", "sk", ")", ",", "sv", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "kvs", "=", "append", "(", "kvs", ",", "skvs", "...", ")", "\n", "}", "\n", "case", "map", "[", "string", "]", "interface", "{", "}", ":", "for", "sk", ",", "sv", ":=", "range", "j", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "skvs", ",", "err", ":=", "traverse", "(", "pathPre", "+", "sk", ",", "sv", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "kvs", "=", "append", "(", "kvs", ",", "skvs", "...", ")", "\n", "}", "\n", "case", "int", ":", "kvs", "=", "append", "(", "kvs", ",", "&", "pair", "{", "Key", ":", "path", ",", "Value", ":", "strconv", ".", "Itoa", "(", "j", ".", "(", "int", ")", ")", "}", ")", "\n", "case", "int64", ":", "var", "y", "int", "=", "int", "(", "j", ".", "(", "int64", ")", ")", "\n\n", "kvs", "=", "append", "(", "kvs", ",", "&", "pair", "{", "Key", ":", "path", ",", "Value", ":", "strconv", ".", "Itoa", "(", "y", ")", "}", ")", "\n", "case", "float64", ":", "kvs", "=", "append", "(", "kvs", ",", "&", "pair", "{", "Key", ":", "path", ",", "Value", ":", "strconv", ".", "FormatFloat", "(", "j", ".", "(", "float64", ")", ",", "'f'", ",", "-", "1", ",", "64", ")", "}", ")", "\n", "case", "bool", ":", "kvs", "=", "append", "(", "kvs", ",", "&", "pair", "{", "Key", ":", "path", ",", "Value", ":", "strconv", ".", "FormatBool", "(", "j", ".", "(", "bool", ")", ")", "}", ")", "\n", "case", "nil", ":", "kvs", "=", "append", "(", "kvs", ",", "&", "pair", "{", "Key", ":", "path", ",", "Value", ":", "\"", "\"", "}", ")", "\n", "default", ":", "kvs", "=", "append", "(", "kvs", ",", "&", "pair", "{", "Key", ":", "path", ",", "Value", ":", "j", ".", "(", "string", ")", "}", ")", "\n", "}", "\n\n", "return", "kvs", ",", "nil", "\n", "}" ]
// Traverse or walk hierarchical configuration in preparation for loading into Registry
[ "Traverse", "or", "walk", "hierarchical", "configuration", "in", "preparation", "for", "loading", "into", "Registry" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/seed/config/populate.go#L229-L272
train
edgexfoundry/edgex-go
internal/export/distro/registrations.go
Loop
func Loop() { go func() { p := fmt.Sprintf(":%d", Configuration.Service.Port) LoggingClient.Info(fmt.Sprintf("Starting Export Distro %s", p)) messageErrors <- http.ListenAndServe(p, httpServer()) }() registrations := make(map[string]*registrationInfo) allRegs, err := getRegistrations() for allRegs == nil { LoggingClient.Info("Waiting for client microservice") select { case e := <-messageErrors: LoggingClient.Error(fmt.Sprintf("exit msg: %s", e.Error())) if err != nil { LoggingClient.Error(fmt.Sprintf("with error: %s", err.Error())) } return case <-time.After(time.Second): } allRegs, err = getRegistrations() } // Create new goroutines for each registration for _, reg := range allRegs { regInfo := newRegistrationInfo() if regInfo.update(reg) { registrations[reg.Name] = regInfo go registrationLoop(regInfo) } } LoggingClient.Info("Starting registration loop") for { select { case e := <-messageErrors: // kill all registration goroutines for k, reg := range registrations { if !reg.deleteFlag { // Do not write in channel that will not be read reg.chRegistration <- nil } delete(registrations, k) } LoggingClient.Error(fmt.Sprintf("exit msg: %s", e.Error())) return case update := <-registrationChanges: LoggingClient.Info("Registration changes") err := updateRunningRegistrations(registrations, update) if err != nil { LoggingClient.Error(err.Error()) LoggingClient.Warn(fmt.Sprintf("Error updating registration %s", update.Name)) } case msgEnvelope := <-messageEnvelopes: LoggingClient.Info(fmt.Sprintf("Event received on message queue. Topic: %s, Correlation-id: %s ", Configuration.MessageQueue.Topic, msgEnvelope.CorrelationID)) if msgEnvelope.ContentType != clients.ContentTypeJSON { LoggingClient.Error(fmt.Sprintf("Incorrect content type for event message. Received: %s, Expected: %s", msgEnvelope.ContentType, clients.ContentTypeJSON)) continue } str := string(msgEnvelope.Payload) event := parseEvent(str) if event == nil { continue } for k, reg := range registrations { if reg.deleteFlag { delete(registrations, k) } else { // TODO only sent event if it is not blocking reg.chEvent <- event } } } } }
go
func Loop() { go func() { p := fmt.Sprintf(":%d", Configuration.Service.Port) LoggingClient.Info(fmt.Sprintf("Starting Export Distro %s", p)) messageErrors <- http.ListenAndServe(p, httpServer()) }() registrations := make(map[string]*registrationInfo) allRegs, err := getRegistrations() for allRegs == nil { LoggingClient.Info("Waiting for client microservice") select { case e := <-messageErrors: LoggingClient.Error(fmt.Sprintf("exit msg: %s", e.Error())) if err != nil { LoggingClient.Error(fmt.Sprintf("with error: %s", err.Error())) } return case <-time.After(time.Second): } allRegs, err = getRegistrations() } // Create new goroutines for each registration for _, reg := range allRegs { regInfo := newRegistrationInfo() if regInfo.update(reg) { registrations[reg.Name] = regInfo go registrationLoop(regInfo) } } LoggingClient.Info("Starting registration loop") for { select { case e := <-messageErrors: // kill all registration goroutines for k, reg := range registrations { if !reg.deleteFlag { // Do not write in channel that will not be read reg.chRegistration <- nil } delete(registrations, k) } LoggingClient.Error(fmt.Sprintf("exit msg: %s", e.Error())) return case update := <-registrationChanges: LoggingClient.Info("Registration changes") err := updateRunningRegistrations(registrations, update) if err != nil { LoggingClient.Error(err.Error()) LoggingClient.Warn(fmt.Sprintf("Error updating registration %s", update.Name)) } case msgEnvelope := <-messageEnvelopes: LoggingClient.Info(fmt.Sprintf("Event received on message queue. Topic: %s, Correlation-id: %s ", Configuration.MessageQueue.Topic, msgEnvelope.CorrelationID)) if msgEnvelope.ContentType != clients.ContentTypeJSON { LoggingClient.Error(fmt.Sprintf("Incorrect content type for event message. Received: %s, Expected: %s", msgEnvelope.ContentType, clients.ContentTypeJSON)) continue } str := string(msgEnvelope.Payload) event := parseEvent(str) if event == nil { continue } for k, reg := range registrations { if reg.deleteFlag { delete(registrations, k) } else { // TODO only sent event if it is not blocking reg.chEvent <- event } } } } }
[ "func", "Loop", "(", ")", "{", "go", "func", "(", ")", "{", "p", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "Configuration", ".", "Service", ".", "Port", ")", "\n", "LoggingClient", ".", "Info", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "p", ")", ")", "\n", "messageErrors", "<-", "http", ".", "ListenAndServe", "(", "p", ",", "httpServer", "(", ")", ")", "\n", "}", "(", ")", "\n\n", "registrations", ":=", "make", "(", "map", "[", "string", "]", "*", "registrationInfo", ")", "\n\n", "allRegs", ",", "err", ":=", "getRegistrations", "(", ")", "\n\n", "for", "allRegs", "==", "nil", "{", "LoggingClient", ".", "Info", "(", "\"", "\"", ")", "\n", "select", "{", "case", "e", ":=", "<-", "messageErrors", ":", "LoggingClient", ".", "Error", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "Error", "(", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ".", "Error", "(", ")", ")", ")", "\n", "}", "\n", "return", "\n", "case", "<-", "time", ".", "After", "(", "time", ".", "Second", ")", ":", "}", "\n", "allRegs", ",", "err", "=", "getRegistrations", "(", ")", "\n", "}", "\n\n", "// Create new goroutines for each registration", "for", "_", ",", "reg", ":=", "range", "allRegs", "{", "regInfo", ":=", "newRegistrationInfo", "(", ")", "\n", "if", "regInfo", ".", "update", "(", "reg", ")", "{", "registrations", "[", "reg", ".", "Name", "]", "=", "regInfo", "\n", "go", "registrationLoop", "(", "regInfo", ")", "\n", "}", "\n", "}", "\n\n", "LoggingClient", ".", "Info", "(", "\"", "\"", ")", "\n", "for", "{", "select", "{", "case", "e", ":=", "<-", "messageErrors", ":", "// kill all registration goroutines", "for", "k", ",", "reg", ":=", "range", "registrations", "{", "if", "!", "reg", ".", "deleteFlag", "{", "// Do not write in channel that will not be read", "reg", ".", "chRegistration", "<-", "nil", "\n", "}", "\n", "delete", "(", "registrations", ",", "k", ")", "\n", "}", "\n", "LoggingClient", ".", "Error", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "Error", "(", ")", ")", ")", "\n", "return", "\n\n", "case", "update", ":=", "<-", "registrationChanges", ":", "LoggingClient", ".", "Info", "(", "\"", "\"", ")", "\n", "err", ":=", "updateRunningRegistrations", "(", "registrations", ",", "update", ")", "\n", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "LoggingClient", ".", "Warn", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "update", ".", "Name", ")", ")", "\n", "}", "\n\n", "case", "msgEnvelope", ":=", "<-", "messageEnvelopes", ":", "LoggingClient", ".", "Info", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "Configuration", ".", "MessageQueue", ".", "Topic", ",", "msgEnvelope", ".", "CorrelationID", ")", ")", "\n", "if", "msgEnvelope", ".", "ContentType", "!=", "clients", ".", "ContentTypeJSON", "{", "LoggingClient", ".", "Error", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "msgEnvelope", ".", "ContentType", ",", "clients", ".", "ContentTypeJSON", ")", ")", "\n", "continue", "\n", "}", "\n", "str", ":=", "string", "(", "msgEnvelope", ".", "Payload", ")", "\n", "event", ":=", "parseEvent", "(", "str", ")", "\n", "if", "event", "==", "nil", "{", "continue", "\n", "}", "\n\n", "for", "k", ",", "reg", ":=", "range", "registrations", "{", "if", "reg", ".", "deleteFlag", "{", "delete", "(", "registrations", ",", "k", ")", "\n", "}", "else", "{", "// TODO only sent event if it is not blocking", "reg", ".", "chEvent", "<-", "event", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// Loop - registration loop
[ "Loop", "-", "registration", "loop" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/export/distro/registrations.go#L275-L354
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceprofile.go
checkDuplicateProfileNames
func checkDuplicateProfileNames(dp models.DeviceProfile, w http.ResponseWriter) error { profiles, err := dbClient.GetAllDeviceProfiles() if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } for _, p := range profiles { if p.Name == dp.Name && p.Id != dp.Id { err = errors.New("Duplicate profile name") http.Error(w, err.Error(), http.StatusConflict) return err } } return nil }
go
func checkDuplicateProfileNames(dp models.DeviceProfile, w http.ResponseWriter) error { profiles, err := dbClient.GetAllDeviceProfiles() if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } for _, p := range profiles { if p.Name == dp.Name && p.Id != dp.Id { err = errors.New("Duplicate profile name") http.Error(w, err.Error(), http.StatusConflict) return err } } return nil }
[ "func", "checkDuplicateProfileNames", "(", "dp", "models", ".", "DeviceProfile", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "profiles", ",", "err", ":=", "dbClient", ".", "GetAllDeviceProfiles", "(", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n\n", "for", "_", ",", "p", ":=", "range", "profiles", "{", "if", "p", ".", "Name", "==", "dp", ".", "Name", "&&", "p", ".", "Id", "!=", "dp", ".", "Id", "{", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusConflict", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Check for duplicate names in device profiles
[ "Check", "for", "duplicate", "names", "in", "device", "profiles" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceprofile.go#L192-L208
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceprofile.go
checkDuplicateCommands
func checkDuplicateCommands(dp models.DeviceProfile, w http.ResponseWriter) error { // Check if there are duplicate names in the device profile command list for _, c1 := range dp.CoreCommands { count := 0 for _, c2 := range dp.CoreCommands { if c1.Name == c2.Name { count += 1 } } if count > 1 { err := errors.New("Error adding device profile: Duplicate names in the commands") http.Error(w, err.Error(), http.StatusConflict) return err } } return nil }
go
func checkDuplicateCommands(dp models.DeviceProfile, w http.ResponseWriter) error { // Check if there are duplicate names in the device profile command list for _, c1 := range dp.CoreCommands { count := 0 for _, c2 := range dp.CoreCommands { if c1.Name == c2.Name { count += 1 } } if count > 1 { err := errors.New("Error adding device profile: Duplicate names in the commands") http.Error(w, err.Error(), http.StatusConflict) return err } } return nil }
[ "func", "checkDuplicateCommands", "(", "dp", "models", ".", "DeviceProfile", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "// Check if there are duplicate names in the device profile command list", "for", "_", ",", "c1", ":=", "range", "dp", ".", "CoreCommands", "{", "count", ":=", "0", "\n", "for", "_", ",", "c2", ":=", "range", "dp", ".", "CoreCommands", "{", "if", "c1", ".", "Name", "==", "c2", ".", "Name", "{", "count", "+=", "1", "\n", "}", "\n", "}", "\n", "if", "count", ">", "1", "{", "err", ":=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusConflict", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Check for duplicate command names in the device profile
[ "Check", "for", "duplicate", "command", "names", "in", "the", "device", "profile" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceprofile.go#L211-L228
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceprofile.go
deleteCommands
func deleteCommands(dp models.DeviceProfile, w http.ResponseWriter) error { for _, command := range dp.CoreCommands { err := dbClient.DeleteCommandById(command.Id) if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } } return nil }
go
func deleteCommands(dp models.DeviceProfile, w http.ResponseWriter) error { for _, command := range dp.CoreCommands { err := dbClient.DeleteCommandById(command.Id) if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } } return nil }
[ "func", "deleteCommands", "(", "dp", "models", ".", "DeviceProfile", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "for", "_", ",", "command", ":=", "range", "dp", ".", "CoreCommands", "{", "err", ":=", "dbClient", ".", "DeleteCommandById", "(", "command", ".", "Id", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Delete all of the commands that are a part of the device profile
[ "Delete", "all", "of", "the", "commands", "that", "are", "a", "part", "of", "the", "device", "profile" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceprofile.go#L231-L241
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceprofile.go
addCommands
func addCommands(dp *models.DeviceProfile, w http.ResponseWriter) error { for i := range dp.CoreCommands { if newId, err := dbClient.AddCommand(dp.CoreCommands[i]); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } else { dp.CoreCommands[i].Id = newId } } return nil }
go
func addCommands(dp *models.DeviceProfile, w http.ResponseWriter) error { for i := range dp.CoreCommands { if newId, err := dbClient.AddCommand(dp.CoreCommands[i]); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } else { dp.CoreCommands[i].Id = newId } } return nil }
[ "func", "addCommands", "(", "dp", "*", "models", ".", "DeviceProfile", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "for", "i", ":=", "range", "dp", ".", "CoreCommands", "{", "if", "newId", ",", "err", ":=", "dbClient", ".", "AddCommand", "(", "dp", ".", "CoreCommands", "[", "i", "]", ")", ";", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "else", "{", "dp", ".", "CoreCommands", "[", "i", "]", ".", "Id", "=", "newId", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Add all of the commands that are a part of the device profile
[ "Add", "all", "of", "the", "commands", "that", "are", "a", "part", "of", "the", "device", "profile" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceprofile.go#L244-L255
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceprofile.go
restDeleteProfileByName
func restDeleteProfileByName(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) n, err := url.QueryUnescape(vars[NAME]) if err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusBadRequest) return } // Check if the device profile exists dp, err := dbClient.GetDeviceProfileByName(n) if err != nil { if err == db.ErrNotFound { http.Error(w, err.Error(), http.StatusNotFound) } else { http.Error(w, err.Error(), http.StatusInternalServerError) } LoggingClient.Error(err.Error()) return } // Delete the device profile if err = deleteDeviceProfile(dp, w); err != nil { LoggingClient.Error(err.Error()) return } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write([]byte("true")) }
go
func restDeleteProfileByName(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) n, err := url.QueryUnescape(vars[NAME]) if err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusBadRequest) return } // Check if the device profile exists dp, err := dbClient.GetDeviceProfileByName(n) if err != nil { if err == db.ErrNotFound { http.Error(w, err.Error(), http.StatusNotFound) } else { http.Error(w, err.Error(), http.StatusInternalServerError) } LoggingClient.Error(err.Error()) return } // Delete the device profile if err = deleteDeviceProfile(dp, w); err != nil { LoggingClient.Error(err.Error()) return } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write([]byte("true")) }
[ "func", "restDeleteProfileByName", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "vars", ":=", "mux", ".", "Vars", "(", "r", ")", "\n", "n", ",", "err", ":=", "url", ".", "QueryUnescape", "(", "vars", "[", "NAME", "]", ")", "\n", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusBadRequest", ")", "\n", "return", "\n", "}", "\n\n", "// Check if the device profile exists", "dp", ",", "err", ":=", "dbClient", ".", "GetDeviceProfileByName", "(", "n", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "db", ".", "ErrNotFound", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusNotFound", ")", "\n", "}", "else", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusInternalServerError", ")", "\n", "}", "\n", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n\n", "// Delete the device profile", "if", "err", "=", "deleteDeviceProfile", "(", "dp", ",", "w", ")", ";", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "w", ".", "WriteHeader", "(", "http", ".", "StatusOK", ")", "\n", "w", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\"", ")", ")", "\n", "}" ]
// Delete the device profile based on its name
[ "Delete", "the", "device", "profile", "based", "on", "its", "name" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceprofile.go#L302-L331
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceprofile.go
deleteDeviceProfile
func deleteDeviceProfile(dp models.DeviceProfile, w http.ResponseWriter) error { // Check if the device profile is still in use by devices d, err := dbClient.GetDevicesByProfileId(dp.Id) // XXX ErrNotFound should always be returned but this is not consistent in the implementations if err == db.ErrNotFound { err = nil d = []models.Device{} } else if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } if len(d) > 0 { err = errors.New("Can't delete device profile, the profile is still in use by a device") http.Error(w, err.Error(), http.StatusConflict) return err } // Check if the device profile is still in use by provision watchers pw, err := dbClient.GetProvisionWatchersByProfileId(dp.Id) if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } if len(pw) > 0 { err = errors.New("Cant delete device profile, the profile is still in use by a provision watcher") http.Error(w, err.Error(), http.StatusConflict) return err } // Delete the profile if err := dbClient.DeleteDeviceProfileById(dp.Id); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } return nil }
go
func deleteDeviceProfile(dp models.DeviceProfile, w http.ResponseWriter) error { // Check if the device profile is still in use by devices d, err := dbClient.GetDevicesByProfileId(dp.Id) // XXX ErrNotFound should always be returned but this is not consistent in the implementations if err == db.ErrNotFound { err = nil d = []models.Device{} } else if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } if len(d) > 0 { err = errors.New("Can't delete device profile, the profile is still in use by a device") http.Error(w, err.Error(), http.StatusConflict) return err } // Check if the device profile is still in use by provision watchers pw, err := dbClient.GetProvisionWatchersByProfileId(dp.Id) if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } if len(pw) > 0 { err = errors.New("Cant delete device profile, the profile is still in use by a provision watcher") http.Error(w, err.Error(), http.StatusConflict) return err } // Delete the profile if err := dbClient.DeleteDeviceProfileById(dp.Id); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } return nil }
[ "func", "deleteDeviceProfile", "(", "dp", "models", ".", "DeviceProfile", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "// Check if the device profile is still in use by devices", "d", ",", "err", ":=", "dbClient", ".", "GetDevicesByProfileId", "(", "dp", ".", "Id", ")", "\n\n", "// XXX ErrNotFound should always be returned but this is not consistent in the implementations", "if", "err", "==", "db", ".", "ErrNotFound", "{", "err", "=", "nil", "\n", "d", "=", "[", "]", "models", ".", "Device", "{", "}", "\n", "}", "else", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n", "if", "len", "(", "d", ")", ">", "0", "{", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusConflict", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Check if the device profile is still in use by provision watchers", "pw", ",", "err", ":=", "dbClient", ".", "GetProvisionWatchersByProfileId", "(", "dp", ".", "Id", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n", "if", "len", "(", "pw", ")", ">", "0", "{", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusConflict", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Delete the profile", "if", "err", ":=", "dbClient", ".", "DeleteDeviceProfileById", "(", "dp", ".", "Id", ")", ";", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Delete the device profile // Make sure there are no devices still using it // Delete the associated commands
[ "Delete", "the", "device", "profile", "Make", "sure", "there", "are", "no", "devices", "still", "using", "it", "Delete", "the", "associated", "commands" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceprofile.go#L336-L373
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceprofile.go
restAddProfileByYamlRaw
func restAddProfileByYamlRaw(w http.ResponseWriter, r *http.Request) { // Get the YAML string body, err := ioutil.ReadAll(r.Body) if err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } addDeviceProfileYaml(body, w) }
go
func restAddProfileByYamlRaw(w http.ResponseWriter, r *http.Request) { // Get the YAML string body, err := ioutil.ReadAll(r.Body) if err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } addDeviceProfileYaml(body, w) }
[ "func", "restAddProfileByYamlRaw", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "// Get the YAML string", "body", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n\n", "addDeviceProfileYaml", "(", "body", ",", "w", ")", "\n", "}" ]
// Add a device profile with YAML content // The YAML content is passed as a string in the http request
[ "Add", "a", "device", "profile", "with", "YAML", "content", "The", "YAML", "content", "is", "passed", "as", "a", "string", "in", "the", "http", "request" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceprofile.go#L408-L418
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceprofile.go
notifyProfileAssociates
func notifyProfileAssociates(dp models.DeviceProfile, action string) error { // Get the devices d, err := dbClient.GetDevicesByProfileId(dp.Id) if err != nil { LoggingClient.Error(err.Error()) return err } // Get the services for each device // Use map as a Set dsMap := map[string]models.DeviceService{} ds := []models.DeviceService{} for _, device := range d { // Only add if not there if _, ok := dsMap[device.Service.Id]; !ok { dsMap[device.Service.Id] = device.Service ds = append(ds, device.Service) } } if err := notifyAssociates(ds, dp.Id, action, models.PROFILE); err != nil { LoggingClient.Error(err.Error()) return err } return nil }
go
func notifyProfileAssociates(dp models.DeviceProfile, action string) error { // Get the devices d, err := dbClient.GetDevicesByProfileId(dp.Id) if err != nil { LoggingClient.Error(err.Error()) return err } // Get the services for each device // Use map as a Set dsMap := map[string]models.DeviceService{} ds := []models.DeviceService{} for _, device := range d { // Only add if not there if _, ok := dsMap[device.Service.Id]; !ok { dsMap[device.Service.Id] = device.Service ds = append(ds, device.Service) } } if err := notifyAssociates(ds, dp.Id, action, models.PROFILE); err != nil { LoggingClient.Error(err.Error()) return err } return nil }
[ "func", "notifyProfileAssociates", "(", "dp", "models", ".", "DeviceProfile", ",", "action", "string", ")", "error", "{", "// Get the devices", "d", ",", "err", ":=", "dbClient", ".", "GetDevicesByProfileId", "(", "dp", ".", "Id", ")", "\n", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Get the services for each device", "// Use map as a Set", "dsMap", ":=", "map", "[", "string", "]", "models", ".", "DeviceService", "{", "}", "\n", "ds", ":=", "[", "]", "models", ".", "DeviceService", "{", "}", "\n", "for", "_", ",", "device", ":=", "range", "d", "{", "// Only add if not there", "if", "_", ",", "ok", ":=", "dsMap", "[", "device", ".", "Service", ".", "Id", "]", ";", "!", "ok", "{", "dsMap", "[", "device", ".", "Service", ".", "Id", "]", "=", "device", ".", "Service", "\n", "ds", "=", "append", "(", "ds", ",", "device", ".", "Service", ")", "\n", "}", "\n", "}", "\n\n", "if", "err", ":=", "notifyAssociates", "(", "ds", ",", "dp", ".", "Id", ",", "action", ",", "models", ".", "PROFILE", ")", ";", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Notify the associated device services for changes in the device profile
[ "Notify", "the", "associated", "device", "services", "for", "changes", "in", "the", "device", "profile" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceprofile.go#L649-L675
train
edgexfoundry/edgex-go
internal/core/metadata/rest_command.go
restUpdateCommand
func restUpdateCommand(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() var c contract.Command if err := json.NewDecoder(r.Body).Decode(&c); err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusBadRequest) return } // Check if command exists (By ID) former, err := dbClient.GetCommandById(c.Id) if err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusNotFound) return } // Name is changed, make sure the new name doesn't conflict with device profile if c.Name != "" { dps, err := dbClient.GetDeviceProfilesByCommandId(c.Id) if err == db.ErrNotFound { err = nil dps = []contract.DeviceProfile{} } else if err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } // Loop through matched device profiles to ensure the name isn't duplicate for _, profile := range dps { for _, command := range profile.CoreCommands { if command.Name == c.Name { err = errors.New("Error updating command: duplicate command name in device profile") LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusConflict) return } } } } // Update the fields if c.Name != "" { former.Name = c.Name } if (c.Get.String() != contract.Get{}.String()) { former.Get = c.Get } if (c.Put.String() != contract.Put{}.String()) { former.Put = c.Put } if err := dbClient.UpdateCommand(c); err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) w.Write([]byte("true")) }
go
func restUpdateCommand(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() var c contract.Command if err := json.NewDecoder(r.Body).Decode(&c); err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusBadRequest) return } // Check if command exists (By ID) former, err := dbClient.GetCommandById(c.Id) if err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusNotFound) return } // Name is changed, make sure the new name doesn't conflict with device profile if c.Name != "" { dps, err := dbClient.GetDeviceProfilesByCommandId(c.Id) if err == db.ErrNotFound { err = nil dps = []contract.DeviceProfile{} } else if err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } // Loop through matched device profiles to ensure the name isn't duplicate for _, profile := range dps { for _, command := range profile.CoreCommands { if command.Name == c.Name { err = errors.New("Error updating command: duplicate command name in device profile") LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusConflict) return } } } } // Update the fields if c.Name != "" { former.Name = c.Name } if (c.Get.String() != contract.Get{}.String()) { former.Get = c.Get } if (c.Put.String() != contract.Put{}.String()) { former.Put = c.Put } if err := dbClient.UpdateCommand(c); err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) w.Write([]byte("true")) }
[ "func", "restUpdateCommand", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "defer", "r", ".", "Body", ".", "Close", "(", ")", "\n", "var", "c", "contract", ".", "Command", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "r", ".", "Body", ")", ".", "Decode", "(", "&", "c", ")", ";", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusBadRequest", ")", "\n", "return", "\n", "}", "\n\n", "// Check if command exists (By ID)", "former", ",", "err", ":=", "dbClient", ".", "GetCommandById", "(", "c", ".", "Id", ")", "\n", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusNotFound", ")", "\n", "return", "\n", "}", "\n\n", "// Name is changed, make sure the new name doesn't conflict with device profile", "if", "c", ".", "Name", "!=", "\"", "\"", "{", "dps", ",", "err", ":=", "dbClient", ".", "GetDeviceProfilesByCommandId", "(", "c", ".", "Id", ")", "\n", "if", "err", "==", "db", ".", "ErrNotFound", "{", "err", "=", "nil", "\n", "dps", "=", "[", "]", "contract", ".", "DeviceProfile", "{", "}", "\n", "}", "else", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n\n", "// Loop through matched device profiles to ensure the name isn't duplicate", "for", "_", ",", "profile", ":=", "range", "dps", "{", "for", "_", ",", "command", ":=", "range", "profile", ".", "CoreCommands", "{", "if", "command", ".", "Name", "==", "c", ".", "Name", "{", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusConflict", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Update the fields", "if", "c", ".", "Name", "!=", "\"", "\"", "{", "former", ".", "Name", "=", "c", ".", "Name", "\n", "}", "\n", "if", "(", "c", ".", "Get", ".", "String", "(", ")", "!=", "contract", ".", "Get", "{", "}", ".", "String", "(", ")", ")", "{", "former", ".", "Get", "=", "c", ".", "Get", "\n", "}", "\n", "if", "(", "c", ".", "Put", ".", "String", "(", ")", "!=", "contract", ".", "Put", "{", "}", ".", "String", "(", ")", ")", "{", "former", ".", "Put", "=", "c", ".", "Put", "\n", "}", "\n\n", "if", "err", ":=", "dbClient", ".", "UpdateCommand", "(", "c", ")", ";", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n\n", "w", ".", "WriteHeader", "(", "http", ".", "StatusOK", ")", "\n", "w", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\"", ")", ")", "\n", "}" ]
// Update a command // 404 if the command can't be found by ID // 409 if the name of the command changes and its not unique to the device profile
[ "Update", "a", "command", "404", "if", "the", "command", "can", "t", "be", "found", "by", "ID", "409", "if", "the", "name", "of", "the", "command", "changes", "and", "its", "not", "unique", "to", "the", "device", "profile" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_command.go#L69-L130
train
edgexfoundry/edgex-go
internal/core/metadata/rest_command.go
restDeleteCommandById
func restDeleteCommandById(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) var id string = vars[ID] // Check if the command exists _, err := dbClient.GetCommandById(id) if err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusNotFound) return } // Check if the command is still in use by a device profile isStillInUse, err := isCommandStillInUse(id) if err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } if isStillInUse { err = errors.New("Can't delete command. Its still in use by Device Profiles") LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusConflict) return } if err := dbClient.DeleteCommandById(id); err != nil { LoggingClient.Error(err.Error()) if err == db.ErrCommandStillInUse { http.Error(w, err.Error(), http.StatusConflict) } else { http.Error(w, err.Error(), http.StatusInternalServerError) } return } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write([]byte("true")) }
go
func restDeleteCommandById(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) var id string = vars[ID] // Check if the command exists _, err := dbClient.GetCommandById(id) if err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusNotFound) return } // Check if the command is still in use by a device profile isStillInUse, err := isCommandStillInUse(id) if err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } if isStillInUse { err = errors.New("Can't delete command. Its still in use by Device Profiles") LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusConflict) return } if err := dbClient.DeleteCommandById(id); err != nil { LoggingClient.Error(err.Error()) if err == db.ErrCommandStillInUse { http.Error(w, err.Error(), http.StatusConflict) } else { http.Error(w, err.Error(), http.StatusInternalServerError) } return } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write([]byte("true")) }
[ "func", "restDeleteCommandById", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "vars", ":=", "mux", ".", "Vars", "(", "r", ")", "\n", "var", "id", "string", "=", "vars", "[", "ID", "]", "\n\n", "// Check if the command exists", "_", ",", "err", ":=", "dbClient", ".", "GetCommandById", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusNotFound", ")", "\n", "return", "\n", "}", "\n\n", "// Check if the command is still in use by a device profile", "isStillInUse", ",", "err", ":=", "isCommandStillInUse", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n", "if", "isStillInUse", "{", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusConflict", ")", "\n", "return", "\n", "}", "\n\n", "if", "err", ":=", "dbClient", ".", "DeleteCommandById", "(", "id", ")", ";", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "if", "err", "==", "db", ".", "ErrCommandStillInUse", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusConflict", ")", "\n", "}", "else", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusInternalServerError", ")", "\n", "}", "\n", "return", "\n", "}", "\n", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "w", ".", "WriteHeader", "(", "http", ".", "StatusOK", ")", "\n", "w", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\"", ")", ")", "\n", "}" ]
// Delete a command by its ID
[ "Delete", "a", "command", "by", "its", "ID" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_command.go#L175-L213
train
edgexfoundry/edgex-go
internal/core/metadata/rest_command.go
isCommandStillInUse
func isCommandStillInUse(id string) (bool, error) { dp, err := dbClient.GetDeviceProfilesByCommandId(id) if err == db.ErrNotFound { // XXX Inconsistent return values. Should be ErrNotFound err = nil } else if err != nil { return false, err } if len(dp) == 0 { return false, err } return true, err }
go
func isCommandStillInUse(id string) (bool, error) { dp, err := dbClient.GetDeviceProfilesByCommandId(id) if err == db.ErrNotFound { // XXX Inconsistent return values. Should be ErrNotFound err = nil } else if err != nil { return false, err } if len(dp) == 0 { return false, err } return true, err }
[ "func", "isCommandStillInUse", "(", "id", "string", ")", "(", "bool", ",", "error", ")", "{", "dp", ",", "err", ":=", "dbClient", ".", "GetDeviceProfilesByCommandId", "(", "id", ")", "\n\n", "if", "err", "==", "db", ".", "ErrNotFound", "{", "// XXX Inconsistent return values. Should be ErrNotFound", "err", "=", "nil", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "if", "len", "(", "dp", ")", "==", "0", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "return", "true", ",", "err", "\n", "}" ]
// Helper function to determine if the command is still in use by device profiles
[ "Helper", "function", "to", "determine", "if", "the", "command", "is", "still", "in", "use", "by", "device", "profiles" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_command.go#L216-L230
train
edgexfoundry/edgex-go
internal/pkg/usage/usage.go
HelpCallback
func HelpCallback() { msg := fmt.Sprintf(usageStr, os.Args[0]) fmt.Printf("%s\n", msg) os.Exit(0) }
go
func HelpCallback() { msg := fmt.Sprintf(usageStr, os.Args[0]) fmt.Printf("%s\n", msg) os.Exit(0) }
[ "func", "HelpCallback", "(", ")", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "usageStr", ",", "os", ".", "Args", "[", "0", "]", ")", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "msg", ")", "\n", "os", ".", "Exit", "(", "0", ")", "\n", "}" ]
// usage will print out the flag options for the server.
[ "usage", "will", "print", "out", "the", "flag", "options", "for", "the", "server", "." ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/usage/usage.go#L42-L46
train
edgexfoundry/edgex-go
internal/core/metadata/rest_devicereport.go
updateDeviceReportFields
func updateDeviceReportFields(from models.DeviceReport, to *models.DeviceReport, w http.ResponseWriter) error { if from.Device != "" { to.Device = from.Device if err := validateDevice(to.Device, w); err != nil { return err } } if from.Action != "" { to.Action = from.Action } if from.Expected != nil { to.Expected = from.Expected // TODO: Someday find a way to check the value descriptors } if from.Name != "" { to.Name = from.Name } if from.Origin != 0 { to.Origin = from.Origin } return nil }
go
func updateDeviceReportFields(from models.DeviceReport, to *models.DeviceReport, w http.ResponseWriter) error { if from.Device != "" { to.Device = from.Device if err := validateDevice(to.Device, w); err != nil { return err } } if from.Action != "" { to.Action = from.Action } if from.Expected != nil { to.Expected = from.Expected // TODO: Someday find a way to check the value descriptors } if from.Name != "" { to.Name = from.Name } if from.Origin != 0 { to.Origin = from.Origin } return nil }
[ "func", "updateDeviceReportFields", "(", "from", "models", ".", "DeviceReport", ",", "to", "*", "models", ".", "DeviceReport", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "if", "from", ".", "Device", "!=", "\"", "\"", "{", "to", ".", "Device", "=", "from", ".", "Device", "\n", "if", "err", ":=", "validateDevice", "(", "to", ".", "Device", ",", "w", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "from", ".", "Action", "!=", "\"", "\"", "{", "to", ".", "Action", "=", "from", ".", "Action", "\n", "}", "\n", "if", "from", ".", "Expected", "!=", "nil", "{", "to", ".", "Expected", "=", "from", ".", "Expected", "\n", "// TODO: Someday find a way to check the value descriptors", "}", "\n", "if", "from", ".", "Name", "!=", "\"", "\"", "{", "to", ".", "Name", "=", "from", ".", "Name", "\n", "}", "\n", "if", "from", ".", "Origin", "!=", "0", "{", "to", ".", "Origin", "=", "from", ".", "Origin", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Update the relevant fields for the device report
[ "Update", "the", "relevant", "fields", "for", "the", "device", "report" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_devicereport.go#L139-L161
train
edgexfoundry/edgex-go
internal/core/metadata/rest_devicereport.go
validateDevice
func validateDevice(d string, w http.ResponseWriter) error { if _, err := dbClient.GetDeviceByName(d); err != nil { if err == db.ErrNotFound { http.Error(w, "Device was not found", http.StatusNotFound) } else { http.Error(w, err.Error(), http.StatusServiceUnavailable) } return err } return nil }
go
func validateDevice(d string, w http.ResponseWriter) error { if _, err := dbClient.GetDeviceByName(d); err != nil { if err == db.ErrNotFound { http.Error(w, "Device was not found", http.StatusNotFound) } else { http.Error(w, err.Error(), http.StatusServiceUnavailable) } return err } return nil }
[ "func", "validateDevice", "(", "d", "string", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "if", "_", ",", "err", ":=", "dbClient", ".", "GetDeviceByName", "(", "d", ")", ";", "err", "!=", "nil", "{", "if", "err", "==", "db", ".", "ErrNotFound", "{", "http", ".", "Error", "(", "w", ",", "\"", "\"", ",", "http", ".", "StatusNotFound", ")", "\n", "}", "else", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "}", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Validate that the device exists
[ "Validate", "that", "the", "device", "exists" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_devicereport.go#L164-L175
train
edgexfoundry/edgex-go
internal/core/metadata/rest_devicereport.go
restGetValueDescriptorsForDeviceName
func restGetValueDescriptorsForDeviceName(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) n, err := url.QueryUnescape(vars[DEVICENAME]) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) LoggingClient.Error(err.Error()) return } // Get all the associated device reports reports, err := dbClient.GetDeviceReportByDeviceName(n) if err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } valueDescriptors := []string{} for _, report := range reports { for _, e := range report.Expected { valueDescriptors = append(valueDescriptors, e) } } w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(valueDescriptors) }
go
func restGetValueDescriptorsForDeviceName(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) n, err := url.QueryUnescape(vars[DEVICENAME]) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) LoggingClient.Error(err.Error()) return } // Get all the associated device reports reports, err := dbClient.GetDeviceReportByDeviceName(n) if err != nil { LoggingClient.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } valueDescriptors := []string{} for _, report := range reports { for _, e := range report.Expected { valueDescriptors = append(valueDescriptors, e) } } w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(valueDescriptors) }
[ "func", "restGetValueDescriptorsForDeviceName", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "vars", ":=", "mux", ".", "Vars", "(", "r", ")", "\n", "n", ",", "err", ":=", "url", ".", "QueryUnescape", "(", "vars", "[", "DEVICENAME", "]", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusBadRequest", ")", "\n", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n\n", "// Get all the associated device reports", "reports", ",", "err", ":=", "dbClient", ".", "GetDeviceReportByDeviceName", "(", "n", ")", "\n", "if", "err", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n\n", "valueDescriptors", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "report", ":=", "range", "reports", "{", "for", "_", ",", "e", ":=", "range", "report", ".", "Expected", "{", "valueDescriptors", "=", "append", "(", "valueDescriptors", ",", "e", ")", "\n", "}", "\n", "}", "\n\n", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "json", ".", "NewEncoder", "(", "w", ")", ".", "Encode", "(", "valueDescriptors", ")", "\n", "}" ]
// Get a list of value descriptor names // The names are a union of all the value descriptors from the device reports for the given device
[ "Get", "a", "list", "of", "value", "descriptor", "names", "The", "names", "are", "a", "union", "of", "all", "the", "value", "descriptors", "from", "the", "device", "reports", "for", "the", "given", "device" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_devicereport.go#L221-L247
train
edgexfoundry/edgex-go
internal/core/metadata/rest_devicereport.go
notifyDeviceReportAssociates
func notifyDeviceReportAssociates(dr models.DeviceReport, action string) error { // Get the device of the report d, err := dbClient.GetDeviceByName(dr.Device) if err != nil { return err } // Get the device service for the device ds, err := dbClient.GetDeviceServiceById(d.Service.Id) if err != nil { return err } // Notify the associating device services if err = notifyAssociates([]models.DeviceService{ds}, dr.Id, action, models.REPORT); err != nil { return err } return nil }
go
func notifyDeviceReportAssociates(dr models.DeviceReport, action string) error { // Get the device of the report d, err := dbClient.GetDeviceByName(dr.Device) if err != nil { return err } // Get the device service for the device ds, err := dbClient.GetDeviceServiceById(d.Service.Id) if err != nil { return err } // Notify the associating device services if err = notifyAssociates([]models.DeviceService{ds}, dr.Id, action, models.REPORT); err != nil { return err } return nil }
[ "func", "notifyDeviceReportAssociates", "(", "dr", "models", ".", "DeviceReport", ",", "action", "string", ")", "error", "{", "// Get the device of the report", "d", ",", "err", ":=", "dbClient", ".", "GetDeviceByName", "(", "dr", ".", "Device", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Get the device service for the device", "ds", ",", "err", ":=", "dbClient", ".", "GetDeviceServiceById", "(", "d", ".", "Service", ".", "Id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Notify the associating device services", "if", "err", "=", "notifyAssociates", "(", "[", "]", "models", ".", "DeviceService", "{", "ds", "}", ",", "dr", ".", "Id", ",", "action", ",", "models", ".", "REPORT", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Notify the associated device services to the device report
[ "Notify", "the", "associated", "device", "services", "to", "the", "device", "report" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_devicereport.go#L338-L357
train
edgexfoundry/edgex-go
internal/pkg/config/types.go
HealthCheck
func (s ServiceInfo) HealthCheck() string { hc := fmt.Sprintf("%s://%s:%v%s", s.Protocol, s.Host, s.Port, clients.ApiPingRoute) return hc }
go
func (s ServiceInfo) HealthCheck() string { hc := fmt.Sprintf("%s://%s:%v%s", s.Protocol, s.Host, s.Port, clients.ApiPingRoute) return hc }
[ "func", "(", "s", "ServiceInfo", ")", "HealthCheck", "(", ")", "string", "{", "hc", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "Protocol", ",", "s", ".", "Host", ",", "s", ".", "Port", ",", "clients", ".", "ApiPingRoute", ")", "\n", "return", "hc", "\n", "}" ]
// HealthCheck is a URL specifying a healthcheck REST endpoint used by the Registry to determine if the // service is available.
[ "HealthCheck", "is", "a", "URL", "specifying", "a", "healthcheck", "REST", "endpoint", "used", "by", "the", "Registry", "to", "determine", "if", "the", "service", "is", "available", "." ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/config/types.go#L50-L53
train
edgexfoundry/edgex-go
internal/pkg/config/types.go
Url
func (s ServiceInfo) Url() string { url := fmt.Sprintf("%s://%s:%v", s.Protocol, s.Host, s.Port) return url }
go
func (s ServiceInfo) Url() string { url := fmt.Sprintf("%s://%s:%v", s.Protocol, s.Host, s.Port) return url }
[ "func", "(", "s", "ServiceInfo", ")", "Url", "(", ")", "string", "{", "url", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "Protocol", ",", "s", ".", "Host", ",", "s", ".", "Port", ")", "\n", "return", "url", "\n", "}" ]
// Url provides a way to obtain the full url of the host service for use in initialization or, in some cases, // responses to a caller.
[ "Url", "provides", "a", "way", "to", "obtain", "the", "full", "url", "of", "the", "host", "service", "for", "use", "in", "initialization", "or", "in", "some", "cases", "responses", "to", "a", "caller", "." ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/config/types.go#L57-L60
train
edgexfoundry/edgex-go
internal/pkg/config/types.go
Url
func (e IntervalActionInfo) Url() string { url := fmt.Sprintf("%s://%s:%v", e.Protocol, e.Host, e.Port) return url }
go
func (e IntervalActionInfo) Url() string { url := fmt.Sprintf("%s://%s:%v", e.Protocol, e.Host, e.Port) return url }
[ "func", "(", "e", "IntervalActionInfo", ")", "Url", "(", ")", "string", "{", "url", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "Protocol", ",", "e", ".", "Host", ",", "e", ".", "Port", ")", "\n", "return", "url", "\n", "}" ]
// ScheduleEventInfo helper function
[ "ScheduleEventInfo", "helper", "function" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/config/types.go#L142-L145
train
edgexfoundry/edgex-go
internal/support/scheduler/utils.go
msToTime
func msToTime(ms string) (time.Time, error) { msInt, err := strconv.ParseInt(ms, 10, 64) if err != nil { // todo: support-scheduler will be removed later issue_650a t, err := time.Parse(TIMELAYOUT, ms) if err == nil { return t, nil } return time.Time{}, err } return time.Unix(0, msInt*int64(time.Millisecond)), nil }
go
func msToTime(ms string) (time.Time, error) { msInt, err := strconv.ParseInt(ms, 10, 64) if err != nil { // todo: support-scheduler will be removed later issue_650a t, err := time.Parse(TIMELAYOUT, ms) if err == nil { return t, nil } return time.Time{}, err } return time.Unix(0, msInt*int64(time.Millisecond)), nil }
[ "func", "msToTime", "(", "ms", "string", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "msInt", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "ms", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "// todo: support-scheduler will be removed later issue_650a", "t", ",", "err", ":=", "time", ".", "Parse", "(", "TIMELAYOUT", ",", "ms", ")", "\n", "if", "err", "==", "nil", "{", "return", "t", ",", "nil", "\n", "}", "\n", "return", "time", ".", "Time", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "time", ".", "Unix", "(", "0", ",", "msInt", "*", "int64", "(", "time", ".", "Millisecond", ")", ")", ",", "nil", "\n", "}" ]
// Convert millisecond string to Time
[ "Convert", "millisecond", "string", "to", "Time" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/support/scheduler/utils.go#L37-L49
train
edgexfoundry/edgex-go
internal/pkg/db/redis/export.go
DeleteRegistrationByName
func (c *Client) DeleteRegistrationByName(name string) error { conn := c.Pool.Get() defer conn.Close() id, err := redis.String(conn.Do("HGET", db.ExportCollection+":name", name)) if err == redis.ErrNil { return db.ErrNotFound } else if err != nil { return err } return deleteRegistration(conn, id) }
go
func (c *Client) DeleteRegistrationByName(name string) error { conn := c.Pool.Get() defer conn.Close() id, err := redis.String(conn.Do("HGET", db.ExportCollection+":name", name)) if err == redis.ErrNil { return db.ErrNotFound } else if err != nil { return err } return deleteRegistration(conn, id) }
[ "func", "(", "c", "*", "Client", ")", "DeleteRegistrationByName", "(", "name", "string", ")", "error", "{", "conn", ":=", "c", ".", "Pool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "id", ",", "err", ":=", "redis", ".", "String", "(", "conn", ".", "Do", "(", "\"", "\"", ",", "db", ".", "ExportCollection", "+", "\"", "\"", ",", "name", ")", ")", "\n", "if", "err", "==", "redis", ".", "ErrNil", "{", "return", "db", ".", "ErrNotFound", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "deleteRegistration", "(", "conn", ",", "id", ")", "\n", "}" ]
// Delete a registration by name // UnexpectedError - problem getting in database // NotFound - no registration with the name was found
[ "Delete", "a", "registration", "by", "name", "UnexpectedError", "-", "problem", "getting", "in", "database", "NotFound", "-", "no", "registration", "with", "the", "name", "was", "found" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/export.go#L115-L127
train
edgexfoundry/edgex-go
internal/pkg/db/redis/export.go
ScrubAllRegistrations
func (c *Client) ScrubAllRegistrations() (err error) { conn := c.Pool.Get() defer conn.Close() return unlinkCollection(conn, db.ExportCollection) }
go
func (c *Client) ScrubAllRegistrations() (err error) { conn := c.Pool.Get() defer conn.Close() return unlinkCollection(conn, db.ExportCollection) }
[ "func", "(", "c", "*", "Client", ")", "ScrubAllRegistrations", "(", ")", "(", "err", "error", ")", "{", "conn", ":=", "c", ".", "Pool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "return", "unlinkCollection", "(", "conn", ",", "db", ".", "ExportCollection", ")", "\n", "}" ]
// ScrubAllRegistrations deletes all export related data
[ "ScrubAllRegistrations", "deletes", "all", "export", "related", "data" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/export.go#L130-L135
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceservice.go
updateDeviceServiceFields
func updateDeviceServiceFields(from models.DeviceService, to *models.DeviceService, w http.ResponseWriter) error { // Use .String() to compare empty structs (not ideal, but there is no .equals method) if (from.Addressable.String() != models.Addressable{}.String()) { var addr models.Addressable var err error if from.Addressable.Id != "" { addr, err = dbClient.GetAddressableById(from.Addressable.Id) } if from.Addressable.Id == "" || err != nil { addr, err = dbClient.GetAddressableByName(from.Addressable.Name) if err != nil { return err } } to.Addressable = addr } to.AdminState = from.AdminState if from.Description != "" { to.Description = from.Description } if from.Labels != nil { to.Labels = from.Labels } if from.LastConnected != 0 { to.LastConnected = from.LastConnected } if from.LastReported != 0 { to.LastReported = from.LastReported } if from.Name != "" { to.Name = from.Name // Check if the new name is unique checkDS, err := dbClient.GetDeviceServiceByName(from.Name) if err != nil { // A problem occurred accessing database if err != db.ErrNotFound { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } } // Found a device service, make sure its the one we're trying to update if err != db.ErrNotFound { // Different IDs -> Name is not unique if checkDS.Id != to.Id { err = errors.New("Duplicate name for Device Service") http.Error(w, err.Error(), http.StatusConflict) return err } } } to.OperatingState = from.OperatingState if from.Origin != 0 { to.Origin = from.Origin } return nil }
go
func updateDeviceServiceFields(from models.DeviceService, to *models.DeviceService, w http.ResponseWriter) error { // Use .String() to compare empty structs (not ideal, but there is no .equals method) if (from.Addressable.String() != models.Addressable{}.String()) { var addr models.Addressable var err error if from.Addressable.Id != "" { addr, err = dbClient.GetAddressableById(from.Addressable.Id) } if from.Addressable.Id == "" || err != nil { addr, err = dbClient.GetAddressableByName(from.Addressable.Name) if err != nil { return err } } to.Addressable = addr } to.AdminState = from.AdminState if from.Description != "" { to.Description = from.Description } if from.Labels != nil { to.Labels = from.Labels } if from.LastConnected != 0 { to.LastConnected = from.LastConnected } if from.LastReported != 0 { to.LastReported = from.LastReported } if from.Name != "" { to.Name = from.Name // Check if the new name is unique checkDS, err := dbClient.GetDeviceServiceByName(from.Name) if err != nil { // A problem occurred accessing database if err != db.ErrNotFound { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } } // Found a device service, make sure its the one we're trying to update if err != db.ErrNotFound { // Different IDs -> Name is not unique if checkDS.Id != to.Id { err = errors.New("Duplicate name for Device Service") http.Error(w, err.Error(), http.StatusConflict) return err } } } to.OperatingState = from.OperatingState if from.Origin != 0 { to.Origin = from.Origin } return nil }
[ "func", "updateDeviceServiceFields", "(", "from", "models", ".", "DeviceService", ",", "to", "*", "models", ".", "DeviceService", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "// Use .String() to compare empty structs (not ideal, but there is no .equals method)", "if", "(", "from", ".", "Addressable", ".", "String", "(", ")", "!=", "models", ".", "Addressable", "{", "}", ".", "String", "(", ")", ")", "{", "var", "addr", "models", ".", "Addressable", "\n", "var", "err", "error", "\n", "if", "from", ".", "Addressable", ".", "Id", "!=", "\"", "\"", "{", "addr", ",", "err", "=", "dbClient", ".", "GetAddressableById", "(", "from", ".", "Addressable", ".", "Id", ")", "\n", "}", "\n", "if", "from", ".", "Addressable", ".", "Id", "==", "\"", "\"", "||", "err", "!=", "nil", "{", "addr", ",", "err", "=", "dbClient", ".", "GetAddressableByName", "(", "from", ".", "Addressable", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "to", ".", "Addressable", "=", "addr", "\n", "}", "\n\n", "to", ".", "AdminState", "=", "from", ".", "AdminState", "\n", "if", "from", ".", "Description", "!=", "\"", "\"", "{", "to", ".", "Description", "=", "from", ".", "Description", "\n", "}", "\n", "if", "from", ".", "Labels", "!=", "nil", "{", "to", ".", "Labels", "=", "from", ".", "Labels", "\n", "}", "\n", "if", "from", ".", "LastConnected", "!=", "0", "{", "to", ".", "LastConnected", "=", "from", ".", "LastConnected", "\n", "}", "\n", "if", "from", ".", "LastReported", "!=", "0", "{", "to", ".", "LastReported", "=", "from", ".", "LastReported", "\n", "}", "\n", "if", "from", ".", "Name", "!=", "\"", "\"", "{", "to", ".", "Name", "=", "from", ".", "Name", "\n\n", "// Check if the new name is unique", "checkDS", ",", "err", ":=", "dbClient", ".", "GetDeviceServiceByName", "(", "from", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "// A problem occurred accessing database", "if", "err", "!=", "db", ".", "ErrNotFound", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Found a device service, make sure its the one we're trying to update", "if", "err", "!=", "db", ".", "ErrNotFound", "{", "// Different IDs -> Name is not unique", "if", "checkDS", ".", "Id", "!=", "to", ".", "Id", "{", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusConflict", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n\n", "to", ".", "OperatingState", "=", "from", ".", "OperatingState", "\n", "if", "from", ".", "Origin", "!=", "0", "{", "to", ".", "Origin", "=", "from", ".", "Origin", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Update the relevant device service fields
[ "Update", "the", "relevant", "device", "service", "fields" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceservice.go#L142-L202
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceservice.go
deleteDeviceService
func deleteDeviceService(ds models.DeviceService, w http.ResponseWriter, ctx context.Context) error { // Delete the associated devices devices, err := dbClient.GetDevicesByServiceId(ds.Id) if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } for _, device := range devices { if err = deleteDevice(device, w, ctx); err != nil { return err } } // Delete the associated provision watchers watchers, err := dbClient.GetProvisionWatchersByServiceId(ds.Id) if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } for _, watcher := range watchers { if err = deleteProvisionWatcher(watcher, w); err != nil { return err } } // Delete the device service if err = dbClient.DeleteDeviceServiceById(ds.Id); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } return nil }
go
func deleteDeviceService(ds models.DeviceService, w http.ResponseWriter, ctx context.Context) error { // Delete the associated devices devices, err := dbClient.GetDevicesByServiceId(ds.Id) if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } for _, device := range devices { if err = deleteDevice(device, w, ctx); err != nil { return err } } // Delete the associated provision watchers watchers, err := dbClient.GetProvisionWatchersByServiceId(ds.Id) if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } for _, watcher := range watchers { if err = deleteProvisionWatcher(watcher, w); err != nil { return err } } // Delete the device service if err = dbClient.DeleteDeviceServiceById(ds.Id); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } return nil }
[ "func", "deleteDeviceService", "(", "ds", "models", ".", "DeviceService", ",", "w", "http", ".", "ResponseWriter", ",", "ctx", "context", ".", "Context", ")", "error", "{", "// Delete the associated devices", "devices", ",", "err", ":=", "dbClient", ".", "GetDevicesByServiceId", "(", "ds", ".", "Id", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n", "for", "_", ",", "device", ":=", "range", "devices", "{", "if", "err", "=", "deleteDevice", "(", "device", ",", "w", ",", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Delete the associated provision watchers", "watchers", ",", "err", ":=", "dbClient", ".", "GetProvisionWatchersByServiceId", "(", "ds", ".", "Id", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n", "for", "_", ",", "watcher", ":=", "range", "watchers", "{", "if", "err", "=", "deleteProvisionWatcher", "(", "watcher", ",", "w", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Delete the device service", "if", "err", "=", "dbClient", ".", "DeleteDeviceServiceById", "(", "ds", ".", "Id", ")", ";", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Delete the device service // Delete the associated devices // Delete the associated provision watchers
[ "Delete", "the", "device", "service", "Delete", "the", "associated", "devices", "Delete", "the", "associated", "provision", "watchers" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceservice.go#L367-L399
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceservice.go
updateServiceLastConnected
func updateServiceLastConnected(ds models.DeviceService, lc int64, w http.ResponseWriter) error { ds.LastConnected = lc if err := dbClient.UpdateDeviceService(ds); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } return nil }
go
func updateServiceLastConnected(ds models.DeviceService, lc int64, w http.ResponseWriter) error { ds.LastConnected = lc if err := dbClient.UpdateDeviceService(ds); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } return nil }
[ "func", "updateServiceLastConnected", "(", "ds", "models", ".", "DeviceService", ",", "lc", "int64", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "ds", ".", "LastConnected", "=", "lc", "\n\n", "if", "err", ":=", "dbClient", ".", "UpdateDeviceService", "(", "ds", ")", ";", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Update the last connected value of the device service
[ "Update", "the", "last", "connected", "value", "of", "the", "device", "service" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceservice.go#L472-L481
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceservice.go
updateServiceOpState
func updateServiceOpState(ds models.DeviceService, os models.OperatingState, w http.ResponseWriter) error { ds.OperatingState = os if err := dbClient.UpdateDeviceService(ds); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } return nil }
go
func updateServiceOpState(ds models.DeviceService, os models.OperatingState, w http.ResponseWriter) error { ds.OperatingState = os if err := dbClient.UpdateDeviceService(ds); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } return nil }
[ "func", "updateServiceOpState", "(", "ds", "models", ".", "DeviceService", ",", "os", "models", ".", "OperatingState", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "ds", ".", "OperatingState", "=", "os", "\n", "if", "err", ":=", "dbClient", ".", "UpdateDeviceService", "(", "ds", ")", ";", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Update the OpState for the device service
[ "Update", "the", "OpState", "for", "the", "device", "service" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceservice.go#L578-L586
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceservice.go
updateServiceAdminState
func updateServiceAdminState(ds models.DeviceService, as models.AdminState, w http.ResponseWriter) error { ds.AdminState = as if err := dbClient.UpdateDeviceService(ds); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } return nil }
go
func updateServiceAdminState(ds models.DeviceService, as models.AdminState, w http.ResponseWriter) error { ds.AdminState = as if err := dbClient.UpdateDeviceService(ds); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } return nil }
[ "func", "updateServiceAdminState", "(", "ds", "models", ".", "DeviceService", ",", "as", "models", ".", "AdminState", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "ds", ".", "AdminState", "=", "as", "\n", "if", "err", ":=", "dbClient", ".", "UpdateDeviceService", "(", "ds", ")", ";", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Update the admin state for the device service
[ "Update", "the", "admin", "state", "for", "the", "device", "service" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceservice.go#L666-L674
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceservice.go
updateServiceLastReported
func updateServiceLastReported(ds models.DeviceService, lr int64, w http.ResponseWriter) error { ds.LastReported = lr if err := dbClient.UpdateDeviceService(ds); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } return nil }
go
func updateServiceLastReported(ds models.DeviceService, lr int64, w http.ResponseWriter) error { ds.LastReported = lr if err := dbClient.UpdateDeviceService(ds); err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return err } return nil }
[ "func", "updateServiceLastReported", "(", "ds", "models", ".", "DeviceService", ",", "lr", "int64", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "ds", ".", "LastReported", "=", "lr", "\n", "if", "err", ":=", "dbClient", ".", "UpdateDeviceService", "(", "ds", ")", ";", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusServiceUnavailable", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Update the last reported value for the device service
[ "Update", "the", "last", "reported", "value", "for", "the", "device", "service" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceservice.go#L746-L754
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceservice.go
callback
func callback(service models.DeviceService, id string, action string, actionType models.ActionType) error { client := &http.Client{} url := service.Addressable.GetCallbackURL() if len(url) > 0 { body, err := getBody(id, actionType) if err != nil { return err } req, err := http.NewRequest(string(action), url, bytes.NewReader(body)) if err != nil { return err } req.Header.Add("Content-Type", "application/json") go makeRequest(client, req) } else { LoggingClient.Info("callback::no addressable for " + service.Name) } return nil }
go
func callback(service models.DeviceService, id string, action string, actionType models.ActionType) error { client := &http.Client{} url := service.Addressable.GetCallbackURL() if len(url) > 0 { body, err := getBody(id, actionType) if err != nil { return err } req, err := http.NewRequest(string(action), url, bytes.NewReader(body)) if err != nil { return err } req.Header.Add("Content-Type", "application/json") go makeRequest(client, req) } else { LoggingClient.Info("callback::no addressable for " + service.Name) } return nil }
[ "func", "callback", "(", "service", "models", ".", "DeviceService", ",", "id", "string", ",", "action", "string", ",", "actionType", "models", ".", "ActionType", ")", "error", "{", "client", ":=", "&", "http", ".", "Client", "{", "}", "\n", "url", ":=", "service", ".", "Addressable", ".", "GetCallbackURL", "(", ")", "\n", "if", "len", "(", "url", ")", ">", "0", "{", "body", ",", "err", ":=", "getBody", "(", "id", ",", "actionType", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "string", "(", "action", ")", ",", "url", ",", "bytes", ".", "NewReader", "(", "body", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "req", ".", "Header", ".", "Add", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "go", "makeRequest", "(", "client", ",", "req", ")", "\n", "}", "else", "{", "LoggingClient", ".", "Info", "(", "\"", "\"", "+", "service", ".", "Name", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Make the callback for the device service
[ "Make", "the", "callback", "for", "the", "device", "service" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceservice.go#L769-L788
train
edgexfoundry/edgex-go
internal/core/metadata/rest_deviceservice.go
getBody
func getBody(id string, actionType models.ActionType) ([]byte, error) { return json.Marshal(models.CallbackAlert{ActionType: actionType, Id: id}) }
go
func getBody(id string, actionType models.ActionType) ([]byte, error) { return json.Marshal(models.CallbackAlert{ActionType: actionType, Id: id}) }
[ "func", "getBody", "(", "id", "string", ",", "actionType", "models", ".", "ActionType", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "json", ".", "Marshal", "(", "models", ".", "CallbackAlert", "{", "ActionType", ":", "actionType", ",", "Id", ":", "id", "}", ")", "\n", "}" ]
// Turn the ID and ActionType into the JSON body that will be passed
[ "Turn", "the", "ID", "and", "ActionType", "into", "the", "JSON", "body", "that", "will", "be", "passed" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/metadata/rest_deviceservice.go#L803-L805
train
edgexfoundry/edgex-go
internal/core/data/router.go
scrubAllHandler
func scrubAllHandler(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() LoggingClient.Info("Deleting all events from database") err := deleteAllEvents() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) LoggingClient.Error(err.Error()) return } encode(true, w) }
go
func scrubAllHandler(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() LoggingClient.Info("Deleting all events from database") err := deleteAllEvents() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) LoggingClient.Error(err.Error()) return } encode(true, w) }
[ "func", "scrubAllHandler", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "defer", "r", ".", "Body", ".", "Close", "(", ")", "\n\n", "LoggingClient", ".", "Info", "(", "\"", "\"", ")", "\n\n", "err", ":=", "deleteAllEvents", "(", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusInternalServerError", ")", "\n", "LoggingClient", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n\n", "encode", "(", "true", ",", "w", ")", "\n", "}" ]
// Undocumented feature to remove all readings and events from the database // This should primarily be used for debugging purposes
[ "Undocumented", "feature", "to", "remove", "all", "readings", "and", "events", "from", "the", "database", "This", "should", "primarily", "be", "used", "for", "debugging", "purposes" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/data/router.go#L288-L301
train
edgexfoundry/edgex-go
internal/core/command/types.go
Execute
func (sc serviceCommand) Execute() (string, int, error) { if sc.AdminState == contract.Locked { LoggingClient.Error(sc.Name + " is in admin locked state") return "", DefaultErrorCode, ErrDeviceLocked{} } LoggingClient.Info("Issuing" + sc.Request.Method + " command to: " + sc.Request.URL.String()) resp, reqErr := sc.HttpCaller.Do(sc.Request) if reqErr != nil { LoggingClient.Error(reqErr.Error()) return "", http.StatusInternalServerError, reqErr } buf := new(bytes.Buffer) _, readErr := buf.ReadFrom(resp.Body) if readErr != nil { return "", DefaultErrorCode, readErr } return buf.String(), resp.StatusCode, nil }
go
func (sc serviceCommand) Execute() (string, int, error) { if sc.AdminState == contract.Locked { LoggingClient.Error(sc.Name + " is in admin locked state") return "", DefaultErrorCode, ErrDeviceLocked{} } LoggingClient.Info("Issuing" + sc.Request.Method + " command to: " + sc.Request.URL.String()) resp, reqErr := sc.HttpCaller.Do(sc.Request) if reqErr != nil { LoggingClient.Error(reqErr.Error()) return "", http.StatusInternalServerError, reqErr } buf := new(bytes.Buffer) _, readErr := buf.ReadFrom(resp.Body) if readErr != nil { return "", DefaultErrorCode, readErr } return buf.String(), resp.StatusCode, nil }
[ "func", "(", "sc", "serviceCommand", ")", "Execute", "(", ")", "(", "string", ",", "int", ",", "error", ")", "{", "if", "sc", ".", "AdminState", "==", "contract", ".", "Locked", "{", "LoggingClient", ".", "Error", "(", "sc", ".", "Name", "+", "\"", "\"", ")", "\n\n", "return", "\"", "\"", ",", "DefaultErrorCode", ",", "ErrDeviceLocked", "{", "}", "\n", "}", "\n\n", "LoggingClient", ".", "Info", "(", "\"", "\"", "+", "sc", ".", "Request", ".", "Method", "+", "\"", "\"", "+", "sc", ".", "Request", ".", "URL", ".", "String", "(", ")", ")", "\n", "resp", ",", "reqErr", ":=", "sc", ".", "HttpCaller", ".", "Do", "(", "sc", ".", "Request", ")", "\n", "if", "reqErr", "!=", "nil", "{", "LoggingClient", ".", "Error", "(", "reqErr", ".", "Error", "(", ")", ")", "\n", "return", "\"", "\"", ",", "http", ".", "StatusInternalServerError", ",", "reqErr", "\n\n", "}", "\n\n", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "_", ",", "readErr", ":=", "buf", ".", "ReadFrom", "(", "resp", ".", "Body", ")", "\n\n", "if", "readErr", "!=", "nil", "{", "return", "\"", "\"", ",", "DefaultErrorCode", ",", "readErr", "\n", "}", "\n", "return", "buf", ".", "String", "(", ")", ",", "resp", ".", "StatusCode", ",", "nil", "\n", "}" ]
// Execute sends the command to the command service
[ "Execute", "sends", "the", "command", "to", "the", "command", "service" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/core/command/types.go#L41-L63
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/scheduler.go
IntervalByName
func (mc MongoClient) IntervalByName(name string) (contract.Interval, error) { s := mc.getSessionCopy() defer s.Close() query := bson.M{"name": name} mi := models.Interval{} if err := s.DB(mc.database.Name).C(db.Interval).Find(query).One(&mi); err != nil { return contract.Interval{}, errorMap(err) } return mi.ToContract(), nil }
go
func (mc MongoClient) IntervalByName(name string) (contract.Interval, error) { s := mc.getSessionCopy() defer s.Close() query := bson.M{"name": name} mi := models.Interval{} if err := s.DB(mc.database.Name).C(db.Interval).Find(query).One(&mi); err != nil { return contract.Interval{}, errorMap(err) } return mi.ToContract(), nil }
[ "func", "(", "mc", "MongoClient", ")", "IntervalByName", "(", "name", "string", ")", "(", "contract", ".", "Interval", ",", "error", ")", "{", "s", ":=", "mc", ".", "getSessionCopy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n\n", "query", ":=", "bson", ".", "M", "{", "\"", "\"", ":", "name", "}", "\n\n", "mi", ":=", "models", ".", "Interval", "{", "}", "\n", "if", "err", ":=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "Interval", ")", ".", "Find", "(", "query", ")", ".", "One", "(", "&", "mi", ")", ";", "err", "!=", "nil", "{", "return", "contract", ".", "Interval", "{", "}", ",", "errorMap", "(", "err", ")", "\n", "}", "\n", "return", "mi", ".", "ToContract", "(", ")", ",", "nil", "\n", "}" ]
// Return an Interval by name // UnexpectedError - failed to retrieve interval from the database
[ "Return", "an", "Interval", "by", "name", "UnexpectedError", "-", "failed", "to", "retrieve", "interval", "from", "the", "database" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/scheduler.go#L42-L53
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/scheduler.go
IntervalById
func (mc MongoClient) IntervalById(id string) (contract.Interval, error) { s := mc.getSessionCopy() defer s.Close() query, err := idToBsonM(id) if err != nil { return contract.Interval{}, err } var interval models.Interval if err := s.DB(mc.database.Name).C(db.Interval).Find(query).One(&interval); err != nil { return contract.Interval{}, errorMap(err) } return interval.ToContract(), nil }
go
func (mc MongoClient) IntervalById(id string) (contract.Interval, error) { s := mc.getSessionCopy() defer s.Close() query, err := idToBsonM(id) if err != nil { return contract.Interval{}, err } var interval models.Interval if err := s.DB(mc.database.Name).C(db.Interval).Find(query).One(&interval); err != nil { return contract.Interval{}, errorMap(err) } return interval.ToContract(), nil }
[ "func", "(", "mc", "MongoClient", ")", "IntervalById", "(", "id", "string", ")", "(", "contract", ".", "Interval", ",", "error", ")", "{", "s", ":=", "mc", ".", "getSessionCopy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n\n", "query", ",", "err", ":=", "idToBsonM", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "contract", ".", "Interval", "{", "}", ",", "err", "\n", "}", "\n\n", "var", "interval", "models", ".", "Interval", "\n", "if", "err", ":=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "Interval", ")", ".", "Find", "(", "query", ")", ".", "One", "(", "&", "interval", ")", ";", "err", "!=", "nil", "{", "return", "contract", ".", "Interval", "{", "}", ",", "errorMap", "(", "err", ")", "\n", "}", "\n", "return", "interval", ".", "ToContract", "(", ")", ",", "nil", "\n", "}" ]
// Return an Interval by ID // UnexpectedError - failed to retrieve interval from the database
[ "Return", "an", "Interval", "by", "ID", "UnexpectedError", "-", "failed", "to", "retrieve", "interval", "from", "the", "database" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/scheduler.go#L57-L71
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/scheduler.go
UpdateInterval
func (mc MongoClient) UpdateInterval(interval contract.Interval) error { var mapped models.Interval id, err := mapped.FromContract(interval) if err != nil { return err } mapped.TimestampForUpdate() return mc.updateId(db.Interval, id, mapped) }
go
func (mc MongoClient) UpdateInterval(interval contract.Interval) error { var mapped models.Interval id, err := mapped.FromContract(interval) if err != nil { return err } mapped.TimestampForUpdate() return mc.updateId(db.Interval, id, mapped) }
[ "func", "(", "mc", "MongoClient", ")", "UpdateInterval", "(", "interval", "contract", ".", "Interval", ")", "error", "{", "var", "mapped", "models", ".", "Interval", "\n", "id", ",", "err", ":=", "mapped", ".", "FromContract", "(", "interval", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "mapped", ".", "TimestampForUpdate", "(", ")", "\n\n", "return", "mc", ".", "updateId", "(", "db", ".", "Interval", ",", "id", ",", "mapped", ")", "\n", "}" ]
// Update an Interval // UnexpectedError - failed to update interval in the database
[ "Update", "an", "Interval", "UnexpectedError", "-", "failed", "to", "update", "interval", "in", "the", "database" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/scheduler.go#L103-L113
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/scheduler.go
DeleteIntervalById
func (mc MongoClient) DeleteIntervalById(id string) error { return mc.deleteById(db.Interval, id) }
go
func (mc MongoClient) DeleteIntervalById(id string) error { return mc.deleteById(db.Interval, id) }
[ "func", "(", "mc", "MongoClient", ")", "DeleteIntervalById", "(", "id", "string", ")", "error", "{", "return", "mc", ".", "deleteById", "(", "db", ".", "Interval", ",", "id", ")", "\n", "}" ]
// Remove an Interval by ID // UnexpectedError - failed to remove interval from the database
[ "Remove", "an", "Interval", "by", "ID", "UnexpectedError", "-", "failed", "to", "remove", "interval", "from", "the", "database" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/scheduler.go#L117-L119
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/scheduler.go
IntervalActionById
func (mc MongoClient) IntervalActionById(id string) (contract.IntervalAction, error) { s := mc.getSessionCopy() defer s.Close() query, err := idToBsonM(id) if err != nil { return contract.IntervalAction{}, err } var action models.IntervalAction if err := s.DB(mc.database.Name).C(db.IntervalAction).Find(query).One(&action); err != nil { return contract.IntervalAction{}, errorMap(err) } return action.ToContract(), nil }
go
func (mc MongoClient) IntervalActionById(id string) (contract.IntervalAction, error) { s := mc.getSessionCopy() defer s.Close() query, err := idToBsonM(id) if err != nil { return contract.IntervalAction{}, err } var action models.IntervalAction if err := s.DB(mc.database.Name).C(db.IntervalAction).Find(query).One(&action); err != nil { return contract.IntervalAction{}, errorMap(err) } return action.ToContract(), nil }
[ "func", "(", "mc", "MongoClient", ")", "IntervalActionById", "(", "id", "string", ")", "(", "contract", ".", "IntervalAction", ",", "error", ")", "{", "s", ":=", "mc", ".", "getSessionCopy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n\n", "query", ",", "err", ":=", "idToBsonM", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "contract", ".", "IntervalAction", "{", "}", ",", "err", "\n", "}", "\n\n", "var", "action", "models", ".", "IntervalAction", "\n", "if", "err", ":=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "IntervalAction", ")", ".", "Find", "(", "query", ")", ".", "One", "(", "&", "action", ")", ";", "err", "!=", "nil", "{", "return", "contract", ".", "IntervalAction", "{", "}", ",", "errorMap", "(", "err", ")", "\n", "}", "\n", "return", "action", ".", "ToContract", "(", ")", ",", "nil", "\n", "}" ]
// Return an Interval Action by ID // UnexpectedError - failed to retrieve interval actions from the database // Sort the interval actions in descending order by ID
[ "Return", "an", "Interval", "Action", "by", "ID", "UnexpectedError", "-", "failed", "to", "retrieve", "interval", "actions", "from", "the", "database", "Sort", "the", "interval", "actions", "in", "descending", "order", "by", "ID" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/scheduler.go#L154-L168
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/scheduler.go
IntervalActionByName
func (mc MongoClient) IntervalActionByName(name string) (contract.IntervalAction, error) { s := mc.getSessionCopy() defer s.Close() query := bson.M{"name": name} mia := models.IntervalAction{} if err := s.DB(mc.database.Name).C(db.IntervalAction).Find(query).One(&mia); err != nil { return contract.IntervalAction{}, errorMap(err) } return mia.ToContract(), nil }
go
func (mc MongoClient) IntervalActionByName(name string) (contract.IntervalAction, error) { s := mc.getSessionCopy() defer s.Close() query := bson.M{"name": name} mia := models.IntervalAction{} if err := s.DB(mc.database.Name).C(db.IntervalAction).Find(query).One(&mia); err != nil { return contract.IntervalAction{}, errorMap(err) } return mia.ToContract(), nil }
[ "func", "(", "mc", "MongoClient", ")", "IntervalActionByName", "(", "name", "string", ")", "(", "contract", ".", "IntervalAction", ",", "error", ")", "{", "s", ":=", "mc", ".", "getSessionCopy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n\n", "query", ":=", "bson", ".", "M", "{", "\"", "\"", ":", "name", "}", "\n\n", "mia", ":=", "models", ".", "IntervalAction", "{", "}", "\n", "if", "err", ":=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "IntervalAction", ")", ".", "Find", "(", "query", ")", ".", "One", "(", "&", "mia", ")", ";", "err", "!=", "nil", "{", "return", "contract", ".", "IntervalAction", "{", "}", ",", "errorMap", "(", "err", ")", "\n", "}", "\n", "return", "mia", ".", "ToContract", "(", ")", ",", "nil", "\n", "}" ]
// Return an Interval Action by name // UnexpectedError - failed to retrieve interval actions from the database // Sort the interval actions in descending order by ID
[ "Return", "an", "Interval", "Action", "by", "name", "UnexpectedError", "-", "failed", "to", "retrieve", "interval", "actions", "from", "the", "database", "Sort", "the", "interval", "actions", "in", "descending", "order", "by", "ID" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/scheduler.go#L173-L184
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/scheduler.go
AddIntervalAction
func (mc MongoClient) AddIntervalAction(action contract.IntervalAction) (string, error) { s := mc.getSessionCopy() defer s.Close() var mapped models.IntervalAction id, err := mapped.FromContract(action) if err != nil { return "", err } // See if the name is unique and add the value descriptors found, err := s.DB(mc.database.Name).C(db.IntervalAction).Find(bson.M{"name": mapped.Name}).Count() // Duplicate name if found > 0 { return "", db.ErrNotUnique } mapped.TimestampForAdd() if err = s.DB(mc.database.Name).C(db.IntervalAction).Insert(mapped); err != nil { return "", errorMap(err) } return id, nil }
go
func (mc MongoClient) AddIntervalAction(action contract.IntervalAction) (string, error) { s := mc.getSessionCopy() defer s.Close() var mapped models.IntervalAction id, err := mapped.FromContract(action) if err != nil { return "", err } // See if the name is unique and add the value descriptors found, err := s.DB(mc.database.Name).C(db.IntervalAction).Find(bson.M{"name": mapped.Name}).Count() // Duplicate name if found > 0 { return "", db.ErrNotUnique } mapped.TimestampForAdd() if err = s.DB(mc.database.Name).C(db.IntervalAction).Insert(mapped); err != nil { return "", errorMap(err) } return id, nil }
[ "func", "(", "mc", "MongoClient", ")", "AddIntervalAction", "(", "action", "contract", ".", "IntervalAction", ")", "(", "string", ",", "error", ")", "{", "s", ":=", "mc", ".", "getSessionCopy", "(", ")", "\n", "defer", "s", ".", "Close", "(", ")", "\n\n", "var", "mapped", "models", ".", "IntervalAction", "\n", "id", ",", "err", ":=", "mapped", ".", "FromContract", "(", "action", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "// See if the name is unique and add the value descriptors", "found", ",", "err", ":=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "IntervalAction", ")", ".", "Find", "(", "bson", ".", "M", "{", "\"", "\"", ":", "mapped", ".", "Name", "}", ")", ".", "Count", "(", ")", "\n", "// Duplicate name", "if", "found", ">", "0", "{", "return", "\"", "\"", ",", "db", ".", "ErrNotUnique", "\n", "}", "\n\n", "mapped", ".", "TimestampForAdd", "(", ")", "\n\n", "if", "err", "=", "s", ".", "DB", "(", "mc", ".", "database", ".", "Name", ")", ".", "C", "(", "db", ".", "IntervalAction", ")", ".", "Insert", "(", "mapped", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errorMap", "(", "err", ")", "\n", "}", "\n", "return", "id", ",", "nil", "\n", "}" ]
// Add a new Interval Action // UnexpectedError - failed to add interval action into the database
[ "Add", "a", "new", "Interval", "Action", "UnexpectedError", "-", "failed", "to", "add", "interval", "action", "into", "the", "database" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/scheduler.go#L188-L211
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/scheduler.go
UpdateIntervalAction
func (mc MongoClient) UpdateIntervalAction(action contract.IntervalAction) error { var mapped models.IntervalAction id, err := mapped.FromContract(action) if err != nil { return err } mapped.TimestampForUpdate() return mc.updateId(db.IntervalAction, id, mapped) }
go
func (mc MongoClient) UpdateIntervalAction(action contract.IntervalAction) error { var mapped models.IntervalAction id, err := mapped.FromContract(action) if err != nil { return err } mapped.TimestampForUpdate() return mc.updateId(db.IntervalAction, id, mapped) }
[ "func", "(", "mc", "MongoClient", ")", "UpdateIntervalAction", "(", "action", "contract", ".", "IntervalAction", ")", "error", "{", "var", "mapped", "models", ".", "IntervalAction", "\n", "id", ",", "err", ":=", "mapped", ".", "FromContract", "(", "action", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "mapped", ".", "TimestampForUpdate", "(", ")", "\n\n", "return", "mc", ".", "updateId", "(", "db", ".", "IntervalAction", ",", "id", ",", "mapped", ")", "\n", "}" ]
// Update an Interval Action // UnexpectedError - failed to update interval action in the database
[ "Update", "an", "Interval", "Action", "UnexpectedError", "-", "failed", "to", "update", "interval", "action", "in", "the", "database" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/scheduler.go#L215-L225
train
edgexfoundry/edgex-go
internal/pkg/db/mongo/scheduler.go
DeleteIntervalActionById
func (mc MongoClient) DeleteIntervalActionById(id string) error { return mc.deleteById(db.IntervalAction, id) }
go
func (mc MongoClient) DeleteIntervalActionById(id string) error { return mc.deleteById(db.IntervalAction, id) }
[ "func", "(", "mc", "MongoClient", ")", "DeleteIntervalActionById", "(", "id", "string", ")", "error", "{", "return", "mc", ".", "deleteById", "(", "db", ".", "IntervalAction", ",", "id", ")", "\n", "}" ]
// Remove an Interval Action by ID // UnexpectedError - failed to remove interval action from the database
[ "Remove", "an", "Interval", "Action", "by", "ID", "UnexpectedError", "-", "failed", "to", "remove", "interval", "action", "from", "the", "database" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/mongo/scheduler.go#L229-L231
train
edgexfoundry/edgex-go
internal/pkg/db/redis/client.go
NewClient
func NewClient(config db.Configuration) (*Client, error) { once.Do(func() { connectionString := fmt.Sprintf("%s:%d", config.Host, config.Port) opts := []redis.DialOption{ redis.DialPassword(config.Password), redis.DialConnectTimeout(time.Duration(config.Timeout) * time.Millisecond), } dialFunc := func() (redis.Conn, error) { conn, err := redis.Dial( "tcp", connectionString, opts..., ) if err != nil { return nil, fmt.Errorf("Could not dial Redis: %s", err) } return conn, nil } currClient = &Client{ Pool: &redis.Pool{ IdleTimeout: 0, /* The current implementation processes nested structs using concurrent connections. * With the deepest nesting level being 3, three shall be the number of maximum open * idle connections in the pool, to allow reuse. * TODO: Once we have a concurrent benchmark, this should be revisited. * TODO: Longer term, once the objects are clean of external dependencies, the use * of another serializer should make this moot. */ MaxIdle: 10, Dial: dialFunc, }, } }) return currClient, nil }
go
func NewClient(config db.Configuration) (*Client, error) { once.Do(func() { connectionString := fmt.Sprintf("%s:%d", config.Host, config.Port) opts := []redis.DialOption{ redis.DialPassword(config.Password), redis.DialConnectTimeout(time.Duration(config.Timeout) * time.Millisecond), } dialFunc := func() (redis.Conn, error) { conn, err := redis.Dial( "tcp", connectionString, opts..., ) if err != nil { return nil, fmt.Errorf("Could not dial Redis: %s", err) } return conn, nil } currClient = &Client{ Pool: &redis.Pool{ IdleTimeout: 0, /* The current implementation processes nested structs using concurrent connections. * With the deepest nesting level being 3, three shall be the number of maximum open * idle connections in the pool, to allow reuse. * TODO: Once we have a concurrent benchmark, this should be revisited. * TODO: Longer term, once the objects are clean of external dependencies, the use * of another serializer should make this moot. */ MaxIdle: 10, Dial: dialFunc, }, } }) return currClient, nil }
[ "func", "NewClient", "(", "config", "db", ".", "Configuration", ")", "(", "*", "Client", ",", "error", ")", "{", "once", ".", "Do", "(", "func", "(", ")", "{", "connectionString", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "config", ".", "Host", ",", "config", ".", "Port", ")", "\n", "opts", ":=", "[", "]", "redis", ".", "DialOption", "{", "redis", ".", "DialPassword", "(", "config", ".", "Password", ")", ",", "redis", ".", "DialConnectTimeout", "(", "time", ".", "Duration", "(", "config", ".", "Timeout", ")", "*", "time", ".", "Millisecond", ")", ",", "}", "\n\n", "dialFunc", ":=", "func", "(", ")", "(", "redis", ".", "Conn", ",", "error", ")", "{", "conn", ",", "err", ":=", "redis", ".", "Dial", "(", "\"", "\"", ",", "connectionString", ",", "opts", "...", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "conn", ",", "nil", "\n", "}", "\n\n", "currClient", "=", "&", "Client", "{", "Pool", ":", "&", "redis", ".", "Pool", "{", "IdleTimeout", ":", "0", ",", "/* The current implementation processes nested structs using concurrent connections.\n\t\t\t\t * With the deepest nesting level being 3, three shall be the number of maximum open\n\t\t\t\t * idle connections in the pool, to allow reuse.\n\t\t\t\t * TODO: Once we have a concurrent benchmark, this should be revisited.\n\t\t\t\t * TODO: Longer term, once the objects are clean of external dependencies, the use\n\t\t\t\t * of another serializer should make this moot.\n\t\t\t\t */", "MaxIdle", ":", "10", ",", "Dial", ":", "dialFunc", ",", "}", ",", "}", "\n", "}", ")", "\n", "return", "currClient", ",", "nil", "\n", "}" ]
// Return a pointer to the Redis client
[ "Return", "a", "pointer", "to", "the", "Redis", "client" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/client.go#L35-L69
train
edgexfoundry/edgex-go
internal/pkg/db/redis/client.go
CloseSession
func (c *Client) CloseSession() { c.Pool.Close() currClient = nil once = sync.Once{} }
go
func (c *Client) CloseSession() { c.Pool.Close() currClient = nil once = sync.Once{} }
[ "func", "(", "c", "*", "Client", ")", "CloseSession", "(", ")", "{", "c", ".", "Pool", ".", "Close", "(", ")", "\n", "currClient", "=", "nil", "\n", "once", "=", "sync", ".", "Once", "{", "}", "\n", "}" ]
// CloseSession closes the connections to Redis
[ "CloseSession", "closes", "the", "connections", "to", "Redis" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/client.go#L77-L81
train
edgexfoundry/edgex-go
internal/pkg/db/redis/client.go
getConnection
func getConnection() (conn redis.Conn, err error) { if currClient == nil { return nil, errors.New("No current Redis client: create a new client before getting a connection from it") } conn = currClient.Pool.Get() return conn, nil }
go
func getConnection() (conn redis.Conn, err error) { if currClient == nil { return nil, errors.New("No current Redis client: create a new client before getting a connection from it") } conn = currClient.Pool.Get() return conn, nil }
[ "func", "getConnection", "(", ")", "(", "conn", "redis", ".", "Conn", ",", "err", "error", ")", "{", "if", "currClient", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "conn", "=", "currClient", ".", "Pool", ".", "Get", "(", ")", "\n", "return", "conn", ",", "nil", "\n", "}" ]
// getConnection gets a connection from the pool
[ "getConnection", "gets", "a", "connection", "from", "the", "pool" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/client.go#L84-L91
train
edgexfoundry/edgex-go
internal/pkg/db/redis/scheduler.go
IntervalByName
func (c *Client) IntervalByName(name string) (interval contract.Interval, err error) { conn := c.Pool.Get() defer conn.Close() err = getObjectByKey(conn, models.IntervalNameKey, name, &interval) return interval, err }
go
func (c *Client) IntervalByName(name string) (interval contract.Interval, err error) { conn := c.Pool.Get() defer conn.Close() err = getObjectByKey(conn, models.IntervalNameKey, name, &interval) return interval, err }
[ "func", "(", "c", "*", "Client", ")", "IntervalByName", "(", "name", "string", ")", "(", "interval", "contract", ".", "Interval", ",", "err", "error", ")", "{", "conn", ":=", "c", ".", "Pool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "err", "=", "getObjectByKey", "(", "conn", ",", "models", ".", "IntervalNameKey", ",", "name", ",", "&", "interval", ")", "\n", "return", "interval", ",", "err", "\n", "}" ]
// Return schedule interval by name
[ "Return", "schedule", "interval", "by", "name" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/scheduler.go#L73-L79
train
edgexfoundry/edgex-go
internal/pkg/db/redis/scheduler.go
IntervalById
func (c *Client) IntervalById(id string) (interval contract.Interval, err error) { conn := c.Pool.Get() defer conn.Close() object, err := redis.Bytes(conn.Do("GET", id)) if err == redis.ErrNil { return contract.Interval{}, db.ErrNotFound } else if err != nil { return contract.Interval{}, err } err = json.Unmarshal(object, &interval) if err != nil { return contract.Interval{}, err } return interval, err }
go
func (c *Client) IntervalById(id string) (interval contract.Interval, err error) { conn := c.Pool.Get() defer conn.Close() object, err := redis.Bytes(conn.Do("GET", id)) if err == redis.ErrNil { return contract.Interval{}, db.ErrNotFound } else if err != nil { return contract.Interval{}, err } err = json.Unmarshal(object, &interval) if err != nil { return contract.Interval{}, err } return interval, err }
[ "func", "(", "c", "*", "Client", ")", "IntervalById", "(", "id", "string", ")", "(", "interval", "contract", ".", "Interval", ",", "err", "error", ")", "{", "conn", ":=", "c", ".", "Pool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "object", ",", "err", ":=", "redis", ".", "Bytes", "(", "conn", ".", "Do", "(", "\"", "\"", ",", "id", ")", ")", "\n", "if", "err", "==", "redis", ".", "ErrNil", "{", "return", "contract", ".", "Interval", "{", "}", ",", "db", ".", "ErrNotFound", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "contract", ".", "Interval", "{", "}", ",", "err", "\n", "}", "\n\n", "err", "=", "json", ".", "Unmarshal", "(", "object", ",", "&", "interval", ")", "\n", "if", "err", "!=", "nil", "{", "return", "contract", ".", "Interval", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "interval", ",", "err", "\n", "}" ]
// Return schedule interval by ID
[ "Return", "schedule", "interval", "by", "ID" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/scheduler.go#L82-L99
train
edgexfoundry/edgex-go
internal/pkg/db/redis/scheduler.go
AddInterval
func (c *Client) AddInterval(from contract.Interval) (id string, err error) { interval := models.NewInterval(from) if interval.ID != "" { _, err = uuid.Parse(interval.ID) if err != nil { return "", db.ErrInvalidObjectId } } else { interval.ID = uuid.New().String() } if interval.Timestamps.Created == 0 { ts := db.MakeTimestamp() interval.Timestamps.Created = ts interval.Timestamps.Modified = ts } data, err := json.Marshal(interval) if err != nil { return "", err } conn := c.Pool.Get() defer conn.Close() _ = conn.Send("MULTI") addObject(data, interval, interval.ID, conn) _, err = conn.Do("EXEC") return interval.ID, err }
go
func (c *Client) AddInterval(from contract.Interval) (id string, err error) { interval := models.NewInterval(from) if interval.ID != "" { _, err = uuid.Parse(interval.ID) if err != nil { return "", db.ErrInvalidObjectId } } else { interval.ID = uuid.New().String() } if interval.Timestamps.Created == 0 { ts := db.MakeTimestamp() interval.Timestamps.Created = ts interval.Timestamps.Modified = ts } data, err := json.Marshal(interval) if err != nil { return "", err } conn := c.Pool.Get() defer conn.Close() _ = conn.Send("MULTI") addObject(data, interval, interval.ID, conn) _, err = conn.Do("EXEC") return interval.ID, err }
[ "func", "(", "c", "*", "Client", ")", "AddInterval", "(", "from", "contract", ".", "Interval", ")", "(", "id", "string", ",", "err", "error", ")", "{", "interval", ":=", "models", ".", "NewInterval", "(", "from", ")", "\n", "if", "interval", ".", "ID", "!=", "\"", "\"", "{", "_", ",", "err", "=", "uuid", ".", "Parse", "(", "interval", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "db", ".", "ErrInvalidObjectId", "\n", "}", "\n", "}", "else", "{", "interval", ".", "ID", "=", "uuid", ".", "New", "(", ")", ".", "String", "(", ")", "\n", "}", "\n\n", "if", "interval", ".", "Timestamps", ".", "Created", "==", "0", "{", "ts", ":=", "db", ".", "MakeTimestamp", "(", ")", "\n", "interval", ".", "Timestamps", ".", "Created", "=", "ts", "\n", "interval", ".", "Timestamps", ".", "Modified", "=", "ts", "\n", "}", "\n\n", "data", ",", "err", ":=", "json", ".", "Marshal", "(", "interval", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "conn", ":=", "c", ".", "Pool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "_", "=", "conn", ".", "Send", "(", "\"", "\"", ")", "\n", "addObject", "(", "data", ",", "interval", ",", "interval", ".", "ID", ",", "conn", ")", "\n", "_", ",", "err", "=", "conn", ".", "Do", "(", "\"", "\"", ")", "\n\n", "return", "interval", ".", "ID", ",", "err", "\n", "}" ]
// Add a new schedule interval
[ "Add", "a", "new", "schedule", "interval" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/scheduler.go#L102-L132
train
edgexfoundry/edgex-go
internal/pkg/db/redis/scheduler.go
UpdateInterval
func (c *Client) UpdateInterval(from contract.Interval) (err error) { check, err := c.IntervalByName(from.Name) if err != nil && err != redis.ErrNil { return err } if err == nil && from.ID != check.ID { // IDs are different -> name not unique return db.ErrNotUnique } from.Timestamps.Modified = db.MakeTimestamp() err = mergo.Merge(&from, check) if err != nil { return err } interval := models.NewInterval(from) data, err := json.Marshal(interval) if err != nil { return err } conn := c.Pool.Get() defer conn.Close() _ = conn.Send("MULTI") deleteObject(interval, interval.ID, conn) addObject(data, interval, interval.ID, conn) _, err = conn.Do("EXEC") return err }
go
func (c *Client) UpdateInterval(from contract.Interval) (err error) { check, err := c.IntervalByName(from.Name) if err != nil && err != redis.ErrNil { return err } if err == nil && from.ID != check.ID { // IDs are different -> name not unique return db.ErrNotUnique } from.Timestamps.Modified = db.MakeTimestamp() err = mergo.Merge(&from, check) if err != nil { return err } interval := models.NewInterval(from) data, err := json.Marshal(interval) if err != nil { return err } conn := c.Pool.Get() defer conn.Close() _ = conn.Send("MULTI") deleteObject(interval, interval.ID, conn) addObject(data, interval, interval.ID, conn) _, err = conn.Do("EXEC") return err }
[ "func", "(", "c", "*", "Client", ")", "UpdateInterval", "(", "from", "contract", ".", "Interval", ")", "(", "err", "error", ")", "{", "check", ",", "err", ":=", "c", ".", "IntervalByName", "(", "from", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "&&", "err", "!=", "redis", ".", "ErrNil", "{", "return", "err", "\n", "}", "\n", "if", "err", "==", "nil", "&&", "from", ".", "ID", "!=", "check", ".", "ID", "{", "// IDs are different -> name not unique", "return", "db", ".", "ErrNotUnique", "\n", "}", "\n\n", "from", ".", "Timestamps", ".", "Modified", "=", "db", ".", "MakeTimestamp", "(", ")", "\n", "err", "=", "mergo", ".", "Merge", "(", "&", "from", ",", "check", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "interval", ":=", "models", ".", "NewInterval", "(", "from", ")", "\n", "data", ",", "err", ":=", "json", ".", "Marshal", "(", "interval", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "conn", ":=", "c", ".", "Pool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "_", "=", "conn", ".", "Send", "(", "\"", "\"", ")", "\n", "deleteObject", "(", "interval", ",", "interval", ".", "ID", ",", "conn", ")", "\n", "addObject", "(", "data", ",", "interval", ",", "interval", ".", "ID", ",", "conn", ")", "\n", "_", ",", "err", "=", "conn", ".", "Do", "(", "\"", "\"", ")", "\n\n", "return", "err", "\n", "}" ]
// Update a schedule interval
[ "Update", "a", "schedule", "interval" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/scheduler.go#L135-L166
train
edgexfoundry/edgex-go
internal/pkg/db/redis/scheduler.go
DeleteIntervalById
func (c *Client) DeleteIntervalById(id string) (err error) { check, err := c.IntervalById(id) if err != nil { if err == db.ErrNotFound { return nil } return } interval := models.NewInterval(check) conn := c.Pool.Get() defer conn.Close() _ = conn.Send("MULTI") deleteObject(interval, id, conn) _, err = conn.Do("EXEC") return err }
go
func (c *Client) DeleteIntervalById(id string) (err error) { check, err := c.IntervalById(id) if err != nil { if err == db.ErrNotFound { return nil } return } interval := models.NewInterval(check) conn := c.Pool.Get() defer conn.Close() _ = conn.Send("MULTI") deleteObject(interval, id, conn) _, err = conn.Do("EXEC") return err }
[ "func", "(", "c", "*", "Client", ")", "DeleteIntervalById", "(", "id", "string", ")", "(", "err", "error", ")", "{", "check", ",", "err", ":=", "c", ".", "IntervalById", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "db", ".", "ErrNotFound", "{", "return", "nil", "\n", "}", "\n", "return", "\n", "}", "\n\n", "interval", ":=", "models", ".", "NewInterval", "(", "check", ")", "\n", "conn", ":=", "c", ".", "Pool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "_", "=", "conn", ".", "Send", "(", "\"", "\"", ")", "\n", "deleteObject", "(", "interval", ",", "id", ",", "conn", ")", "\n\n", "_", ",", "err", "=", "conn", ".", "Do", "(", "\"", "\"", ")", "\n\n", "return", "err", "\n", "}" ]
// Remove schedule interval by ID
[ "Remove", "schedule", "interval", "by", "ID" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/scheduler.go#L169-L188
train
edgexfoundry/edgex-go
internal/pkg/db/redis/scheduler.go
IntervalActionById
func (c *Client) IntervalActionById(id string) (action contract.IntervalAction, err error) { conn := c.Pool.Get() defer conn.Close() object, err := redis.Bytes(conn.Do("GET", id)) if err == redis.ErrNil { return contract.IntervalAction{}, db.ErrNotFound } else if err != nil { return contract.IntervalAction{}, err } err = json.Unmarshal(object, &action) if err != nil { return contract.IntervalAction{}, err } return action, err }
go
func (c *Client) IntervalActionById(id string) (action contract.IntervalAction, err error) { conn := c.Pool.Get() defer conn.Close() object, err := redis.Bytes(conn.Do("GET", id)) if err == redis.ErrNil { return contract.IntervalAction{}, db.ErrNotFound } else if err != nil { return contract.IntervalAction{}, err } err = json.Unmarshal(object, &action) if err != nil { return contract.IntervalAction{}, err } return action, err }
[ "func", "(", "c", "*", "Client", ")", "IntervalActionById", "(", "id", "string", ")", "(", "action", "contract", ".", "IntervalAction", ",", "err", "error", ")", "{", "conn", ":=", "c", ".", "Pool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "object", ",", "err", ":=", "redis", ".", "Bytes", "(", "conn", ".", "Do", "(", "\"", "\"", ",", "id", ")", ")", "\n", "if", "err", "==", "redis", ".", "ErrNil", "{", "return", "contract", ".", "IntervalAction", "{", "}", ",", "db", ".", "ErrNotFound", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "contract", ".", "IntervalAction", "{", "}", ",", "err", "\n", "}", "\n\n", "err", "=", "json", ".", "Unmarshal", "(", "object", ",", "&", "action", ")", "\n", "if", "err", "!=", "nil", "{", "return", "contract", ".", "IntervalAction", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "action", ",", "err", "\n", "}" ]
// Get schedule interval action by id
[ "Get", "schedule", "interval", "action", "by", "id" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/scheduler.go#L296-L313
train
edgexfoundry/edgex-go
internal/pkg/db/redis/scheduler.go
IntervalActionByName
func (c *Client) IntervalActionByName(name string) (action contract.IntervalAction, err error) { conn := c.Pool.Get() defer conn.Close() err = getObjectByKey(conn, models.IntervalActionNameKey, name, &action) return action, err }
go
func (c *Client) IntervalActionByName(name string) (action contract.IntervalAction, err error) { conn := c.Pool.Get() defer conn.Close() err = getObjectByKey(conn, models.IntervalActionNameKey, name, &action) return action, err }
[ "func", "(", "c", "*", "Client", ")", "IntervalActionByName", "(", "name", "string", ")", "(", "action", "contract", ".", "IntervalAction", ",", "err", "error", ")", "{", "conn", ":=", "c", ".", "Pool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "err", "=", "getObjectByKey", "(", "conn", ",", "models", ".", "IntervalActionNameKey", ",", "name", ",", "&", "action", ")", "\n", "return", "action", ",", "err", "\n", "}" ]
// Get schedule interval action by name
[ "Get", "schedule", "interval", "action", "by", "name" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/scheduler.go#L316-L322
train
edgexfoundry/edgex-go
internal/pkg/db/redis/scheduler.go
AddIntervalAction
func (c *Client) AddIntervalAction(from contract.IntervalAction) (id string, err error) { action := models.NewIntervalAction(from) if action.ID != "" { _, err = uuid.Parse(action.ID) if err != nil { return "", db.ErrInvalidObjectId } } else { action.ID = uuid.New().String() } if action.Created == 0 { ts := db.MakeTimestamp() action.Created = ts action.Modified = ts } data, err := json.Marshal(action) if err != nil { return "", err } conn := c.Pool.Get() defer conn.Close() _ = conn.Send("MULTI") addObject(data, action, action.ID, conn) _, err = conn.Do("EXEC") return action.ID, err }
go
func (c *Client) AddIntervalAction(from contract.IntervalAction) (id string, err error) { action := models.NewIntervalAction(from) if action.ID != "" { _, err = uuid.Parse(action.ID) if err != nil { return "", db.ErrInvalidObjectId } } else { action.ID = uuid.New().String() } if action.Created == 0 { ts := db.MakeTimestamp() action.Created = ts action.Modified = ts } data, err := json.Marshal(action) if err != nil { return "", err } conn := c.Pool.Get() defer conn.Close() _ = conn.Send("MULTI") addObject(data, action, action.ID, conn) _, err = conn.Do("EXEC") return action.ID, err }
[ "func", "(", "c", "*", "Client", ")", "AddIntervalAction", "(", "from", "contract", ".", "IntervalAction", ")", "(", "id", "string", ",", "err", "error", ")", "{", "action", ":=", "models", ".", "NewIntervalAction", "(", "from", ")", "\n", "if", "action", ".", "ID", "!=", "\"", "\"", "{", "_", ",", "err", "=", "uuid", ".", "Parse", "(", "action", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "db", ".", "ErrInvalidObjectId", "\n", "}", "\n", "}", "else", "{", "action", ".", "ID", "=", "uuid", ".", "New", "(", ")", ".", "String", "(", ")", "\n", "}", "\n\n", "if", "action", ".", "Created", "==", "0", "{", "ts", ":=", "db", ".", "MakeTimestamp", "(", ")", "\n", "action", ".", "Created", "=", "ts", "\n", "action", ".", "Modified", "=", "ts", "\n", "}", "\n\n", "data", ",", "err", ":=", "json", ".", "Marshal", "(", "action", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "conn", ":=", "c", ".", "Pool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "_", "=", "conn", ".", "Send", "(", "\"", "\"", ")", "\n", "addObject", "(", "data", ",", "action", ",", "action", ".", "ID", ",", "conn", ")", "\n", "_", ",", "err", "=", "conn", ".", "Do", "(", "\"", "\"", ")", "\n\n", "return", "action", ".", "ID", ",", "err", "\n", "}" ]
// Add schedule interval action
[ "Add", "schedule", "interval", "action" ]
c67086fe10c4d34caeefffaee5379490103dd63f
https://github.com/edgexfoundry/edgex-go/blob/c67086fe10c4d34caeefffaee5379490103dd63f/internal/pkg/db/redis/scheduler.go#L325-L355
train