@@ -18,6 +18,7 @@ import (
18
18
19
19
type DeploymentConfigService interface {
20
20
CreateOrUpdateConfig (tx * pg.Tx , config * bean.DeploymentConfig , userId int32 ) (* bean.DeploymentConfig , error )
21
+ CreateOrUpdateConfigInBulk (tx * pg.Tx , configToBeCreated , configToBeUpdated []* bean.DeploymentConfig , userId int32 ) error
21
22
IsDeploymentConfigUsed () bool
22
23
GetConfigForDevtronApps (appId , envId int ) (* bean.DeploymentConfig , error )
23
24
GetAndMigrateConfigIfAbsentForDevtronApps (appId , envId int ) (* bean.DeploymentConfig , error )
@@ -27,6 +28,7 @@ type DeploymentConfigService interface {
27
28
GetAppLevelConfigForDevtronApp (appId int ) (* bean.DeploymentConfig , error )
28
29
UpdateRepoUrlForAppAndEnvId (repoURL string , appId , envId int ) error
29
30
GetDeploymentAppTypeForCDInBulk (pipelines []* pipelineConfig.Pipeline ) (map [int ]string , error )
31
+ GetConfigsByAppIds (appIds []int ) ([]* bean.DeploymentConfig , error )
30
32
}
31
33
32
34
type DeploymentConfigServiceImpl struct {
@@ -90,6 +92,41 @@ func (impl *DeploymentConfigServiceImpl) CreateOrUpdateConfig(tx *pg.Tx, config
90
92
return ConvertDeploymentConfigDbObjToDTO (newDBObj ), nil
91
93
}
92
94
95
+ func (impl * DeploymentConfigServiceImpl ) CreateOrUpdateConfigInBulk (tx * pg.Tx , configToBeCreated , configToBeUpdated []* bean.DeploymentConfig , userId int32 ) error {
96
+
97
+ dbObjCreate := make ([]* deploymentConfig.DeploymentConfig , len (configToBeCreated ))
98
+ for i := range configToBeCreated {
99
+ dbObj := ConvertDeploymentConfigDTOToDbObj (configToBeCreated [i ])
100
+ dbObj .AuditLog .CreateAuditLog (userId )
101
+ dbObjCreate = append (dbObjCreate , dbObj )
102
+ }
103
+
104
+ dbObjUpdate := make ([]* deploymentConfig.DeploymentConfig , len (configToBeUpdated ))
105
+ for i := range configToBeUpdated {
106
+ dbObj := ConvertDeploymentConfigDTOToDbObj (configToBeUpdated [i ])
107
+ dbObj .AuditLog .CreateAuditLog (userId )
108
+ dbObjUpdate = append (dbObjUpdate , dbObj )
109
+ }
110
+
111
+ if len (dbObjCreate ) > 0 {
112
+ _ , err := impl .deploymentConfigRepository .SaveAll (tx , dbObjCreate )
113
+ if err != nil {
114
+ impl .logger .Errorw ("error in saving deploymentConfig" , "dbObjCreate" , dbObjCreate , "err" , err )
115
+ return err
116
+ }
117
+ }
118
+
119
+ if len (dbObjUpdate ) > 0 {
120
+ _ , err := impl .deploymentConfigRepository .UpdateAll (tx , dbObjUpdate )
121
+ if err != nil {
122
+ impl .logger .Errorw ("error in updating deploymentConfig" , "dbObjUpdate" , dbObjUpdate , "err" , err )
123
+ return err
124
+ }
125
+ }
126
+
127
+ return nil
128
+ }
129
+
93
130
func (impl * DeploymentConfigServiceImpl ) IsDeploymentConfigUsed () bool {
94
131
return impl .deploymentServiceTypeConfig .UseDeploymentConfigData
95
132
}
@@ -478,3 +515,19 @@ func (impl *DeploymentConfigServiceImpl) GetDeploymentAppTypeForCDInBulk(pipelin
478
515
}
479
516
return resp , nil
480
517
}
518
+
519
+ func (impl * DeploymentConfigServiceImpl ) GetConfigsByAppIds (appIds []int ) ([]* bean.DeploymentConfig , error ) {
520
+ if len (appIds ) == 0 {
521
+ return nil , nil
522
+ }
523
+ configs , err := impl .deploymentConfigRepository .GetConfigByAppIds (appIds )
524
+ if err != nil {
525
+ impl .logger .Errorw ("error in getting deployment config db object by appIds" , "appIds" , appIds , "err" , err )
526
+ return nil , err
527
+ }
528
+ resp := make ([]* bean.DeploymentConfig , 0 , len (configs ))
529
+ for _ , config := range configs {
530
+ resp = append (resp , ConvertDeploymentConfigDbObjToDTO (config ))
531
+ }
532
+ return resp , nil
533
+ }
0 commit comments