Skip to content

Commit

Permalink
make task action can be disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
chengjoey committed Oct 20, 2021
1 parent 4c05ade commit a360ffc
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 45 deletions.
1 change: 1 addition & 0 deletions .erda/migrations/qa/20211015-auto-test-step-disable.sql
@@ -0,0 +1 @@
ALTER TABLE dice_autotest_scene_step ADD COLUMN `is_disabled` bool DEFAULT false COMMENT 'disable or enable execute';
2 changes: 1 addition & 1 deletion api/proto-go/core/pipeline/base/pb/base.validator.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 20 additions & 18 deletions apistructs/autotest_scene.go
Expand Up @@ -88,18 +88,19 @@ type AutoTestSceneOutput struct {

type AutoTestSceneStep struct {
AutoTestSceneParams
Type StepAPIType `json:"type"` // 类型
Method StepAPIMethod `json:"method"` // method
Value string `json:"value"` // 值
Name string `json:"name"` // 名称
PreID uint64 `json:"preID"` // 排序id
PreType PreType `json:"preType"` // 串行/并行类型
SceneID uint64 `json:"sceneID"` // 场景ID
SpaceID uint64 `json:"spaceID"` // 所属测试空间ID
CreatorID string `json:"creatorID"`
UpdaterID string `json:"updaterID"`
Children []AutoTestSceneStep // 并行子节点
APISpecID uint64 `json:"apiSpecID"` // api集市id
Type StepAPIType `json:"type"` // 类型
Method StepAPIMethod `json:"method"` // method
Value string `json:"value"` // 值
Name string `json:"name"` // 名称
PreID uint64 `json:"preID"` // 排序id
PreType PreType `json:"preType"` // 串行/并行类型
SceneID uint64 `json:"sceneID"` // 场景ID
SpaceID uint64 `json:"spaceID"` // 所属测试空间ID
IsDisabled bool `json:"isDisabled"` // disable or enable step execute
CreatorID string `json:"creatorID"`
UpdaterID string `json:"updaterID"`
Children []AutoTestSceneStep // 并行子节点
APISpecID uint64 `json:"apiSpecID"` // api集市id
}

type AutotestSceneRequest struct {
Expand All @@ -113,12 +114,13 @@ type AutotestSceneRequest struct {
APISpecID uint64 `json:"apiSpecID,omitempty"` // api集市id
RefSetID uint64 `json:"refSetID,omitempty"` // 引用场景集的ID

Type StepAPIType `json:"type,omitempty"`
Target int64 `json:"target,omitempty"` // 目标位置
GroupID int64 `json:"groupID,omitempty"` // 串行ID
PreType PreType `json:"preType,omitempty"` // 并行/并行
Position int64 `json:"position,omitempty"` // 插入位置 (-1为前/1为后)
IsGroup bool `json:"isGroup,omitempty"` // 是否整组移动
Type StepAPIType `json:"type,omitempty"`
Target int64 `json:"target,omitempty"` // 目标位置
GroupID int64 `json:"groupID,omitempty"` // 串行ID
PreType PreType `json:"preType,omitempty"` // 并行/并行
Position int64 `json:"position,omitempty"` // 插入位置 (-1为前/1为后)
IsGroup bool `json:"isGroup,omitempty"` // 是否整组移动
IsDisabled *bool `json:"isDisabled,omitempty"` // disable or enable step execute

PageNo uint64 `json:"pageNo"`
PageSize uint64 `json:"pageSize"`
Expand Down
1 change: 1 addition & 0 deletions apistructs/component_protocol.go
Expand Up @@ -167,6 +167,7 @@ const (
AutoTestSceneStepMoveGroupOperationKey OperationKey = "moveGroup"
AutoTestSceneStepDeleteOperationKey OperationKey = "deleteAPI"
AutoTestSceneStepSplitOperationKey OperationKey = "standalone"
AutoTestSceneStepSwitchOperationKey OperationKey = "switch"

//auto-test scene set
ListSceneSetOperationKey OperationKey = "ListSceneSet"
Expand Down
4 changes: 4 additions & 0 deletions apistructs/pipeline_status.go
Expand Up @@ -235,6 +235,10 @@ func (status PipelineStatus) IsAbnormalFailedStatus() bool {
}
}

func (status PipelineStatus) IsDisabledStatus() bool {
return status == PipelineStatusDisabled
}

func (status PipelineStatus) IsFailedStatus() bool {
return status.IsNormalFailedStatus() || status.IsAbnormalFailedStatus()
}
Expand Down
38 changes: 20 additions & 18 deletions modules/dop/dao/autotest_scene_step.go
Expand Up @@ -25,16 +25,17 @@ import (

type AutoTestSceneStep struct {
dbengine.BaseModel
Type apistructs.StepAPIType `gorm:"type"` // 类型
Value string `gorm:"value"` // 值
Name string `gorm:"name"` // 名称
PreID uint64 `gorm:"pre_id"` // 排序id
PreType apistructs.PreType `gorm:"pre_type"` // 串行/并行类型
SceneID uint64 `gorm:"scene_id"` // 场景ID
SpaceID uint64 `gorm:"space_id"` // 所属测试空间ID
APISpecID uint64 `gorm:"column:api_spec_id"` // api集市id
CreatorID string `gorm:"creator_id"`
UpdaterID string `gorm:"updater_id"`
Type apistructs.StepAPIType `gorm:"type"` // 类型
Value string `gorm:"value"` // 值
Name string `gorm:"name"` // 名称
PreID uint64 `gorm:"pre_id"` // 排序id
PreType apistructs.PreType `gorm:"pre_type"` // 串行/并行类型
SceneID uint64 `gorm:"scene_id"` // 场景ID
SpaceID uint64 `gorm:"space_id"` // 所属测试空间ID
APISpecID uint64 `gorm:"column:api_spec_id"` // api集市id
IsDisabled bool `gorm:"is_disabled"` // disable or enable step execute
CreatorID string `gorm:"creator_id"`
UpdaterID string `gorm:"updater_id"`
}

func (AutoTestSceneStep) TableName() string {
Expand All @@ -54,14 +55,15 @@ func (v *AutoTestSceneStep) Convert() *apistructs.AutoTestSceneStep {
CreatorID: v.CreatorID,
UpdaterID: v.UpdaterID,
},
Type: v.Type,
Name: v.Name,
Value: v.Value,
PreID: v.PreID,
PreType: v.PreType,
SceneID: v.SceneID,
SpaceID: v.SpaceID,
APISpecID: v.APISpecID,
Type: v.Type,
Name: v.Name,
Value: v.Value,
PreID: v.PreID,
PreType: v.PreType,
SceneID: v.SceneID,
SpaceID: v.SpaceID,
IsDisabled: v.IsDisabled,
APISpecID: v.APISpecID,
}
}

Expand Down
1 change: 1 addition & 0 deletions modules/dop/services/autotest_v2/scene.go
Expand Up @@ -759,6 +759,7 @@ func StepToAction(step apistructs.AutoTestSceneStep) (map[pipelineyml.ActionType
action.Labels[apistructs.AutotestType] = apistructs.AutotestSceneStep
action.Alias = pipelineyml.ActionAlias(strconv.Itoa(int(step.ID)))
action.If = expression.LeftPlaceholder + " 1 == 1 " + expression.RightPlaceholder
action.Disable = step.IsDisabled

switch step.Type {
case apistructs.StepTypeCustomScript:
Expand Down
3 changes: 3 additions & 0 deletions modules/dop/services/autotest_v2/scene_step.go
Expand Up @@ -114,6 +114,9 @@ func (svc *Service) UpdateAutoTestSceneStep(req apistructs.AutotestSceneRequest)
step.Name = req.Name
step.UpdaterID = req.UserID
step.APISpecID = req.APISpecID
if req.IsDisabled != nil {
step.IsDisabled = *req.IsDisabled
}
if err := svc.db.UpdateAutotestSceneStep(step); err != nil {
return 0, err
}
Expand Down
Expand Up @@ -50,6 +50,7 @@ type PropColumn struct {
ValueKey string `json:"valueKey"`
RenderType string `json:"renderType"`
Operations map[apistructs.OperationKey]apistructs.Operation `json:"operations"`
Tips string `json:"tips"`
}

type State struct {
Expand Down Expand Up @@ -216,6 +217,7 @@ Label:
{
Label: "接口总数",
ValueKey: "autoTestNum",
Tips: "接口总数不包括禁用接口",
},
{
Label: "接口执行率",
Expand Down
Expand Up @@ -279,6 +279,9 @@ func getStatus(req apistructs.PipelineStatus) map[string]interface{} {
if req.IsBeforePressRunButton() {
res["status"] = "default"
}
if req.IsDisabledStatus() {
res["status"] = "default"
}
return res
}

Expand Down Expand Up @@ -376,18 +379,26 @@ func (a *ExecuteTaskTable) setData(pipeline *apistructs.PipelineDetailDTO) error
res.Type = apistructs.StepAPIType(task.Type)
}
operations := map[string]interface{}{}
disable := false
if task.Status.IsDisabledStatus() {
disable = true
}
if res.Type == apistructs.StepTypeAPI || res.Type == apistructs.StepTypeWait || res.Type == apistructs.StepTypeCustomScript {
operations = map[string]interface{}{
"checkDetail": dataOperation{
Key: "checkDetail",
Text: "查看结果",
Reload: false,
Meta: task.Result,
Key: "checkDetail",
Text: "查看结果",
Reload: false,
Disabled: disable,
DisabledTip: "禁用接口无法查看结果和日志",
Meta: task.Result,
},
"checkLog": dataOperation{
Key: "checkLog",
Reload: false,
Text: "日志",
Key: "checkLog",
Reload: false,
Text: "日志",
Disabled: disable,
DisabledTip: "禁用接口无法查看结果和日志",
Meta: map[string]interface{}{
"logId": task.Extra.UUID,
"pipelineId": a.State.PipelineID,
Expand Down
Expand Up @@ -45,6 +45,7 @@ type StageData struct {
Title string `json:"title"`
ID uint64 `json:"id"`
GroupID int64 `json:"groupId"`
Disabled bool `json:"disabled"`
Operations map[string]interface{} `json:"operations"`
}

Expand Down Expand Up @@ -97,6 +98,7 @@ type OpMetaData struct {
Name string `json:"name"` // 名称
APISpecID uint64 `json:"apiSpecID"` // api集市id
ID uint64 `json:"id"`
Disable bool `json:"disable"`
}

type OpMetaInfo struct {
Expand Down
Expand Up @@ -211,6 +211,15 @@ func (i *ComponentStageForm) Render(ctx context.Context, c *apistructs.Component
if err != nil {
return err
}
case apistructs.AutoTestSceneStepSwitchOperationKey:
err = i.RenderDisableStagesForm(event.OperationData)
if err != nil {
return err
}
err = i.RenderListStageForm()
if err != nil {
return err
}
case "clickItem":
data, err := GetOpsInfo(event.OperationData)
if err != nil {
Expand Down
Expand Up @@ -79,6 +79,7 @@ func RenderStage(groupID uint64, step apistructs.AutoTestSceneStep) (StageData,
Title: title,
ID: step.ID,
GroupID: int64(groupID),
Disabled: step.IsDisabled,
Operations: make(map[string]interface{}),
}
if step.Type == apistructs.StepTypeAPI {
Expand Down Expand Up @@ -125,13 +126,24 @@ func RenderStage(groupID uint64, step apistructs.AutoTestSceneStep) (StageData,
oc.Disabled = false
oc.Reload = true
oc.Confirm = "是否确认删除"
oc.HoverShow = true
oc.Meta = OpMetaInfo{AutotestSceneRequest: apistructs.AutotestSceneRequest{
AutoTestSceneParams: apistructs.AutoTestSceneParams{
ID: pd.ID,
},
}}
pd.Operations["delete"] = oc

od := OperationInfo{}
od.Key = apistructs.AutoTestSceneStepSwitchOperationKey.String()
od.Reload = true
od.Meta = OpMetaInfo{
Data: OpMetaData{
ID: step.ID,
Disable: step.IsDisabled,
},
}
pd.Operations["switch"] = od
return pd, nil
}

Expand Down Expand Up @@ -256,6 +268,38 @@ func (i *ComponentStageForm) RenderDeleteStagesForm(opsData interface{}) error {
return nil
}

func (i *ComponentStageForm) RenderDisableStagesForm(opsData interface{}) error {
meta, err := GetOpsInfo(opsData)
if err != nil {
return err
}
var d bool
if !meta.Data.Disable {
d = true
}
oldStep, err := i.ctxBdl.Bdl.GetAutoTestSceneStep(apistructs.AutotestGetSceneStepReq{
ID: meta.Data.ID,
})
if err != nil {
return err
}
i.State.AutotestSceneRequest.IsDisabled = &d
i.State.AutotestSceneRequest.ID = meta.Data.ID
i.State.AutotestSceneRequest.Name = oldStep.Name
i.State.AutotestSceneRequest.Type = oldStep.Type
i.State.AutotestSceneRequest.Value = oldStep.Value
i.State.AutotestSceneRequest.SpaceID = oldStep.SpaceID
i.State.AutotestSceneRequest.SceneID = oldStep.SceneID
i.State.AutotestSceneRequest.UpdaterID = i.ctxBdl.Identity.UserID
i.State.AutotestSceneRequest.APISpecID = oldStep.APISpecID
id, err := i.ctxBdl.Bdl.UpdateAutoTestSceneStep(i.State.AutotestSceneRequest)
if err != nil {
return err
}
i.State.StepId = id
return nil
}

func (i *ComponentStageForm) RenderMoveStagesForm() error {
req := apistructs.AutotestSceneRequest{
SceneID: i.State.AutotestSceneRequest.SceneID,
Expand Down
2 changes: 1 addition & 1 deletion modules/pipeline/services/pipelinesvc/create.go
Expand Up @@ -274,7 +274,7 @@ func ymlTasksMergeDBTasks(actionTasks []spec.PipelineTask, dbTasks []spec.Pipeli
return mergeTasks
}

// determine whether the task status is disabled according to the TaskOperates of the pipeline
// determine whether the task status is disabled according to the TaskOperates of the pipeline and task extra disable field
func (s *PipelineSvc) OperateTask(p *spec.Pipeline, task *spec.PipelineTask) (*spec.PipelineTask, error) {
for _, taskOp := range p.Extra.TaskOperates {
// the name of the disabled task matches the task name
Expand Down
4 changes: 4 additions & 0 deletions modules/pipeline/services/pipelinesvc/create_task.go
Expand Up @@ -85,6 +85,10 @@ func (s *PipelineSvc) makeNormalPipelineTask(p *spec.Pipeline, ps *spec.Pipeline
if task.Extra.Pause {
task.Status = apistructs.PipelineStatusPaused
}
// if action is disabled, set task status disabled directly
if action.Disable {
task.Status = apistructs.PipelineStatusDisabled
}
task.CostTimeSec = -1
task.QueueTimeSec = -1

Expand Down
2 changes: 2 additions & 0 deletions pkg/parser/pipelineyml/define.go
Expand Up @@ -138,6 +138,8 @@ type Action struct {

If string `yaml:"if,omitempty"` // 条件执行

Disable bool `yaml:"disable"` // make task disable or enable

// TODO 在未来版本中,可能去除 stage,依赖关系则必须通过 Needs 来声明。
// 目前不开放给用户使用。由 parser 自动赋值。
// Needs 显式声明依赖的 actions。隐式依赖关系是下一个 stage 依赖之前所有 stage 里的 action。
Expand Down

0 comments on commit a360ffc

Please sign in to comment.