提交 b40ed198 编写于 作者: L lixiaoguang

atune: fix the error that check the fixed port of the rest service

上级 c2b22332
......@@ -187,7 +187,7 @@ func runatuned(ctx *cli.Context) error {
return err
}
if err := utils.WaitForPyservice(); err != nil {
if err := utils.WaitForPyservice(config.LocalHost, config.RestPort); err != nil {
log.Errorf("waiting for pyservice faild: %v", err)
return err
}
......
......@@ -175,4 +175,3 @@ func ExecCommand(script string) ([]byte, error) {
out, err := cmd.CombinedOutput()
return out, err
}
......@@ -48,7 +48,7 @@ func (m *Monitor) Set(cfg *config.Cfg) {
// Run method start the monitor service
func (m *Monitor) Run() error {
if err := utils.WaitForPyservice(); err != nil {
if err := utils.WaitForPyservice(config.LocalHost, config.RestPort); err != nil {
log.Errorf("waiting for pyservice faild: %v", err)
return err
}
......
......@@ -149,4 +149,3 @@ func CheckRpcIsLocalAddr(ctx context.Context) (bool, error) {
}
return false, nil
}
......@@ -53,7 +53,7 @@ func (t *Timer) Set(cfg *config.Cfg) {
//Run method start the ticker, auto-tuning the system
func (t *Timer) Run() error {
/* Static & Dynamic judge */
if err := utils.WaitForPyservice(); err != nil {
if err := utils.WaitForPyservice(config.LocalHost, config.RestPort); err != nil {
log.Errorf("waiting for pyservice faild: %v", err)
return err
}
......
......@@ -301,4 +301,3 @@ func CheckServerPrj(data string, optimizer *Optimizer) error {
return fmt.Errorf("project:%s not found", data)
}
......@@ -59,6 +59,12 @@ const (
UNKNOWN = "UNKNOWN"
)
// config for waiting rest service
const (
period = 2
timeout = 120
)
// CheckArgs method check command args num
func CheckArgs(context *cli.Context, expected, checkType int) error {
var err error
......@@ -229,13 +235,14 @@ func RemoveDuplicateElement(message []string) []string {
}
// WaitForPyservice method waiting for pyEngine service start success
func WaitForPyservice() error {
ticker := time.NewTicker(time.Second * 2)
timeout := time.After(time.Second * 120)
func WaitForPyservice(address string, port string) error {
ticker := time.NewTicker(time.Second * period)
timeout := time.After(time.Second * timeout)
addr := address + ":" + port
for {
select {
case <-ticker.C:
_, err := net.Dial("tcp", "localhost:8383")
_, err := net.Dial("tcp", addr)
if err != nil {
continue
}
......@@ -354,4 +361,3 @@ func CreateDir(dir string, perm os.FileMode) error {
}
return nil
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册