mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 18:46:24 +05:00
Added CoreSv1 APIs back
This commit is contained in:
committed by
Dan Christian Bogos
parent
6dbdb45006
commit
fcddc96f30
45
apis/cores.go
Normal file
45
apis/cores.go
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package apis
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/cores"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func NewCoreSv1(cS *cores.CoreService) *CoreSv1 {
|
||||
return &CoreSv1{cS: cS}
|
||||
}
|
||||
|
||||
// CoreSv1 exports RPC from RLs
|
||||
type CoreSv1 struct {
|
||||
cS *cores.CoreService
|
||||
ping
|
||||
}
|
||||
|
||||
func (cS *CoreSv1) Status(_ *context.Context, arg *utils.TenantWithAPIOpts, reply *map[string]interface{}) error {
|
||||
return cS.cS.Status(arg, reply)
|
||||
}
|
||||
|
||||
// Sleep is used to test the concurrent requests mechanism
|
||||
func (cS *CoreSv1) Sleep(_ *context.Context, arg *utils.DurationArgs, reply *string) error {
|
||||
time.Sleep(arg.Duration)
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
59
apis/cores_test.go
Normal file
59
apis/cores_test.go
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package apis
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/cores"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestCoreSStatus(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
caps := engine.NewCaps(2, utils.MetaTopUp)
|
||||
coreService := cores.NewCoreService(cfg, caps, make(chan struct{}))
|
||||
cS := NewCoreSv1(coreService)
|
||||
arg := &utils.TenantWithAPIOpts{
|
||||
Tenant: "cgrates.org",
|
||||
APIOpts: map[string]interface{}{},
|
||||
}
|
||||
var reply map[string]interface{}
|
||||
if err := cS.Status(context.Background(), arg, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCoreSSleep(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
caps := engine.NewCaps(2, utils.MetaTopUp)
|
||||
coreService := cores.NewCoreService(cfg, caps, make(chan struct{}))
|
||||
cS := NewCoreSv1(coreService)
|
||||
arg := &utils.DurationArgs{
|
||||
Duration: 3 * time.Second,
|
||||
}
|
||||
var reply string
|
||||
if err := cS.Sleep(context.Background(), arg, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != "OK" {
|
||||
t.Errorf("Expected OK, reveived %+v", reply)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/cgrates/birpc"
|
||||
"github.com/cgrates/cgrates/apis"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/cores"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
@@ -51,8 +52,8 @@ type CoreService struct {
|
||||
caps *engine.Caps
|
||||
stopChan chan struct{}
|
||||
|
||||
cS *cores.CoreService
|
||||
// rpc *v1.CoreSv1
|
||||
cS *cores.CoreService
|
||||
rpc *apis.CoreSv1
|
||||
connChan chan birpc.ClientConnector
|
||||
anz *AnalyzerService
|
||||
srvDep map[string]*sync.WaitGroup
|
||||
@@ -69,11 +70,12 @@ func (cS *CoreService) Start() (err error) {
|
||||
utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.CoreS))
|
||||
cS.stopChan = make(chan struct{})
|
||||
cS.cS = cores.NewCoreService(cS.cfg, cS.caps, cS.stopChan)
|
||||
// cS.rpc = v1.NewCoreSv1(cS.cS)
|
||||
// if !cS.cfg.DispatcherSCfg().Enabled {
|
||||
// cS.server.RpcRegister(cS.rpc)
|
||||
// }
|
||||
// cS.connChan <- cS.anz.GetInternalCodec(cS.rpc, utils.CoreS)
|
||||
cS.rpc = apis.NewCoreSv1(cS.cS)
|
||||
srv, _ := birpc.NewService(cS.rpc, utils.EmptyString, false)
|
||||
if !cS.cfg.DispatcherSCfg().Enabled {
|
||||
cS.server.RpcRegister(srv)
|
||||
}
|
||||
cS.connChan <- cS.anz.GetInternalCodec(srv, utils.CoreS)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -89,8 +91,8 @@ func (cS *CoreService) Shutdown() (err error) {
|
||||
cS.cS.Shutdown()
|
||||
close(cS.stopChan)
|
||||
cS.cS = nil
|
||||
// cS.rpc = nil
|
||||
//<-cS.connChan
|
||||
cS.rpc = nil
|
||||
<-cS.connChan
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user