feat: support nbi cm task

This commit is contained in:
zhangsz
2025-04-25 10:44:24 +08:00
parent 8705ac68c1
commit d973c8af49
11 changed files with 717 additions and 1 deletions

View File

@@ -0,0 +1,57 @@
package amf
type ManagedElement struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
VendorName string `json:"vendorName"`
ManagedBy string `json:"managedBy"`
ManagementIpAddress string `json:"managementIpAddress"`
SwVersion string `json:"swVersion"`
PatchInfo string `json:"patchInfo"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
}
type AmfFunction struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
VnfInstanceId string `json:"vnfInstanceId"`
Fqdn string `json:"fqdn"`
SbiServiceList string `json:"sbiServiceList"`
AmfGuamiList string `json:"amfGuamiList"`
SnssaiList string `json:"snssaiList"`
MaxUser int `json:"maxUser"`
RelativeCapacity int `json:"relativeCapacity"`
MaxGnbNum int `json:"maxGnbNum"`
}
type EpRpDynN8Amf struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
LocIpAddrList string `json:"locIpAddrList"`
FarIpSubnetworkList string `json:"farIpSubnetworkList"`
}
type EpRpDynN11Amf struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
LocIpAddrList string `json:"locIpAddrList"`
FarIpSubnetworkList string `json:"farIpSubnetworkList"`
}
type EpRpDynN12Amf struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
LocIpAddrList string `json:"locIpAddrList"`
FarIpSubnetworkList string `json:"farIpSubnetworkList"`
}
type IPResource struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
InterfaceType string `json:"interfaceType"`
LocIpV4AddrList string `json:"locIpV4AddrList"`
LocIpV6AddrList string `json:"locIpV6AddrList"`
}

View File

@@ -0,0 +1,125 @@
package nbiNRM
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"be.ems/lib/log"
"be.ems/src/framework/cron"
)
const (
// NBI CM表名
NbiCmTableName = "nbi_cm"
CmVersion = "v1" // CM版本
)
type EventType int
const (
ObjectCreationEvent EventType = iota // ObjectCreationEvent 创建事件
ObjectDeletionEvent // ObjectDeletionEvent 删除事件
ObjectAttributeValueChangeEvent // ObjectAttributeValueChangeEvent 修改事件
ObjectUnkownEvent // 未知事件
)
func (et EventType) EventTypeEnumString() string {
switch et {
case ObjectCreationEvent:
return "ObjectCreationEvent"
case ObjectDeletionEvent:
return "ObjectDeletionEvent"
case ObjectAttributeValueChangeEvent:
return "ObjectAttributeValueChangeEvent"
default:
return "ObjectUnkownEvent"
}
}
func (et EventType) EventTypeIntString() string {
return fmt.Sprintf("%d", et)
}
// ParseCallTag 将字符串转换为 CallTag 枚举类型
func EventTypeInt(s string) EventType {
if i, err := strconv.Atoi(s); err == nil {
return EventType(i)
}
// 如果转换失败,则按名称匹配(忽略大小写)
switch strings.ToLower(s) {
case "ObjectCreationEvent":
return ObjectCreationEvent
case "ObjectDeletionEvent":
return ObjectDeletionEvent
case "ObjectAttributeValueChangeEvent":
return ObjectAttributeValueChangeEvent
case "":
// 如果字符串为空,则返回未知事件
return ObjectUnkownEvent
default:
return ObjectUnkownEvent
}
}
// NbiCm 表结构
type NbiCm struct {
Id string `json:"id" db:"id PRIMARY KEY"`
NeType string `json:"neType" db:"ne_type"`
NeId string `json:"neId" db:"ne_id"`
CmVersion string `json:"cmVersion" db:"cm_version"`
RmUid string `json:"rmUid" db:"rm_uid"`
EventType EventType `json:"eventType" db:"event_type"`
ObjectType string `json:"objectType" db:"object_type"`
ValueJson string `json:"valueJson" db:"value_json"`
Timestamp string `json:"timestamp" db:"timestamp"`
}
var NewProcessor = &BarProcessor{
progress: 0,
count: 0,
}
// bar 队列任务处理
type BarProcessor struct {
// 任务进度
progress int
// 执行次数
count int
}
type BarParams struct {
Duration int `json:"duration"`
TableName string `json:"tableName"`
Columns string `json:"columns"` // exported column name of time string
TimeCol string `json:"timeCol"` // time stamp of column name
TimeUnit string `json:"timeUnit"` // timestamp unit: second/micro/milli
Extras string `json:"extras"` // extras condition for where
FilePath string `json:"filePath"` // file path
}
func (s *BarProcessor) Execute(data any) (any, error) {
s.count++
options := data.(cron.JobData)
sysJob := options.SysJob
var params BarParams
err := json.Unmarshal([]byte(sysJob.TargetParams), &params)
if err != nil {
return nil, err
}
err = s.SyncAmfNbiCM()
if err != nil {
log.Errorf("SyncAmfNbiCM error: %v", err)
return nil, err
}
// 返回结果,用于记录执行结果
return map[string]any{
"msg": "sucess",
"affected": 1,
}, nil
}

View File

@@ -0,0 +1,39 @@
package pcf
type ManagedElement struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
VendorName string `json:"vendorName"`
ManagedBy string `json:"managedBy"`
ManagementIpAddress string `json:"managementIpAddress"`
SwVersion string `json:"swVersion"`
PatchInfo string `json:"patchInfo"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
}
type PcfFunction struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
VnfInstanceId string `json:"vnfInstanceId"`
Fqdn string `json:"fqdn"`
SbiServiceList string `json:"sbiServiceList"`
}
type UdrFunction struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
MaxSubNbr int `json:"maxSubNbr"`
}
type IPResource struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
InterfaceType string `json:"interfaceType"`
LocIpV4AddrList string `json:"locIpV4AddrList"`
LocIpV6AddrList string `json:"locIpV6AddrList"`
}

