FIX: ne status, ba
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"ems.agt/lib/log"
|
||||
"ems.agt/lib/services"
|
||||
"ems.agt/restagent/config"
|
||||
tokenConst "ems.agt/src/framework/constants/token"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/gorilla/mux"
|
||||
@@ -22,6 +23,7 @@ import (
|
||||
|
||||
var (
|
||||
UriParamOmcNeConfig = config.DefaultUriPrefix + "/systemManagement/v1/elementType/%s/objectType/config/omcNeConfig"
|
||||
UriOmcNeConfig = config.DefaultUriPrefix + "/systemManagement/v1/elementType/omc/objectType/config/omcNeConfig"
|
||||
// NE CM export/import
|
||||
NeCmUri = config.DefaultUriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/cm"
|
||||
// NE info
|
||||
@@ -34,6 +36,7 @@ var (
|
||||
UriNeInstance = config.DefaultUriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/instance/{action}"
|
||||
|
||||
CustomUriParamOmcNeConfig = config.UriPrefix + "/systemManagement/v1/elementType/%s/objectType/config/omcNeConfig"
|
||||
CustomUriOmcNeConfig = config.UriPrefix + "/systemManagement/v1/elementType/omc/objectType/config/omcNeConfig"
|
||||
CustomNeCmUri = config.UriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/cm"
|
||||
CustomUriNeInfo = config.UriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/neInfo"
|
||||
CustomUriNeCmFile = config.UriPrefix + "/systemManagement/{apiVersion}/{neType}/neBackup/{fileName}"
|
||||
@@ -231,6 +234,8 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
|
||||
services.ResponseNotFound404UriNotExist(w, r)
|
||||
return
|
||||
}
|
||||
neTypeLower := strings.ToLower(neType)
|
||||
neTypeUpper := strings.ToUpper(neType)
|
||||
syncFlag := services.GetUriParamString(r, "sync2ne", ",", false, false)
|
||||
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
|
||||
if err != nil {
|
||||
@@ -246,7 +251,7 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
|
||||
log.Debug("NE info:", neInfo)
|
||||
|
||||
//if !config.GetYamlConfig().OMC.Chk2Ne {
|
||||
if syncFlag == "false" {
|
||||
if syncFlag == "false" || neTypeUpper == config.GetYamlConfig().OMC.NeType {
|
||||
neInfo.Status = NEStatusMaintain
|
||||
affected, err := dborm.XormUpdateNeInfo(neInfo)
|
||||
if err != nil {
|
||||
@@ -263,7 +268,7 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
hostUri := global.CombineHostUri(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, neTypeLower)
|
||||
requestURI2NF := fmt.Sprintf("%s%s", hostUri, apiUri)
|
||||
log.Debug("requestURI2NF:", requestURI2NF)
|
||||
|
||||
@@ -279,6 +284,7 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
|
||||
body, _ = json.Marshal(omcNeConfig)
|
||||
response, err := client.R().
|
||||
EnableTrace().
|
||||
SetHeaders(map[string]string{tokenConst.HEADER_KEY: r.Header.Get(tokenConst.HEADER_KEY)}).
|
||||
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
|
||||
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
|
||||
SetBody(body).
|
||||
@@ -316,6 +322,28 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func PutOMCNeConfig(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
neType := vars["elementTypeValue"]
|
||||
if neType == "" {
|
||||
log.Error("elementTypeValue is empty")
|
||||
services.ResponseNotFound404UriNotExist(w, r)
|
||||
return
|
||||
}
|
||||
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
|
||||
if err != nil {
|
||||
log.Error("Failed to io.ReadAll:", err)
|
||||
services.ResponseNotFound404UriNotExist(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
neInfo := new(dborm.NeInfo)
|
||||
_ = json.Unmarshal(body, neInfo)
|
||||
neInfo.NeType = strings.ToUpper(neType)
|
||||
|
||||
services.ResponseStatusOK204NoContent(w)
|
||||
}
|
||||
|
||||
func DeleteNeInfo(w http.ResponseWriter, r *http.Request) {
|
||||
log.Debug("DeleteNeInfo processing... ")
|
||||
|
||||
|
||||
@@ -48,9 +48,9 @@ func GetParamConfigFromNF(w http.ResponseWriter, r *http.Request) {
|
||||
getNeInfoURI := restHostPort + getNeInfoPattern
|
||||
neId := services.GetUriParamString(r, "ne_id", ",", true, true)
|
||||
if neId == "" {
|
||||
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status in ('0','3')+and+ne_type='%s'", neType)
|
||||
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status+in+('0','3')+and+ne_type='%s'", neType)
|
||||
} else {
|
||||
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status in ('0','3')+and+ne_type='%v'+and+ne_id+in+%v", neType, neId)
|
||||
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status+in+('0','3')+and+ne_type='%v'+and+ne_id+in+%v", neType, neId)
|
||||
}
|
||||
log.Debug("getNeInfoURI:", getNeInfoURI)
|
||||
|
||||
@@ -63,11 +63,11 @@ func GetParamConfigFromNF(w http.ResponseWriter, r *http.Request) {
|
||||
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
|
||||
Get(getNeInfoURI)
|
||||
if err != nil {
|
||||
log.Error("Get from database is failure!")
|
||||
services.ResponseInternalServerError500NFConnectRefused(w)
|
||||
log.Error("Failed to Get:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
log.Debug("NE info:", string(resp.Body()))
|
||||
log.Trace("NE info:", string(resp.Body()))
|
||||
|
||||
// var neList []dborm.NeInfo
|
||||
neList, _ := dborm.XormParseResult(resp.Body())
|
||||
|
||||
@@ -750,7 +750,7 @@ func GetStateFromNF(w http.ResponseWriter, r *http.Request) {
|
||||
restHostPort := fmt.Sprintf("http://127.0.0.1:%d", config.GetYamlConfig().Rest[0].Port)
|
||||
getNeInfoPattern := fmt.Sprintf(config.DefaultUriPrefix+"/databaseManagement/v1/elementType/%s/objectType/ne_info",
|
||||
config.GetYamlConfig().Database.Name)
|
||||
getNeInfoURI := restHostPort + getNeInfoPattern + "?WHERE=status in ('0','3')"
|
||||
getNeInfoURI := restHostPort + getNeInfoPattern + "?WHERE=status+in+('0','3')"
|
||||
log.Debug("getNeInfoPattern:", getNeInfoPattern)
|
||||
|
||||
resp, err := client.R().
|
||||
@@ -774,9 +774,9 @@ func GetStateFromNF(w http.ResponseWriter, r *http.Request) {
|
||||
getNeInfoURI := restHostPort + getNeInfoPattern
|
||||
neId := services.GetUriParamString(r, "ne_id", ",", true, true)
|
||||
if neId == "" {
|
||||
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status in ('0','3')+and+ne_type='%s'", neType)
|
||||
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status+in+('0','3')+and+ne_type='%s'", neType)
|
||||
} else {
|
||||
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status in ('0','3')+and+ne_type='%v'+and+ne_id+in+%v", neType, neId)
|
||||
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status+in+('0','3')+and+ne_type='%v'+and+ne_id+in+%v", neType, neId)
|
||||
}
|
||||
log.Debug("getNeInfoURI:", getNeInfoURI)
|
||||
|
||||
@@ -881,10 +881,11 @@ func GetEMSState(ip string) *SysState {
|
||||
version = global.Version
|
||||
}
|
||||
hostName, _ := os.Hostname()
|
||||
dbInfo, _ := dborm.XormGetMySQLVersion()
|
||||
emsState := &SysState{
|
||||
HostName: hostName,
|
||||
OsInfo: getUnameStr(),
|
||||
DbInfo: "mysql Ver 15.1 Distrib 10.3.35-MariaDB, for Linux (aarch64) using readline 5.1",
|
||||
DbInfo: dbInfo,
|
||||
IpAddr: []string{ip},
|
||||
Port: config.GetYamlConfig().Rest[0].Port,
|
||||
Version: version,
|
||||
|
||||
@@ -196,6 +196,34 @@ type NeInfo struct {
|
||||
UpdateTime string `json:"-" xorm:"-"`
|
||||
}
|
||||
|
||||
func XormGetMySQLVersion() (string, error) {
|
||||
var versionInfo string = ""
|
||||
|
||||
var ver, verComment, verCompileOS, verCompile string
|
||||
_, err := xEngine.SQL("SHOW VARIABLES LIKE 'version'").Get(&ver, &ver)
|
||||
if err != nil {
|
||||
return versionInfo, err
|
||||
}
|
||||
|
||||
_, err = xEngine.SQL("SHOW VARIABLES LIKE 'version_comment'").Get(&verComment, &verComment)
|
||||
if err != nil {
|
||||
return versionInfo, err
|
||||
}
|
||||
|
||||
_, err = xEngine.SQL("SHOW VARIABLES LIKE 'version_compile_os'").Get(&verCompileOS, &verCompileOS)
|
||||
if err != nil {
|
||||
return versionInfo, err
|
||||
}
|
||||
|
||||
_, err = xEngine.SQL("SHOW VARIABLES LIKE 'version_compile_machine'").Get(&verCompile, &verCompile)
|
||||
if err != nil {
|
||||
return versionInfo, err
|
||||
}
|
||||
|
||||
versionInfo = fmt.Sprintf("%s %s, for %s (%s)", ver, verComment, verCompileOS, verCompile)
|
||||
return versionInfo, nil
|
||||
}
|
||||
|
||||
func XormGetNeInfo(neType string, neId string) (*NeInfo, error) {
|
||||
log.Debug("XormGetNeInfo processing... ")
|
||||
|
||||
|
||||
@@ -164,6 +164,10 @@ func init() {
|
||||
Register("POST", cm.CustomUriNeInfo, cm.PostNeInfo, nil)
|
||||
Register("PUT", cm.CustomUriNeInfo, cm.PutNeInfo, nil)
|
||||
Register("DELETE", cm.CustomUriNeInfo, cm.DeleteNeInfo, nil)
|
||||
|
||||
Register("PUT", cm.UriOmcNeConfig, cm.PutOMCNeConfig, nil)
|
||||
Register("PUT", cm.CustomUriOmcNeConfig, cm.PutOMCNeConfig, nil)
|
||||
|
||||
//ne service action handle
|
||||
Register("POST", cm.UriNeService, cm.PostNeServiceAction, nil)
|
||||
//ne service action handle
|
||||
|
||||
@@ -35,15 +35,8 @@ CustomizedDirGeneric=${OMCStaticDir}/generic.d
|
||||
check_args "$@"
|
||||
|
||||
case "${M_ARG}" in
|
||||
install | upgrade | upgvue3)
|
||||
install)
|
||||
${OMCBinDir}/importdb.sh ${M_ARG}
|
||||
;;
|
||||
skip)
|
||||
;;
|
||||
*)
|
||||
${OMCBinDir}/importdb.sh
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$C_ARG" in
|
||||
ba)
|
||||
@@ -51,9 +44,7 @@ case "$C_ARG" in
|
||||
for SQL in ${CustomizedDirBA}/db/*.sql; do
|
||||
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
|
||||
done
|
||||
rm -f ${OMCStaticDir}/logo/*.png
|
||||
cp -rf ${CustomizedDirBA}/logo/* ${OMCStaticDir}/logo
|
||||
rm -f ${OMCStaticDir}/helpDoc/*.pdf
|
||||
cp -rf ${CustomizedDirBA}/doc/* ${OMCStaticDir}/helpDoc
|
||||
;;
|
||||
agt)
|
||||
@@ -61,19 +52,58 @@ case "$C_ARG" in
|
||||
for SQL in ${CustomizedDirBA}/db/*.sql; do
|
||||
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
|
||||
done
|
||||
rm -f ${OMCStaticDir}/logo/*.png
|
||||
cp -rf ${CustomizedDirBA}/logo/* ${OMCStaticDir}/logo
|
||||
rm -f ${OMCStaticDir}/helpDoc/*.pdf
|
||||
cp -rf ${CustomizedDirBA}/doc/* ${OMCStaticDir}/helpDoc
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Setting Generic OMC ..."
|
||||
if [ ${M_ARG} == "install" ]; then
|
||||
for SQL in ${CustomizedDirGeneric}/db/*.sql; do
|
||||
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
|
||||
done
|
||||
cp -rf ${CustomizedDirGeneric}/logo/* ${OMCStaticDir}/logo
|
||||
cp -rf ${CustomizedDirGeneric}/doc/* ${OMCStaticDir}/helpDoc
|
||||
fi
|
||||
;;
|
||||
"")
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
upgrade | upgvue3)
|
||||
${OMCBinDir}/importdb.sh ${M_ARG}
|
||||
;;
|
||||
skip)
|
||||
case "$C_ARG" in
|
||||
ba)
|
||||
echo "Setting BA customized OMC ..."
|
||||
for SQL in ${CustomizedDirBA}/db/*.sql; do
|
||||
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
|
||||
done
|
||||
cp -rf ${CustomizedDirBA}/logo/* ${OMCStaticDir}/logo
|
||||
cp -rf ${CustomizedDirBA}/doc/* ${OMCStaticDir}/helpDoc
|
||||
;;
|
||||
agt)
|
||||
echo "Setting AGT customized OMC ..."
|
||||
for SQL in ${CustomizedDirBA}/db/*.sql; do
|
||||
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
|
||||
done
|
||||
cp -rf ${CustomizedDirBA}/logo/* ${OMCStaticDir}/logo
|
||||
cp -rf ${CustomizedDirBA}/doc/* ${OMCStaticDir}/helpDoc
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Setting Generic OMC ..."
|
||||
for SQL in ${CustomizedDirGeneric}/db/*.sql; do
|
||||
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
|
||||
done
|
||||
cp -rf ${CustomizedDirGeneric}/logo/* ${OMCStaticDir}/logo
|
||||
cp -rf ${CustomizedDirGeneric}/doc/* ${OMCStaticDir}/helpDoc
|
||||
;;
|
||||
"")
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
${OMCBinDir}/importdb.sh
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
/**无Token可访问白名单 */
|
||||
var URL_WHITE_LIST = []string{"/performanceManagement", "/faultManagement", "/systemState"}
|
||||
var URL_WHITE_LIST = []string{"/performanceManagement", "/faultManagement", "/systemState", "/omcNeConfig"}
|
||||
|
||||
// PreAuthorize 用户身份授权认证校验
|
||||
//
|
||||
|
||||
@@ -127,7 +127,7 @@ func (s *BarProcessor) Execute(data any) (any, error) {
|
||||
log.Debug("StatusCode: ", response.StatusCode())
|
||||
switch response.StatusCode() {
|
||||
case http.StatusOK, http.StatusCreated, http.StatusNoContent, http.StatusAccepted:
|
||||
log.Debug("response body:", string(response.Body()))
|
||||
log.Trace("response body:", string(response.Body()))
|
||||
state := new(SystemState)
|
||||
_ = json.Unmarshal(response.Body(), &state)
|
||||
neState := new(dborm.NeState)
|
||||
@@ -143,7 +143,7 @@ func (s *BarProcessor) Execute(data any) (any, error) {
|
||||
neState.MemUsage = string(mu)
|
||||
ds, _ := json.Marshal(state.DiskSpace)
|
||||
neState.DiskSpace = string(ds)
|
||||
log.Debug("neState:", neState)
|
||||
log.Trace("neState:", neState)
|
||||
_, err := dborm.XormInsertNeState(neState)
|
||||
if err != nil {
|
||||
log.Error("Failed to insert ne_state:", err)
|
||||
@@ -152,7 +152,7 @@ func (s *BarProcessor) Execute(data any) (any, error) {
|
||||
}
|
||||
succNum++
|
||||
default:
|
||||
log.Debug("response body:", string(response.Body()))
|
||||
log.Trace("response body:", string(response.Body()))
|
||||
body := new(map[string]interface{})
|
||||
_ = json.Unmarshal(response.Body(), &body)
|
||||
failNum++
|
||||
|
||||
Reference in New Issue
Block a user