Add StatsConfig in apier/v1/stats.go and ResourceConfig in apier/v1/resourcesv1.go and add test for them and modify name at tpresourcelimits.go to tpresources.go

This commit is contained in:
TeoV
2017-08-29 10:24:54 -04:00
parent d862a435d2
commit 08f5b7b060
6 changed files with 208 additions and 15 deletions

View File

@@ -80,15 +80,46 @@ func (rsv1 *ResourceSV1) ReleaseResource(args utils.AttrRLsResourceUsage, reply
return rsv1.rls.V1ReleaseResource(args, reply)
}
//after implement test for it
func (apierV1 *ApierV1) GetResourceConfig() {
type AttrGetResCfg struct {
ID string
}
func (apierV1 *ApierV1) SetResourceConfig() {
func (apierV1 *ApierV1) GetResourceConfig(attr AttrGetResCfg, reply *engine.ResourceCfg) error {
if missing := utils.MissingStructFields(&attr, []string{"ID"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if rcfg, err := apierV1.DataDB.GetResourceCfg(attr.ID, true, utils.NonTransactional); err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
} else {
*reply = *rcfg
}
return nil
}
func (apierV1 *ApierV1) RemResourceConfig() {
func (apierV1 *ApierV1) SetResourceConfig(attr *engine.ResourceCfg, reply *string) error {
if missing := utils.MissingStructFields(attr, []string{"ID"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierV1.DataDB.SetResourceCfg(attr, utils.NonTransactional); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
return nil
}
func (apierV1 *ApierV1) RemResourceConfig(attrs AttrGetResCfg, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"ID"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierV1.DataDB.RemoveResourceCfg(attrs.ID, utils.NonTransactional); err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = utils.OK
return nil
}

View File

@@ -23,6 +23,7 @@ import (
"net/rpc"
"net/rpc/jsonrpc"
"path"
"reflect"
"testing"
"time"
@@ -211,6 +212,69 @@ func TestRLsV1ReleaseResource(t *testing.T) {
}
var resConfig = &engine.ResourceCfg{
ID: "RCFG1",
Filters: []*engine.RequestFilter{
&engine.RequestFilter{
Type: "type",
FieldName: "Name",
Values: []string{"FilterValue1", "FilterValue2"},
},
},
ActivationInterval: &utils.ActivationInterval{
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
},
UsageTTL: time.Duration(10) * time.Microsecond,
Limit: 10,
AllocationMessage: "MessageAllocation",
Blocker: true,
Stored: true,
Weight: 20,
Thresholds: []string{"Val1", "Val2"},
}
func TestRLsV1GetResourceConfigBeforeSet(t *testing.T) {
var reply *string
if err := rlsV1Rpc.Call("ApierV1.GetResourceConfig", &AttrGetResCfg{ID: "RCFG1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func TestRLsV1SetResourceConfig(t *testing.T) {
var result string
if err := rlsV1Rpc.Call("ApierV1.SetResourceConfig", resConfig, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func TestRLsV1GetResourceConfigAfterSet(t *testing.T) {
var reply *engine.ResourceCfg
if err := rlsV1Rpc.Call("ApierV1.GetResourceConfig", &AttrGetResCfg{ID: "RCFG1"}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(reply, resConfig) {
t.Errorf("Expecting: %+v, received: %+v", resConfig, reply)
}
}
func TestRLsV1RemResourceCOnfig(t *testing.T) {
var resp string
if err := rlsV1Rpc.Call("ApierV1.RemResourceConfig", &AttrGetResCfg{ID: resConfig.ID}, &resp); err != nil {
t.Error(err)
} else if resp != utils.OK {
t.Error("Unexpected reply returned", resp)
}
}
func TestRLsV1GetResourceConfigAfterDelete(t *testing.T) {
var reply *string
if err := rlsV1Rpc.Call("ApierV1.GetResourceConfig", &AttrGetResCfg{ID: resConfig.ID}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func TestRLsV1StopEngine(t *testing.T) {
if err := engine.KillEngine(100); err != nil {
t.Error(err)

View File

@@ -88,15 +88,48 @@ func (stsv1 *StatSV1) LoadQueues(args stats.ArgsLoadQueues, reply *string) (err
return stsv1.sts.V1LoadQueues(args, reply)
}
//after implement test for it
func (apierV1 *ApierV1) GetStatConfig() {
type AttrGetStatsCfg struct {
ID string
}
func (apierV1 *ApierV1) GetStatConfig(attr AttrGetStatsCfg, reply *engine.StatsConfig) error {
if missing := utils.MissingStructFields(&attr, []string{"ID"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if sCfg, err := apierV1.DataDB.GetStatsConfig(attr.ID); err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
} else {
*reply = *sCfg
}
return nil
}
func (apierV1 *ApierV1) SetStatConfig(attr *engine.StatsConfig, reply *string) error {
if missing := utils.MissingStructFields(attr, []string{"ID"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierV1.DataDB.SetStatsConfig(attr); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
return nil
}
func (apierV1 *ApierV1) SetStatConfig() {
}
func (apierV1 *ApierV1) RemStatConfig() {
func (apierV1 *ApierV1) RemStatConfig(attrs AttrGetStatsCfg, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"ID"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierV1.DataDB.RemStatsConfig(attrs.ID); err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = utils.OK
return nil
}

View File

@@ -93,6 +93,7 @@ func TestStatSV1TPFromFolder(t *testing.T) {
time.Sleep(time.Duration(1000) * time.Millisecond)
}
/*
func TestStatSV1GetStats(t *testing.T) {
var reply []string
// first attempt should be empty since there is no queue in cache yet
@@ -166,6 +167,71 @@ func TestStatSV1ProcessEvent(t *testing.T) {
t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
}
}
*/
var statConfig = &engine.StatsConfig{
ID: "SCFG1",
Filters: []*engine.RequestFilter{
&engine.RequestFilter{
Type: "type",
FieldName: "Name",
Values: []string{"FilterValue1", "FilterValue2"},
},
},
ActivationInterval: &utils.ActivationInterval{
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
},
QueueLength: 10,
TTL: time.Duration(10) * time.Second,
Metrics: []string{"MetricValue", "MetricValueTwo"},
Store: false,
Thresholds: []string{"Val1", "Val2"},
Blocker: true,
Stored: true,
Weight: 20,
}
func TestStatSV1GetStatConfigBeforeSet(t *testing.T) {
var reply *engine.StatsConfig
if err := stsV1Rpc.Call("ApierV1.GetStatConfig", &AttrGetStatsCfg{ID: statConfig.ID}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func TestStatSV1SetStatConfig(t *testing.T) {
var result string
if err := stsV1Rpc.Call("ApierV1.SetStatConfig", statConfig, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
func TestStatSV1GetStatAfterSet(t *testing.T) {
var reply *engine.StatsConfig
if err := stsV1Rpc.Call("ApierV1.GetStatConfig", &AttrGetStatsCfg{ID: "SCFG1"}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(statConfig, reply) {
t.Errorf("Expecting: %+v, received: %+v", statConfig, reply)
}
}
func TestStatSV1RemoveStatConfig(t *testing.T) {
var resp string
if err := stsV1Rpc.Call("ApierV1.RemStatConfig", &AttrGetStatsCfg{ID: statConfig.ID}, &resp); err != nil {
t.Error(err)
} else if resp != utils.OK {
t.Error("Unexpected reply returned", resp)
}
}
func TestStatSV1GetStatConfigAfterRemove(t *testing.T) {
var reply *engine.StatsConfig
if err := stsV1Rpc.Call("ApierV1.GetStatConfig", &AttrGetStatsCfg{ID: "SCFG1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}
func TestStatSV1StopEngine(t *testing.T) {
if err := engine.KillEngine(100); err != nil {

View File

@@ -111,7 +111,6 @@ type DataDB interface {
GetReqFilterIndexes(dbKey string) (indexes map[string]map[string]utils.StringMap, err error)
SetReqFilterIndexes(dbKey string, indexes map[string]map[string]utils.StringMap) (err error)
MatchReqFilterIndex(dbKey, fieldName, fieldVal string) (itemIDs utils.StringMap, err error)
//modicari
GetStatsConfig(sqID string) (sq *StatsConfig, err error)
SetStatsConfig(sq *StatsConfig) (err error)
RemStatsConfig(sqID string) (err error)