feat: sync NBI NRM task
This commit is contained in:
138
src/modules/crontask/processor/syncNbiNRM/common/common.go
Normal file
138
src/modules/crontask/processor/syncNbiNRM/common/common.go
Normal file
@@ -0,0 +1,138 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type AdministrativeState string
|
||||
|
||||
const (
|
||||
Locked AdministrativeState = "Locked"
|
||||
Unlocked AdministrativeState = "Unlocked"
|
||||
ShuttingDown AdministrativeState = "ShuttingDown"
|
||||
)
|
||||
|
||||
type OperationalState string
|
||||
|
||||
const (
|
||||
Enabled OperationalState = "Enabled"
|
||||
Disabled OperationalState = "Disabled"
|
||||
)
|
||||
|
||||
const (
|
||||
// NBI CM表名
|
||||
NbiCmTableName = "nbi_cm"
|
||||
CmVersion = "v1" // CM版本
|
||||
)
|
||||
|
||||
type EventType int
|
||||
|
||||
const (
|
||||
ObjectNullEvent EventType = iota // ObjectNullEvent 空事件
|
||||
ObjectCreationEvent // 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"
|
||||
case ObjectNullEvent:
|
||||
return "ObjectNullEvent"
|
||||
default:
|
||||
return "ObjectUnkownEvent"
|
||||
}
|
||||
}
|
||||
|
||||
func (et EventType) EventTypeIntString() string {
|
||||
return fmt.Sprintf("%d", et)
|
||||
}
|
||||
|
||||
// EventTypeInt 将字符串转换为 EventType 枚举类型
|
||||
func EventTypeInt(s string) EventType {
|
||||
if i, err := strconv.Atoi(s); err == nil {
|
||||
return EventType(i)
|
||||
}
|
||||
|
||||
switch s {
|
||||
case "ObjectCreationEvent":
|
||||
return ObjectCreationEvent
|
||||
case "ObjectDeletionEvent":
|
||||
return ObjectDeletionEvent
|
||||
case "ObjectAttributeValueChangeEvent":
|
||||
return ObjectAttributeValueChangeEvent
|
||||
case "":
|
||||
// 如果字符串为空,则返回未知事件
|
||||
return ObjectNullEvent
|
||||
default:
|
||||
return ObjectUnkownEvent
|
||||
}
|
||||
}
|
||||
|
||||
type NeStatus int
|
||||
|
||||
const (
|
||||
NeStatusOffline NeStatus = iota
|
||||
NeStatusActive
|
||||
NeStatusToSync
|
||||
NeStatusStandby
|
||||
NeStatusUnknown
|
||||
)
|
||||
|
||||
// ParseStateFromStatus 将状态字符串转换为 AdministrativeState 和 OperationalState
|
||||
func ParseStateFromStatus(status NeStatus) (AdministrativeState, OperationalState) {
|
||||
var adminState AdministrativeState
|
||||
var operState OperationalState
|
||||
|
||||
switch status {
|
||||
case NeStatusOffline:
|
||||
adminState = Locked
|
||||
operState = Disabled
|
||||
case NeStatusActive:
|
||||
adminState = Unlocked
|
||||
operState = Enabled
|
||||
case NeStatusToSync:
|
||||
adminState = Unlocked
|
||||
operState = Enabled
|
||||
case NeStatusStandby:
|
||||
adminState = Locked
|
||||
operState = Enabled
|
||||
default:
|
||||
adminState = ShuttingDown
|
||||
operState = Disabled
|
||||
}
|
||||
|
||||
return adminState, operState
|
||||
}
|
||||
|
||||
type NeInfo struct {
|
||||
NeId string `db:"ne_id"`
|
||||
NeType string `db:"ne_type"`
|
||||
RmUid string `db:"rm_uid"`
|
||||
VendorName string `db:"vendor_name"`
|
||||
NeName string `db:"ne_name"`
|
||||
Ip string `db:"ip"`
|
||||
Port string `db:"port"`
|
||||
Dn string `db:"dn"`
|
||||
Status NeStatus `db:"status"`
|
||||
}
|
||||
|
||||
// NbiCm 表结构
|
||||
type NbiCm struct {
|
||||
Id int `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"`
|
||||
}
|
||||
Reference in New Issue
Block a user