perf: 优化网元直连函数调用
This commit is contained in:
@@ -26,12 +26,13 @@ func NeConfigOMC(neInfo model.NeInfo) (map[string]any, error) {
|
||||
}, nil)
|
||||
var resData map[string]any
|
||||
if err != nil {
|
||||
status := err.Error()
|
||||
logger.Warnf("NeConfigOMC %s Put \"%s\"", status, neUrl)
|
||||
if strings.HasPrefix(status, "201") || strings.HasPrefix(status, "204") {
|
||||
errStr := err.Error()
|
||||
logger.Warnf("NeConfigOMC Put \"%s\"", neUrl)
|
||||
if strings.HasPrefix(errStr, "201") || strings.HasPrefix(errStr, "204") {
|
||||
return resData, nil
|
||||
}
|
||||
return nil, err
|
||||
logger.Errorf("NeConfigOMC %s", errStr)
|
||||
return nil, fmt.Errorf("NeService Config OMC Update API Error")
|
||||
}
|
||||
|
||||
// 200 成功无数据时
|
||||
@@ -42,7 +43,7 @@ func NeConfigOMC(neInfo model.NeInfo) (map[string]any, error) {
|
||||
// 序列化结果
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Warnf("NeConfigOMC Unmarshal %s", err.Error())
|
||||
logger.Errorf("NeConfigOMC Unmarshal %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -50,20 +51,115 @@ func NeConfigOMC(neInfo model.NeInfo) (map[string]any, error) {
|
||||
}
|
||||
|
||||
// NeConfigInfo 网元配置信息
|
||||
func NeConfigInfo(neInfo model.NeInfo, name string) (map[string]any, error) {
|
||||
func NeConfigInfo(neInfo model.NeInfo, paramName string) (map[string]any, error) {
|
||||
// 网元配置对端网管信息
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), name)
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), paramName)
|
||||
resBytes, err := fetch.Get(neUrl, nil, 1000)
|
||||
if err != nil {
|
||||
logger.Warnf("NeConfigInfo %s Get \"%s\"", err.Error(), neUrl)
|
||||
return nil, err
|
||||
logger.Warnf("NeConfigInfo Get \"%s\"", neUrl)
|
||||
logger.Errorf("NeConfigInfo %s", err.Error())
|
||||
return nil, fmt.Errorf("NeService Config Info API Error")
|
||||
}
|
||||
|
||||
// 序列化结果
|
||||
var resData map[string]any
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Warnf("NeConfigInfo Unmarshal %s", err.Error())
|
||||
logger.Errorf("NeConfigInfo Unmarshal %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return resData, nil
|
||||
}
|
||||
|
||||
// NeConfigUpdate 网元配置更新
|
||||
func NeConfigUpdate(neInfo model.NeInfo, paramName, loc string, data map[string]any) (map[string]any, error) {
|
||||
// array需要层级
|
||||
if loc != "" {
|
||||
loc = fmt.Sprintf("?loc=%v", loc)
|
||||
}
|
||||
// 网元参数配置新增(array)
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s%s", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), paramName, loc)
|
||||
resBytes, err := fetch.PutJSON(neUrl, data, nil)
|
||||
var resData map[string]any
|
||||
if err != nil {
|
||||
errStr := err.Error()
|
||||
logger.Warnf("NeConfigUpdate Put \"%s\"", neUrl)
|
||||
if strings.HasPrefix(errStr, "201") || strings.HasPrefix(errStr, "204") {
|
||||
return resData, nil
|
||||
}
|
||||
logger.Errorf("NeConfigUpdate %s", errStr)
|
||||
return nil, fmt.Errorf("NeService Config Update API Error")
|
||||
}
|
||||
|
||||
// 200 成功无数据时
|
||||
if len(resBytes) == 0 {
|
||||
return resData, nil
|
||||
}
|
||||
|
||||
// 序列化结果
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Errorf("NeConfigUpdate Unmarshal %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return resData, nil
|
||||
}
|
||||
|
||||
// NeConfigInstall 网元配置新增 array
|
||||
func NeConfigInstall(neInfo model.NeInfo, paramName, loc string, data map[string]any) (map[string]any, error) {
|
||||
// 网元参数配置新增(array)
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s?loc=%v", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), paramName, loc)
|
||||
resBytes, err := fetch.PostJSON(neUrl, data, nil)
|
||||
var resData map[string]any
|
||||
if err != nil {
|
||||
errStr := err.Error()
|
||||
logger.Warnf("NeConfigInfoAdd Post \"%s\"", neUrl)
|
||||
if strings.HasPrefix(errStr, "201") || strings.HasPrefix(errStr, "204") {
|
||||
return resData, nil
|
||||
}
|
||||
logger.Errorf("NeConfigInfoAdd %s", errStr)
|
||||
return nil, fmt.Errorf("NeService Config Add API Error")
|
||||
}
|
||||
|
||||
// 200 成功无数据时
|
||||
if len(resBytes) == 0 {
|
||||
return resData, nil
|
||||
}
|
||||
|
||||
// 序列化结果
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Errorf("NeConfigInfoAdd Unmarshal %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return resData, nil
|
||||
}
|
||||
|
||||
// NeConfigDelete 网元配置删除 array
|
||||
func NeConfigDelete(neInfo model.NeInfo, paramName, loc string) (map[string]any, error) {
|
||||
// 网元参数配置删除(array)
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s?loc=%v", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), paramName, loc)
|
||||
resBytes, err := fetch.Delete(neUrl, nil)
|
||||
var resData map[string]any
|
||||
if err != nil {
|
||||
errStr := err.Error()
|
||||
logger.Warnf("NeConfigDelete Delete \"%s\"", neUrl)
|
||||
if strings.HasPrefix(errStr, "201") || strings.HasPrefix(errStr, "204") {
|
||||
return resData, nil
|
||||
}
|
||||
logger.Errorf("NeConfigDelete %s", errStr)
|
||||
return nil, fmt.Errorf("NeService Config Update API Error")
|
||||
}
|
||||
|
||||
// 200 成功无数据时
|
||||
if len(resBytes) == 0 {
|
||||
return resData, nil
|
||||
}
|
||||
|
||||
// 序列化结果
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Errorf("NeConfigInfoDel Unmarshal %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return resData, nil
|
||||
|
||||
@@ -17,15 +17,15 @@ func NeState(neInfo model.NeInfo) (map[string]any, error) {
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/systemState", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType))
|
||||
resBytes, err := fetch.Get(neUrl, nil, 1000)
|
||||
if err != nil {
|
||||
logger.Warnf("NeState %s", err.Error())
|
||||
return nil, err
|
||||
logger.Errorf("NeState %s", err.Error())
|
||||
return nil, fmt.Errorf("NeService System State API Error")
|
||||
}
|
||||
|
||||
// 序列化结果
|
||||
var resData map[string]any
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Warnf("NeState Unmarshal %s", err.Error())
|
||||
logger.Errorf("NeState Unmarshal %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
36
src/modules/network_element/fetch_link/udm.go
Normal file
36
src/modules/network_element/fetch_link/udm.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package fetchlink
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/fetch"
|
||||
)
|
||||
|
||||
// UDMImportAuth UDM导入鉴权数据
|
||||
//
|
||||
// data参数 {path:"服务器文件路径", k4:"可选,k4为空时Ki不加密。"}
|
||||
func UDMImportAuth(udmIP string, data map[string]any) (string, error) {
|
||||
// 网元参数配置新增(array)
|
||||
neUrl := fmt.Sprintf("http://%s:8080/ue-manage/v1/import-auth", udmIP)
|
||||
resBytes, err := fetch.PostJSON(neUrl, data, nil)
|
||||
var resData map[string]string
|
||||
if err != nil {
|
||||
errStr := err.Error()
|
||||
logger.Warnf("UDMImportAuth Post \"%s\"", neUrl)
|
||||
logger.Errorf("UDMImportAuth %s", errStr)
|
||||
return "", fmt.Errorf("NeService UDM API Error")
|
||||
}
|
||||
|
||||
// 序列化结果
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Errorf("UDMImportAuth Unmarshal %s", err.Error())
|
||||
return "", err
|
||||
}
|
||||
if v, ok := resData["code"]; ok && v == "00000" {
|
||||
return "ok", nil
|
||||
}
|
||||
return "", fmt.Errorf(resData["message"])
|
||||
}
|
||||
Reference in New Issue
Block a user