@@ -23,8 +23,8 @@ import (
23
23
apiBean "github.com/devtron-labs/devtron/api/bean"
24
24
"github.com/devtron-labs/devtron/client/gitSensor"
25
25
"github.com/devtron-labs/devtron/internal/sql/repository"
26
- repository2 "github.com/devtron-labs/devtron/internal/sql/repository/imageTagging "
27
- "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/cdWorkflow"
26
+ "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow "
27
+ "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/ cdWorkflow"
28
28
"github.com/devtron-labs/devtron/internal/util"
29
29
"github.com/devtron-labs/devtron/pkg/sql"
30
30
"github.com/go-pg/pg"
@@ -43,13 +43,13 @@ type CdWorkflowRepository interface {
43
43
FindArtifactByPipelineIdAndRunnerType (pipelineId int , runnerType apiBean.WorkflowType , limit int , runnerStatuses []string ) ([]CdWorkflowRunner , error )
44
44
SaveWorkFlowRunner (wfr * CdWorkflowRunner ) (* CdWorkflowRunner , error )
45
45
UpdateWorkFlowRunner (wfr * CdWorkflowRunner ) error
46
+ UpdateIsArtifactUploaded (wfrId int , isArtifactUploaded workflow.ArtifactUploadedType ) error
46
47
GetPreviousQueuedRunners (cdWfrId , pipelineId int ) ([]* CdWorkflowRunner , error )
47
48
UpdateRunnerStatusToFailedForIds (errMsg string , triggeredBy int32 , cdWfrIds ... int ) error
48
49
UpdateWorkFlowRunnersWithTxn (wfrs []* CdWorkflowRunner , tx * pg.Tx ) error
49
50
UpdateWorkFlowRunners (wfr []* CdWorkflowRunner ) error
50
51
FindWorkflowRunnerByCdWorkflowId (wfIds []int ) ([]* CdWorkflowRunner , error )
51
52
FindPreviousCdWfRunnerByStatus (pipelineId int , currentWFRunnerId int , status []string ) ([]* CdWorkflowRunner , error )
52
- FindConfigByPipelineId (pipelineId int ) (* CdWorkflowConfig , error )
53
53
FindWorkflowRunnerById (wfrId int ) (* CdWorkflowRunner , error )
54
54
FindBasicWorkflowRunnerById (wfrId int ) (* CdWorkflowRunner , error )
55
55
FindRetriedWorkflowCountByReferenceId (wfrId int ) (int , error )
@@ -76,6 +76,9 @@ type CdWorkflowRepository interface {
76
76
FetchArtifactsByCdPipelineId (pipelineId int , runnerType apiBean.WorkflowType , offset , limit int , searchString string ) ([]CdWorkflowRunner , error )
77
77
GetLatestTriggersOfHelmPipelinesStuckInNonTerminalStatuses (getPipelineDeployedWithinHours int ) ([]* CdWorkflowRunner , error )
78
78
FindLatestRunnerByPipelineIdsAndRunnerType (ctx context.Context , pipelineIds []int , runnerType apiBean.WorkflowType ) ([]CdWorkflowRunner , error )
79
+
80
+ MigrateIsArtifactUploaded (wfrId int , isArtifactUploaded bool )
81
+ MigrateCdArtifactLocation (wfrId int , cdArtifactLocation string )
79
82
}
80
83
81
84
type CdWorkflowRepositoryImpl struct {
@@ -95,27 +98,6 @@ type CdWorkflow struct {
95
98
sql.AuditLog
96
99
}
97
100
98
- type CdWorkflowConfig struct {
99
- tableName struct {} `sql:"cd_workflow_config" pg:",discard_unknown_columns"`
100
- Id int `sql:"id,pk"`
101
- CdTimeout int64 `sql:"cd_timeout"`
102
- MinCpu string `sql:"min_cpu"`
103
- MaxCpu string `sql:"max_cpu"`
104
- MinMem string `sql:"min_mem"`
105
- MaxMem string `sql:"max_mem"`
106
- MinStorage string `sql:"min_storage"`
107
- MaxStorage string `sql:"max_storage"`
108
- MinEphStorage string `sql:"min_eph_storage"`
109
- MaxEphStorage string `sql:"max_eph_storage"`
110
- CdCacheBucket string `sql:"cd_cache_bucket"`
111
- CdCacheRegion string `sql:"cd_cache_region"`
112
- CdImage string `sql:"cd_image"`
113
- Namespace string `sql:"wf_namespace"`
114
- CdPipelineId int `sql:"cd_pipeline_id"`
115
- LogsBucket string `sql:"logs_bucket"`
116
- CdArtifactLocationFormat string `sql:"cd_artifact_location_format"`
117
- }
118
-
119
101
type CdWorkflowRunnerWithExtraFields struct {
120
102
CdWorkflowRunner
121
103
TotalCount int
@@ -134,6 +116,8 @@ type CdWorkflowRunner struct {
134
116
FinishedOn time.Time `sql:"finished_on"`
135
117
Namespace string `sql:"namespace"`
136
118
LogLocation string `sql:"log_file_path"`
119
+ CdArtifactLocation string `sql:"cd_artifact_location"`
120
+ IsArtifactUploaded workflow.ArtifactUploadedType `sql:"is_artifact_uploaded"`
137
121
TriggeredBy int32 `sql:"triggered_by"`
138
122
CdWorkflowId int `sql:"cd_workflow_id"`
139
123
PodName string `sql:"pod_name"`
@@ -145,6 +129,15 @@ type CdWorkflowRunner struct {
145
129
sql.AuditLog
146
130
}
147
131
132
+ func (c * CdWorkflowRunner ) GetIsArtifactUploaded () (isArtifactUploaded bool , isMigrationRequired bool ) {
133
+ return workflow .IsArtifactUploaded (c .IsArtifactUploaded )
134
+ }
135
+
136
+ func (c * CdWorkflowRunner ) WithIsArtifactUploaded (isArtifactUploaded bool ) * CdWorkflowRunner {
137
+ c .IsArtifactUploaded = workflow .GetArtifactUploadedType (isArtifactUploaded )
138
+ return c
139
+ }
140
+
148
141
func (c * CdWorkflowRunner ) IsExternalRun () bool {
149
142
var isExtCluster bool
150
143
if c .WorkflowType == cdWorkflow .WorkflowTypePre {
@@ -173,34 +166,6 @@ type CiPipelineMaterialResponse struct {
173
166
Regex string `json:"regex"`
174
167
}
175
168
176
- type CdWorkflowWithArtifact struct {
177
- Id int `json:"id"`
178
- CdWorkflowId int `json:"cd_workflow_id"`
179
- Name string `json:"name"`
180
- Status string `json:"status"`
181
- PodStatus string `json:"pod_status"`
182
- Message string `json:"message"`
183
- StartedOn time.Time `json:"started_on"`
184
- FinishedOn time.Time `json:"finished_on"`
185
- PipelineId int `json:"pipeline_id"`
186
- Namespace string `json:"namespace"`
187
- LogFilePath string `json:"log_file_path"`
188
- TriggeredBy int32 `json:"triggered_by"`
189
- EmailId string `json:"email_id"`
190
- Image string `json:"image"`
191
- MaterialInfo string `json:"material_info,omitempty"`
192
- DataSource string `json:"data_source,omitempty"`
193
- CiArtifactId int `json:"ci_artifact_id,omitempty"`
194
- WorkflowType string `json:"workflow_type,omitempty"`
195
- ExecutorType string `json:"executor_type,omitempty"`
196
- BlobStorageEnabled bool `json:"blobStorageEnabled"`
197
- GitTriggers map [int ]GitCommit `json:"gitTriggers"`
198
- CiMaterials []CiPipelineMaterialResponse `json:"ciMaterials"`
199
- ImageReleaseTags []* repository2.ImageTag `json:"imageReleaseTags"`
200
- ImageComment * repository2.ImageComment `json:"imageComment"`
201
- RefCdWorkflowRunnerId int `json:"referenceCdWorkflowRunnerId"`
202
- }
203
-
204
169
type TriggerWorkflowStatus struct {
205
170
CdWorkflowStatus []* CdWorkflowStatus `json:"cdWorkflowStatus"`
206
171
CiWorkflowStatus []* CiWorkflowStatus `json:"ciWorkflowStatus"`
@@ -277,12 +242,6 @@ func (impl *CdWorkflowRepositoryImpl) FindById(wfId int) (*CdWorkflow, error) {
277
242
return ddWorkflow , err
278
243
}
279
244
280
- func (impl * CdWorkflowRepositoryImpl ) FindConfigByPipelineId (pipelineId int ) (* CdWorkflowConfig , error ) {
281
- cdWorkflowConfig := & CdWorkflowConfig {}
282
- err := impl .dbConnection .Model (cdWorkflowConfig ).Where ("cd_pipeline_id = ?" , pipelineId ).Select ()
283
- return cdWorkflowConfig , err
284
- }
285
-
286
245
func (impl * CdWorkflowRepositoryImpl ) FindLatestCdWorkflowByPipelineId (pipelineIds []int ) (* CdWorkflow , error ) {
287
246
cdWorkflow := & CdWorkflow {}
288
247
err := impl .dbConnection .Model (cdWorkflow ).Where ("pipeline_id in (?)" , pg .In (pipelineIds )).Order ("id DESC" ).Limit (1 ).Select ()
@@ -502,6 +461,14 @@ func (impl *CdWorkflowRepositoryImpl) UpdateWorkFlowRunner(wfr *CdWorkflowRunner
502
461
return err
503
462
}
504
463
464
+ func (impl * CdWorkflowRepositoryImpl ) UpdateIsArtifactUploaded (wfrId int , isArtifactUploaded workflow.ArtifactUploadedType ) error {
465
+ _ , err := impl .dbConnection .Model ((* CdWorkflowRunner )(nil )).
466
+ Set ("is_artifact_uploaded = ?" , isArtifactUploaded ).
467
+ Where ("id = ?" , wfrId ).
468
+ Update ()
469
+ return err
470
+ }
471
+
505
472
func (impl * CdWorkflowRepositoryImpl ) GetPreviousQueuedRunners (cdWfrId , pipelineId int ) ([]* CdWorkflowRunner , error ) {
506
473
var cdWfrs []* CdWorkflowRunner
507
474
err := impl .dbConnection .Model (& cdWfrs ).
@@ -773,3 +740,23 @@ func (impl *CdWorkflowRepositoryImpl) FindLatestRunnerByPipelineIdsAndRunnerType
773
740
}
774
741
return latestWfrs , err
775
742
}
743
+
744
+ func (impl * CdWorkflowRepositoryImpl ) MigrateIsArtifactUploaded (wfrId int , isArtifactUploaded bool ) {
745
+ _ , err := impl .dbConnection .Model ((* CdWorkflowRunner )(nil )).
746
+ Set ("is_artifact_uploaded = ?" , workflow .GetArtifactUploadedType (isArtifactUploaded )).
747
+ Where ("id = ?" , wfrId ).
748
+ Update ()
749
+ if err != nil {
750
+ impl .logger .Errorw ("error in updating is artifact uploaded" , "wfrId" , wfrId , "err" , err )
751
+ }
752
+ }
753
+
754
+ func (impl * CdWorkflowRepositoryImpl ) MigrateCdArtifactLocation (wfrId int , cdArtifactLocation string ) {
755
+ _ , err := impl .dbConnection .Model ((* CdWorkflowRunner )(nil )).
756
+ Set ("cd_artifact_location = ?" , cdArtifactLocation ).
757
+ Where ("id = ?" , wfrId ).
758
+ Update ()
759
+ if err != nil {
760
+ impl .logger .Errorw ("error in updating cd artifact location" , "wfrId" , wfrId , "err" , err )
761
+ }
762
+ }
0 commit comments