fix: sync to ne

This commit is contained in:
2023-12-27 12:11:48 +08:00
parent c708ea4215
commit 2b3785361a

View File

@@ -115,7 +115,7 @@ func PostNeInfo(w http.ResponseWriter, r *http.Request) {
syncFlag := services.GetUriParamString(r, "sync2ne", ",", false, false) syncFlag := services.GetUriParamString(r, "sync2ne", ",", false, false)
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen)) body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
if err != nil { if err != nil {
log.Error("io.ReadAll is failed:", err) log.Error("Failed to o.ReadAll:", err)
services.ResponseNotFound404UriNotExist(w, r) services.ResponseNotFound404UriNotExist(w, r)
return return
} }
@@ -131,6 +131,22 @@ func PostNeInfo(w http.ResponseWriter, r *http.Request) {
neInfo.UpdateTime = time.Now().Format(time.DateTime) neInfo.UpdateTime = time.Now().Format(time.DateTime)
log.Debug("NE info:", neInfo) log.Debug("NE info:", neInfo)
//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.ResponseInternalServerError500ProcessError(w, err)
return
}
mapRow := make(map[string]interface{})
row := map[string]interface{}{"affectedRows": affected}
mapRow["data"] = row
services.ResponseWithJson(w, http.StatusOK, mapRow)
return
} else {
hostUri := global.CombineHostUri(neInfo.Ip, neInfo.Port) hostUri := global.CombineHostUri(neInfo.Ip, neInfo.Port)
//hostUri := fmt.Sprintf("http://%s:%v", neInfo.Ip, neInfo.Port) //hostUri := fmt.Sprintf("http://%s:%v", neInfo.Ip, neInfo.Port)
apiUri := fmt.Sprintf(UriParamOmcNeConfig, strings.ToLower(neInfo.NeType)) apiUri := fmt.Sprintf(UriParamOmcNeConfig, strings.ToLower(neInfo.NeType))
@@ -161,22 +177,6 @@ func PostNeInfo(w http.ResponseWriter, r *http.Request) {
} }
log.Info("StatusCode: ", response.StatusCode()) log.Info("StatusCode: ", response.StatusCode())
//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.ResponseInternalServerError500ProcessError(w, err)
return
}
mapRow := make(map[string]interface{})
row := map[string]interface{}{"affectedRows": affected}
mapRow["data"] = row
services.ResponseWithJson(w, http.StatusOK, mapRow)
return
} else {
respMsg := make(map[string]interface{}) respMsg := make(map[string]interface{})
switch response.StatusCode() { switch response.StatusCode() {
case http.StatusOK, http.StatusCreated, http.StatusNoContent, http.StatusAccepted: case http.StatusOK, http.StatusCreated, http.StatusNoContent, http.StatusAccepted:
@@ -222,7 +222,7 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
syncFlag := services.GetUriParamString(r, "sync2ne", ",", false, false) syncFlag := services.GetUriParamString(r, "sync2ne", ",", false, false)
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen)) body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
if err != nil { if err != nil {
log.Error("io.ReadAll is failed:", err) log.Error("Failed to io.ReadAll:", err)
services.ResponseNotFound404UriNotExist(w, r) services.ResponseNotFound404UriNotExist(w, r)
return return
} }
@@ -233,6 +233,22 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
neInfo.UpdateTime = time.Now().Format(time.DateTime) neInfo.UpdateTime = time.Now().Format(time.DateTime)
log.Debug("NE info:", neInfo) log.Debug("NE info:", neInfo)
//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)
services.ResponseInternalServerError500DatabaseOperationFailed(w)
return
}
mapRow := make(map[string]interface{})
row := map[string]interface{}{"affectedRows": affected}
mapRow["data"] = row
services.ResponseWithJson(w, http.StatusOK, mapRow)
return
} else {
hostUri := global.CombineHostUri(neInfo.Ip, neInfo.Port) hostUri := global.CombineHostUri(neInfo.Ip, neInfo.Port)
//hostUri := fmt.Sprintf("http://%s:%v", neInfo.Ip, neInfo.Port) //hostUri := fmt.Sprintf("http://%s:%v", neInfo.Ip, neInfo.Port)
apiUri := fmt.Sprintf(UriParamOmcNeConfig, strings.ToLower(neType)) apiUri := fmt.Sprintf(UriParamOmcNeConfig, strings.ToLower(neType))
@@ -263,22 +279,6 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
} }
log.Info("StatusCode: ", response.StatusCode()) log.Info("StatusCode: ", response.StatusCode())
//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)
services.ResponseInternalServerError500DatabaseOperationFailed(w)
return
}
mapRow := make(map[string]interface{})
row := map[string]interface{}{"affectedRows": affected}
mapRow["data"] = row
services.ResponseWithJson(w, http.StatusOK, mapRow)
return
} else {
respMsg := make(map[string]interface{}) respMsg := make(map[string]interface{})
switch response.StatusCode() { switch response.StatusCode() {
case http.StatusOK, http.StatusCreated, http.StatusNoContent, http.StatusAccepted: case http.StatusOK, http.StatusCreated, http.StatusNoContent, http.StatusAccepted: