2 * Copyright 2020 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 "mepserver/mp1/arch/bus"
34 func WkRun(plan SpaceIf) ErrCode {
35 curPlan := plan.getPlan()
37 if curPlan.CurGrpIdx >= len(curPlan.PlanGrp) {
40 curSub := &curPlan.PlanGrp[curPlan.CurGrpIdx]
41 retCode, stepIdx := GrpRun(curSub, plan, &curPlan.WtPlan)
42 if retCode <= TaskOK {
46 RecordErrInfo(curPlan, stepIdx)
47 GotoErrorProc(curPlan)
49 // wait backgroud job finish
55 func TaskRunner(wkSpace interface{}, stepIf TaskBaseIf) int {
57 bus.LoadObjByInd(stepIf, wkSpace, "in")
58 retCode := stepIf.OnRequest("")
59 if retCode <= TaskFinish {
60 bus.LoadObjByInd(stepIf, wkSpace, "out")
67 func StepPolicy(wg *sync.WaitGroup, curSub *SubGrp, plan SpaceIf, wtPlan *sync.WaitGroup, stepIf TaskBaseIf) ErrCode {
69 switch curSub.Policy {
74 TaskRunner(plan, stepIf)
81 TaskRunner(plan, stepIf)
84 TaskRunner(plan, stepIf)
85 taskRet, _ = stepIf.GetErrCode()
91 func GrpOneStep(wg *sync.WaitGroup, curSub *SubGrp, plan SpaceIf, wtPlan *sync.WaitGroup) bool {
92 if curSub.CurStepIdx >= len(curSub.StepObjs) {
95 curStep := curSub.StepObjs[curSub.CurStepIdx]
100 stepIf, ok := curStep.(TaskBaseIf)
104 taskRet := StepPolicy(wg, curSub, plan, wtPlan, stepIf)
107 return taskRet <= TaskOK
110 func GrpGetRetCode(curSub *SubGrp) (ErrCode, int) {
111 for idx, curStep := range curSub.StepObjs {
112 stepIf, ok := curStep.(TaskBaseIf)
116 errCode, _ := stepIf.GetErrCode()
117 if errCode > TaskOK {
125 func GrpRun(curSub *SubGrp, plan SpaceIf, wtPlan *sync.WaitGroup) (ErrCode, int) {
126 var wg sync.WaitGroup
128 nextStep := GrpOneStep(&wg, curSub, plan, wtPlan)
133 if curSub.Policy == GoParallel {
136 return GrpGetRetCode(curSub)