Skip to content

Commit 20ae577

Browse files
authored
feat: Historical task get apis for new components on UI (#1634)
* updated spec * aded new get apis, old apis cleanup * wip - code refactoring * optimised history listing service * handled case for empty cm/secret * updated c,cs response * updated db model for pipeline strategy history and history cretion points * fixed response payload * fixed payload data bugs, legacy issues(incorrect history auditlog in app metrics update & auto trigger) * update script no. * updated script no * updated secret history fetch service for hiding values for non-admin users * fixed secret order issue * wip
1 parent 88f8218 commit 20ae577

20 files changed

+931
-498
lines changed

Wire.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,9 @@ func InitializeApp() (*App, error) {
688688
wire.Bind(new(history3.ConfigMapHistoryService), new(*history3.ConfigMapHistoryServiceImpl)),
689689
history3.NewPipelineStrategyHistoryServiceImpl,
690690
wire.Bind(new(history3.PipelineStrategyHistoryService), new(*history3.PipelineStrategyHistoryServiceImpl)),
691+
692+
history3.NewDeployedConfigurationHistoryServiceImpl,
693+
wire.Bind(new(history3.DeployedConfigurationHistoryService), new(*history3.DeployedConfigurationHistoryServiceImpl)),
691694
//history ends
692695

693696
//plugin starts

api/restHandler/PipelineHistoryRestHandler.go

Lines changed: 69 additions & 333 deletions
Large diffs are not rendered by default.

api/router/PipelineConfigRouter.go

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -148,37 +148,15 @@ func (router PipelineConfigRouterImpl) initPipelineConfigRouter(configRouter *mu
148148
configRouter.Path("/pipeline/suggest/{type}/{appId}").
149149
HandlerFunc(router.restHandler.PipelineNameSuggestion).Methods("GET")
150150

151-
configRouter.Path("/history/cm/{appId}/{pipelineId}").
152-
HandlerFunc(router.pipelineHistoryRestHandler.FetchDeploymentDetailsForDeployedCMHistory).
153-
Methods("GET")
154-
configRouter.Path("/history/cs/{appId}/{pipelineId}").
155-
HandlerFunc(router.pipelineHistoryRestHandler.FetchDeploymentDetailsForDeployedCSHistory).
156-
Methods("GET")
157-
158-
configRouter.Path("/history/template/{appId}/{pipelineId}").
159-
HandlerFunc(router.pipelineHistoryRestHandler.FetchDeploymentDetailsForDeployedTemplatesHistory).
160-
Methods("GET")
161-
162-
configRouter.Path("/history/strategy/{appId}/{pipelineId}").
163-
HandlerFunc(router.pipelineHistoryRestHandler.FetchDeploymentDetailsForDeployedStrategyHistory).
164-
Methods("GET")
165-
166-
configRouter.Path("/history/cm/{appId}/{pipelineId}/{id}").
167-
HandlerFunc(router.pipelineHistoryRestHandler.FetchDeployedCMHistoryById).
168-
Methods("GET")
169-
configRouter.Path("/history/cs/{appId}/{pipelineId}/{id}").
170-
HandlerFunc(router.pipelineHistoryRestHandler.FetchDeployedCSHistoryById).
171-
Methods("GET")
172-
173-
configRouter.Path("/history/template/{appId}/{pipelineId}/{id}").
174-
HandlerFunc(router.pipelineHistoryRestHandler.FetchDeployedTemplatesHistoryById).
151+
configRouter.Path("/history/deployed-configuration/{appId}/{pipelineId}/{wfrId}").
152+
HandlerFunc(router.pipelineHistoryRestHandler.FetchDeployedConfigurationsForWorkflow).
175153
Methods("GET")
176154

177-
configRouter.Path("/history/strategy/{appId}/{pipelineId}/{id}").
178-
HandlerFunc(router.pipelineHistoryRestHandler.FetchDeployedStrategyHistoryById).
155+
configRouter.Path("/history/deployed-component/list/{appId}/{pipelineId}").
156+
HandlerFunc(router.pipelineHistoryRestHandler.FetchDeployedHistoryComponentList).
179157
Methods("GET")
180158

181-
configRouter.Path("/history/cd-config/{appId}/{pipelineId}").
182-
HandlerFunc(router.pipelineHistoryRestHandler.FetchDeployedPrePostCdScriptHistory).
159+
configRouter.Path("/history/deployed-component/detail/{appId}/{pipelineId}/{id}").
160+
HandlerFunc(router.pipelineHistoryRestHandler.FetchDeployedHistoryComponentDetail).
183161
Methods("GET")
184162
}

pkg/app/AppService.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ type AppServiceImpl struct {
101101
}
102102

103103
type AppService interface {
104-
TriggerRelease(overrideRequest *bean.ValuesOverrideRequest, ctx context.Context, triggeredAt time.Time) (id int, err error)
104+
TriggerRelease(overrideRequest *bean.ValuesOverrideRequest, ctx context.Context, triggeredAt time.Time, triggeredBy int32) (id int, err error)
105105
UpdateReleaseStatus(request *bean.ReleaseStatusUpdateRequest) (bool, error)
106106
UpdateApplicationStatusAndCheckIsHealthy(application v1alpha1.Application) (bool, error)
107107
TriggerCD(artifact *repository.CiArtifact, cdWorkflowId int, pipeline *pipelineConfig.Pipeline, async bool, triggeredAt time.Time) error
@@ -365,8 +365,8 @@ func (impl AppServiceImpl) releasePipeline(pipeline *pipelineConfig.Pipeline, ar
365365
impl.logger.Errorw("error in creating acd synch context", "pipelineId", pipeline.Id, "artifactId", artifact.Id, "err", err)
366366
return err
367367
}
368-
369-
id, err := impl.TriggerRelease(request, ctx, triggeredAt)
368+
//setting deployedBy as 1(system user) since case of auto trigger
369+
id, err := impl.TriggerRelease(request, ctx, triggeredAt, 1)
370370
if err != nil {
371371
impl.logger.Errorw("error in auto cd pipeline trigger", "pipelineId", pipeline.Id, "artifactId", artifact.Id, "err", err)
372372
} else {
@@ -456,7 +456,7 @@ func (impl AppServiceImpl) getDbMigrationOverride(overrideRequest *bean.ValuesOv
456456
return confByte, nil
457457
}
458458

459-
func (impl AppServiceImpl) TriggerRelease(overrideRequest *bean.ValuesOverrideRequest, ctx context.Context, triggeredAt time.Time) (id int, err error) {
459+
func (impl AppServiceImpl) TriggerRelease(overrideRequest *bean.ValuesOverrideRequest, ctx context.Context, triggeredAt time.Time, deployedBy int32) (id int, err error) {
460460
if overrideRequest.DeploymentType == models.DEPLOYMENTTYPE_UNKNOWN {
461461
overrideRequest.DeploymentType = models.DEPLOYMENTTYPE_DEPLOY
462462
}
@@ -583,7 +583,7 @@ func (impl AppServiceImpl) TriggerRelease(overrideRequest *bean.ValuesOverrideRe
583583
configMapJson = nil
584584
}
585585

586-
releaseId, pipelineOverrideId, saveErr := impl.mergeAndSave(envOverride, overrideRequest, dbMigrationOverride, artifact, pipeline, configMapJson, strategy, ctx, triggeredAt)
586+
releaseId, pipelineOverrideId, saveErr := impl.mergeAndSave(envOverride, overrideRequest, dbMigrationOverride, artifact, pipeline, configMapJson, strategy, ctx, triggeredAt, deployedBy)
587587
if releaseId != 0 {
588588
flag, err := impl.updateArgoPipeline(overrideRequest.AppId, pipeline.Name, envOverride, ctx)
589589
if err != nil {
@@ -1055,7 +1055,7 @@ func (impl AppServiceImpl) mergeAndSave(envOverride *chartConfig.EnvConfigOverri
10551055
dbMigrationOverride []byte,
10561056
artifact *repository.CiArtifact,
10571057
pipeline *pipelineConfig.Pipeline, configMapJson []byte, strategy *chartConfig.PipelineStrategy, ctx context.Context,
1058-
triggeredAt time.Time) (releaseId int, overrideId int, err error) {
1058+
triggeredAt time.Time, deployedBy int32) (releaseId int, overrideId int, err error) {
10591059

10601060
//register release , obtain release id TODO: populate releaseId to template
10611061
override, err := impl.savePipelineOverride(overrideRequest, envOverride.Id, triggeredAt)
@@ -1144,13 +1144,13 @@ func (impl AppServiceImpl) mergeAndSave(envOverride *chartConfig.EnvConfigOverri
11441144
PipelineId: overrideRequest.PipelineId,
11451145
CiArtifactId: overrideRequest.CiArtifactId,
11461146
PipelineMergedValues: string(merged),
1147-
AuditLog: sql.AuditLog{UpdatedOn: triggeredAt, UpdatedBy: overrideRequest.UserId},
1147+
AuditLog: sql.AuditLog{UpdatedOn: triggeredAt, UpdatedBy: deployedBy},
11481148
}
11491149
err = impl.pipelineOverrideRepository.Update(pipelineOverride)
11501150
if err != nil {
11511151
return 0, 0, err
11521152
}
1153-
err = impl.CreateHistoriesForDeploymentTrigger(pipeline, strategy, envOverride, overrideJson, triggeredAt, pipelineOverride.UpdatedBy)
1153+
err = impl.CreateHistoriesForDeploymentTrigger(pipeline, strategy, envOverride, overrideJson, triggeredAt, deployedBy)
11541154
if err != nil {
11551155
impl.logger.Errorw("error in creating history entries for deployment trigger", "err", err)
11561156
return 0, 0, err
@@ -1366,7 +1366,7 @@ func (impl *AppServiceImpl) CreateHistoriesForDeploymentTrigger(pipeline *pipeli
13661366
impl.logger.Errorw("error in creating CM/CS history for deployment trigger", "err", err)
13671367
return err
13681368
}
1369-
err = impl.pipelineStrategyHistoryService.CreateStrategyHistoryForDeploymentTrigger(strategy, deployedOn, deployedBy)
1369+
err = impl.pipelineStrategyHistoryService.CreateStrategyHistoryForDeploymentTrigger(strategy, deployedOn, deployedBy, pipeline.TriggerType)
13701370
if err != nil {
13711371
impl.logger.Errorw("error in creating strategy history for deployment trigger", "err", err)
13721372
return err

pkg/pipeline/ChartService.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,9 @@ func (impl ChartServiceImpl) AppMetricsEnableDisable(appMetricRequest AppMetricE
11571157
impl.logger.Errorw("error in saving app level metrics flag", "error", err)
11581158
return nil, err
11591159
}
1160+
//updating audit log details of chart as history service uses it
1161+
currentChart.UpdatedOn = time.Now()
1162+
currentChart.UpdatedBy = appMetricRequest.UserId
11601163
//creating history entry for deployment template
11611164
err = impl.deploymentTemplateHistoryService.CreateDeploymentTemplateHistoryFromGlobalTemplate(currentChart, nil, appMetricRequest.IsAppMetricsEnabled)
11621165
if err != nil {

pkg/pipeline/PipelineBuilder.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ func (impl PipelineBuilderImpl) createCdPipeline(ctx context.Context, app *app2.
13581358
return pipelineId, fmt.Errorf("pipeline created but failed to add strategy")
13591359
}
13601360
//creating history entry for strategy
1361-
_, err = impl.pipelineStrategyHistoryService.CreatePipelineStrategyHistory(strategy, tx)
1361+
_, err = impl.pipelineStrategyHistoryService.CreatePipelineStrategyHistory(strategy, pipeline.TriggerType, tx)
13621362
if err != nil {
13631363
impl.logger.Errorw("error in creating strategy history entry", "err", err)
13641364
return 0, err
@@ -1455,7 +1455,7 @@ func (impl PipelineBuilderImpl) updateCdPipeline(ctx context.Context, pipeline *
14551455
return fmt.Errorf("pipeline updated but failed to update one strategy")
14561456
}
14571457
//creating history entry for strategy
1458-
_, err = impl.pipelineStrategyHistoryService.CreatePipelineStrategyHistory(strategy, tx)
1458+
_, err = impl.pipelineStrategyHistoryService.CreatePipelineStrategyHistory(strategy, pipeline.TriggerType, tx)
14591459
if err != nil {
14601460
impl.logger.Errorw("error in creating strategy history entry", "err", err)
14611461
return err
@@ -1475,7 +1475,7 @@ func (impl PipelineBuilderImpl) updateCdPipeline(ctx context.Context, pipeline *
14751475
return fmt.Errorf("pipeline created but failed to add strategy")
14761476
}
14771477
//creating history entry for strategy
1478-
_, err = impl.pipelineStrategyHistoryService.CreatePipelineStrategyHistory(strategy, tx)
1478+
_, err = impl.pipelineStrategyHistoryService.CreatePipelineStrategyHistory(strategy, pipeline.TriggerType, tx)
14791479
if err != nil {
14801480
impl.logger.Errorw("error in creating strategy history entry", "err", err)
14811481
return err

pkg/pipeline/PropertiesConfig.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,9 @@ func (impl PropertiesConfigServiceImpl) EnvMetricsEnableDisable(appMetricRequest
702702
return nil, err
703703
}
704704
}
705+
//updating audit log details of chart as history service uses it
706+
currentChart.UpdatedOn = time.Now()
707+
currentChart.UpdatedBy = appMetricRequest.UserId
705708
//creating history entry
706709
err = impl.deploymentTemplateHistoryService.CreateDeploymentTemplateHistoryFromEnvOverrideTemplate(currentChart, nil, appMetricRequest.IsAppMetricsEnabled, 0)
707710
if err != nil {

pkg/pipeline/WorkflowDagExecutor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ func (impl *WorkflowDagExecutorImpl) ManualCdTrigger(overrideRequest *bean.Value
10221022
return 0, fmt.Errorf("found vulnerability for image digest %s", artifact.ImageDigest)
10231023
}
10241024

1025-
releaseId, err = impl.appService.TriggerRelease(overrideRequest, ctx, triggeredAt)
1025+
releaseId, err = impl.appService.TriggerRelease(overrideRequest, ctx, triggeredAt, overrideRequest.UserId)
10261026
// return after error handling
10271027
/*if err != nil {
10281028
return 0, err

0 commit comments

Comments
 (0)