Skip to content

Commit

Permalink
refactored CdWorkflowWithArtifact struct to bean
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-exp committed Sep 26, 2024
1 parent 8468c66 commit ba6023b
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ import (
)

type DeploymentHistoryResp struct {
CdWorkflows []pipelineConfig.CdWorkflowWithArtifact `json:"cdWorkflows"`
TagsEdiatable bool `json:"tagsEditable"`
AppReleaseTagNames []string `json:"appReleaseTagNames"` //unique list of tags exists in the app
HideImageTaggingHardDelete bool `json:"hideImageTaggingHardDelete"`
CdWorkflows []pipelineBean.CdWorkflowWithArtifact `json:"cdWorkflows"`
TagsEdiatable bool `json:"tagsEditable"`
AppReleaseTagNames []string `json:"appReleaseTagNames"` //unique list of tags exists in the app
HideImageTaggingHardDelete bool `json:"hideImageTaggingHardDelete"`
}

type DevtronAppDeploymentRestHandler interface {
Expand Down
30 changes: 0 additions & 30 deletions internal/sql/repository/pipelineConfig/CdWorfkflowRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
apiBean "github.com/devtron-labs/devtron/api/bean"
"github.com/devtron-labs/devtron/client/gitSensor"
"github.com/devtron-labs/devtron/internal/sql/repository"
repository2 "github.com/devtron-labs/devtron/internal/sql/repository/imageTagging"
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/cdWorkflow"
"github.com/devtron-labs/devtron/internal/util"
"github.com/devtron-labs/devtron/pkg/sql"
Expand Down Expand Up @@ -176,35 +175,6 @@ type CiPipelineMaterialResponse struct {
Regex string `json:"regex"`
}

type CdWorkflowWithArtifact struct {
Id int `json:"id"`
CdWorkflowId int `json:"cd_workflow_id"`
Name string `json:"name"`
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"`
PipelineId int `json:"pipeline_id"`
Namespace string `json:"namespace"`
LogFilePath string `json:"log_file_path"`
TriggeredBy int32 `json:"triggered_by"`
EmailId string `json:"email_id"`
Image string `json:"image"`
MaterialInfo string `json:"material_info,omitempty"`
DataSource string `json:"data_source,omitempty"`
CiArtifactId int `json:"ci_artifact_id,omitempty"`
IsArtifactUploaded bool `json:"isArtifactUploaded"`
WorkflowType string `json:"workflow_type,omitempty"`
ExecutorType string `json:"executor_type,omitempty"`
BlobStorageEnabled bool `json:"blobStorageEnabled"`
GitTriggers map[int]GitCommit `json:"gitTriggers"`
CiMaterials []CiPipelineMaterialResponse `json:"ciMaterials"`
ImageReleaseTags []*repository2.ImageTag `json:"imageReleaseTags"`
ImageComment *repository2.ImageComment `json:"imageComment"`
RefCdWorkflowRunnerId int `json:"referenceCdWorkflowRunnerId"`
}

type TriggerWorkflowStatus struct {
CdWorkflowStatus []*CdWorkflowStatus `json:"cdWorkflowStatus"`
CiWorkflowStatus []*CiWorkflowStatus `json:"ciWorkflowStatus"`
Expand Down
12 changes: 7 additions & 5 deletions pkg/devtronResource/bean/history/cdPipelineDeploymentHistory.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package history

import "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
import (
"github.com/devtron-labs/devtron/pkg/pipeline/bean"
)

type CdPipelineDeploymentHistoryListReq struct {
PipelineId int
Expand All @@ -18,8 +20,8 @@ type CdPipelineDeploymentHistoryConfigListReq struct {
}

type DeploymentHistoryResp struct {
CdWorkflows []pipelineConfig.CdWorkflowWithArtifact `json:"cdWorkflows"`
TagsEditable bool `json:"tagsEditable"`
AppReleaseTagNames []string `json:"appReleaseTagNames"` // unique list of tags exists in the app
HideImageTaggingHardDelete bool `json:"hideImageTaggingHardDelete"`
CdWorkflows []bean.CdWorkflowWithArtifact `json:"cdWorkflows"`
TagsEditable bool `json:"tagsEditable"`
AppReleaseTagNames []string `json:"appReleaseTagNames"` // unique list of tags exists in the app
HideImageTaggingHardDelete bool `json:"hideImageTaggingHardDelete"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
historyBean "github.com/devtron-labs/devtron/pkg/devtronResource/bean/history"
"github.com/devtron-labs/devtron/pkg/pipeline"
"github.com/devtron-labs/devtron/pkg/pipeline/bean"
"github.com/devtron-labs/devtron/pkg/pipeline/history"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -36,7 +37,7 @@ func NewDeploymentHistoryServiceImpl(logger *zap.SugaredLogger,
}

func (impl *DeploymentHistoryServiceImpl) GetCdPipelineDeploymentHistory(req *historyBean.CdPipelineDeploymentHistoryListReq) (resp historyBean.DeploymentHistoryResp, err error) {
var wfs []pipelineConfig.CdWorkflowWithArtifact
var wfs []bean.CdWorkflowWithArtifact
wfs, err = impl.cdHandler.GetCdBuildHistory(req.AppId, req.EnvId, req.PipelineId, req.Offset, req.Limit)
if err != nil {
impl.logger.Errorw("service err, List", "err", err, "req", req)
Expand Down
28 changes: 14 additions & 14 deletions pkg/pipeline/CdHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ const (

type CdHandler interface {
UpdateWorkflow(workflowStatus v1alpha1.WorkflowStatus) (int, string, error)
GetCdBuildHistory(appId int, environmentId int, pipelineId int, offset int, size int) ([]pipelineConfig.CdWorkflowWithArtifact, error)
GetCdBuildHistory(appId int, environmentId int, pipelineId int, offset int, size int) ([]pipelineBean.CdWorkflowWithArtifact, error)
GetRunningWorkflowLogs(environmentId int, pipelineId int, workflowId int) (*bufio.Reader, func() error, error)
FetchCdWorkflowDetails(appId int, environmentId int, pipelineId int, buildId int) (types.WorkflowResponse, error)
DownloadCdWorkflowArtifacts(pipelineId int, buildId int) (*os.File, error)
FetchCdPrePostStageStatus(pipelineId int) ([]pipelineConfig.CdWorkflowWithArtifact, error)
FetchCdPrePostStageStatus(pipelineId int) ([]pipelineBean.CdWorkflowWithArtifact, error)
CancelStage(workflowRunnerId int, userId int32) (int, error)
FetchAppWorkflowStatusForTriggerView(appId int) ([]*pipelineConfig.CdWorkflowStatus, error)
FetchAppWorkflowStatusForTriggerViewForEnvironment(request resourceGroup2.ResourceGroupingRequest, token string) ([]*pipelineConfig.CdWorkflowStatus, error)
Expand Down Expand Up @@ -308,9 +308,9 @@ func (impl *CdHandlerImpl) stateChanged(status string, podStatus string, msg str
return savedWorkflow.Status != status || savedWorkflow.PodStatus != podStatus || savedWorkflow.Message != msg || savedWorkflow.FinishedOn != finishedAt
}

func (impl *CdHandlerImpl) GetCdBuildHistory(appId int, environmentId int, pipelineId int, offset int, size int) ([]pipelineConfig.CdWorkflowWithArtifact, error) {
func (impl *CdHandlerImpl) GetCdBuildHistory(appId int, environmentId int, pipelineId int, offset int, size int) ([]pipelineBean.CdWorkflowWithArtifact, error) {

var cdWorkflowArtifact []pipelineConfig.CdWorkflowWithArtifact
var cdWorkflowArtifact []pipelineBean.CdWorkflowWithArtifact
// this map contains artifactId -> array of tags of that artifact
imageTagsDataMap, err := impl.imageTaggingService.GetTagsDataMapByAppId(appId)
if err != nil {
Expand Down Expand Up @@ -392,7 +392,7 @@ func (impl *CdHandlerImpl) GetCdBuildHistory(appId int, environmentId int, pipel
}
ciMaterialsArr = append(ciMaterialsArr, res)
}
var newCdWorkflowArtifact []pipelineConfig.CdWorkflowWithArtifact
var newCdWorkflowArtifact []pipelineBean.CdWorkflowWithArtifact
for _, cdWfA := range cdWorkflowArtifact {

gitTriggers := make(map[int]pipelineConfig.GitCommit)
Expand Down Expand Up @@ -741,8 +741,8 @@ func (impl *CdHandlerImpl) DownloadCdWorkflowArtifacts(pipelineId int, buildId i
return file, nil
}

func (impl *CdHandlerImpl) converterWFR(wfr pipelineConfig.CdWorkflowRunner) pipelineConfig.CdWorkflowWithArtifact {
workflow := pipelineConfig.CdWorkflowWithArtifact{}
func (impl *CdHandlerImpl) converterWFR(wfr pipelineConfig.CdWorkflowRunner) pipelineBean.CdWorkflowWithArtifact {
workflow := pipelineBean.CdWorkflowWithArtifact{}
if wfr.Id > 0 {
workflow.Name = wfr.Name
workflow.Id = wfr.Id
Expand All @@ -767,9 +767,9 @@ func (impl *CdHandlerImpl) converterWFR(wfr pipelineConfig.CdWorkflowRunner) pip
return workflow
}

func (impl *CdHandlerImpl) converterWFRList(wfrList []pipelineConfig.CdWorkflowRunner) []pipelineConfig.CdWorkflowWithArtifact {
var workflowList []pipelineConfig.CdWorkflowWithArtifact
var results []pipelineConfig.CdWorkflowWithArtifact
func (impl *CdHandlerImpl) converterWFRList(wfrList []pipelineConfig.CdWorkflowRunner) []pipelineBean.CdWorkflowWithArtifact {
var workflowList []pipelineBean.CdWorkflowWithArtifact
var results []pipelineBean.CdWorkflowWithArtifact
var ids []int32
for _, item := range wfrList {
ids = append(ids, item.TriggeredBy)
Expand All @@ -790,8 +790,8 @@ func (impl *CdHandlerImpl) converterWFRList(wfrList []pipelineConfig.CdWorkflowR
return results
}

func (impl *CdHandlerImpl) FetchCdPrePostStageStatus(pipelineId int) ([]pipelineConfig.CdWorkflowWithArtifact, error) {
var results []pipelineConfig.CdWorkflowWithArtifact
func (impl *CdHandlerImpl) FetchCdPrePostStageStatus(pipelineId int) ([]pipelineBean.CdWorkflowWithArtifact, error) {
var results []pipelineBean.CdWorkflowWithArtifact
wfrPre, err := impl.cdWorkflowRepository.FindLatestByPipelineIdAndRunnerType(pipelineId, bean.CD_WORKFLOW_TYPE_PRE)
if err != nil && err != pg.ErrNoRows {
return results, err
Expand All @@ -800,7 +800,7 @@ func (impl *CdHandlerImpl) FetchCdPrePostStageStatus(pipelineId int) ([]pipeline
workflowPre := impl.converterWFR(wfrPre)
results = append(results, workflowPre)
} else {
workflowPre := pipelineConfig.CdWorkflowWithArtifact{Status: "Notbuilt", WorkflowType: string(bean.CD_WORKFLOW_TYPE_PRE), PipelineId: pipelineId}
workflowPre := pipelineBean.CdWorkflowWithArtifact{Status: "Notbuilt", WorkflowType: string(bean.CD_WORKFLOW_TYPE_PRE), PipelineId: pipelineId}
results = append(results, workflowPre)
}

Expand All @@ -812,7 +812,7 @@ func (impl *CdHandlerImpl) FetchCdPrePostStageStatus(pipelineId int) ([]pipeline
workflowPost := impl.converterWFR(wfrPost)
results = append(results, workflowPost)
} else {
workflowPost := pipelineConfig.CdWorkflowWithArtifact{Status: "Notbuilt", WorkflowType: string(bean.CD_WORKFLOW_TYPE_POST), PipelineId: pipelineId}
workflowPost := pipelineBean.CdWorkflowWithArtifact{Status: "Notbuilt", WorkflowType: string(bean.CD_WORKFLOW_TYPE_POST), PipelineId: pipelineId}
results = append(results, workflowPost)
}
return results, nil
Expand Down
36 changes: 36 additions & 0 deletions pkg/pipeline/bean/CdHandlerBean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package bean

import (
"github.com/devtron-labs/devtron/internal/sql/repository/imageTagging"
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
"time"
)

type CdWorkflowWithArtifact struct {
Id int `json:"id"`
CdWorkflowId int `json:"cd_workflow_id"`
Name string `json:"name"`
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"`
PipelineId int `json:"pipeline_id"`
Namespace string `json:"namespace"`
LogFilePath string `json:"log_file_path"`
TriggeredBy int32 `json:"triggered_by"`
EmailId string `json:"email_id"`
Image string `json:"image"`
MaterialInfo string `json:"material_info,omitempty"`
DataSource string `json:"data_source,omitempty"`
CiArtifactId int `json:"ci_artifact_id,omitempty"`
IsArtifactUploaded bool `json:"isArtifactUploaded"`
WorkflowType string `json:"workflow_type,omitempty"`
ExecutorType string `json:"executor_type,omitempty"`
BlobStorageEnabled bool `json:"blobStorageEnabled"`
GitTriggers map[int]pipelineConfig.GitCommit `json:"gitTriggers"`
CiMaterials []pipelineConfig.CiPipelineMaterialResponse `json:"ciMaterials"`
ImageReleaseTags []*repository.ImageTag `json:"imageReleaseTags"`
ImageComment *repository.ImageComment `json:"imageComment"`
RefCdWorkflowRunnerId int `json:"referenceCdWorkflowRunnerId"`
}

0 comments on commit ba6023b

Please sign in to comment.