fix: UDM数据来源通过网元主机的Redis客户端进行连接
This commit is contained in:
@@ -27,8 +27,7 @@ var NewNeInfo = &NeInfo{
|
||||
|
||||
// 网元信息 服务层处理
|
||||
type NeInfo struct {
|
||||
// 网元信息数据信息
|
||||
neInfoRepository *repository.NeInfo
|
||||
neInfoRepository *repository.NeInfo // 网元信息数据信息
|
||||
Para5GData map[string]string
|
||||
}
|
||||
|
||||
@@ -226,6 +225,7 @@ func (r *NeInfo) Insert(neInfo model.NeInfo) string {
|
||||
for _, host := range neInfo.Hosts {
|
||||
host.Title = fmt.Sprintf("%s_%s_%d", strings.ToUpper(neInfo.NeType), neInfo.NeId, host.Port)
|
||||
host.GroupID = "1"
|
||||
host.CreateBy = neInfo.CreateBy
|
||||
hostId := NewNeHost.Insert(host)
|
||||
if hostId != "" {
|
||||
hostIDs = append(hostIDs, hostId)
|
||||
@@ -250,6 +250,7 @@ func (r *NeInfo) Update(neInfo model.NeInfo) int64 {
|
||||
if host.HostID != "" {
|
||||
host.Title = fmt.Sprintf("%s_%s_%d", strings.ToUpper(neInfo.NeType), neInfo.NeId, host.Port)
|
||||
host.GroupID = "1"
|
||||
host.UpdateBy = neInfo.UpdateBy
|
||||
NewNeHost.Update(host)
|
||||
}
|
||||
}
|
||||
@@ -371,7 +372,7 @@ func (r *NeInfo) NeRunSSHCmd(neType, neId, cmd string) (string, error) {
|
||||
}
|
||||
|
||||
// NeRunTelnetClient 网元主机的Telnet客户端-为创建相关连接,注意结束后 Close()
|
||||
// num 是网元主机telnet 1:4100 2:5200
|
||||
// num 是网元主机telnet 1:4100 2:5200(UPF标准版)
|
||||
func (r *NeInfo) NeRunTelnetClient(neType, neId string, num int) (*telnet.ConnTelnet, error) {
|
||||
neInfo := r.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||
if neInfo.NeId != neId {
|
||||
@@ -406,6 +407,42 @@ func (r *NeInfo) NeRunTelnetClient(neType, neId string, num int) (*telnet.ConnTe
|
||||
return telnetClient, nil
|
||||
}
|
||||
|
||||
// NeRunRedisClient 网元主机的Redis客户端-为创建相关连接,注意结束后 Close()
|
||||
// 暂时只有UDM有Redis配置项
|
||||
func (r *NeInfo) NeRunRedisClient(neType, neId string) (*redis.ConnRedis, error) {
|
||||
neInfo := r.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||
if neInfo.NeId != neId {
|
||||
logger.Errorf("NeRunRedisClient NeType:%s NeID:%s not found", neType, neId)
|
||||
return nil, fmt.Errorf("neinfo not found")
|
||||
}
|
||||
// 取主机信息
|
||||
if neInfo.HostIDs == "" {
|
||||
logger.Errorf("NeRunRedisClient NeType:%s NeID:%s hostId not found", neType, neId)
|
||||
return nil, fmt.Errorf("neinfo hostId not found")
|
||||
}
|
||||
hostIds := strings.Split(neInfo.HostIDs, ",")
|
||||
if len(hostIds) <= 2 {
|
||||
logger.Errorf("NeRunRedisClient hosts id %s not found", neInfo.HostIDs)
|
||||
return nil, fmt.Errorf("neinfo host id not found")
|
||||
}
|
||||
hostId := hostIds[2]
|
||||
neHost := NewNeHost.SelectById(hostId)
|
||||
if neHost.HostID == "" || neHost.HostID != hostId {
|
||||
logger.Errorf("NeRunRedisClient Hosts %s not found", neInfo.HostIDs)
|
||||
return nil, fmt.Errorf("neinfo host not found")
|
||||
}
|
||||
|
||||
// 创建链接Redis客户端
|
||||
var connRedis redis.ConnRedis
|
||||
neHost.CopyTo(&connRedis)
|
||||
redisClient, err := connRedis.NewClient()
|
||||
if err != nil {
|
||||
logger.Errorf("NeRunRedisClient NewClient err => %s", err.Error())
|
||||
return nil, fmt.Errorf("neinfo redis client new err")
|
||||
}
|
||||
return redisClient, nil
|
||||
}
|
||||
|
||||
// NeConfOAMReadSync 网元OAM配置文件读取
|
||||
func (r *NeInfo) NeConfOAMReadSync(neType, neId string) (map[string]any, error) {
|
||||
oamData, err := r.neConfOAMRead(neType, neId, true)
|
||||
|
||||
Reference in New Issue
Block a user