Skip to content

Commit

Permalink
cherry-pick fix(bamboo): fix cicd_deployment_commits.id, remove PlanR…
Browse files Browse the repository at this point in the history
…esultKey from primary key list from BambooDeployBuild to v0.19 (#6403)

* docs(bamboot): add some comments

* fix(bamboo): fix e2e test

* fix(bamboo): fix cicd_deployment_commits.id, remove `PlanResultKey` from primary key list from BambooDeployBuild
  • Loading branch information
d4x1 authored Nov 7, 2023
1 parent e3056e1 commit ba0b393
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion backend/core/dal/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540097,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,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540100,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,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540101,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,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540102,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,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540105,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,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540106,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,79b062bd53af15c701193c90b543386557cb7a3a,bamboo:BambooPlan:1:TEST-PLA2,bamboo:BambooDeployBuild:1:1540117,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,
2 changes: 1 addition & 1 deletion backend/plugins/bamboo/models/deploy_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
33 changes: 27 additions & 6 deletions backend/plugins/bamboo/tasks/deploy_build_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package tasks

import (
"fmt"
"github.com/apache/incubator-devlake/core/models/common"
"reflect"
"strconv"
"time"
Expand All @@ -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
Expand All @@ -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"),
Expand All @@ -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,
Expand All @@ -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),
Id: deploymentCommitId,
},
CicdScopeId: planIdGen.Generate(data.Options.ConnectionId, data.Options.PlanKey),
CicdDeploymentId: deployBuildIdGen.Generate(data.Options.ConnectionId, input.DeployBuildId),
CicdDeploymentId: deploymentCommitId,
Name: input.GenerateCICDDeploymentCommitName(),
Result: devops.GetResult(&devops.ResultRule{
Failed: []string{"Failed"},
Expand Down

0 comments on commit ba0b393

Please sign in to comment.