Skip to content

Commit cf644c0

Browse files
authored
replace material info json.rawmsg with string (#964)
1 parent f71781e commit cf644c0

File tree

3 files changed

+48
-47
lines changed

3 files changed

+48
-47
lines changed

api/bean/AppView.go

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,30 +79,30 @@ type AppEnvironmentContainer struct {
7979
}
8080

8181
type DeploymentDetailContainer struct {
82-
InstalledAppId int `json:"installedAppId,omitempty"`
83-
AppId int `json:"appId,omitempty"`
84-
AppStoreInstalledAppVersionId int `json:"appStoreInstalledAppVersionId,omitempty"`
85-
AppStoreChartName string `json:"appStoreChartName,omitempty"`
86-
AppStoreChartId int `json:"appStoreChartId,omitempty"`
87-
AppStoreAppName string `json:"appStoreAppName,omitempty"`
88-
AppStoreAppVersion string `json:"appStoreAppVersion,omitempty"`
89-
AppName string `json:"appName"`
90-
EnvironmentId int `json:"environmentId"`
91-
EnvironmentName string `json:"environmentName"`
92-
Namespace string `json:"namespace,omitempty"`
93-
//PrometheusEndpoint string `json:"prometheusEndpoint,omitempty"`
94-
Status string `json:"status,omitempty"`
95-
StatusMessage string `json:"statusMessage,omitempty"`
96-
LastDeployedTime string `json:"lastDeployedTime,omitempty"`
97-
LastDeployedBy string `json:"lastDeployedBy,omitempty"`
98-
MaterialInfo json.RawMessage `json:"materialInfo,omitempty"`
99-
ReleaseVersion string `json:"releaseVersion,omitempty"`
100-
Default bool `json:"default,omitempty"`
101-
DataSource string `json:"dataSource,omitempty"`
102-
LastDeployedPipeline string `json:"lastDeployedPipeline,omitempty"`
103-
Deprecated bool `json:"deprecated"`
104-
K8sVersion string `json:"k8sVersion"`
105-
CiArtifactId int `json:"ciArtifactId"`
82+
InstalledAppId int `json:"installedAppId,omitempty"`
83+
AppId int `json:"appId,omitempty"`
84+
AppStoreInstalledAppVersionId int `json:"appStoreInstalledAppVersionId,omitempty"`
85+
AppStoreChartName string `json:"appStoreChartName,omitempty"`
86+
AppStoreChartId int `json:"appStoreChartId,omitempty"`
87+
AppStoreAppName string `json:"appStoreAppName,omitempty"`
88+
AppStoreAppVersion string `json:"appStoreAppVersion,omitempty"`
89+
AppName string `json:"appName"`
90+
EnvironmentId int `json:"environmentId"`
91+
EnvironmentName string `json:"environmentName"`
92+
Namespace string `json:"namespace,omitempty"`
93+
Status string `json:"status,omitempty"`
94+
StatusMessage string `json:"statusMessage,omitempty"`
95+
LastDeployedTime string `json:"lastDeployedTime,omitempty"`
96+
LastDeployedBy string `json:"lastDeployedBy,omitempty"`
97+
MaterialInfo json.RawMessage `json:"materialInfo,omitempty"`
98+
MaterialInfoJsonString string `json:"-"`
99+
ReleaseVersion string `json:"releaseVersion,omitempty"`
100+
Default bool `json:"default,omitempty"`
101+
DataSource string `json:"dataSource,omitempty"`
102+
LastDeployedPipeline string `json:"lastDeployedPipeline,omitempty"`
103+
Deprecated bool `json:"deprecated"`
104+
K8sVersion string `json:"k8sVersion"`
105+
CiArtifactId int `json:"ciArtifactId"`
106106
}
107107

108108
type AppDetailContainer struct {
@@ -139,20 +139,21 @@ type ResourceUsage struct {
139139
}
140140

141141
type TriggerView struct {
142-
CiPipelineId int `json:"ciPipelineId"`
143-
CiPipelineName string `json:"ciPipelineName"`
144-
CdPipelineId int `json:"cdPipelineId"`
145-
CdPipelineName string `json:"cdPipelineName"`
146-
Status string `json:"status"`
147-
StatusMessage string `json:"statusMessage,omitempty"`
148-
LastDeployedTime string `json:"lastDeployedTime,omitempty"`
149-
LastDeployedBy string `json:"lastDeployedBy,omitempty"`
150-
MaterialInfo json.RawMessage `json:"materialInfo,omitempty"`
151-
ReleaseVersion string `json:"releaseVersion,omitempty"`
152-
DataSource string `json:"dataSource,omitempty"`
153-
Conditions []v1alpha1.ApplicationCondition `json:"conditions"`
154-
AppName string `json:"appName"`
155-
EnvironmentName string `json:"environmentName"`
142+
CiPipelineId int `json:"ciPipelineId"`
143+
CiPipelineName string `json:"ciPipelineName"`
144+
CdPipelineId int `json:"cdPipelineId"`
145+
CdPipelineName string `json:"cdPipelineName"`
146+
Status string `json:"status"`
147+
StatusMessage string `json:"statusMessage,omitempty"`
148+
LastDeployedTime string `json:"lastDeployedTime,omitempty"`
149+
LastDeployedBy string `json:"lastDeployedBy,omitempty"`
150+
MaterialInfo json.RawMessage `json:"materialInfo,omitempty"`
151+
MaterialInfoJsonString string `json:"-"`
152+
ReleaseVersion string `json:"releaseVersion,omitempty"`
153+
DataSource string `json:"dataSource,omitempty"`
154+
Conditions []v1alpha1.ApplicationCondition `json:"conditions"`
155+
AppName string `json:"appName"`
156+
EnvironmentName string `json:"environmentName"`
156157
}
157158

158159
type DeploymentDetailStat struct {

internal/sql/repository/AppListingRepository.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (impl AppListingRepositoryImpl) FetchAppsByEnvironment(appListingFilter hel
134134
}
135135

136136
if len(item.DataSource) > 0 {
137-
mInfo, err := parseMaterialInfo([]byte(item.MaterialInfoJson), item.DataSource)
137+
mInfo, err := parseMaterialInfo(item.MaterialInfoJson, item.DataSource)
138138
if err == nil && len(mInfo) > 0 {
139139
item.MaterialInfo = mInfo
140140
} else {
@@ -157,7 +157,7 @@ func (impl AppListingRepositoryImpl) DeploymentDetailsByAppIdAndEnvId(appId int,
157157
impl.Logger.Debugf("reached at AppListingRepository:")
158158
var deploymentDetail bean.DeploymentDetailContainer
159159
query := "SELECT env.environment_name, a.app_name, ceco.namespace, u.email_id as last_deployed_by" +
160-
" , cia.material_info, pco.created_on AS last_deployed_time, pco.pipeline_release_counter as release_version" +
160+
" , cia.material_info as material_info_json_string, pco.created_on AS last_deployed_time, pco.pipeline_release_counter as release_version" +
161161
" , env.default, cia.data_source, p.pipeline_name as last_deployed_pipeline, cia.id as ci_artifact_id" +
162162
" FROM chart_env_config_override ceco" +
163163
" INNER JOIN environment env ON env.id=ceco.target_environment" +
@@ -175,7 +175,7 @@ func (impl AppListingRepositoryImpl) DeploymentDetailsByAppIdAndEnvId(appId int,
175175
return deploymentDetail, err
176176
}
177177

178-
mInfo, err := parseMaterialInfo(deploymentDetail.MaterialInfo, deploymentDetail.DataSource)
178+
mInfo, err := parseMaterialInfo(deploymentDetail.MaterialInfoJsonString, deploymentDetail.DataSource)
179179
if err == nil && len(mInfo) > 0 {
180180
deploymentDetail.MaterialInfo = mInfo
181181
} else {
@@ -185,7 +185,7 @@ func (impl AppListingRepositoryImpl) DeploymentDetailsByAppIdAndEnvId(appId int,
185185
return deploymentDetail, nil
186186
}
187187

188-
func parseMaterialInfo(materialInfo json.RawMessage, source string) (json.RawMessage, error) {
188+
func parseMaterialInfo(materialInfo string, source string) (json.RawMessage, error) {
189189
defer func() {
190190
if r := recover(); r != nil {
191191
fmt.Printf("PARSEMATERIALINFO_MATERIAL_RECOVER, materialInfo: %s, source: %s, err: %s \n", materialInfo, source, r)
@@ -194,11 +194,11 @@ func parseMaterialInfo(materialInfo json.RawMessage, source string) (json.RawMes
194194
if source != "GOCD" && source != "CI-RUNNER" && source != "EXTERNAL" {
195195
return nil, fmt.Errorf("datasource: %s not supported", source)
196196
}
197-
if materialInfo == nil {
197+
if materialInfo == "" {
198198
return []byte("[]"), nil
199199
}
200200
var ciMaterials []*CiMaterialInfo
201-
err := json.Unmarshal(materialInfo, &ciMaterials)
201+
err := json.Unmarshal([]byte(materialInfo), &ciMaterials)
202202
if err != nil {
203203
return []byte("[]"), err
204204
}
@@ -318,7 +318,7 @@ func (impl AppListingRepositoryImpl) FetchAppTriggerView(appId int) ([]bean.Trig
318318
var tView bean.TriggerView
319319
statusQuery := "SELECT p.id as cd_pipeline_id, pco.created_on as last_deployed_time," +
320320
" u.email_id as last_deployed_by, pco.pipeline_release_counter as release_version," +
321-
" cia.material_info, cia.data_source, evt.reason as status" +
321+
" cia.material_info as material_info_json_string, cia.data_source, evt.reason as status" +
322322
" FROM pipeline p" +
323323
" INNER JOIN pipeline_config_override pco ON pco.pipeline_id = p.id" +
324324
" INNER JOIN ci_artifact cia on cia.id = pco.ci_artifact_id" +
@@ -346,7 +346,7 @@ func (impl AppListingRepositoryImpl) FetchAppTriggerView(appId int) ([]bean.Trig
346346
item.ReleaseVersion = tView.ReleaseVersion
347347
item.DataSource = tView.DataSource
348348
item.MaterialInfo = tView.MaterialInfo
349-
mInfo, err := parseMaterialInfo(tView.MaterialInfo, tView.DataSource)
349+
mInfo, err := parseMaterialInfo(tView.MaterialInfoJsonString, tView.DataSource)
350350
if err == nil && len(mInfo) > 0 {
351351
item.MaterialInfo = mInfo
352352
} else {

wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)