提交 fc63b020 编写于 作者: H hanxinke

atune:modify the check command and add exception printing

上级 38bf68c7
......@@ -53,7 +53,8 @@ class Optimizer(Resource):
args = OPTIMIZER_POST_PARSER.parse_args()
LOGGER.info(args)
if args["max_eval"] < 10:
abort(400, "max_eval must be >=10")
LOGGER.error("the max iterations %s must be greater than 10", args["max_eval"])
abort(400, "the max iterations {} must be greater than 10".format(args["max_eval"]))
task_id = str(uuid.uuid1())
parent_conn, child_conn = Pipe()
......@@ -74,7 +75,7 @@ class Optimizer(Resource):
def put(self, task_id):
"""provide the method of put"""
if not task_id:
abort(404)
abort(404, "task id does not exist")
task = task_cache.TasksCache.get_instance().get(task_id)
if not task:
abort(404, "taskid {0} not found".format(task_id))
......@@ -95,7 +96,7 @@ class Optimizer(Resource):
def delete(self, task_id):
"""provide the method of delete"""
if not task_id:
abort(404)
abort(404, "task id does not exist")
process = task_cache.TasksCache.get_instance().get(task_id)
if not process:
abort(404, "{0} {1} not found".format(self.task_id_info, task_id))
......
/*
* Copyright (c) 2019 Huawei Technologies Co., Ltd.
* A-Tune is licensed under the Mulan PSL v1.
* You can use this software according to the terms and conditions of the Mulan PSL v1.
* You may obtain a copy of Mulan PSL v1 at:
* http://license.coscl.org.cn/MulanPSL
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v1 for more details.
* Create: 2019-10-29
*/
package checker
import (
PB "atune/api/profile"
"atune/common/log"
"atune/common/utils"
)
//ELF file structer
type ELF struct {
FileName string
}
/*
Check method check the elf file format
*/
func (elf *ELF) Check(ch chan *PB.AckCheck) error {
log.Debugf("Check %s", elf.FileName)
sendChanToAdm(ch, elf.FileName, utils.SUCCESS, "FIXME: NOT Implement")
return nil
}
......@@ -17,6 +17,7 @@ import (
"atune/common/config"
"atune/common/http"
"encoding/json"
"fmt"
"io/ioutil"
)
......@@ -40,8 +41,9 @@ type Knob struct {
// RespPostBody :the body returned of create optimizer task
type RespPostBody struct {
TaskID string `json:"task_id"`
Status string `json:"status"`
TaskID string `json:"task_id"`
Status string `json:"status"`
Message string `json:"message"`
}
// OptimizerPutBody send to the optimizer service when iterations
......@@ -52,7 +54,8 @@ type OptimizerPutBody struct {
// RespPutBody :the body returned of each optimizer iteration
type RespPutBody struct {
Param string `json:"param"`
Param string `json:"param"`
Message string `json:"message"`
}
// Post method create a optimizer task
......@@ -77,6 +80,10 @@ func (o *OptimizerPostBody) Post() (*RespPostBody, error) {
return nil, err
}
if res.StatusCode != 200 {
return nil, fmt.Errorf(respPostIns.Message)
}
return respPostIns, nil
}
......@@ -101,5 +108,9 @@ func (o *OptimizerPutBody) Put(url string) (*RespPutBody, error) {
return nil, err
}
if res.StatusCode != 200 {
return nil, fmt.Errorf(respPutIns.Message)
}
return respPutIns, nil
}
......@@ -114,8 +114,7 @@ func (y *YamlPrjCli) BenchMark() (string, error) {
benchOutByte, err := cmd.CombinedOutput()
if err != nil {
log.Error(err)
return "", err
return "", fmt.Errorf("failed to run benchmark, err: %v", err)
}
for _, evaluation := range y.Evaluations {
newScript := strings.Replace(evaluation.Info.Get, "$out", string(benchOutByte), -1)
......
......@@ -28,7 +28,7 @@ import (
var profileCheckCommand = cli.Command{
Name: "check",
Usage: "check system basic information",
ArgsUsage: "[arguments...]",
UsageText: "atune-adm check",
Description: func() string {
desc := "\n check system basic information\n"
return desc
......@@ -53,12 +53,8 @@ func newProfileCheckCmd(ctx *cli.Context, opts ...interface{}) (interface{}, err
}
func profileCheck(ctx *cli.Context) error {
appname := ""
if ctx.NArg() > 2 {
return fmt.Errorf("only one or zero argument required")
}
if ctx.NArg() == 1 {
appname = ctx.Args().Get(0)
if err := utils.CheckArgs(ctx, 0, utils.ConstExactArgs); err != nil {
return err
}
c, err := client.NewClientFromContext(ctx)
......@@ -68,7 +64,7 @@ func profileCheck(ctx *cli.Context) error {
defer c.Close()
svc := PB.NewProfileMgrClient(c.Connection())
stream, err := svc.CheckInitProfile(CTX.Background(), &PB.ProfileInfo{Name: appname})
stream, err := svc.CheckInitProfile(CTX.Background(), &PB.ProfileInfo{})
if err != nil {
return err
}
......@@ -104,5 +100,6 @@ func profileCheck(ctx *cli.Context) error {
utils.Print(reply)
}
fmt.Println("\nCheck finished")
return nil
}
......@@ -99,8 +99,8 @@ func checkCollectionCtx(ctx *cli.Context) error {
return fmt.Errorf("error: filename must be specified")
}
if len(ctx.String("filename")) > 255 {
return fmt.Errorf("error: filename length is longer than 255 charaters")
if len(ctx.String("filename")) > 128 {
return fmt.Errorf("error: filename length is longer than 128 charaters")
}
if ctx.String("disk") == "" {
......
......@@ -104,6 +104,18 @@ func profileTunning(ctx *cli.Context) error {
return err
}
if len(prj.Project) < 1 || len(prj.Project) > 128 {
return fmt.Errorf("project name must be no less than 1 and no greater than 128 in yaml or yml")
}
if len(prj.Benchmark) < 1 {
return fmt.Errorf("benchmark must be specified in yaml or yml")
}
if len(prj.Evaluations) > 10 {
return fmt.Errorf("evaluations must be no greater than 10 in project %s", prj.Project)
}
_, err = runTuningRPC(ctx, &PB.ProfileInfo{Name: prj.Project, Content: []byte(strconv.Itoa(prj.Iterations))})
if err != nil {
return err
......@@ -171,8 +183,8 @@ func checkTuningCtx(ctx *cli.Context) error {
return fmt.Errorf("error: project name must be specified")
}
if len(ctx.String("project")) > 255 {
return fmt.Errorf("error: project name length is longer than 255 charaters")
if len(ctx.String("project")) > 128 {
return fmt.Errorf("error: project name length is longer than 128 charaters")
}
return nil
......
......@@ -15,7 +15,7 @@ package main
import (
PB "atune/api/profile"
"atune/common/checker"
_ "atune/common/checker"
"atune/common/config"
"atune/common/http"
"atune/common/log"
......@@ -243,8 +243,6 @@ func (s *ProfileServer) ListWorkload(profileInfo *PB.ProfileInfo, stream PB.Prof
// like BIOS version, memory balanced...
func (s *ProfileServer) CheckInitProfile(profileInfo *PB.ProfileInfo,
stream PB.ProfileMgr_CheckInitProfileServer) error {
elf := profileInfo.GetName()
ch := make(chan *PB.AckCheck)
defer close(ch)
go func() {
......@@ -253,14 +251,6 @@ func (s *ProfileServer) CheckInitProfile(profileInfo *PB.ProfileInfo,
}
}()
elf = strings.Trim(elf, "")
if elf != "" {
if exist, _ := utils.PathExist(elf); exist {
program := checker.ELF{FileName: elf}
_ = program.Check(ch)
}
}
services := registry.GetCheckerServices()
for _, service := range services {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册