From f3fb2c25d2aaff8da076b0c74fb05fcbbcd1af10 Mon Sep 17 00:00:00 2001 From: ShashwatDadhich Date: Wed, 1 May 2024 12:28:08 +0530 Subject: [PATCH 1/5] git material flow added in transaction --- .../pipelineConfig/MaterialRepository.go | 18 +++---- pkg/pipeline/CiCdPipelineOrchestrator.go | 54 +++++++++++++++---- pkg/pipeline/CiMaterialConfigService.go | 27 ++++++---- .../history/GitMaterialHistoryService.go | 13 ++--- .../GitMaterialHistoryRepository.go | 6 +-- 5 files changed, 82 insertions(+), 36 deletions(-) diff --git a/internal/sql/repository/pipelineConfig/MaterialRepository.go b/internal/sql/repository/pipelineConfig/MaterialRepository.go index 5dc8b4456e..94930c2e64 100644 --- a/internal/sql/repository/pipelineConfig/MaterialRepository.go +++ b/internal/sql/repository/pipelineConfig/MaterialRepository.go @@ -52,8 +52,8 @@ type GitMaterial struct { type MaterialRepository interface { MaterialExists(url string) (bool, error) - SaveMaterial(material *GitMaterial) error - UpdateMaterial(material *GitMaterial) error + SaveMaterial(material *GitMaterial, tx *pg.Tx) error + UpdateMaterial(material *GitMaterial, tx *pg.Tx) error Update(materials []*GitMaterial) error FindByAppId(appId int) ([]*GitMaterial, error) FindById(Id int) (*GitMaterial, error) @@ -61,7 +61,7 @@ type MaterialRepository interface { UpdateMaterialScmId(material *GitMaterial) error FindByAppIdAndCheckoutPath(appId int, checkoutPath string) (*GitMaterial, error) FindByGitProviderId(gitProviderId int) (materials []*GitMaterial, err error) - MarkMaterialDeleted(material *GitMaterial) error + MarkMaterialDeleted(material *GitMaterial, tx *pg.Tx) error FindNumberOfAppsWithGitRepo(appIds []int) (int, error) FindByAppIds(appIds []int) ([]*GitMaterial, error) } @@ -113,12 +113,12 @@ func (repo MaterialRepositoryImpl) MaterialExists(url string) (bool, error) { return exists, err } -func (repo MaterialRepositoryImpl) SaveMaterial(material *GitMaterial) error { - return repo.dbConnection.Insert(material) +func (repo MaterialRepositoryImpl) SaveMaterial(material *GitMaterial, tx *pg.Tx) error { + return tx.Insert(material) } -func (repo MaterialRepositoryImpl) UpdateMaterial(material *GitMaterial) error { - return repo.dbConnection.Update(material) +func (repo MaterialRepositoryImpl) UpdateMaterial(material *GitMaterial, tx *pg.Tx) error { + return tx.Update(material) } func (repo MaterialRepositoryImpl) UpdateMaterialScmId(material *GitMaterial) error { @@ -164,9 +164,9 @@ func (repo MaterialRepositoryImpl) FindByGitProviderId(gitProviderId int) (mater return materials, err } -func (repo MaterialRepositoryImpl) MarkMaterialDeleted(material *GitMaterial) error { +func (repo MaterialRepositoryImpl) MarkMaterialDeleted(material *GitMaterial, tx *pg.Tx) error { material.Active = false - return repo.dbConnection.Update(material) + return tx.Update(material) } func (repo MaterialRepositoryImpl) FindNumberOfAppsWithGitRepo(appIds []int) (int, error) { diff --git a/pkg/pipeline/CiCdPipelineOrchestrator.go b/pkg/pipeline/CiCdPipelineOrchestrator.go index 24e399f4e8..c580aca65e 100644 --- a/pkg/pipeline/CiCdPipelineOrchestrator.go +++ b/pkg/pipeline/CiCdPipelineOrchestrator.go @@ -130,6 +130,7 @@ type CiCdPipelineOrchestratorImpl struct { genericNoteService genericNotes.GenericNoteService customTagService CustomTagService chartService chart.ChartService + transactionManager sql.TransactionWrapper } func NewCiCdPipelineOrchestrator( @@ -156,7 +157,7 @@ func NewCiCdPipelineOrchestrator( configMapService ConfigMapService, customTagService CustomTagService, genericNoteService genericNotes.GenericNoteService, - chartService chart.ChartService) *CiCdPipelineOrchestratorImpl { + chartService chart.ChartService, transactionManager sql.TransactionWrapper) *CiCdPipelineOrchestratorImpl { return &CiCdPipelineOrchestratorImpl{ appRepository: pipelineGroupRepository, logger: logger, @@ -183,6 +184,7 @@ func NewCiCdPipelineOrchestrator( genericNoteService: genericNoteService, customTagService: customTagService, chartService: chartService, + transactionManager: transactionManager, } } @@ -1271,6 +1273,23 @@ func (impl CiCdPipelineOrchestratorImpl) DeleteApp(appId int, userId int32) erro } func (impl CiCdPipelineOrchestratorImpl) CreateMaterials(createMaterialRequest *bean.CreateMaterialDTO) (*bean.CreateMaterialDTO, error) { + tx, err := impl.transactionManager.StartTx() + if err != nil { + return nil, err + } + defer func() { + if err != nil { + err := tx.Rollback() + if err != nil { + impl.logger.Errorw("error in rollback Create material", "err", err) + } + } else { + err = impl.transactionManager.CommitTx(tx) + if err != nil { + impl.logger.Errorw("error in committing tx Create material", "err", err) + } + } + }() existingMaterials, err := impl.materialRepository.FindByAppId(createMaterialRequest.AppId) if err != nil { impl.logger.Errorw("err", "err", err) @@ -1295,7 +1314,7 @@ func (impl CiCdPipelineOrchestratorImpl) CreateMaterials(createMaterialRequest * var materials []*bean.GitMaterial for _, inputMaterial := range createMaterialRequest.Material { inputMaterial.UpdateSanitisedGitRepoUrl() - m, err := impl.createMaterial(inputMaterial, createMaterialRequest.AppId, createMaterialRequest.UserId) + m, err := impl.createMaterial(inputMaterial, createMaterialRequest.AppId, createMaterialRequest.UserId, tx) inputMaterial.Id = m.Id if err != nil { return nil, err @@ -1312,7 +1331,24 @@ func (impl CiCdPipelineOrchestratorImpl) CreateMaterials(createMaterialRequest * } func (impl CiCdPipelineOrchestratorImpl) UpdateMaterial(updateMaterialDTO *bean.UpdateMaterialDTO) (*bean.UpdateMaterialDTO, error) { - updatedMaterial, err := impl.updateMaterial(updateMaterialDTO) + tx, err := impl.transactionManager.StartTx() + if err != nil { + return nil, err + } + defer func() { + if err != nil { + err := tx.Rollback() + if err != nil { + impl.logger.Errorw("error in rollback Update material", "err", err) + } + } else { + err = impl.transactionManager.CommitTx(tx) + if err != nil { + impl.logger.Errorw("error in committing tx Update material", "err", err) + } + } + }() + updatedMaterial, err := impl.updateMaterial(updateMaterialDTO, tx) if err != nil { impl.logger.Errorw("err", "err", err) return nil, err @@ -1456,7 +1492,7 @@ func (impl CiCdPipelineOrchestratorImpl) validateCheckoutPathsForMultiGit(allPat return nil } -func (impl CiCdPipelineOrchestratorImpl) updateMaterial(updateMaterialDTO *bean.UpdateMaterialDTO) (*pipelineConfig.GitMaterial, error) { +func (impl CiCdPipelineOrchestratorImpl) updateMaterial(updateMaterialDTO *bean.UpdateMaterialDTO, tx *pg.Tx) (*pipelineConfig.GitMaterial, error) { existingMaterials, err := impl.materialRepository.FindByAppId(updateMaterialDTO.AppId) if err != nil { impl.logger.Errorw("err", "err", err) @@ -1497,19 +1533,19 @@ func (impl CiCdPipelineOrchestratorImpl) updateMaterial(updateMaterialDTO *bean. currentMaterial.FilterPattern = updateMaterialDTO.Material.FilterPattern currentMaterial.AuditLog = sql.AuditLog{UpdatedBy: updateMaterialDTO.UserId, CreatedBy: currentMaterial.CreatedBy, UpdatedOn: time.Now(), CreatedOn: currentMaterial.CreatedOn} - err = impl.materialRepository.UpdateMaterial(currentMaterial) + err = impl.materialRepository.UpdateMaterial(currentMaterial, tx) if err != nil { impl.logger.Errorw("error in updating material", "material", currentMaterial, "err", err) return nil, err } - err = impl.gitMaterialHistoryService.CreateMaterialHistory(currentMaterial) + err = impl.gitMaterialHistoryService.CreateMaterialHistory(currentMaterial, tx) return currentMaterial, nil } -func (impl CiCdPipelineOrchestratorImpl) createMaterial(inputMaterial *bean.GitMaterial, appId int, userId int32) (*pipelineConfig.GitMaterial, error) { +func (impl CiCdPipelineOrchestratorImpl) createMaterial(inputMaterial *bean.GitMaterial, appId int, userId int32, tx *pg.Tx) (*pipelineConfig.GitMaterial, error) { basePath := path.Base(inputMaterial.Url) basePath = strings.TrimSuffix(basePath, ".git") material := &pipelineConfig.GitMaterial{ @@ -1523,12 +1559,12 @@ func (impl CiCdPipelineOrchestratorImpl) createMaterial(inputMaterial *bean.GitM FilterPattern: inputMaterial.FilterPattern, AuditLog: sql.AuditLog{UpdatedBy: userId, CreatedBy: userId, UpdatedOn: time.Now(), CreatedOn: time.Now()}, } - err := impl.materialRepository.SaveMaterial(material) + err := impl.materialRepository.SaveMaterial(material, tx) if err != nil { impl.logger.Errorw("error in saving material", "material", material, "err", err) return nil, err } - err = impl.gitMaterialHistoryService.CreateMaterialHistory(material) + err = impl.gitMaterialHistoryService.CreateMaterialHistory(material, tx) return material, err } diff --git a/pkg/pipeline/CiMaterialConfigService.go b/pkg/pipeline/CiMaterialConfigService.go index 1b1e7331c2..31ad40422e 100644 --- a/pkg/pipeline/CiMaterialConfigService.go +++ b/pkg/pipeline/CiMaterialConfigService.go @@ -22,6 +22,7 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" "github.com/devtron-labs/devtron/pkg/bean" "github.com/devtron-labs/devtron/pkg/pipeline/history" + "github.com/devtron-labs/devtron/pkg/sql" "github.com/go-pg/pg" "github.com/juju/errors" "go.uber.org/zap" @@ -52,6 +53,7 @@ type CiMaterialConfigServiceImpl struct { gitMaterialHistoryService history.GitMaterialHistoryService pipelineRepository pipelineConfig.PipelineRepository ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository + transactionManager sql.TransactionWrapper } func NewCiMaterialConfigServiceImpl( @@ -62,7 +64,7 @@ func NewCiMaterialConfigServiceImpl( ciPipelineRepository pipelineConfig.CiPipelineRepository, gitMaterialHistoryService history.GitMaterialHistoryService, pipelineRepository pipelineConfig.PipelineRepository, - ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository) *CiMaterialConfigServiceImpl { + ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository, transactionManager sql.TransactionWrapper) *CiMaterialConfigServiceImpl { return &CiMaterialConfigServiceImpl{ logger: logger, @@ -73,6 +75,7 @@ func NewCiMaterialConfigServiceImpl( gitMaterialHistoryService: gitMaterialHistoryService, pipelineRepository: pipelineRepository, ciPipelineMaterialRepository: ciPipelineMaterialRepository, + transactionManager: transactionManager, } } @@ -122,21 +125,27 @@ func (impl *CiMaterialConfigServiceImpl) DeleteMaterial(request *bean.UpdateMate existingMaterial.UpdatedOn = time.Now() existingMaterial.UpdatedBy = request.UserId - err = impl.materialRepo.MarkMaterialDeleted(existingMaterial) + tx, err := impl.transactionManager.StartTx() if err != nil { - impl.logger.Errorw("error in deleting git material", "gitMaterial", existingMaterial) return err } + defer func() { + if err != nil { + err := tx.Rollback() + if err != nil { + impl.logger.Errorw("error in rollback ", "err", err) + } + } + }() - err = impl.gitMaterialHistoryService.MarkMaterialDeletedAndCreateHistory(existingMaterial) - - dbConnection := impl.pipelineRepository.GetConnection() - tx, err := dbConnection.Begin() + err = impl.materialRepo.MarkMaterialDeleted(existingMaterial, tx) if err != nil { + impl.logger.Errorw("error in deleting git material", "gitMaterial", existingMaterial) return err } - // Rollback tx on error. - defer tx.Rollback() + + err = impl.gitMaterialHistoryService.MarkMaterialDeletedAndCreateHistory(existingMaterial, tx) + var materials []*pipelineConfig.CiPipelineMaterial for _, pipeline := range pipelines { materialDbObject, err := impl.ciPipelineMaterialRepository.GetByPipelineIdAndGitMaterialId(pipeline.Id, request.Material.Id) diff --git a/pkg/pipeline/history/GitMaterialHistoryService.go b/pkg/pipeline/history/GitMaterialHistoryService.go index e2a19cfad4..f41665f56f 100644 --- a/pkg/pipeline/history/GitMaterialHistoryService.go +++ b/pkg/pipeline/history/GitMaterialHistoryService.go @@ -4,13 +4,14 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" "github.com/devtron-labs/devtron/pkg/sql" + "github.com/go-pg/pg" "go.uber.org/zap" ) type GitMaterialHistoryService interface { - CreateMaterialHistory(inputMaterial *pipelineConfig.GitMaterial) error + CreateMaterialHistory(inputMaterial *pipelineConfig.GitMaterial, tx *pg.Tx) error CreateDeleteMaterialHistory(materials []*pipelineConfig.GitMaterial) error - MarkMaterialDeletedAndCreateHistory(material *pipelineConfig.GitMaterial) error + MarkMaterialDeletedAndCreateHistory(material *pipelineConfig.GitMaterial, tx *pg.Tx) error } type GitMaterialHistoryServiceImpl struct { @@ -27,7 +28,7 @@ func NewGitMaterialHistoryServiceImpl(gitMaterialHistoryRepository repository.Gi } } -func (impl GitMaterialHistoryServiceImpl) CreateMaterialHistory(inputMaterial *pipelineConfig.GitMaterial) error { +func (impl GitMaterialHistoryServiceImpl) CreateMaterialHistory(inputMaterial *pipelineConfig.GitMaterial, tx *pg.Tx) error { material := &repository.GitMaterialHistory{ GitMaterialId: inputMaterial.Id, @@ -41,7 +42,7 @@ func (impl GitMaterialHistoryServiceImpl) CreateMaterialHistory(inputMaterial *p FilterPattern: inputMaterial.FilterPattern, AuditLog: sql.AuditLog{UpdatedBy: inputMaterial.UpdatedBy, CreatedBy: inputMaterial.CreatedBy, UpdatedOn: inputMaterial.UpdatedOn, CreatedOn: inputMaterial.CreatedOn}, } - err := impl.gitMaterialHistoryRepository.SaveGitMaterialHistory(material) + err := impl.gitMaterialHistoryRepository.SaveGitMaterialHistory(material, tx) if err != nil { impl.logger.Errorw("error in saving create/update history for git repository") } @@ -86,11 +87,11 @@ func (impl GitMaterialHistoryServiceImpl) CreateDeleteMaterialHistory(materials } -func (impl GitMaterialHistoryServiceImpl) MarkMaterialDeletedAndCreateHistory(material *pipelineConfig.GitMaterial) error { +func (impl GitMaterialHistoryServiceImpl) MarkMaterialDeletedAndCreateHistory(material *pipelineConfig.GitMaterial, tx *pg.Tx) error { material.Active = false - err := impl.CreateMaterialHistory(material) + err := impl.CreateMaterialHistory(material, tx) if err != nil { impl.logger.Errorw("error in saving delete history for git material repository") diff --git a/pkg/pipeline/history/repository/GitMaterialHistoryRepository.go b/pkg/pipeline/history/repository/GitMaterialHistoryRepository.go index c6553b0ded..51fffb8329 100644 --- a/pkg/pipeline/history/repository/GitMaterialHistoryRepository.go +++ b/pkg/pipeline/history/repository/GitMaterialHistoryRepository.go @@ -21,7 +21,7 @@ type GitMaterialHistory struct { } type GitMaterialHistoryRepository interface { - SaveGitMaterialHistory(material *GitMaterialHistory) error + SaveGitMaterialHistory(material *GitMaterialHistory, tx *pg.Tx) error SaveDeleteMaterialHistory(materials []*GitMaterialHistory) error } @@ -35,8 +35,8 @@ func NewGitMaterialHistoryRepositoyImpl(dbConnection *pg.DB) *GitMaterialHistory } } -func (repo GitMaterialHistoryRepositoryImpl) SaveGitMaterialHistory(material *GitMaterialHistory) error { - return repo.dbConnection.Insert(material) +func (repo GitMaterialHistoryRepositoryImpl) SaveGitMaterialHistory(material *GitMaterialHistory, tx *pg.Tx) error { + return tx.Insert(material) } func (repo GitMaterialHistoryRepositoryImpl) SaveDeleteMaterialHistory(materials []*GitMaterialHistory) error { From 1727c8f5c03705e3b5267a635a0215a93877f8e7 Mon Sep 17 00:00:00 2001 From: ShashwatDadhich Date: Wed, 1 May 2024 12:43:16 +0530 Subject: [PATCH 2/5] wire refactored --- Wire.go | 3 +++ cmd/external-app/wire.go | 2 ++ cmd/external-app/wire_gen.go | 11 ++++---- .../imageTagging/ImageTaggingRepository.go | 4 +-- .../pipelineConfig/CiPipelineRepository.go | 4 +-- pkg/chartRepo/repository/ChartsRepository.go | 4 +-- .../EphemeralContainersRepository.go | 4 +-- .../GenericNoteHistoryRepository.go | 3 +-- .../repository/GenericNoteRepository.go | 3 +-- pkg/infraConfig/infraConfigRepository.go | 4 +-- .../ResourceQualifiersMappingRepository.go | 4 +-- .../repository/ScopedVariableRepository.go | 4 +-- .../VariableEntityMappingRepository.go | 4 +-- wire_gen.go | 27 ++++++++++--------- 14 files changed, 43 insertions(+), 38 deletions(-) diff --git a/Wire.go b/Wire.go index 0e90a00a71..0ec70b9fcc 100644 --- a/Wire.go +++ b/Wire.go @@ -226,6 +226,9 @@ func InitializeApp() (*App, error) { wire.Bind(new(router.PProfRouter), new(*router.PProfRouterImpl)), // ---- pprof end ---- + sql.NewTransactionUtilImpl, + wire.Bind(new(sql.TransactionWrapper), new(*sql.TransactionUtilImpl)), + trigger.NewPipelineRestHandler, wire.Bind(new(trigger.PipelineTriggerRestHandler), new(*trigger.PipelineTriggerRestHandlerImpl)), app.GetAppServiceConfig, diff --git a/cmd/external-app/wire.go b/cmd/external-app/wire.go index 6cb5e494fa..21b24851c1 100644 --- a/cmd/external-app/wire.go +++ b/cmd/external-app/wire.go @@ -103,6 +103,8 @@ func InitializeApp() (*App, error) { telemetry.NewPosthogClient, delete2.NewDeleteServiceImpl, + sql.NewTransactionUtilImpl, + pipelineConfig.NewMaterialRepositoryImpl, wire.Bind(new(pipelineConfig.MaterialRepository), new(*pipelineConfig.MaterialRepositoryImpl)), // appStatus diff --git a/cmd/external-app/wire_gen.go b/cmd/external-app/wire_gen.go index d82b8c6fa1..27176fcd7e 100644 --- a/cmd/external-app/wire_gen.go +++ b/cmd/external-app/wire_gen.go @@ -1,6 +1,6 @@ // Code generated by Wire. DO NOT EDIT. -//go:generate go run -mod=mod github.com/google/wire/cmd/wire +//go:generate go run github.com/google/wire/cmd/wire //go:build !wireinject // +build !wireinject @@ -222,8 +222,9 @@ func InitializeApp() (*App, error) { roleGroupServiceImpl := user.NewRoleGroupServiceImpl(userAuthRepositoryImpl, sugaredLogger, userRepositoryImpl, roleGroupRepositoryImpl, userCommonServiceImpl) userRestHandlerImpl := user2.NewUserRestHandlerImpl(userServiceImpl, validate, sugaredLogger, enforcerImpl, roleGroupServiceImpl, userCommonServiceImpl) userRouterImpl := user2.NewUserRouterImpl(userRestHandlerImpl) - genericNoteRepositoryImpl := repository6.NewGenericNoteRepositoryImpl(db) - genericNoteHistoryRepositoryImpl := repository6.NewGenericNoteHistoryRepositoryImpl(db) + transactionUtilImpl := sql.NewTransactionUtilImpl(db) + genericNoteRepositoryImpl := repository6.NewGenericNoteRepositoryImpl(db, transactionUtilImpl) + genericNoteHistoryRepositoryImpl := repository6.NewGenericNoteHistoryRepositoryImpl(db, transactionUtilImpl) genericNoteHistoryServiceImpl := genericNotes.NewGenericNoteHistoryServiceImpl(genericNoteHistoryRepositoryImpl, sugaredLogger) genericNoteServiceImpl := genericNotes.NewGenericNoteServiceImpl(genericNoteRepositoryImpl, genericNoteHistoryServiceImpl, userRepositoryImpl, sugaredLogger) clusterDescriptionRepositoryImpl := repository2.NewClusterDescriptionRepositoryImpl(db, sugaredLogger) @@ -264,14 +265,14 @@ func InitializeApp() (*App, error) { environmentRouterImpl := cluster2.NewEnvironmentRouterImpl(environmentRestHandlerImpl) k8sResourceHistoryRepositoryImpl := repository8.NewK8sResourceHistoryRepositoryImpl(db, sugaredLogger) k8sResourceHistoryServiceImpl := kubernetesResourceAuditLogs.Newk8sResourceHistoryServiceImpl(k8sResourceHistoryRepositoryImpl, sugaredLogger, appRepositoryImpl, environmentRepositoryImpl) - ephemeralContainersRepositoryImpl := repository2.NewEphemeralContainersRepositoryImpl(db) + ephemeralContainersRepositoryImpl := repository2.NewEphemeralContainersRepositoryImpl(db, transactionUtilImpl) ephemeralContainerServiceImpl := cluster.NewEphemeralContainerServiceImpl(ephemeralContainersRepositoryImpl, sugaredLogger) terminalSessionHandlerImpl := terminal.NewTerminalSessionHandlerImpl(environmentServiceImpl, clusterServiceImpl, sugaredLogger, k8sServiceImpl, ephemeralContainerServiceImpl, argoApplicationServiceImpl) k8sApplicationServiceImpl, err := application.NewK8sApplicationServiceImpl(sugaredLogger, clusterServiceImpl, pumpImpl, helmAppServiceImpl, k8sServiceImpl, acdAuthConfig, k8sResourceHistoryServiceImpl, k8sCommonServiceImpl, terminalSessionHandlerImpl, ephemeralContainerServiceImpl, ephemeralContainersRepositoryImpl, argoApplicationServiceImpl) if err != nil { return nil, err } - ciPipelineRepositoryImpl := pipelineConfig.NewCiPipelineRepositoryImpl(db, sugaredLogger) + ciPipelineRepositoryImpl := pipelineConfig.NewCiPipelineRepositoryImpl(db, sugaredLogger, transactionUtilImpl) enforcerUtilImpl := rbac.NewEnforcerUtilImpl(sugaredLogger, teamRepositoryImpl, appRepositoryImpl, environmentRepositoryImpl, pipelineRepositoryImpl, ciPipelineRepositoryImpl, clusterRepositoryImpl, enforcerImpl) k8sApplicationRestHandlerImpl := application2.NewK8sApplicationRestHandlerImpl(sugaredLogger, k8sApplicationServiceImpl, pumpImpl, terminalSessionHandlerImpl, enforcerImpl, enforcerUtilHelmImpl, enforcerUtilImpl, helmAppServiceImpl, userServiceImpl, k8sCommonServiceImpl, validate) k8sApplicationRouterImpl := application2.NewK8sApplicationRouterImpl(k8sApplicationRestHandlerImpl) diff --git a/internal/sql/repository/imageTagging/ImageTaggingRepository.go b/internal/sql/repository/imageTagging/ImageTaggingRepository.go index 680a11afdd..e80f34540a 100644 --- a/internal/sql/repository/imageTagging/ImageTaggingRepository.go +++ b/internal/sql/repository/imageTagging/ImageTaggingRepository.go @@ -85,10 +85,10 @@ type ImageTaggingRepositoryImpl struct { *sql.TransactionUtilImpl } -func NewImageTaggingRepositoryImpl(db *pg.DB) *ImageTaggingRepositoryImpl { +func NewImageTaggingRepositoryImpl(db *pg.DB, TransactionUtilImpl *sql.TransactionUtilImpl) *ImageTaggingRepositoryImpl { return &ImageTaggingRepositoryImpl{ dbConnection: db, - TransactionUtilImpl: sql.NewTransactionUtilImpl(db), + TransactionUtilImpl: TransactionUtilImpl, } } diff --git a/internal/sql/repository/pipelineConfig/CiPipelineRepository.go b/internal/sql/repository/pipelineConfig/CiPipelineRepository.go index f16a4e6cf1..18369aa1c1 100644 --- a/internal/sql/repository/pipelineConfig/CiPipelineRepository.go +++ b/internal/sql/repository/pipelineConfig/CiPipelineRepository.go @@ -150,11 +150,11 @@ type CiPipelineRepositoryImpl struct { *sql.TransactionUtilImpl } -func NewCiPipelineRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger) *CiPipelineRepositoryImpl { +func NewCiPipelineRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger, TransactionUtilImpl *sql.TransactionUtilImpl) *CiPipelineRepositoryImpl { return &CiPipelineRepositoryImpl{ dbConnection: dbConnection, logger: logger, - TransactionUtilImpl: sql.NewTransactionUtilImpl(dbConnection), + TransactionUtilImpl: TransactionUtilImpl, } } diff --git a/pkg/chartRepo/repository/ChartsRepository.go b/pkg/chartRepo/repository/ChartsRepository.go index c742b943c7..4f404b4374 100644 --- a/pkg/chartRepo/repository/ChartsRepository.go +++ b/pkg/chartRepo/repository/ChartsRepository.go @@ -58,10 +58,10 @@ type ChartRepository interface { sql.TransactionWrapper } -func NewChartRepository(dbConnection *pg.DB) *ChartRepositoryImpl { +func NewChartRepository(dbConnection *pg.DB, TransactionUtilImpl *sql.TransactionUtilImpl) *ChartRepositoryImpl { return &ChartRepositoryImpl{ dbConnection: dbConnection, - TransactionUtilImpl: sql.NewTransactionUtilImpl(dbConnection), + TransactionUtilImpl: TransactionUtilImpl, } } diff --git a/pkg/cluster/repository/EphemeralContainersRepository.go b/pkg/cluster/repository/EphemeralContainersRepository.go index 40dce0d66a..de98db7718 100644 --- a/pkg/cluster/repository/EphemeralContainersRepository.go +++ b/pkg/cluster/repository/EphemeralContainersRepository.go @@ -40,10 +40,10 @@ type EphemeralContainersRepository interface { FindContainerByName(clusterID int, namespace, podName, name string) (*EphemeralContainerBean, error) } -func NewEphemeralContainersRepositoryImpl(db *pg.DB) *EphemeralContainersRepositoryImpl { +func NewEphemeralContainersRepositoryImpl(db *pg.DB, transactionUtilImpl *sql.TransactionUtilImpl) *EphemeralContainersRepositoryImpl { return &EphemeralContainersRepositoryImpl{ dbConnection: db, - TransactionUtilImpl: sql.NewTransactionUtilImpl(db), + TransactionUtilImpl: transactionUtilImpl, } } diff --git a/pkg/genericNotes/repository/GenericNoteHistoryRepository.go b/pkg/genericNotes/repository/GenericNoteHistoryRepository.go index 465a397235..9f0427bb85 100644 --- a/pkg/genericNotes/repository/GenericNoteHistoryRepository.go +++ b/pkg/genericNotes/repository/GenericNoteHistoryRepository.go @@ -36,8 +36,7 @@ type GenericNoteHistoryRepository interface { FindHistoryByNoteId(id []int) ([]GenericNoteHistory, error) } -func NewGenericNoteHistoryRepositoryImpl(dbConnection *pg.DB) *GenericNoteHistoryRepositoryImpl { - TransactionUtilImpl := sql.NewTransactionUtilImpl(dbConnection) +func NewGenericNoteHistoryRepositoryImpl(dbConnection *pg.DB, TransactionUtilImpl *sql.TransactionUtilImpl) *GenericNoteHistoryRepositoryImpl { return &GenericNoteHistoryRepositoryImpl{ dbConnection: dbConnection, TransactionUtilImpl: TransactionUtilImpl, diff --git a/pkg/genericNotes/repository/GenericNoteRepository.go b/pkg/genericNotes/repository/GenericNoteRepository.go index 6049f30e43..369b9536ed 100644 --- a/pkg/genericNotes/repository/GenericNoteRepository.go +++ b/pkg/genericNotes/repository/GenericNoteRepository.go @@ -51,8 +51,7 @@ type GenericNoteRepository interface { GetDescriptionFromAppIds(appIds []int) ([]*GenericNote, error) } -func NewGenericNoteRepositoryImpl(dbConnection *pg.DB) *GenericNoteRepositoryImpl { - TransactionUtilImpl := sql.NewTransactionUtilImpl(dbConnection) +func NewGenericNoteRepositoryImpl(dbConnection *pg.DB, TransactionUtilImpl *sql.TransactionUtilImpl) *GenericNoteRepositoryImpl { return &GenericNoteRepositoryImpl{ dbConnection: dbConnection, TransactionUtilImpl: TransactionUtilImpl, diff --git a/pkg/infraConfig/infraConfigRepository.go b/pkg/infraConfig/infraConfigRepository.go index 7bf97817bb..1b29037a3c 100644 --- a/pkg/infraConfig/infraConfigRepository.go +++ b/pkg/infraConfig/infraConfigRepository.go @@ -24,10 +24,10 @@ type InfraConfigRepositoryImpl struct { *sql.TransactionUtilImpl } -func NewInfraProfileRepositoryImpl(dbConnection *pg.DB) *InfraConfigRepositoryImpl { +func NewInfraProfileRepositoryImpl(dbConnection *pg.DB, TransactionUtilImpl *sql.TransactionUtilImpl) *InfraConfigRepositoryImpl { return &InfraConfigRepositoryImpl{ dbConnection: dbConnection, - TransactionUtilImpl: sql.NewTransactionUtilImpl(dbConnection), + TransactionUtilImpl: TransactionUtilImpl, } } diff --git a/pkg/resourceQualifiers/ResourceQualifiersMappingRepository.go b/pkg/resourceQualifiers/ResourceQualifiersMappingRepository.go index edeba3932d..e5f51b359c 100644 --- a/pkg/resourceQualifiers/ResourceQualifiersMappingRepository.go +++ b/pkg/resourceQualifiers/ResourceQualifiersMappingRepository.go @@ -30,11 +30,11 @@ type QualifiersMappingRepositoryImpl struct { logger *zap.SugaredLogger } -func NewQualifiersMappingRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger) (*QualifiersMappingRepositoryImpl, error) { +func NewQualifiersMappingRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger, TransactionUtilImpl *sql.TransactionUtilImpl) (*QualifiersMappingRepositoryImpl, error) { return &QualifiersMappingRepositoryImpl{ dbConnection: dbConnection, logger: logger, - TransactionUtilImpl: sql.NewTransactionUtilImpl(dbConnection), + TransactionUtilImpl: TransactionUtilImpl, }, nil } diff --git a/pkg/variables/repository/ScopedVariableRepository.go b/pkg/variables/repository/ScopedVariableRepository.go index fc6023a48b..7a18d188c1 100644 --- a/pkg/variables/repository/ScopedVariableRepository.go +++ b/pkg/variables/repository/ScopedVariableRepository.go @@ -33,11 +33,11 @@ type ScopedVariableRepositoryImpl struct { logger *zap.SugaredLogger } -func NewScopedVariableRepository(dbConnection *pg.DB, logger *zap.SugaredLogger) *ScopedVariableRepositoryImpl { +func NewScopedVariableRepository(dbConnection *pg.DB, logger *zap.SugaredLogger, TransactionUtilImpl *sql.TransactionUtilImpl) *ScopedVariableRepositoryImpl { return &ScopedVariableRepositoryImpl{ dbConnection: dbConnection, logger: logger, - TransactionUtilImpl: sql.NewTransactionUtilImpl(dbConnection), + TransactionUtilImpl: TransactionUtilImpl, } } diff --git a/pkg/variables/repository/VariableEntityMappingRepository.go b/pkg/variables/repository/VariableEntityMappingRepository.go index eeda18d3f4..9857fcb3b0 100644 --- a/pkg/variables/repository/VariableEntityMappingRepository.go +++ b/pkg/variables/repository/VariableEntityMappingRepository.go @@ -16,11 +16,11 @@ type VariableEntityMappingRepository interface { DeleteVariablesForEntity(tx *pg.Tx, variableIDs []string, entity Entity, userId int32) error } -func NewVariableEntityMappingRepository(logger *zap.SugaredLogger, dbConnection *pg.DB) *VariableEntityMappingRepositoryImpl { +func NewVariableEntityMappingRepository(logger *zap.SugaredLogger, dbConnection *pg.DB, TransactionUtilImpl *sql.TransactionUtilImpl) *VariableEntityMappingRepositoryImpl { return &VariableEntityMappingRepositoryImpl{ logger: logger, dbConnection: dbConnection, - TransactionUtilImpl: sql.NewTransactionUtilImpl(dbConnection), + TransactionUtilImpl: TransactionUtilImpl, } } diff --git a/wire_gen.go b/wire_gen.go index 5163df0977..3e126ae10a 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -1,6 +1,6 @@ // Code generated by Wire. DO NOT EDIT. -//go:generate go run -mod=mod github.com/google/wire/cmd/wire +//go:generate go run github.com/google/wire/cmd/wire //go:build !wireinject // +build !wireinject @@ -336,8 +336,9 @@ func InitializeApp() (*App, error) { k8sCommonServiceImpl := k8s2.NewK8sCommonServiceImpl(sugaredLogger, k8sServiceImpl, clusterServiceImplExtended, argoApplicationServiceImpl) environmentRestHandlerImpl := cluster3.NewEnvironmentRestHandlerImpl(environmentServiceImpl, sugaredLogger, userServiceImpl, validate, enforcerImpl, deleteServiceExtendedImpl, k8sServiceImpl, k8sCommonServiceImpl) environmentRouterImpl := cluster3.NewEnvironmentRouterImpl(environmentRestHandlerImpl) - genericNoteRepositoryImpl := repository6.NewGenericNoteRepositoryImpl(db) - genericNoteHistoryRepositoryImpl := repository6.NewGenericNoteHistoryRepositoryImpl(db) + transactionUtilImpl := sql.NewTransactionUtilImpl(db) + genericNoteRepositoryImpl := repository6.NewGenericNoteRepositoryImpl(db, transactionUtilImpl) + genericNoteHistoryRepositoryImpl := repository6.NewGenericNoteHistoryRepositoryImpl(db, transactionUtilImpl) genericNoteHistoryServiceImpl := genericNotes.NewGenericNoteHistoryServiceImpl(genericNoteHistoryRepositoryImpl, sugaredLogger) genericNoteServiceImpl := genericNotes.NewGenericNoteServiceImpl(genericNoteRepositoryImpl, genericNoteHistoryServiceImpl, userRepositoryImpl, sugaredLogger) clusterDescriptionRepositoryImpl := repository.NewClusterDescriptionRepositoryImpl(db, sugaredLogger) @@ -359,7 +360,7 @@ func InitializeApp() (*App, error) { return nil, err } pubSubClientServiceImpl := pubsub_lib.NewPubSubClientServiceImpl(sugaredLogger) - ciPipelineRepositoryImpl := pipelineConfig.NewCiPipelineRepositoryImpl(db, sugaredLogger) + ciPipelineRepositoryImpl := pipelineConfig.NewCiPipelineRepositoryImpl(db, sugaredLogger, transactionUtilImpl) moduleActionAuditLogRepositoryImpl := module.NewModuleActionAuditLogRepositoryImpl(db) serverCacheServiceImpl := server.NewServerCacheServiceImpl(sugaredLogger, serverEnvConfigServerEnvConfig, serverDataStoreServerDataStore, helmAppServiceImpl) moduleEnvConfig, err := module.ParseModuleEnvConfig() @@ -385,7 +386,7 @@ func InitializeApp() (*App, error) { eventSimpleFactoryImpl := client2.NewEventSimpleFactoryImpl(sugaredLogger, cdWorkflowRepositoryImpl, pipelineOverrideRepositoryImpl, ciWorkflowRepositoryImpl, ciPipelineMaterialRepositoryImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, userRepositoryImpl, ciArtifactRepositoryImpl) applicationServiceClientImpl := application.NewApplicationClientImpl(sugaredLogger, argoCDConnectionManagerImpl) configMapRepositoryImpl := chartConfig.NewConfigMapRepositoryImpl(sugaredLogger, db) - chartRepositoryImpl := chartRepoRepository.NewChartRepository(db) + chartRepositoryImpl := chartRepoRepository.NewChartRepository(db, transactionUtilImpl) gitProviderRepositoryImpl := repository2.NewGitProviderRepositoryImpl(db) commonServiceImpl := commonService.NewCommonServiceImpl(sugaredLogger, chartRepositoryImpl, installedAppRepositoryImpl, envConfigOverrideRepositoryImpl, dockerArtifactStoreRepositoryImpl, attributesRepositoryImpl, gitProviderRepositoryImpl, environmentRepositoryImpl, teamRepositoryImpl, appRepositoryImpl, gitOpsConfigReadServiceImpl) chartTemplateServiceImpl := util.NewChartTemplateServiceImpl(sugaredLogger) @@ -402,13 +403,13 @@ func InitializeApp() (*App, error) { } enforcerUtilImpl := rbac.NewEnforcerUtilImpl(sugaredLogger, teamRepositoryImpl, appRepositoryImpl, environmentRepositoryImpl, pipelineRepositoryImpl, ciPipelineRepositoryImpl, clusterRepositoryImpl, enforcerImpl) appStatusServiceImpl := appStatus2.NewAppStatusServiceImpl(appStatusRepositoryImpl, sugaredLogger, enforcerImpl, enforcerUtilImpl) - scopedVariableRepositoryImpl := repository7.NewScopedVariableRepository(db, sugaredLogger) + scopedVariableRepositoryImpl := repository7.NewScopedVariableRepository(db, sugaredLogger, transactionUtilImpl) devtronResourceSearchableKeyRepositoryImpl := repository8.NewDevtronResourceSearchableKeyRepositoryImpl(sugaredLogger, db) devtronResourceSearchableKeyServiceImpl, err := devtronResource.NewDevtronResourceSearchableKeyServiceImpl(sugaredLogger, devtronResourceSearchableKeyRepositoryImpl) if err != nil { return nil, err } - qualifiersMappingRepositoryImpl, err := resourceQualifiers.NewQualifiersMappingRepositoryImpl(db, sugaredLogger) + qualifiersMappingRepositoryImpl, err := resourceQualifiers.NewQualifiersMappingRepositoryImpl(db, sugaredLogger, transactionUtilImpl) if err != nil { return nil, err } @@ -420,7 +421,7 @@ func InitializeApp() (*App, error) { if err != nil { return nil, err } - variableEntityMappingRepositoryImpl := repository7.NewVariableEntityMappingRepository(sugaredLogger, db) + variableEntityMappingRepositoryImpl := repository7.NewVariableEntityMappingRepository(sugaredLogger, db, transactionUtilImpl) variableEntityMappingServiceImpl := variables.NewVariableEntityMappingServiceImpl(variableEntityMappingRepositoryImpl, sugaredLogger) variableSnapshotHistoryRepositoryImpl := repository7.NewVariableSnapshotHistoryRepository(sugaredLogger, db) variableSnapshotHistoryServiceImpl := variables.NewVariableSnapshotHistoryServiceImpl(variableSnapshotHistoryRepositoryImpl, sugaredLogger) @@ -452,7 +453,7 @@ func InitializeApp() (*App, error) { globalCMCSServiceImpl := pipeline.NewGlobalCMCSServiceImpl(sugaredLogger, globalCMCSRepositoryImpl) argoWorkflowExecutorImpl := executors.NewArgoWorkflowExecutorImpl(sugaredLogger) systemWorkflowExecutorImpl := executors.NewSystemWorkflowExecutorImpl(sugaredLogger, k8sServiceImpl) - infraConfigRepositoryImpl := infraConfig.NewInfraProfileRepositoryImpl(db) + infraConfigRepositoryImpl := infraConfig.NewInfraProfileRepositoryImpl(db, transactionUtilImpl) unitsUnits := units.NewUnits() infraConfigServiceImpl, err := infraConfig.NewInfraConfigServiceImpl(sugaredLogger, infraConfigRepositoryImpl, appServiceImpl, unitsUnits) if err != nil { @@ -501,7 +502,7 @@ func InitializeApp() (*App, error) { resourceGroupRepositoryImpl := resourceGroup.NewResourceGroupRepositoryImpl(db) resourceGroupMappingRepositoryImpl := resourceGroup.NewResourceGroupMappingRepositoryImpl(db) resourceGroupServiceImpl := resourceGroup2.NewResourceGroupServiceImpl(sugaredLogger, resourceGroupRepositoryImpl, resourceGroupMappingRepositoryImpl, enforcerUtilImpl, devtronResourceSearchableKeyServiceImpl, appStatusRepositoryImpl) - imageTaggingRepositoryImpl := repository11.NewImageTaggingRepositoryImpl(db) + imageTaggingRepositoryImpl := repository11.NewImageTaggingRepositoryImpl(db, transactionUtilImpl) imageTaggingServiceImpl := pipeline.NewImageTaggingServiceImpl(imageTaggingRepositoryImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, environmentRepositoryImpl, sugaredLogger) blobStorageConfigServiceImpl := pipeline.NewBlobStorageConfigServiceImpl(sugaredLogger, k8sServiceImpl, ciCdConfig) ciHandlerImpl := pipeline.NewCiHandlerImpl(sugaredLogger, ciServiceImpl, ciPipelineMaterialRepositoryImpl, clientImpl, ciWorkflowRepositoryImpl, workflowServiceImpl, ciLogServiceImpl, ciArtifactRepositoryImpl, userServiceImpl, eventRESTClientImpl, eventSimpleFactoryImpl, ciPipelineRepositoryImpl, appListingRepositoryImpl, k8sServiceImpl, pipelineRepositoryImpl, enforcerUtilImpl, resourceGroupServiceImpl, environmentRepositoryImpl, imageTaggingServiceImpl, k8sCommonServiceImpl, clusterServiceImplExtended, blobStorageConfigServiceImpl, appWorkflowRepositoryImpl, customTagServiceImpl, environmentServiceImpl) @@ -524,7 +525,7 @@ func InitializeApp() (*App, error) { deployedAppMetricsServiceImpl := deployedAppMetrics.NewDeployedAppMetricsServiceImpl(sugaredLogger, appLevelMetricsRepositoryImpl, envLevelAppMetricsRepositoryImpl, chartRefServiceImpl) deploymentTemplateHistoryServiceImpl := history.NewDeploymentTemplateHistoryServiceImpl(sugaredLogger, deploymentTemplateHistoryRepositoryImpl, pipelineRepositoryImpl, chartRepositoryImpl, userServiceImpl, cdWorkflowRepositoryImpl, scopedVariableManagerImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl) chartServiceImpl := chart.NewChartServiceImpl(chartRepositoryImpl, sugaredLogger, chartTemplateServiceImpl, chartRepoRepositoryImpl, appRepositoryImpl, utilMergeUtil, envConfigOverrideRepositoryImpl, pipelineConfigRepositoryImpl, environmentRepositoryImpl, deploymentTemplateHistoryServiceImpl, scopedVariableManagerImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl, gitOpsConfigReadServiceImpl) - ciCdPipelineOrchestratorImpl := pipeline.NewCiCdPipelineOrchestrator(appRepositoryImpl, sugaredLogger, materialRepositoryImpl, pipelineRepositoryImpl, ciPipelineRepositoryImpl, ciPipelineMaterialRepositoryImpl, cdWorkflowRepositoryImpl, clientImpl, ciCdConfig, appWorkflowRepositoryImpl, environmentRepositoryImpl, attributesServiceImpl, appCrudOperationServiceImpl, userAuthServiceImpl, prePostCdScriptHistoryServiceImpl, pipelineStageServiceImpl, gitMaterialHistoryServiceImpl, ciPipelineHistoryServiceImpl, ciTemplateServiceImpl, dockerArtifactStoreRepositoryImpl, ciArtifactRepositoryImpl, configMapServiceImpl, customTagServiceImpl, genericNoteServiceImpl, chartServiceImpl) + ciCdPipelineOrchestratorImpl := pipeline.NewCiCdPipelineOrchestrator(appRepositoryImpl, sugaredLogger, materialRepositoryImpl, pipelineRepositoryImpl, ciPipelineRepositoryImpl, ciPipelineMaterialRepositoryImpl, cdWorkflowRepositoryImpl, clientImpl, ciCdConfig, appWorkflowRepositoryImpl, environmentRepositoryImpl, attributesServiceImpl, appCrudOperationServiceImpl, userAuthServiceImpl, prePostCdScriptHistoryServiceImpl, pipelineStageServiceImpl, gitMaterialHistoryServiceImpl, ciPipelineHistoryServiceImpl, ciTemplateServiceImpl, dockerArtifactStoreRepositoryImpl, ciArtifactRepositoryImpl, configMapServiceImpl, customTagServiceImpl, genericNoteServiceImpl, chartServiceImpl, transactionUtilImpl) ecrConfig, err := pipeline.GetEcrConfig() if err != nil { return nil, err @@ -533,7 +534,7 @@ func InitializeApp() (*App, error) { ciTemplateHistoryServiceImpl := history.NewCiTemplateHistoryServiceImpl(ciTemplateHistoryRepositoryImpl, sugaredLogger) buildPipelineSwitchServiceImpl := pipeline.NewBuildPipelineSwitchServiceImpl(sugaredLogger, ciPipelineRepositoryImpl, ciCdPipelineOrchestratorImpl, pipelineRepositoryImpl, ciWorkflowRepositoryImpl, appWorkflowRepositoryImpl, ciPipelineHistoryServiceImpl, ciTemplateOverrideRepositoryImpl, ciPipelineMaterialRepositoryImpl) ciPipelineConfigServiceImpl := pipeline.NewCiPipelineConfigServiceImpl(sugaredLogger, ciCdPipelineOrchestratorImpl, dockerArtifactStoreRepositoryImpl, materialRepositoryImpl, appRepositoryImpl, pipelineRepositoryImpl, ciPipelineRepositoryImpl, ecrConfig, appWorkflowRepositoryImpl, ciCdConfig, attributesServiceImpl, pipelineStageServiceImpl, ciPipelineMaterialRepositoryImpl, ciTemplateServiceImpl, ciTemplateOverrideRepositoryImpl, ciTemplateHistoryServiceImpl, enforcerUtilImpl, ciWorkflowRepositoryImpl, resourceGroupServiceImpl, customTagServiceImpl, cdWorkflowRepositoryImpl, buildPipelineSwitchServiceImpl) - ciMaterialConfigServiceImpl := pipeline.NewCiMaterialConfigServiceImpl(sugaredLogger, materialRepositoryImpl, ciTemplateServiceImpl, ciCdPipelineOrchestratorImpl, ciPipelineRepositoryImpl, gitMaterialHistoryServiceImpl, pipelineRepositoryImpl, ciPipelineMaterialRepositoryImpl) + ciMaterialConfigServiceImpl := pipeline.NewCiMaterialConfigServiceImpl(sugaredLogger, materialRepositoryImpl, ciTemplateServiceImpl, ciCdPipelineOrchestratorImpl, ciPipelineRepositoryImpl, gitMaterialHistoryServiceImpl, pipelineRepositoryImpl, ciPipelineMaterialRepositoryImpl, transactionUtilImpl) deploymentGroupRepositoryImpl := repository2.NewDeploymentGroupRepositoryImpl(sugaredLogger, db) pipelineStrategyHistoryRepositoryImpl := repository12.NewPipelineStrategyHistoryRepositoryImpl(sugaredLogger, db) pipelineStrategyHistoryServiceImpl := history.NewPipelineStrategyHistoryServiceImpl(sugaredLogger, pipelineStrategyHistoryRepositoryImpl, userServiceImpl) @@ -640,7 +641,7 @@ func InitializeApp() (*App, error) { configMapRouterImpl := router.NewConfigMapRouterImpl(configMapRestHandlerImpl) k8sResourceHistoryRepositoryImpl := repository15.NewK8sResourceHistoryRepositoryImpl(db, sugaredLogger) k8sResourceHistoryServiceImpl := kubernetesResourceAuditLogs.Newk8sResourceHistoryServiceImpl(k8sResourceHistoryRepositoryImpl, sugaredLogger, appRepositoryImpl, environmentRepositoryImpl) - ephemeralContainersRepositoryImpl := repository.NewEphemeralContainersRepositoryImpl(db) + ephemeralContainersRepositoryImpl := repository.NewEphemeralContainersRepositoryImpl(db, transactionUtilImpl) ephemeralContainerServiceImpl := cluster2.NewEphemeralContainerServiceImpl(ephemeralContainersRepositoryImpl, sugaredLogger) terminalSessionHandlerImpl := terminal.NewTerminalSessionHandlerImpl(environmentServiceImpl, clusterServiceImplExtended, sugaredLogger, k8sServiceImpl, ephemeralContainerServiceImpl, argoApplicationServiceImpl) k8sApplicationServiceImpl, err := application2.NewK8sApplicationServiceImpl(sugaredLogger, clusterServiceImplExtended, pumpImpl, helmAppServiceImpl, k8sServiceImpl, acdAuthConfig, k8sResourceHistoryServiceImpl, k8sCommonServiceImpl, terminalSessionHandlerImpl, ephemeralContainerServiceImpl, ephemeralContainersRepositoryImpl, argoApplicationServiceImpl) From fdaf1c0a507c64fc82b9bb1d5231fee0ad6a2b47 Mon Sep 17 00:00:00 2001 From: ShashwatDadhich Date: Wed, 1 May 2024 15:19:27 +0530 Subject: [PATCH 3/5] code review comments incorporated --- pkg/pipeline/CiCdPipelineOrchestrator.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/pipeline/CiCdPipelineOrchestrator.go b/pkg/pipeline/CiCdPipelineOrchestrator.go index c580aca65e..a827fd33ee 100644 --- a/pkg/pipeline/CiCdPipelineOrchestrator.go +++ b/pkg/pipeline/CiCdPipelineOrchestrator.go @@ -1283,11 +1283,6 @@ func (impl CiCdPipelineOrchestratorImpl) CreateMaterials(createMaterialRequest * if err != nil { impl.logger.Errorw("error in rollback Create material", "err", err) } - } else { - err = impl.transactionManager.CommitTx(tx) - if err != nil { - impl.logger.Errorw("error in committing tx Create material", "err", err) - } } }() existingMaterials, err := impl.materialRepository.FindByAppId(createMaterialRequest.AppId) @@ -1326,6 +1321,11 @@ func (impl CiCdPipelineOrchestratorImpl) CreateMaterials(createMaterialRequest * impl.logger.Errorw("error in updating to sensor", "err", err) return nil, err } + err = impl.transactionManager.CommitTx(tx) + if err != nil { + impl.logger.Errorw("error in committing tx Create material", "err", err) + return nil, err + } impl.logger.Debugw("all materials are ", "materials", materials) return createMaterialRequest, nil } @@ -1341,11 +1341,6 @@ func (impl CiCdPipelineOrchestratorImpl) UpdateMaterial(updateMaterialDTO *bean. if err != nil { impl.logger.Errorw("error in rollback Update material", "err", err) } - } else { - err = impl.transactionManager.CommitTx(tx) - if err != nil { - impl.logger.Errorw("error in committing tx Update material", "err", err) - } } }() updatedMaterial, err := impl.updateMaterial(updateMaterialDTO, tx) @@ -1359,6 +1354,11 @@ func (impl CiCdPipelineOrchestratorImpl) UpdateMaterial(updateMaterialDTO *bean. impl.logger.Errorw("error in updating to git-sensor", "err", err) return nil, err } + err = impl.transactionManager.CommitTx(tx) + if err != nil { + impl.logger.Errorw("error in committing tx Update material", "err", err) + return nil, err + } return updateMaterialDTO, nil } From 2f6be7557b4b44baea5a2957c0c85ba35fb64708 Mon Sep 17 00:00:00 2001 From: ShashwatDadhich Date: Wed, 1 May 2024 19:57:02 +0530 Subject: [PATCH 4/5] code review comments incorporated --- pkg/pipeline/CiCdPipelineOrchestrator.go | 18 ++---------------- pkg/pipeline/CiMaterialConfigService.go | 10 ++-------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/pkg/pipeline/CiCdPipelineOrchestrator.go b/pkg/pipeline/CiCdPipelineOrchestrator.go index a827fd33ee..c32611f92c 100644 --- a/pkg/pipeline/CiCdPipelineOrchestrator.go +++ b/pkg/pipeline/CiCdPipelineOrchestrator.go @@ -1277,14 +1277,7 @@ func (impl CiCdPipelineOrchestratorImpl) CreateMaterials(createMaterialRequest * if err != nil { return nil, err } - defer func() { - if err != nil { - err := tx.Rollback() - if err != nil { - impl.logger.Errorw("error in rollback Create material", "err", err) - } - } - }() + defer tx.Rollback() existingMaterials, err := impl.materialRepository.FindByAppId(createMaterialRequest.AppId) if err != nil { impl.logger.Errorw("err", "err", err) @@ -1335,14 +1328,7 @@ func (impl CiCdPipelineOrchestratorImpl) UpdateMaterial(updateMaterialDTO *bean. if err != nil { return nil, err } - defer func() { - if err != nil { - err := tx.Rollback() - if err != nil { - impl.logger.Errorw("error in rollback Update material", "err", err) - } - } - }() + defer tx.Rollback() updatedMaterial, err := impl.updateMaterial(updateMaterialDTO, tx) if err != nil { impl.logger.Errorw("err", "err", err) diff --git a/pkg/pipeline/CiMaterialConfigService.go b/pkg/pipeline/CiMaterialConfigService.go index 31ad40422e..3e7264797e 100644 --- a/pkg/pipeline/CiMaterialConfigService.go +++ b/pkg/pipeline/CiMaterialConfigService.go @@ -129,14 +129,8 @@ func (impl *CiMaterialConfigServiceImpl) DeleteMaterial(request *bean.UpdateMate if err != nil { return err } - defer func() { - if err != nil { - err := tx.Rollback() - if err != nil { - impl.logger.Errorw("error in rollback ", "err", err) - } - } - }() + + defer tx.Rollback() err = impl.materialRepo.MarkMaterialDeleted(existingMaterial, tx) if err != nil { From 74e1e75a995f70a29b302c72441ad0598a672254 Mon Sep 17 00:00:00 2001 From: ShashwatDadhich Date: Wed, 1 May 2024 20:10:52 +0530 Subject: [PATCH 5/5] code review comments incorporated --- .../pipelineConfig/MaterialRepository.go | 12 ++++++------ pkg/pipeline/CiCdPipelineOrchestrator.go | 18 +++++++++--------- pkg/pipeline/CiMaterialConfigService.go | 4 ++-- .../history/GitMaterialHistoryService.go | 12 ++++++------ .../repository/GitMaterialHistoryRepository.go | 4 ++-- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/internal/sql/repository/pipelineConfig/MaterialRepository.go b/internal/sql/repository/pipelineConfig/MaterialRepository.go index 94930c2e64..6f7d2087bf 100644 --- a/internal/sql/repository/pipelineConfig/MaterialRepository.go +++ b/internal/sql/repository/pipelineConfig/MaterialRepository.go @@ -52,8 +52,8 @@ type GitMaterial struct { type MaterialRepository interface { MaterialExists(url string) (bool, error) - SaveMaterial(material *GitMaterial, tx *pg.Tx) error - UpdateMaterial(material *GitMaterial, tx *pg.Tx) error + SaveMaterial(tx *pg.Tx, material *GitMaterial) error + UpdateMaterial(tx *pg.Tx, material *GitMaterial) error Update(materials []*GitMaterial) error FindByAppId(appId int) ([]*GitMaterial, error) FindById(Id int) (*GitMaterial, error) @@ -61,7 +61,7 @@ type MaterialRepository interface { UpdateMaterialScmId(material *GitMaterial) error FindByAppIdAndCheckoutPath(appId int, checkoutPath string) (*GitMaterial, error) FindByGitProviderId(gitProviderId int) (materials []*GitMaterial, err error) - MarkMaterialDeleted(material *GitMaterial, tx *pg.Tx) error + MarkMaterialDeleted(tx *pg.Tx, material *GitMaterial) error FindNumberOfAppsWithGitRepo(appIds []int) (int, error) FindByAppIds(appIds []int) ([]*GitMaterial, error) } @@ -113,11 +113,11 @@ func (repo MaterialRepositoryImpl) MaterialExists(url string) (bool, error) { return exists, err } -func (repo MaterialRepositoryImpl) SaveMaterial(material *GitMaterial, tx *pg.Tx) error { +func (repo MaterialRepositoryImpl) SaveMaterial(tx *pg.Tx, material *GitMaterial) error { return tx.Insert(material) } -func (repo MaterialRepositoryImpl) UpdateMaterial(material *GitMaterial, tx *pg.Tx) error { +func (repo MaterialRepositoryImpl) UpdateMaterial(tx *pg.Tx, material *GitMaterial) error { return tx.Update(material) } @@ -164,7 +164,7 @@ func (repo MaterialRepositoryImpl) FindByGitProviderId(gitProviderId int) (mater return materials, err } -func (repo MaterialRepositoryImpl) MarkMaterialDeleted(material *GitMaterial, tx *pg.Tx) error { +func (repo MaterialRepositoryImpl) MarkMaterialDeleted(tx *pg.Tx, material *GitMaterial) error { material.Active = false return tx.Update(material) } diff --git a/pkg/pipeline/CiCdPipelineOrchestrator.go b/pkg/pipeline/CiCdPipelineOrchestrator.go index c32611f92c..a8f03e2629 100644 --- a/pkg/pipeline/CiCdPipelineOrchestrator.go +++ b/pkg/pipeline/CiCdPipelineOrchestrator.go @@ -1302,7 +1302,7 @@ func (impl CiCdPipelineOrchestratorImpl) CreateMaterials(createMaterialRequest * var materials []*bean.GitMaterial for _, inputMaterial := range createMaterialRequest.Material { inputMaterial.UpdateSanitisedGitRepoUrl() - m, err := impl.createMaterial(inputMaterial, createMaterialRequest.AppId, createMaterialRequest.UserId, tx) + m, err := impl.createMaterial(tx, inputMaterial, createMaterialRequest.AppId, createMaterialRequest.UserId) inputMaterial.Id = m.Id if err != nil { return nil, err @@ -1316,7 +1316,7 @@ func (impl CiCdPipelineOrchestratorImpl) CreateMaterials(createMaterialRequest * } err = impl.transactionManager.CommitTx(tx) if err != nil { - impl.logger.Errorw("error in committing tx Create material", "err", err) + impl.logger.Errorw("error in committing tx Create material", "err", err, "materials", materials) return nil, err } impl.logger.Debugw("all materials are ", "materials", materials) @@ -1329,7 +1329,7 @@ func (impl CiCdPipelineOrchestratorImpl) UpdateMaterial(updateMaterialDTO *bean. return nil, err } defer tx.Rollback() - updatedMaterial, err := impl.updateMaterial(updateMaterialDTO, tx) + updatedMaterial, err := impl.updateMaterial(tx, updateMaterialDTO) if err != nil { impl.logger.Errorw("err", "err", err) return nil, err @@ -1478,7 +1478,7 @@ func (impl CiCdPipelineOrchestratorImpl) validateCheckoutPathsForMultiGit(allPat return nil } -func (impl CiCdPipelineOrchestratorImpl) updateMaterial(updateMaterialDTO *bean.UpdateMaterialDTO, tx *pg.Tx) (*pipelineConfig.GitMaterial, error) { +func (impl CiCdPipelineOrchestratorImpl) updateMaterial(tx *pg.Tx, updateMaterialDTO *bean.UpdateMaterialDTO) (*pipelineConfig.GitMaterial, error) { existingMaterials, err := impl.materialRepository.FindByAppId(updateMaterialDTO.AppId) if err != nil { impl.logger.Errorw("err", "err", err) @@ -1519,19 +1519,19 @@ func (impl CiCdPipelineOrchestratorImpl) updateMaterial(updateMaterialDTO *bean. currentMaterial.FilterPattern = updateMaterialDTO.Material.FilterPattern currentMaterial.AuditLog = sql.AuditLog{UpdatedBy: updateMaterialDTO.UserId, CreatedBy: currentMaterial.CreatedBy, UpdatedOn: time.Now(), CreatedOn: currentMaterial.CreatedOn} - err = impl.materialRepository.UpdateMaterial(currentMaterial, tx) + err = impl.materialRepository.UpdateMaterial(tx, currentMaterial) if err != nil { impl.logger.Errorw("error in updating material", "material", currentMaterial, "err", err) return nil, err } - err = impl.gitMaterialHistoryService.CreateMaterialHistory(currentMaterial, tx) + err = impl.gitMaterialHistoryService.CreateMaterialHistory(tx, currentMaterial) return currentMaterial, nil } -func (impl CiCdPipelineOrchestratorImpl) createMaterial(inputMaterial *bean.GitMaterial, appId int, userId int32, tx *pg.Tx) (*pipelineConfig.GitMaterial, error) { +func (impl CiCdPipelineOrchestratorImpl) createMaterial(tx *pg.Tx, inputMaterial *bean.GitMaterial, appId int, userId int32) (*pipelineConfig.GitMaterial, error) { basePath := path.Base(inputMaterial.Url) basePath = strings.TrimSuffix(basePath, ".git") material := &pipelineConfig.GitMaterial{ @@ -1545,12 +1545,12 @@ func (impl CiCdPipelineOrchestratorImpl) createMaterial(inputMaterial *bean.GitM FilterPattern: inputMaterial.FilterPattern, AuditLog: sql.AuditLog{UpdatedBy: userId, CreatedBy: userId, UpdatedOn: time.Now(), CreatedOn: time.Now()}, } - err := impl.materialRepository.SaveMaterial(material, tx) + err := impl.materialRepository.SaveMaterial(tx, material) if err != nil { impl.logger.Errorw("error in saving material", "material", material, "err", err) return nil, err } - err = impl.gitMaterialHistoryService.CreateMaterialHistory(material, tx) + err = impl.gitMaterialHistoryService.CreateMaterialHistory(tx, material) return material, err } diff --git a/pkg/pipeline/CiMaterialConfigService.go b/pkg/pipeline/CiMaterialConfigService.go index 3e7264797e..d1acbc0d8d 100644 --- a/pkg/pipeline/CiMaterialConfigService.go +++ b/pkg/pipeline/CiMaterialConfigService.go @@ -132,13 +132,13 @@ func (impl *CiMaterialConfigServiceImpl) DeleteMaterial(request *bean.UpdateMate defer tx.Rollback() - err = impl.materialRepo.MarkMaterialDeleted(existingMaterial, tx) + err = impl.materialRepo.MarkMaterialDeleted(tx, existingMaterial) if err != nil { impl.logger.Errorw("error in deleting git material", "gitMaterial", existingMaterial) return err } - err = impl.gitMaterialHistoryService.MarkMaterialDeletedAndCreateHistory(existingMaterial, tx) + err = impl.gitMaterialHistoryService.MarkMaterialDeletedAndCreateHistory(tx, existingMaterial) var materials []*pipelineConfig.CiPipelineMaterial for _, pipeline := range pipelines { diff --git a/pkg/pipeline/history/GitMaterialHistoryService.go b/pkg/pipeline/history/GitMaterialHistoryService.go index f41665f56f..af5f7ba08c 100644 --- a/pkg/pipeline/history/GitMaterialHistoryService.go +++ b/pkg/pipeline/history/GitMaterialHistoryService.go @@ -9,9 +9,9 @@ import ( ) type GitMaterialHistoryService interface { - CreateMaterialHistory(inputMaterial *pipelineConfig.GitMaterial, tx *pg.Tx) error + CreateMaterialHistory(tx *pg.Tx, inputMaterial *pipelineConfig.GitMaterial) error CreateDeleteMaterialHistory(materials []*pipelineConfig.GitMaterial) error - MarkMaterialDeletedAndCreateHistory(material *pipelineConfig.GitMaterial, tx *pg.Tx) error + MarkMaterialDeletedAndCreateHistory(tx *pg.Tx, material *pipelineConfig.GitMaterial) error } type GitMaterialHistoryServiceImpl struct { @@ -28,7 +28,7 @@ func NewGitMaterialHistoryServiceImpl(gitMaterialHistoryRepository repository.Gi } } -func (impl GitMaterialHistoryServiceImpl) CreateMaterialHistory(inputMaterial *pipelineConfig.GitMaterial, tx *pg.Tx) error { +func (impl GitMaterialHistoryServiceImpl) CreateMaterialHistory(tx *pg.Tx, inputMaterial *pipelineConfig.GitMaterial) error { material := &repository.GitMaterialHistory{ GitMaterialId: inputMaterial.Id, @@ -42,7 +42,7 @@ func (impl GitMaterialHistoryServiceImpl) CreateMaterialHistory(inputMaterial *p FilterPattern: inputMaterial.FilterPattern, AuditLog: sql.AuditLog{UpdatedBy: inputMaterial.UpdatedBy, CreatedBy: inputMaterial.CreatedBy, UpdatedOn: inputMaterial.UpdatedOn, CreatedOn: inputMaterial.CreatedOn}, } - err := impl.gitMaterialHistoryRepository.SaveGitMaterialHistory(material, tx) + err := impl.gitMaterialHistoryRepository.SaveGitMaterialHistory(tx, material) if err != nil { impl.logger.Errorw("error in saving create/update history for git repository") } @@ -87,11 +87,11 @@ func (impl GitMaterialHistoryServiceImpl) CreateDeleteMaterialHistory(materials } -func (impl GitMaterialHistoryServiceImpl) MarkMaterialDeletedAndCreateHistory(material *pipelineConfig.GitMaterial, tx *pg.Tx) error { +func (impl GitMaterialHistoryServiceImpl) MarkMaterialDeletedAndCreateHistory(tx *pg.Tx, material *pipelineConfig.GitMaterial) error { material.Active = false - err := impl.CreateMaterialHistory(material, tx) + err := impl.CreateMaterialHistory(tx, material) if err != nil { impl.logger.Errorw("error in saving delete history for git material repository") diff --git a/pkg/pipeline/history/repository/GitMaterialHistoryRepository.go b/pkg/pipeline/history/repository/GitMaterialHistoryRepository.go index 51fffb8329..6f6c15a211 100644 --- a/pkg/pipeline/history/repository/GitMaterialHistoryRepository.go +++ b/pkg/pipeline/history/repository/GitMaterialHistoryRepository.go @@ -21,7 +21,7 @@ type GitMaterialHistory struct { } type GitMaterialHistoryRepository interface { - SaveGitMaterialHistory(material *GitMaterialHistory, tx *pg.Tx) error + SaveGitMaterialHistory(tx *pg.Tx, material *GitMaterialHistory) error SaveDeleteMaterialHistory(materials []*GitMaterialHistory) error } @@ -35,7 +35,7 @@ func NewGitMaterialHistoryRepositoyImpl(dbConnection *pg.DB) *GitMaterialHistory } } -func (repo GitMaterialHistoryRepositoryImpl) SaveGitMaterialHistory(material *GitMaterialHistory, tx *pg.Tx) error { +func (repo GitMaterialHistoryRepositoryImpl) SaveGitMaterialHistory(tx *pg.Tx, material *GitMaterialHistory) error { return tx.Insert(material) }