[REV] update code style

This commit is contained in:
barnett 2018-04-09 23:08:51 +08:00
parent c4a607a941
commit 4f32a94da8
5 changed files with 93 additions and 190 deletions

View File

@ -46,13 +46,14 @@ type AppRuntimeSync struct {
} }
//Start start if have master right //Start start if have master right
//start grpc server
func (a *AppRuntimeSync) Start() error { func (a *AppRuntimeSync) Start() error {
a.srss.Start() a.srss.Start()
go a.startAppRuntimeSync() go a.startAppRuntimeSync()
return a.registServer() return a.registServer()
} }
//Stop 停止 //Stop stop app runtime sync server
func (a *AppRuntimeSync) Stop() error { func (a *AppRuntimeSync) Stop() error {
a.srss.Stop() a.srss.Stop()
if a.keepalive != nil { if a.keepalive != nil {

View File

@ -35,4 +35,4 @@ Client code demo:
} }
*/ */
package appruntimesync package appruntimesync //import

View File

@ -72,19 +72,19 @@ func (n *NodeService) AddNode(node *model.APIHostNode) *utils.APIHandleError {
if _, err := rbnode.Update(); err != nil { if _, err := rbnode.Update(); err != nil {
return utils.CreateAPIHandleErrorFromDBError("save node", err) return utils.CreateAPIHandleErrorFromDBError("save node", err)
} }
//判断是否需要安装 //Determine if the node needs to be installed.
n.nodecluster.CheckNodeInstall(rbnode) n.nodecluster.CheckNodeInstall(rbnode)
return nil return nil
} }
//DeleteNode 删除节点信息 //DeleteNode delete node
//只有节点状态属于(离线状态)才能删除 //only node status is offline and node can be deleted
func (n *NodeService) DeleteNode(nodeID string) *utils.APIHandleError { func (n *NodeService) DeleteNode(nodeID string) *utils.APIHandleError {
node := n.nodecluster.GetNode(nodeID) node := n.nodecluster.GetNode(nodeID)
if node.Alived { if node.Alived {
return utils.CreateAPIHandleError(400, fmt.Errorf("node is online, can not delete")) return utils.CreateAPIHandleError(400, fmt.Errorf("node is online, can not delete"))
} }
//TODO:计算节点,判断节点是否下线 //TODO:compute node check node is offline
if node.Role.HasRule(model.ComputeNode) { if node.Role.HasRule(model.ComputeNode) {
if node.NodeStatus != nil { if node.NodeStatus != nil {
return utils.CreateAPIHandleError(400, fmt.Errorf("node is k8s compute node, can not delete")) return utils.CreateAPIHandleError(400, fmt.Errorf("node is k8s compute node, can not delete"))
@ -97,7 +97,7 @@ func (n *NodeService) DeleteNode(nodeID string) *utils.APIHandleError {
return nil return nil
} }
//GetNode 获取node //GetNode get node info
func (n *NodeService) GetNode(nodeID string) (*model.HostNode, *utils.APIHandleError) { func (n *NodeService) GetNode(nodeID string) (*model.HostNode, *utils.APIHandleError) {
node := n.nodecluster.GetNode(nodeID) node := n.nodecluster.GetNode(nodeID)
if node == nil { if node == nil {
@ -117,7 +117,7 @@ func (n *NodeService) GetAllNode() ([]*model.HostNode, *utils.APIHandleError) {
return nodes, nil return nodes, nil
} }
//CordonNode 设置节点不可调度熟悉 //CordonNode set node is unscheduler
func (n *NodeService) CordonNode(nodeID string, unschedulable bool) *utils.APIHandleError { func (n *NodeService) CordonNode(nodeID string, unschedulable bool) *utils.APIHandleError {
hostNode, apierr := n.GetNode(nodeID) hostNode, apierr := n.GetNode(nodeID)
if apierr != nil { if apierr != nil {
@ -126,16 +126,15 @@ func (n *NodeService) CordonNode(nodeID string, unschedulable bool) *utils.APIHa
if !hostNode.Role.HasRule(model.ComputeNode) { if !hostNode.Role.HasRule(model.ComputeNode) {
return utils.CreateAPIHandleError(400, fmt.Errorf("this node can not support this api")) return utils.CreateAPIHandleError(400, fmt.Errorf("this node can not support this api"))
} }
//更新节点状态 //update k8s node unshcedulable status
hostNode.Unschedulable = unschedulable hostNode.Unschedulable = unschedulable
//k8s节点存在 //update node status
if unschedulable { if unschedulable {
hostNode.Status = "unschedulable" hostNode.Status = "unschedulable"
} else { } else {
hostNode.Status = "running" hostNode.Status = "running"
} }
if hostNode.NodeStatus != nil { if hostNode.NodeStatus != nil {
//true表示drain不可调度
node, err := k8s.CordonOrUnCordon(hostNode.ID, unschedulable) node, err := k8s.CordonOrUnCordon(hostNode.ID, unschedulable)
if err != nil { if err != nil {
return utils.CreateAPIHandleError(500, fmt.Errorf("set node schedulable info error,%s", err.Error())) return utils.CreateAPIHandleError(500, fmt.Errorf("set node schedulable info error,%s", err.Error()))
@ -146,7 +145,7 @@ func (n *NodeService) CordonNode(nodeID string, unschedulable bool) *utils.APIHa
return nil return nil
} }
//PutNodeLabel 更新node label //PutNodeLabel update node label
func (n *NodeService) PutNodeLabel(nodeID string, labels map[string]string) *utils.APIHandleError { func (n *NodeService) PutNodeLabel(nodeID string, labels map[string]string) *utils.APIHandleError {
hostNode, apierr := n.GetNode(nodeID) hostNode, apierr := n.GetNode(nodeID)
if apierr != nil { if apierr != nil {
@ -164,7 +163,7 @@ func (n *NodeService) PutNodeLabel(nodeID string, labels map[string]string) *uti
return nil return nil
} }
//DownNode 节点下线 //DownNode down node
func (n *NodeService) DownNode(nodeID string) (*model.HostNode, *utils.APIHandleError) { func (n *NodeService) DownNode(nodeID string) (*model.HostNode, *utils.APIHandleError) {
hostNode, apierr := n.GetNode(nodeID) hostNode, apierr := n.GetNode(nodeID)
if apierr != nil { if apierr != nil {
@ -183,7 +182,7 @@ func (n *NodeService) DownNode(nodeID string) (*model.HostNode, *utils.APIHandle
return hostNode, nil return hostNode, nil
} }
//UpNode 节点上线 //UpNode up node
func (n *NodeService) UpNode(nodeID string) (*model.HostNode, *utils.APIHandleError) { func (n *NodeService) UpNode(nodeID string) (*model.HostNode, *utils.APIHandleError) {
hostNode, apierr := n.GetNode(nodeID) hostNode, apierr := n.GetNode(nodeID)
if apierr != nil { if apierr != nil {
@ -201,6 +200,8 @@ func (n *NodeService) UpNode(nodeID string) (*model.HostNode, *utils.APIHandleEr
n.nodecluster.UpdateNode(hostNode) n.nodecluster.UpdateNode(hostNode)
return hostNode, nil return hostNode, nil
} }
//InstallNode install a node
func (n *NodeService) InstallNode(nodeID string) *utils.APIHandleError { func (n *NodeService) InstallNode(nodeID string) *utils.APIHandleError {
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
node, err := n.GetNode(nodeID) node, err := n.GetNode(nodeID)
@ -228,6 +229,8 @@ func (n *NodeService) InstallNode(nodeID string) *utils.APIHandleError {
n.nodecluster.UpdateNode(node) n.nodecluster.UpdateNode(node)
return nil return nil
} }
//InitStatus node init status
func (n *NodeService) InitStatus(nodeIP string) (*model.InitStatus, *utils.APIHandleError) { func (n *NodeService) InitStatus(nodeIP string) (*model.InitStatus, *utils.APIHandleError) {
var hostnode model.HostNode var hostnode model.HostNode
gotNode := false gotNode := false
@ -245,34 +248,28 @@ func (n *NodeService) InitStatus(nodeIP string) (*model.InitStatus, *utils.APIHa
break break
} }
} }
if i > 0 { if i > 0 {
time.Sleep(time.Second) time.Sleep(time.Second)
} }
i++ i++
} }
if i != 10 { if i != 10 {
return nil, utils.CreateAPIHandleError(400, fmt.Errorf("can't find node with given ip %s", nodeIP)) return nil, utils.CreateAPIHandleError(400, fmt.Errorf("can't find node with given ip %s", nodeIP))
} }
nodeUID := hostnode.ID nodeUID := hostnode.ID
node, err := n.GetNode(nodeUID) node, err := n.GetNode(nodeUID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var status model.InitStatus var status model.InitStatus
for _, val := range node.Conditions { for _, val := range node.Conditions {
if node.Alived || (val.Type == model.NodeInit && val.Status == model.ConditionTrue) { if node.Alived || (val.Type == model.NodeInit && val.Status == model.ConditionTrue) {
//初始化成功
status.Status = 0 status.Status = 0
status.StatusCN = "初始化成功" status.StatusCN = "初始化成功"
status.HostID = node.ID status.HostID = node.ID
} else if val.Type == model.NodeInit && val.Status == model.ConditionFalse { } else if val.Type == model.NodeInit && val.Status == model.ConditionFalse {
status.Status = 1 status.Status = 1
status.StatusCN = fmt.Sprintf("初始化失<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,%s", val.Message) status.StatusCN = fmt.Sprintf("初始化失,%s", val.Message)
} else { } else {
status.Status = 2 status.Status = 2
status.StatusCN = "初始化中" status.StatusCN = "初始化中"
@ -285,12 +282,12 @@ func (n *NodeService) InitStatus(nodeIP string) (*model.InitStatus, *utils.APIHa
return &status, nil return &status, nil
} }
//GetNodeResource get node resource
func (n *NodeService) GetNodeResource(nodeUID string) (*model.NodePodResource, *utils.APIHandleError) { func (n *NodeService) GetNodeResource(nodeUID string) (*model.NodePodResource, *utils.APIHandleError) {
node, err := n.GetNode(nodeUID) node, err := n.GetNode(nodeUID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if !node.Role.HasRule("compute") { if !node.Role.HasRule("compute") {
} }
@ -298,8 +295,8 @@ func (n *NodeService) GetNodeResource(nodeUID string) (*model.NodePodResource, *
if error != nil { if error != nil {
return nil, utils.CreateAPIHandleError(404, err) return nil, utils.CreateAPIHandleError(404, err)
} }
var cpuTotal int64 = node.AvailableCPU var cpuTotal = node.AvailableCPU
var memTotal int64 = node.AvailableMemory var memTotal = node.AvailableMemory
var cpuLimit int64 var cpuLimit int64
var cpuRequest int64 var cpuRequest int64
var memLimit int64 var memLimit int64
@ -308,9 +305,7 @@ func (n *NodeService) GetNodeResource(nodeUID string) (*model.NodePodResource, *
lc := v.Spec.Containers[0].Resources.Limits.Cpu().MilliValue() lc := v.Spec.Containers[0].Resources.Limits.Cpu().MilliValue()
cpuLimit += lc cpuLimit += lc
lm := v.Spec.Containers[0].Resources.Limits.Memory().Value() lm := v.Spec.Containers[0].Resources.Limits.Memory().Value()
memLimit += lm memLimit += lm
//logrus.Infof("pod %s limit cpu is %s",v.Name,v.Spec.Containers[0].Resources.Limits.Cpu().MilliValue()) //logrus.Infof("pod %s limit cpu is %s",v.Name,v.Spec.Containers[0].Resources.Limits.Cpu().MilliValue())
rc := v.Spec.Containers[0].Resources.Requests.Cpu().MilliValue() rc := v.Spec.Containers[0].Resources.Requests.Cpu().MilliValue()
cpuRequest += rc cpuRequest += rc
@ -318,7 +313,6 @@ func (n *NodeService) GetNodeResource(nodeUID string) (*model.NodePodResource, *
memRequest += rm memRequest += rm
} }
var res model.NodePodResource var res model.NodePodResource
res.CPULimits = cpuLimit res.CPULimits = cpuLimit
//logrus.Infof("node %s cpu limit is %v",cpuLimit) //logrus.Infof("node %s cpu limit is %v",cpuLimit)
res.CPURequests = cpuRequest res.CPURequests = cpuRequest
@ -332,6 +326,8 @@ func (n *NodeService) GetNodeResource(nodeUID string) (*model.NodePodResource, *
res.MemoryRequestsR = strconv.FormatFloat(float64(res.MemoryRequests*100)/float64(res.MemR), 'f', 2, 64) res.MemoryRequestsR = strconv.FormatFloat(float64(res.MemoryRequests*100)/float64(res.MemR), 'f', 2, 64)
return &res, nil return &res, nil
} }
//CheckNode check node install status
func (n *NodeService) CheckNode(nodeUID string) (*model.InstallStatus, *utils.APIHandleError) { func (n *NodeService) CheckNode(nodeUID string) (*model.InstallStatus, *utils.APIHandleError) {
descMap := make(map[string]string) descMap := make(map[string]string)
descMap["check_compute_services"] = "检测计算节点所需服务" descMap["check_compute_services"] = "检测计算节点所需服务"
@ -371,8 +367,8 @@ func (n *NodeService) CheckNode(nodeUID string) (*model.InstallStatus, *utils.AP
var final model.InstallStatus var final model.InstallStatus
var result []*model.ExecedTask var result []*model.ExecedTask
var installStatus int = 1 //0 success 1 ing 2 failed var installStatus = 1 //0 success 1 ing 2 failed
var statusCN string = "安装中" //0 success 1 ing 2 failed var statusCN = "安装中" //0 success 1 ing 2 failed
successCount := 0 successCount := 0
for _, v := range tasks { for _, v := range tasks {
var task model.ExecedTask var task model.ExecedTask
@ -382,7 +378,7 @@ func (n *NodeService) CheckNode(nodeUID string) (*model.InstallStatus, *utils.AP
task.Status = strings.ToLower(taskStatus.Status) task.Status = strings.ToLower(taskStatus.Status)
task.CompleteStatus = taskStatus.CompleStatus task.CompleteStatus = taskStatus.CompleStatus
if strings.ToLower(task.Status) == "complete" && strings.ToLower(task.CompleteStatus) == "success" { if strings.ToLower(task.Status) == "complete" && strings.ToLower(task.CompleteStatus) == "success" {
successCount += 1 successCount++
} }
if strings.ToLower(task.Status) == "parse task output error" { if strings.ToLower(task.Status) == "parse task output error" {
task.Status = "failure" task.Status = "failure"

View File

@ -19,18 +19,13 @@
package service package service
import ( import (
"fmt"
"time"
"github.com/goodrain/rainbond/cmd/node/option" "github.com/goodrain/rainbond/cmd/node/option"
"github.com/goodrain/rainbond/pkg/node/api/model" "github.com/goodrain/rainbond/pkg/node/api/model"
"github.com/goodrain/rainbond/pkg/node/masterserver" "github.com/goodrain/rainbond/pkg/node/masterserver"
"github.com/goodrain/rainbond/pkg/node/utils" "github.com/goodrain/rainbond/pkg/node/utils"
"github.com/twinj/uuid"
) )
//TaskService 处理taskAPI //PrometheusService prometheus service
type PrometheusService struct { type PrometheusService struct {
prometheusAPI *model.PrometheusAPI prometheusAPI *model.PrometheusAPI
conf *option.Conf conf *option.Conf
@ -39,124 +34,32 @@ type PrometheusService struct {
var prometheusService *PrometheusService var prometheusService *PrometheusService
//CreateTaskService 创建Task service //CreatePrometheusService create prometheus service
func CreatePrometheusService(c *option.Conf, ms *masterserver.MasterServer) *PrometheusService { func CreatePrometheusService(c *option.Conf, ms *masterserver.MasterServer) *PrometheusService {
if prometheusService == nil { if prometheusService == nil {
prometheusService = &PrometheusService{ prometheusService = &PrometheusService{
prometheusAPI: &model.PrometheusAPI{API:c.PrometheusAPI}, prometheusAPI: &model.PrometheusAPI{API: c.PrometheusAPI},
conf: c, conf: c,
ms: ms, ms: ms,
} }
} }
return prometheusService return prometheusService
} }
func (ts *PrometheusService)getTasksByCheck(checkTasks []string,nodeID string) ([]*model.Task, *utils.APIHandleError) {
var result []*model.Task
var nextTask []string
for _,v:=range checkTasks{
checkTask,err:=taskService.GetTask(v)
if err != nil {
return nil,err
}
for _,out:=range checkTask.OutPut{
if out.NodeID == nodeID {
for _,status:=range out.Status{
for _,v:=range status.NextTask{
nextTask=append(nextTask,v)
}
}
}
}
} //Exec exec prometheus query
//tids:=[]string{"do_rbd_images","install_acp_plugins","install_base_plugins","install_db", func (ts *PrometheusService) Exec(expr string) (*model.Prome, *utils.APIHandleError) {
// "install_docker","install_k8s","install_manage_ready","install_network","install_plugins","install_storage","install_webcli","update_dns","update_entrance_services","create_host_id_list"}
for _,v:=range nextTask{
task,err:=taskService.GetTask(v)
if err != nil {
return nil,err
}
result=append(result, task)
}
return result,nil
}
func (ts *PrometheusService)GetTasksByNode(n *model.HostNode)([]*model.Task,*utils.APIHandleError) {
if n.Role.HasRule("compute") &&len(n.Role)==1{
checkTask:=[]string{"check_compute_services"}
//tids:=[]string{"install_compute_ready","update_dns_compute","install_storage_client","install_network_compute","install_plugins_compute","install_docker_compute","install_kubelet"}
result,err:=ts.getTasksByCheck(checkTask,n.ID)
if err != nil {
return nil,err
}
return result,nil
}else if n.Role.HasRule("manage") &&len(n.Role)==1{
//checkTask:=[]string{"check_manage_base_services","check_manage_services"}
checkTask:=[]string{"check_manage_services"}
result,err:=ts.getTasksByCheck(checkTask,n.ID)
if err != nil {
return nil,err
}
return result,nil
}else {
//checkTask:=[]string{"check_manage_base_services","check_manage_services","check_compute_services"}
checkTask:=[]string{"check_manage_services","check_compute_services"}
//tids:=[]string{"do_rbd_images","install_acp_plugins","install_base_plugins","install_db","install_docker","install_k8s","install_manage_ready","install_network","install_plugins","install_storage","install_webcli","update_dns","update_entrance_services","create_host_id_list","install_kubelet_manage","install_compute_ready_manage"}
result,err:=ts.getTasksByCheck(checkTask,n.ID)
if err != nil {
return nil,err
}
return result,nil
}
}
//AddTask add task
func (ts *PrometheusService) AddTask(t *model.Task) *utils.APIHandleError {
if t.ID == "" {
t.ID = uuid.NewV4().String()
}
if len(t.Nodes) < 1 {
return utils.CreateAPIHandleError(400, fmt.Errorf("task exec nodes can not be empty"))
}
if t.TempID == "" && t.Temp == nil {
return utils.CreateAPIHandleError(400, fmt.Errorf("task temp can not be empty"))
}
if t.TempID != "" {
//TODO:确定是否应该在执行时获取最新TEMP
temp, err := taskTempService.GetTaskTemp(t.TempID)
if err != nil {
return err
}
t.Temp = temp
}
if t.Temp == nil {
return utils.CreateAPIHandleError(400, fmt.Errorf("task temp can not be empty"))
}
t.Status = map[string]model.TaskStatus{}
for _, n := range t.Nodes {
t.Status[n] = model.TaskStatus{
Status: "create",
}
}
t.CreateTime = time.Now()
err := ts.ms.TaskEngine.AddTask(t)
if err != nil {
return utils.CreateAPIHandleErrorFromDBError("save task", err)
}
return nil
}
//AddTask add task
func (ts *PrometheusService) Exec(expr string) (*model.Prome,*utils.APIHandleError) {
resp, err := ts.prometheusAPI.Query(expr) resp, err := ts.prometheusAPI.Query(expr)
if err != nil { if err != nil {
return nil,err return nil, err
} }
return resp,nil return resp, nil
} }
func (ts *PrometheusService) ExecRange(expr,start,end,step string) (*model.Prome,*utils.APIHandleError) {
resp, err := ts.prometheusAPI.QueryRange(expr,start,end,step) //ExecRange exec prometheus query range
func (ts *PrometheusService) ExecRange(expr, start, end, step string) (*model.Prome, *utils.APIHandleError) {
resp, err := ts.prometheusAPI.QueryRange(expr, start, end, step)
if err != nil { if err != nil {
return nil,err return nil, err
} }
return resp,nil return resp, nil
} }

View File

@ -36,7 +36,7 @@ import (
"github.com/twinj/uuid" "github.com/twinj/uuid"
) )
//TaskService 处理taskAPI //TaskService task services
type TaskService struct { type TaskService struct {
SavePath string SavePath string
conf *option.Conf conf *option.Conf
@ -45,7 +45,7 @@ type TaskService struct {
var taskService *TaskService var taskService *TaskService
//CreateTaskService 创建Task service //CreateTaskService create task service
func CreateTaskService(c *option.Conf, ms *masterserver.MasterServer) *TaskService { func CreateTaskService(c *option.Conf, ms *masterserver.MasterServer) *TaskService {
if taskService == nil { if taskService == nil {
taskService = &TaskService{ taskService = &TaskService{
@ -56,19 +56,19 @@ func CreateTaskService(c *option.Conf, ms *masterserver.MasterServer) *TaskServi
} }
return taskService return taskService
} }
func (ts *TaskService)getTasksByCheck(checkTasks []string,nodeID string) ([]*model.Task, *utils.APIHandleError) { func (ts *TaskService) getTasksByCheck(checkTasks []string, nodeID string) ([]*model.Task, *utils.APIHandleError) {
var result []*model.Task var result []*model.Task
var nextTask []string var nextTask []string
for _,v:=range checkTasks{ for _, v := range checkTasks {
checkTask,err:=taskService.GetTask(v) checkTask, err := taskService.GetTask(v)
if err != nil { if err != nil {
return nil,err return nil, err
} }
for _,out:=range checkTask.OutPut{ for _, out := range checkTask.OutPut {
if out.NodeID == nodeID { if out.NodeID == nodeID {
for _,status:=range out.Status{ for _, status := range out.Status {
for _,v:=range status.NextTask{ for _, v := range status.NextTask {
nextTask=append(nextTask,v) nextTask = append(nextTask, v)
} }
} }
} }
@ -77,43 +77,46 @@ func (ts *TaskService)getTasksByCheck(checkTasks []string,nodeID string) ([]*mod
} }
//tids:=[]string{"do_rbd_images","install_acp_plugins","install_base_plugins","install_db", //tids:=[]string{"do_rbd_images","install_acp_plugins","install_base_plugins","install_db",
// "install_docker","install_k8s","install_manage_ready","install_network","install_plugins","install_storage","install_webcli","update_dns","update_entrance_services","create_host_id_list"} // "install_docker","install_k8s","install_manage_ready","install_network","install_plugins","install_storage","install_webcli","update_dns","update_entrance_services","create_host_id_list"}
for _,v:=range nextTask{ for _, v := range nextTask {
task,err:=taskService.GetTask(v) task, err := taskService.GetTask(v)
if err != nil { if err != nil {
return nil,err return nil, err
} }
result=append(result, task) result = append(result, task)
} }
return result,nil return result, nil
} }
func (ts *TaskService)GetTasksByNode(n *model.HostNode)([]*model.Task,*utils.APIHandleError) {
if n.Role.HasRule("compute") &&len(n.Role)==1{ //GetTasksByNode get tasks by node
checkTask:=[]string{"check_compute_services"} func (ts *TaskService) GetTasksByNode(n *model.HostNode) ([]*model.Task, *utils.APIHandleError) {
if n.Role.HasRule("compute") && len(n.Role) == 1 {
checkTask := []string{"check_compute_services"}
//tids:=[]string{"install_compute_ready","update_dns_compute","install_storage_client","install_network_compute","install_plugins_compute","install_docker_compute","install_kubelet"} //tids:=[]string{"install_compute_ready","update_dns_compute","install_storage_client","install_network_compute","install_plugins_compute","install_docker_compute","install_kubelet"}
result,err:=ts.getTasksByCheck(checkTask,n.ID) result, err := ts.getTasksByCheck(checkTask, n.ID)
if err != nil { if err != nil {
return nil,err return nil, err
} }
return result,nil return result, nil
}else if n.Role.HasRule("manage") &&len(n.Role)==1{ } else if n.Role.HasRule("manage") && len(n.Role) == 1 {
//checkTask:=[]string{"check_manage_base_services","check_manage_services"} //checkTask:=[]string{"check_manage_base_services","check_manage_services"}
checkTask:=[]string{"check_manage_services"} checkTask := []string{"check_manage_services"}
result,err:=ts.getTasksByCheck(checkTask,n.ID) result, err := ts.getTasksByCheck(checkTask, n.ID)
if err != nil { if err != nil {
return nil,err return nil, err
} }
return result,nil return result, nil
}else { } else {
//checkTask:=[]string{"check_manage_base_services","check_manage_services","check_compute_services"} //checkTask:=[]string{"check_manage_base_services","check_manage_services","check_compute_services"}
checkTask:=[]string{"check_manage_services","check_compute_services"} checkTask := []string{"check_manage_services", "check_compute_services"}
//tids:=[]string{"do_rbd_images","install_acp_plugins","install_base_plugins","install_db","install_docker","install_k8s","install_manage_ready","install_network","install_plugins","install_storage","install_webcli","update_dns","update_entrance_services","create_host_id_list","install_kubelet_manage","install_compute_ready_manage"} //tids:=[]string{"do_rbd_images","install_acp_plugins","install_base_plugins","install_db","install_docker","install_k8s","install_manage_ready","install_network","install_plugins","install_storage","install_webcli","update_dns","update_entrance_services","create_host_id_list","install_kubelet_manage","install_compute_ready_manage"}
result,err:=ts.getTasksByCheck(checkTask,n.ID) result, err := ts.getTasksByCheck(checkTask, n.ID)
if err != nil { if err != nil {
return nil,err return nil, err
} }
return result,nil return result, nil
} }
} }
//AddTask add task //AddTask add task
func (ts *TaskService) AddTask(t *model.Task) *utils.APIHandleError { func (ts *TaskService) AddTask(t *model.Task) *utils.APIHandleError {
if t.ID == "" { if t.ID == "" {
@ -181,7 +184,7 @@ func (ts *TaskService) GetTasks() ([]*model.Task, *utils.APIHandleError) {
return result, nil return result, nil
} }
//GetTask 获取Task //GetTask get task by taskID
func (ts *TaskService) GetTask(taskID string) (*model.Task, *utils.APIHandleError) { func (ts *TaskService) GetTask(taskID string) (*model.Task, *utils.APIHandleError) {
var task *model.Task var task *model.Task
task = ts.ms.TaskEngine.GetTask(taskID) task = ts.ms.TaskEngine.GetTask(taskID)
@ -191,7 +194,7 @@ func (ts *TaskService) GetTask(taskID string) (*model.Task, *utils.APIHandleErro
return task, nil return task, nil
} }
//DeleteTask 删除Task //DeleteTask delete task by taskID
func (ts *TaskService) DeleteTask(taskID string) *utils.APIHandleError { func (ts *TaskService) DeleteTask(taskID string) *utils.APIHandleError {
task, err := ts.GetTask(taskID) task, err := ts.GetTask(taskID)
if err != nil { if err != nil {
@ -219,7 +222,7 @@ func (ts *TaskService) DeleteTask(taskID string) *utils.APIHandleError {
return nil return nil
} }
//ExecTask 执行任务API处理 //ExecTask exec a task in nodes
func (ts *TaskService) ExecTask(taskID string, nodes []string) *utils.APIHandleError { func (ts *TaskService) ExecTask(taskID string, nodes []string) *utils.APIHandleError {
t, err := ts.GetTask(taskID) t, err := ts.GetTask(taskID)
if err != nil { if err != nil {
@ -260,7 +263,7 @@ func (ts *TaskService) ReloadStaticTasks() {
ts.ms.TaskEngine.LoadStaticTask() ts.ms.TaskEngine.LoadStaticTask()
} }
//TaskTempService 任务模版 //TaskTempService task temp service
type TaskTempService struct { type TaskTempService struct {
SavePath string SavePath string
conf *option.Conf conf *option.Conf
@ -268,7 +271,7 @@ type TaskTempService struct {
var taskTempService *TaskTempService var taskTempService *TaskTempService
//CreateTaskTempService 创建Task service //CreateTaskTempService create task temp service
func CreateTaskTempService(c *option.Conf) *TaskTempService { func CreateTaskTempService(c *option.Conf) *TaskTempService {
if taskTempService == nil { if taskTempService == nil {
taskTempService = &TaskTempService{ taskTempService = &TaskTempService{
@ -279,7 +282,7 @@ func CreateTaskTempService(c *option.Conf) *TaskTempService {
return taskTempService return taskTempService
} }
//SaveTaskTemp add task //SaveTaskTemp add task temp
func (ts *TaskTempService) SaveTaskTemp(t *model.TaskTemp) *utils.APIHandleError { func (ts *TaskTempService) SaveTaskTemp(t *model.TaskTemp) *utils.APIHandleError {
if t.ID == "" { if t.ID == "" {
t.ID = uuid.NewV4().String() t.ID = uuid.NewV4().String()
@ -294,7 +297,7 @@ func (ts *TaskTempService) SaveTaskTemp(t *model.TaskTemp) *utils.APIHandleError
return nil return nil
} }
//GetTaskTemp add task //GetTaskTemp get task temp
func (ts *TaskTempService) GetTaskTemp(tempID string) (*model.TaskTemp, *utils.APIHandleError) { func (ts *TaskTempService) GetTaskTemp(tempID string) (*model.TaskTemp, *utils.APIHandleError) {
res, err := store.DefalutClient.Get(ts.SavePath + "/" + tempID) res, err := store.DefalutClient.Get(ts.SavePath + "/" + tempID)
if err != nil { if err != nil {
@ -314,7 +317,7 @@ func (ts *TaskTempService) GetTaskTemp(tempID string) (*model.TaskTemp, *utils.A
return &task, nil return &task, nil
} }
//DeleteTaskTemp 删除任务模版 //DeleteTaskTemp delete task temp
func (ts *TaskTempService) DeleteTaskTemp(tempID string) *utils.APIHandleError { func (ts *TaskTempService) DeleteTaskTemp(tempID string) *utils.APIHandleError {
_, err := ts.GetTaskTemp(tempID) _, err := ts.GetTaskTemp(tempID)
if err != nil { if err != nil {
@ -327,7 +330,7 @@ func (ts *TaskTempService) DeleteTaskTemp(tempID string) *utils.APIHandleError {
return nil return nil
} }
//TaskGroupService 任务组 //TaskGroupService task group
type TaskGroupService struct { type TaskGroupService struct {
SavePath string SavePath string
conf *option.Conf conf *option.Conf
@ -336,7 +339,7 @@ type TaskGroupService struct {
var taskGroupService *TaskGroupService var taskGroupService *TaskGroupService
//CreateTaskGroupService 创建Task group service //CreateTaskGroupService create Task group service
func CreateTaskGroupService(c *option.Conf, ms *masterserver.MasterServer) *TaskGroupService { func CreateTaskGroupService(c *option.Conf, ms *masterserver.MasterServer) *TaskGroupService {
if taskGroupService == nil { if taskGroupService == nil {
taskGroupService = &TaskGroupService{ taskGroupService = &TaskGroupService{
@ -393,7 +396,7 @@ func (ts *TaskGroupService) GetTaskGroups() ([]*model.TaskGroup, *utils.APIHandl
return tasks, nil return tasks, nil
} }
//GetTaskGroup 获取Task //GetTaskGroup get Task group
func (ts *TaskGroupService) GetTaskGroup(taskGroupID string) (*model.TaskGroup, *utils.APIHandleError) { func (ts *TaskGroupService) GetTaskGroup(taskGroupID string) (*model.TaskGroup, *utils.APIHandleError) {
res, err := store.DefalutClient.Get(ts.SavePath + "/" + taskGroupID) res, err := store.DefalutClient.Get(ts.SavePath + "/" + taskGroupID)
if err != nil { if err != nil {
@ -413,8 +416,8 @@ func (ts *TaskGroupService) GetTaskGroup(taskGroupID string) (*model.TaskGroup,
return &task, nil return &task, nil
} }
//DeleteTaskGroup 删除TaskGroup //DeleteTaskGroup delete TaskGroup
//删除Group不删除包含的Task //delete group but do not delete task in this group
func (ts *TaskGroupService) DeleteTaskGroup(taskGroupID string) *utils.APIHandleError { func (ts *TaskGroupService) DeleteTaskGroup(taskGroupID string) *utils.APIHandleError {
taskGroup, err := ts.GetTaskGroup(taskGroupID) taskGroup, err := ts.GetTaskGroup(taskGroupID)
if err != nil { if err != nil {
@ -430,7 +433,7 @@ func (ts *TaskGroupService) DeleteTaskGroup(taskGroupID string) *utils.APIHandle
return nil return nil
} }
//ExecTaskGroup 执行组任务API处理 //ExecTaskGroup exec group task
func (ts *TaskGroupService) ExecTaskGroup(taskGroupID string, nodes []string) *utils.APIHandleError { func (ts *TaskGroupService) ExecTaskGroup(taskGroupID string, nodes []string) *utils.APIHandleError {
t, err := ts.GetTaskGroup(taskGroupID) t, err := ts.GetTaskGroup(taskGroupID)
if err != nil { if err != nil {