You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by kl...@apache.org on 2023/11/01 07:38:10 UTC

(incubator-devlake) branch main updated: fix(bamboo): fix cicd_deployment_commits.id, remove `PlanResultKey` from primary key list from BambooDeployBuild (#6375)

This is an automated email from the ASF dual-hosted git repository.

klesh 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 bc21bd877 fix(bamboo): fix cicd_deployment_commits.id, remove `PlanResultKey` from primary key list from BambooDeployBuild (#6375)
bc21bd877 is described below

commit bc21bd877cd61d1cfc007ebc4636864a94ca6b73
Author: Lynwee <li...@merico.dev>
AuthorDate: Wed Nov 1 15:38:06 2023 +0800

    fix(bamboo): fix cicd_deployment_commits.id, remove `PlanResultKey` from primary key list from BambooDeployBuild (#6375)
    
    * fix(bamboo): fix cicd_deployment_commits.id, remove `PlanResultKey` from primary key list from BambooDeployBuild
    
    * fix(bamboo): remove unused file
    
    * fix(bamboo): fix e2e test
    
    * docs(bamboot): add some comments
---
 backend/core/dal/dal.go                            |  2 +-
 .../snapshot_tables/cicd_deployment_commits.csv    | 14 ++++-----
 backend/plugins/bamboo/models/deploy_build.go      |  2 +-
 .../plugins/bamboo/tasks/deploy_build_convertor.go | 33 ++++++++++++++++++----
 4 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/backend/core/dal/dal.go b/backend/core/dal/dal.go
index 5737922bd..48cc36010 100644
--- a/backend/core/dal/dal.go
+++ b/backend/core/dal/dal.go
@@ -127,7 +127,7 @@ type Dal interface {
 	Fetch(cursor Rows, dst interface{}) errors.Error
 	// All loads matched rows from database to `dst`, USE IT WITH CAUTIOUS!!
 	All(dst interface{}, clauses ...Clause) errors.Error
-	// First loads first matched row from database to `dst`, error will be returned if no records were found
+	// First loads the first matched row from database to `dst`, error will be returned if no records were found
 	First(dst interface{}, clauses ...Clause) errors.Error
 	// Count matched rows from database
 	Count(clauses ...Clause) (int64, errors.Error)
diff --git a/backend/plugins/bamboo/e2e/snapshot_tables/cicd_deployment_commits.csv b/backend/plugins/bamboo/e2e/snapshot_tables/cicd_deployment_commits.csv
index 688263102..c4773a80e 100644
--- a/backend/plugins/bamboo/e2e/snapshot_tables/cicd_deployment_commits.csv
+++ b/backend/plugins/bamboo/e2e/snapshot_tables/cicd_deployment_commits.csv
@@ -1,8 +1,8 @@
 id,commit_sha,cicd_scope_id,cicd_deployment_id,name,result,status,environment,created_date,started_date,finished_date,duration_sec,ref_name,repo_id,repo_url,prev_success_deployment_commit_id
-bamboo:BambooDeployBuild:1:1540097:TEST-PLA2-11,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540097:TEST-PLA2-11,release-1,FAILURE,DONE,dev,2023-07-31T10:16:41.000+00:00,2023-07-31T10:16:41.000+00:00,2023-07-31T10:16:41.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
-bamboo:BambooDeployBuild:1:1540100:TEST-PLA2-11,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540100:TEST-PLA2-11,release-1,FAILURE,DONE,dev,2023-07-31T11:50:10.000+00:00,2023-07-31T11:50:10.000+00:00,2023-07-31T11:50:10.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
-bamboo:BambooDeployBuild:1:1540101:TEST-PLA2-11,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540101:TEST-PLA2-11,release-2,FAILURE,DONE,dev,2023-07-31T11:51:14.000+00:00,2023-07-31T11:51:14.000+00:00,2023-07-31T11:51:14.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
-bamboo:BambooDeployBuild:1:1540102:TEST-PLA2-11,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540102:TEST-PLA2-11,release-2,SUCCESS,DONE,dev,2023-07-31T11:52:32.000+00:00,2023-07-31T11:52:32.000+00:00,2023-07-31T11:52:32.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
-bamboo:BambooDeployBuild:1:1540105:TEST-PLA2-11,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540105:TEST-PLA2-11,release-2,SUCCESS,DONE,dev,2023-08-01T09:31:53.000+00:00,2023-08-01T09:31:53.000+00:00,2023-08-01T09:31:53.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
-bamboo:BambooDeployBuild:1:1540106:TEST-PLA2-11,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540106:TEST-PLA2-11,release-2,SUCCESS,DONE,dev,2023-08-01T09:32:00.000+00:00,2023-08-01T09:32:00.000+00:00,2023-08-01T09:32:00.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
-bamboo:BambooDeployBuild:1:1540117:TEST-PLA2-12,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540117:TEST-PLA2-12,release-3,SUCCESS,DONE,dev,2023-08-03T09:49:07.000+00:00,2023-08-03T09:49:07.000+00:00,2023-08-03T09:49:07.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
+bamboo:deployBuildWithVcsRevision:1:1540097:622595,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:deployBuildWithVcsRevision:1:1540097:622595,release-1,FAILURE,DONE,dev,2023-07-31T10:16:41.000+00:00,2023-07-31T10:16:41.000+00:00,2023-07-31T10:16:41.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
+bamboo:deployBuildWithVcsRevision:1:1540100:622595,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:deployBuildWithVcsRevision:1:1540100:622595,release-1,FAILURE,DONE,dev,2023-07-31T11:50:10.000+00:00,2023-07-31T11:50:10.000+00:00,2023-07-31T11:50:10.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
+bamboo:deployBuildWithVcsRevision:1:1540101:622595,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:deployBuildWithVcsRevision:1:1540101:622595,release-2,FAILURE,DONE,dev,2023-07-31T11:51:14.000+00:00,2023-07-31T11:51:14.000+00:00,2023-07-31T11:51:14.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
+bamboo:deployBuildWithVcsRevision:1:1540102:622595,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:deployBuildWithVcsRevision:1:1540102:622595,release-2,SUCCESS,DONE,dev,2023-07-31T11:52:32.000+00:00,2023-07-31T11:52:32.000+00:00,2023-07-31T11:52:32.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
+bamboo:deployBuildWithVcsRevision:1:1540105:622595,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:deployBuildWithVcsRevision:1:1540105:622595,release-2,SUCCESS,DONE,dev,2023-08-01T09:31:53.000+00:00,2023-08-01T09:31:53.000+00:00,2023-08-01T09:31:53.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
+bamboo:deployBuildWithVcsRevision:1:1540106:622595,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:deployBuildWithVcsRevision:1:1540106:622595,release-2,SUCCESS,DONE,dev,2023-08-01T09:32:00.000+00:00,2023-08-01T09:32:00.000+00:00,2023-08-01T09:32:00.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
+bamboo:deployBuildWithVcsRevision:1:1540117:622595,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:deployBuildWithVcsRevision:1:1540117:622595,release-3,SUCCESS,DONE,dev,2023-08-03T09:49:07.000+00:00,2023-08-03T09:49:07.000+00:00,2023-08-03T09:49:07.000+00:00,0,,622595,fake://127.0.0.1:8080/repos/622595,
diff --git a/backend/plugins/bamboo/models/deploy_build.go b/backend/plugins/bamboo/models/deploy_build.go
index 1e291ff6a..6e9299eda 100644
--- a/backend/plugins/bamboo/models/deploy_build.go
+++ b/backend/plugins/bamboo/models/deploy_build.go
@@ -26,7 +26,7 @@ import (
 type BambooDeployBuild struct {
 	ConnectionId          uint64     `json:"connection_id" gorm:"primaryKey"`
 	DeployBuildId         uint64     `json:"deploy_build_id" gorm:"primaryKey"`
-	PlanResultKey         string     `json:"planResultKey"  gorm:"primaryKey"`
+	PlanResultKey         string     `json:"planResultKey"`
 	DeploymentVersionName string     `json:"deploymentVersionName"`
 	DeploymentState       string     `json:"deploymentState"`
 	LifeCycleState        string     `json:"lifeCycleState"`
diff --git a/backend/plugins/bamboo/tasks/deploy_build_convertor.go b/backend/plugins/bamboo/tasks/deploy_build_convertor.go
index cad5c5b2f..5b1bac142 100644
--- a/backend/plugins/bamboo/tasks/deploy_build_convertor.go
+++ b/backend/plugins/bamboo/tasks/deploy_build_convertor.go
@@ -19,6 +19,7 @@ package tasks
 
 import (
 	"fmt"
+	"github.com/apache/incubator-devlake/core/models/common"
 	"reflect"
 	"strconv"
 	"time"
@@ -41,9 +42,28 @@ var ConvertDeployBuildsMeta = plugin.SubTaskMeta{
 	DomainTypes:      []string{plugin.DOMAIN_TYPE_CICD},
 }
 
+// deployBuildWithVcsRevision is a virtual tool layer table,
+// it's used to store records from a complicated sql
+// and generate id field for table cicd_deployment_commits.
 type deployBuildWithVcsRevision struct {
-	models.BambooDeployBuild
-	RepositoryId    int
+	ConnectionId          uint64     `json:"connection_id" gorm:"primaryKey"`
+	DeployBuildId         uint64     `json:"deploy_build_id" gorm:"primaryKey"`
+	PlanResultKey         string     `json:"planResultKey" `
+	DeploymentVersionName string     `json:"deploymentVersionName"`
+	DeploymentState       string     `json:"deploymentState"`
+	LifeCycleState        string     `json:"lifeCycleState"`
+	StartedDate           *time.Time `json:"startedDate"`
+	QueuedDate            *time.Time `json:"queuedDate"`
+	ExecutedDate          *time.Time `json:"executedDate"`
+	FinishedDate          *time.Time `json:"finishedDate"`
+	ReasonSummary         string     `json:"reasonSummary"`
+	ProjectKey            string     `json:"project_key" gorm:"index"`
+	PlanKey               string     `json:"plan_key" gorm:"index"`
+	Environment           string     `gorm:"type:varchar(255)"`
+	PlanBranchName        string     `gorm:"type:varchar(255)"`
+	models.ApiBambooOperations
+	common.NoPKModel
+	RepositoryId    int `json:"repository_id" gorm:"primaryKey"`
 	RepositoryName  string
 	VcsRevisionKey  string
 	ProjectPlanName string
@@ -61,6 +81,8 @@ func ConvertDeployBuilds(taskCtx plugin.SubTaskContext) errors.Error {
 	db := taskCtx.GetDal()
 	logger := taskCtx.GetLogger()
 	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_JOB_BUILD_TABLE)
+	// INNER JOIN may cause loss of deploy entities here.
+	// It is not known that bamboo deploy can be associated with commits, so this is not an issue at the moment.
 	cursor, err := db.Cursor(
 		dal.Select("db.*, pbc.repository_id, pbc.repository_name, pbc.vcs_revision_key, p.name as project_plan_name, p.project_name"),
 		dal.From("_tool_bamboo_deploy_builds AS db"),
@@ -72,9 +94,7 @@ func ConvertDeployBuilds(taskCtx plugin.SubTaskContext) errors.Error {
 	}
 	defer cursor.Close()
 
-	deployBuildIdGen := didgen.NewDomainIdGenerator(&models.BambooDeployBuild{})
 	planIdGen := didgen.NewDomainIdGenerator(&models.BambooPlan{})
-
 	converter, err := api.NewDataConverter(api.DataConverterArgs{
 		InputRowType:       reflect.TypeOf(deployBuildWithVcsRevision{}),
 		Input:              cursor,
@@ -84,12 +104,13 @@ func ConvertDeployBuilds(taskCtx plugin.SubTaskContext) errors.Error {
 			if input.VcsRevisionKey == "" {
 				return nil, nil
 			}
+			deploymentCommitId := didgen.NewDomainIdGenerator(&deployBuildWithVcsRevision{}).Generate(data.Options.ConnectionId, input.DeployBuildId, input.RepositoryId)
 			deploymentCommit := &devops.CicdDeploymentCommit{
 				DomainEntity: domainlayer.DomainEntity{
-					Id: deployBuildIdGen.Generate(data.Options.ConnectionId, input.DeployBuildId, input.PlanResultKey),
+					Id: deploymentCommitId,
 				},
 				CicdScopeId:      planIdGen.Generate(data.Options.ConnectionId, data.Options.PlanKey),
-				CicdDeploymentId: deployBuildIdGen.Generate(data.Options.ConnectionId, input.DeployBuildId, input.PlanResultKey),
+				CicdDeploymentId: deploymentCommitId,
 				Name:             input.GenerateCICDDeploymentCommitName(),
 				Result: devops.GetResult(&devops.ResultRule{
 					Failed:  []string{"Failed"},