You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2023/05/29 13:19:11 UTC
[incubator-devlake] branch main updated: Skip empty blueprint (#5308)
This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 51a7399ea Skip empty blueprint (#5308)
51a7399ea is described below
commit 51a7399eaf7eb28734d102bc96ef3a903c67b468
Author: Liang Zhang <li...@merico.dev>
AuthorDate: Mon May 29 21:19:06 2023 +0800
Skip empty blueprint (#5308)
* feat: skip empty blueprint
* feat: allow empty plan in advance mode
---
backend/core/plugin/plugin_blueprint.go | 13 +++++++
backend/core/plugin/plugin_blueprint_test.go | 53 ++++++++++++++++++++++++++++
backend/server/services/blueprint.go | 26 +++++++++++---
3 files changed, 88 insertions(+), 4 deletions(-)
diff --git a/backend/core/plugin/plugin_blueprint.go b/backend/core/plugin/plugin_blueprint.go
index 644163015..30671af50 100644
--- a/backend/core/plugin/plugin_blueprint.go
+++ b/backend/core/plugin/plugin_blueprint.go
@@ -38,6 +38,19 @@ type PipelineStage []*PipelineTask
// PipelinePlan consist of multiple PipelineStages, they will be executed in sequential order
type PipelinePlan []PipelineStage
+// IsEmpty checks if a PipelinePlan is empty
+func (plan PipelinePlan) IsEmpty() bool {
+ if len(plan) == 0 {
+ return true
+ }
+ for _, stage := range plan {
+ if len(stage) > 0 {
+ return false
+ }
+ }
+ return true
+}
+
// PluginBlueprintV100 is used to support Blueprint Normal model, for Plugin and Blueprint to
// collaboarte and generate a sophisticated Pipeline Plan based on User Settings.
// V100 doesn't support Project, and being deprecated, please use PluginBlueprintV200 instead
diff --git a/backend/core/plugin/plugin_blueprint_test.go b/backend/core/plugin/plugin_blueprint_test.go
new file mode 100644
index 000000000..e19ebe86b
--- /dev/null
+++ b/backend/core/plugin/plugin_blueprint_test.go
@@ -0,0 +1,53 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package plugin
+
+import (
+ "github.com/stretchr/testify/assert"
+ "testing"
+)
+
+func TestPipelinePlan_IsEmpty(t *testing.T) {
+ tests := []struct {
+ name string
+ plan PipelinePlan
+ want bool
+ }{
+ {
+ name: "empty",
+ plan: PipelinePlan{},
+ want: true,
+ },
+ {
+ name: "empty",
+ plan: []PipelineStage{{}, {}},
+ want: true,
+ },
+ {
+ name: "empty",
+ plan: []PipelineStage{{}, {&PipelineTask{}}},
+ want: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ t.Log("length of plan is", len(tt.plan))
+ assert.Equalf(t, tt.want, tt.plan.IsEmpty(), "IsEmpty()")
+ })
+ }
+}
diff --git a/backend/server/services/blueprint.go b/backend/server/services/blueprint.go
index f89438d6b..1ab97fb15 100644
--- a/backend/server/services/blueprint.go
+++ b/backend/server/services/blueprint.go
@@ -34,6 +34,7 @@ import (
var (
blueprintLog = logruslog.Global.Nested("blueprint")
+ ErrEmptyPlan = errors.Default.New("empty plan")
)
// BlueprintQuery is a query for GetBlueprints
@@ -51,6 +52,10 @@ type BlueprintJob struct {
func (bj BlueprintJob) Run() {
blueprint := bj.Blueprint
pipeline, err := createPipelineByBlueprint(blueprint)
+ if err == ErrEmptyPlan {
+ blueprintLog.Info("Empty plan, blueprint id:[%d] blueprint name:[%s]", blueprint.ID, blueprint.Name)
+ return
+ }
if err != nil {
blueprintLog.Error(err, fmt.Sprintf("run cron job failed on blueprint:[%d][%s]", blueprint.ID, blueprint.Name))
} else {
@@ -161,10 +166,6 @@ func validateBlueprintAndMakePlan(blueprint *models.Blueprint) errors.Error {
if err != nil {
return errors.Default.Wrap(err, "invalid plan")
}
- // tasks should not be empty
- if len(plan) == 0 || len(plan[0]) == 0 {
- return errors.Default.New("empty plan")
- }
} else if blueprint.Mode == models.BLUEPRINT_MODE_NORMAL {
plan, err := MakePlanForBlueprint(blueprint)
if err != nil {
@@ -293,6 +294,23 @@ func createPipelineByBlueprint(blueprint *models.Blueprint) (*models.Pipeline, e
newPipeline.BlueprintId = blueprint.ID
newPipeline.Labels = blueprint.Labels
newPipeline.SkipOnFail = blueprint.SkipOnFail
+
+ // if the plan is empty, we should not create the pipeline
+ var shouldCreatePipeline bool
+ for _, stage := range plan {
+ for _, task := range stage {
+ switch task.Plugin {
+ case "org", "refdiff", "dora":
+ default:
+ if !plan.IsEmpty() {
+ shouldCreatePipeline = true
+ }
+ }
+ }
+ }
+ if !shouldCreatePipeline {
+ return nil, ErrEmptyPlan
+ }
pipeline, err := CreatePipeline(&newPipeline)
// Return all created tasks to the User
if err != nil {