ims online user support multi-tenancy
This commit is contained in:
@@ -25,16 +25,6 @@ type SmfUENum struct {
|
|||||||
UENum int `json:"ueNum"` // 当前在线用户数
|
UENum int `json:"ueNum"` // 当前在线用户数
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImsUEInfo IMS在线用户信息
|
|
||||||
type ImsUEInfo struct {
|
|
||||||
IMSI string `json:"imsi"`
|
|
||||||
MSISDN string `json:"msisdn"`
|
|
||||||
IMPU string `json:"impu"`
|
|
||||||
Barring int `json:"barring"`
|
|
||||||
RegState int `json:"regState"`
|
|
||||||
Activetime string `json:"activeTime"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// N3iwfUEInfo N3IWF在线用户信息
|
// N3iwfUEInfo N3IWF在线用户信息
|
||||||
type N3iwfUEInfo struct {
|
type N3iwfUEInfo struct {
|
||||||
IMSI string `json:"imsi"`
|
IMSI string `json:"imsi"`
|
||||||
@@ -50,7 +40,8 @@ type N3iwfUEData struct {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
UriNBInfo = config.DefaultUriPrefix + "/ueManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/nbInfo"
|
UriNBInfo = config.DefaultUriPrefix + "/ueManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/nbInfo"
|
||||||
UriUEInfo = config.DefaultUriPrefix + "/ueManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/ueInfo"
|
UriSMFUEInfo = config.DefaultUriPrefix + "/ueManagement/{apiVersion}/elementType/smf/objectType/ueInfo"
|
||||||
|
UriIMSUEInfo = config.DefaultUriPrefix + "/ueManagement/{apiVersion}/elementType/ims/objectType/ueInfo"
|
||||||
UriUENum = config.DefaultUriPrefix + "/ueManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/ueNum"
|
UriUENum = config.DefaultUriPrefix + "/ueManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/ueNum"
|
||||||
UriPCFUser = config.DefaultUriPrefix + "/ueManagement/{apiVersion}/elementType/pcf/objectType/ueInfo"
|
UriPCFUser = config.DefaultUriPrefix + "/ueManagement/{apiVersion}/elementType/pcf/objectType/ueInfo"
|
||||||
UriPCFUserM = config.DefaultUriPrefix + "/ueManagement/{apiVersion}/elementType/pcf/objectType/ueInfo/batch/{number}"
|
UriPCFUserM = config.DefaultUriPrefix + "/ueManagement/{apiVersion}/elementType/pcf/objectType/ueInfo/batch/{number}"
|
||||||
@@ -60,7 +51,8 @@ var (
|
|||||||
UriNSSFSubscriptions = config.DefaultUriPrefix + "/ueManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/subscriptions"
|
UriNSSFSubscriptions = config.DefaultUriPrefix + "/ueManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/subscriptions"
|
||||||
|
|
||||||
CustomUriNBInfo = config.UriPrefix + "/ueManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/nbInfo"
|
CustomUriNBInfo = config.UriPrefix + "/ueManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/nbInfo"
|
||||||
CustomUriUEInfo = config.UriPrefix + "/ueManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/ueInfo"
|
CustomUriSMFUEInfo = config.UriPrefix + "/ueManagement/{apiVersion}/elementType/smf/objectType/ueInfo"
|
||||||
|
CustomUriIMSUEInfo = config.UriPrefix + "/ueManagement/{apiVersion}/elementType/ims/objectType/ueInfo"
|
||||||
CustomUriUENum = config.UriPrefix + "/ueManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/ueNum"
|
CustomUriUENum = config.UriPrefix + "/ueManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/ueNum"
|
||||||
CustomUriPCFUser = config.UriPrefix + "/ueManagement/{apiVersion}/elementType/pcf/objectType/ueInfo"
|
CustomUriPCFUser = config.UriPrefix + "/ueManagement/{apiVersion}/elementType/pcf/objectType/ueInfo"
|
||||||
CustomUriPCFUserM = config.UriPrefix + "/ueManagement/{apiVersion}/elementType/pcf/objectType/ueInfo/batch/{number}"
|
CustomUriPCFUserM = config.UriPrefix + "/ueManagement/{apiVersion}/elementType/pcf/objectType/ueInfo/batch/{number}"
|
||||||
@@ -214,6 +206,35 @@ func GetSubscriptionsFromNSSF(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ImsUEInfo IMS在线用户信息
|
||||||
|
type ImsUEInfo struct {
|
||||||
|
IMSI string `json:"imsi"`
|
||||||
|
MSISDN string `json:"msisdn"`
|
||||||
|
IMPU string `json:"impu"`
|
||||||
|
Barring int `json:"barring"`
|
||||||
|
RegState int `json:"regState"`
|
||||||
|
Activetime string `json:"activeTime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImsUEInfo IMS在线用户信息
|
||||||
|
type TenantImsUEInfo struct {
|
||||||
|
IMSI string `json:"imsi"`
|
||||||
|
MSISDN string `json:"msisdn"`
|
||||||
|
IMPU string `json:"impu"`
|
||||||
|
Barring int `json:"barring"`
|
||||||
|
RegState int `json:"regState"`
|
||||||
|
Activetime string `json:"activeTime"`
|
||||||
|
TenantName string `json:"tenantName"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ImsUEInfoResponse struct {
|
||||||
|
Data []ImsUEInfo `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TenantImsUEInfoResponse struct {
|
||||||
|
Data []TenantImsUEInfo `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
// SmfUEInfo SMF在线用户信息
|
// SmfUEInfo SMF在线用户信息
|
||||||
type SmfUEInfo struct {
|
type SmfUEInfo struct {
|
||||||
IMSI string `json:"imsi"`
|
IMSI string `json:"imsi"`
|
||||||
@@ -265,7 +286,7 @@ func GetUEInfoFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Debug("GetUEInfoFromNF processing... ")
|
log.Debug("GetUEInfoFromNF processing... ")
|
||||||
|
|
||||||
neId := ctx.GetQuery(r, "neId")
|
neId := ctx.GetQuery(r, "neId")
|
||||||
neType := ctx.GetParam(r, "elementTypeValue")
|
neType := "smf"
|
||||||
if neType == "" || neId == "" {
|
if neType == "" || neId == "" {
|
||||||
log.Error("elementTypeValue/neId is empty")
|
log.Error("elementTypeValue/neId is empty")
|
||||||
services.ResponseNotFound404UriNotExist(w, r)
|
services.ResponseNotFound404UriNotExist(w, r)
|
||||||
@@ -282,6 +303,7 @@ func GetUEInfoFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
var response services.MapResponse
|
var response services.MapResponse
|
||||||
if neInfo.NeId == neId && neInfo.NeId != "" {
|
if neInfo.NeId == neId && neInfo.NeId != "" {
|
||||||
requestURI2NF := fmt.Sprintf("http://%s:%v%s", neInfo.IP, neInfo.Port, r.RequestURI)
|
requestURI2NF := fmt.Sprintf("http://%s:%v%s", neInfo.IP, neInfo.Port, r.RequestURI)
|
||||||
|
//requestURI2NF := "http://127.0.0.1:4523/m1/3157310-1528434-default/api/rest/ueManagement/v1/elementType/smf/objectType/ueInfo?apifoxApiId=128609449"
|
||||||
log.Debug("requestURI2NF:", requestURI2NF)
|
log.Debug("requestURI2NF:", requestURI2NF)
|
||||||
resp, err := client.R().
|
resp, err := client.R().
|
||||||
EnableTrace().
|
EnableTrace().
|
||||||
@@ -292,57 +314,140 @@ func GetUEInfoFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Error("Failed to Get from NF:", err)
|
log.Error("Failed to Get from NF:", err)
|
||||||
services.ResponseInternalServerError500ProcessError(w, err)
|
services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
// multi-tenancy solution
|
||||||
|
var tenantID, where string
|
||||||
|
//var cols []string
|
||||||
|
if tenantName != "" {
|
||||||
|
where = fmt.Sprintf("status='1' and tenant_name='%s'", tenantName)
|
||||||
|
tenantID, _ = dborm.XormGetSingleColStringByWhere("sys_tenant", "tenant_id", where)
|
||||||
} else {
|
} else {
|
||||||
// multi-tenancy solution
|
userName := ctx.LoginUserToUserName(r)
|
||||||
var tenantID, where string
|
where = fmt.Sprintf("status='1' and user_name='%s'", userName)
|
||||||
//var cols []string
|
tenantID, _ = dborm.XormGetSingleColStringByWhere("sys_user", "tenant_id", where)
|
||||||
if tenantName != "" {
|
where = fmt.Sprintf("status='1' and tenant_id='%s'", tenantID)
|
||||||
where = fmt.Sprintf("status='1' and tenant_name='%s'", tenantName)
|
tenantName, _ = dborm.XormGetSingleColStringByWhere("sys_tenant", "tenant_name", where)
|
||||||
tenantID, _ = dborm.XormGetSingleColStringByWhere("sys_tenant", "tenant_id", where)
|
}
|
||||||
} else {
|
if tenantID == "" {
|
||||||
userName := ctx.LoginUserToUserName(r)
|
var response UEInfoResponse
|
||||||
where = fmt.Sprintf("status='1' and user_name='%s'", userName)
|
_ = json.Unmarshal(resp.Body(), &response)
|
||||||
tenantID, _ = dborm.XormGetSingleColStringByWhere("sys_user", "tenant_id", where)
|
for i := 0; i < len(response.Data); i++ {
|
||||||
|
where = fmt.Sprintf("status='1' and tenancy_type='IMSI' and '%s' like tenancy_key", response.Data[i].IMSI[5:])
|
||||||
|
tenantID, _ = dborm.XormGetSingleColStringByWhere("sys_tenant", "parent_id", where)
|
||||||
where = fmt.Sprintf("status='1' and tenant_id='%s'", tenantID)
|
where = fmt.Sprintf("status='1' and tenant_id='%s'", tenantID)
|
||||||
tenantName, _ = dborm.XormGetSingleColStringByWhere("sys_tenant", "tenant_name", where)
|
tenantName, _ = dborm.XormGetSingleColStringByWhere("sys_tenant", "tenant_name", where)
|
||||||
|
log.Tracef("tenantName: %s tenantID: %s", tenantName, tenantID)
|
||||||
|
response.Data[i].TenantName = tenantName
|
||||||
}
|
}
|
||||||
if tenantID == "" {
|
services.ResponseWithJson(w, resp.StatusCode(), &response)
|
||||||
var response UEInfoResponse
|
return
|
||||||
_ = json.Unmarshal(resp.Body(), &response)
|
} else {
|
||||||
for i := 0; i < len(response.Data); i++ {
|
var tenantUEInfos []TenantUEInfo
|
||||||
where = fmt.Sprintf("status='1' and tenancy_type='IMSI' and '%s' like tenancy_key", response.Data[i].IMSI[5:])
|
var ueInfos UEInfoResponse
|
||||||
tenantID, _ = dborm.XormGetSingleColStringByWhere("sys_tenant", "parent_id", where)
|
log.Trace("body:", string(resp.Body()))
|
||||||
where = fmt.Sprintf("status='1' and tenant_id='%s'", tenantID)
|
_ = json.Unmarshal(resp.Body(), &ueInfos)
|
||||||
tenantName, _ = dborm.XormGetSingleColStringByWhere("sys_tenant", "tenant_name", where)
|
log.Trace("ueInfos:", ueInfos)
|
||||||
log.Tracef("tenantName: %s tenantID: %s", tenantName, tenantID)
|
for _, n := range ueInfos.Data {
|
||||||
response.Data[i].TenantName = tenantName
|
log.Trace("tenantID, n.IMSI[5:]:", tenantID, n.IMSI[5:])
|
||||||
|
// "imsi": "imsi-460000100029999",
|
||||||
|
where = fmt.Sprintf("status='1' and parent_id='%s' and tenancy_type='IMSI' and '%s' like tenancy_key", tenantID, n.IMSI[5:])
|
||||||
|
has, err := dborm.XormExistTableOne("sys_tenant", where)
|
||||||
|
if err == nil && has {
|
||||||
|
n.TenantName = tenantName
|
||||||
|
tenantUEInfos = append(tenantUEInfos, n)
|
||||||
}
|
}
|
||||||
services.ResponseWithJson(w, resp.StatusCode(), &response)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
var tenantUEInfos []TenantUEInfo
|
|
||||||
var ueInfos UEInfoResponse
|
|
||||||
log.Trace("body:", string(resp.Body()))
|
|
||||||
_ = json.Unmarshal(resp.Body(), &ueInfos)
|
|
||||||
log.Trace("ueInfos:", ueInfos)
|
|
||||||
for _, n := range ueInfos.Data {
|
|
||||||
log.Trace("tenantID, n.IMSI[5:]:", tenantID, n.IMSI[5:])
|
|
||||||
// "imsi": "imsi-460000100029999",
|
|
||||||
where = fmt.Sprintf("status='1' and parent_id='%s' and tenancy_type='IMSI' and '%s' like tenancy_key", tenantID, n.IMSI[5:])
|
|
||||||
has, err := dborm.XormExistTableOne("sys_tenant", where)
|
|
||||||
if err == nil && has {
|
|
||||||
n.TenantName = tenantName
|
|
||||||
tenantUEInfos = append(tenantUEInfos, n)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var response UEInfoResponse
|
|
||||||
response.Data = tenantUEInfos
|
|
||||||
services.ResponseWithJson(w, resp.StatusCode(), &response)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
var response UEInfoResponse
|
||||||
|
response.Data = tenantUEInfos
|
||||||
|
services.ResponseWithJson(w, resp.StatusCode(), &response)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get UEInfo from NF/NFs, IMS Online users
|
||||||
|
func GetIMSUEInfoFromNF(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.Debug("GetUEInfoFromNF processing... ")
|
||||||
|
|
||||||
|
neId := ctx.GetQuery(r, "neId")
|
||||||
|
neType := "ims"
|
||||||
|
if neType == "" || neId == "" {
|
||||||
|
log.Error("elementTypeValue/neId is empty")
|
||||||
|
services.ResponseNotFound404UriNotExist(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var tenantName string
|
||||||
|
tenantNames := services.GetParamsArrByName("tenantName", r)
|
||||||
|
if len(tenantNames) > 0 {
|
||||||
|
tenantName = tenantNames[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
neInfo := neService.NewNeInfoImpl.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||||
|
|
||||||
|
var response services.MapResponse
|
||||||
|
if neInfo.NeId == neId && neInfo.NeId != "" {
|
||||||
|
requestURI2NF := fmt.Sprintf("http://%s:%v%s", neInfo.IP, neInfo.Port, r.RequestURI)
|
||||||
|
//requestURI2NF := "http://127.0.0.1:4523/m1/3157310-1528434-default/api/rest/ueManagement/v1/elementType/ims/objectType/ueInfo?apifoxApiId=128609458"
|
||||||
|
log.Debug("requestURI2NF:", requestURI2NF)
|
||||||
|
resp, err := client.R().
|
||||||
|
EnableTrace().
|
||||||
|
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
|
||||||
|
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
|
||||||
|
Get(requestURI2NF)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to Get from NF:", err)
|
||||||
|
services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// multi-tenancy solution
|
||||||
|
var tenantID, where string
|
||||||
|
//var cols []string
|
||||||
|
if tenantName != "" {
|
||||||
|
where = fmt.Sprintf("status='1' and tenant_name='%s'", tenantName)
|
||||||
|
tenantID, _ = dborm.XormGetSingleColStringByWhere("sys_tenant", "tenant_id", where)
|
||||||
|
} else {
|
||||||
|
userName := ctx.LoginUserToUserName(r)
|
||||||
|
where = fmt.Sprintf("status='1' and user_name='%s'", userName)
|
||||||
|
tenantID, _ = dborm.XormGetSingleColStringByWhere("sys_user", "tenant_id", where)
|
||||||
|
where = fmt.Sprintf("status='1' and tenant_id='%s'", tenantID)
|
||||||
|
tenantName, _ = dborm.XormGetSingleColStringByWhere("sys_tenant", "tenant_name", where)
|
||||||
|
}
|
||||||
|
if tenantID == "" {
|
||||||
|
var response TenantImsUEInfoResponse
|
||||||
|
_ = json.Unmarshal(resp.Body(), &response)
|
||||||
|
for i := 0; i < len(response.Data); i++ {
|
||||||
|
where = fmt.Sprintf("status='1' and tenancy_type='IMSI' and '%s' like tenancy_key", response.Data[i].IMSI)
|
||||||
|
tenantID, _ = dborm.XormGetSingleColStringByWhere("sys_tenant", "parent_id", where)
|
||||||
|
where = fmt.Sprintf("status='1' and tenant_id='%s'", tenantID)
|
||||||
|
tenantName, _ = dborm.XormGetSingleColStringByWhere("sys_tenant", "tenant_name", where)
|
||||||
|
log.Tracef("tenantName: %s tenantID: %s", tenantName, tenantID)
|
||||||
|
response.Data[i].TenantName = tenantName
|
||||||
|
}
|
||||||
|
services.ResponseWithJson(w, resp.StatusCode(), &response)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
var tenantUEInfos []TenantImsUEInfo
|
||||||
|
var ueInfos TenantImsUEInfoResponse
|
||||||
|
log.Trace("body:", string(resp.Body()))
|
||||||
|
_ = json.Unmarshal(resp.Body(), &ueInfos)
|
||||||
|
log.Trace("ueInfos:", ueInfos)
|
||||||
|
for _, n := range ueInfos.Data {
|
||||||
|
log.Trace("tenantID, n.IMSI:", tenantID, n.IMSI)
|
||||||
|
// "imsi": "460000100029999",
|
||||||
|
where = fmt.Sprintf("status='1' and parent_id='%s' and tenancy_type='IMSI' and '%s' like tenancy_key", tenantID, n.IMSI)
|
||||||
|
has, err := dborm.XormExistTableOne("sys_tenant", where)
|
||||||
|
if err == nil && has {
|
||||||
|
n.TenantName = tenantName
|
||||||
|
tenantUEInfos = append(tenantUEInfos, n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var response TenantImsUEInfoResponse
|
||||||
|
response.Data = tenantUEInfos
|
||||||
|
services.ResponseWithJson(w, resp.StatusCode(), &response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
services.ResponseWithJson(w, http.StatusOK, response)
|
services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -239,8 +239,12 @@ func init() {
|
|||||||
Register("GET", aaaa.CustomUriAAAASSO, aaaa.GetSSOFromAAAA, nil)
|
Register("GET", aaaa.CustomUriAAAASSO, aaaa.GetSSOFromAAAA, nil)
|
||||||
|
|
||||||
// UEInfo: SMF
|
// UEInfo: SMF
|
||||||
Register("GET", ue.UriUEInfo, ue.GetUEInfoFromNF, nil)
|
Register("GET", ue.UriSMFUEInfo, ue.GetUEInfoFromNF, nil)
|
||||||
Register("GET", ue.CustomUriUEInfo, ue.GetUEInfoFromNF, nil)
|
Register("GET", ue.CustomUriSMFUEInfo, ue.GetUEInfoFromNF, nil)
|
||||||
|
|
||||||
|
// UEInfo: IMS
|
||||||
|
Register("GET", ue.UriIMSUEInfo, ue.GetIMSUEInfoFromNF, nil)
|
||||||
|
Register("GET", ue.CustomUriIMSUEInfo, ue.GetIMSUEInfoFromNF, nil)
|
||||||
|
|
||||||
// UEInfo: PCF
|
// UEInfo: PCF
|
||||||
Register("GET", ue.UriPCFUser, ue.GetUEInfoFromNF, nil)
|
Register("GET", ue.UriPCFUser, ue.GetUEInfoFromNF, nil)
|
||||||
|
|||||||
Reference in New Issue
Block a user