-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: propagate Subscriber deletion to Device Groups #299
base: main
Are you sure you want to change the base?
Changes from all commits
a43c3ba
4eeb21f
bebae5a
d14f2ed
1aeb1bd
15a3a76
58eb6d5
b81328a
b9e7ddf
69f69fe
e65064e
a092729
3fcddbd
e5c3c3b
709b066
fe11864
6597b57
0cafddb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import ( | |
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/omec-project/openapi/models" | ||
|
@@ -268,9 +269,12 @@ func GetSubscribers(c *gin.Context) { | |
logger.WebUILog.Infoln("Get All Subscribers List") | ||
|
||
var subsList []configmodels.SubsListIE | ||
subsList = make([]configmodels.SubsListIE, 0) | ||
amDataList, errGetMany := dbadapter.CommonDBClient.RestfulAPIGetMany(amDataColl, bson.M{}) | ||
if errGetMany != nil { | ||
logger.DbLog.Warnln(errGetMany) | ||
logger.DbLog.Errorw("failed to retrieve subscribers list", "error", errGetMany) | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to retrieve subscribers list"}) | ||
return | ||
} | ||
for _, amData := range amDataList { | ||
|
||
|
@@ -483,17 +487,61 @@ func DeleteSubscriberByID(c *gin.Context) { | |
|
||
ueId := c.Param("ueId") | ||
|
||
c.JSON(http.StatusNoContent, gin.H{}) | ||
imsi := strings.TrimPrefix(ueId, "imsi-") | ||
err := updateSubscriberInDeviceGroups(imsi) | ||
if err != nil { | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": "error deleting subscriber"}) | ||
return | ||
} | ||
|
||
msg := configmodels.ConfigMessage{ | ||
MsgType: configmodels.Sub_data, | ||
MsgMethod: configmodels.Delete_op, | ||
Imsi: ueId, | ||
} | ||
configChannel <- &msg | ||
c.JSON(http.StatusNoContent, gin.H{}) | ||
logger.WebUILog.Infoln("Delete Subscriber Data complete") | ||
} | ||
|
||
func updateSubscriberInDeviceGroups(imsi string) error { | ||
filterByImsi := bson.M{ | ||
"imsis": imsi, | ||
} | ||
rawDeviceGroups, err := dbadapter.CommonDBClient.RestfulAPIGetMany(devGroupDataColl, filterByImsi) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In RestfulAPIGetMany There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initial value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. Please discard this comment. |
||
if err != nil { | ||
logger.DbLog.Errorf("failed to fetch device groups: %v", err) | ||
return err | ||
} | ||
var deviceGroupUpdateMessages []configmodels.ConfigMessage | ||
for _, rawDeviceGroup := range rawDeviceGroups { | ||
var deviceGroup configmodels.DeviceGroups | ||
if err = json.Unmarshal(configmodels.MapToByte(rawDeviceGroup), &deviceGroup); err != nil { | ||
logger.DbLog.Errorf("error unmarshaling device group: %v", err) | ||
return err | ||
} | ||
filteredImsis := []string{} | ||
for _, currImsi := range deviceGroup.Imsis { | ||
if currImsi != imsi { | ||
filteredImsis = append(filteredImsis, currImsi) | ||
} | ||
} | ||
deviceGroup.Imsis = filteredImsis | ||
deviceGroupUpdateMessage := configmodels.ConfigMessage{ | ||
MsgType: configmodels.Device_group, | ||
MsgMethod: configmodels.Post_op, | ||
DevGroupName: deviceGroup.DeviceGroupName, | ||
DevGroup: &deviceGroup, | ||
} | ||
deviceGroupUpdateMessages = append(deviceGroupUpdateMessages, deviceGroupUpdateMessage) | ||
} | ||
for _, msg := range deviceGroupUpdateMessages { | ||
This comment was marked as outdated.
Sorry, something went wrong. |
||
configChannel <- &msg | ||
logger.WebUILog.Infof("device group [%v] update sent to config channel", msg.DevGroupName) | ||
} | ||
return nil | ||
} | ||
|
||
func GetRegisteredUEContext(c *gin.Context) { | ||
setCorsHeader(c) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to validate the existence of imsi here.