From c0bb4cb14d9bcf8cc9e292038bec396d6c916917 Mon Sep 17 00:00:00 2001 From: Asher Liu Date: Tue, 22 Feb 2022 09:58:07 +0800 Subject: [PATCH] feat: deployment order support show batch status (#4113) --- apistructs/deployment_order.go | 3 +- conf/orchestrator/orchestrator.yaml | 3 +- .../orchestrator/dbclient/deployment_order.go | 16 ++- .../endpoints/deployment_order.go | 1 + modules/orchestrator/initialize.go | 2 +- modules/orchestrator/provider.go | 2 +- .../services/deployment/deployment_context.go | 2 +- .../deployment_order_create.go | 16 +-- .../deployment_order/deployment_order_cron.go | 32 ++++- .../deployment_order_cron_test.go | 79 +++++++++++++ .../deployment_order/deployment_order_get.go | 110 ++++++++++-------- .../deployment_order_get_test.go | 56 ++++----- .../deployment_order_render.go | 67 ++++++----- .../orchestrator/services/runtime/runtime.go | 4 +- 14 files changed, 268 insertions(+), 125 deletions(-) create mode 100644 modules/orchestrator/services/deployment_order/deployment_order_cron_test.go diff --git a/apistructs/deployment_order.go b/apistructs/deployment_order.go index 67e94f00d97..a1430b2ed4f 100644 --- a/apistructs/deployment_order.go +++ b/apistructs/deployment_order.go @@ -59,7 +59,7 @@ type DeploymentOrderListConditions struct { type DeploymentOrderDetail struct { DeploymentOrderItem - ApplicationsInfo []*ApplicationInfo `json:"applicationsInfo"` + ApplicationsInfo [][]*ApplicationInfo `json:"applicationsInfo"` } type ApplicationInfo struct { @@ -73,7 +73,6 @@ type ApplicationInfo struct { CommitId string `json:"commitId,omitempty"` PreCheckResult *PreCheckResult `json:"preCheckResult,omitempty"` DiceYaml string `json:"diceYaml,omitempty"` - Batch int `json:"batch"` Status DeploymentStatus `json:"status,omitempty"` } diff --git a/conf/orchestrator/orchestrator.yaml b/conf/orchestrator/orchestrator.yaml index 771b21bd0fb..3168c1aab92 100644 --- a/conf/orchestrator/orchestrator.yaml +++ b/conf/orchestrator/orchestrator.yaml @@ -15,8 +15,9 @@ grpc-server: service-register: i18n: - files: + common: - conf/orchestrator/i18n/log-trans.yaml + - conf/orchestrator/i18n/deployment-order-precheck.yaml erda.orchestrator.runtime: erda.orchestrator.events: diff --git a/modules/orchestrator/dbclient/deployment_order.go b/modules/orchestrator/dbclient/deployment_order.go index 7f0d2e426ac..facea746749 100644 --- a/modules/orchestrator/dbclient/deployment_order.go +++ b/modules/orchestrator/dbclient/deployment_order.go @@ -170,7 +170,19 @@ func (db *DBClient) ListReleases(releasesId []string) ([]*Release, error) { return releases, nil } -func (db *DBClient) UpdateDeploymentOrderAppsStatus(orderId string, newOrderStatusMap apistructs.DeploymentOrderStatusMap) error { +func (db *DBClient) ListReleasesMap(releasesId []string) (map[string]*Release, error) { + releases := make([]*Release, 0) + releaseMap := make(map[string]*Release, 0) + if err := db.Where("release_id in (?)", releasesId).Find(&releases).Error; err != nil { + return nil, errors.Wrapf(err, "failed to list release %+v", releasesId) + } + for _, r := range releases { + releaseMap[r.ReleaseId] = r + } + return releaseMap, nil +} + +func (db *DBClient) UpdateDeploymentOrderStatusDetail(orderId string, newOrderStatusMap apistructs.DeploymentOrderStatusMap) error { var ( deploymentOrder DeploymentOrder curOrderStatusMap apistructs.DeploymentOrderStatusMap @@ -209,7 +221,7 @@ func (db *DBClient) UpdateDeploymentOrderAppsStatus(orderId string, newOrderStat return nil } -func (db *DBClient) UpdateDeploymentOrderStatus(id string, appName string, +func (db *DBClient) UpdateDeploymentOrderAppStatus(id string, appName string, appStatus apistructs.DeploymentOrderStatusItem) error { return db.Transaction(func(tx *gorm.DB) error { var ( diff --git a/modules/orchestrator/endpoints/deployment_order.go b/modules/orchestrator/endpoints/deployment_order.go index edc56634370..3d71a8469a6 100644 --- a/modules/orchestrator/endpoints/deployment_order.go +++ b/modules/orchestrator/endpoints/deployment_order.go @@ -58,6 +58,7 @@ func (e *Endpoints) CreateDeploymentOrder(ctx context.Context, r *http.Request, return apierrors.ErrCreateDeploymentOrder.InvalidParameter(strutil.Concat("illegal workspace ", req.Workspace)).ToResp(), nil } + req.Workspace = strings.ToUpper(req.Workspace) req.Operator = userID.String() data, err := e.deploymentOrder.Create(&req) diff --git a/modules/orchestrator/initialize.go b/modules/orchestrator/initialize.go index d510e9154a1..ff2dfab598c 100644 --- a/modules/orchestrator/initialize.go +++ b/modules/orchestrator/initialize.go @@ -91,7 +91,7 @@ func (p *provider) Initialize(ctx servicehub.Context) error { // start cron jobs to sync addon & project infos go initCron(ep, ctx) - i18n.SetSingle(p.LogTrans) + i18n.SetSingle(p.Trans) return nil } diff --git a/modules/orchestrator/provider.go b/modules/orchestrator/provider.go index d35939e94e6..a5ee33203c6 100644 --- a/modules/orchestrator/provider.go +++ b/modules/orchestrator/provider.go @@ -29,7 +29,7 @@ type provider struct { Orm *gorm.DB `autowired:"mysql-client"` EventManager *events.EventManager `autowired:"erda.orchestrator.events.event-manager"` PusherQueue *queue.PusherQueue `autowired:"erda.orchestrator.events.pusher-queue"` - LogTrans i18n.Translator `translator:"log-trans"` + Trans i18n.Translator `autowired:"i18n" translator:"common"` } func (p *provider) Init(ctx servicehub.Context) error { diff --git a/modules/orchestrator/services/deployment/deployment_context.go b/modules/orchestrator/services/deployment/deployment_context.go index 1b0bb519433..d40ed2bd519 100644 --- a/modules/orchestrator/services/deployment/deployment_context.go +++ b/modules/orchestrator/services/deployment/deployment_context.go @@ -711,7 +711,7 @@ func (fsm *DeployFSMContext) UpdateDeploymentStatusToRuntimeAndOrder() error { } logrus.Infof("update deployment(%+v) status for app (%+v) to deployment_order (%+v) detail is: %+v", fsm.deploymentID, app.Name, DeploymentOrderID, appDeploymentStatus) - if err := fsm.db.UpdateDeploymentOrderStatus(DeploymentOrderID, + if err := fsm.db.UpdateDeploymentOrderAppStatus(DeploymentOrderID, app.Name, appDeploymentStatus); err != nil { errMsg := fmt.Sprintf("failed to update deployment order status of deployment[%s]: %v", DeploymentOrderID, err) diff --git a/modules/orchestrator/services/deployment_order/deployment_order_create.go b/modules/orchestrator/services/deployment_order/deployment_order_create.go index f83168f6b30..915f09b381c 100644 --- a/modules/orchestrator/services/deployment_order/deployment_order_create.go +++ b/modules/orchestrator/services/deployment_order/deployment_order_create.go @@ -125,8 +125,10 @@ func (d *DeploymentOrder) Deploy(req *apistructs.DeploymentOrderDeployRequest) ( } // deploy interface will means execute from the first batch - // TODO: continue deploying need front function design - order.CurrentBatch = FirstBatch + // if current batch is not zero, means it is a retry at current batch, deploy will continue from the current batch + if order.CurrentBatch == 0 { + order.CurrentBatch = FirstBatch + } if _, err := d.executeDeploy(order, releaseResp, apistructs.SourceDeployCenter, false); err != nil { logrus.Errorf("failed to execute deploy, order id: %s, err: %v", req.DeploymentOrderId, err) @@ -168,12 +170,10 @@ func (d *DeploymentOrder) executeDeploy(order *dbclient.DeploymentOrder, release applicationsStatus := make(apistructs.DeploymentOrderStatusMap) // redeploy - if order.CurrentBatch != FirstBatch { - if order.StatusDetail != "" { - if err := json.Unmarshal([]byte(order.StatusDetail), &applicationsStatus); err != nil { - return nil, fmt.Errorf("failed to unmarshal to deployment order status (%s), err: %v", - order.ID, err) - } + if order.CurrentBatch != FirstBatch && order.StatusDetail != "" { + if err := json.Unmarshal([]byte(order.StatusDetail), &applicationsStatus); err != nil { + return nil, fmt.Errorf("failed to unmarshal to deployment order status (%s), err: %v", + order.ID, err) } } else { order.StartedAt = time.Now() diff --git a/modules/orchestrator/services/deployment_order/deployment_order_cron.go b/modules/orchestrator/services/deployment_order/deployment_order_cron.go index d273210df77..9449d771735 100644 --- a/modules/orchestrator/services/deployment_order/deployment_order_cron.go +++ b/modules/orchestrator/services/deployment_order/deployment_order_cron.go @@ -15,11 +15,14 @@ package deployment_order import ( + "encoding/json" + "github.com/jinzhu/gorm" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/erda-project/erda/apistructs" + "github.com/erda-project/erda/modules/orchestrator/dbclient" "github.com/erda-project/erda/modules/orchestrator/queue" "github.com/erda-project/erda/modules/orchestrator/utils" ) @@ -90,7 +93,7 @@ func (d *DeploymentOrder) PushOnDeploymentOrderPolling() (abort bool, err0 error } // status update, only update status of current batch - if err := d.db.UpdateDeploymentOrderAppsStatus(order.ID, statusMap); err != nil { + if err := inspectDeploymentStatusDetail(&order, statusMap); err != nil { logrus.Errorf("failed to update deployment order %s status, (%v)", order.ID, err) continue } @@ -132,3 +135,30 @@ func (d *DeploymentOrder) PushOnDeploymentOrderPolling() (abort bool, err0 error return } + +func inspectDeploymentStatusDetail(order *dbclient.DeploymentOrder, newOrderStatusMap apistructs.DeploymentOrderStatusMap) error { + curOrderStatusMap := make(apistructs.DeploymentOrderStatusMap, 0) + + if order.StatusDetail != "" { + if err := json.Unmarshal([]byte(order.StatusDetail), &curOrderStatusMap); err != nil { + return errors.Wrapf(err, "failed to unmarshal to deployment order status (%s)", + order.ID) + } + } + + for appName, status := range newOrderStatusMap { + if status.DeploymentID == 0 || status.DeploymentStatus == "" { + continue + } + curOrderStatusMap[appName] = status + } + + orderStatusMapJson, err := json.Marshal(curOrderStatusMap) + if err != nil { + return errors.Wrapf(err, "failed to marshal to deployment order status (%s)", + order.ID) + } + + order.StatusDetail = string(orderStatusMapJson) + return nil +} diff --git a/modules/orchestrator/services/deployment_order/deployment_order_cron_test.go b/modules/orchestrator/services/deployment_order/deployment_order_cron_test.go new file mode 100644 index 00000000000..852bb182440 --- /dev/null +++ b/modules/orchestrator/services/deployment_order/deployment_order_cron_test.go @@ -0,0 +1,79 @@ +// Copyright (c) 2021 Terminus, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package deployment_order + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/erda-project/erda/apistructs" + "github.com/erda-project/erda/modules/orchestrator/dbclient" +) + +func TestInspectDeploymentStatusDetail(t *testing.T) { + type args struct { + DeploymentOrder *dbclient.DeploymentOrder + StatusMap apistructs.DeploymentOrderStatusMap + } + + tests := []struct { + name string + args args + want string + }{ + { + name: "first-batch", + args: args{ + DeploymentOrder: &dbclient.DeploymentOrder{}, + StatusMap: apistructs.DeploymentOrderStatusMap{ + "java-demo": apistructs.DeploymentOrderStatusItem{ + AppID: 1, + DeploymentID: 1, + DeploymentStatus: apistructs.DeploymentStatusInit, + RuntimeID: 1, + }, + }, + }, + want: "{\"java-demo\":{\"appId\":1,\"deploymentId\":1,\"deploymentStatus\":\"INIT\",\"runtimeId\":1}}", + }, + { + name: "status-appending", + args: args{ + DeploymentOrder: &dbclient.DeploymentOrder{ + StatusDetail: "{\"go-demo\":{\"appId\":0,\"deploymentId\":0,\"deploymentStatus\":\"INIT\",\"runtimeId\":0}}", + }, + StatusMap: apistructs.DeploymentOrderStatusMap{ + "java-demo": apistructs.DeploymentOrderStatusItem{ + AppID: 1, + DeploymentID: 1, + DeploymentStatus: apistructs.DeploymentStatusDeploying, + RuntimeID: 1, + }, + }, + }, + want: "{\"go-demo\":{\"appId\":0,\"deploymentId\":0,\"deploymentStatus\":\"INIT\",\"runtimeId\":0},\"" + + "java-demo\":{\"appId\":1,\"deploymentId\":1,\"deploymentStatus\":\"DEPLOYING\",\"runtimeId\":1}}", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := inspectDeploymentStatusDetail(tt.args.DeploymentOrder, tt.args.StatusMap) + assert.NoError(t, err) + assert.Equal(t, tt.want, tt.args.DeploymentOrder.StatusDetail) + }) + } +} diff --git a/modules/orchestrator/services/deployment_order/deployment_order_get.go b/modules/orchestrator/services/deployment_order/deployment_order_get.go index b91c893acbd..d3ce26d6721 100644 --- a/modules/orchestrator/services/deployment_order/deployment_order_get.go +++ b/modules/orchestrator/services/deployment_order/deployment_order_get.go @@ -61,7 +61,7 @@ func (d *DeploymentOrder) Get(userId string, orderId string) (*apistructs.Deploy return nil, fmt.Errorf("failed to get release, err: %v", err) } - releases := make([]*dbclient.Release, 0) + releases := make([][]*dbclient.Release, 0) if curRelease.IsProjectRelease { subReleasesId := make([][]string, 0) @@ -74,15 +74,21 @@ func (d *DeploymentOrder) Get(userId string, orderId string) (*apistructs.Deploy conditionData = append(conditionData, id...) } - subReleases, err := d.db.ListReleases(conditionData) + subReleaseMap, err := d.db.ListReleasesMap(conditionData) if err != nil { return nil, fmt.Errorf("failed to list sub release, err: %v", err) } - for _, subRelease := range subReleases { - releases = append(releases, subRelease) + + for _, sr := range subReleasesId { + tmp := make([]*dbclient.Release, 0) + for _, r := range sr { + tmp = append(tmp, subReleaseMap[r]) + } + releases = append(releases, tmp) } + } else { - releases = append(releases, curRelease) + releases = append(releases, []*dbclient.Release{curRelease}) } // compose applications info @@ -117,56 +123,60 @@ func (d *DeploymentOrder) Get(userId string, orderId string) (*apistructs.Deploy }, nil } -func composeApplicationsInfo(releases []*dbclient.Release, params map[string]apistructs.DeploymentOrderParam, - appsStatus apistructs.DeploymentOrderStatusMap) ([]*apistructs.ApplicationInfo, error) { - - asi := make([]*apistructs.ApplicationInfo, 0) - - for _, subRelease := range releases { - applicationName := subRelease.ApplicationName - - // parse deployment order - orderParamsData := make(apistructs.DeploymentOrderParam, 0) - - param, ok := params[applicationName] - if ok { - for _, data := range param { - if data.Encrypt { - data.Value = "" +func composeApplicationsInfo(releases [][]*dbclient.Release, params map[string]apistructs.DeploymentOrderParam, + appsStatus apistructs.DeploymentOrderStatusMap) ([][]*apistructs.ApplicationInfo, error) { + + asi := make([][]*apistructs.ApplicationInfo, 0) + + for _, sr := range releases { + ai := make([]*apistructs.ApplicationInfo, 0) + for _, r := range sr { + applicationName := r.ApplicationName + + // parse deployment order + orderParamsData := make(apistructs.DeploymentOrderParam, 0) + + param, ok := params[applicationName] + if ok { + for _, data := range param { + if data.Encrypt { + data.Value = "" + } + orderParamsData = append(orderParamsData, &apistructs.DeploymentOrderParamData{ + Key: data.Key, + Value: data.Value, + Encrypt: data.Encrypt, + Type: convertConfigType(data.Type), + Comment: data.Comment, + }) } - orderParamsData = append(orderParamsData, &apistructs.DeploymentOrderParamData{ - Key: data.Key, - Value: data.Value, - Encrypt: data.Encrypt, - Type: convertConfigType(data.Type), - Comment: data.Comment, - }) } - } - var status apistructs.DeploymentStatus - app, ok := appsStatus[subRelease.ApplicationName] - if ok { - status = app.DeploymentStatus - } + var status apistructs.DeploymentStatus = apistructs.OrderStatusWaitDeploy + app, ok := appsStatus[r.ApplicationName] + if ok { + status = app.DeploymentStatus + } - labels := make(map[string]string) - if err := json.Unmarshal([]byte(subRelease.Labels), &labels); err != nil { - return nil, fmt.Errorf("failed to unmarshal release labels, err: %v", err) - } + labels := make(map[string]string) + if err := json.Unmarshal([]byte(r.Labels), &labels); err != nil { + return nil, fmt.Errorf("failed to unmarshal release labels, err: %v", err) + } - asi = append(asi, &apistructs.ApplicationInfo{ - Id: subRelease.ApplicationId, - Name: applicationName, - DeploymentId: app.DeploymentID, - Params: &orderParamsData, - ReleaseId: subRelease.ReleaseId, - ReleaseVersion: subRelease.Version, - Branch: labels["gitBranch"], - DiceYaml: subRelease.DiceYaml, - CommitId: labels["gitCommitId"], - Status: status, - }) + ai = append(ai, &apistructs.ApplicationInfo{ + Id: r.ApplicationId, + Name: applicationName, + DeploymentId: app.DeploymentID, + Params: &orderParamsData, + ReleaseId: r.ReleaseId, + ReleaseVersion: r.Version, + Branch: labels["gitBranch"], + DiceYaml: r.DiceYaml, + CommitId: labels["gitCommitId"], + Status: status, + }) + } + asi = append(asi, ai) } return asi, nil diff --git a/modules/orchestrator/services/deployment_order/deployment_order_get_test.go b/modules/orchestrator/services/deployment_order/deployment_order_get_test.go index 4e2ed1f7b4a..2175414f43e 100644 --- a/modules/orchestrator/services/deployment_order/deployment_order_get_test.go +++ b/modules/orchestrator/services/deployment_order/deployment_order_get_test.go @@ -29,7 +29,7 @@ import ( func TestComposeApplicationsInfo(t *testing.T) { type args struct { - Releases []*dbclient.Release + Releases [][]*dbclient.Release Params map[string]apistructs.DeploymentOrderParam AppsStatus apistructs.DeploymentOrderStatusMap } @@ -51,44 +51,48 @@ func TestComposeApplicationsInfo(t *testing.T) { tests := []struct { name string args args - want []*apistructs.ApplicationInfo + want [][]*apistructs.ApplicationInfo }{ { name: "pipeline", args: args{ - Releases: []*dbclient.Release{ + Releases: [][]*dbclient.Release{ { - ReleaseId: "8d2385a088df415decdf6357147ed4a2", - Labels: "{\n \"gitCommitId\": \"27504bb7cb788bee08a50612b97faea201c0efed\",\n \"gitBranch\": \"master\"\n}", - ApplicationName: "app1", + { + ReleaseId: "8d2385a088df415decdf6357147ed4a2", + Labels: "{\n \"gitCommitId\": \"27504bb7cb788bee08a50612b97faea201c0efed\",\n \"gitBranch\": \"master\"\n}", + ApplicationName: "app1", + }, }, }, Params: params, AppsStatus: appStatus, }, - want: []*apistructs.ApplicationInfo{ + want: [][]*apistructs.ApplicationInfo{ { - Name: "app1", - DeploymentId: 10, - ReleaseId: "8d2385a088df415decdf6357147ed4a2", - Params: &apistructs.DeploymentOrderParam{ - { - Key: "key1", - Value: "", - Encrypt: true, - Type: "kv", - Comment: "test1", - }, - { - Key: "key2", - Value: "value2", - Type: "dice-file", - Comment: "test2", + { + Name: "app1", + DeploymentId: 10, + ReleaseId: "8d2385a088df415decdf6357147ed4a2", + Params: &apistructs.DeploymentOrderParam{ + { + Key: "key1", + Value: "", + Encrypt: true, + Type: "kv", + Comment: "test1", + }, + { + Key: "key2", + Value: "value2", + Type: "dice-file", + Comment: "test2", + }, }, + Branch: "master", + CommitId: "27504bb7cb788bee08a50612b97faea201c0efed", + Status: apistructs.DeploymentStatusDeploying, }, - Branch: "master", - CommitId: "27504bb7cb788bee08a50612b97faea201c0efed", - Status: apistructs.DeploymentStatusDeploying, }, }, }, diff --git a/modules/orchestrator/services/deployment_order/deployment_order_render.go b/modules/orchestrator/services/deployment_order/deployment_order_render.go index fdcea1aab11..1d8c1469306 100644 --- a/modules/orchestrator/services/deployment_order/deployment_order_render.go +++ b/modules/orchestrator/services/deployment_order/deployment_order_render.go @@ -87,14 +87,16 @@ func (d *DeploymentOrder) RenderDetail(orgId uint64, userId, releaseId, workspac }, nil } -func (d *DeploymentOrder) renderAppsPreCheckResult(orgId uint64, projectId int64, userId, workspace string, asi *[]*apistructs.ApplicationInfo) error { +func (d *DeploymentOrder) renderAppsPreCheckResult(orgId uint64, projectId int64, userId, workspace string, asi *[][]*apistructs.ApplicationInfo) error { if asi == nil { return nil } appList := make([]string, 0) - for _, info := range *asi { - appList = append(appList, info.Name) + for _, apps := range *asi { + for _, info := range apps { + appList = append(appList, info.Name) + } } appStatus, err := d.getDeploymentsStatus(workspace, uint64(projectId), appList) @@ -102,26 +104,28 @@ func (d *DeploymentOrder) renderAppsPreCheckResult(orgId uint64, projectId int64 return err } - for _, info := range *asi { - failReasons, err := d.staticPreCheck(orgId, userId, workspace, projectId, info.Id, []byte(info.DiceYaml)) - if err != nil { - return err - } - isDeploying, ok := appStatus[info.Id] - if ok && isDeploying { - failReasons = append(failReasons, i18n.OrgUintSprintf(orgId, I18nApplicationDeploying, info.Name)) - } + for _, apps := range *asi { + for _, info := range apps { + failReasons, err := d.staticPreCheck(orgId, userId, workspace, projectId, info.Id, []byte(info.DiceYaml)) + if err != nil { + return err + } + isDeploying, ok := appStatus[info.Id] + if ok && isDeploying { + failReasons = append(failReasons, i18n.OrgUintSprintf(orgId, I18nApplicationDeploying, info.Name)) + } - checkResult := &apistructs.PreCheckResult{ - Success: true, - } + checkResult := &apistructs.PreCheckResult{ + Success: true, + } - if len(failReasons) != 0 { - checkResult.Success = false - checkResult.FailReasons = failReasons - } + if len(failReasons) != 0 { + checkResult.Success = false + checkResult.FailReasons = failReasons + } - info.PreCheckResult = checkResult + info.PreCheckResult = checkResult + } } return nil @@ -212,9 +216,9 @@ func (d *DeploymentOrder) staticPreCheck(orgId uint64, userId, workspace string, } func (d *DeploymentOrder) composeAppsInfoByReleaseResp(releaseResp *apistructs.ReleaseGetResponseData, workspace string) ( - []*apistructs.ApplicationInfo, error) { + [][]*apistructs.ApplicationInfo, error) { - asi := make([]*apistructs.ApplicationInfo, 0) + asi := make([][]*apistructs.ApplicationInfo, 0) if releaseResp.IsProjectRelease { params, err := d.fetchApplicationsParams(releaseResp, workspace) if err != nil { @@ -239,21 +243,22 @@ func (d *DeploymentOrder) composeAppsInfoByReleaseResp(releaseResp *apistructs.R releasesMap[r.ReleaseId] = r } - for batchId, batch := range releaseResp.ApplicationReleaseList { + for _, batch := range releaseResp.ApplicationReleaseList { + ai := make([]*apistructs.ApplicationInfo, 0) for _, r := range batch { ret, ok := releasesMap[r.ReleaseID] if !ok { return nil, fmt.Errorf("failed to get releases %s from dicehub", r.ReleaseID) } - asi = append(asi, &apistructs.ApplicationInfo{ + ai = append(ai, &apistructs.ApplicationInfo{ Id: uint64(r.ApplicationID), Name: r.ApplicationName, - Batch: batchId + 1, Params: covertParamsType(params[r.ApplicationName]), DiceYaml: ret.DiceYaml, }) } + asi = append(asi, ai) } } else { params, err := d.fetchDeploymentParams(releaseResp.ApplicationID, workspace) @@ -261,11 +266,13 @@ func (d *DeploymentOrder) composeAppsInfoByReleaseResp(releaseResp *apistructs.R return nil, fmt.Errorf("failed to fetch deployment params, err: %v", err) } - asi = append(asi, &apistructs.ApplicationInfo{ - Id: uint64(releaseResp.ApplicationID), - Name: releaseResp.ApplicationName, - Params: covertParamsType(params), - DiceYaml: releaseResp.Diceyml, + asi = append(asi, []*apistructs.ApplicationInfo{ + { + Id: uint64(releaseResp.ApplicationID), + Name: releaseResp.ApplicationName, + Params: covertParamsType(params), + DiceYaml: releaseResp.Diceyml, + }, }) } diff --git a/modules/orchestrator/services/runtime/runtime.go b/modules/orchestrator/services/runtime/runtime.go index ad9a9f9ac39..6482d95e32a 100644 --- a/modules/orchestrator/services/runtime/runtime.go +++ b/modules/orchestrator/services/runtime/runtime.go @@ -1370,7 +1370,7 @@ func (r *Runtime) generateListGroupAppResult(result *struct { } func (r *Runtime) GetServiceByRuntime(runtimeIDs []uint64) (map[uint64]*apistructs.RuntimeSummaryDTO, error) { - logrus.Infof("get services finished") + logrus.Debug("get services started") var l = logrus.WithField("func", "*Runtime.GetServiceByRuntime") runtimes, err := r.db.FindRuntimesByIds(runtimeIDs) if err != nil { @@ -1428,7 +1428,7 @@ func (r *Runtime) GetServiceByRuntime(runtimeIDs []uint64) (map[uint64]*apistruc } } wg.Wait() - logrus.Infof("get services finished") + logrus.Debug("get services finished") return servicesMap.m, nil }