feat: 更新多个模块以支持新的数据结构和日志格式
This commit is contained in:
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/constants/cachekey"
|
||||
"be.ems/src/framework/redis"
|
||||
"be.ems/src/framework/constants"
|
||||
"be.ems/src/framework/database/redis"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/repository"
|
||||
)
|
||||
@@ -25,7 +25,7 @@ type NeConfig struct {
|
||||
func (r *NeConfig) RefreshByNeTypeAndNeID(neType string) []model.NeConfig {
|
||||
// 多个
|
||||
if neType == "" || neType == "*" {
|
||||
neConfigList := r.neConfigRepository.SelectList(model.NeConfig{})
|
||||
neConfigList := r.neConfigRepository.Select(model.NeConfig{})
|
||||
if len(neConfigList) > 0 {
|
||||
neConfigGroup := map[string][]model.NeConfig{}
|
||||
for _, v := range neConfigList {
|
||||
@@ -36,7 +36,7 @@ func (r *NeConfig) RefreshByNeTypeAndNeID(neType string) []model.NeConfig {
|
||||
}
|
||||
}
|
||||
for k, v := range neConfigGroup {
|
||||
key := fmt.Sprintf("%sNeConfig:%s", cachekey.NE_DATA_KEY, strings.ToUpper(k))
|
||||
key := fmt.Sprintf("%s:NeConfig:%s", constants.CACHE_NE_DATA, strings.ToUpper(k))
|
||||
redis.Del("", key)
|
||||
if len(v) > 0 {
|
||||
for i, item := range v {
|
||||
@@ -53,9 +53,9 @@ func (r *NeConfig) RefreshByNeTypeAndNeID(neType string) []model.NeConfig {
|
||||
return neConfigList
|
||||
}
|
||||
// 单个
|
||||
key := fmt.Sprintf("%sNeConfig:%s", cachekey.NE_DATA_KEY, strings.ToUpper(neType))
|
||||
key := fmt.Sprintf("%s:NeConfig:%s", constants.CACHE_NE_DATA, strings.ToUpper(neType))
|
||||
redis.Del("", key)
|
||||
neConfigList := r.neConfigRepository.SelectList(model.NeConfig{
|
||||
neConfigList := r.neConfigRepository.Select(model.NeConfig{
|
||||
NeType: neType,
|
||||
})
|
||||
if len(neConfigList) > 0 {
|
||||
@@ -73,22 +73,21 @@ func (r *NeConfig) RefreshByNeTypeAndNeID(neType string) []model.NeConfig {
|
||||
|
||||
// ClearNeCacheByNeType 清除网元类型参数配置缓存
|
||||
func (r *NeConfig) ClearNeCacheByNeType(neType string) bool {
|
||||
key := fmt.Sprintf("%sNeConfig:%s", cachekey.NE_DATA_KEY, neType)
|
||||
key := fmt.Sprintf("%s:NeConfig:%s", constants.CACHE_NE_DATA, neType)
|
||||
if neType == "*" {
|
||||
key = fmt.Sprintf("%sNeConfig:*", cachekey.NE_DATA_KEY)
|
||||
key = fmt.Sprintf("%s:NeConfig:*", constants.CACHE_NE_DATA)
|
||||
}
|
||||
keys, err := redis.GetKeys("", key)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
delOk, _ := redis.DelKeys("", keys)
|
||||
return delOk
|
||||
return redis.DelKeys("", keys) == nil
|
||||
}
|
||||
|
||||
// SelectNeConfigByNeType 查询网元类型参数配置
|
||||
func (r *NeConfig) SelectNeConfigByNeType(neType string) []model.NeConfig {
|
||||
// FindByNeType 查询网元类型参数配置
|
||||
func (r *NeConfig) FindByNeType(neType string) []model.NeConfig {
|
||||
var neConfigList []model.NeConfig
|
||||
key := fmt.Sprintf("%sNeConfig:%s", cachekey.NE_DATA_KEY, strings.ToUpper(neType))
|
||||
key := fmt.Sprintf("%s:NeConfig:%s", constants.CACHE_NE_DATA, strings.ToUpper(neType))
|
||||
jsonStr, _ := redis.Get("", key)
|
||||
if len(jsonStr) > 7 {
|
||||
err := json.Unmarshal([]byte(jsonStr), &neConfigList)
|
||||
@@ -101,9 +100,9 @@ func (r *NeConfig) SelectNeConfigByNeType(neType string) []model.NeConfig {
|
||||
return neConfigList
|
||||
}
|
||||
|
||||
// SelectNeConfigByNeTypeAndParamName 查询网元类型参数配置By参数名
|
||||
func (r *NeConfig) SelectNeConfigByNeTypeAndParamName(neType, paramName string) model.NeConfig {
|
||||
neConfigList := r.SelectNeConfigByNeType(neType)
|
||||
// FindByNeTypeAndParamName 查询网元类型参数配置By参数名
|
||||
func (r *NeConfig) FindByNeTypeAndParamName(neType, paramName string) model.NeConfig {
|
||||
neConfigList := r.FindByNeType(neType)
|
||||
var neConfig model.NeConfig
|
||||
for _, v := range neConfigList {
|
||||
if v.ParamName == paramName {
|
||||
@@ -114,22 +113,22 @@ func (r *NeConfig) SelectNeConfigByNeTypeAndParamName(neType, paramName string)
|
||||
return neConfig
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeConfig) SelectPage(query map[string]string) ([]model.NeConfig, int64) {
|
||||
// FindByPage 分页查询列表数据
|
||||
func (r *NeConfig) FindByPage(query map[string]string) ([]model.NeConfig, int64) {
|
||||
return r.neConfigRepository.SelectByPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *NeConfig) SelectList(param model.NeConfig) []model.NeConfig {
|
||||
return r.neConfigRepository.SelectList(param)
|
||||
// Find 查询列表
|
||||
func (r *NeConfig) Find(param model.NeConfig) []model.NeConfig {
|
||||
return r.neConfigRepository.Select(param)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeConfig) SelectById(id string) model.NeConfig {
|
||||
if id == "" {
|
||||
// FindById 通过ID查询
|
||||
func (r *NeConfig) FindById(id int64) model.NeConfig {
|
||||
if id <= 0 {
|
||||
return model.NeConfig{}
|
||||
}
|
||||
neHosts := r.neConfigRepository.SelectByIds([]string{id})
|
||||
neHosts := r.neConfigRepository.SelectByIds([]int64{id})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
}
|
||||
@@ -137,7 +136,7 @@ func (r *NeConfig) SelectById(id string) model.NeConfig {
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeConfig) Insert(param model.NeConfig) string {
|
||||
func (r *NeConfig) Insert(param model.NeConfig) int64 {
|
||||
return r.neConfigRepository.Insert(param)
|
||||
}
|
||||
|
||||
@@ -147,7 +146,7 @@ func (r *NeConfig) Update(param model.NeConfig) int64 {
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeConfig) DeleteByIds(ids []string) (int64, error) {
|
||||
func (r *NeConfig) DeleteByIds(ids []int64) (int64, error) {
|
||||
// 检查是否存在
|
||||
data := r.neConfigRepository.SelectByIds(ids)
|
||||
if len(data) <= 0 {
|
||||
|
||||
@@ -23,22 +23,17 @@ type NeConfigBackup struct {
|
||||
neConfigBackupRepository *repository.NeConfigBackup // 网元配置文件备份记录
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeConfigBackup) SelectPage(query map[string]any) map[string]any {
|
||||
return r.neConfigBackupRepository.SelectPage(query)
|
||||
// FindByPage 分页查询列表数据
|
||||
func (s NeConfigBackup) FindByPage(query map[string]string) ([]model.NeConfigBackup, int64) {
|
||||
return s.neConfigBackupRepository.SelectByPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *NeConfigBackup) SelectList(item model.NeConfigBackup) []model.NeConfigBackup {
|
||||
return r.neConfigBackupRepository.SelectList(item)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeConfigBackup) SelectById(id string) model.NeConfigBackup {
|
||||
if id == "" {
|
||||
// FindById 通过ID查询
|
||||
func (s NeConfigBackup) FindById(id int64) model.NeConfigBackup {
|
||||
if id <= 0 {
|
||||
return model.NeConfigBackup{}
|
||||
}
|
||||
arr := r.neConfigBackupRepository.SelectByIds([]string{id})
|
||||
arr := s.neConfigBackupRepository.SelectByIds([]int64{id})
|
||||
if len(arr) > 0 {
|
||||
return arr[0]
|
||||
}
|
||||
@@ -46,33 +41,33 @@ func (r *NeConfigBackup) SelectById(id string) model.NeConfigBackup {
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeConfigBackup) Insert(item model.NeConfigBackup) string {
|
||||
return r.neConfigBackupRepository.Insert(item)
|
||||
func (s NeConfigBackup) Insert(item model.NeConfigBackup) int64 {
|
||||
return s.neConfigBackupRepository.Insert(item)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeConfigBackup) Update(item model.NeConfigBackup) int64 {
|
||||
return r.neConfigBackupRepository.Update(item)
|
||||
func (s NeConfigBackup) Update(item model.NeConfigBackup) int64 {
|
||||
return s.neConfigBackupRepository.Update(item)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeConfigBackup) DeleteByIds(ids []string) (int64, error) {
|
||||
func (s NeConfigBackup) DeleteByIds(ids []int64) (int64, error) {
|
||||
// 检查是否存在
|
||||
data := r.neConfigBackupRepository.SelectByIds(ids)
|
||||
data := s.neConfigBackupRepository.SelectByIds(ids)
|
||||
if len(data) <= 0 {
|
||||
return 0, fmt.Errorf("neConfigBackup.noData")
|
||||
}
|
||||
|
||||
if len(data) == len(ids) {
|
||||
rows := r.neConfigBackupRepository.DeleteByIds(ids)
|
||||
rows := s.neConfigBackupRepository.DeleteByIds(ids)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// NeConfigLocalToNe 网元配置文件复制到网元端覆盖
|
||||
func (r *NeConfigBackup) NeConfigLocalToNe(neInfo model.NeInfo, localFile string) error {
|
||||
// FileLocalToNe 网元配置文件复制到网元端覆盖
|
||||
func (s NeConfigBackup) FileLocalToNe(neInfo model.NeInfo, localFile string) error {
|
||||
neTypeLower := strings.ToLower(neInfo.NeType)
|
||||
// 网管本地路径
|
||||
omcPath := "/usr/local/etc/omc/ne_config"
|
||||
@@ -108,7 +103,7 @@ func (r *NeConfigBackup) NeConfigLocalToNe(neInfo model.NeInfo, localFile string
|
||||
// 配置复制到网元内
|
||||
if neTypeLower == "ims" {
|
||||
// ims目录
|
||||
imsDirArr := [...]string{"bgcf", "icscf", "ismc", "mmtel", "mrf", "oam_manager.yaml", "pcscf", "scscf", "vars.cfg", "zlog"}
|
||||
imsDirArr := [...]string{"bgcf", "icscf", "ismc", "mmtel", "mrf", "oam_manages.yaml", "pcscf", "scscf", "vars.cfg", "zlog"}
|
||||
for _, v := range imsDirArr {
|
||||
sshClient.RunCMD(fmt.Sprintf("sudo mkdir -p /usr/local/etc/ims && sudo cp -rf %s/ims/%s /usr/local/etc/ims/%v && sudo chmod 755 -R /usr/local/etc/ims/%s", neDirTemp, v, v, v))
|
||||
}
|
||||
@@ -137,8 +132,8 @@ func (r *NeConfigBackup) NeConfigLocalToNe(neInfo model.NeInfo, localFile string
|
||||
return nil
|
||||
}
|
||||
|
||||
// NeConfigNeToLocal 网元备份文件网元端复制到本地
|
||||
func (r *NeConfigBackup) NeConfigNeToLocal(neInfo model.NeInfo) (string, error) {
|
||||
// FileNeToLocal 网元备份文件网元端复制到本地
|
||||
func (s NeConfigBackup) FileNeToLocal(neInfo model.NeInfo) (string, error) {
|
||||
// 网元主机的SSH客户端
|
||||
sshClient, err := NewNeInfo.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
|
||||
if err != nil {
|
||||
@@ -166,7 +161,7 @@ func (r *NeConfigBackup) NeConfigNeToLocal(neInfo model.NeInfo) (string, error)
|
||||
if neTypeLower == "ims" {
|
||||
// ims目录
|
||||
sshClient.RunCMD(fmt.Sprintf("mkdir -p %s/ims", neDirTemp))
|
||||
imsDirArr := [...]string{"bgcf", "icscf", "ismc", "mmtel", "mrf", "oam_manager.yaml", "pcscf", "scscf", "vars.cfg", "zlog"}
|
||||
imsDirArr := [...]string{"bgcf", "icscf", "ismc", "mmtel", "mrf", "oam_manages.yaml", "pcscf", "scscf", "vars.cfg", "zlog"}
|
||||
for _, v := range imsDirArr {
|
||||
sshClient.RunCMD(fmt.Sprintf("sudo cp -rf /usr/local/etc/ims/%s %s/ims", v, neDirTemp))
|
||||
}
|
||||
|
||||
@@ -20,23 +20,18 @@ type NeHost struct {
|
||||
neHostRepository *repository.NeHost // 网元主机连接表
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeHost) SelectPage(query map[string]any) map[string]any {
|
||||
return r.neHostRepository.SelectPage(query)
|
||||
// FindByPage 分页查询列表数据
|
||||
func (r NeHost) FindByPage(query map[string]string) ([]model.NeHost, int64) {
|
||||
return r.neHostRepository.SelectByPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *NeHost) SelectList(neHost model.NeHost) []model.NeHost {
|
||||
return r.neHostRepository.SelectList(neHost)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeHost) SelectById(hostId string) model.NeHost {
|
||||
// FindById 通过ID查询
|
||||
func (r NeHost) FindById(hostId int64) model.NeHost {
|
||||
neHost := model.NeHost{}
|
||||
if hostId == "" {
|
||||
if hostId <= 0 {
|
||||
return neHost
|
||||
}
|
||||
neHosts := r.neHostRepository.SelectByIds([]string{hostId})
|
||||
neHosts := r.neHostRepository.SelectByIds([]int64{hostId})
|
||||
if len(neHosts) > 0 {
|
||||
neHost := neHosts[0]
|
||||
hostKey := config.Get("aes.hostKey").(string)
|
||||
@@ -70,11 +65,11 @@ func (r *NeHost) SelectById(hostId string) model.NeHost {
|
||||
}
|
||||
|
||||
// Insert 批量添加
|
||||
func (r *NeHost) Inserts(neHosts []model.NeHost) int64 {
|
||||
func (r NeHost) Inserts(neHosts []model.NeHost) int64 {
|
||||
var num int64 = 0
|
||||
for _, v := range neHosts {
|
||||
hostId := r.neHostRepository.Insert(v)
|
||||
if hostId != "" {
|
||||
if hostId > 0 {
|
||||
num += 1
|
||||
}
|
||||
}
|
||||
@@ -82,13 +77,13 @@ func (r *NeHost) Inserts(neHosts []model.NeHost) int64 {
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeHost) Insert(neHost model.NeHost) string {
|
||||
func (r NeHost) Insert(neHost model.NeHost) int64 {
|
||||
hostKey := config.Get("aes.hostKey").(string)
|
||||
if neHost.Password != "" {
|
||||
passwordEn, err := crypto.AESEncryptBase64(neHost.Password, hostKey)
|
||||
if err != nil {
|
||||
logger.Errorf("insert encrypt: %v", err.Error())
|
||||
return ""
|
||||
return 0
|
||||
}
|
||||
neHost.Password = passwordEn
|
||||
}
|
||||
@@ -96,7 +91,7 @@ func (r *NeHost) Insert(neHost model.NeHost) string {
|
||||
privateKeyEn, err := crypto.AESEncryptBase64(neHost.PrivateKey, hostKey)
|
||||
if err != nil {
|
||||
logger.Errorf("insert encrypt: %v", err.Error())
|
||||
return ""
|
||||
return 0
|
||||
}
|
||||
neHost.PrivateKey = privateKeyEn
|
||||
}
|
||||
@@ -104,7 +99,7 @@ func (r *NeHost) Insert(neHost model.NeHost) string {
|
||||
passPhraseEn, err := crypto.AESEncryptBase64(neHost.PassPhrase, hostKey)
|
||||
if err != nil {
|
||||
logger.Errorf("insert encrypt: %v", err.Error())
|
||||
return ""
|
||||
return 0
|
||||
}
|
||||
neHost.PassPhrase = passPhraseEn
|
||||
}
|
||||
@@ -112,7 +107,7 @@ func (r *NeHost) Insert(neHost model.NeHost) string {
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeHost) Update(neHost model.NeHost) int64 {
|
||||
func (r NeHost) Update(neHost model.NeHost) int64 {
|
||||
hostKey := config.Get("aes.hostKey").(string)
|
||||
if neHost.Password != "" {
|
||||
passwordEn, err := crypto.AESEncryptBase64(neHost.Password, hostKey)
|
||||
@@ -142,7 +137,7 @@ func (r *NeHost) Update(neHost model.NeHost) int64 {
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除网元主机连接信息
|
||||
func (r *NeHost) DeleteByIds(hostIds []string) (int64, error) {
|
||||
func (r NeHost) DeleteByIds(hostIds []int64) (int64, error) {
|
||||
// 检查是否存在
|
||||
ids := r.neHostRepository.SelectByIds(hostIds)
|
||||
if len(ids) <= 0 {
|
||||
@@ -165,8 +160,8 @@ func (r *NeHost) DeleteByIds(hostIds []string) (int64, error) {
|
||||
}
|
||||
|
||||
// CheckUniqueHostTitle 校验分组组和主机名称是否唯一
|
||||
func (r *NeHost) CheckUniqueHostTitle(groupId, title, hostType, hostId string) bool {
|
||||
uniqueId := r.neHostRepository.CheckUniqueNeHost(model.NeHost{
|
||||
func (r NeHost) CheckUniqueHostTitle(groupId, title, hostType string, hostId int64) bool {
|
||||
uniqueId := r.neHostRepository.CheckUnique(model.NeHost{
|
||||
HostType: hostType,
|
||||
GroupID: groupId,
|
||||
Title: title,
|
||||
@@ -174,5 +169,5 @@ func (r *NeHost) CheckUniqueHostTitle(groupId, title, hostType, hostId string) b
|
||||
if uniqueId == hostId {
|
||||
return true
|
||||
}
|
||||
return uniqueId == ""
|
||||
return uniqueId == 0
|
||||
}
|
||||
|
||||
@@ -17,22 +17,17 @@ type NeHostCmd struct {
|
||||
neHostCmdRepository *repository.NeHostCmd // 网元主机命令表
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeHostCmd) SelectPage(query map[string]any) map[string]any {
|
||||
return r.neHostCmdRepository.SelectPage(query)
|
||||
// FindByPage 分页查询列表数据
|
||||
func (r *NeHostCmd) FindByPage(query map[string]string) ([]model.NeHostCmd, int64) {
|
||||
return r.neHostCmdRepository.SelectByPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *NeHostCmd) SelectList(neHostCmd model.NeHostCmd) []model.NeHostCmd {
|
||||
return r.neHostCmdRepository.SelectList(neHostCmd)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeHostCmd) SelectById(cmdId string) model.NeHostCmd {
|
||||
if cmdId == "" {
|
||||
// FindById 通过ID查询
|
||||
func (r *NeHostCmd) FindById(id int64) model.NeHostCmd {
|
||||
if id <= 0 {
|
||||
return model.NeHostCmd{}
|
||||
}
|
||||
neHosts := r.neHostCmdRepository.SelectByIds([]string{cmdId})
|
||||
neHosts := r.neHostCmdRepository.SelectByIds([]int64{id})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
}
|
||||
@@ -40,7 +35,7 @@ func (r *NeHostCmd) SelectById(cmdId string) model.NeHostCmd {
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeHostCmd) Insert(neHostCmd model.NeHostCmd) string {
|
||||
func (r *NeHostCmd) Insert(neHostCmd model.NeHostCmd) int64 {
|
||||
return r.neHostCmdRepository.Insert(neHostCmd)
|
||||
}
|
||||
|
||||
@@ -50,15 +45,15 @@ func (r *NeHostCmd) Update(neHostCmd model.NeHostCmd) int64 {
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeHostCmd) DeleteByIds(cmdIds []string) (int64, error) {
|
||||
func (r *NeHostCmd) DeleteByIds(ids []int64) (int64, error) {
|
||||
// 检查是否存在
|
||||
ids := r.neHostCmdRepository.SelectByIds(cmdIds)
|
||||
if len(ids) <= 0 {
|
||||
rows := r.neHostCmdRepository.SelectByIds(ids)
|
||||
if len(rows) <= 0 {
|
||||
return 0, fmt.Errorf("neHostCmd.noData")
|
||||
}
|
||||
|
||||
if len(ids) == len(cmdIds) {
|
||||
rows := r.neHostCmdRepository.DeleteByIds(cmdIds)
|
||||
if len(rows) == len(ids) {
|
||||
rows := r.neHostCmdRepository.DeleteByIds(ids)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
@@ -66,8 +61,8 @@ func (r *NeHostCmd) DeleteByIds(cmdIds []string) (int64, error) {
|
||||
}
|
||||
|
||||
// CheckUniqueGroupTitle 校验同类型组内是否唯一
|
||||
func (r *NeHostCmd) CheckUniqueGroupTitle(groupId, title, cmdType, cmdId string) bool {
|
||||
uniqueId := r.neHostCmdRepository.CheckUniqueGroupTitle(model.NeHostCmd{
|
||||
func (r *NeHostCmd) CheckUniqueGroupTitle(groupId, title, cmdType string, cmdId int64) bool {
|
||||
uniqueId := r.neHostCmdRepository.CheckUnique(model.NeHostCmd{
|
||||
CmdType: cmdType,
|
||||
GroupID: groupId,
|
||||
Title: title,
|
||||
@@ -75,5 +70,5 @@ func (r *NeHostCmd) CheckUniqueGroupTitle(groupId, title, cmdType, cmdId string)
|
||||
if uniqueId == cmdId {
|
||||
return true
|
||||
}
|
||||
return uniqueId == ""
|
||||
return uniqueId == 0
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/constants/cachekey"
|
||||
"be.ems/src/framework/constants"
|
||||
"be.ems/src/framework/database/redis"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/redis"
|
||||
"be.ems/src/framework/ssh"
|
||||
"be.ems/src/framework/telnet"
|
||||
"be.ems/src/framework/utils/generate"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/utils/ssh"
|
||||
neFetchlink "be.ems/src/modules/network_element/fetch_link"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/repository"
|
||||
@@ -23,19 +23,21 @@ import (
|
||||
// 实例化服务层 NeInfo 结构体
|
||||
var NewNeInfo = &NeInfo{
|
||||
neInfoRepository: repository.NewNeInfo,
|
||||
neHostService: NewNeHost,
|
||||
Para5GData: map[string]string{},
|
||||
}
|
||||
|
||||
// 网元信息 服务层处理
|
||||
type NeInfo struct {
|
||||
neInfoRepository *repository.NeInfo // 网元信息数据信息
|
||||
neHostService *NeHost // 网元主机连接服务
|
||||
Para5GData map[string]string
|
||||
}
|
||||
|
||||
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||
func (r *NeInfo) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||
// FindByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||
func (r NeInfo) FindByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||
var neInfo model.NeInfo
|
||||
key := fmt.Sprintf("%s%s:%s", cachekey.NE_KEY, strings.ToUpper(neType), neID)
|
||||
key := fmt.Sprintf("%s:%s:%s", constants.CACHE_NE_INFO, strings.ToUpper(neType), neID)
|
||||
jsonStr, _ := redis.Get("", key)
|
||||
if len(jsonStr) > 7 {
|
||||
err := json.Unmarshal([]byte(jsonStr), &neInfo)
|
||||
@@ -44,7 +46,7 @@ func (r *NeInfo) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||
}
|
||||
} else {
|
||||
neInfo = r.neInfoRepository.SelectNeInfoByNeTypeAndNeID(neType, neID)
|
||||
if neInfo.ID != "" && neInfo.NeId == neID {
|
||||
if neInfo.ID != 0 && neInfo.NeId == neID {
|
||||
redis.Del("", key)
|
||||
values, _ := json.Marshal(neInfo)
|
||||
redis.Set("", key, string(values))
|
||||
@@ -54,12 +56,12 @@ func (r *NeInfo) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||
}
|
||||
|
||||
// RefreshByNeTypeAndNeID 通过ne_type和ne_id刷新redis中的缓存
|
||||
func (r *NeInfo) RefreshByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||
func (r NeInfo) RefreshByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||
var neInfo model.NeInfo
|
||||
key := fmt.Sprintf("%s%s:%s", cachekey.NE_KEY, strings.ToUpper(neType), neID)
|
||||
key := fmt.Sprintf("%s:%s:%s", constants.CACHE_NE_INFO, strings.ToUpper(neType), neID)
|
||||
redis.Del("", key)
|
||||
neInfo = r.neInfoRepository.SelectNeInfoByNeTypeAndNeID(neType, neID)
|
||||
if neInfo.ID != "" && neInfo.NeId == neID {
|
||||
if neInfo.ID != 0 && neInfo.NeId == neID {
|
||||
values, _ := json.Marshal(neInfo)
|
||||
redis.Set("", key, string(values))
|
||||
}
|
||||
@@ -67,23 +69,22 @@ func (r *NeInfo) RefreshByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||
}
|
||||
|
||||
// ClearNeCacheByNeType 清除网元类型缓存
|
||||
func (r *NeInfo) ClearNeCacheByNeType(neType string) bool {
|
||||
key := fmt.Sprintf("%s*", cachekey.NE_KEY)
|
||||
func (r NeInfo) ClearNeCacheByNeType(neType string) bool {
|
||||
key := fmt.Sprintf("%s:*", constants.CACHE_NE_INFO)
|
||||
if neType != "*" {
|
||||
key = fmt.Sprintf("%s%s*", cachekey.NE_KEY, neType)
|
||||
key = fmt.Sprintf("%s:%s*", constants.CACHE_NE_INFO, neType)
|
||||
}
|
||||
keys, err := redis.GetKeys("", key)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
delOk, _ := redis.DelKeys("", keys)
|
||||
return delOk
|
||||
return redis.DelKeys("", keys) == nil
|
||||
}
|
||||
|
||||
// SelectNeInfoByNeType 通过ne_type查询网元信息
|
||||
func (r *NeInfo) SelectNeInfoByNeType(neType string) []model.NeInfo {
|
||||
// FindByNeType 通过ne_type查询网元信息
|
||||
func (r NeInfo) FindByNeType(neType string) []model.NeInfo {
|
||||
neInfo := make([]model.NeInfo, 0)
|
||||
key := fmt.Sprintf("%s%s:*", cachekey.NE_KEY, strings.ToUpper(neType))
|
||||
key := fmt.Sprintf("%s:%s:*", constants.CACHE_NE_INFO, strings.ToUpper(neType))
|
||||
jsonStr, _ := redis.Get("", key)
|
||||
if len(jsonStr) > 7 {
|
||||
err := json.Unmarshal([]byte(jsonStr), &neInfo)
|
||||
@@ -93,7 +94,7 @@ func (r *NeInfo) SelectNeInfoByNeType(neType string) []model.NeInfo {
|
||||
} else {
|
||||
neInfo = r.neInfoRepository.SelectList(model.NeInfo{NeType: neType})
|
||||
for _, v := range neInfo {
|
||||
key := fmt.Sprintf("%s%s:%s", cachekey.NE_KEY, strings.ToUpper(v.NeType), v.NeId)
|
||||
key := fmt.Sprintf("%s:%s:%s", constants.CACHE_NE_INFO, strings.ToUpper(v.NeType), v.NeId)
|
||||
redis.Del("", key)
|
||||
values, _ := json.Marshal(v)
|
||||
redis.Set("", key, string(values))
|
||||
@@ -102,10 +103,10 @@ func (r *NeInfo) SelectNeInfoByNeType(neType string) []model.NeInfo {
|
||||
return neInfo
|
||||
}
|
||||
|
||||
// SelectNeInfoByRmuid 通过rmUID查询网元信息
|
||||
func (r *NeInfo) SelectNeInfoByRmuid(rmUid string) model.NeInfo {
|
||||
// FindByRmuid 通过rmUID查询网元信息
|
||||
func (r NeInfo) FindByRmuid(rmUid string) model.NeInfo {
|
||||
var neInfo model.NeInfo
|
||||
cacheKeys, _ := redis.GetKeys("", cachekey.NE_KEY+"*")
|
||||
cacheKeys, _ := redis.GetKeys("", constants.CACHE_NE_INFO+":*")
|
||||
if len(cacheKeys) > 0 {
|
||||
for _, key := range cacheKeys {
|
||||
var v model.NeInfo
|
||||
@@ -119,9 +120,9 @@ func (r *NeInfo) SelectNeInfoByRmuid(rmUid string) model.NeInfo {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
neInfos := r.SelectList(neInfo, false, false)
|
||||
neInfos := r.Find(neInfo, false, false)
|
||||
for _, v := range neInfos {
|
||||
key := fmt.Sprintf("%s%s:%s", cachekey.NE_KEY, strings.ToUpper(v.NeType), v.NeId)
|
||||
key := fmt.Sprintf("%s:%s:%s", constants.CACHE_NE_INFO, strings.ToUpper(v.NeType), v.NeId)
|
||||
redis.Del("", key)
|
||||
values, _ := json.Marshal(v)
|
||||
redis.Set("", key, string(values))
|
||||
@@ -133,10 +134,10 @@ func (r *NeInfo) SelectNeInfoByRmuid(rmUid string) model.NeInfo {
|
||||
return neInfo
|
||||
}
|
||||
|
||||
// SelectPage 根据条件分页查询
|
||||
// FindByPage 根据条件分页查询
|
||||
//
|
||||
// bandStatus 带状态信息
|
||||
func (r *NeInfo) SelectPage(query map[string]string, bandStatus bool) ([]model.NeInfo, int64) {
|
||||
func (r NeInfo) FindByPage(query map[string]string, bandStatus bool) ([]model.NeInfo, int64) {
|
||||
rows, total := r.neInfoRepository.SelectByPage(query)
|
||||
|
||||
// 网元直连读取网元服务状态
|
||||
@@ -147,11 +148,11 @@ func (r *NeInfo) SelectPage(query map[string]string, bandStatus bool) ([]model.N
|
||||
return rows, total
|
||||
}
|
||||
|
||||
// SelectList 查询列表
|
||||
// Find 查询列表
|
||||
//
|
||||
// bandStatus 带状态信息
|
||||
// bandHost 带主机信息
|
||||
func (r *NeInfo) SelectList(ne model.NeInfo, bandStatus bool, bandHost bool) []model.NeInfo {
|
||||
func (r NeInfo) Find(ne model.NeInfo, bandStatus bool, bandHost bool) []model.NeInfo {
|
||||
list := r.neInfoRepository.SelectList(ne)
|
||||
|
||||
// 网元直连读取网元服务状态
|
||||
@@ -168,7 +169,7 @@ func (r *NeInfo) SelectList(ne model.NeInfo, bandStatus bool, bandHost bool) []m
|
||||
}
|
||||
|
||||
// bandNeStatus 网元列表项数据带网元服务状态
|
||||
func (r *NeInfo) bandNeStatus(arr *[]model.NeInfo) {
|
||||
func (r NeInfo) bandNeStatus(arr *[]model.NeInfo) {
|
||||
for i := range *arr {
|
||||
v := (*arr)[i]
|
||||
result, err := neFetchlink.NeState(v)
|
||||
@@ -177,8 +178,8 @@ func (r *NeInfo) bandNeStatus(arr *[]model.NeInfo) {
|
||||
"online": false,
|
||||
}
|
||||
// 网元状态设置为离线
|
||||
if v.Status != "0" {
|
||||
v.Status = "0"
|
||||
if v.Status != 0 {
|
||||
v.Status = 0
|
||||
(*arr)[i].Status = v.Status
|
||||
r.neInfoRepository.UpdateState(v.ID, v.Status)
|
||||
}
|
||||
@@ -187,13 +188,13 @@ func (r *NeInfo) bandNeStatus(arr *[]model.NeInfo) {
|
||||
result["online"] = true
|
||||
(*arr)[i].ServerState = result
|
||||
// 网元状态设置为在线
|
||||
status := "1"
|
||||
var status int64 = 1
|
||||
if parse.Boolean(result["standby"]) {
|
||||
status = "3"
|
||||
status = 3
|
||||
}
|
||||
// 下发网管配置信息给网元
|
||||
if _, err = neFetchlink.NeConfigOMC(v); err != nil {
|
||||
status = "2"
|
||||
status = 2
|
||||
}
|
||||
(*arr)[i].Status = status
|
||||
if v.Status != status {
|
||||
@@ -203,7 +204,7 @@ func (r *NeInfo) bandNeStatus(arr *[]model.NeInfo) {
|
||||
}
|
||||
|
||||
// bandNeHosts 网元列表项数据带网元主机信息
|
||||
func (r *NeInfo) bandNeHosts(arr *[]model.NeInfo) {
|
||||
func (r NeInfo) bandNeHosts(arr *[]model.NeInfo) {
|
||||
for i := range *arr {
|
||||
v := (*arr)[i]
|
||||
if v.HostIDs != "" {
|
||||
@@ -211,9 +212,10 @@ func (r *NeInfo) bandNeHosts(arr *[]model.NeInfo) {
|
||||
if len(hostIds) <= 1 {
|
||||
continue
|
||||
}
|
||||
for _, hostId := range hostIds {
|
||||
neHost := NewNeHost.SelectById(hostId)
|
||||
if neHost.HostID == "" || neHost.HostID != hostId {
|
||||
for _, v := range hostIds {
|
||||
hostId := parse.Number(v)
|
||||
neHost := r.neHostService.FindById(hostId)
|
||||
if neHost.ID == 0 || neHost.ID != hostId {
|
||||
continue
|
||||
}
|
||||
(*arr)[i].Hosts = append((*arr)[i].Hosts, neHost)
|
||||
@@ -222,14 +224,14 @@ func (r *NeInfo) bandNeHosts(arr *[]model.NeInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
// FindById 通过ID查询
|
||||
//
|
||||
// bandHost 带主机信息
|
||||
func (r *NeInfo) SelectById(infoId string, bandHost bool) model.NeInfo {
|
||||
if infoId == "" {
|
||||
func (r NeInfo) FindById(id int64, bandHost bool) model.NeInfo {
|
||||
if id <= 0 {
|
||||
return model.NeInfo{}
|
||||
}
|
||||
neInfos := r.neInfoRepository.SelectByIds([]string{infoId})
|
||||
neInfos := r.neInfoRepository.SelectByIds([]int64{id})
|
||||
if len(neInfos) > 0 {
|
||||
// 带主机信息
|
||||
if neInfos[0].HostIDs != "" && bandHost {
|
||||
@@ -241,7 +243,7 @@ func (r *NeInfo) SelectById(infoId string, bandHost bool) model.NeInfo {
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeInfo) Insert(neInfo model.NeInfo) string {
|
||||
func (r NeInfo) Insert(neInfo model.NeInfo) int64 {
|
||||
// 主机信息新增
|
||||
if neInfo.Hosts != nil {
|
||||
uuid := generate.Code(4)
|
||||
@@ -250,16 +252,16 @@ func (r *NeInfo) Insert(neInfo model.NeInfo) string {
|
||||
host.Title = neInfo.NeName + "_" + uuid
|
||||
host.GroupID = "1"
|
||||
host.CreateBy = neInfo.CreateBy
|
||||
hostId := NewNeHost.Insert(host)
|
||||
if hostId != "" {
|
||||
hostIDs = append(hostIDs, hostId)
|
||||
hostId := r.neHostService.Insert(host)
|
||||
if hostId > 0 {
|
||||
hostIDs = append(hostIDs, fmt.Sprint(hostId))
|
||||
}
|
||||
}
|
||||
neInfo.HostIDs = strings.Join(hostIDs, ",")
|
||||
}
|
||||
|
||||
insertId := r.neInfoRepository.Insert(neInfo)
|
||||
if insertId != "" {
|
||||
if insertId > 0 {
|
||||
// 刷新缓存
|
||||
r.RefreshByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
|
||||
}
|
||||
@@ -267,16 +269,16 @@ func (r *NeInfo) Insert(neInfo model.NeInfo) string {
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeInfo) Update(neInfo model.NeInfo) int64 {
|
||||
func (r NeInfo) Update(neInfo model.NeInfo) int64 {
|
||||
// 主机信息更新
|
||||
if neInfo.Hosts != nil {
|
||||
uuid := generate.Code(4)
|
||||
for _, host := range neInfo.Hosts {
|
||||
if host.HostID != "" {
|
||||
if host.ID != 0 {
|
||||
host.Title = neInfo.NeName + "_" + uuid
|
||||
host.GroupID = "1"
|
||||
host.UpdateBy = neInfo.UpdateBy
|
||||
NewNeHost.Update(host)
|
||||
r.neHostService.Update(host)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,33 +292,38 @@ func (r *NeInfo) Update(neInfo model.NeInfo) int64 {
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeInfo) DeleteByIds(infoIds []string) (int64, error) {
|
||||
func (r NeInfo) DeleteByIds(ids []int64) (int64, error) {
|
||||
// 检查是否存在
|
||||
infos := r.neInfoRepository.SelectByIds(infoIds)
|
||||
infos := r.neInfoRepository.SelectByIds(ids)
|
||||
if len(infos) <= 0 {
|
||||
return 0, fmt.Errorf("neHostCmd.noData")
|
||||
}
|
||||
|
||||
if len(infos) == len(infoIds) {
|
||||
if len(infos) == len(ids) {
|
||||
for _, v := range infos {
|
||||
// 主机信息删除
|
||||
if v.HostIDs != "" {
|
||||
NewNeHost.DeleteByIds(strings.Split(v.HostIDs, ","))
|
||||
hostIds := make([]int64, 0)
|
||||
arr := strings.Split(v.HostIDs, ",")
|
||||
for _, hostId := range arr {
|
||||
hostIds = append(hostIds, parse.Number(hostId))
|
||||
}
|
||||
r.neHostService.DeleteByIds(hostIds)
|
||||
}
|
||||
// 删除License
|
||||
neLicense := NewNeLicense.SelectByNeTypeAndNeID(v.NeType, v.NeId)
|
||||
neLicense := NewNeLicense.FindByNeTypeAndNeID(v.NeType, v.NeId)
|
||||
if neLicense.NeId == v.NeId {
|
||||
NewNeLicense.DeleteByIds([]string{neLicense.ID})
|
||||
NewNeLicense.DeleteByIds([]int64{neLicense.ID})
|
||||
}
|
||||
// 删除Version
|
||||
neVersion := NewNeVersion.SelectByNeTypeAndNeID(v.NeType, v.NeId)
|
||||
neVersion := NewNeVersion.FindByNeTypeAndNeID(v.NeType, v.NeId)
|
||||
if neVersion.NeId == v.NeId {
|
||||
NewNeVersion.DeleteByIds([]string{neVersion.ID})
|
||||
NewNeVersion.DeleteByIds([]int64{neVersion.ID})
|
||||
}
|
||||
// 缓存信息删除
|
||||
redis.Del("", fmt.Sprintf("%s%s:%s", cachekey.NE_KEY, v.NeType, v.NeId))
|
||||
redis.Del("", fmt.Sprintf("%s:%s:%s", constants.CACHE_NE_INFO, v.NeType, v.NeId))
|
||||
}
|
||||
rows := r.neInfoRepository.DeleteByIds(infoIds)
|
||||
rows := r.neInfoRepository.DeleteByIds(ids)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
@@ -324,7 +331,7 @@ func (r *NeInfo) DeleteByIds(infoIds []string) (int64, error) {
|
||||
}
|
||||
|
||||
// CheckUniqueNeTypeAndNeId 校验同类型下标识是否唯一
|
||||
func (r *NeInfo) CheckUniqueNeTypeAndNeId(neType, neId, id string) bool {
|
||||
func (r NeInfo) CheckUniqueNeTypeAndNeId(neType, neId string, id int64) bool {
|
||||
uniqueId := r.neInfoRepository.CheckUniqueNeTypeAndNeId(model.NeInfo{
|
||||
NeType: neType,
|
||||
NeId: neId,
|
||||
@@ -332,12 +339,12 @@ func (r *NeInfo) CheckUniqueNeTypeAndNeId(neType, neId, id string) bool {
|
||||
if uniqueId == id {
|
||||
return true
|
||||
}
|
||||
return uniqueId == ""
|
||||
return uniqueId == 0
|
||||
}
|
||||
|
||||
// NeRunSSHClient 网元主机的SSH客户端-为创建相关连接,注意结束后 Close()
|
||||
func (r *NeInfo) NeRunSSHClient(neType, neId string) (*ssh.ConnSSH, error) {
|
||||
neInfo := r.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||
func (r NeInfo) NeRunSSHClient(neType, neId string) (*ssh.ConnSSH, error) {
|
||||
neInfo := r.FindByNeTypeAndNeID(neType, neId)
|
||||
if neInfo.NeId != neId {
|
||||
logger.Errorf("NeRunSSHClient NeType:%s NeID:%s not found", neType, neId)
|
||||
return nil, fmt.Errorf("neinfo not found")
|
||||
@@ -352,9 +359,9 @@ func (r *NeInfo) NeRunSSHClient(neType, neId string) (*ssh.ConnSSH, error) {
|
||||
logger.Errorf("NeRunTelnetClient hosts id %s not found", neInfo.HostIDs)
|
||||
return nil, fmt.Errorf("neinfo host id not found")
|
||||
}
|
||||
hostId := hostIds[0] // 网元主机ssh 0:22
|
||||
neHost := NewNeHost.SelectById(hostId)
|
||||
if neHost.HostID == "" || neHost.HostID != hostId {
|
||||
hostId := parse.Number(hostIds[0]) // 网元主机ssh 0:22
|
||||
neHost := r.neHostService.FindById(hostId)
|
||||
if neHost.ID == 0 || neHost.ID != hostId {
|
||||
logger.Errorf("NeRunTelnetClient Hosts %s not found", neInfo.HostIDs)
|
||||
return nil, fmt.Errorf("neinfo host not found")
|
||||
}
|
||||
@@ -380,7 +387,7 @@ func (r *NeInfo) NeRunSSHClient(neType, neId string) (*ssh.ConnSSH, error) {
|
||||
}
|
||||
|
||||
// NeRunSSHCmd 网元主机的SSH客户端发送cmd命令
|
||||
func (r *NeInfo) NeRunSSHCmd(neType, neId, cmd string) (string, error) {
|
||||
func (r NeInfo) NeRunSSHCmd(neType, neId, cmd string) (string, error) {
|
||||
sshClient, err := r.NeRunSSHClient(neType, neId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -398,8 +405,8 @@ func (r *NeInfo) NeRunSSHCmd(neType, neId, cmd string) (string, error) {
|
||||
|
||||
// NeRunTelnetClient 网元主机的Telnet客户端-为创建相关连接,注意结束后 Close()
|
||||
// num 是网元主机telnet 1:4100 2:5200(UPF标准版)
|
||||
func (r *NeInfo) NeRunTelnetClient(neType, neId string, num int) (*telnet.ConnTelnet, error) {
|
||||
neInfo := r.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||
func (r NeInfo) NeRunTelnetClient(neType, neId string, num int) (*telnet.ConnTelnet, error) {
|
||||
neInfo := r.FindByNeTypeAndNeID(neType, neId)
|
||||
if neInfo.NeId != neId {
|
||||
logger.Errorf("NeRunTelnetClient NeType:%s NeID:%s not found", neType, neId)
|
||||
return nil, fmt.Errorf("neinfo not found")
|
||||
@@ -414,9 +421,9 @@ func (r *NeInfo) NeRunTelnetClient(neType, neId string, num int) (*telnet.ConnTe
|
||||
logger.Errorf("NeRunTelnetClient hosts id %s not found", neInfo.HostIDs)
|
||||
return nil, fmt.Errorf("neinfo host id not found")
|
||||
}
|
||||
hostId := hostIds[num] // 网元主机telnet 1:4100 2:5200
|
||||
neHost := NewNeHost.SelectById(hostId)
|
||||
if neHost.HostID == "" || neHost.HostID != hostId {
|
||||
hostId := parse.Number(hostIds[num]) // 网元主机telnet 1:4100 2:5200
|
||||
neHost := r.neHostService.FindById(hostId)
|
||||
if neHost.ID == 0 || neHost.ID != hostId {
|
||||
logger.Errorf("NeRunTelnetClient Hosts %s not found", neInfo.HostIDs)
|
||||
return nil, fmt.Errorf("neinfo host not found")
|
||||
}
|
||||
@@ -434,8 +441,8 @@ func (r *NeInfo) NeRunTelnetClient(neType, neId string, num int) (*telnet.ConnTe
|
||||
|
||||
// NeRunRedisClient 网元主机的Redis客户端-为创建相关连接,注意结束后 Close()
|
||||
// 暂时只有UDM有Redis配置项
|
||||
func (r *NeInfo) NeRunRedisClient(neType, neId string) (*redis.ConnRedis, error) {
|
||||
neInfo := r.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||
func (r NeInfo) NeRunRedisClient(neType, neId string) (*redis.ConnRedis, error) {
|
||||
neInfo := r.FindByNeTypeAndNeID(neType, neId)
|
||||
if neInfo.NeId != neId {
|
||||
logger.Errorf("NeRunRedisClient NeType:%s NeID:%s not found", neType, neId)
|
||||
return nil, fmt.Errorf("neinfo not found")
|
||||
@@ -450,9 +457,9 @@ func (r *NeInfo) NeRunRedisClient(neType, neId string) (*redis.ConnRedis, error)
|
||||
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 {
|
||||
hostId := parse.Number(hostIds[2])
|
||||
neHost := r.neHostService.FindById(hostId)
|
||||
if neHost.ID == 0 || neHost.ID != hostId {
|
||||
logger.Errorf("NeRunRedisClient Hosts %s not found", neInfo.HostIDs)
|
||||
return nil, fmt.Errorf("neinfo host not found")
|
||||
}
|
||||
@@ -469,7 +476,7 @@ func (r *NeInfo) NeRunRedisClient(neType, neId string) (*redis.ConnRedis, error)
|
||||
}
|
||||
|
||||
// NeConfOAMReadSync 网元OAM配置文件读取
|
||||
func (r *NeInfo) NeConfOAMReadSync(neType, neId string) (map[string]any, error) {
|
||||
func (r NeInfo) NeConfOAMReadSync(neType, neId string) (map[string]any, error) {
|
||||
oamData, err := r.neConfOAMRead(neType, neId, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -531,7 +538,7 @@ func (r *NeInfo) NeConfOAMReadSync(neType, neId string) (map[string]any, error)
|
||||
}
|
||||
|
||||
// neConfOAMData 网元OAM配置文件默认格式数据
|
||||
func (r *NeInfo) neConfOAMData() map[string]any {
|
||||
func (r NeInfo) neConfOAMData() map[string]any {
|
||||
return map[string]any{
|
||||
"httpManageCfg": map[string]any{
|
||||
"ipType": "ipv4",
|
||||
@@ -574,7 +581,7 @@ func (r *NeInfo) neConfOAMData() map[string]any {
|
||||
}
|
||||
|
||||
// neConfOAMRead 网元OAM配置文件读取 sync从网元端同步到本地
|
||||
func (r *NeInfo) neConfOAMRead(neType, neId string, sync bool) (map[string]any, error) {
|
||||
func (r NeInfo) neConfOAMRead(neType, neId string, sync bool) (map[string]any, error) {
|
||||
neTypeLower := strings.ToLower(neType)
|
||||
fileName := "oam_manager.yaml"
|
||||
// 网管本地路径
|
||||
@@ -629,7 +636,7 @@ func (r *NeInfo) neConfOAMRead(neType, neId string, sync bool) (map[string]any,
|
||||
}
|
||||
|
||||
// neConfOAMWirte 网元OAM配置文件写入 content内容 sync同步到网元端
|
||||
func (r *NeInfo) neConfOAMWirte(neType, neId string, content any, sync bool) error {
|
||||
func (r NeInfo) neConfOAMWirte(neType, neId string, content any, sync bool) error {
|
||||
neTypeLower := strings.ToLower(neType)
|
||||
fileName := "oam_manager.yaml"
|
||||
// 网管本地路径
|
||||
@@ -674,7 +681,7 @@ func (r *NeInfo) neConfOAMWirte(neType, neId string, content any, sync bool) err
|
||||
}
|
||||
|
||||
// NeConfOAMWirteSync 网元OAM配置文件生成并同步
|
||||
func (r *NeInfo) NeConfOAMWirteSync(neInfo model.NeInfo, content map[string]any, sync bool) error {
|
||||
func (r NeInfo) NeConfOAMWirteSync(neInfo model.NeInfo, content map[string]any, sync bool) error {
|
||||
oamData, err := r.neConfOAMRead(neInfo.NeType, neInfo.NeId, false)
|
||||
if oamData == nil || err != nil {
|
||||
return fmt.Errorf("error read OAM file info")
|
||||
@@ -782,7 +789,7 @@ func (r *NeInfo) NeConfOAMWirteSync(neInfo model.NeInfo, content map[string]any,
|
||||
}
|
||||
|
||||
// NeConfPara5GRead 网元公共配置文件读取
|
||||
func (r *NeInfo) NeConfPara5GRead() (map[string]any, error) {
|
||||
func (r NeInfo) NeConfPara5GRead() (map[string]any, error) {
|
||||
// 网管本地路径
|
||||
omcFilePath := "/usr/local/etc/omc/para5G.yaml"
|
||||
if runtime.GOOS == "windows" {
|
||||
@@ -806,7 +813,7 @@ func (r *NeInfo) NeConfPara5GRead() (map[string]any, error) {
|
||||
}
|
||||
|
||||
// NeConfPara5GWirte 网元公共配置文件写入 content内容 syncNE同步到网元端NeType@NeId
|
||||
func (r *NeInfo) NeConfPara5GWirte(content map[string]any, syncNE []string) error {
|
||||
func (r NeInfo) NeConfPara5GWirte(content map[string]any, syncNE []string) error {
|
||||
// 网管本地路径
|
||||
omcFilePath := "/usr/local/etc/omc/para5G.yaml"
|
||||
if runtime.GOOS == "windows" {
|
||||
@@ -859,7 +866,7 @@ func (r *NeInfo) NeConfPara5GWirte(content map[string]any, syncNE []string) erro
|
||||
}
|
||||
|
||||
// NeConfPara5GConvert 网元公共配置数据转化 content网元公共配置文件读取内容
|
||||
func (r *NeInfo) neConfPara5GDataConvert(content map[string]any) map[string]string {
|
||||
func (r NeInfo) neConfPara5GDataConvert(content map[string]any) map[string]string {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logger.Errorf("NeConfPara5GDataConvert panic: %v", err)
|
||||
|
||||
@@ -23,22 +23,22 @@ type NeLicense struct {
|
||||
neLicenseRepository *repository.NeLicense // 网元授权激活信息表
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeLicense) SelectPage(query map[string]any) map[string]any {
|
||||
return r.neLicenseRepository.SelectPage(query)
|
||||
// FindByPage 分页查询列表数据
|
||||
func (r *NeLicense) FindByPage(query map[string]string) ([]model.NeLicense, int64) {
|
||||
return r.neLicenseRepository.SelectByPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *NeLicense) SelectList(neLicense model.NeLicense) []model.NeLicense {
|
||||
return r.neLicenseRepository.SelectList(neLicense)
|
||||
// Find 查询列表
|
||||
func (r *NeLicense) Find(neLicense model.NeLicense) []model.NeLicense {
|
||||
return r.neLicenseRepository.Select(neLicense)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeLicense) SelectById(id string) model.NeLicense {
|
||||
if id == "" {
|
||||
// FindById 通过ID查询
|
||||
func (r *NeLicense) FindById(id int64) model.NeLicense {
|
||||
if id <= 0 {
|
||||
return model.NeLicense{}
|
||||
}
|
||||
neLicenses := r.neLicenseRepository.SelectByIds([]string{id})
|
||||
neLicenses := r.neLicenseRepository.SelectByIds([]int64{id})
|
||||
if len(neLicenses) > 0 {
|
||||
return neLicenses[0]
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func (r *NeLicense) SelectById(id string) model.NeLicense {
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeLicense) Insert(neLicense model.NeLicense) string {
|
||||
func (r *NeLicense) Insert(neLicense model.NeLicense) int64 {
|
||||
return r.neLicenseRepository.Insert(neLicense)
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ func (r *NeLicense) Update(neLicense model.NeLicense) int64 {
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeLicense) DeleteByIds(ids []string) (int64, error) {
|
||||
func (r *NeLicense) DeleteByIds(ids []int64) (int64, error) {
|
||||
// 检查是否存在
|
||||
rowIds := r.neLicenseRepository.SelectByIds(ids)
|
||||
if len(rowIds) <= 0 {
|
||||
@@ -71,9 +71,9 @@ func (r *NeLicense) DeleteByIds(ids []string) (int64, error) {
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// SelectByTypeAndID 通过网元类型和网元ID查询
|
||||
func (r *NeLicense) SelectByTypeAndID(neType, neId string) model.NeLicense {
|
||||
neLicenses := r.neLicenseRepository.SelectList(model.NeLicense{
|
||||
// FindByTypeAndID 通过网元类型和网元ID查询
|
||||
func (r *NeLicense) FindByTypeAndID(neType, neId string) model.NeLicense {
|
||||
neLicenses := r.neLicenseRepository.Select(model.NeLicense{
|
||||
NeType: neType,
|
||||
NeId: neId,
|
||||
})
|
||||
@@ -83,9 +83,9 @@ func (r *NeLicense) SelectByTypeAndID(neType, neId string) model.NeLicense {
|
||||
return model.NeLicense{}
|
||||
}
|
||||
|
||||
// SelectByNeTypeAndNeID 通过ne_type和ne_id查询信息
|
||||
func (r *NeLicense) SelectByNeTypeAndNeID(neType, neId string) model.NeLicense {
|
||||
neLicenses := r.neLicenseRepository.SelectList(model.NeLicense{
|
||||
// FindByNeTypeAndNeID 通过ne_type和ne_id查询信息
|
||||
func (r *NeLicense) FindByNeTypeAndNeID(neType, neId string) model.NeLicense {
|
||||
neLicenses := r.neLicenseRepository.Select(model.NeLicense{
|
||||
NeType: neType,
|
||||
NeId: neId,
|
||||
})
|
||||
@@ -142,7 +142,7 @@ func (r *NeLicense) ReadLicenseInfo(neLicense model.NeLicense) (string, string)
|
||||
// UploadLicense 授权文件上传到网元主机
|
||||
func (r *NeLicense) UploadLicense(neLicense model.NeLicense) error {
|
||||
// 检查文件是否存在
|
||||
omcLicensePath := file.ParseUploadFilePath(neLicense.LicensePath)
|
||||
omcLicensePath := file.ParseUploadFileAbsPath(neLicense.LicensePath)
|
||||
if _, err := os.Stat(omcLicensePath); err != nil {
|
||||
return fmt.Errorf("file read failure")
|
||||
}
|
||||
|
||||
@@ -12,29 +12,31 @@ import (
|
||||
// 实例化服务层 NeSoftware 结构体
|
||||
var NewNeSoftware = &NeSoftware{
|
||||
neSoftwareRepository: repository.NewNeSoftware,
|
||||
neVersionService: NewNeVersion,
|
||||
}
|
||||
|
||||
// NeSoftware 网元软件包信息 服务层处理
|
||||
type NeSoftware struct {
|
||||
neSoftwareRepository *repository.NeSoftware // 网元软件包信息
|
||||
neVersionService *NeVersion // 网元版本信息服务
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeSoftware) SelectPage(query map[string]any) map[string]any {
|
||||
return r.neSoftwareRepository.SelectPage(query)
|
||||
// FindByPage 分页查询列表数据
|
||||
func (r NeSoftware) FindByPage(query map[string]string) ([]model.NeSoftware, int64) {
|
||||
return r.neSoftwareRepository.SelectByPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *NeSoftware) SelectList(neSoftware model.NeSoftware) []model.NeSoftware {
|
||||
return r.neSoftwareRepository.SelectList(neSoftware)
|
||||
// Find 查询列表
|
||||
func (r NeSoftware) Find(neSoftware model.NeSoftware) []model.NeSoftware {
|
||||
return r.neSoftwareRepository.Select(neSoftware)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeSoftware) SelectById(id string) model.NeSoftware {
|
||||
if id == "" {
|
||||
// FindById 通过ID查询
|
||||
func (r NeSoftware) FindById(id int64) model.NeSoftware {
|
||||
if id <= 0 {
|
||||
return model.NeSoftware{}
|
||||
}
|
||||
neHosts := r.neSoftwareRepository.SelectByIds([]string{id})
|
||||
neHosts := r.neSoftwareRepository.SelectByIds([]int64{id})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
}
|
||||
@@ -42,11 +44,11 @@ func (r *NeSoftware) SelectById(id string) model.NeSoftware {
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeSoftware) Insert(neSoftware model.NeSoftware) string {
|
||||
func (r NeSoftware) Insert(neSoftware model.NeSoftware) int64 {
|
||||
inserId := r.neSoftwareRepository.Insert(neSoftware)
|
||||
if inserId != "" {
|
||||
if inserId > 0 {
|
||||
// 更新同类型的新包版本
|
||||
neVersions := NewNeVersion.SelectList(model.NeVersion{NeType: neSoftware.NeType}, false)
|
||||
neVersions := r.neVersionService.Find(model.NeVersion{NeType: neSoftware.NeType}, false)
|
||||
if len(neVersions) > 0 {
|
||||
for _, neVersion := range neVersions {
|
||||
neVersion.NewName = neSoftware.Name
|
||||
@@ -54,7 +56,7 @@ func (r *NeSoftware) Insert(neSoftware model.NeSoftware) string {
|
||||
neVersion.NewPath = neSoftware.Path
|
||||
neVersion.Status = "3"
|
||||
neVersion.UpdateBy = neSoftware.CreateBy
|
||||
NewNeVersion.Update(neVersion)
|
||||
r.neVersionService.Update(neVersion)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,11 +64,11 @@ func (r *NeSoftware) Insert(neSoftware model.NeSoftware) string {
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeSoftware) Update(neSoftware model.NeSoftware) int64 {
|
||||
func (r NeSoftware) Update(neSoftware model.NeSoftware) int64 {
|
||||
rows := r.neSoftwareRepository.Update(neSoftware)
|
||||
if rows > 0 {
|
||||
// 更新同类型的新包版本
|
||||
neVersions := NewNeVersion.SelectList(model.NeVersion{
|
||||
neVersions := r.neVersionService.Find(model.NeVersion{
|
||||
NeType: neSoftware.NeType,
|
||||
Status: "3",
|
||||
}, false)
|
||||
@@ -77,7 +79,7 @@ func (r *NeSoftware) Update(neSoftware model.NeSoftware) int64 {
|
||||
neVersion.NewPath = neSoftware.Path
|
||||
neVersion.Status = "3"
|
||||
neVersion.UpdateBy = neSoftware.UpdateBy
|
||||
NewNeVersion.Update(neVersion)
|
||||
r.neVersionService.Update(neVersion)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,7 +87,7 @@ func (r *NeSoftware) Update(neSoftware model.NeSoftware) int64 {
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeSoftware) DeleteByIds(ids []string) (int64, error) {
|
||||
func (r NeSoftware) DeleteByIds(ids []int64) (int64, error) {
|
||||
// 检查是否存在
|
||||
rows := r.neSoftwareRepository.SelectByIds(ids)
|
||||
if len(rows) <= 0 {
|
||||
@@ -96,7 +98,7 @@ func (r *NeSoftware) DeleteByIds(ids []string) (int64, error) {
|
||||
// 遍历软件包列表进行文件删除
|
||||
for _, row := range rows {
|
||||
// 检查文件是否存在
|
||||
filePath := file.ParseUploadFilePath(row.Path)
|
||||
filePath := file.ParseUploadFileAbsPath(row.Path)
|
||||
if _, err := os.Stat(filePath); err != nil {
|
||||
continue
|
||||
}
|
||||
@@ -111,8 +113,8 @@ func (r *NeSoftware) DeleteByIds(ids []string) (int64, error) {
|
||||
}
|
||||
|
||||
// CheckUniqueTypeAndNameAndVersion 校验网元类型和文件名版本是否唯一
|
||||
func (r *NeSoftware) CheckUniqueTypeAndNameAndVersion(neType, name, version, id string) bool {
|
||||
uniqueId := r.neSoftwareRepository.CheckUniqueTypeAndNameAndVersion(model.NeSoftware{
|
||||
func (r NeSoftware) CheckUniqueTypeAndNameAndVersion(neType, name, version string, id int64) bool {
|
||||
uniqueId := r.neSoftwareRepository.CheckUnique(model.NeSoftware{
|
||||
NeType: neType,
|
||||
Name: name,
|
||||
Version: version,
|
||||
@@ -120,14 +122,14 @@ func (r *NeSoftware) CheckUniqueTypeAndNameAndVersion(neType, name, version, id
|
||||
if uniqueId == id {
|
||||
return true
|
||||
}
|
||||
return uniqueId == ""
|
||||
return uniqueId == 0
|
||||
}
|
||||
|
||||
// UpdateVersions 更新软件包对应网元的新版本
|
||||
func (r *NeSoftware) UpdateVersions(neSoftware model.NeSoftware, neVersion model.NeVersion) int64 {
|
||||
func (r NeSoftware) UpdateVersions(neSoftware model.NeSoftware, neVersion model.NeVersion) int64 {
|
||||
var rows int64 = 0
|
||||
// 更新同类型的新包版本
|
||||
neVersions := NewNeVersion.SelectList(neVersion, false)
|
||||
neVersions := r.neVersionService.Find(neVersion, false)
|
||||
if len(neVersions) > 0 {
|
||||
for _, v := range neVersions {
|
||||
v.NewName = neSoftware.Name
|
||||
@@ -135,7 +137,7 @@ func (r *NeSoftware) UpdateVersions(neSoftware model.NeSoftware, neVersion model
|
||||
v.NewPath = neSoftware.Path
|
||||
v.Status = "3"
|
||||
v.UpdateBy = neVersion.UpdateBy
|
||||
rows += NewNeVersion.Update(v)
|
||||
rows += r.neVersionService.Update(v)
|
||||
}
|
||||
}
|
||||
return rows
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/ssh"
|
||||
"be.ems/src/framework/utils/file"
|
||||
"be.ems/src/framework/utils/ssh"
|
||||
neFetchlink "be.ems/src/modules/network_element/fetch_link"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/repository"
|
||||
@@ -17,29 +17,30 @@ import (
|
||||
// 实例化服务层 NeVersion 结构体
|
||||
var NewNeVersion = &NeVersion{
|
||||
neVersionRepository: repository.NewNeVersion,
|
||||
neInfoService: NewNeInfo,
|
||||
}
|
||||
|
||||
// NeVersion 网元版本信息 服务层处理
|
||||
type NeVersion struct {
|
||||
neVersionRepository *repository.NeVersion // 网元版本信息表
|
||||
neInfoService *NeInfo // 网元信息数据信息
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeVersion) SelectPage(query map[string]any, checkVersion bool) map[string]any {
|
||||
data := r.neVersionRepository.SelectPage(query)
|
||||
// FindByPage 分页查询列表数据
|
||||
func (r NeVersion) FindByPage(query map[string]string, checkVersion bool) ([]model.NeVersion, int64) {
|
||||
rows, total := r.neVersionRepository.SelectByPage(query)
|
||||
|
||||
// 网元直连检查更新网元服务版本
|
||||
if checkVersion {
|
||||
rows := data["rows"].([]model.NeVersion)
|
||||
r.checkNeVersion(&rows)
|
||||
}
|
||||
|
||||
return data
|
||||
return rows, total
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *NeVersion) SelectList(neVersion model.NeVersion, checkVersion bool) []model.NeVersion {
|
||||
list := r.neVersionRepository.SelectList(neVersion)
|
||||
// Find 查询列表
|
||||
func (r NeVersion) Find(neVersion model.NeVersion, checkVersion bool) []model.NeVersion {
|
||||
list := r.neVersionRepository.Select(neVersion)
|
||||
|
||||
// 网元直连检查更新网元服务版本
|
||||
if checkVersion {
|
||||
@@ -50,11 +51,11 @@ func (r *NeVersion) SelectList(neVersion model.NeVersion, checkVersion bool) []m
|
||||
}
|
||||
|
||||
// checkNeVersion 网元列表检查更新网元版本
|
||||
func (r *NeVersion) checkNeVersion(arr *[]model.NeVersion) {
|
||||
func (r NeVersion) checkNeVersion(arr *[]model.NeVersion) {
|
||||
for i := range *arr {
|
||||
item := (*arr)[i]
|
||||
// 查询网元获取IP
|
||||
neInfo := NewNeInfo.SelectNeInfoByNeTypeAndNeID(item.NeType, item.NeId)
|
||||
neInfo := r.neInfoService.FindByNeTypeAndNeID(item.NeType, item.NeId)
|
||||
if neInfo.NeId != item.NeId || neInfo.IP == "" {
|
||||
continue
|
||||
}
|
||||
@@ -80,12 +81,12 @@ func (r *NeVersion) checkNeVersion(arr *[]model.NeVersion) {
|
||||
}
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeVersion) SelectById(id string) model.NeVersion {
|
||||
if id == "" {
|
||||
// FindById 通过ID查询
|
||||
func (r NeVersion) FindById(id int64) model.NeVersion {
|
||||
if id <= 0 {
|
||||
return model.NeVersion{}
|
||||
}
|
||||
neVersions := r.neVersionRepository.SelectByIds([]string{id})
|
||||
neVersions := r.neVersionRepository.SelectByIds([]int64{id})
|
||||
if len(neVersions) > 0 {
|
||||
return neVersions[0]
|
||||
}
|
||||
@@ -93,17 +94,17 @@ func (r *NeVersion) SelectById(id string) model.NeVersion {
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeVersion) Insert(neVersion model.NeVersion) string {
|
||||
func (r NeVersion) Insert(neVersion model.NeVersion) int64 {
|
||||
return r.neVersionRepository.Insert(neVersion)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeVersion) Update(neVersion model.NeVersion) int64 {
|
||||
func (r NeVersion) Update(neVersion model.NeVersion) int64 {
|
||||
return r.neVersionRepository.Update(neVersion)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeVersion) DeleteByIds(ids []string) (int64, error) {
|
||||
func (r NeVersion) DeleteByIds(ids []int64) (int64, error) {
|
||||
// 检查是否存在
|
||||
rowIds := r.neVersionRepository.SelectByIds(ids)
|
||||
if len(rowIds) <= 0 {
|
||||
@@ -118,9 +119,9 @@ func (r *NeVersion) DeleteByIds(ids []string) (int64, error) {
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// SelectByNeTypeAndNeID 通过网元类型和网元ID查询
|
||||
func (r *NeVersion) SelectByNeTypeAndNeID(neType, neId string) model.NeVersion {
|
||||
neVersions := r.neVersionRepository.SelectList(model.NeVersion{
|
||||
// FindByNeTypeAndNeID 通过网元类型和网元ID查询
|
||||
func (r NeVersion) FindByNeTypeAndNeID(neType, neId string) model.NeVersion {
|
||||
neVersions := r.neVersionRepository.Select(model.NeVersion{
|
||||
NeType: neType,
|
||||
NeId: neId,
|
||||
})
|
||||
@@ -133,9 +134,9 @@ func (r *NeVersion) SelectByNeTypeAndNeID(neType, neId string) model.NeVersion {
|
||||
// Operate 操作版本上传到网元主机执行命令
|
||||
//
|
||||
// action 安装行为:install upgrade rollback
|
||||
func (r *NeVersion) Operate(action string, neVersion model.NeVersion, preinput map[string]string) (string, error) {
|
||||
func (r NeVersion) Operate(action string, neVersion model.NeVersion, preinput map[string]string) (string, error) {
|
||||
// 网元主机的SSH客户端
|
||||
sshClient, err := NewNeInfo.NeRunSSHClient(neVersion.NeType, neVersion.NeId)
|
||||
sshClient, err := r.neInfoService.NeRunSSHClient(neVersion.NeType, neVersion.NeId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -157,11 +158,11 @@ func (r *NeVersion) Operate(action string, neVersion model.NeVersion, preinput m
|
||||
// ========= 安装时设置 =========
|
||||
if action == "install" {
|
||||
// 网元公共配置文件
|
||||
para5GMap, err := NewNeInfo.NeConfPara5GRead()
|
||||
para5GMap, err := r.neInfoService.NeConfPara5GRead()
|
||||
if para5GMap == nil || err != nil {
|
||||
return "", fmt.Errorf("error read para5G file info")
|
||||
}
|
||||
if err := NewNeInfo.NeConfPara5GWirte(para5GMap, []string{fmt.Sprintf("%s@%s", neVersion.NeType, neVersion.NeId)}); err != nil {
|
||||
if err := r.neInfoService.NeConfPara5GWirte(para5GMap, []string{fmt.Sprintf("%s@%s", neVersion.NeType, neVersion.NeId)}); err != nil {
|
||||
return "", fmt.Errorf("error wirte para5G file info")
|
||||
}
|
||||
}
|
||||
@@ -188,7 +189,7 @@ func (r *NeVersion) Operate(action string, neVersion model.NeVersion, preinput m
|
||||
}
|
||||
|
||||
// operateFile 操作版本-文件传输阶段
|
||||
func (r *NeVersion) operateFile(sshClient *ssh.ConnSSH, softwarePath string) ([]string, error) {
|
||||
func (r NeVersion) operateFile(sshClient *ssh.ConnSSH, softwarePath string) ([]string, error) {
|
||||
// 网元主机的SSH客户端进行文件传输
|
||||
sftpClient, err := sshClient.NewClientSFTP()
|
||||
if err != nil {
|
||||
@@ -209,7 +210,7 @@ func (r *NeVersion) operateFile(sshClient *ssh.ConnSSH, softwarePath string) ([]
|
||||
|
||||
for _, path := range softwarePaths {
|
||||
// 检查文件是否存在
|
||||
localFilePath := file.ParseUploadFilePath(path)
|
||||
localFilePath := file.ParseUploadFileAbsPath(path)
|
||||
if _, err := os.Stat(localFilePath); err != nil {
|
||||
return nil, fmt.Errorf("file read failure")
|
||||
}
|
||||
@@ -231,7 +232,7 @@ func (r *NeVersion) operateFile(sshClient *ssh.ConnSSH, softwarePath string) ([]
|
||||
}
|
||||
|
||||
// operateCommand 操作版本-命令生成阶段
|
||||
func (r *NeVersion) operateCommand(action, neType string, neFilePaths []string) (string, []string, error) {
|
||||
func (r NeVersion) operateCommand(action, neType string, neFilePaths []string) (string, []string, error) {
|
||||
neTypeLower := strings.ToLower(neType)
|
||||
// 命令终止结束标记
|
||||
okFlagStr := fmt.Sprintf("%s version %s successful!", neTypeLower, action)
|
||||
@@ -271,7 +272,7 @@ func (r *NeVersion) operateCommand(action, neType string, neFilePaths []string)
|
||||
return okFlagStr, cmdStrArr, nil
|
||||
} else if neType == "IMS" {
|
||||
if action == "install" {
|
||||
para5GData := NewNeInfo.Para5GData
|
||||
para5GData := r.neInfoService.Para5GData
|
||||
cmdStrArr = append(cmdStrArr, pkgCmdStr+" \n")
|
||||
|
||||
// 公网 PLMN地址
|
||||
@@ -313,7 +314,7 @@ func (r *NeVersion) operateCommand(action, neType string, neFilePaths []string)
|
||||
}
|
||||
} else {
|
||||
if action == "install" {
|
||||
para5GData := NewNeInfo.Para5GData
|
||||
para5GData := r.neInfoService.Para5GData
|
||||
cmdStrArr = append(cmdStrArr, pkgCmdStr+" \n")
|
||||
|
||||
// AMF配置修改
|
||||
@@ -560,14 +561,14 @@ func (r *NeVersion) operateCommand(action, neType string, neFilePaths []string)
|
||||
if action == "install" && (neTypeLower == "ims" || neTypeLower == "udm") {
|
||||
// adb
|
||||
if strings.Contains(pkgCmdStr, "adb") {
|
||||
para5GData := NewNeInfo.Para5GData
|
||||
para5GData := r.neInfoService.Para5GData
|
||||
cmdStrArr = append(cmdStrArr, "sudo cp /usr/local/etc/adb/default/adb.conf /usr/local/etc/adb/adb.conf \n")
|
||||
cmdStrArr = append(cmdStrArr, fmt.Sprintf("sudo sed -i \"s/bind 127.0.0.1/bind %s/g\" /usr/local/etc/adb/adb.conf \n", para5GData["DB_IP"]))
|
||||
cmdStrArr = append(cmdStrArr, "sudo service adb restart \n")
|
||||
}
|
||||
// kvdb
|
||||
if strings.Contains(pkgCmdStr, "kvdb") {
|
||||
para5GData := NewNeInfo.Para5GData
|
||||
para5GData := r.neInfoService.Para5GData
|
||||
cmdStrArr = append(cmdStrArr, "sudo cp /usr/local/etc/kvdb/default/kvdb.conf /usr/local/etc/kvdb/kvdb.conf \n")
|
||||
cmdStrArr = append(cmdStrArr, fmt.Sprintf("sudo sed -i \"s/bind 127.0.0.1/bind %s/g\" /usr/local/etc/kvdb/kvdb.conf \n", para5GData["DB_IP"]))
|
||||
cmdStrArr = append(cmdStrArr, "sudo service kvdb restart \n")
|
||||
@@ -583,7 +584,7 @@ func (r *NeVersion) operateCommand(action, neType string, neFilePaths []string)
|
||||
}
|
||||
|
||||
// operateRun 操作版本-执行阶段
|
||||
func (r *NeVersion) operateRun(sshClient *ssh.ConnSSH, preinput map[string]string, cmdStrArr []string, neType string, okFlagStr string) (string, error) {
|
||||
func (r NeVersion) operateRun(sshClient *ssh.ConnSSH, preinput map[string]string, cmdStrArr []string, neType string, okFlagStr string) (string, error) {
|
||||
// ssh连接会话
|
||||
clientSession, err := sshClient.NewClientSession(127, 42)
|
||||
if err != nil {
|
||||
@@ -673,23 +674,23 @@ func (r *NeVersion) operateRun(sshClient *ssh.ConnSSH, preinput map[string]strin
|
||||
}
|
||||
|
||||
// operateDome 操作版本-完成阶段
|
||||
func (r *NeVersion) operateDome(action string, neVersion model.NeVersion) error {
|
||||
func (r NeVersion) operateDome(action string, neVersion model.NeVersion) error {
|
||||
if action == "install" {
|
||||
// 网元信息
|
||||
neInfo := NewNeInfo.SelectNeInfoByNeTypeAndNeID(neVersion.NeType, neVersion.NeId)
|
||||
neInfo := r.neInfoService.FindByNeTypeAndNeID(neVersion.NeType, neVersion.NeId)
|
||||
if neInfo.NeId != neVersion.NeId {
|
||||
return fmt.Errorf("error found neinfo")
|
||||
}
|
||||
|
||||
// ========= 网元OAM配置文件 start ==========
|
||||
if err := NewNeInfo.NeConfOAMWirteSync(neInfo, nil, true); err != nil {
|
||||
if err := r.neInfoService.NeConfOAMWirteSync(neInfo, nil, true); err != nil {
|
||||
return fmt.Errorf("error wirte OAM file info")
|
||||
}
|
||||
// ========= 网元OAM配置文件 end ===========
|
||||
|
||||
// SMSC配置修改 IMS/UDM 配置
|
||||
if neInfo.NeType == "SMSC" {
|
||||
para5GData := NewNeInfo.Para5GData
|
||||
para5GData := r.neInfoService.Para5GData
|
||||
mnc_mcc := fmt.Sprintf("mnc%s.mcc%s", para5GData["MNC_DOMAIN"], para5GData["MCC"])
|
||||
smscHost := fmt.Sprintf("%s smsc.ims.%s.3gppnetwork.org", para5GData["SMSC_IP"], mnc_mcc)
|
||||
smscHostCMD := fmt.Sprintf("grep -qxF '%s' /etc/hosts || echo '%s' | sudo tee -a /etc/hosts \n", smscHost, smscHost)
|
||||
@@ -697,30 +698,30 @@ func (r *NeVersion) operateDome(action string, neVersion model.NeVersion) error
|
||||
smsHost := fmt.Sprintf("sudo sed -i '/^%s smsc.*smsc$/c\\' /etc/hosts", para5GData["SIP_IP"])
|
||||
|
||||
// IMS 配置
|
||||
imsNEs := NewNeInfo.SelectList(model.NeInfo{NeType: "IMS"}, false, false)
|
||||
imsNEs := r.neInfoService.Find(model.NeInfo{NeType: "IMS"}, false, false)
|
||||
for _, v := range imsNEs {
|
||||
NewNeInfo.NeRunSSHCmd(v.NeType, v.NeId, smscIPCMD)
|
||||
NewNeInfo.NeRunSSHCmd(v.NeType, v.NeId, smscHostCMD)
|
||||
NewNeInfo.NeRunSSHCmd(v.NeType, v.NeId, smsHost)
|
||||
NewNeInfo.NeRunSSHCmd(v.NeType, v.NeId, "sudo sed -i '/^#!define WITH_SMS/ s/^/#/' /usr/local/etc/ims/vars.cfg")
|
||||
NewNeInfo.NeRunSSHCmd(v.NeType, v.NeId, "ims-stop || true && ims-start")
|
||||
r.neInfoService.NeRunSSHCmd(v.NeType, v.NeId, smscIPCMD)
|
||||
r.neInfoService.NeRunSSHCmd(v.NeType, v.NeId, smscHostCMD)
|
||||
r.neInfoService.NeRunSSHCmd(v.NeType, v.NeId, smsHost)
|
||||
r.neInfoService.NeRunSSHCmd(v.NeType, v.NeId, "sudo sed -i '/^#!define WITH_SMS/ s/^/#/' /usr/local/etc/ims/vars.cfg")
|
||||
r.neInfoService.NeRunSSHCmd(v.NeType, v.NeId, "ims-stop || true && ims-start")
|
||||
}
|
||||
// UDM 配置
|
||||
smscASName := fmt.Sprintf("sudo sed -i \"/- name: 'sms_as'/{n;s|serverName: .*|serverName: 'sip:%s:5060'|}\" /usr/local/etc/udm/as.yaml", para5GData["SMSC_IP"])
|
||||
smscASAddress := fmt.Sprintf("sudo sed -i \"/- name: 'sms_as'/{n;n;n;s|diameterAddress: .*|diameterAddress: 'smsc.ims.%s.3gppnetwork.org'|}\" /usr/local/etc/udm/as.yaml", mnc_mcc)
|
||||
udmNEs := NewNeInfo.SelectList(model.NeInfo{NeType: "UDM"}, false, false)
|
||||
udmNEs := r.neInfoService.Find(model.NeInfo{NeType: "UDM"}, false, false)
|
||||
for _, v := range udmNEs {
|
||||
NewNeInfo.NeRunSSHCmd(v.NeType, v.NeId, smscIPCMD)
|
||||
NewNeInfo.NeRunSSHCmd(v.NeType, v.NeId, smscHostCMD)
|
||||
NewNeInfo.NeRunSSHCmd(v.NeType, v.NeId, smscASName)
|
||||
NewNeInfo.NeRunSSHCmd(v.NeType, v.NeId, smscASAddress)
|
||||
NewNeInfo.NeRunSSHCmd(v.NeType, v.NeId, "sudo service udm restart")
|
||||
r.neInfoService.NeRunSSHCmd(v.NeType, v.NeId, smscIPCMD)
|
||||
r.neInfoService.NeRunSSHCmd(v.NeType, v.NeId, smscHostCMD)
|
||||
r.neInfoService.NeRunSSHCmd(v.NeType, v.NeId, smscASName)
|
||||
r.neInfoService.NeRunSSHCmd(v.NeType, v.NeId, smscASAddress)
|
||||
r.neInfoService.NeRunSSHCmd(v.NeType, v.NeId, "sudo service udm restart")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新Version
|
||||
verInfo := r.SelectByNeTypeAndNeID(neVersion.NeType, neVersion.NeId)
|
||||
verInfo := r.FindByNeTypeAndNeID(neVersion.NeType, neVersion.NeId)
|
||||
if verInfo.NeId == neVersion.NeId {
|
||||
curName := verInfo.Name
|
||||
curVersion := verInfo.Version
|
||||
|
||||
Reference in New Issue
Block a user