diff --git a/services/tpes.go b/services/tpes.go
index 88ee058a8..5a33b47be 100644
--- a/services/tpes.go
+++ b/services/tpes.go
@@ -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
*/
-
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
}
diff --git a/tpes/tpes.go b/tpes/tpes.go
index 9ceed4b1f..3515dac5b 100644
--- a/tpes/tpes.go
+++ b/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
*/
@@ -16,15 +19,27 @@ along with this program. If not, see
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
}
diff --git a/tpes/tpexporter.go b/tpes/tpexporter.go
new file mode 100644
index 000000000..6ce11e96d
--- /dev/null
+++ b/tpes/tpexporter.go
@@ -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
+*/
+
+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
+}
diff --git a/utils/errors.go b/utils/errors.go
index 445942bb7..a1b0235a9 100644
--- a/utils/errors.go
+++ b/utils/errors.go
@@ -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,