Skip to content

Commit

Permalink
removed redundant tables ci_workflow_config and cd_workflow_config
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-exp committed Sep 27, 2024
1 parent 30cbc7b commit 805f628
Show file tree
Hide file tree
Showing 14 changed files with 1,068 additions and 428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetHistoricBuildLogs(w http.Respon
return
}
//RBAC
resp, err := handler.ciHandler.GetHistoricBuildLogs(pipelineId, workflowId, nil)
resp, err := handler.ciHandler.GetHistoricBuildLogs(workflowId, nil)
if err != nil {
handler.Logger.Errorw("service err, GetHistoricBuildLogs", "err", err, "pipelineId", pipelineId, "workflowId", workflowId)
common.WriteJsonResp(w, err, resp, http.StatusInternalServerError)
Expand Down Expand Up @@ -1155,7 +1155,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetBuildLogs(w http.ResponseWriter
return
}
}
logsReader, cleanUp, err := handler.ciHandler.GetRunningWorkflowLogs(pipelineId, workflowId)
logsReader, cleanUp, err := handler.ciHandler.GetRunningWorkflowLogs(workflowId)
if err != nil {
handler.Logger.Errorw("service err, GetBuildLogs", "err", err, "pipelineId", pipelineId, "workflowId", workflowId, "lastEventId", lastEventId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,7 @@ func (handler *PipelineConfigRestHandlerImpl) DownloadArtifacts(w http.ResponseW
}
//RBAC CHECK

file, err := handler.cdHandler.DownloadCdWorkflowArtifacts(pipelineId, buildId)
file, err := handler.cdHandler.DownloadCdWorkflowArtifacts(buildId)
defer file.Close()

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions client/events/EventBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
type EventFactory interface {
Build(eventType util.EventType, sourceId *int, appId int, envId *int, pipelineType util.PipelineType) Event
BuildExtraCDData(event Event, wfr *pipelineConfig.CdWorkflowRunner, pipelineOverrideId int, stage bean2.WorkflowType) Event
BuildExtraCIData(event Event, material *MaterialTriggerInfo, dockerImage string) Event
BuildExtraCIData(event Event, material *MaterialTriggerInfo) Event
//BuildFinalData(event Event) *Payload
}

Expand Down Expand Up @@ -163,7 +163,7 @@ func (impl *EventSimpleFactoryImpl) BuildExtraCDData(event Event, wfr *pipelineC
return event
}

func (impl *EventSimpleFactoryImpl) BuildExtraCIData(event Event, material *MaterialTriggerInfo, dockerImage string) Event {
func (impl *EventSimpleFactoryImpl) BuildExtraCIData(event Event, material *MaterialTriggerInfo) Event {
if material == nil {
materialInfo, err := impl.getCiMaterialInfo(event.PipelineId, event.CiArtifactId)
if err != nil {
Expand Down
28 changes: 0 additions & 28 deletions internal/sql/repository/pipelineConfig/CdWorfkflowRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ type CdWorkflowRepository interface {
UpdateWorkFlowRunners(wfr []*CdWorkflowRunner) error
FindWorkflowRunnerByCdWorkflowId(wfIds []int) ([]*CdWorkflowRunner, error)
FindPreviousCdWfRunnerByStatus(pipelineId int, currentWFRunnerId int, status []string) ([]*CdWorkflowRunner, error)
FindConfigByPipelineId(pipelineId int) (*CdWorkflowConfig, error)
FindWorkflowRunnerById(wfrId int) (*CdWorkflowRunner, error)
FindBasicWorkflowRunnerById(wfrId int) (*CdWorkflowRunner, error)
FindRetriedWorkflowCountByReferenceId(wfrId int) (int, error)
Expand Down Expand Up @@ -95,27 +94,6 @@ type CdWorkflow struct {
sql.AuditLog
}

type CdWorkflowConfig struct {
tableName struct{} `sql:"cd_workflow_config" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
CdTimeout int64 `sql:"cd_timeout"`
MinCpu string `sql:"min_cpu"`
MaxCpu string `sql:"max_cpu"`
MinMem string `sql:"min_mem"`
MaxMem string `sql:"max_mem"`
MinStorage string `sql:"min_storage"`
MaxStorage string `sql:"max_storage"`
MinEphStorage string `sql:"min_eph_storage"`
MaxEphStorage string `sql:"max_eph_storage"`
CdCacheBucket string `sql:"cd_cache_bucket"`
CdCacheRegion string `sql:"cd_cache_region"`
CdImage string `sql:"cd_image"`
Namespace string `sql:"wf_namespace"`
CdPipelineId int `sql:"cd_pipeline_id"`
LogsBucket string `sql:"logs_bucket"`
CdArtifactLocationFormat string `sql:"cd_artifact_location_format"`
}

type CdWorkflowRunnerWithExtraFields struct {
CdWorkflowRunner
TotalCount int
Expand Down Expand Up @@ -251,12 +229,6 @@ func (impl *CdWorkflowRepositoryImpl) FindById(wfId int) (*CdWorkflow, error) {
return ddWorkflow, err
}

func (impl *CdWorkflowRepositoryImpl) FindConfigByPipelineId(pipelineId int) (*CdWorkflowConfig, error) {
cdWorkflowConfig := &CdWorkflowConfig{}
err := impl.dbConnection.Model(cdWorkflowConfig).Where("cd_pipeline_id = ?", pipelineId).Select()
return cdWorkflowConfig, err
}

func (impl *CdWorkflowRepositoryImpl) FindLatestCdWorkflowByPipelineId(pipelineIds []int) (*CdWorkflow, error) {
cdWorkflow := &CdWorkflow{}
err := impl.dbConnection.Model(cdWorkflow).Where("pipeline_id in (?)", pg.In(pipelineIds)).Order("id DESC").Limit(1).Select()
Expand Down
90 changes: 28 additions & 62 deletions internal/sql/repository/pipelineConfig/CiWorkflowRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import (
)

type CiWorkflowRepository interface {
SaveWorkFlowConfig(config *CiWorkflowConfig) error
FindConfigByPipelineId(pipelineId int) (*CiWorkflowConfig, error)

SaveWorkFlow(wf *CiWorkflow) error
FindLastTriggeredWorkflow(pipelineId int) (*CiWorkflow, error)
UpdateWorkFlow(wf *CiWorkflow) error
Expand Down Expand Up @@ -94,34 +91,34 @@ func (ciWorkflow *CiWorkflow) IsExternalRunInJobType() bool {
}

type WorkflowWithArtifact struct {
Id int `json:"id"`
Name string `json:"name"`
PodName string `json:"podName"`
Status string `json:"status"`
PodStatus string `json:"pod_status"`
Message string `json:"message"`
StartedOn time.Time `json:"started_on"`
FinishedOn time.Time `json:"finished_on"`
CiPipelineId int `json:"ci_pipeline_id"`
Namespace string `json:"namespace"`
LogFilePath string `json:"log_file_path"`
GitTriggers map[int]GitCommit `json:"git_triggers"`
TriggeredBy int32 `json:"triggered_by"`
EmailId string `json:"email_id"`
Image string `json:"image"`
CiArtifactLocation string `json:"ci_artifact_location"`
CiArtifactId int `json:"ci_artifact_d"`
BlobStorageEnabled bool `json:"blobStorageEnabled"`
CiBuildType string `json:"ci_build_type"`
IsArtifactUploadedV2 *bool `json:"is_artifact_uploaded"` // IsArtifactUploadedV2 is the new column from ci_workflow table, IsArtifactUploaded is Deprecated and will be removed in future
IsArtifactUploaded bool `json:"old_is_artifact_uploaded"` // Deprecated; Use IsArtifactUploadedV2 instead. IsArtifactUploaded is the column from ci_artifact table
EnvironmentId int `json:"environmentId"`
EnvironmentName string `json:"environmentName"`
RefCiWorkflowId int `json:"referenceCiWorkflowId"`
ParentCiWorkflowId int `json:"parent_ci_workflow_id"`
ExecutorType cdWorkflow.WorkflowExecutorType `json:"executor_type"` //awf, system
ImagePathReservationId int `json:"image_path_reservation_id"`
ImagePathReservationIds []int `json:"image_path_reservation_ids" pg:",array"`
Id int `psql:"id"`
Name string `psql:"name"`
PodName string `psql:"pod_name"`
Status string `psql:"status"`
PodStatus string `psql:"pod_status"`
Message string `psql:"message"`
StartedOn time.Time `psql:"started_on"`
FinishedOn time.Time `psql:"finished_on"`
CiPipelineId int `psql:"ci_pipeline_id"`
Namespace string `psql:"namespace"`
LogFilePath string `psql:"log_file_path"`
GitTriggers map[int]GitCommit `psql:"git_triggers"`
TriggeredBy int32 `psql:"triggered_by"`
EmailId string `psql:"email_id"`
Image string `psql:"image"`
CiArtifactLocation string `psql:"ci_artifact_location"`
CiArtifactId int `psql:"ci_artifact_id"`
BlobStorageEnabled bool `psql:"blob_storage_enabled"`
CiBuildType string `psql:"ci_build_type"`
IsArtifactUploadedV2 *bool `psql:"is_artifact_uploaded"` // IsArtifactUploadedV2 is the new column from ci_workflow table, IsArtifactUploaded is Deprecated and will be removed in future
IsArtifactUploaded bool `psql:"old_is_artifact_uploaded"` // Deprecated; Use IsArtifactUploadedV2 instead. IsArtifactUploaded is the column from ci_artifact table
EnvironmentId int `psql:"environment_id"`
EnvironmentName string `psql:"environment_name"`
RefCiWorkflowId int `psql:"ref_ci_workflow_id"`
ParentCiWorkflowId int `psql:"parent_ci_workflow_id"`
ExecutorType cdWorkflow.WorkflowExecutorType `psql:"executor_type"` //awf, system
ImagePathReservationId int `psql:"image_path_reservation_id"`
ImagePathReservationIds []int `psql:"image_path_reservation_ids" pg:",array"`
}

type GitCommit struct {
Expand All @@ -143,27 +140,6 @@ type WebhookData struct {
Data map[string]string `json:"data"`
}

type CiWorkflowConfig struct {
tableName struct{} `sql:"ci_workflow_config" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
CiTimeout int64 `sql:"ci_timeout"`
MinCpu string `sql:"min_cpu"`
MaxCpu string `sql:"max_cpu"`
MinMem string `sql:"min_mem"`
MaxMem string `sql:"max_mem"`
MinStorage string `sql:"min_storage"`
MaxStorage string `sql:"max_storage"`
MinEphStorage string `sql:"min_eph_storage"`
MaxEphStorage string `sql:"max_eph_storage"`
CiCacheBucket string `sql:"ci_cache_bucket"`
CiCacheRegion string `sql:"ci_cache_region"`
CiImage string `sql:"ci_image"`
Namespace string `sql:"wf_namespace"`
CiPipelineId int `sql:"ci_pipeline_id"`
LogsBucket string `sql:"logs_bucket"`
CiArtifactLocationFormat string `sql:"ci_artifact_location_format"`
}

func NewCiWorkflowRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger) *CiWorkflowRepositoryImpl {
return &CiWorkflowRepositoryImpl{
dbConnection: dbConnection,
Expand Down Expand Up @@ -251,16 +227,6 @@ func (impl *CiWorkflowRepositoryImpl) FindCiWorkflowGitTriggersByIds(ids []int)

return workflows, err
}
func (impl *CiWorkflowRepositoryImpl) SaveWorkFlowConfig(config *CiWorkflowConfig) error {
err := impl.dbConnection.Insert(config)
return err
}

func (impl *CiWorkflowRepositoryImpl) FindConfigByPipelineId(pipelineId int) (*CiWorkflowConfig, error) {
ciWorkflowConfig := &CiWorkflowConfig{}
err := impl.dbConnection.Model(ciWorkflowConfig).Where("ci_pipeline_id = ?", pipelineId).Select()
return ciWorkflowConfig, err
}

func (impl *CiWorkflowRepositoryImpl) SaveWorkFlow(wf *CiWorkflow) error {
err := impl.dbConnection.Insert(wf)
Expand Down
Loading

0 comments on commit 805f628

Please sign in to comment.