mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 00:58:45 +05:00
Basic Skel of tpExporter
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
/*
|
||||
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 services
|
||||
|
||||
import (
|
||||
@@ -74,6 +76,7 @@ func (tpSrv *TPeService) Reload(*context.Context, context.CancelFunc) (err error
|
||||
func (tpSrv *TPeService) Shutdown() (err error) {
|
||||
tpSrv.srv = nil
|
||||
close(tpSrv.stopChan)
|
||||
utils.Logger.Info(fmt.Sprintf("<%s> stopped <%s> subsystem", utils.CoreS, utils.TPeS))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
44
tpes/tpes.go
44
tpes/tpes.go
@@ -1,14 +1,17 @@
|
||||
/*
|
||||
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/>
|
||||
*/
|
||||
@@ -16,15 +19,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func NewTPeS(cfg *config.CGRConfig, cm *engine.ConnManager) *TPeS {
|
||||
return &TPeS{
|
||||
func NewTPeS(cfg *config.CGRConfig, cm *engine.ConnManager) (tpE *TPeS) {
|
||||
tpE = &TPeS{
|
||||
cfg: cfg,
|
||||
connMgr: cm,
|
||||
exps: make(map[string]tpExporter),
|
||||
}
|
||||
/*
|
||||
for expType := range tpExporterTypes {
|
||||
if tpE[expType], err = newTPExporter(expType, dm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
*/
|
||||
return
|
||||
}
|
||||
|
||||
// TPeS is managing the TariffPlanExporter
|
||||
@@ -32,4 +47,29 @@ type TPeS struct {
|
||||
cfg *config.CGRConfig
|
||||
connMgr *engine.ConnManager
|
||||
fltr *engine.FilterS
|
||||
exps map[string]tpExporter
|
||||
}
|
||||
|
||||
type ArgsExportTP struct {
|
||||
Tenant string
|
||||
APIOpts map[string]interface{}
|
||||
ExportItems map[string][]string // map[expType][]string{"itemID1", "itemID2"}
|
||||
}
|
||||
|
||||
// V1ExportTariffPlan is the API executed to export tariff plan items
|
||||
func (tpE *TPeS) V1ExportTariffPlan(ctx *context.Context, args *ArgsExportTP, reply *utils.Account) (err error) {
|
||||
for eType := range args.ExportItems {
|
||||
if _, has := tpE.exps[eType]; !has {
|
||||
return utils.ErrPrefix(utils.ErrUnsupportedTPExporterType, eType)
|
||||
}
|
||||
}
|
||||
/*
|
||||
code to export to zip comes here
|
||||
for expType, expItms := range args.ExportItems {
|
||||
if expCnt, err = tpE.exps[expType].exportItems(expItms); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
}
|
||||
*/
|
||||
return
|
||||
}
|
||||
|
||||
42
tpes/tpexporter.go
Normal file
42
tpes/tpexporter.go
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
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 tpes
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var tpExporterTypes = utils.NewStringSet([]string{utils.MetaAttributes, utils.MetaResources, utils.MetaFilters, utils.MetaStats,
|
||||
utils.MetaThresholds, utils.MetaRoutes, utils.MetaChargers, utils.MetaDispatchers, utils.MetaDispatcherHosts,
|
||||
utils.MetaRateProfiles, utils.MetaActions, utils.MetaAccounts})
|
||||
|
||||
// tpExporter is the interface implementing exports of tariff plan items
|
||||
type tpExporter interface {
|
||||
exportItems(itmIDs []string) (expContent []byte, err error)
|
||||
}
|
||||
|
||||
// newTPExporter constructs tpExporters
|
||||
func newTPExporter(expType string, dm *engine.DataManager) (tpE tpExporter, err error) {
|
||||
switch expType {
|
||||
default:
|
||||
return nil, utils.ErrPrefix(utils.ErrUnsupportedTPExporterType, expType)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -75,6 +75,7 @@ var (
|
||||
ErrMaxConcurentRPCExceeded = errors.New("MAX_CONCURENT_RPC_EXCEEDED") // but the codec will rewrite it with this one to be sure that we corectly dealocate the request
|
||||
ErrMaxIterationsReached = errors.New("maximum iterations reached")
|
||||
ErrNegative = errors.New("NEGATIVE")
|
||||
ErrUnsupportedTPExporterType = errors.New("UNSUPPORTED_TPEXPORTER_TYPE")
|
||||
|
||||
ErrMap = map[string]error{
|
||||
ErrNoMoreData.Error(): ErrNoMoreData,
|
||||
|
||||
Reference in New Issue
Block a user