From 428bef93ed9b8228d7126b0556edc863d35f4fc4 Mon Sep 17 00:00:00 2001 From: bay1ts Date: Fri, 8 Dec 2017 21:31:55 +0800 Subject: [PATCH] [REV] optimize status function get status by node strategy;add task dependency relation --- pkg/grctl/cmd/cmd.go | 1 + pkg/grctl/cmd/installStatus.go | 3 ++ pkg/grctl/cmd/tasksMap.go | 64 ++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 pkg/grctl/cmd/tasksMap.go diff --git a/pkg/grctl/cmd/cmd.go b/pkg/grctl/cmd/cmd.go index a26e76f3b..5b47123fa 100644 --- a/pkg/grctl/cmd/cmd.go +++ b/pkg/grctl/cmd/cmd.go @@ -41,6 +41,7 @@ func GetCmds() []cli.Command { cmds = append(cmds, NewCmdGet()) cmds = append(cmds, NewCmdInit()) cmds = append(cmds, NewCmdShow()) + cmds = append(cmds, NewCmdTask()) //cmds = append(cmds, NewCmdAddNode()) //cmds = append(cmds, NewCmdComputeGroup()) diff --git a/pkg/grctl/cmd/installStatus.go b/pkg/grctl/cmd/installStatus.go index 3af92d3e0..32529dfd9 100644 --- a/pkg/grctl/cmd/installStatus.go +++ b/pkg/grctl/cmd/installStatus.go @@ -276,6 +276,9 @@ func Task(c *cli.Context,task string,status bool) error { logrus.Errorf("error exec task:%s,details %s",task,err.Error()) return err } + if nodes==nil||len(nodes)==0 { + nodes=taskEntity.Task.Nodes + } Status(task,nodes) return nil diff --git a/pkg/grctl/cmd/tasksMap.go b/pkg/grctl/cmd/tasksMap.go new file mode 100644 index 000000000..25f892f87 --- /dev/null +++ b/pkg/grctl/cmd/tasksMap.go @@ -0,0 +1,64 @@ +// RAINBOND, Application Management Platform +// Copyright (C) 2014-2017 Goodrain Co., Ltd. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. For any non-GPL usage of Rainbond, +// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd. +// must be obtained first. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package cmd +import ( + "github.com/urfave/cli" + "github.com/Sirupsen/logrus" + + + "github.com/goodrain/rainbond/pkg/grctl/clients" + "github.com/goodrain/rainbond/pkg/node/api/model" +) + +func NewCmdTask() cli.Command { + c:=cli.Command{ + Name: "tasks", + Usage: "tasks", + Action: func(c *cli.Context) error { + v:=clients.NodeClient.Tasks().Get("check_compute_services").Task + getDependTask(v) + v2:=clients.NodeClient.Tasks().Get("check_manage_base_services").Task + getDependTask(v2) + v3:=clients.NodeClient.Tasks().Get("check_manage_services").Task + getDependTask(v3) + return nil + }, + } + return c +} +func getDependTask(task *model.Task) []*model.Task { + logrus.Infof(task.ID+"--->") + depends:=task.Temp.Depends + result:=[]*model.Task{} + for _,v:=range depends{ + tid:=v.DependTaskID + task:=clients.NodeClient.Tasks().Get(tid) + result=append(result,task.Task) + } + for _,Deptask:=range result { + if len(Deptask.Temp.Depends)==0||Deptask.Temp==nil { + return nil + } + getDependTask(Deptask) + } + return result +} + + +