diff --git a/analysis/resources/optimizer.py b/analysis/resources/optimizer.py index b466a732c9660d31a2d7a48bb944768c11ab9769..d0a3fa5763647c22bd27c15b618ab29c006fda32 100644 --- a/analysis/resources/optimizer.py +++ b/analysis/resources/optimizer.py @@ -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)) diff --git a/common/checker/elf.go b/common/checker/elf.go deleted file mode 100644 index 874c0007ca2e466b71059bf52b1135ef3b4296a8..0000000000000000000000000000000000000000 --- a/common/checker/elf.go +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 -} diff --git a/common/models/optimizer.go b/common/models/optimizer.go index 156491d1c1cd651a4b1397f0da19561cca4294aa..168111e7b7c90cceb640ab1ae89645b34f85017a 100644 --- a/common/models/optimizer.go +++ b/common/models/optimizer.go @@ -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 } diff --git a/common/project/projet.go b/common/project/projet.go index 8ca80f5f2af257ae48898734085a000e131b2b13..33c093e3c21b48424b78efaa14e86c9a4df8b166 100644 --- a/common/project/projet.go +++ b/common/project/projet.go @@ -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) diff --git a/modules/client/profile/profile_check.go b/modules/client/profile/profile_check.go index 183010383a6e1b6fe4eef1dba90484563fc313eb..81e44523d83045107f739ef4775df2cb50e52ec7 100644 --- a/modules/client/profile/profile_check.go +++ b/modules/client/profile/profile_check.go @@ -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 } diff --git a/modules/client/profile/profile_collection.go b/modules/client/profile/profile_collection.go index 02ca2a38c863de8330c7756ca30e7bd78643d5c7..3f76cb7ad4263339d75d021545bca046e3fffb50 100644 --- a/modules/client/profile/profile_collection.go +++ b/modules/client/profile/profile_collection.go @@ -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") == "" { diff --git a/modules/client/profile/profile_tuning.go b/modules/client/profile/profile_tuning.go index 97edafbd09553c01cdf50462267bb0c91eb00954..20402b51bb3139142856b763a6a373dd169cde34 100644 --- a/modules/client/profile/profile_tuning.go +++ b/modules/client/profile/profile_tuning.go @@ -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 diff --git a/modules/server/profile/profile.go b/modules/server/profile/profile.go index e88150c541f85aee01dde07216e48d3458499785..cd79eeb9816ff119b8628839bedb72900dd95cbd 100644 --- a/modules/server/profile/profile.go +++ b/modules/server/profile/profile.go @@ -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 {