fix: sync2ne flag

This commit is contained in:
2023-12-26 17:58:16 +08:00
parent 374fb9b8f3
commit 491456caa0
2 changed files with 22 additions and 7 deletions

View File

@@ -43,6 +43,13 @@ var (
CustomUriNeInstance = config.UriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/instance/{action}"
)
const (
NEStatusActive = 0
NEStatusOffline = 1
NEStatusStandby = 2
NEStatusMaintain = 3
)
func init() {
}
@@ -105,6 +112,7 @@ func PostNeInfo(w http.ResponseWriter, r *http.Request) {
services.ResponseNotFound404UriNotExist(w, r)
return
}
syncFlag := services.GetUriParamString(r, "sync2ne", ",", false, false)
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
if err != nil {
log.Error("io.ReadAll is failed:", err)
@@ -148,16 +156,18 @@ func PostNeInfo(w http.ResponseWriter, r *http.Request) {
Put(requestURI2NF)
if err != nil {
log.Error("Failed to Put:", err)
services.ResponseInternalServerError500NFConnectRefused(w)
services.ResponseInternalServerError500ProcessError(w, err)
return
}
log.Info("StatusCode: ", response.StatusCode())
if !config.GetYamlConfig().OMC.Chk2Ne {
//if !config.GetYamlConfig().OMC.Chk2Ne {
if syncFlag == "false" {
neInfo.Status = NEStatusMaintain
affected, err := dborm.XormInsertNeInfo(neInfo)
if err != nil {
log.Error("Failed to insert Ne info:", err)
services.ResponseInternalServerError500DatabaseOperationFailed(w)
services.ResponseInternalServerError500ProcessError(w, err)
return
}
@@ -170,10 +180,11 @@ func PostNeInfo(w http.ResponseWriter, r *http.Request) {
respMsg := make(map[string]interface{})
switch response.StatusCode() {
case http.StatusOK, http.StatusCreated, http.StatusNoContent, http.StatusAccepted:
neInfo.Status = NEStatusActive
affected, err := dborm.XormInsertNeInfo(neInfo)
if err != nil {
log.Error("Failed to dborm.XormInsertNeInfo:", err)
services.ResponseInternalServerError500DatabaseOperationFailed(w)
services.ResponseInternalServerError500ProcessError(w, err)
return
} else if affected <= 0 {
log.Infof("Not record affected to insert ne_info")
@@ -208,6 +219,7 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
services.ResponseNotFound404UriNotExist(w, r)
return
}
syncFlag := services.GetUriParamString(r, "sync2ne", ",", false, false)
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
if err != nil {
log.Error("io.ReadAll is failed:", err)
@@ -246,12 +258,14 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
Put(requestURI2NF)
if err != nil {
log.Error("Failed to Put:", err)
services.ResponseInternalServerError500NFConnectRefused(w)
services.ResponseInternalServerError500ProcessError(w, err)
return
}
log.Info("StatusCode: ", response.StatusCode())
if !config.GetYamlConfig().OMC.Chk2Ne {
//if !config.GetYamlConfig().OMC.Chk2Ne {
if syncFlag == "false" {
neInfo.Status = NEStatusMaintain
affected, err := dborm.XormUpdateNeInfo(neInfo)
if err != nil {
log.Error("Failed to update Ne info:", err)
@@ -268,6 +282,7 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
respMsg := make(map[string]interface{})
switch response.StatusCode() {
case http.StatusOK, http.StatusCreated, http.StatusNoContent, http.StatusAccepted:
neInfo.Status = NEStatusActive
affected, err := dborm.XormUpdateNeInfo(neInfo)
if err != nil {
log.Error("Failed to dborm.XormUpdateNeInfo:", err)