Skip to content

Commit

Permalink
fix: wf deletion bug and bulk cd pipeline req (#2693)
Browse files Browse the repository at this point in the history
* fix for wf deletion bug and bulk cd pipeline req

* fix
  • Loading branch information
kartik-579 authored Nov 28, 2022
1 parent 4c31141 commit bb7cea3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
17 changes: 15 additions & 2 deletions internal/sql/repository/appWorkflow/AppWorkflowRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type AppWorkflowRepository interface {
FindWFCDMappingByExternalCiId(externalCiId int) ([]*AppWorkflowMapping, error)
FindByTypeAndComponentId(wfId int, componentId int, componentType string) (*AppWorkflowMapping, error)
FindAllWfsHavingCdPipelinesFromSpecificEnvsOnly(envIds []int, appIds []int) ([]*AppWorkflowMapping, error)
FindCiPipelineIdsFromAppWfIds(appWfIds []int) ([]int, error)
}

type AppWorkflowRepositoryImpl struct {
Expand Down Expand Up @@ -349,17 +350,29 @@ func (impl AppWorkflowRepositoryImpl) DeleteAppWorkflowMappingsByCdPipelineId(pi
func (impl AppWorkflowRepositoryImpl) FindAllWfsHavingCdPipelinesFromSpecificEnvsOnly(envIds []int, appIds []int) ([]*AppWorkflowMapping, error) {
var models []*AppWorkflowMapping
query := `select * from app_workflow_mapping awm inner join app_workflow aw on aw.id=awm.app_workflow_id
where aw.app_id in (?) and awm.active = ? and awm.app_workflow_id not in
where awm.type = ? and aw.app_id in (?) and awm.active = ? and awm.app_workflow_id not in
(select app_workflow_id from app_workflow_mapping awm inner join pipeline p on p.id=awm.component_id
and awm.type = ? and p.environment_id not in (?) and p.app_id in (?) and p.deleted = ? and awm.active = ?); `
_, err := impl.dbConnection.Query(&models, query, pg.In(appIds), true, CDPIPELINE, pg.In(envIds), pg.In(appIds), false, true)
_, err := impl.dbConnection.Query(&models, query, CDPIPELINE, pg.In(appIds), true, CDPIPELINE, pg.In(envIds), pg.In(appIds), false, true)
if err != nil {
impl.Logger.Errorw("error, FindAllWfsHavingCdPipelinesFromSpecificEnvsOnly", "err", err)
return nil, err
}
return models, nil
}

func (impl AppWorkflowRepositoryImpl) FindCiPipelineIdsFromAppWfIds(appWfIds []int) ([]int, error) {
var ciPipelineIds []int
query := `select DISTINCT component_id from app_workflow_mapping
where type = ? and app_workflow_id in (?) and active = ?; `
_, err := impl.dbConnection.Query(&ciPipelineIds, query, CIPIPELINE, pg.In(appWfIds), true)
if err != nil {
impl.Logger.Errorw("error, FindCiPipelineIdsFromAppWfIds", "err", err)
return nil, err
}
return ciPipelineIds, nil
}

func (impl AppWorkflowRepositoryImpl) FindWFCDMappingByExternalCiId(externalCiId int) ([]*AppWorkflowMapping, error) {
var models []*AppWorkflowMapping
err := impl.dbConnection.Model(&models).
Expand Down
5 changes: 3 additions & 2 deletions pkg/appWorkflow/AppWorkflowService.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ func (impl AppWorkflowServiceImpl) CreateAppWorkflow(req AppWorkflowDto) (AppWor

if req.Id != 0 {
wf = &appWorkflow.AppWorkflow{
Id: req.Id,
Name: req.Name,
Id: req.Id,
Name: req.Name,
Active: true,
AuditLog: sql.AuditLog{
UpdatedOn: time.Now(),
UpdatedBy: req.UserId,
Expand Down
13 changes: 9 additions & 4 deletions pkg/bulkAction/BulkUpdateService.go
Original file line number Diff line number Diff line change
Expand Up @@ -1325,23 +1325,28 @@ func (impl BulkUpdateServiceImpl) GetBulkActionImpactedPipelinesAndWfs(dto *CdBu
}
} else {
//getting all workflows in given apps which do not have pipelines of other than given environments
appWfs, err := impl.appWorkflowRepository.FindAllWfsHavingCdPipelinesFromSpecificEnvsOnly(dto.EnvIds, dto.AppIds)
appWfsHavingSpecificCdPipelines, err := impl.appWorkflowRepository.FindAllWfsHavingCdPipelinesFromSpecificEnvsOnly(dto.EnvIds, dto.AppIds)
if err != nil && err != pg.ErrNoRows {
impl.logger.Errorw("error in getting wfs having cd pipelines from specific env only", "err", err)
return nil, nil, nil, err
}
impactedWfIdsMap := make(map[int]bool)
for _, appWf := range appWfs {
for _, appWf := range appWfsHavingSpecificCdPipelines {
if appWf.Type == appWorkflow.CDPIPELINE {
impactedPipelineIds = append(impactedPipelineIds, appWf.ComponentId)
} else if appWf.Type == appWorkflow.CIPIPELINE {
impactedCiPipelineIds = append(impactedCiPipelineIds, appWf.ComponentId)
}
if _, ok := impactedWfIdsMap[appWf.AppWorkflowId]; !ok {
impactedWfIds = append(impactedWfIds, appWf.AppWorkflowId)
impactedWfIdsMap[appWf.AppWorkflowId] = true
}
}
if len(impactedWfIds) > 0 {
impactedCiPipelineIds, err = impl.appWorkflowRepository.FindCiPipelineIdsFromAppWfIds(impactedWfIds)
if err != nil {
impl.logger.Errorw("error in getting ciPipelineIds from appWfIds", "err", err, "wfIds", impactedWfIds)
return nil, nil, nil, err
}
}
}
}
var pipelines []*pipelineConfig.Pipeline
Expand Down

0 comments on commit bb7cea3

Please sign in to comment.