fix: mml enhancement
This commit is contained in:
@@ -65,15 +65,16 @@ redis:
|
|||||||
# used to specify the default data source for multiple data resourece
|
# used to specify the default data source for multiple data resourece
|
||||||
defaultDataSourceName: "default"
|
defaultDataSourceName: "default"
|
||||||
|
|
||||||
# upfHeaderLength: spare upf buffer, must destroy
|
# sleep: time delay for after write buffer (millisecond)
|
||||||
|
# deadLine: timeout for io read and write (second)
|
||||||
mml:
|
mml:
|
||||||
port: 4100
|
port: 4100
|
||||||
sleep: 200
|
sleep: 200
|
||||||
|
deadLine: 10
|
||||||
user: admin
|
user: admin
|
||||||
password: admin
|
password: admin
|
||||||
mmlHome: ./mmlhome
|
mmlHome: ./mmlhome
|
||||||
upload: /home/agtuser
|
upload: /home/agtuser
|
||||||
upfHeaderLength: 2335
|
|
||||||
|
|
||||||
# NE config
|
# NE config
|
||||||
ne:
|
ne:
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ import (
|
|||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
// const (
|
||||||
//经过测试,linux下,延时需要大于100ms
|
// //经过测试,linux下,延时需要大于100ms
|
||||||
TIME_DELAY_AFTER_WRITE = 200
|
// TIME_DELAY_AFTER_WRITE = 200
|
||||||
)
|
// )
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Data []string `json:"data"`
|
Data []string `json:"data"`
|
||||||
@@ -48,6 +48,15 @@ var (
|
|||||||
CustomUriOmMmlInt = config.UriPrefix + "/omManagement/{apiVersion}/mml/{neType}/{neId}"
|
CustomUriOmMmlInt = config.UriPrefix + "/omManagement/{apiVersion}/mml/{neType}/{neId}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// func init() {
|
||||||
|
// if config.GetYamlConfig().MML.Sleep != 0 {
|
||||||
|
// TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep)
|
||||||
|
// }
|
||||||
|
// if config.GetYamlConfig().MML.DeadLine != 0 {
|
||||||
|
// TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Debug("PostMMLToNF processing... ")
|
log.Debug("PostMMLToNF processing... ")
|
||||||
|
|
||||||
@@ -56,6 +65,16 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Error("Request error:", err)
|
log.Error("Request error:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 经过测试,linux下,延时需要大于100ms
|
||||||
|
var TIME_DELAY_AFTER_WRITE time.Duration = 200
|
||||||
|
var TIME_DEAD_LINE time.Duration = 10
|
||||||
|
if config.GetYamlConfig().MML.Sleep != 0 {
|
||||||
|
TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep)
|
||||||
|
}
|
||||||
|
if config.GetYamlConfig().MML.DeadLine != 0 {
|
||||||
|
TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine)
|
||||||
|
}
|
||||||
|
|
||||||
pack := "mml"
|
pack := "mml"
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
module := vars["managedType"]
|
module := vars["managedType"]
|
||||||
@@ -73,6 +92,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
token, r.Method, module, neType, neId[0], pack)
|
token, r.Method, module, neType, neId[0], pack)
|
||||||
|
|
||||||
var buf [20 * 1024]byte
|
var buf [20 * 1024]byte
|
||||||
|
//buf := make([]byte, 0)
|
||||||
var n int
|
var n int
|
||||||
var mmlResult []string
|
var mmlResult []string
|
||||||
|
|
||||||
@@ -215,7 +235,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
conn.SetDeadline(time.Now().Add(10 * time.Second))
|
conn.SetDeadline(time.Now().Add(TIME_DEAD_LINE * time.Second))
|
||||||
|
|
||||||
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
||||||
_, err = conn.Write([]byte(loginStr))
|
_, err = conn.Write([]byte(loginStr))
|
||||||
@@ -254,7 +274,8 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
re2 := regexp.MustCompile(`[\x00-\x08\x0B\x0C\x0E-\x1F\x7F\x1B]`) // 匹配空字符和包含␛的控制字符
|
re2 := regexp.MustCompile(`[\x00-\x08\x0B\x0C\x0E-\x1F\x7F\x1B]`) // 匹配空字符和包含␛的控制字符
|
||||||
//re := regexp.MustCompile(`[\x00-\x1F\x7F]`)
|
//re := regexp.MustCompile(`[\x00-\x1F\x7F]`)
|
||||||
// upf telnet buffer只能读取一次,需要去掉前面的多余字符
|
// upf telnet buffer只能读取一次,需要去掉前面的多余字符
|
||||||
result := re1.ReplaceAllString(string(buf[config.GetYamlConfig().MML.UpfHeaderLength:n-len(neType)-2]), "")
|
//result := re1.ReplaceAllString(string(buf[config.GetYamlConfig().MML.UpfHeaderLength:n-len(neType)-2]), "")
|
||||||
|
result := re1.ReplaceAllString(string(buf[0:n-len(neType)-2]), "")
|
||||||
result = re2.ReplaceAllString(result, "")
|
result = re2.ReplaceAllString(result, "")
|
||||||
mmlResult = append(mmlResult, result)
|
mmlResult = append(mmlResult, result)
|
||||||
conn.Close()
|
conn.Close()
|
||||||
@@ -286,7 +307,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
// services.ResponseWithJson(w, http.StatusOK, response)
|
// services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
conn.SetDeadline(time.Now().Add(10 * time.Second))
|
conn.SetDeadline(time.Now().Add(TIME_DEAD_LINE * time.Second))
|
||||||
|
|
||||||
_, err = conn.Write([]byte(config.GetYamlConfig().MML.User + "\r\n"))
|
_, err = conn.Write([]byte(config.GetYamlConfig().MML.User + "\r\n"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -405,7 +426,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
|
|
||||||
conn.SetDeadline(time.Now().Add(10 * time.Second))
|
conn.SetDeadline(time.Now().Add(TIME_DEAD_LINE * time.Second))
|
||||||
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
||||||
_, err = conn.Write([]byte(loginStr))
|
_, err = conn.Write([]byte(loginStr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -103,13 +103,13 @@ type YamlConfig struct {
|
|||||||
} `yaml:"alarm"`
|
} `yaml:"alarm"`
|
||||||
|
|
||||||
MML struct {
|
MML struct {
|
||||||
Port int `yaml:"port"`
|
Port int `yaml:"port"`
|
||||||
Sleep int64 `yaml:"sleep"`
|
Sleep int64 `yaml:"sleep"`
|
||||||
User string `yaml:"user"`
|
DeadLine int64 `yaml:"deadLine"`
|
||||||
Password string `ymal:"password"`
|
User string `yaml:"user"`
|
||||||
MmlHome string `yaml:"mmlHome"`
|
Password string `ymal:"password"`
|
||||||
Upload string `yaml:"upload"`
|
MmlHome string `yaml:"mmlHome"`
|
||||||
UpfHeaderLength int `yaml:"upfHeaderLength"`
|
Upload string `yaml:"upload"`
|
||||||
} `yaml:"mml"`
|
} `yaml:"mml"`
|
||||||
|
|
||||||
NE struct {
|
NE struct {
|
||||||
|
|||||||
@@ -65,15 +65,16 @@ redis:
|
|||||||
# 多个数据源时可以用这个指定默认的数据源
|
# 多个数据源时可以用这个指定默认的数据源
|
||||||
defaultDataSourceName: "default"
|
defaultDataSourceName: "default"
|
||||||
|
|
||||||
# upfHeaderLength: spare upf buffer, must destroy
|
# sleep: time delay for after write buffer (millisecond)
|
||||||
|
# deadLine: timeout for io read and write (second)
|
||||||
mml:
|
mml:
|
||||||
port: 4100
|
port: 4100
|
||||||
sleep: 200
|
sleep: 200
|
||||||
|
deadLine: 10
|
||||||
user: admin
|
user: admin
|
||||||
password: admin
|
password: admin
|
||||||
mmlHome: ./mmlhome
|
mmlHome: ./mmlhome
|
||||||
upload: /home/agtuser
|
upload: /home/agtuser
|
||||||
upfHeaderLength: 2335
|
|
||||||
|
|
||||||
# NE config
|
# NE config
|
||||||
ne:
|
ne:
|
||||||
|
|||||||
Reference in New Issue
Block a user