diff --git a/Wire.go b/Wire.go index 28e21c0a04..2e43644117 100644 --- a/Wire.go +++ b/Wire.go @@ -125,7 +125,7 @@ import ( "github.com/devtron-labs/devtron/pkg/build" "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging" pipeline6 "github.com/devtron-labs/devtron/pkg/build/pipeline" - "github.com/devtron-labs/devtron/pkg/bulkAction" + "github.com/devtron-labs/devtron/pkg/bulkAction/service" "github.com/devtron-labs/devtron/pkg/chart" "github.com/devtron-labs/devtron/pkg/chart/gitOpsConfig" chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository" @@ -357,8 +357,8 @@ func InitializeApp() (*App, error) { wire.Bind(new(gitOpsConfig.DevtronAppGitOpConfigService), new(*gitOpsConfig.DevtronAppGitOpConfigServiceImpl)), chart.NewChartServiceImpl, wire.Bind(new(chart.ChartService), new(*chart.ChartServiceImpl)), - bulkAction.NewBulkUpdateServiceImpl, - wire.Bind(new(bulkAction.BulkUpdateService), new(*bulkAction.BulkUpdateServiceImpl)), + service.NewBulkUpdateServiceImpl, + wire.Bind(new(service.BulkUpdateService), new(*service.BulkUpdateServiceImpl)), repository.NewImageTagRepository, wire.Bind(new(repository.ImageTagRepository), new(*repository.ImageTagRepositoryImpl)), diff --git a/api/deployment/DeploymentConfigRestHandler.go b/api/deployment/DeploymentConfigRestHandler.go index e060d638b5..28d7fce4c2 100644 --- a/api/deployment/DeploymentConfigRestHandler.go +++ b/api/deployment/DeploymentConfigRestHandler.go @@ -82,7 +82,7 @@ func (handler *DeploymentConfigRestHandlerImpl) CreateChartFromFile(w http.Respo } token := r.Header.Get("token") - if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionUpdate, "*"); !ok { + if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*"); !ok { common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) return } @@ -177,7 +177,7 @@ func (handler *DeploymentConfigRestHandlerImpl) SaveChart(w http.ResponseWriter, } token := r.Header.Get("token") - if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionDelete, "*"); !ok { + if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*"); !ok { common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) return } @@ -234,7 +234,7 @@ func (handler *DeploymentConfigRestHandlerImpl) DownloadChart(w http.ResponseWri } token := r.Header.Get("token") - if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionUpdate, "*"); !ok { + if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok { common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) return } diff --git a/api/restHandler/BulkUpdateRestHandler.go b/api/restHandler/BulkUpdateRestHandler.go index 464bd55fbe..61b65644b7 100644 --- a/api/restHandler/BulkUpdateRestHandler.go +++ b/api/restHandler/BulkUpdateRestHandler.go @@ -21,6 +21,8 @@ import ( "fmt" "github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/repository" "github.com/devtron-labs/devtron/pkg/build/git/gitProvider" + "github.com/devtron-labs/devtron/pkg/bulkAction/bean" + "github.com/devtron-labs/devtron/pkg/bulkAction/service" "github.com/devtron-labs/devtron/pkg/cluster/environment" "net/http" "strconv" @@ -34,7 +36,6 @@ import ( "github.com/devtron-labs/devtron/pkg/appWorkflow" "github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin" "github.com/devtron-labs/devtron/pkg/auth/user" - "github.com/devtron-labs/devtron/pkg/bulkAction" "github.com/devtron-labs/devtron/pkg/chart" "github.com/devtron-labs/devtron/pkg/pipeline" "github.com/devtron-labs/devtron/pkg/team" @@ -61,7 +62,7 @@ type BulkUpdateRestHandlerImpl struct { ciPipelineRepository pipelineConfig.CiPipelineRepository ciHandler pipeline.CiHandler logger *zap.SugaredLogger - bulkUpdateService bulkAction.BulkUpdateService + bulkUpdateService service.BulkUpdateService chartService chart.ChartService propertiesConfigService pipeline.PropertiesConfigService userAuthService user.UserService @@ -81,7 +82,7 @@ type BulkUpdateRestHandlerImpl struct { } func NewBulkUpdateRestHandlerImpl(pipelineBuilder pipeline.PipelineBuilder, logger *zap.SugaredLogger, - bulkUpdateService bulkAction.BulkUpdateService, + bulkUpdateService service.BulkUpdateService, chartService chart.ChartService, propertiesConfigService pipeline.PropertiesConfigService, userAuthService user.UserService, @@ -135,7 +136,7 @@ func (handler BulkUpdateRestHandlerImpl) FindBulkUpdateReadme(w http.ResponseWri return } //auth free, only login required - var responseArr []*bulkAction.BulkUpdateSeeExampleResponse + var responseArr []*bean.BulkUpdateSeeExampleResponse responseArr = append(responseArr, response) common.WriteJsonResp(w, nil, responseArr, http.StatusOK) } @@ -157,7 +158,7 @@ func (handler BulkUpdateRestHandlerImpl) CheckAuthForImpactedObjects(AppId int, } func (handler BulkUpdateRestHandlerImpl) GetImpactedAppsName(w http.ResponseWriter, r *http.Request) { decoder := json.NewDecoder(r.Body) - var script bulkAction.BulkUpdateScript + var script bean.BulkUpdateScript err := decoder.Decode(&script) if err != nil { common.WriteJsonResp(w, err, nil, http.StatusBadRequest) @@ -212,7 +213,7 @@ func (handler BulkUpdateRestHandlerImpl) CheckAuthForBulkUpdate(AppId int, EnvId } func (handler BulkUpdateRestHandlerImpl) BulkUpdate(w http.ResponseWriter, r *http.Request) { decoder := json.NewDecoder(r.Body) - var script bulkAction.BulkUpdateScript + var script bean.BulkUpdateScript err := decoder.Decode(&script) if err != nil { common.WriteJsonResp(w, err, nil, http.StatusBadRequest) @@ -255,28 +256,12 @@ func (handler BulkUpdateRestHandlerImpl) BulkUpdate(w http.ResponseWriter, r *ht } func (handler BulkUpdateRestHandlerImpl) BulkHibernate(w http.ResponseWriter, r *http.Request) { - userId, err := handler.userAuthService.GetLoggedInUser(r) - if userId == 0 || err != nil { - common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized) - return - } - decoder := json.NewDecoder(r.Body) - var request bulkAction.BulkApplicationForEnvironmentPayload - err = decoder.Decode(&request) - if err != nil { - common.WriteJsonResp(w, err, nil, http.StatusBadRequest) - return - } - request.UserId = userId - err = handler.validator.Struct(request) + request, err := handler.decodeAndValidateBulkRequest(w, r) if err != nil { - handler.logger.Errorw("validation err", "err", err, "request", request) - common.WriteJsonResp(w, err, nil, http.StatusBadRequest) - return + return // response already written by the helper on error. } - token := r.Header.Get("token") - response, err := handler.bulkUpdateService.BulkHibernate(&request, r.Context(), w, token, handler.checkAuthForBulkHibernateAndUnhibernate) + response, err := handler.bulkUpdateService.BulkHibernate(request, r.Context(), w, token, handler.checkAuthForBulkHibernateAndUnhibernate) if err != nil { common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) return @@ -284,36 +269,42 @@ func (handler BulkUpdateRestHandlerImpl) BulkHibernate(w http.ResponseWriter, r common.WriteJsonResp(w, nil, response, http.StatusOK) } -func (handler BulkUpdateRestHandlerImpl) BulkUnHibernate(w http.ResponseWriter, r *http.Request) { +// decodeAndValidateBulkRequest is a helper to decode and validate the request. +func (handler BulkUpdateRestHandlerImpl) decodeAndValidateBulkRequest(w http.ResponseWriter, r *http.Request) (*bean.BulkApplicationForEnvironmentPayload, error) { userId, err := handler.userAuthService.GetLoggedInUser(r) if userId == 0 || err != nil { common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized) - return + return nil, err } + decoder := json.NewDecoder(r.Body) - var request bulkAction.BulkApplicationForEnvironmentPayload - err = decoder.Decode(&request) - if err != nil { + var request bean.BulkApplicationForEnvironmentPayload + if err = decoder.Decode(&request); err != nil { common.WriteJsonResp(w, err, nil, http.StatusBadRequest) - return + return nil, err } request.UserId = userId - err = handler.validator.Struct(request) - if err != nil { - handler.logger.Errorw("validation err", "err", err, "request", request) + if err = handler.validator.Struct(request); err != nil { + handler.logger.Errorw("validation error", "request", request, "err", err) common.WriteJsonResp(w, err, nil, http.StatusBadRequest) - return + return nil, err } + return &request, nil +} +func (handler BulkUpdateRestHandlerImpl) BulkUnHibernate(w http.ResponseWriter, r *http.Request) { + request, err := handler.decodeAndValidateBulkRequest(w, r) + if err != nil { + return // response already written by the helper on error. + } token := r.Header.Get("token") - response, err := handler.bulkUpdateService.BulkUnHibernate(&request, r.Context(), w, token, handler.checkAuthForBulkHibernateAndUnhibernate) + response, err := handler.bulkUpdateService.BulkUnHibernate(request, r.Context(), w, token, handler.checkAuthForBulkHibernateAndUnhibernate) if err != nil { common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) return } common.WriteJsonResp(w, nil, response, http.StatusOK) } - func (handler BulkUpdateRestHandlerImpl) BulkDeploy(w http.ResponseWriter, r *http.Request) { token := r.Header.Get("token") userId, err := handler.userAuthService.GetLoggedInUser(r) @@ -322,7 +313,7 @@ func (handler BulkUpdateRestHandlerImpl) BulkDeploy(w http.ResponseWriter, r *ht return } decoder := json.NewDecoder(r.Body) - var request bulkAction.BulkApplicationForEnvironmentPayload + var request bean.BulkApplicationForEnvironmentPayload err = decoder.Decode(&request) if err != nil { common.WriteJsonResp(w, err, nil, http.StatusBadRequest) @@ -350,7 +341,7 @@ func (handler BulkUpdateRestHandlerImpl) BulkBuildTrigger(w http.ResponseWriter, return } decoder := json.NewDecoder(r.Body) - var request bulkAction.BulkApplicationForEnvironmentPayload + var request bean.BulkApplicationForEnvironmentPayload err = decoder.Decode(&request) if err != nil { common.WriteJsonResp(w, err, nil, http.StatusBadRequest) @@ -399,7 +390,7 @@ func (handler BulkUpdateRestHandlerImpl) HandleCdPipelineBulkAction(w http.Respo common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized) return } - var cdPipelineBulkActionReq bulkAction.CdBulkActionRequestDto + var cdPipelineBulkActionReq bean.CdBulkActionRequestDto err = decoder.Decode(&cdPipelineBulkActionReq) cdPipelineBulkActionReq.UserId = userId if err != nil { diff --git a/api/restHandler/ReleaseMetricsRestHandler.go b/api/restHandler/ReleaseMetricsRestHandler.go index f2b083d4b4..a2d9169ca9 100644 --- a/api/restHandler/ReleaseMetricsRestHandler.go +++ b/api/restHandler/ReleaseMetricsRestHandler.go @@ -148,12 +148,10 @@ func (impl *ReleaseMetricsRestHandlerImpl) ResetDataForAllAppEnvironment(w http. } } -// err := decoder.Decode(&employeeStruct, r.URL.Query()) -var decoder = schema.NewDecoder() - func (impl *ReleaseMetricsRestHandlerImpl) GetDeploymentMetrics(w http.ResponseWriter, r *http.Request) { //decoder := json.NewDecoder(r.Body) metricRequest := &lens.MetricRequest{} + decoder := schema.NewDecoder() err := decoder.Decode(metricRequest, r.URL.Query()) if err != nil { impl.logger.Errorw("request err, GetDeploymentMetrics", "err", err, "payload", metricRequest) diff --git a/api/router/BulkUpdateRouter.go b/api/router/BulkUpdateRouter.go index ac8728ba60..423bac665d 100644 --- a/api/router/BulkUpdateRouter.go +++ b/api/router/BulkUpdateRouter.go @@ -42,6 +42,8 @@ func (router BulkUpdateRouterImpl) initBulkUpdateRouter(bulkRouter *mux.Router) bulkRouter.Path("/v1beta1/hibernate").HandlerFunc(router.restHandler.BulkHibernate).Methods("POST") bulkRouter.Path("/v1beta1/unhibernate").HandlerFunc(router.restHandler.BulkUnHibernate).Methods("POST") + bulkRouter.Path("/v1beta2/hibernate").HandlerFunc(router.restHandler.BulkHibernate).Methods("POST") + bulkRouter.Path("/v1beta2/unhibernate").HandlerFunc(router.restHandler.BulkUnHibernate).Methods("POST") bulkRouter.Path("/v1beta1/deploy").HandlerFunc(router.restHandler.BulkDeploy).Methods("POST") bulkRouter.Path("/v1beta1/build").HandlerFunc(router.restHandler.BulkBuildTrigger).Methods("POST") bulkRouter.Path("/v1beta1/cd-pipeline").HandlerFunc(router.restHandler.HandleCdPipelineBulkAction).Methods("POST") diff --git a/api/router/app/pipeline/trigger/PipelineTriggerRouter.go b/api/router/app/pipeline/trigger/PipelineTriggerRouter.go index 762312ebda..fc84a3fc1c 100644 --- a/api/router/app/pipeline/trigger/PipelineTriggerRouter.go +++ b/api/router/app/pipeline/trigger/PipelineTriggerRouter.go @@ -60,6 +60,7 @@ func (router PipelineTriggerRouterImpl) InitPipelineTriggerRouter(pipelineTrigge pipelineTriggerRouter.Path("/update-release-status").HandlerFunc(router.restHandler.ReleaseStatusUpdate).Methods("POST") pipelineTriggerRouter.Path("/rotate-pods").HandlerFunc(router.restHandler.RotatePods).Methods("POST") pipelineTriggerRouter.Path("/stop-start-app").HandlerFunc(router.restHandler.StartStopApp).Methods("POST") + pipelineTriggerRouter.Path("/alpha1/stop-start-app").HandlerFunc(router.restHandler.StartStopApp).Methods("POST") pipelineTriggerRouter.Path("/stop-start-dg").HandlerFunc(router.restHandler.StartStopDeploymentGroup).Methods("POST") pipelineTriggerRouter.Path("/release/"). Handler(sse2.SubscribeHandler(sse.Broker, PollTopic, fetchReleaseData)). diff --git a/pkg/bulkAction/bean.go b/pkg/bulkAction/bean/bean.go similarity index 99% rename from pkg/bulkAction/bean.go rename to pkg/bulkAction/bean/bean.go index c9d0833ab8..1b4306d8c3 100644 --- a/pkg/bulkAction/bean.go +++ b/pkg/bulkAction/bean/bean.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package bulkAction +package bean type NameIncludesExcludes struct { Names []string `json:"names"` diff --git a/pkg/bulkAction/BulkUpdateService.go b/pkg/bulkAction/service/BulkUpdateService.go similarity index 89% rename from pkg/bulkAction/BulkUpdateService.go rename to pkg/bulkAction/service/BulkUpdateService.go index cd10bfc282..3b94648b69 100644 --- a/pkg/bulkAction/BulkUpdateService.go +++ b/pkg/bulkAction/service/BulkUpdateService.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package bulkAction +package service import ( "context" @@ -35,14 +35,16 @@ import ( "github.com/devtron-labs/devtron/internal/util" appWorkflow2 "github.com/devtron-labs/devtron/pkg/appWorkflow" bean2 "github.com/devtron-labs/devtron/pkg/bean" + bean4 "github.com/devtron-labs/devtron/pkg/bulkAction/bean" + "github.com/devtron-labs/devtron/pkg/bulkAction/utils" chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository" repository2 "github.com/devtron-labs/devtron/pkg/cluster/environment/repository" "github.com/devtron-labs/devtron/pkg/deployment/deployedApp" bean5 "github.com/devtron-labs/devtron/pkg/deployment/deployedApp/bean" "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" - "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/adapter" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/adapter" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef" bean3 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef/bean" "github.com/devtron-labs/devtron/pkg/eventProcessor/out" @@ -63,21 +65,22 @@ import ( ) type BulkUpdateService interface { - FindBulkUpdateReadme(operation string) (response *BulkUpdateSeeExampleResponse, err error) - GetBulkAppName(bulkUpdateRequest *BulkUpdatePayload) (*ImpactedObjectsResponse, error) + FindBulkUpdateReadme(operation string) (response *bean4.BulkUpdateSeeExampleResponse, err error) + GetBulkAppName(bulkUpdateRequest *bean4.BulkUpdatePayload) (*bean4.ImpactedObjectsResponse, error) ApplyJsonPatch(patch jsonpatch.Patch, target string) (string, error) - BulkUpdateDeploymentTemplate(bulkUpdatePayload *BulkUpdatePayload) *DeploymentTemplateBulkUpdateResponse - BulkUpdateConfigMap(bulkUpdatePayload *BulkUpdatePayload) *CmAndSecretBulkUpdateResponse - BulkUpdateSecret(bulkUpdatePayload *BulkUpdatePayload) *CmAndSecretBulkUpdateResponse - BulkUpdate(bulkUpdateRequest *BulkUpdatePayload) (bulkUpdateResponse *BulkUpdateResponse) - - BulkHibernate(request *BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) - BulkUnHibernate(request *BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) - BulkDeploy(request *BulkApplicationForEnvironmentPayload, token string, checkAuthBatch func(token string, appObject []string, envObject []string) (map[string]bool, map[string]bool)) (*BulkApplicationForEnvironmentResponse, error) - BulkBuildTrigger(request *BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*BulkApplicationForEnvironmentResponse, error) + BulkUpdateDeploymentTemplate(bulkUpdatePayload *bean4.BulkUpdatePayload) *bean4.DeploymentTemplateBulkUpdateResponse + BulkUpdateConfigMap(bulkUpdatePayload *bean4.BulkUpdatePayload) *bean4.CmAndSecretBulkUpdateResponse + BulkUpdateSecret(bulkUpdatePayload *bean4.BulkUpdatePayload) *bean4.CmAndSecretBulkUpdateResponse + BulkUpdate(bulkUpdateRequest *bean4.BulkUpdatePayload) (bulkUpdateResponse *bean4.BulkUpdateResponse) + // BulkHibernate deprecated + BulkHibernate(request *bean4.BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) + BulkHibernateV1(request *bean4.BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) + BulkUnHibernate(request *bean4.BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) + BulkDeploy(request *bean4.BulkApplicationForEnvironmentPayload, token string, checkAuthBatch func(token string, appObject []string, envObject []string) (map[string]bool, map[string]bool)) (*bean4.BulkApplicationForEnvironmentResponse, error) + BulkBuildTrigger(request *bean4.BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*bean4.BulkApplicationForEnvironmentResponse, error) - GetBulkActionImpactedPipelinesAndWfs(dto *CdBulkActionRequestDto) ([]*pipelineConfig.Pipeline, []int, []int, error) - PerformBulkActionOnCdPipelines(dto *CdBulkActionRequestDto, impactedPipelines []*pipelineConfig.Pipeline, ctx context.Context, dryRun bool, impactedAppWfIds []int, impactedCiPipelineIds []int) (*PipelineAndWfBulkActionResponseDto, error) + GetBulkActionImpactedPipelinesAndWfs(dto *bean4.CdBulkActionRequestDto) ([]*pipelineConfig.Pipeline, []int, []int, error) + PerformBulkActionOnCdPipelines(dto *bean4.CdBulkActionRequestDto, impactedPipelines []*pipelineConfig.Pipeline, ctx context.Context, dryRun bool, impactedAppWfIds []int, impactedCiPipelineIds []int) (*bean4.PipelineAndWfBulkActionResponseDto, error) } type BulkUpdateServiceImpl struct { @@ -148,20 +151,20 @@ const ( Skipped = "skipped" ) -func (impl BulkUpdateServiceImpl) FindBulkUpdateReadme(operation string) (*BulkUpdateSeeExampleResponse, error) { +func (impl BulkUpdateServiceImpl) FindBulkUpdateReadme(operation string) (*bean4.BulkUpdateSeeExampleResponse, error) { bulkUpdateReadme, err := impl.bulkUpdateRepository.FindBulkUpdateReadme(operation) - response := &BulkUpdateSeeExampleResponse{} + response := &bean4.BulkUpdateSeeExampleResponse{} if err != nil { impl.logger.Errorw("error in fetching batch operation example", "err", err) return response, err } - script := &BulkUpdateScript{} + script := &bean4.BulkUpdateScript{} err = json.Unmarshal([]byte(bulkUpdateReadme.Script), &script) if err != nil { impl.logger.Errorw("error in script value(in db) of batch operation example", "err", err) return response, err } - response = &BulkUpdateSeeExampleResponse{ + response = &bean4.BulkUpdateSeeExampleResponse{ Operation: bulkUpdateReadme.Resource, Script: script, ReadMe: bulkUpdateReadme.Readme, @@ -169,11 +172,11 @@ func (impl BulkUpdateServiceImpl) FindBulkUpdateReadme(operation string) (*BulkU return response, nil } -func (impl BulkUpdateServiceImpl) GetBulkAppName(bulkUpdatePayload *BulkUpdatePayload) (*ImpactedObjectsResponse, error) { - impactedObjectsResponse := &ImpactedObjectsResponse{} - deploymentTemplateImpactedObjects := []*DeploymentTemplateImpactedObjectsResponseForOneApp{} - configMapImpactedObjects := []*CmAndSecretImpactedObjectsResponseForOneApp{} - secretImpactedObjects := []*CmAndSecretImpactedObjectsResponseForOneApp{} +func (impl BulkUpdateServiceImpl) GetBulkAppName(bulkUpdatePayload *bean4.BulkUpdatePayload) (*bean4.ImpactedObjectsResponse, error) { + impactedObjectsResponse := &bean4.ImpactedObjectsResponse{} + deploymentTemplateImpactedObjects := []*bean4.DeploymentTemplateImpactedObjectsResponseForOneApp{} + configMapImpactedObjects := []*bean4.CmAndSecretImpactedObjectsResponseForOneApp{} + secretImpactedObjects := []*bean4.CmAndSecretImpactedObjectsResponseForOneApp{} var appNameIncludes []string var appNameExcludes []string if bulkUpdatePayload.Includes == nil || len(bulkUpdatePayload.Includes.Names) == 0 { @@ -194,7 +197,7 @@ func (impl BulkUpdateServiceImpl) GetBulkAppName(bulkUpdatePayload *BulkUpdatePa return nil, err } for _, app := range appsGlobalDT { - deploymentTemplateImpactedObject := &DeploymentTemplateImpactedObjectsResponseForOneApp{ + deploymentTemplateImpactedObject := &bean4.DeploymentTemplateImpactedObjectsResponseForOneApp{ AppId: app.Id, AppName: app.AppName, } @@ -227,7 +230,7 @@ func (impl BulkUpdateServiceImpl) GetBulkAppName(bulkUpdatePayload *BulkUpdatePa } if len(finalConfigMapNames) != 0 { appDetailsById, _ := impl.appRepository.FindById(configMapAppModel.AppId) - configMapImpactedObject := &CmAndSecretImpactedObjectsResponseForOneApp{ + configMapImpactedObject := &bean4.CmAndSecretImpactedObjectsResponseForOneApp{ AppId: configMapAppModel.AppId, AppName: appDetailsById.AppName, Names: finalConfigMapNames, @@ -261,7 +264,7 @@ func (impl BulkUpdateServiceImpl) GetBulkAppName(bulkUpdatePayload *BulkUpdatePa } if len(finalSecretNames) != 0 { appDetailsById, _ := impl.appRepository.FindById(secretAppModel.AppId) - secretImpactedObject := &CmAndSecretImpactedObjectsResponseForOneApp{ + secretImpactedObject := &bean4.CmAndSecretImpactedObjectsResponseForOneApp{ AppId: secretAppModel.AppId, AppName: appDetailsById.AppName, Names: finalSecretNames, @@ -282,7 +285,7 @@ func (impl BulkUpdateServiceImpl) GetBulkAppName(bulkUpdatePayload *BulkUpdatePa return nil, err } for _, app := range appsNotGlobalDT { - deploymentTemplateImpactedObject := &DeploymentTemplateImpactedObjectsResponseForOneApp{ + deploymentTemplateImpactedObject := &bean4.DeploymentTemplateImpactedObjectsResponseForOneApp{ AppId: app.Id, AppName: app.AppName, EnvId: envId, @@ -316,7 +319,7 @@ func (impl BulkUpdateServiceImpl) GetBulkAppName(bulkUpdatePayload *BulkUpdatePa if len(finalConfigMapNames) != 0 { appDetailsById, _ := impl.appRepository.FindById(configMapEnvModel.AppId) - configMapImpactedObject := &CmAndSecretImpactedObjectsResponseForOneApp{ + configMapImpactedObject := &bean4.CmAndSecretImpactedObjectsResponseForOneApp{ AppId: configMapEnvModel.AppId, AppName: appDetailsById.AppName, EnvId: envId, @@ -352,7 +355,7 @@ func (impl BulkUpdateServiceImpl) GetBulkAppName(bulkUpdatePayload *BulkUpdatePa if len(finalSecretNames) != 0 { appDetailsById, _ := impl.appRepository.FindById(secretEnvModel.AppId) - secretImpactedObject := &CmAndSecretImpactedObjectsResponseForOneApp{ + secretImpactedObject := &bean4.CmAndSecretImpactedObjectsResponseForOneApp{ AppId: secretEnvModel.AppId, AppName: appDetailsById.AppName, EnvId: envId, @@ -376,8 +379,8 @@ func (impl BulkUpdateServiceImpl) ApplyJsonPatch(patch jsonpatch.Patch, target s } return string(modified), err } -func (impl BulkUpdateServiceImpl) BulkUpdateDeploymentTemplate(bulkUpdatePayload *BulkUpdatePayload) *DeploymentTemplateBulkUpdateResponse { - deploymentTemplateBulkUpdateResponse := &DeploymentTemplateBulkUpdateResponse{} +func (impl BulkUpdateServiceImpl) BulkUpdateDeploymentTemplate(bulkUpdatePayload *bean4.BulkUpdatePayload) *bean4.DeploymentTemplateBulkUpdateResponse { + deploymentTemplateBulkUpdateResponse := &bean4.DeploymentTemplateBulkUpdateResponse{} var appNameIncludes []string var appNameExcludes []string if bulkUpdatePayload.Includes == nil || len(bulkUpdatePayload.Includes.Names) == 0 { @@ -410,7 +413,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdateDeploymentTemplate(bulkUpdatePayload modifiedValuesYml, err := impl.ApplyJsonPatch(deploymentTemplatePatch, chart.Values) if err != nil { impl.logger.Errorw("error in applying JSON patch to chart.Values", "err", err) - bulkUpdateFailedResponse := &DeploymentTemplateBulkUpdateResponseForOneApp{ + bulkUpdateFailedResponse := &bean4.DeploymentTemplateBulkUpdateResponseForOneApp{ AppId: appDetailsByChart.Id, AppName: appDetailsByChart.AppName, Message: fmt.Sprintf("Error in applying JSON patch : %s", err.Error()), @@ -420,7 +423,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdateDeploymentTemplate(bulkUpdatePayload modifiedGlobalOverrideYml, err := impl.ApplyJsonPatch(deploymentTemplatePatch, chart.GlobalOverride) if err != nil { impl.logger.Errorw("error in applying JSON patch to GlobalOverride", "err", err) - bulkUpdateFailedResponse := &DeploymentTemplateBulkUpdateResponseForOneApp{ + bulkUpdateFailedResponse := &bean4.DeploymentTemplateBulkUpdateResponseForOneApp{ AppId: appDetailsByChart.Id, AppName: appDetailsByChart.AppName, Message: fmt.Sprintf("Error in applying JSON patch : %s", err.Error()), @@ -430,14 +433,14 @@ func (impl BulkUpdateServiceImpl) BulkUpdateDeploymentTemplate(bulkUpdatePayload err = impl.bulkUpdateRepository.BulkUpdateChartsValuesYamlAndGlobalOverrideById(chart.Id, modifiedValuesYml, modifiedGlobalOverrideYml) if err != nil { impl.logger.Errorw("error in bulk updating charts", "err", err) - bulkUpdateFailedResponse := &DeploymentTemplateBulkUpdateResponseForOneApp{ + bulkUpdateFailedResponse := &bean4.DeploymentTemplateBulkUpdateResponseForOneApp{ AppId: appDetailsByChart.Id, AppName: appDetailsByChart.AppName, Message: fmt.Sprintf("Error in updating in db : %s", err.Error()), } deploymentTemplateBulkUpdateResponse.Failure = append(deploymentTemplateBulkUpdateResponse.Failure, bulkUpdateFailedResponse) } else { - bulkUpdateSuccessResponse := &DeploymentTemplateBulkUpdateResponseForOneApp{ + bulkUpdateSuccessResponse := &bean4.DeploymentTemplateBulkUpdateResponseForOneApp{ AppId: appDetailsByChart.Id, AppName: appDetailsByChart.AppName, Message: "Updated Successfully", @@ -485,7 +488,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdateDeploymentTemplate(bulkUpdatePayload modified, err := impl.ApplyJsonPatch(deploymentTemplatePatch, chartEnv.EnvOverrideValues) if err != nil { impl.logger.Errorw("error in applying JSON patch", "err", err) - bulkUpdateFailedResponse := &DeploymentTemplateBulkUpdateResponseForOneApp{ + bulkUpdateFailedResponse := &bean4.DeploymentTemplateBulkUpdateResponseForOneApp{ AppId: appDetailsByChart.Id, AppName: appDetailsByChart.AppName, EnvId: envId, @@ -496,7 +499,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdateDeploymentTemplate(bulkUpdatePayload err = impl.bulkUpdateRepository.BulkUpdateChartsEnvYamlOverrideById(chartEnv.Id, modified) if err != nil { impl.logger.Errorw("error in bulk updating charts", "err", err) - bulkUpdateFailedResponse := &DeploymentTemplateBulkUpdateResponseForOneApp{ + bulkUpdateFailedResponse := &bean4.DeploymentTemplateBulkUpdateResponseForOneApp{ AppId: appDetailsByChart.Id, AppName: appDetailsByChart.AppName, EnvId: envId, @@ -504,7 +507,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdateDeploymentTemplate(bulkUpdatePayload } deploymentTemplateBulkUpdateResponse.Failure = append(deploymentTemplateBulkUpdateResponse.Failure, bulkUpdateFailedResponse) } else { - bulkUpdateSuccessResponse := &DeploymentTemplateBulkUpdateResponseForOneApp{ + bulkUpdateSuccessResponse := &bean4.DeploymentTemplateBulkUpdateResponseForOneApp{ AppId: appDetailsByChart.Id, AppName: appDetailsByChart.AppName, EnvId: envId, @@ -541,8 +544,8 @@ func (impl BulkUpdateServiceImpl) BulkUpdateDeploymentTemplate(bulkUpdatePayload return deploymentTemplateBulkUpdateResponse } -func (impl BulkUpdateServiceImpl) BulkUpdateConfigMap(bulkUpdatePayload *BulkUpdatePayload) *CmAndSecretBulkUpdateResponse { - configMapBulkUpdateResponse := &CmAndSecretBulkUpdateResponse{} +func (impl BulkUpdateServiceImpl) BulkUpdateConfigMap(bulkUpdatePayload *bean4.BulkUpdatePayload) *bean4.CmAndSecretBulkUpdateResponse { + configMapBulkUpdateResponse := &bean4.CmAndSecretBulkUpdateResponse{} var appNameIncludes []string var appNameExcludes []string if bulkUpdatePayload.Includes == nil || len(bulkUpdatePayload.Includes.Names) == 0 { @@ -625,7 +628,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdateConfigMap(bulkUpdatePayload *BulkUpd appDetailsById, _ := impl.appRepository.FindById(configMapAppModel.AppId) for key, value := range messageCmNamesMap { if key == "Updated Successfully" { - bulkUpdateSuccessResponse := &CmAndSecretBulkUpdateResponseForOneApp{ + bulkUpdateSuccessResponse := &bean4.CmAndSecretBulkUpdateResponseForOneApp{ AppId: appDetailsById.Id, AppName: appDetailsById.AppName, Names: value, @@ -633,7 +636,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdateConfigMap(bulkUpdatePayload *BulkUpd } configMapBulkUpdateResponse.Successful = append(configMapBulkUpdateResponse.Successful, bulkUpdateSuccessResponse) } else { - bulkUpdateFailedResponse := &CmAndSecretBulkUpdateResponseForOneApp{ + bulkUpdateFailedResponse := &bean4.CmAndSecretBulkUpdateResponseForOneApp{ AppId: appDetailsById.Id, AppName: appDetailsById.AppName, Names: value, @@ -717,7 +720,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdateConfigMap(bulkUpdatePayload *BulkUpd appDetailsById, _ := impl.appRepository.FindById(configMapEnvModel.AppId) for key, value := range messageCmNamesMap { if key == "Updated Successfully" { - bulkUpdateSuccessResponse := &CmAndSecretBulkUpdateResponseForOneApp{ + bulkUpdateSuccessResponse := &bean4.CmAndSecretBulkUpdateResponseForOneApp{ AppId: appDetailsById.Id, AppName: appDetailsById.AppName, Names: value, @@ -726,7 +729,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdateConfigMap(bulkUpdatePayload *BulkUpd } configMapBulkUpdateResponse.Successful = append(configMapBulkUpdateResponse.Successful, bulkUpdateSuccessResponse) } else { - bulkUpdateFailedResponse := &CmAndSecretBulkUpdateResponseForOneApp{ + bulkUpdateFailedResponse := &bean4.CmAndSecretBulkUpdateResponseForOneApp{ AppId: appDetailsById.Id, AppName: appDetailsById.AppName, Names: value, @@ -746,8 +749,8 @@ func (impl BulkUpdateServiceImpl) BulkUpdateConfigMap(bulkUpdatePayload *BulkUpd } return configMapBulkUpdateResponse } -func (impl BulkUpdateServiceImpl) BulkUpdateSecret(bulkUpdatePayload *BulkUpdatePayload) *CmAndSecretBulkUpdateResponse { - secretBulkUpdateResponse := &CmAndSecretBulkUpdateResponse{} +func (impl BulkUpdateServiceImpl) BulkUpdateSecret(bulkUpdatePayload *bean4.BulkUpdatePayload) *bean4.CmAndSecretBulkUpdateResponse { + secretBulkUpdateResponse := &bean4.CmAndSecretBulkUpdateResponse{} var appNameIncludes []string var appNameExcludes []string if bulkUpdatePayload.Includes == nil || len(bulkUpdatePayload.Includes.Names) == 0 { @@ -836,7 +839,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdateSecret(bulkUpdatePayload *BulkUpdate appDetailsById, _ := impl.appRepository.FindById(secretAppModel.AppId) for key, value := range messageSecretNamesMap { if key == "Updated Successfully" { - bulkUpdateSuccessResponse := &CmAndSecretBulkUpdateResponseForOneApp{ + bulkUpdateSuccessResponse := &bean4.CmAndSecretBulkUpdateResponseForOneApp{ AppId: appDetailsById.Id, AppName: appDetailsById.AppName, Names: value, @@ -844,7 +847,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdateSecret(bulkUpdatePayload *BulkUpdate } secretBulkUpdateResponse.Successful = append(secretBulkUpdateResponse.Successful, bulkUpdateSuccessResponse) } else { - bulkUpdateFailedResponse := &CmAndSecretBulkUpdateResponseForOneApp{ + bulkUpdateFailedResponse := &bean4.CmAndSecretBulkUpdateResponseForOneApp{ AppId: appDetailsById.Id, AppName: appDetailsById.AppName, Names: value, @@ -934,7 +937,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdateSecret(bulkUpdatePayload *BulkUpdate appDetailsById, _ := impl.appRepository.FindById(secretEnvModel.AppId) for key, value := range messageSecretNamesMap { if key == "Updated Successfully" { - bulkUpdateSuccessResponse := &CmAndSecretBulkUpdateResponseForOneApp{ + bulkUpdateSuccessResponse := &bean4.CmAndSecretBulkUpdateResponseForOneApp{ AppId: appDetailsById.Id, AppName: appDetailsById.AppName, Names: value, @@ -943,7 +946,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdateSecret(bulkUpdatePayload *BulkUpdate } secretBulkUpdateResponse.Successful = append(secretBulkUpdateResponse.Successful, bulkUpdateSuccessResponse) } else { - bulkUpdateFailedResponse := &CmAndSecretBulkUpdateResponseForOneApp{ + bulkUpdateFailedResponse := &bean4.CmAndSecretBulkUpdateResponseForOneApp{ AppId: appDetailsById.Id, AppName: appDetailsById.AppName, Names: value, @@ -963,11 +966,11 @@ func (impl BulkUpdateServiceImpl) BulkUpdateSecret(bulkUpdatePayload *BulkUpdate } return secretBulkUpdateResponse } -func (impl BulkUpdateServiceImpl) BulkUpdate(bulkUpdatePayload *BulkUpdatePayload) *BulkUpdateResponse { - bulkUpdateResponse := &BulkUpdateResponse{} - var deploymentTemplateBulkUpdateResponse *DeploymentTemplateBulkUpdateResponse - var configMapBulkUpdateResponse *CmAndSecretBulkUpdateResponse - var secretBulkUpdateResponse *CmAndSecretBulkUpdateResponse +func (impl BulkUpdateServiceImpl) BulkUpdate(bulkUpdatePayload *bean4.BulkUpdatePayload) *bean4.BulkUpdateResponse { + bulkUpdateResponse := &bean4.BulkUpdateResponse{} + var deploymentTemplateBulkUpdateResponse *bean4.DeploymentTemplateBulkUpdateResponse + var configMapBulkUpdateResponse *bean4.CmAndSecretBulkUpdateResponse + var secretBulkUpdateResponse *bean4.CmAndSecretBulkUpdateResponse if bulkUpdatePayload.DeploymentTemplate != nil && bulkUpdatePayload.DeploymentTemplate.Spec != nil && bulkUpdatePayload.DeploymentTemplate.Spec.PatchJson != "" { deploymentTemplateBulkUpdateResponse = impl.BulkUpdateDeploymentTemplate(bulkUpdatePayload) } @@ -984,7 +987,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdate(bulkUpdatePayload *BulkUpdatePayloa return bulkUpdateResponse } -func (impl BulkUpdateServiceImpl) BulkHibernate(request *BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) { +func (impl BulkUpdateServiceImpl) BulkHibernate(request *bean4.BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) { var pipelines []*pipelineConfig.Pipeline var err error if len(request.AppIdIncludes) > 0 { @@ -1010,8 +1013,8 @@ func (impl BulkUpdateServiceImpl) BulkHibernate(request *BulkApplicationForEnvir return nil, err } for _, pipeline := range pipelines { - appKey := fmt.Sprintf("%d_%s", pipeline.AppId, pipeline.App.AppName) - pipelineKey := fmt.Sprintf("%d_%s", pipeline.Id, pipeline.Name) + appKey := utils.GenerateIdentifierKey(pipeline.AppId, pipeline.App.AppName) + pipelineKey := utils.GenerateIdentifierKey(pipeline.Id, pipeline.Name) if _, ok := response[appKey]; !ok { pResponse := make(map[string]any) pResponse[pipelineKey] = true //by default assuming that the operation is successful, if not so then we'll mark it as false @@ -1080,7 +1083,7 @@ func (impl BulkUpdateServiceImpl) BulkHibernate(request *BulkApplicationForEnvir } responseArray = append(responseArray, appMap) } - bulkOperationResponse := &BulkApplicationHibernateUnhibernateForEnvironmentResponse{} + bulkOperationResponse := &bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse{} bulkOperationResponse.BulkApplicationForEnvironmentPayload = *request bulkOperationResponse.Response = responseArray return bulkOperationResponse, nil @@ -1140,7 +1143,7 @@ func (impl BulkUpdateServiceImpl) buildHibernateUnHibernateRequestForHelmPipelin } return appIdentifier, hibernateRequest, nil } -func (impl BulkUpdateServiceImpl) BulkUnHibernate(request *BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) { +func (impl BulkUpdateServiceImpl) BulkUnHibernate(request *bean4.BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) { var pipelines []*pipelineConfig.Pipeline var err error if len(request.AppIdIncludes) > 0 { @@ -1165,8 +1168,8 @@ func (impl BulkUpdateServiceImpl) BulkUnHibernate(request *BulkApplicationForEnv } response := make(map[string]map[string]any) for _, pipeline := range pipelines { - appKey := fmt.Sprintf("%d_%s", pipeline.AppId, pipeline.App.AppName) - pipelineKey := fmt.Sprintf("%d_%s", pipeline.Id, pipeline.Name) + appKey := utils.GenerateIdentifierKey(pipeline.AppId, pipeline.App.AppName) + pipelineKey := utils.GenerateIdentifierKey(pipeline.Id, pipeline.Name) if _, ok := response[appKey]; !ok { pResponse := make(map[string]any) pResponse[pipelineKey] = true //by default assuming that the operation is successful, if not so then we'll mark it as false @@ -1239,13 +1242,13 @@ func (impl BulkUpdateServiceImpl) BulkUnHibernate(request *BulkApplicationForEnv } responseArray = append(responseArray, appMap) } - bulkOperationResponse := &BulkApplicationHibernateUnhibernateForEnvironmentResponse{} + bulkOperationResponse := &bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse{} bulkOperationResponse.BulkApplicationForEnvironmentPayload = *request bulkOperationResponse.Response = responseArray return bulkOperationResponse, nil } -func (impl BulkUpdateServiceImpl) BulkDeploy(request *BulkApplicationForEnvironmentPayload, token string, checkAuthBatch func(token string, appObject []string, envObject []string) (map[string]bool, map[string]bool)) (*BulkApplicationForEnvironmentResponse, error) { +func (impl BulkUpdateServiceImpl) BulkDeploy(request *bean4.BulkApplicationForEnvironmentPayload, token string, checkAuthBatch func(token string, appObject []string, envObject []string) (map[string]bool, map[string]bool)) (*bean4.BulkApplicationForEnvironmentResponse, error) { var pipelines []*pipelineConfig.Pipeline var err error @@ -1317,8 +1320,8 @@ func (impl BulkUpdateServiceImpl) BulkDeploy(request *BulkApplicationForEnvironm response := make(map[string]map[string]bool) for _, pipeline := range pipelines { - appKey := fmt.Sprintf("%d_%s", pipeline.AppId, pipeline.App.AppName) - pipelineKey := fmt.Sprintf("%d_%s", pipeline.Id, pipeline.Name) + appKey := utils.GenerateIdentifierKey(pipeline.AppId, pipeline.App.AppName) + pipelineKey := utils.GenerateIdentifierKey(pipeline.Id, pipeline.Name) success := true if _, ok := response[appKey]; !ok { pResponse := make(map[string]bool) @@ -1370,13 +1373,13 @@ func (impl BulkUpdateServiceImpl) BulkDeploy(request *BulkApplicationForEnvironm pipelineResponse[pipelineKey] = success response[appKey] = pipelineResponse } - bulkOperationResponse := &BulkApplicationForEnvironmentResponse{} + bulkOperationResponse := &bean4.BulkApplicationForEnvironmentResponse{} bulkOperationResponse.BulkApplicationForEnvironmentPayload = *request bulkOperationResponse.Response = response return bulkOperationResponse, nil } -func (impl BulkUpdateServiceImpl) BulkBuildTrigger(request *BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*BulkApplicationForEnvironmentResponse, error) { +func (impl BulkUpdateServiceImpl) BulkBuildTrigger(request *bean4.BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*bean4.BulkApplicationForEnvironmentResponse, error) { var pipelines []*pipelineConfig.Pipeline var err error if len(request.AppIdIncludes) > 0 { @@ -1444,7 +1447,7 @@ func (impl BulkUpdateServiceImpl) BulkBuildTrigger(request *BulkApplicationForEn for _, pipeline := range pipelines { ciCompleted := ciCompletedStatus[pipeline.CiPipelineId] if !ciCompleted { - appKey := fmt.Sprintf("%d_%s", pipeline.AppId, pipeline.App.AppName) + appKey := utils.GenerateIdentifierKey(pipeline.AppId, pipeline.App.AppName) pipelineKey := fmt.Sprintf("%d", pipeline.CiPipelineId) success := true if _, ok := response[appKey]; !ok { @@ -1479,13 +1482,13 @@ func (impl BulkUpdateServiceImpl) BulkBuildTrigger(request *BulkApplicationForEn ciCompletedStatus[pipeline.CiPipelineId] = true } } - bulkOperationResponse := &BulkApplicationForEnvironmentResponse{} + bulkOperationResponse := &bean4.BulkApplicationForEnvironmentResponse{} bulkOperationResponse.BulkApplicationForEnvironmentPayload = *request bulkOperationResponse.Response = response return bulkOperationResponse, nil } -func (impl BulkUpdateServiceImpl) GetBulkActionImpactedPipelinesAndWfs(dto *CdBulkActionRequestDto) ([]*pipelineConfig.Pipeline, []int, []int, error) { +func (impl BulkUpdateServiceImpl) GetBulkActionImpactedPipelinesAndWfs(dto *bean4.CdBulkActionRequestDto) ([]*pipelineConfig.Pipeline, []int, []int, error) { var err error if (len(dto.EnvIds) == 0 && len(dto.EnvNames) == 0) || ((len(dto.AppIds) == 0 && len(dto.AppNames) == 0) && (len(dto.ProjectIds) == 0 && len(dto.ProjectNames) == 0)) { //invalid payload, envIds or envNames are must and at least one of appIds, appNames, projectIds, projectNames is must @@ -1563,10 +1566,10 @@ func (impl BulkUpdateServiceImpl) GetBulkActionImpactedPipelinesAndWfs(dto *CdBu return pipelines, impactedWfIds, impactedCiPipelineIds, nil } -func (impl BulkUpdateServiceImpl) PerformBulkActionOnCdPipelines(dto *CdBulkActionRequestDto, impactedPipelines []*pipelineConfig.Pipeline, - ctx context.Context, dryRun bool, impactedAppWfIds []int, impactedCiPipelineIds []int) (*PipelineAndWfBulkActionResponseDto, error) { +func (impl BulkUpdateServiceImpl) PerformBulkActionOnCdPipelines(dto *bean4.CdBulkActionRequestDto, impactedPipelines []*pipelineConfig.Pipeline, + ctx context.Context, dryRun bool, impactedAppWfIds []int, impactedCiPipelineIds []int) (*bean4.PipelineAndWfBulkActionResponseDto, error) { switch dto.Action { - case CD_BULK_DELETE: + case bean4.CD_BULK_DELETE: deleteAction := bean2.CASCADE_DELETE if dto.ForceDelete { deleteAction = bean2.FORCE_DELETE @@ -1583,10 +1586,10 @@ func (impl BulkUpdateServiceImpl) PerformBulkActionOnCdPipelines(dto *CdBulkActi } } -func (impl BulkUpdateServiceImpl) PerformBulkDeleteActionOnCdPipelines(impactedPipelines []*pipelineConfig.Pipeline, ctx context.Context, dryRun bool, deleteAction int, deleteWfAndCiPipeline bool, impactedAppWfIds, impactedCiPipelineIds []int, userId int32) (*PipelineAndWfBulkActionResponseDto, error) { - var cdPipelineRespDtos []*CdBulkActionResponseDto - var wfRespDtos []*WfBulkActionResponseDto - var ciPipelineRespDtos []*CiBulkActionResponseDto +func (impl BulkUpdateServiceImpl) PerformBulkDeleteActionOnCdPipelines(impactedPipelines []*pipelineConfig.Pipeline, ctx context.Context, dryRun bool, deleteAction int, deleteWfAndCiPipeline bool, impactedAppWfIds, impactedCiPipelineIds []int, userId int32) (*bean4.PipelineAndWfBulkActionResponseDto, error) { + var cdPipelineRespDtos []*bean4.CdBulkActionResponseDto + var wfRespDtos []*bean4.WfBulkActionResponseDto + var ciPipelineRespDtos []*bean4.CiBulkActionResponseDto //sorting pipelines in decreasing order to tackle problem of sequential pipelines //here we are assuming that for now sequential pipelines can only be made through UI and pipelines can not be moved //(thus ids in decreasing order should not create problems when deleting) @@ -1598,7 +1601,7 @@ func (impl BulkUpdateServiceImpl) PerformBulkDeleteActionOnCdPipelines(impactedP }) } for _, pipeline := range impactedPipelines { - respDto := &CdBulkActionResponseDto{ + respDto := &bean4.CdBulkActionResponseDto{ PipelineName: pipeline.Name, AppName: pipeline.App.AppName, EnvironmentName: pipeline.Environment.Name, @@ -1625,7 +1628,7 @@ func (impl BulkUpdateServiceImpl) PerformBulkDeleteActionOnCdPipelines(impactedP impl.logger.Errorw("error in getting ciPipeline by id", "err", err, "id", impactedCiPipelineId) return nil, err } - respDto := &CiBulkActionResponseDto{ + respDto := &bean4.CiBulkActionResponseDto{ PipelineName: ciPipeline.Name, } if !dryRun { @@ -1646,7 +1649,7 @@ func (impl BulkUpdateServiceImpl) PerformBulkDeleteActionOnCdPipelines(impactedP } for _, impactedAppWfId := range impactedAppWfIds { - respDto := &WfBulkActionResponseDto{ + respDto := &bean4.WfBulkActionResponseDto{ WorkflowId: impactedAppWfId, } if !dryRun { @@ -1662,7 +1665,7 @@ func (impl BulkUpdateServiceImpl) PerformBulkDeleteActionOnCdPipelines(impactedP } } - respDto := &PipelineAndWfBulkActionResponseDto{ + respDto := &bean4.PipelineAndWfBulkActionResponseDto{ CdPipelinesRespDtos: cdPipelineRespDtos, CiPipelineRespDtos: ciPipelineRespDtos, AppWfRespDtos: wfRespDtos, diff --git a/pkg/bulkAction/service/BulkUpdateService_ent.go b/pkg/bulkAction/service/BulkUpdateService_ent.go new file mode 100644 index 0000000000..a3b9d266db --- /dev/null +++ b/pkg/bulkAction/service/BulkUpdateService_ent.go @@ -0,0 +1,11 @@ +package service + +import ( + "context" + "github.com/devtron-labs/devtron/pkg/bulkAction/bean" + "net/http" +) + +func (impl BulkUpdateServiceImpl) BulkHibernateV1(request *bean.BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*bean.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) { + return nil, nil +} diff --git a/pkg/bulkAction/utils/utils.go b/pkg/bulkAction/utils/utils.go new file mode 100644 index 0000000000..b427905632 --- /dev/null +++ b/pkg/bulkAction/utils/utils.go @@ -0,0 +1,13 @@ +package utils + +import ( + "fmt" +) + +// GenerateIdentifierKey returns the appKey and pipelineKey for a given pipeline. +// It assumes that the Pipeline struct has the fields AppId, Id, and Name, +// and that it contains an embedded App struct with an AppName field. +func GenerateIdentifierKey(id int, name string) (appKey string) { + appKey = fmt.Sprintf("%d_%s", id, name) + return appKey +} diff --git a/pkg/chartRepo/repository/ChartRefRepository.go b/pkg/chartRepo/repository/ChartRefRepository.go index 591b2730e6..1d58ebe2da 100644 --- a/pkg/chartRepo/repository/ChartRefRepository.go +++ b/pkg/chartRepo/repository/ChartRefRepository.go @@ -40,6 +40,10 @@ type ChartRef struct { sql.AuditLog } +type ChartRefExt struct { + ChartRef + EmailId string `sql:"email_id"` +} type ChartRefMetaData struct { tableName struct{} `sql:"chart_ref_metadata" pg:",discard_unknown_columns"` ChartName string `sql:"chart_name,pk"` @@ -58,6 +62,7 @@ type ChartRefRepository interface { FetchChart(name string) ([]*ChartRef, error) FetchInfoOfChartConfiguredInApp(appId int) (*ChartRef, error) FetchAllNonUserUploadedChartInfo() ([]*ChartRef, error) + GetAllChartsWithUserUploadedEmail() ([]*ChartRefExt, error) } type ChartRefRepositoryImpl struct { dbConnection *pg.DB @@ -171,6 +176,20 @@ func (impl ChartRefRepositoryImpl) FetchInfoOfChartConfiguredInApp(appId int) (* return &repo, nil } +func (impl ChartRefRepositoryImpl) GetAllChartsWithUserUploadedEmail() ([]*ChartRefExt, error) { + var chartRefs []*ChartRefExt + err := impl.dbConnection. + Model(). + Table("chart_ref"). + Column("chart_ref.id", "chart_ref.name", "chart_ref.chart_description", "chart_ref.version", "chart_ref.user_uploaded"). // Include user email in the query + ColumnExpr("users.email_id AS email_id"). + Join("INNER JOIN users"). // Join with users table + JoinOn("users.id = chart_ref.created_by"). // Join with users table + Where("chart_ref.active = ?", true). // Filter by active charts + Select(&chartRefs) + return chartRefs, err +} + // pipeline strategy metadata repository starts here type DeploymentStrategy string diff --git a/pkg/deployment/common/bean/bean.go b/pkg/deployment/common/bean/bean.go index e057c24998..60fe73a6a1 100644 --- a/pkg/deployment/common/bean/bean.go +++ b/pkg/deployment/common/bean/bean.go @@ -63,3 +63,6 @@ const ( func (d DeploymentConfigCredentialType) String() string { return string(d) } + +// DefaultStopTemplate default Stop template for system charts +const DefaultStopTemplate = `{"replicaCount":0,"autoscaling":{"MinReplicas":0,"MaxReplicas":0,"enabled":false},"kedaAutoscaling":{"minReplicaCount":0,"maxReplicaCount":0,"enabled":false},"secondaryWorkload":{"replicaCount":0,"autoscaling":{"enabled":false,"MinReplicas":0,"MaxReplicas":0}}}` diff --git a/pkg/deployment/deployedApp/DeployedAppService.go b/pkg/deployment/deployedApp/DeployedAppService.go index 9609e9ee56..f8c65d2373 100644 --- a/pkg/deployment/deployedApp/DeployedAppService.go +++ b/pkg/deployment/deployedApp/DeployedAppService.go @@ -26,6 +26,7 @@ import ( "github.com/devtron-labs/devtron/internal/sql/models" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" "github.com/devtron-labs/devtron/pkg/cluster/environment/repository" + bean5 "github.com/devtron-labs/devtron/pkg/deployment/common/bean" "github.com/devtron-labs/devtron/pkg/deployment/deployedApp/bean" "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps" bean3 "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps/bean" @@ -38,6 +39,8 @@ import ( type DeployedAppService interface { StopStartApp(ctx context.Context, stopRequest *bean.StopAppRequest) (int, error) RotatePods(ctx context.Context, podRotateRequest *bean.PodRotateRequest) (*bean4.RotatePodResponse, error) + StopStartAppV1(ctx context.Context, stopRequest *bean.StopAppRequest) (int, error) + HibernationPatch(ctx context.Context, appId, envId int) (*bean.HibernationPatchResponse, error) } type DeployedAppServiceImpl struct { @@ -66,6 +69,10 @@ func NewDeployedAppServiceImpl(logger *zap.SugaredLogger, } func (impl *DeployedAppServiceImpl) StopStartApp(ctx context.Context, stopRequest *bean.StopAppRequest) (int, error) { + return impl.stopStartApp(ctx, stopRequest) +} + +func (impl *DeployedAppServiceImpl) stopStartApp(ctx context.Context, stopRequest *bean.StopAppRequest) (int, error) { pipelines, err := impl.pipelineRepository.FindActiveByAppIdAndEnvironmentId(stopRequest.AppId, stopRequest.EnvironmentId) if err != nil { impl.logger.Errorw("error in fetching pipeline", "app", stopRequest.AppId, "env", stopRequest.EnvironmentId, "err", err) @@ -91,7 +98,11 @@ func (impl *DeployedAppServiceImpl) StopStartApp(ctx context.Context, stopReques impl.logger.Errorw("error in fetching latest release", "err", err) return 0, err } - stopTemplate := `{"replicaCount":0,"autoscaling":{"MinReplicas":0,"MaxReplicas":0 ,"enabled": false},"kedaAutoscaling":{"minReplicaCount":0,"maxReplicaCount":0 ,"enabled": false}}` + err = impl.checkForFeasibilityBeforeStartStop(stopRequest.AppId, stopRequest.EnvironmentId, stopRequest.UserId) + if err != nil { + impl.logger.Errorw("error in checking for feasibility before hibernating and un hibernating", "stopRequest", stopRequest, "err", err) + return 0, err + } overrideRequest := &bean2.ValuesOverrideRequest{ PipelineId: pipeline.Id, AppId: stopRequest.AppId, @@ -100,7 +111,12 @@ func (impl *DeployedAppServiceImpl) StopStartApp(ctx context.Context, stopReques CdWorkflowType: bean2.CD_WORKFLOW_TYPE_DEPLOY, } if stopRequest.RequestType == bean.STOP { - overrideRequest.AdditionalOverride = json.RawMessage([]byte(stopTemplate)) + err = impl.setStopTemplate(stopRequest) + if err != nil { + impl.logger.Errorw("error in configuring stopTemplate stopStartApp", "stopRequest", stopRequest, "err", err) + return 0, err + } + overrideRequest.AdditionalOverride = json.RawMessage([]byte(stopRequest.StopPatch)) overrideRequest.DeploymentType = models.DEPLOYMENTTYPE_STOP } else if stopRequest.RequestType == bean.START { overrideRequest.DeploymentType = models.DEPLOYMENTTYPE_START @@ -128,6 +144,11 @@ func (impl *DeployedAppServiceImpl) RotatePods(ctx context.Context, podRotateReq impl.logger.Errorw("error occurred while fetching env details", "envId", environmentId, "err", err) return nil, err } + err = impl.checkForFeasibilityBeforeStartStop(podRotateRequest.AppId, podRotateRequest.EnvironmentId, podRotateRequest.UserId) + if err != nil { + impl.logger.Errorw("error in checking for feasibility in Rotating pods", "podRotateRequest", podRotateRequest, "err", err) + return nil, err + } var resourceIdentifiers []util5.ResourceIdentifier for _, resourceIdentifier := range podRotateRequest.ResourceIdentifiers { resourceIdentifier.Namespace = environment.Namespace @@ -144,3 +165,28 @@ func (impl *DeployedAppServiceImpl) RotatePods(ctx context.Context, podRotateReq //TODO KB: make entry in cd workflow runner return response, nil } +func (impl *DeployedAppServiceImpl) setStopTemplate(stopRequest *bean.StopAppRequest) error { + var stopTemplate string + var err error + if stopRequest.IsHibernationPatchConfigured { + stopTemplate, err = impl.getTemplate(stopRequest) + if err != nil { + impl.logger.Errorw("error in getting hibernation patch configuration", "stopRequest", stopRequest, "err", err) + return err + } + impl.logger.Debugw("stop template fetched from scope", "stopTemplate", stopTemplate) + } else { + stopTemplate, err = impl.getTemplateDefault() + if err != nil { + impl.logger.Errorw("error in getting hibernation patch configuration", "stopRequest", stopRequest, "err", err) + return err + } + } + stopRequest.StopPatch = stopTemplate + return nil +} + +func (impl *DeployedAppServiceImpl) getTemplateDefault() (string, error) { + stopTemplate := bean5.DefaultStopTemplate + return stopTemplate, nil +} diff --git a/pkg/deployment/deployedApp/DeployedAppService_ent.go b/pkg/deployment/deployedApp/DeployedAppService_ent.go new file mode 100644 index 0000000000..8429762833 --- /dev/null +++ b/pkg/deployment/deployedApp/DeployedAppService_ent.go @@ -0,0 +1,21 @@ +package deployedApp + +import ( + "context" + "github.com/devtron-labs/devtron/pkg/deployment/deployedApp/bean" +) + +func (impl *DeployedAppServiceImpl) getTemplate(stopRequest *bean.StopAppRequest) (string, error) { + return "", nil +} +func (impl *DeployedAppServiceImpl) checkForFeasibilityBeforeStartStop(appId, envId int, userId int32) error { + return nil +} + +func (impl *DeployedAppServiceImpl) StopStartAppV1(ctx context.Context, stopRequest *bean.StopAppRequest) (int, error) { + return 0, nil +} + +func (impl *DeployedAppServiceImpl) HibernationPatch(ctx context.Context, appId, envId int) (*bean.HibernationPatchResponse, error) { + return nil, nil +} diff --git a/pkg/deployment/deployedApp/bean/bean.go b/pkg/deployment/deployedApp/bean/bean.go index 9ad11b48e6..028b0a27f2 100644 --- a/pkg/deployment/deployedApp/bean/bean.go +++ b/pkg/deployment/deployedApp/bean/bean.go @@ -39,5 +39,11 @@ type StopAppRequest struct { RequestType RequestType `json:"requestType" validate:"oneof=START STOP"` // ReferenceId is a unique identifier for the workflow runner // refer pipelineConfig.CdWorkflowRunner - ReferenceId *string + ReferenceId *string + StopPatch string // for internal use only + IsHibernationPatchConfigured bool //for internal use only +} + +type HibernationPatchResponse struct { + IsHibernationPatchConfigured bool `json:"isHibernationPatchConfigured"` } diff --git a/pkg/deployment/manifest/ManifestCreationService.go b/pkg/deployment/manifest/ManifestCreationService.go index d58179f646..ad8986af87 100644 --- a/pkg/deployment/manifest/ManifestCreationService.go +++ b/pkg/deployment/manifest/ManifestCreationService.go @@ -20,6 +20,7 @@ import ( "context" "crypto/sha256" "encoding/json" + "errors" "fmt" application3 "github.com/argoproj/argo-cd/v2/pkg/apiclient/application" k8sUtil "github.com/devtron-labs/common-lib/utils/k8s" @@ -316,10 +317,13 @@ func (impl *ManifestCreationServiceImpl) getDeploymentStrategyByTriggerType(over var err error if overrideRequest.DeploymentWithConfig == bean.DEPLOYMENT_CONFIG_TYPE_SPECIFIC_TRIGGER { strategyHistory, err := impl.strategyHistoryRepository.GetHistoryByPipelineIdAndWfrId(newCtx, overrideRequest.PipelineId, overrideRequest.WfrIdForDeploymentWithSpecificTrigger) - if err != nil { + if err != nil && !errors.Is(err, pg.ErrNoRows) { impl.logger.Errorw("error in getting deployed strategy history by pipelineId and wfrId", "err", err, "pipelineId", overrideRequest.PipelineId, "wfrId", overrideRequest.WfrIdForDeploymentWithSpecificTrigger) return nil, err } + if errors.Is(err, pg.ErrNoRows) { + return nil, nil //making this to prevent the strategy value in audit in history marking for the sake of chart with no strategy + } strategy.Strategy = strategyHistory.Strategy strategy.Config = strategyHistory.Config strategy.PipelineId = overrideRequest.PipelineId diff --git a/pkg/deployment/manifest/deploymentTemplate/chartRef/ChartRefService.go b/pkg/deployment/manifest/deploymentTemplate/chartRef/ChartRefService.go index c34dd2d571..8dde120246 100644 --- a/pkg/deployment/manifest/deploymentTemplate/chartRef/ChartRefService.go +++ b/pkg/deployment/manifest/deploymentTemplate/chartRef/ChartRefService.go @@ -403,7 +403,7 @@ func (impl *ChartRefServiceImpl) FetchCustomChartsInfo() ([]*bean.ChartDto, erro for _, resultMetadata := range resultsMetadata { chartsMetadata[resultMetadata.ChartName] = resultMetadata.ChartDescription } - repo, err := impl.chartRefRepository.GetAll() + repo, err := impl.chartRefRepository.GetAllChartsWithUserUploadedEmail() if err != nil { return nil, err } @@ -421,6 +421,7 @@ func (impl *ChartRefServiceImpl) FetchCustomChartsInfo() ([]*bean.ChartDto, erro ChartDescription: ref.ChartDescription, Version: ref.Version, IsUserUploaded: ref.UserUploaded, + UploadedBy: ref.EmailId, } chartDtos = append(chartDtos, chartDto) } diff --git a/pkg/deployment/manifest/deploymentTemplate/chartRef/bean/bean.go b/pkg/deployment/manifest/deploymentTemplate/chartRef/bean/bean.go index 1640837d60..562dd3c204 100644 --- a/pkg/deployment/manifest/deploymentTemplate/chartRef/bean/bean.go +++ b/pkg/deployment/manifest/deploymentTemplate/chartRef/bean/bean.go @@ -109,4 +109,5 @@ type ChartDto struct { ChartDescription string `json:"chartDescription"` Version string `json:"version"` IsUserUploaded bool `json:"isUserUploaded"` + UploadedBy string `json:"uploadedBy"` } diff --git a/scripts/sql/32102900_app_hibernation_patch.down.sql b/scripts/sql/32102900_app_hibernation_patch.down.sql new file mode 100644 index 0000000000..665dce154d --- /dev/null +++ b/scripts/sql/32102900_app_hibernation_patch.down.sql @@ -0,0 +1,9 @@ +-- Drop the unique index if it exists +DROP INDEX IF EXISTS public.chart_ref_schema_unique_active_idx; + +-- Drop columns if they exist +ALTER TABLE public.chart_ref_schema +DROP COLUMN IF EXISTS resource_type, +DROP COLUMN IF EXISTS resource_value; +--- hard Deleting the added resourceQualifier entries for the hibernationPatch +DELETE FROM public.resource_qualifier_mapping where qualifier_id=9 and resource_type=10; \ No newline at end of file diff --git a/scripts/sql/32102900_app_hibernation_patch.up.sql b/scripts/sql/32102900_app_hibernation_patch.up.sql new file mode 100644 index 0000000000..c3bc91c060 --- /dev/null +++ b/scripts/sql/32102900_app_hibernation_patch.up.sql @@ -0,0 +1,23 @@ +Begin; + +ALTER TABLE public.chart_ref_schema + ADD COLUMN IF NOT EXISTS resource_type INT NOT NULL DEFAULT 0; + +ALTER TABLE public.chart_ref_schema + ALTER COLUMN resource_type DROP DEFAULT; + +ALTER TABLE public.chart_ref_schema + ADD COLUMN IF NOT EXISTS resource_value TEXT; + +-- Migrate data from old column "schema" to "resourceValue" +UPDATE public.chart_ref_schema +SET resource_value = "schema", + updated_by = 1, + updated_on = now() +WHERE "schema" IS NOT NULL; + +CREATE UNIQUE INDEX chart_ref_schema_unique_active_idx + ON public.chart_ref_schema (name, resource_type) + WHERE active = TRUE; + +End; \ No newline at end of file diff --git a/tests/pipeline/BulkUpdateService_test.go b/tests/pipeline/BulkUpdateService_test.go index dce80f4c45..5d2456809e 100644 --- a/tests/pipeline/BulkUpdateService_test.go +++ b/tests/pipeline/BulkUpdateService_test.go @@ -20,7 +20,7 @@ import ( "encoding/csv" "encoding/json" "fmt" - "github.com/devtron-labs/devtron/pkg/bulkAction" + "github.com/devtron-labs/devtron/pkg/bulkAction/bean" "io" "log" "os" @@ -34,7 +34,7 @@ func TestBulkUpdate(t *testing.T) { type test struct { ApiVersion string Kind string - Payload *bulkAction.BulkUpdatePayload + Payload *bean.BulkUpdatePayload deploymentTemplateWant string configMapWant string secretWant string @@ -65,28 +65,28 @@ func TestBulkUpdate(t *testing.T) { } namesIncludes := strings.Fields(record[2]) namesExcludes := strings.Fields(record[3]) - includes := &bulkAction.NameIncludesExcludes{Names: namesIncludes} - excludes := &bulkAction.NameIncludesExcludes{Names: namesExcludes} - deploymentTemplateSpec := &bulkAction.DeploymentTemplateSpec{ + includes := &bean.NameIncludesExcludes{Names: namesIncludes} + excludes := &bean.NameIncludesExcludes{Names: namesExcludes} + deploymentTemplateSpec := &bean.DeploymentTemplateSpec{ PatchJson: record[6]} - deploymentTemplateTask := &bulkAction.DeploymentTemplateTask{ + deploymentTemplateTask := &bean.DeploymentTemplateTask{ Spec: deploymentTemplateSpec, } - configMapSpec := &bulkAction.CmAndSecretSpec{ + configMapSpec := &bean.CmAndSecretSpec{ Names: strings.Fields(record[7]), PatchJson: record[8], } - configMapTask := &bulkAction.CmAndSecretTask{ + configMapTask := &bean.CmAndSecretTask{ Spec: configMapSpec, } - secretSpec := &bulkAction.CmAndSecretSpec{ + secretSpec := &bean.CmAndSecretSpec{ Names: strings.Fields(record[9]), PatchJson: record[10], } - secretTask := &bulkAction.CmAndSecretTask{ + secretTask := &bean.CmAndSecretTask{ Spec: secretSpec, } - payload := &bulkAction.BulkUpdatePayload{ + payload := &bean.BulkUpdatePayload{ Includes: includes, Excludes: excludes, EnvIds: envId, diff --git a/tests/pipeline/ChartService_test.go b/tests/pipeline/ChartService_test.go index 415cb0b9c5..8791ecc8ad 100644 --- a/tests/pipeline/ChartService_test.go +++ b/tests/pipeline/ChartService_test.go @@ -22,7 +22,8 @@ import ( "fmt" "github.com/devtron-labs/devtron/internal/sql/repository/bulkUpdate" "github.com/devtron-labs/devtron/internal/util" - "github.com/devtron-labs/devtron/pkg/bulkAction" + "github.com/devtron-labs/devtron/pkg/bulkAction/bean" + "github.com/devtron-labs/devtron/pkg/bulkAction/service" "github.com/devtron-labs/devtron/pkg/chart" "github.com/devtron-labs/devtron/pkg/sql" jsonpatch "github.com/evanphx/json-patch" @@ -34,7 +35,7 @@ import ( "testing" ) -var bulkUpdateService *bulkAction.BulkUpdateServiceImpl +var bulkUpdateService *service.BulkUpdateServiceImpl var bulkUpdateRepository bulkUpdate.BulkUpdateRepositoryImpl func setup() { @@ -42,7 +43,7 @@ func setup() { logger, _ := util.NewSugardLogger() dbConnection, _ := sql.NewDbConnection(config, logger) bulkUpdateRepository := bulkUpdate.NewBulkUpdateRepository(dbConnection, logger) - bulkUpdateService = bulkAction.NewBulkUpdateServiceImpl(bulkUpdateRepository, nil, nil, nil, nil, "", + bulkUpdateService = service.NewBulkUpdateServiceImpl(bulkUpdateRepository, nil, nil, nil, nil, "", chart.DefaultChart(""), util.MergeUtil{}, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) } @@ -52,7 +53,7 @@ func TestBulkUpdateDeploymentTemplate(t *testing.T) { type test struct { ApiVersion string Kind string - Payload *bulkAction.BulkUpdatePayload + Payload *bean.BulkUpdatePayload want string } TestsCsvFile, err := os.Open("ChartService_test.csv") @@ -81,14 +82,14 @@ func TestBulkUpdateDeploymentTemplate(t *testing.T) { } namesIncludes := strings.Fields(record[2]) namesExcludes := strings.Fields(record[3]) - includes := &bulkAction.NameIncludesExcludes{Names: namesIncludes} - excludes := &bulkAction.NameIncludesExcludes{Names: namesExcludes} - spec := &bulkAction.DeploymentTemplateSpec{ + includes := &bean.NameIncludesExcludes{Names: namesIncludes} + excludes := &bean.NameIncludesExcludes{Names: namesExcludes} + spec := &bean.DeploymentTemplateSpec{ PatchJson: record[6]} - task := &bulkAction.DeploymentTemplateTask{ + task := &bean.DeploymentTemplateTask{ Spec: spec, } - payload := &bulkAction.BulkUpdatePayload{ + payload := &bean.BulkUpdatePayload{ Includes: includes, Excludes: excludes, EnvIds: envId, diff --git a/wire_gen.go b/wire_gen.go index 8141c31139..b0e3dcab93 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -153,7 +153,7 @@ import ( repository23 "github.com/devtron-labs/devtron/pkg/build/git/gitWebhook/repository" pipeline2 "github.com/devtron-labs/devtron/pkg/build/pipeline" read10 "github.com/devtron-labs/devtron/pkg/build/pipeline/read" - "github.com/devtron-labs/devtron/pkg/bulkAction" + service7 "github.com/devtron-labs/devtron/pkg/bulkAction/service" "github.com/devtron-labs/devtron/pkg/chart" "github.com/devtron-labs/devtron/pkg/chart/gitOpsConfig" "github.com/devtron-labs/devtron/pkg/chartRepo" @@ -916,7 +916,7 @@ func InitializeApp() (*App, error) { telemetryRouterImpl := router.NewTelemetryRouterImpl(sugaredLogger, telemetryRestHandlerImpl) bulkUpdateRepositoryImpl := bulkUpdate.NewBulkUpdateRepository(db, sugaredLogger) deployedAppServiceImpl := deployedApp.NewDeployedAppServiceImpl(sugaredLogger, k8sCommonServiceImpl, triggerServiceImpl, environmentRepositoryImpl, pipelineRepositoryImpl, cdWorkflowRepositoryImpl) - bulkUpdateServiceImpl := bulkAction.NewBulkUpdateServiceImpl(bulkUpdateRepositoryImpl, sugaredLogger, environmentRepositoryImpl, pipelineRepositoryImpl, appRepositoryImpl, deploymentTemplateHistoryServiceImpl, configMapHistoryServiceImpl, pipelineBuilderImpl, enforcerUtilImpl, ciHandlerImpl, ciPipelineRepositoryImpl, appWorkflowRepositoryImpl, appWorkflowServiceImpl, scopedVariableManagerImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl, deployedAppServiceImpl, cdPipelineEventPublishServiceImpl) + bulkUpdateServiceImpl := service7.NewBulkUpdateServiceImpl(bulkUpdateRepositoryImpl, sugaredLogger, environmentRepositoryImpl, pipelineRepositoryImpl, appRepositoryImpl, deploymentTemplateHistoryServiceImpl, configMapHistoryServiceImpl, pipelineBuilderImpl, enforcerUtilImpl, ciHandlerImpl, ciPipelineRepositoryImpl, appWorkflowRepositoryImpl, appWorkflowServiceImpl, scopedVariableManagerImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl, deployedAppServiceImpl, cdPipelineEventPublishServiceImpl) bulkUpdateRestHandlerImpl := restHandler.NewBulkUpdateRestHandlerImpl(pipelineBuilderImpl, sugaredLogger, bulkUpdateServiceImpl, chartServiceImpl, propertiesConfigServiceImpl, userServiceImpl, teamServiceImpl, enforcerImpl, ciHandlerImpl, validate, clientImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, enforcerUtilImpl, environmentServiceImpl, gitRegistryConfigImpl, dockerRegistryConfigImpl, cdHandlerImpl, appCloneServiceImpl, appWorkflowServiceImpl, materialRepositoryImpl) bulkUpdateRouterImpl := router.NewBulkUpdateRouterImpl(bulkUpdateRestHandlerImpl) webhookSecretValidatorImpl := gitWebhook.NewWebhookSecretValidatorImpl(sugaredLogger)