View File

@@ -0,0 +1,55 @@
package smf
type ManagedElement struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
VendorName string `json:"vendorName"`
ManagedBy string `json:"managedBy"`
ManagementIpAddress string `json:"managementIpAddress"`
SwVersion string `json:"swVersion"`
PatchInfo string `json:"patchInfo"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
}
type SmfFunction struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
VnfInstanceId string `json:"vnfInstanceId"`
Fqdn string `json:"fqdn"`
SbiServiceList string `json:"sbiServiceList"`
MaxPduSessions int `json:"maxPduSessions"`
MaxQfi int `json:"maxQfi"`
UpfList string `json:"upfList"`
}
type AddrPool struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
AddrType string `json:"addrType"`
IpVersion string `json:"ipVersion"`
AddrSegList string `json:"addrSegList"`
}
type EpRpDynN7Smf struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
LocIpAddrList string `json:"locIpAddrList"`
FarIpSubnetworkList string `json:"farIpSubnetworkList"`
}
type EpRpDynN10Smf struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
LocIpAddrList string `json:"locIpAddrList"`
FarIpSubnetworkList string `json:"farIpSubnetworkList"`
}
type IPResource struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
InterfaceType string `json:"interfaceType"`
LocIpV4AddrList string `json:"locIpV4AddrList"`
LocIpV6AddrList string `json:"locIpV6AddrList"`
}

View File

@@ -0,0 +1,136 @@
package nbiNRM
import (
"encoding/json"
"fmt"
"time"
"be.ems/lib/dborm"
"be.ems/lib/log"
"be.ems/src/modules/crontask/processor/nbiNRM/amf"
)
// SyncAmfNbiCM 从ne_info获取AMF网元并同步数据到nbi_cm表
func (s *BarProcessor) SyncAmfNbiCM() error {
log.Info("Starting AMF NBI CM synchronization")
// 从ne_info表获取AMF类型的网元
var amfNEs []struct {
NeID string `db:"ne_id"`
NeType string `db:"ne_type"`
RmUid string `db:"rm_uid"`
}
err := dborm.DefaultDB().Table("ne_info").
Where("ne_type = ? AND status = 1", "AMF").
Find(&amfNEs).Error
if err != nil {
log.Errorf("Failed to query AMF network elements: %v", err)
return err
}
log.Infof("Found %d AMF network elements", len(amfNEs))
// 当前时间戳
now := time.Now()
timestamp := now.Unix()
// 遍历每个AMF网元生成对应的NBI CM记录
for _, ne := range amfNEs {
// 为每个网元生成ManagedElement记录
managedElement := amf.ManagedElement{
Id: "ManagedElement=" + ne.NeID,
UserLabel: "AMF-" + ne.NeID,
VendorName: "Vendor",
ManagedBy: "OMC",
ManagementIpAddress: "", // 可以从其他表获取IP地址
SwVersion: "", // 可以从其他表获取软件版本
AdministrativeState: "UNLOCKED",
OperationalState: "ENABLED",
}
// 序列化为JSON
meJSON, err := json.Marshal(managedElement)
if err != nil {
log.Errorf("Failed to marshal ManagedElement for ne_id %s: %v", ne.NeID, err)
continue
}
// 生成唯一ID
meID := fmt.Sprintf("nbi-cm-%s-me-%d", ne.NeID, timestamp)
// 插入ManagedElement记录
nbiCM := NbiCm{
Id: meID,
NeType: ne.NeType,
NeId: ne.NeID,
CmVersion: CmVersion,
RmUid: ne.RmUid,
EventType: EventTypeInt("ObjectCreationEvent"),
ObjectType: "ManagedElement",
ValueJson: string(meJSON),
Timestamp: fmt.Sprintf("%d", timestamp),
}
// 插入到数据库
err = dborm.DefaultDB().Table("nbi_cm").Create(&nbiCM).Error
if err != nil {
log.Errorf("Failed to insert ManagedElement record: %v", err)
continue
}
// 为每个网元生成AmfFunction记录
amfFunction := amf.AmfFunction{
Id: "ManagedElement=" + ne.NeID + ",AmfFunction=1",
UserLabel: "AMF-" + ne.NeID + "-Func",
AdministrativeState: "UNLOCKED",
OperationalState: "ENABLED",
VnfInstanceId: "vnf-" + ne.NeID,
Fqdn: "amf-" + ne.NeID + ".example.com",
SbiServiceList: "Namf_Communication,Namf_EventExposure,Namf_MT,Namf_Location",
AmfGuamiList: "[{\"mcc\":\"460\",\"mnc\":\"01\",\"amfId\":\"" + ne.NeID + "\"}]",
SnssaiList: "[{\"sst\":1,\"sd\":\"010203\"}]",
MaxUser: 1000000,
RelativeCapacity: 30,
MaxGnbNum: 100,
}
// 序列化为JSON
amfJSON, err := json.Marshal(amfFunction)
if err != nil {
log.Errorf("Failed to marshal AmfFunction for ne_id %s: %v", ne.NeID, err)
continue
}
// 生成唯一ID
amfID := fmt.Sprintf("nbi-cm-%s-amf-%d", ne.NeID, timestamp)
// 插入AmfFunction记录
nbiCM = NbiCm{
Id: amfID,
NeType: ne.NeType,
NeId: ne.NeID,
CmVersion: "1.0",
RmUid: "OMC-SYSTEM",
EventType: EventTypeInt("ObjectCreationEvent"),
ObjectType: "AmfFunction",
ValueJson: string(amfJSON),
Timestamp: fmt.Sprintf("%d", timestamp),
}
// 插入到数据库
err = dborm.DefaultDB().Table("nbi_cm").Create(&nbiCM).Error
if err != nil {
log.Errorf("Failed to insert AmfFunction record: %v", err)
continue
}
// 可以继续添加其他AMF相关对象如EpRpDynN8Amf、IPResource等
// 这里仅展示了基本结构,可根据实际需求扩展
}
log.Info("AMF NBI CM synchronization completed")
return nil
}

View File

@@ -0,0 +1,53 @@
package udm
type ManagedElement struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
VendorName string `json:"vendorName"`
ManagedBy string `json:"managedBy"`
ManagementIpAddress string `json:"managementIpAddress"`
SwVersion string `json:"swVersion"`
PatchInfo string `json:"patchInfo"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
}
type UdmFunction struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
VnfInstanceId string `json:"vnfInstanceId"`
Fqdn string `json:"fqdn"`
SbiServiceList string `json:"sbiServiceList"`
}
type UdrFunction struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
VnfInstanceId string `json:"vnfInstanceId"`
Fqdn string `json:"fqdn"`
SbiServiceList string `json:"sbiServiceList"`
MaxNumSupi int `json:"maxNumSupi"`
MaxNumMsisdn int `json:"maxNumMsisdn"`
}
type AusfFunction struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
VnfInstanceId string `json:"vnfInstanceId"`
Fqdn string `json:"fqdn"`
SbiServiceList string `json:"sbiServiceList"`
}
type IPResource struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
InterfaceType string `json:"interfaceType"`
LocIpV4AddrList string `json:"locIpV4AddrList"`
LocIpV6AddrList string `json:"locIpV6AddrList"`
}

