diff --git a/src/modules/crontask/processor/syncNbiNRM/syncAmf.go b/src/modules/crontask/processor/syncNbiNRM/syncAmf.go index 1f820f11..146b40b8 100644 --- a/src/modules/crontask/processor/syncNbiNRM/syncAmf.go +++ b/src/modules/crontask/processor/syncNbiNRM/syncAmf.go @@ -35,14 +35,23 @@ func (s *BarProcessor) SyncAmfNbiCM() error { for _, ne := range amfNEs { adminState, operState := common.ParseStateFromStatus(ne.Status) + var version string = "-" + err := dborm.DefaultDB().Table("ne_version"). + Where("ne_type = ? and ne_id = ?", ne.NeType, ne.NeId). + Pluck("version", &version).Error + if err != nil { + log.Errorf("Failed to query %s version: %v", ne.NeName, err) + return err + } + // 为每个网元生成ManagedElement记录 managedElement := amf.ManagedElement{ - Id: "ME" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), // 生成唯一ID + Id: fmt.Sprintf("%s-%s-ManagedElement-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName, VendorName: ne.VendorName, ManagedBy: ne.Dn, - ManagementIpAddress: ne.Ip, // 可以从其他表获取IP地址 - SwVersion: "", // 可以从其他表获取软件版本 + ManagementIpAddress: ne.Ip, // 可以从其他表获取IP地址 + SwVersion: version, // 可以从其他表获取软件版本 PatchInfo: "-", AdministrativeState: adminState, OperationalState: operState, @@ -80,7 +89,7 @@ func (s *BarProcessor) SyncAmfNbiCM() error { // 为每个网元生成AmfFunction记录 amfFunction := amf.AmfFunction{ - Id: "AF" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), // 生成唯一ID + Id: fmt.Sprintf("%s-%s-AmfFunction-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-AmfFunction", AdministrativeState: adminState, OperationalState: operState, @@ -101,9 +110,6 @@ func (s *BarProcessor) SyncAmfNbiCM() error { continue } - // 生成唯一ID - // amfID := fmt.Sprintf("nbi-cm-%s-amf-%d", ne.NeID, timestamp) - // 插入AmfFunction记录 nbiCM = common.NbiCm{ // Id: amfID, @@ -128,7 +134,7 @@ func (s *BarProcessor) SyncAmfNbiCM() error { // 创建 EpRpDynN8Amf 记录 epRpDynN8Amf := amf.EpRpDynN8Amf{ - Id: "N8" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-EpRpDynN8Amf-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-N8", LocIpAddrList: "[\"" + ne.Ip + "\"]", FarIpSubnetworkList: "[\"10.10.0.0/16\"]", @@ -160,7 +166,7 @@ func (s *BarProcessor) SyncAmfNbiCM() error { // 创建 EpRpDynN11Amf 记录 epRpDynN11Amf := amf.EpRpDynN11Amf{ - Id: "N11" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-EpRpDynN11Amf-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-N11", LocIpAddrList: "[\"" + ne.Ip + "\"]", FarIpSubnetworkList: "[\"10.11.0.0/16\"]", @@ -192,7 +198,7 @@ func (s *BarProcessor) SyncAmfNbiCM() error { // 创建 EpRpDynN12Amf 记录 epRpDynN12Amf := amf.EpRpDynN12Amf{ - Id: "N12" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-EpRpDynN12Amf-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-N12", LocIpAddrList: "[\"" + ne.Ip + "\"]", FarIpSubnetworkList: "[\"10.12.0.0/16\"]", @@ -224,7 +230,7 @@ func (s *BarProcessor) SyncAmfNbiCM() error { // 创建 IPResource 记录 ipResource := amf.IPResource{ - Id: "IP" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-IPResource-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-IPResource", InterfaceType: "{Mgt,N8,N11,N12}", LocIpV4AddrList: fmt.Sprintf("{%s,Default,Default,Default}", ne.Ip), diff --git a/src/modules/crontask/processor/syncNbiNRM/syncPcf.go b/src/modules/crontask/processor/syncNbiNRM/syncPcf.go index aab63262..019587db 100644 --- a/src/modules/crontask/processor/syncNbiNRM/syncPcf.go +++ b/src/modules/crontask/processor/syncNbiNRM/syncPcf.go @@ -34,14 +34,23 @@ func (s *BarProcessor) SyncPcfNbiCM() error { for _, ne := range pcfNEs { adminState, operState := common.ParseStateFromStatus(ne.Status) + var version string = "-" + err := dborm.DefaultDB().Table("ne_version"). + Where("ne_type = ? and ne_id = ?", ne.NeType, ne.NeId). + Pluck("version", &version).Error + if err != nil { + log.Errorf("Failed to query %s version: %v", ne.NeName, err) + return err + } + // 为每个网元生成ManagedElement记录 managedElement := pcf.ManagedElement{ - Id: "ME" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-ManagedElement-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName, VendorName: ne.VendorName, ManagedBy: ne.Dn, ManagementIpAddress: ne.Ip, - SwVersion: "", + SwVersion: version, PatchInfo: "-", AdministrativeState: adminState, OperationalState: operState, @@ -75,7 +84,7 @@ func (s *BarProcessor) SyncPcfNbiCM() error { // 为每个网元生成PcfFunction记录 pcfFunction := pcf.PcfFunction{ - Id: "PF" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-PcfFunction-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-PcfFunction", AdministrativeState: adminState, OperationalState: operState, @@ -112,7 +121,7 @@ func (s *BarProcessor) SyncPcfNbiCM() error { // 为每个网元生成UdrFunction记录 udrFunction := pcf.UdrFunction{ - Id: "UF" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-UdrFunction-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-UdrFunction", AdministrativeState: adminState, OperationalState: operState, @@ -145,7 +154,7 @@ func (s *BarProcessor) SyncPcfNbiCM() error { // 创建 IPResource 记录 ipResource := pcf.IPResource{ - Id: "IP" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-IPResource-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-IPResource", InterfaceType: "{Mgt,N5,N7,N15}", LocIpV4AddrList: fmt.Sprintf("{%s,Default,Default,Default}", ne.Ip), diff --git a/src/modules/crontask/processor/syncNbiNRM/syncSmf.go b/src/modules/crontask/processor/syncNbiNRM/syncSmf.go index 8e0b087f..20edf0cf 100644 --- a/src/modules/crontask/processor/syncNbiNRM/syncSmf.go +++ b/src/modules/crontask/processor/syncNbiNRM/syncSmf.go @@ -34,14 +34,23 @@ func (s *BarProcessor) SyncSmfNbiCM() error { for _, ne := range smfNEs { adminState, operState := common.ParseStateFromStatus(ne.Status) + var version string = "-" + err := dborm.DefaultDB().Table("ne_version"). + Where("ne_type = ? and ne_id = ?", ne.NeType, ne.NeId). + Pluck("version", &version).Error + if err != nil { + log.Errorf("Failed to query %s version: %v", ne.NeName, err) + return err + } + // 为每个网元生成ManagedElement记录 managedElement := smf.ManagedElement{ - Id: "ME" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-ManagedElement-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName, VendorName: ne.VendorName, ManagedBy: ne.Dn, ManagementIpAddress: ne.Ip, - SwVersion: "", + SwVersion: version, PatchInfo: "-", AdministrativeState: string(adminState), OperationalState: string(operState), @@ -75,7 +84,7 @@ func (s *BarProcessor) SyncSmfNbiCM() error { // 为每个网元生成SmfFunction记录 smfFunction := smf.SmfFunction{ - Id: "SF" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-SmfFunction-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-SmfFunction", AdministrativeState: string(adminState), OperationalState: string(operState), @@ -115,7 +124,7 @@ func (s *BarProcessor) SyncSmfNbiCM() error { // 创建 AddrPool 记录 addrPool := smf.AddrPool{ - Id: "AP" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-AddrPool-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-AddrPool", AddrType: "UE", IpVersion: "IPv4", @@ -148,7 +157,7 @@ func (s *BarProcessor) SyncSmfNbiCM() error { // 创建 EpRpDynN7Smf 记录 epRpDynN7Smf := smf.EpRpDynN7Smf{ - Id: "N7" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-EpRpDynN7Smf-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-N7", LocIpAddrList: "[\"" + ne.Ip + "\"]", FarIpSubnetworkList: "[\"10.17.0.0/16\"]", @@ -180,7 +189,7 @@ func (s *BarProcessor) SyncSmfNbiCM() error { // 创建 EpRpDynN10Smf 记录 epRpDynN10Smf := smf.EpRpDynN10Smf{ - Id: "N10" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-EpRpDynN10Smf-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-N10", LocIpAddrList: "[\"" + ne.Ip + "\"]", FarIpSubnetworkList: "[\"10.20.0.0/16\"]", @@ -212,7 +221,7 @@ func (s *BarProcessor) SyncSmfNbiCM() error { // 创建 IPResource 记录 ipResource := smf.IPResource{ - Id: "IP" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-IPResource-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-IPResource", InterfaceType: "{Mgt,N4,N7,N10,N11}", LocIpV4AddrList: fmt.Sprintf("{%s,%s,%s,%s,%s}", ne.Ip, ne.Ip, ne.Ip, ne.Ip, ne.Ip), diff --git a/src/modules/crontask/processor/syncNbiNRM/syncUdm.go b/src/modules/crontask/processor/syncNbiNRM/syncUdm.go index a8e65c53..c36b786f 100644 --- a/src/modules/crontask/processor/syncNbiNRM/syncUdm.go +++ b/src/modules/crontask/processor/syncNbiNRM/syncUdm.go @@ -34,14 +34,23 @@ func (s *BarProcessor) SyncUdmNbiCM() error { for _, ne := range udmNEs { adminState, operState := common.ParseStateFromStatus(ne.Status) + var version string = "-" + err := dborm.DefaultDB().Table("ne_version"). + Where("ne_type = ? and ne_id = ?", ne.NeType, ne.NeId). + Pluck("version", &version).Error + if err != nil { + log.Errorf("Failed to query %s version: %v", ne.NeName, err) + return err + } + // 为每个网元生成ManagedElement记录 managedElement := udm.ManagedElement{ - Id: "ME" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-ManagedElement-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName, VendorName: ne.VendorName, ManagedBy: ne.Dn, ManagementIpAddress: ne.Ip, - SwVersion: "", + SwVersion: version, PatchInfo: "-", AdministrativeState: string(adminState), OperationalState: string(operState), @@ -75,7 +84,7 @@ func (s *BarProcessor) SyncUdmNbiCM() error { // 为每个网元生成UdmFunction记录 udmFunction := udm.UdmFunction{ - Id: "UF" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-UdmFunction-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-UdmFunction", AdministrativeState: string(adminState), OperationalState: string(operState), @@ -112,7 +121,7 @@ func (s *BarProcessor) SyncUdmNbiCM() error { // 为每个网元生成UdrFunction记录 udrFunction := udm.UdrFunction{ - Id: "UDR" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-UdrFunction-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-UdrFunction", AdministrativeState: string(adminState), OperationalState: string(operState), @@ -149,7 +158,7 @@ func (s *BarProcessor) SyncUdmNbiCM() error { // 为每个网元生成AusfFunction记录 ausfFunction := udm.AusfFunction{ - Id: "AUSF" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-AusfFunction-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-AusfFunction", AdministrativeState: string(adminState), OperationalState: string(operState), @@ -184,7 +193,7 @@ func (s *BarProcessor) SyncUdmNbiCM() error { // 创建 IPResource 记录 ipResource := udm.IPResource{ - Id: "IP" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-IPResource-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-IPResource", InterfaceType: "{Mgt,N8,N10,N12,N21}", LocIpV4AddrList: fmt.Sprintf("{%s,%s,%s,%s,%s}", ne.Ip, ne.Ip, ne.Ip, ne.Ip, ne.Ip), diff --git a/src/modules/crontask/processor/syncNbiNRM/syncUpf.go b/src/modules/crontask/processor/syncNbiNRM/syncUpf.go index 70974aec..de301f0c 100644 --- a/src/modules/crontask/processor/syncNbiNRM/syncUpf.go +++ b/src/modules/crontask/processor/syncNbiNRM/syncUpf.go @@ -34,14 +34,23 @@ func (s *BarProcessor) SyncUpfNbiCM() error { for _, ne := range upfNEs { adminState, operState := common.ParseStateFromStatus(ne.Status) + var version string = "-" + err := dborm.DefaultDB().Table("ne_version"). + Where("ne_type = ? and ne_id = ?", ne.NeType, ne.NeId). + Pluck("version", &version).Error + if err != nil { + log.Errorf("Failed to query %s version: %v", ne.NeName, err) + return err + } + // 为每个网元生成ManagedElement记录 managedElement := upf.ManagedElement{ - Id: "ME" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-ManagedElement-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName, VendorName: ne.VendorName, ManagedBy: ne.Dn, ManagementIpAddress: ne.Ip, - SwVersion: "", + SwVersion: version, PatchInfo: "-", AdministrativeState: string(adminState), OperationalState: string(operState), @@ -75,7 +84,7 @@ func (s *BarProcessor) SyncUpfNbiCM() error { // 生成 InventoryUnitRack 记录 inventoryUnitRack := upf.InventoryUnitRack{ - Id: "RACK" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-InventoryUnitRack-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-Rack", VendorUnitFamilyType: "5G-UPF", VendorUnitTypeNumber: "UPF-" + ne.NeId, @@ -112,7 +121,7 @@ func (s *BarProcessor) SyncUpfNbiCM() error { // 生成 InventoryUnitShelf 记录 inventoryUnitShelf := upf.InventoryUnitShelf{ - Id: "SHELF" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-InventoryUnitShelf-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-Shelf", VendorUnitFamilyType: "5G-UPF-SHELF", VendorUnitTypeNumber: "UPF-SHELF-" + ne.NeId, @@ -149,7 +158,7 @@ func (s *BarProcessor) SyncUpfNbiCM() error { // 生成 InventoryUnitPack 记录 inventoryUnitPack := upf.InventoryUnitPack{ - Id: "PACK" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-InventoryUnitPack-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-Pack", VendorUnitFamilyType: "5G-UPF-PACK", VendorUnitTypeNumber: "UPF-PACK-" + ne.NeId, @@ -186,7 +195,7 @@ func (s *BarProcessor) SyncUpfNbiCM() error { // 生成 InventoryUnitHost 记录 inventoryUnitHost := upf.InventoryUnitHost{ - Id: "HOST" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-InventoryUnitHost-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-Host", VendorUnitFamilyType: "5G-UPF-HOST", VendorUnitTypeNumber: "UPF-HOST-" + ne.NeId, @@ -226,7 +235,7 @@ func (s *BarProcessor) SyncUpfNbiCM() error { // 生成 InventoryUnitAccessory 记录 inventoryUnitAccessory := upf.InventoryUnitAccessory{ - Id: "ACC" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-InventoryUnitAccessory-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-Accessory", VendorUnitFamilyType: "5G-UPF-ACC", VendorUnitTypeNumber: "UPF-ACC-" + ne.NeId, @@ -265,7 +274,7 @@ func (s *BarProcessor) SyncUpfNbiCM() error { // 生成 UpfFunction 记录 upfFunction := upf.UpfFunction{ - Id: "UF" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-UpfFunction-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-UpfFunction", AdministrativeState: string(adminState), OperationalState: string(operState), @@ -298,7 +307,7 @@ func (s *BarProcessor) SyncUpfNbiCM() error { // 创建 EpRpDynN3Upf 记录 epRpDynN3Upf := upf.EpRpDynN3Upf{ - Id: "N3" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-EpRpDynN3Upf-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-N3", LocIpAddrList: "[\"" + ne.Ip + "\"]", FarIpSubnetworkList: "[\"10.13.0.0/16\"]", @@ -328,7 +337,7 @@ func (s *BarProcessor) SyncUpfNbiCM() error { // 创建 EpRpDynN9Upf 记录 epRpDynN9Upf := upf.EpRpDynN9Upf{ - Id: "N9" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-EpRpDynN9Upf-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-N9", LocIpAddrList: "[\"" + ne.Ip + "\"]", FarIpSubnetworkList: "[\"10.19.0.0/16\"]", @@ -358,7 +367,7 @@ func (s *BarProcessor) SyncUpfNbiCM() error { // 创建 IPResource 记录 ipResource := upf.IPResource{ - Id: "IP" + fmt.Sprintf("-%s-%d", ne.NeId, timestamp), + Id: fmt.Sprintf("%s-%s-IPResource-%d", ne.NeType, ne.NeId, timestamp), // 生成唯一ID UserLabel: ne.NeName + "-IPResource", InterfaceType: "{Mgt,N3,N4,N9}", LocIpV4AddrList: fmt.Sprintf("{%s,%s,%s,%s}", ne.Ip, ne.Ip, ne.Ip, ne.Ip),