fix: custom indicator and get state issue merge from main line
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// get customize kpi total and list
|
||||||
func (k *KpiCTitle) GetToalList(c *gin.Context) {
|
func (k *KpiCTitle) GetToalList(c *gin.Context) {
|
||||||
var titles []KpiCTitle
|
var titles []KpiCTitle
|
||||||
var conditions []string
|
var conditions []string
|
||||||
@@ -35,7 +36,10 @@ func (k *KpiCTitle) GetToalList(c *gin.Context) {
|
|||||||
if status := querys.Status; status != "" {
|
if status := querys.Status; status != "" {
|
||||||
conditions = append(conditions, "status = ?")
|
conditions = append(conditions, "status = ?")
|
||||||
params = append(params, status)
|
params = append(params, status)
|
||||||
|
} else {
|
||||||
|
conditions = append(conditions, "status != 'Deleted'")
|
||||||
}
|
}
|
||||||
|
|
||||||
whereSql := ""
|
whereSql := ""
|
||||||
if len(conditions) > 0 {
|
if len(conditions) > 0 {
|
||||||
whereSql += strings.Join(conditions, " and ")
|
whereSql += strings.Join(conditions, " and ")
|
||||||
@@ -87,7 +91,10 @@ func (k *KpiCTitle) Get(c *gin.Context) {
|
|||||||
if status := c.Query("status"); status != "" {
|
if status := c.Query("status"); status != "" {
|
||||||
conditions = append(conditions, "status = ?")
|
conditions = append(conditions, "status = ?")
|
||||||
params = append(params, status)
|
params = append(params, status)
|
||||||
|
} else {
|
||||||
|
conditions = append(conditions, "status != 'Deleted'")
|
||||||
}
|
}
|
||||||
|
|
||||||
whereSql := ""
|
whereSql := ""
|
||||||
if len(conditions) > 0 {
|
if len(conditions) > 0 {
|
||||||
whereSql += strings.Join(conditions, " and ")
|
whereSql += strings.Join(conditions, " and ")
|
||||||
@@ -103,6 +110,7 @@ func (k *KpiCTitle) Get(c *gin.Context) {
|
|||||||
//c.JSON(http.StatusOK, titles)
|
//c.JSON(http.StatusOK, titles)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// alias customized kpi expression with cn/en title
|
||||||
func (k *KpiCTitle) expressionAlias(titles []KpiCTitle, i18n string) {
|
func (k *KpiCTitle) expressionAlias(titles []KpiCTitle, i18n string) {
|
||||||
var title *KpiCTitle
|
var title *KpiCTitle
|
||||||
for i := 0; i < len(titles); i++ {
|
for i := 0; i < len(titles); i++ {
|
||||||
@@ -140,7 +148,10 @@ func (k *KpiCTitle) Total(c *gin.Context) {
|
|||||||
if status := c.Query("status"); status != "" {
|
if status := c.Query("status"); status != "" {
|
||||||
conditions = append(conditions, "status = ?")
|
conditions = append(conditions, "status = ?")
|
||||||
params = append(params, status)
|
params = append(params, status)
|
||||||
|
} else {
|
||||||
|
conditions = append(conditions, "status != 'Deleted'")
|
||||||
}
|
}
|
||||||
|
|
||||||
whereSql := ""
|
whereSql := ""
|
||||||
if len(conditions) > 0 {
|
if len(conditions) > 0 {
|
||||||
whereSql += strings.Join(conditions, " and ")
|
whereSql += strings.Join(conditions, " and ")
|
||||||
@@ -168,7 +179,11 @@ func (k *KpiCTitle) Post(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, services.ErrResp("custom indicator already exist"))
|
c.JSON(http.StatusOK, services.ErrResp("custom indicator already exist"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ret := dborm.DefaultDB().Table("kpi_c_title").Where("ne_type=? ORDER BY kpi_id DESC LIMIT 1", title.NeType).Scan(&res)
|
|
||||||
|
// Regexp match like AMF.C.01
|
||||||
|
kpiIDRegexp := "^" + *title.NeType + "\\.C\\.[0-9]{2}$"
|
||||||
|
ret := dborm.DefaultDB().Table("kpi_c_title").
|
||||||
|
Where("ne_type=? and kpi_id REGEXP ? ORDER BY kpi_id DESC LIMIT 1", title.NeType, kpiIDRegexp).Scan(&res)
|
||||||
if err := ret.Error; err != nil {
|
if err := ret.Error; err != nil {
|
||||||
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||||
return
|
return
|
||||||
@@ -241,8 +256,8 @@ func (k *KpiCTitle) Put(c *gin.Context) {
|
|||||||
func (k *KpiCTitle) Delete(c *gin.Context) {
|
func (k *KpiCTitle) Delete(c *gin.Context) {
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
|
|
||||||
if err := dborm.DefaultDB().Delete(&KpiCTitle{}, id).Error; err != nil {
|
if err := dborm.DefaultDB().Table(k.TableName()).Where("id=?", id).Update("status", "Deleted").Error; err != nil {
|
||||||
c.JSON(http.StatusOK, services.ErrResp("custom indicator not found"))
|
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -762,14 +762,14 @@ func GetStateFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
|
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
|
||||||
Get(requestURI2NF)
|
Get(requestURI2NF)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Get system state from NF is failed:", err)
|
log.Error("Fail to get state:", err)
|
||||||
|
|
||||||
errorMessage := services.ErrorMessage{
|
errorMessage := services.ErrorMessage{
|
||||||
ErrorCode: "1", ErrorInfo: "Internal server error, NF connnect refused",
|
ErrorCode: "1", ErrorInfo: "Internal server error, NF connnect refused",
|
||||||
}
|
}
|
||||||
result["error"] = errorMessage
|
systemState := make(map[string]interface{})
|
||||||
SN, Version, _ := dborm.XormGetNEStateInfo(ne.NeType, ne.NeId)
|
systemState["error"] = errorMessage
|
||||||
result["serialNum"] = SN
|
result["systemState"] = systemState
|
||||||
result["version"] = Version
|
|
||||||
} else {
|
} else {
|
||||||
systemState := make(map[string]interface{})
|
systemState := make(map[string]interface{})
|
||||||
_ = json.Unmarshal(resp.Body(), &systemState)
|
_ = json.Unmarshal(resp.Body(), &systemState)
|
||||||
@@ -786,49 +786,62 @@ func GetStateFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
response.Data = data
|
response.Data = data
|
||||||
services.ResponseWithJson(w, http.StatusOK, response)
|
services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
return
|
return
|
||||||
}
|
} else if neType == "omc" {
|
||||||
|
|
||||||
if neType == "omc" {
|
|
||||||
emsState := GetEMSState("127.0.0.1")
|
emsState := GetEMSState("127.0.0.1")
|
||||||
services.ResponseWithJson(w, http.StatusOK, emsState)
|
services.ResponseWithJson(w, http.StatusOK, emsState)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var neList []dborm.NeInfo
|
// only support omc and all elementType
|
||||||
err := dborm.XormGetNeInfoByNeType(neType, &neList)
|
err := fmt.Errorf("only support omc or all elementTypeValue")
|
||||||
if err != nil {
|
log.Error("Fail to get state:", err)
|
||||||
log.Error("Failed to dborm.XormGetNeInfoByNeType:", err)
|
|
||||||
services.ResponseInternalServerError500ProcessError(w, err)
|
services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
return
|
|
||||||
}
|
|
||||||
data := make([]map[string]interface{}, 0)
|
|
||||||
for _, ne := range neList {
|
|
||||||
hostUri := fmt.Sprintf("http://%s:%v", ne.Ip, ne.Port)
|
|
||||||
requestURI2NF := fmt.Sprintf("%s/api/rest/systemManagement/v1/elementType/%s/objectType/systemState",
|
|
||||||
hostUri, strings.ToLower(ne.NeType))
|
|
||||||
log.Debug("requestURI2NF:", requestURI2NF)
|
|
||||||
|
|
||||||
resp, err := client.R().
|
// var neList []dborm.NeInfo
|
||||||
EnableTrace().
|
// err := dborm.XormGetNeInfoByNeType(neType, &neList)
|
||||||
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
|
// if err != nil {
|
||||||
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
|
// log.Error("Failed to dborm.XormGetNeInfoByNeType:", err)
|
||||||
Get(requestURI2NF)
|
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
if err != nil {
|
// return
|
||||||
log.Error("Get system state from NF is failed:", err)
|
// }
|
||||||
} else {
|
// var omcList []dborm.NeInfo
|
||||||
systemState := make(map[string]interface{})
|
// err = dborm.XormGetNeInfoByNeType("omc", &omcList)
|
||||||
_ = json.Unmarshal(resp.Body(), &systemState)
|
// if err != nil {
|
||||||
data = append(data, systemState)
|
// log.Error("Failed to omc ne list:", err)
|
||||||
}
|
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
}
|
// return
|
||||||
|
// }
|
||||||
|
// for i, ne := range neList {
|
||||||
|
|
||||||
if len(data) == 1 {
|
// }
|
||||||
services.ResponseWithJson(w, http.StatusOK, data[0])
|
// data := make([]map[string]interface{}, 0)
|
||||||
return
|
// for _, ne := range neList {
|
||||||
}
|
// hostUri := fmt.Sprintf("http://%s:%v", ne.Ip, ne.Port)
|
||||||
var response Response
|
// requestURI2NF := fmt.Sprintf("%s/api/rest/systemManagement/v1/elementType/%s/objectType/systemState",
|
||||||
response.Data = data
|
// hostUri, strings.ToLower(ne.NeType))
|
||||||
services.ResponseWithJson(w, http.StatusOK, response)
|
// 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("Get system state from NF is failed:", err)
|
||||||
|
// } else {
|
||||||
|
// systemState := make(map[string]interface{})
|
||||||
|
// _ = json.Unmarshal(resp.Body(), &systemState)
|
||||||
|
// data = append(data, systemState)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if len(data) == 1 {
|
||||||
|
// services.ResponseWithJson(w, http.StatusOK, data[0])
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// var response Response
|
||||||
|
// response.Data = data
|
||||||
|
// services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStateFromNF 旧函数
|
// GetStateFromNF 旧函数
|
||||||
|
|||||||
Reference in New Issue
Block a user