View File

@@ -0,0 +1,156 @@
package upf
type ManagedElement struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
VendorName string `json:"vendorName"`
ManagedBy string `json:"managedBy"`
ManagementIpAddress string `json:"managementIpAddress"`
SwVersion string `json:"swVersion"`
PatchInfo string `json:"patchInfo"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
}
type InventoryUnitRack struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
VendorUnitFamilyType string `json:"vendorUnitFamilyType"`
VendorUnitTypeNumber string `json:"vendorUnitTypeNumber"`
VendorName string `json:"vendorName"`
SerialNumber string `json:"serialNumber"`
VersionNumber string `json:"versionNumber"`
DateOfManufacture string `json:"dateOfManufacture"`
DateOfLastService string `json:"dateOfLastService"`
ManufacturerData string `json:"manufacturerData"`
RackPosition string `json:"rackPosition"`
}
type InventoryUnitShelf struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
VendorUnitFamilyType string `json:"vendorUnitFamilyType"`
VendorUnitTypeNumber string `json:"vendorUnitTypeNumber"`
VendorName string `json:"vendorName"`
SerialNumber string `json:"serialNumber"`
VersionNumber string `json:"versionNumber"`
DateOfManufacture string `json:"dateOfManufacture"`
DateOfLastService string `json:"dateOfLastService"`
ManufacturerData string `json:"manufacturerData"`
ShelfPosition string `json:"shelfPosition"`
}
type InventoryUnitPack struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
VendorUnitFamilyType string `json:"vendorUnitFamilyType"`
VendorUnitTypeNumber string `json:"vendorUnitTypeNumber"`
VendorName string `json:"vendorName"`
SerialNumber string `json:"serialNumber"`
VersionNumber string `json:"versionNumber"`
DateOfManufacture string `json:"dateOfManufacture"`
DateOfLastService string `json:"dateOfLastService"`
ManufacturerData string `json:"manufacturerData"`
SlotsOccupied string `json:"slotsOccupied"`
}
type InventoryUnitHost struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
VendorUnitFamilyType string `json:"vendorUnitFamilyType"`
VendorUnitTypeNumber string `json:"vendorUnitTypeNumber"`
VendorName string `json:"vendorName"`
SerialNumber string `json:"serialNumber"`
VersionNumber string `json:"versionNumber"`
DateOfManufacture string `json:"dateOfManufacture"`
DateOfLastService string `json:"dateOfLastService"`
ManufacturerData string `json:"manufacturerData"`
HostPosition string `json:"hostPosition"`
NumberOfCpu string `json:"numberOfCpu"`
MemSize string `json:"memSize"`
HardDiskSize string `json:"hardDiskSize"`
}
type InventoryUnitAccessory struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
VendorUnitFamilyType string `json:"vendorUnitFamilyType"`
VendorUnitTypeNumber string `json:"vendorUnitTypeNumber"`
VendorName string `json:"vendorName"`
SerialNumber string `json:"serialNumber"`
VersionNumber string `json:"versionNumber"`
DateOfManufacture string `json:"dateOfManufacture"`
DateOfLastService string `json:"dateOfLastService"`
ManufacturerData string `json:"manufacturerData"`
AccessoryPosition string `json:"accessoryPosition"`
AccessoryType string `json:"accessoryType"`
AddtionalInformation string `json:"addtionalInformation"`
}
type UpfFunction struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
VnfInstanceId string `json:"vnfInstanceId"`
MaxQosFlows string `json:"maxQosFlows"`
MaxThroughput string `json:"maxThroughput"`
}
type EpRpDynN9Upf struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
LocIpAddrList string `json:"locIpAddrList"`
FarIpSubnetworkList string `json:"farIpSubnetworkList"`
}
type EpRpDynN3Upf struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
LocIpAddrList string `json:"locIpAddrList"`
FarIpSubnetworkList string `json:"farIpSubnetworkList"`
}
type AmfFunction struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
VnfInstanceId string `json:"vnfInstanceId"`
Fqdn string `json:"fqdn"`
}
type SmfFunction struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
VnfInstanceId string `json:"vnfInstanceId"`
Fqdn string `json:"fqdn"`
}
type UdrFunction struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
VnfInstanceId string `json:"vnfInstanceId"`
Fqdn string `json:"fqdn"`
}
type AusfFunction struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
AdministrativeState string `json:"administrativeState"`
OperationalState string `json:"operationalState"`
VnfInstanceId string `json:"vnfInstanceId"`
Fqdn string `json:"fqdn"`
}
type IPResource struct {
Id string `json:"id"`
UserLabel string `json:"userLabel"`
InterfaceType string `json:"interfaceType"`
LocIpV4AddrList string `json:"locIpV4AddrList"`
LocIpV6AddrList string `json:"locIpV6AddrList"`
}

View File

@@ -9,6 +9,7 @@ import (
"be.ems/src/modules/crontask/processor/genNeStateAlarm"
"be.ems/src/modules/crontask/processor/getStateFromNE"
processorMonitorSysResource "be.ems/src/modules/crontask/processor/monitor_sys_resource"
"be.ems/src/modules/crontask/processor/nbiNRM"
processorNeConfigBackup "be.ems/src/modules/crontask/processor/ne_config_backup"
processorNeDataUDM "be.ems/src/modules/crontask/processor/ne_data_udm"
"be.ems/src/modules/crontask/processor/removeFile"
@@ -30,4 +31,5 @@ func InitCronQueue() {
cron.CreateQueue("genNeStateAlarm", genNeStateAlarm.NewProcessor)
cron.CreateQueue("exportTable", exportTable.NewProcessor)
cron.CreateQueue("removeFile", removeFile.NewProcessor)
cron.CreateQueue("nbiNRM", nbiNRM.NewProcessor)
}