ThresholdS V1GetThresholdIDs

This commit is contained in:
DanB
2017-10-01 10:29:49 +02:00
parent 6a67e93385
commit 5427f395c3
2 changed files with 35 additions and 8 deletions

View File

@@ -61,7 +61,7 @@ const (
colRes = "resources"
colSqs = "statqueues"
colSqp = "statqueue_profiles"
colTlds = "threshold_profiles"
colTps = "threshold_profiles"
colThs = "thresholds"
)
@@ -330,7 +330,7 @@ func (ms *MongoStorage) getColNameForPrefix(prefix string) (name string, ok bool
utils.TimingsPrefix: colTmg,
utils.ResourcesPrefix: colRes,
utils.ResourceProfilesPrefix: colRsP,
utils.ThresholdProfilePrefix: colTlds,
utils.ThresholdProfilePrefix: colTps,
utils.ThresholdPrefix: colThs,
}
name, ok = colMap[prefix]
@@ -681,6 +681,18 @@ func (ms *MongoStorage) GetKeysForPrefix(prefix string) (result []string, err er
for iter.Next(&idResult) {
result = append(result, utils.TimingsPrefix+idResult.Id)
}
case utils.ThresholdPrefix:
qry := bson.M{}
if tntID.Tenant != "" {
qry["tenant"] = tntID.Tenant
}
if tntID.ID != "" {
qry["id"] = bson.M{"$regex": bson.RegEx{Pattern: subject}}
}
iter := db.C(colThs).Find(qry).Select(bson.M{"tenant": 1, "id": 1}).Iter()
for iter.Next(&idResult) {
result = append(result, utils.ThresholdPrefix+utils.ConcatenatedKey(idResult.Tenant, idResult.Id))
}
default:
err = fmt.Errorf("unsupported prefix in GetKeysForPrefix: %s", prefix)
}
@@ -718,7 +730,7 @@ func (ms *MongoStorage) HasData(category, subject string) (has bool, err error)
count, err = db.C(colRes).Find(bson.M{"id": subject}).Count()
has = count > 0
case utils.ThresholdProfilePrefix:
count, err = db.C(colThs).Find(bson.M{"id": subject}).Count()
count, err = db.C(colTps).Find(bson.M{"id": subject}).Count()
has = count > 0
default:
err = fmt.Errorf("unsupported category in HasData: %s", category)
@@ -2145,7 +2157,7 @@ func (ms *MongoStorage) GetThresholdProfile(tenant, ID string,
return x.(*ThresholdProfile), nil
}
}
session, col := ms.conn(colTlds)
session, col := ms.conn(colTps)
defer session.Close()
tp = new(ThresholdProfile)
cCommit := cacheCommit(transactionID)
@@ -2167,7 +2179,7 @@ func (ms *MongoStorage) GetThresholdProfile(tenant, ID string,
// SetThresholdProfile stores a ThresholdProfile into DataDB
func (ms *MongoStorage) SetThresholdProfile(tp *ThresholdProfile) (err error) {
session, col := ms.conn(colTlds)
session, col := ms.conn(colTps)
defer session.Close()
_, err = col.UpsertId(bson.M{"tenant": tp.Tenant, "id": tp.ID}, tp)
return
@@ -2175,7 +2187,7 @@ func (ms *MongoStorage) SetThresholdProfile(tp *ThresholdProfile) (err error) {
// RemThresholdProfile removes a ThresholdProfile from dataDB/cache
func (ms *MongoStorage) RemThresholdProfile(tenant, id, transactionID string) (err error) {
session, col := ms.conn(colTlds)
session, col := ms.conn(colTps)
defer session.Close()
err = col.Remove(bson.M{"tenant": tenant, "id": id})
if err != nil {

View File

@@ -325,7 +325,7 @@ func (tS *ThresholdService) processEvent(ev *ThresholdEvent) (err error) {
return
}
// V1ProcessEvent implements StatV1 method for processing an Event
// V1ProcessEvent implements ThresholdService method for processing an Event
func (tS *ThresholdService) V1ProcessEvent(ev *ThresholdEvent, reply *string) (err error) {
if missing := utils.MissingStructFields(ev, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
@@ -336,7 +336,7 @@ func (tS *ThresholdService) V1ProcessEvent(ev *ThresholdEvent, reply *string) (e
return
}
// V1StatQueuesForEvent implements StatV1 method for processing an Event
// V1GetThresholdsForEvent queries thresholds matching an Event
func (tS *ThresholdService) V1GetThresholdsForEvent(ev *ThresholdEvent, reply *Thresholds) (err error) {
if missing := utils.MissingStructFields(ev, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
@@ -347,3 +347,18 @@ func (tS *ThresholdService) V1GetThresholdsForEvent(ev *ThresholdEvent, reply *T
}
return
}
// V1GetQueueIDs returns list of queueIDs registered for a tenant
func (tS *ThresholdService) V1GetThresholdIDs(tenant string, tIDs *[]string) (err error) {
prfx := utils.ThresholdPrefix + tenant + ":"
keys, err := tS.dm.DataDB().GetKeysForPrefix(prfx)
if err != nil {
return err
}
retIDs := make([]string, len(keys))
for i, key := range keys {
retIDs[i] = key[len(prfx):]
}
*tIDs = retIDs
return
}