diff --git a/internal/database/database.go b/internal/database/database.go new file mode 100644 index 0000000..01d6866 --- /dev/null +++ b/internal/database/database.go @@ -0,0 +1,20 @@ +package database + +import ( + "go.mongodb.org/mongo-driver/bson" + + "github.com/free5gc/openapi/models" +) + +const ( + APPDATA_INFLUDATA_DB_COLLECTION_NAME = "applicationData.influenceData" + APPDATA_INFLUDATA_SUBSC_DB_COLLECTION_NAME = "applicationData.influenceData.subsToNotify" + APPDATA_PFD_DB_COLLECTION_NAME = "applicationData.pfds" +) + +type DbConnector interface { + PatchDataToDBAndNotify(collName string, ueId string, patchItem []models.PatchItem, filter bson.M) error + GetDataFromDB(collName string, filter bson.M) (map[string]interface{}, *models.ProblemDetails) + GetDataFromDBWithArg(collName string, filter bson.M, strength int) (map[string]interface{}, *models.ProblemDetails) + DeleteDataFromDB(collName string, filter bson.M) +} diff --git a/internal/sbi/processor/mongo_db_tools.go b/internal/database/mongodb/mongo_db_inplement.go similarity index 63% rename from internal/sbi/processor/mongo_db_tools.go rename to internal/database/mongodb/mongo_db_inplement.go index 2476ca9..0cae50d 100644 --- a/internal/sbi/processor/mongo_db_tools.go +++ b/internal/database/mongodb/mongo_db_inplement.go @@ -1,4 +1,4 @@ -package processor +package mongodb import ( "encoding/json" @@ -8,17 +8,25 @@ import ( "github.com/free5gc/openapi" "github.com/free5gc/openapi/models" "github.com/free5gc/udr/internal/logger" + "github.com/free5gc/udr/internal/sbi/processor" "github.com/free5gc/udr/internal/util" + "github.com/free5gc/udr/pkg/factory" "github.com/free5gc/util/mongoapi" ) -const ( - APPDATA_INFLUDATA_DB_COLLECTION_NAME = "applicationData.influenceData" - APPDATA_INFLUDATA_SUBSC_DB_COLLECTION_NAME = "applicationData.influenceData.subsToNotify" - APPDATA_PFD_DB_COLLECTION_NAME = "applicationData.pfds" -) +type MongoDbImplement struct { + *factory.Mongodb +} -func patchDataToDBAndNotify(collName string, ueId string, patchItem []models.PatchItem, filter bson.M) error { +func NewMongoDbImplement(m *factory.Mongodb) *MongoDbImplement { + return &MongoDbImplement{ + Mongodb: m, + } +} + +func (m *MongoDbImplement) PatchDataToDBAndNotify( + collName string, ueId string, patchItem []models.PatchItem, filter bson.M, +) error { var err error origValue, err := mongoapi.RestfulAPIGetOne(collName, filter) if err != nil { @@ -38,11 +46,14 @@ func patchDataToDBAndNotify(collName string, ueId string, patchItem []models.Pat if err != nil { return err } - PreHandleOnDataChangeNotify(ueId, CurrentResourceUri, patchItem, origValue, newValue) + processor.PreHandleOnDataChangeNotify(ueId, processor.CurrentResourceUri, patchItem, origValue, newValue) return nil } -func getDataFromDB(collName string, filter bson.M) (map[string]interface{}, *models.ProblemDetails) { +func (m *MongoDbImplement) GetDataFromDB( + collName string, filter bson.M) ( + map[string]interface{}, *models.ProblemDetails, +) { data, err := mongoapi.RestfulAPIGetOne(collName, filter) if err != nil { return nil, openapi.ProblemDetailsSystemFailure(err.Error()) @@ -53,7 +64,7 @@ func getDataFromDB(collName string, filter bson.M) (map[string]interface{}, *mod return data, nil } -func getDataFromDBWithArg(collName string, filter bson.M, strength int) ( +func (m *MongoDbImplement) GetDataFromDBWithArg(collName string, filter bson.M, strength int) ( map[string]interface{}, *models.ProblemDetails, ) { data, err := mongoapi.RestfulAPIGetOne(collName, filter, strength) @@ -68,7 +79,7 @@ func getDataFromDBWithArg(collName string, filter bson.M, strength int) ( return data, nil } -func deleteDataFromDB(collName string, filter bson.M) { +func (m *MongoDbImplement) DeleteDataFromDB(collName string, filter bson.M) { if err := mongoapi.RestfulAPIDeleteOne(collName, filter); err != nil { logger.DataRepoLog.Errorf("deleteDataFromDB: %+v", err) } diff --git a/internal/sbi/api_datarepository.go b/internal/sbi/api_datarepository.go index a77034b..ff40cbb 100644 --- a/internal/sbi/api_datarepository.go +++ b/internal/sbi/api_datarepository.go @@ -737,15 +737,13 @@ func (s *Server) getDataRepositoryRoutes() []Route { "/application-data/influenceData/:influenceId", s.HandleApplicationDataInfluenceDataInfluenceIdPut, }, - + { "ApplicationDataInfluenceDataInfluenceIdPut", strings.ToUpper("Post"), "/application-data/influenceData/:influenceId", s.HandleApplicationDataInfluenceDataInfluenceIdPost, }, - - } } @@ -2573,7 +2571,7 @@ func (s *Server) HandleApplicationDataInfluenceDataInfluenceIdPut(c *gin.Context s.Processor().ApplicationDataInfluenceDataInfluenceIdPutProcedure(c, collName, influenceId, &trafficInfluData) } + func (s *Server) HandleApplicationDataInfluenceDataInfluenceIdPost(c *gin.Context) { s.Processor().ApplicationDataInfluenceDataInfluenceIdPostProcedure(c) } - diff --git a/internal/sbi/api_sanity_test.go b/internal/sbi/api_sanity_test.go index 70db5d6..c34f340 100644 --- a/internal/sbi/api_sanity_test.go +++ b/internal/sbi/api_sanity_test.go @@ -13,8 +13,8 @@ import ( "github.com/stretchr/testify/require" "github.com/free5gc/openapi/models" + db "github.com/free5gc/udr/internal/database" "github.com/free5gc/udr/internal/logger" - "github.com/free5gc/udr/internal/sbi/processor" "github.com/free5gc/udr/pkg/factory" util_logger "github.com/free5gc/util/logger" "github.com/free5gc/util/mongoapi" @@ -37,11 +37,11 @@ func setupHttpServer() *gin.Engine { func setupMongoDB(t *testing.T) { err := mongoapi.SetMongoDB("test5gc", "mongodb://localhost:27017") require.Nil(t, err) - err = mongoapi.Drop(processor.APPDATA_INFLUDATA_DB_COLLECTION_NAME) + err = mongoapi.Drop(db.APPDATA_INFLUDATA_DB_COLLECTION_NAME) require.Nil(t, err) - err = mongoapi.Drop(processor.APPDATA_INFLUDATA_SUBSC_DB_COLLECTION_NAME) + err = mongoapi.Drop(db.APPDATA_INFLUDATA_SUBSC_DB_COLLECTION_NAME) require.Nil(t, err) - err = mongoapi.Drop(processor.APPDATA_PFD_DB_COLLECTION_NAME) + err = mongoapi.Drop(db.APPDATA_PFD_DB_COLLECTION_NAME) require.Nil(t, err) } diff --git a/internal/sbi/processor/access_and_mobility_subscription_data_document.go b/internal/sbi/processor/access_and_mobility_subscription_data_document.go index b0b4cc1..d6f90b2 100644 --- a/internal/sbi/processor/access_and_mobility_subscription_data_document.go +++ b/internal/sbi/processor/access_and_mobility_subscription_data_document.go @@ -22,7 +22,7 @@ func (p *Processor) QueryAmDataProcedure(c *gin.Context, collName string, ueId s logger.DataRepoLog.Infof("QueryAmDataProcedure: ueId: %s, servingPlmnId: %s", ueId, servingPlmnId) filter := bson.M{"ueId": ueId, "servingPlmnId": servingPlmnId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { c.JSON(int(pd.Status), pd) return diff --git a/internal/sbi/processor/amf3_gpp_access_registration_document.go b/internal/sbi/processor/amf3_gpp_access_registration_document.go index 97ce5ab..15465bc 100644 --- a/internal/sbi/processor/amf3_gpp_access_registration_document.go +++ b/internal/sbi/processor/amf3_gpp_access_registration_document.go @@ -25,7 +25,7 @@ func (p *Processor) AmfContext3gppProcedure( c *gin.Context, collName string, ueId string, patchItem []models.PatchItem, ) { filter := bson.M{"ueId": ueId} - if err := patchDataToDBAndNotify(collName, ueId, patchItem, filter); err != nil { + if err := p.PatchDataToDBAndNotify(collName, ueId, patchItem, filter); err != nil { logger.DataRepoLog.Errorf("AmfContext3gppProcedure err: %+v", err) problemDetails := util.ProblemDetailsModifyNotAllowed("") c.JSON(int(problemDetails.Status), problemDetails) @@ -48,7 +48,7 @@ func (p *Processor) CreateAmfContext3gppProcedure(c *gin.Context, collName strin func (p *Processor) QueryAmfContext3gppProcedure(c *gin.Context, collName string, ueId string) { filter := bson.M{"ueId": ueId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("QueryAmfContext3gppProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/amf_non3_gpp_access_registration_document.go b/internal/sbi/processor/amf_non3_gpp_access_registration_document.go index d552e12..157e104 100644 --- a/internal/sbi/processor/amf_non3_gpp_access_registration_document.go +++ b/internal/sbi/processor/amf_non3_gpp_access_registration_document.go @@ -25,7 +25,7 @@ func (p *Processor) AmfContextNon3gppProcedure( c *gin.Context, ueId string, collName string, patchItem []models.PatchItem, filter bson.M, ) { - if err := patchDataToDBAndNotify(collName, ueId, patchItem, filter); err != nil { + if err := p.PatchDataToDBAndNotify(collName, ueId, patchItem, filter); err != nil { logger.DataRepoLog.Errorf("AmfContextNon3gppProcedure err: %+v", err) pd := util.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(pd.Status), pd) @@ -50,7 +50,7 @@ func (p *Processor) CreateAmfContextNon3gppProcedure( func (p *Processor) QueryAmfContextNon3gppProcedure(c *gin.Context, collName string, ueId string) { filter := bson.M{"ueId": ueId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("QueryAmfContextNon3gppProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/authentication_data_document.go b/internal/sbi/processor/authentication_data_document.go index cba95ee..03b6443 100644 --- a/internal/sbi/processor/authentication_data_document.go +++ b/internal/sbi/processor/authentication_data_document.go @@ -24,7 +24,7 @@ func (p *Processor) ModifyAuthenticationProcedure( c *gin.Context, collName string, ueId string, patchItem []models.PatchItem, ) { filter := bson.M{"ueId": ueId} - if err := patchDataToDBAndNotify(collName, ueId, patchItem, filter); err != nil { + if err := p.PatchDataToDBAndNotify(collName, ueId, patchItem, filter); err != nil { logger.DataRepoLog.Errorf("ModifyAuthenticationProcedure err: %+v", err) c.JSON(http.StatusInternalServerError, util.ProblemDetailsModifyNotAllowed("")) } @@ -33,7 +33,7 @@ func (p *Processor) ModifyAuthenticationProcedure( func (p *Processor) QueryAuthSubsDataProcedure(c *gin.Context, collName string, ueId string) { filter := bson.M{"ueId": ueId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { if pd.Status == http.StatusNotFound { logger.DataRepoLog.Warnf("QueryAuthSubsDataProcedure err: %s", pd.Title) diff --git a/internal/sbi/processor/authentication_so_r_document.go b/internal/sbi/processor/authentication_so_r_document.go index 5e34ee0..75f31f8 100644 --- a/internal/sbi/processor/authentication_so_r_document.go +++ b/internal/sbi/processor/authentication_so_r_document.go @@ -32,7 +32,7 @@ func (p *Processor) CreateAuthenticationSoRProcedure(c *gin.Context, collName st func (p *Processor) QueryAuthSoRProcedure(c *gin.Context, collName string, ueId string) { filter := bson.M{"ueId": ueId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("QueryAuthSoRProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/authentication_status_document.go b/internal/sbi/processor/authentication_status_document.go index 441b94c..b89a7d3 100644 --- a/internal/sbi/processor/authentication_status_document.go +++ b/internal/sbi/processor/authentication_status_document.go @@ -32,7 +32,7 @@ func (p *Processor) CreateAuthenticationStatusProcedure(c *gin.Context, collName func (p *Processor) QueryAuthenticationStatusProcedure(c *gin.Context, collName string, ueId string) { filter := bson.M{"ueId": ueId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("QueryAuthenticationStatusProcedure err: %s", pd.Detail) diff --git a/internal/sbi/processor/default.go b/internal/sbi/processor/default.go index a2d2da8..086212f 100644 --- a/internal/sbi/processor/default.go +++ b/internal/sbi/processor/default.go @@ -23,6 +23,7 @@ import ( "github.com/free5gc/openapi" "github.com/free5gc/openapi/models" udr_context "github.com/free5gc/udr/internal/context" + db "github.com/free5gc/udr/internal/database" "github.com/free5gc/udr/internal/logger" "github.com/free5gc/udr/internal/util" "github.com/free5gc/util/mongoapi" @@ -30,13 +31,13 @@ import ( func (p *Processor) DeleteApplicationDataIndividualPfdFromDBProcedure(c *gin.Context, appID string) { filter := bson.M{"applicationId": appID} - deleteDataFromDB(APPDATA_PFD_DB_COLLECTION_NAME, filter) + p.DeleteDataFromDB(db.APPDATA_PFD_DB_COLLECTION_NAME, filter) c.Status(http.StatusNoContent) } func (p *Processor) GetApplicationDataIndividualPfdFromDBProcedure(c *gin.Context, appID string) { filter := bson.M{"applicationId": appID} - data, pd := getDataFromDB(APPDATA_PFD_DB_COLLECTION_NAME, filter) + data, pd := p.GetDataFromDB(db.APPDATA_PFD_DB_COLLECTION_NAME, filter) if pd != nil { logger.DataRepoLog.Errorf("getApplicationDataIndividualPfdFromDB err: %s", pd.Detail) c.JSON(int(pd.Status), pd) @@ -50,7 +51,7 @@ func (p *Processor) PutApplicationDataIndividualPfdToDBProcedure( filter := bson.M{"applicationId": appID} data := util.ToBsonM(*pfdDataForApp) - existed, err := mongoapi.RestfulAPIPutOne(APPDATA_PFD_DB_COLLECTION_NAME, filter, data) + existed, err := mongoapi.RestfulAPIPutOne(db.APPDATA_PFD_DB_COLLECTION_NAME, filter, data) if err != nil { logger.DataRepoLog.Errorf("putApplicationDataIndividualPfdToDB err: %+v", err) c.JSON(http.StatusInternalServerError, nil) @@ -69,7 +70,7 @@ func (p *Processor) GetApplicationDataPfdsFromDBProcedure(c *gin.Context, pfdsAp var matchedPfds []map[string]interface{} if len(pfdsAppIDs) == 0 { var err error - matchedPfds, err = mongoapi.RestfulAPIGetMany(APPDATA_PFD_DB_COLLECTION_NAME, filter) + matchedPfds, err = mongoapi.RestfulAPIGetMany(db.APPDATA_PFD_DB_COLLECTION_NAME, filter) if err != nil { logger.DataRepoLog.Errorf("getApplicationDataPfdsFromDB err: %+v", err) c.JSON(http.StatusOK, nil) @@ -78,7 +79,7 @@ func (p *Processor) GetApplicationDataPfdsFromDBProcedure(c *gin.Context, pfdsAp } else { for _, v := range pfdsAppIDs { filter := bson.M{"applicationId": v} - data, pd := getDataFromDB(APPDATA_PFD_DB_COLLECTION_NAME, filter) + data, pd := p.GetDataFromDB(db.APPDATA_PFD_DB_COLLECTION_NAME, filter) if pd == nil { matchedPfds = append(matchedPfds, data) } @@ -91,7 +92,7 @@ func (p *Processor) PolicyDataBdtDataBdtReferenceIdDeleteProcedure( c *gin.Context, collName string, bdtReferenceId string, ) { filter := bson.M{"bdtReferenceId": bdtReferenceId} - deleteDataFromDB(collName, filter) + p.DeleteDataFromDB(collName, filter) c.Status(http.StatusNoContent) } @@ -99,7 +100,7 @@ func (p *Processor) PolicyDataBdtDataBdtReferenceIdGetProcedure( c *gin.Context, collName string, bdtReferenceId string, ) { filter := bson.M{"bdtReferenceId": bdtReferenceId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("PolicyDataBdtDataBdtReferenceIdGetProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) @@ -141,7 +142,7 @@ func (p *Processor) PolicyDataBdtDataGetProcedure(c *gin.Context, collName strin func (p *Processor) PolicyDataPlmnsPlmnIdUePolicySetGetProcedure(c *gin.Context, collName string, plmnId string) { filter := bson.M{"plmnId": plmnId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("PolicyDataPlmnsPlmnIdUePolicySetGetProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) @@ -154,7 +155,7 @@ func (p *Processor) PolicyDataSponsorConnectivityDataSponsorIdGetProcedure(c *gi sponsorId string, ) { filter := bson.M{"sponsorId": sponsorId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("PolicyDataSponsorConnectivityDataSponsorIdGetProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) @@ -210,7 +211,7 @@ func (p *Processor) PolicyDataUesUeIdAmDataGetProcedure(c *gin.Context, collName ueId string, ) { filter := bson.M{"ueId": ueId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("PolicyDataUesUeIdAmDataGetProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) @@ -222,7 +223,7 @@ func (p *Processor) PolicyDataUesUeIdOperatorSpecificDataGetProcedure(c *gin.Con ueId string, ) { filter := bson.M{"ueId": ueId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("PolicyDataUesUeIdOperatorSpecificDataGetProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) @@ -273,7 +274,7 @@ func (p *Processor) PolicyDataUesUeIdSmDataGetProcedure( ) { filter := bson.M{"ueId": ueId} - smPolicyData, pd := getDataFromDBWithArg(collName, filter, mongoapi.COLLATION_STRENGTH_IGNORE_CASE) + smPolicyData, pd := p.GetDataFromDBWithArg(collName, filter, mongoapi.COLLATION_STRENGTH_IGNORE_CASE) if pd != nil { c.JSON(int(pd.Status), pd) return @@ -366,7 +367,7 @@ func (p *Processor) PolicyDataUesUeIdSmDataPatchProcedure(c *gin.Context, collNa successAll = false } else { var usageMonData models.UsageMonData - usageMonDataBsonM, pd := getDataFromDB(collName, filter) + usageMonDataBsonM, pd := p.GetDataFromDB(collName, filter) if pd != nil && pd.Status == http.StatusInternalServerError { logger.DataRepoLog.Errorf("PolicyDataUesUeIdSmDataPatchProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) @@ -380,7 +381,7 @@ func (p *Processor) PolicyDataUesUeIdSmDataPatchProcedure(c *gin.Context, collNa } if successAll { - smPolicyDataBsonM, pd := getDataFromDB(collName, filter) + smPolicyDataBsonM, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("PolicyDataUesUeIdSmDataPatchProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) @@ -419,7 +420,7 @@ func (p *Processor) PolicyDataUesUeIdSmDataUsageMonIdDeleteProcedure( c *gin.Context, collName string, ueId string, usageMonId string, ) { filter := bson.M{"ueId": ueId, "usageMonId": usageMonId} - deleteDataFromDB(collName, filter) + p.DeleteDataFromDB(collName, filter) c.Status(http.StatusNoContent) } @@ -427,7 +428,7 @@ func (p *Processor) PolicyDataUesUeIdSmDataUsageMonIdGetProcedure(c *gin.Context ueId string, ) { filter := bson.M{"ueId": ueId, "usageMonId": usageMonId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("PolicyDataUesUeIdSmDataUsageMonIdGetProcedure err: %s", pd.Detail) pd := util.ProblemDetailsNotFound("DATA_NOT_FOUND") @@ -458,7 +459,7 @@ func (p *Processor) PolicyDataUesUeIdSmDataUsageMonIdPutProcedure( func (p *Processor) PolicyDataUesUeIdUePolicySetGetProcedure(c *gin.Context, collName string, ueId string) { filter := bson.M{"ueId": ueId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("PolicyDataUesUeIdUePolicySetGetProcedure err: %s", pd.Detail) pd := util.ProblemDetailsNotFound("DATA_NOT_FOUND") @@ -483,7 +484,7 @@ func (p *Processor) PolicyDataUesUeIdUePolicySetPatchProcedure(c *gin.Context, c } var uePolicySet models.UePolicySet - uePolicySetBsonM, pd := getDataFromDB(collName, filter) + uePolicySetBsonM, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("PolicyDataUesUeIdUePolicySetPatchProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/event_exposure_data_document.go b/internal/sbi/processor/event_exposure_data_document.go index b8b7348..43e61bd 100644 --- a/internal/sbi/processor/event_exposure_data_document.go +++ b/internal/sbi/processor/event_exposure_data_document.go @@ -20,7 +20,7 @@ import ( func (p *Processor) QueryEEDataProcedure(c *gin.Context, collName string, ueId string) { filter := bson.M{"ueId": ueId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("QueryEEDataProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/operator_specific_data_container_document.go b/internal/sbi/processor/operator_specific_data_container_document.go index dd09459..d4ea847 100644 --- a/internal/sbi/processor/operator_specific_data_container_document.go +++ b/internal/sbi/processor/operator_specific_data_container_document.go @@ -24,7 +24,7 @@ func (p *Processor) PatchOperSpecDataProcedure( c *gin.Context, collName string, ueId string, patchItem []models.PatchItem, ) { filter := bson.M{"ueId": ueId} - if err := patchDataToDBAndNotify(collName, ueId, patchItem, filter); err != nil { + if err := p.PatchDataToDBAndNotify(collName, ueId, patchItem, filter); err != nil { logger.DataRepoLog.Errorf("PatchOperSpecDataProcedure err: %+v", err) pd := util.ProblemDetailsModifyNotAllowed("") c.JSON(int(pd.Status), pd) @@ -35,7 +35,7 @@ func (p *Processor) PatchOperSpecDataProcedure( func (p *Processor) QueryOperSpecDataProcedure(c *gin.Context, collName string, ueId string) { filter := bson.M{"ueId": ueId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) // The key of the map is operator specific data element name and the value is the operator specific data of the UE. if pd != nil { logger.DataRepoLog.Errorf("QueryOperSpecDataProcedure err: %s", pd.Detail) diff --git a/internal/sbi/processor/parameter_provision_document.go b/internal/sbi/processor/parameter_provision_document.go index a3b5b91..ea17f0f 100644 --- a/internal/sbi/processor/parameter_provision_document.go +++ b/internal/sbi/processor/parameter_provision_document.go @@ -20,7 +20,7 @@ import ( func (p *Processor) GetppDataProcedure(c *gin.Context, collName string, ueId string) { filter := bson.M{"ueId": ueId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("GetppDataProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/processor.go b/internal/sbi/processor/processor.go index bbd6b1a..6356e16 100644 --- a/internal/sbi/processor/processor.go +++ b/internal/sbi/processor/processor.go @@ -1,15 +1,18 @@ package processor import ( + "github.com/free5gc/udr/internal/database" "github.com/free5gc/udr/pkg/app" ) type Processor struct { app.UdrApp + database.DbConnector } -func NewProcessor(udr app.UdrApp) *Processor { +func NewProcessor(udr app.UdrApp, dbInplement database.DbConnector) *Processor { return &Processor{ - UdrApp: udr, + UdrApp: udr, + DbConnector: dbInplement, } } diff --git a/internal/sbi/processor/provisioned_data_document.go b/internal/sbi/processor/provisioned_data_document.go index cf6794a..0b3c2bb 100644 --- a/internal/sbi/processor/provisioned_data_document.go +++ b/internal/sbi/processor/provisioned_data_document.go @@ -32,7 +32,7 @@ func (p *Processor) QueryProvisionedDataProcedure(c *gin.Context, ueId string, s collName = "subscriptionData.provisionedData.amData" filter = bson.M{"ueId": ueId, "servingPlmnId": servingPlmnId} - accessAndMobilitySubscriptionData, pd := getDataFromDB(collName, filter) + accessAndMobilitySubscriptionData, pd := p.GetDataFromDB(collName, filter) if pd != nil && pd.Status == http.StatusInternalServerError { logger.DataRepoLog.Errorf( "QueryProvisionedDataProcedure get accessAndMobilitySubscriptionData err: %s", pd.Detail) @@ -52,7 +52,7 @@ func (p *Processor) QueryProvisionedDataProcedure(c *gin.Context, ueId string, s collName = "subscriptionData.provisionedData.smfSelectionSubscriptionData" filter = bson.M{"ueId": ueId, "servingPlmnId": servingPlmnId} - smfSelectionSubscriptionData, pd := getDataFromDB(collName, filter) + smfSelectionSubscriptionData, pd := p.GetDataFromDB(collName, filter) if pd != nil && pd.Status == http.StatusInternalServerError { logger.DataRepoLog.Errorf("QueryProvisionedDataProcedure get smfSelectionSubscriptionData err: %s", pd.Detail) c.JSON(int(pd.Status), pd) @@ -70,7 +70,7 @@ func (p *Processor) QueryProvisionedDataProcedure(c *gin.Context, ueId string, s collName = "subscriptionData.provisionedData.smsData" filter = bson.M{"ueId": ueId, "servingPlmnId": servingPlmnId} - smsSubscriptionData, pd := getDataFromDB(collName, filter) + smsSubscriptionData, pd := p.GetDataFromDB(collName, filter) if pd != nil && pd.Status == http.StatusInternalServerError { logger.DataRepoLog.Errorf("QueryProvisionedDataProcedure get smsSubscriptionData err: %s", pd.Detail) c.JSON(int(pd.Status), pd) @@ -118,7 +118,7 @@ func (p *Processor) QueryProvisionedDataProcedure(c *gin.Context, ueId string, s collName = "subscriptionData.provisionedData.traceData" filter = bson.M{"ueId": ueId, "servingPlmnId": servingPlmnId} - traceData, pd := getDataFromDB(collName, filter) + traceData, pd := p.GetDataFromDB(collName, filter) if pd != nil && pd.Status == http.StatusInternalServerError { logger.DataRepoLog.Errorf("QueryProvisionedDataProcedure get traceData err: %s", pd.Detail) c.JSON(int(pd.Status), pd) @@ -136,7 +136,7 @@ func (p *Processor) QueryProvisionedDataProcedure(c *gin.Context, ueId string, s collName = "subscriptionData.provisionedData.smsMngData" filter = bson.M{"ueId": ueId, "servingPlmnId": servingPlmnId} - smsManagementSubscriptionData, pd := getDataFromDB(collName, filter) + smsManagementSubscriptionData, pd := p.GetDataFromDB(collName, filter) if pd != nil && pd.Status == http.StatusInternalServerError { logger.DataRepoLog.Errorf( "QueryProvisionedDataProcedure get smsManagementSubscriptionData err: %s", pd.Detail) diff --git a/internal/sbi/processor/provisioned_parameter_data_document.go b/internal/sbi/processor/provisioned_parameter_data_document.go index 2354e2a..627966d 100644 --- a/internal/sbi/processor/provisioned_parameter_data_document.go +++ b/internal/sbi/processor/provisioned_parameter_data_document.go @@ -22,7 +22,7 @@ import ( func (p *Processor) ModifyPpDataProcedure(c *gin.Context, collName string, ueId string, patchItem []models.PatchItem) { filter := bson.M{"ueId": ueId} - if err := patchDataToDBAndNotify(collName, ueId, patchItem, filter); err != nil { + if err := p.PatchDataToDBAndNotify(collName, ueId, patchItem, filter); err != nil { logger.DataRepoLog.Errorf("ModifyPpDataProcedure err: %+v", err) pd := util.ProblemDetailsModifyNotAllowed("") c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/query_identity_data_by_supi_or_gpsi_document.go b/internal/sbi/processor/query_identity_data_by_supi_or_gpsi_document.go index 5d11147..1ef62fa 100644 --- a/internal/sbi/processor/query_identity_data_by_supi_or_gpsi_document.go +++ b/internal/sbi/processor/query_identity_data_by_supi_or_gpsi_document.go @@ -28,7 +28,7 @@ func (p *Processor) GetIdentityDataProcedure(c *gin.Context, collName string, ue }, } - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("GetIdentityDataProcedure err: %+v", pd) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/query_odb_data_by_supi_or_gpsi_document.go b/internal/sbi/processor/query_odb_data_by_supi_or_gpsi_document.go index ea5c598..5ab4ffa 100644 --- a/internal/sbi/processor/query_odb_data_by_supi_or_gpsi_document.go +++ b/internal/sbi/processor/query_odb_data_by_supi_or_gpsi_document.go @@ -20,7 +20,7 @@ import ( func (p *Processor) GetOdbDataProcedure(c *gin.Context, collName string, ueId string) { filter := bson.M{"ueId": ueId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("GetOdbDataProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/retrieval_of_shared_data.go b/internal/sbi/processor/retrieval_of_shared_data.go index 05f8164..79cf875 100644 --- a/internal/sbi/processor/retrieval_of_shared_data.go +++ b/internal/sbi/processor/retrieval_of_shared_data.go @@ -23,7 +23,7 @@ func (p *Processor) GetSharedDataProcedure(c *gin.Context, collName string, shar var sharedDataArray []map[string]interface{} for _, sharedDataId := range sharedDataIds { filter := bson.M{"sharedDataId": sharedDataId} - sharedData, pd := getDataFromDB(collName, filter) + sharedData, pd := p.GetDataFromDB(collName, filter) if pd != nil && pd.Status == http.StatusInternalServerError { logger.DataRepoLog.Errorf("GetSharedDataProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/smf_registration_document.go b/internal/sbi/processor/smf_registration_document.go index 6fc36a5..2a0eb4c 100644 --- a/internal/sbi/processor/smf_registration_document.go +++ b/internal/sbi/processor/smf_registration_document.go @@ -50,7 +50,7 @@ func (p *Processor) DeleteSmfContextProcedure(c *gin.Context, collName string, u logger.DataRepoLog.Error(err) } filter := bson.M{"ueId": ueId, "pduSessionId": pduSessionIdInt} - deleteDataFromDB(collName, filter) + p.DeleteDataFromDB(collName, filter) c.Status(http.StatusNoContent) } @@ -63,7 +63,7 @@ func (p *Processor) QuerySmfRegistrationProcedure(c *gin.Context, collName strin } filter := bson.M{"ueId": ueId, "pduSessionId": pduSessionIdInt} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("QuerySmfRegistrationProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/smf_selection_subscription_data_document.go b/internal/sbi/processor/smf_selection_subscription_data_document.go index a923c17..dc11aa0 100644 --- a/internal/sbi/processor/smf_selection_subscription_data_document.go +++ b/internal/sbi/processor/smf_selection_subscription_data_document.go @@ -22,7 +22,7 @@ func (p *Processor) QuerySmfSelectDataProcedure(c *gin.Context, collName string, servingPlmnId string, ) { filter := bson.M{"ueId": ueId, "servingPlmnId": servingPlmnId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("QuerySmfSelectDataProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/sms_management_subscription_data_document.go b/internal/sbi/processor/sms_management_subscription_data_document.go index c234b53..4a2e4aa 100644 --- a/internal/sbi/processor/sms_management_subscription_data_document.go +++ b/internal/sbi/processor/sms_management_subscription_data_document.go @@ -22,7 +22,7 @@ func (p *Processor) QuerySmsMngDataProcedure(c *gin.Context, collName string, ue servingPlmnId string, ) { filter := bson.M{"ueId": ueId, "servingPlmnId": servingPlmnId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("QuerySmsMngDataProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/sms_subscription_data_document.go b/internal/sbi/processor/sms_subscription_data_document.go index b8df004..3ee9485 100644 --- a/internal/sbi/processor/sms_subscription_data_document.go +++ b/internal/sbi/processor/sms_subscription_data_document.go @@ -22,7 +22,7 @@ func (p *Processor) QuerySmsDataProcedure(c *gin.Context, collName string, ueId servingPlmnId string, ) { filter := bson.M{"ueId": ueId, "servingPlmnId": servingPlmnId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("QuerySmsDataProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/smsf3_gpp_registration_document.go b/internal/sbi/processor/smsf3_gpp_registration_document.go index b4adc8f..5d686e4 100644 --- a/internal/sbi/processor/smsf3_gpp_registration_document.go +++ b/internal/sbi/processor/smsf3_gpp_registration_document.go @@ -38,13 +38,13 @@ func (p *Processor) CreateSmsfContext3gppProcedure( func (p *Processor) DeleteSmsfContext3gppProcedure(c *gin.Context, collName string, ueId string) { filter := bson.M{"ueId": ueId} - deleteDataFromDB(collName, filter) + p.DeleteDataFromDB(collName, filter) c.Status(http.StatusNoContent) } func (p *Processor) QuerySmsfContext3gppProcedure(c *gin.Context, collName string, ueId string) { filter := bson.M{"ueId": ueId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("QuerySmsfContext3gppProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/smsf_non3_gpp_registration_document.go b/internal/sbi/processor/smsf_non3_gpp_registration_document.go index 12be4b7..b90e1f8 100644 --- a/internal/sbi/processor/smsf_non3_gpp_registration_document.go +++ b/internal/sbi/processor/smsf_non3_gpp_registration_document.go @@ -38,13 +38,13 @@ func (p *Processor) CreateSmsfContextNon3gppProcedure( func (p *Processor) DeleteSmsfContextNon3gppProcedure(c *gin.Context, collName string, ueId string) { filter := bson.M{"ueId": ueId} - deleteDataFromDB(collName, filter) + p.DeleteDataFromDB(collName, filter) c.Status(http.StatusNoContent) } func (p *Processor) QuerySmsfContextNon3gppProcedure(c *gin.Context, collName string, ueId string) { filter := bson.M{"ueId": ueId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("QuerySmsfContextNon3gppProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/processor/trace_data_document.go b/internal/sbi/processor/trace_data_document.go index c1f5ad4..74fa844 100644 --- a/internal/sbi/processor/trace_data_document.go +++ b/internal/sbi/processor/trace_data_document.go @@ -22,7 +22,7 @@ func (p *Processor) QueryTraceDataProcedure(c *gin.Context, collName string, ueI servingPlmnId string, ) { filter := bson.M{"ueId": ueId, "servingPlmnId": servingPlmnId} - data, pd := getDataFromDB(collName, filter) + data, pd := p.GetDataFromDB(collName, filter) if pd != nil { logger.DataRepoLog.Errorf("QueryTraceDataProcedure err: %s", pd.Detail) c.JSON(int(pd.Status), pd) diff --git a/internal/sbi/server.go b/internal/sbi/server.go index dcab550..3eec91f 100644 --- a/internal/sbi/server.go +++ b/internal/sbi/server.go @@ -10,7 +10,6 @@ import ( "github.com/gin-gonic/gin" "github.com/free5gc/openapi/models" - udr_context "github.com/free5gc/udr/internal/context" "github.com/free5gc/udr/internal/logger" "github.com/free5gc/udr/internal/sbi/processor" "github.com/free5gc/udr/internal/util" @@ -20,11 +19,6 @@ import ( logger_util "github.com/free5gc/util/logger" ) -type Udr interface { - Config() *factory.Config - Context() *udr_context.UDRContext -} - type Server struct { app.UdrApp @@ -33,10 +27,15 @@ type Server struct { processor *processor.Processor } -func NewServer(udr app.UdrApp, tlsKeyLogPath string) *Server { +type UDR interface { + app.UdrApp + Processor() *processor.Processor +} + +func NewServer(udr UDR, tlsKeyLogPath string) *Server { s := &Server{ UdrApp: udr, - processor: processor.NewProcessor(udr), + processor: udr.Processor(), } s.router = newRouter(s) diff --git a/pkg/service/init.go b/pkg/service/init.go index 66ea2c5..2d27cda 100644 --- a/pkg/service/init.go +++ b/pkg/service/init.go @@ -13,6 +13,7 @@ import ( "github.com/sirupsen/logrus" udr_context "github.com/free5gc/udr/internal/context" + "github.com/free5gc/udr/internal/database/mongodb" "github.com/free5gc/udr/internal/logger" "github.com/free5gc/udr/internal/sbi" "github.com/free5gc/udr/internal/sbi/consumer" @@ -46,7 +47,9 @@ func NewApp(cfg *factory.Config, tlsKeyLogPath string) (*UdrApp, error) { udr.SetLogLevel(cfg.GetLogLevel()) udr.SetReportCaller(cfg.GetLogReportCaller()) - processor := processor.NewProcessor(udr) + mongoDBInple := mongodb.NewMongoDbImplement(udr.Config().Configuration.Mongodb) + + processor := processor.NewProcessor(udr, mongoDBInple) udr.processor = processor consumer := consumer.NewConsumer(udr) @@ -169,6 +172,14 @@ func (a *UdrApp) Start() { go a.listenShutdown(ctx) } +func (a *UdrApp) Processor() *processor.Processor { + return a.processor +} + +func (a *UdrApp) Consumer() *consumer.Consumer { + return a.consumer +} + func (a *UdrApp) listenShutdown(ctx context.Context) { <-ctx.Done() a.Terminate()