Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature. split error status. ERROR -> (INSTALL ERROR & DELETE ERROR) #89

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,34 @@ const docTemplate = `{
}
}
},
"/organizations/{organizationId}/app-serve-apps/count": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "Get number of apps on given stack",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"AppServeApps"
],
"summary": "Get number of apps on given stack",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "integer"
}
}
}
}
},
"/organizations/{organizationId}/app-serve-apps/name/{name}/existence": {
"get": {
"security": [
Expand Down Expand Up @@ -3532,6 +3560,9 @@ const docTemplate = `{
"createdAt": {
"type": "string"
},
"createdIAM": {
"type": "boolean"
},
"creator": {
"$ref": "#/definitions/domain.User"
},
Expand Down Expand Up @@ -3591,6 +3622,9 @@ const docTemplate = `{
"createdAt": {
"type": "string"
},
"createdIAM": {
"type": "boolean"
},
"creator": {
"$ref": "#/definitions/domain.SimpleUserResponse"
},
Expand Down Expand Up @@ -4904,6 +4938,9 @@ const docTemplate = `{
"clusters": {
"type": "integer"
},
"createdIAM": {
"type": "boolean"
},
"description": {
"type": "string"
},
Expand Down
37 changes: 37 additions & 0 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,34 @@
}
}
},
"/organizations/{organizationId}/app-serve-apps/count": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "Get number of apps on given stack",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"AppServeApps"
],
"summary": "Get number of apps on given stack",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "integer"
}
}
}
}
},
"/organizations/{organizationId}/app-serve-apps/name/{name}/existence": {
"get": {
"security": [
Expand Down Expand Up @@ -3525,6 +3553,9 @@
"createdAt": {
"type": "string"
},
"createdIAM": {
"type": "boolean"
},
"creator": {
"$ref": "#/definitions/domain.User"
},
Expand Down Expand Up @@ -3584,6 +3615,9 @@
"createdAt": {
"type": "string"
},
"createdIAM": {
"type": "boolean"
},
"creator": {
"$ref": "#/definitions/domain.SimpleUserResponse"
},
Expand Down Expand Up @@ -4897,6 +4931,9 @@
"clusters": {
"type": "integer"
},
"createdIAM": {
"type": "boolean"
},
"description": {
"type": "string"
},
Expand Down
23 changes: 23 additions & 0 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ definitions:
type: integer
createdAt:
type: string
createdIAM:
type: boolean
creator:
$ref: '#/definitions/domain.User'
creatorId:
Expand Down Expand Up @@ -326,6 +328,8 @@ definitions:
type: integer
createdAt:
type: string
createdIAM:
type: boolean
creator:
$ref: '#/definitions/domain.SimpleUserResponse'
description:
Expand Down Expand Up @@ -1201,6 +1205,8 @@ definitions:
type: string
clusters:
type: integer
createdIAM:
type: boolean
description:
type: string
id:
Expand Down Expand Up @@ -2580,6 +2586,23 @@ paths:
summary: Get appServeApp
tags:
- AppServeApps
/organizations/{organizationId}/app-serve-apps/count:
get:
consumes:
- application/json
description: Get number of apps on given stack
produces:
- application/json
responses:
"200":
description: OK
schema:
type: integer
security:
- JWT: []
summary: Get number of apps on given stack
tags:
- AppServeApps
/organizations/{organizationId}/app-serve-apps/name/{name}/existence:
get:
consumes:
Expand Down
4 changes: 3 additions & 1 deletion internal/repository/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ func (r *AlertRepository) Fetch(organizationId string) (out []domain.Alert, err
}).Preload("AlertActions.Taker").
Preload("Cluster", "status = 2").
Preload("Organization").
Order("created_at desc").Limit(1000).Find(&alerts, "organization_id = ?", organizationId)
Joins("join clusters on clusters.id = alerts.cluster_id AND clusters.status = 2").
Order("created_at desc").Limit(1000).
Find(&alerts, "alerts.organization_id = ?", organizationId)
if res.Error != nil {
return nil, res.Error
}
Expand Down
3 changes: 3 additions & 0 deletions internal/repository/cloud-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type CloudAccount struct {
Status domain.CloudAccountStatus
StatusDesc string
AwsAccountId string
CreatedIAM bool
CreatorId *uuid.UUID `gorm:"type:uuid"`
Creator User `gorm:"foreignKey:CreatorId"`
UpdatorId *uuid.UUID `gorm:"type:uuid"`
Expand Down Expand Up @@ -112,6 +113,7 @@ func (r *CloudAccountRepository) Create(dto domain.CloudAccount) (cloudAccountId
CloudService: dto.CloudService,
Resource: dto.Resource,
AwsAccountId: dto.AwsAccountId,
CreatedIAM: false,
Status: domain.CloudAccountStatus_PENDING,
CreatorId: &dto.CreatorId}
res := r.db.Create(&cloudAccount)
Expand Down Expand Up @@ -162,6 +164,7 @@ func reflectCloudAccount(cloudAccount CloudAccount) domain.CloudAccount {
Status: cloudAccount.Status,
StatusDesc: cloudAccount.StatusDesc,
AwsAccountId: cloudAccount.AwsAccountId,
CreatedIAM: cloudAccount.CreatedIAM,
Creator: reflectSimpleUser(cloudAccount.Creator),
Updator: reflectSimpleUser(cloudAccount.Updator),
CreatedAt: cloudAccount.CreatedAt,
Expand Down
4 changes: 2 additions & 2 deletions internal/usecase/cloud-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ func (u *CloudAccountUsecase) DeleteForce(ctx context.Context, cloudAccountId uu
return err
}

if cloudAccount.Status != domain.CloudAccountStatus_ERROR {
return fmt.Errorf("The status is not ERROR. %s", cloudAccount.Status)
if cloudAccount.Status != domain.CloudAccountStatus_CREATE_ERROR {
return fmt.Errorf("The status is not CREATE_ERROR. %s", cloudAccount.Status)
}

if u.getClusterCnt(cloudAccountId) > 0 {
Expand Down
31 changes: 17 additions & 14 deletions internal/usecase/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,15 @@ func (u *StackUsecase) Delete(ctx context.Context, dto domain.Stack) (err error)
}

for _, cl := range clusters {
if cl.ID != cluster.ID &&
cl.Status != domain.ClusterStatus_DELETED &&
cl.Status != domain.ClusterStatus_ERROR {
if cl.ID != cluster.ID && (cl.Status == domain.ClusterStatus_RUNNING ||
cl.Status == domain.ClusterStatus_INSTALLING ||
cl.Status == domain.ClusterStatus_DELETING) {
return httpErrors.NewBadRequestError(fmt.Errorf("Failed to delete 'Primary' cluster. The clusters remain in organization"), "S_REMAIN_CLUSTER_FOR_DELETION", "")
}
}
break
}
}

appGroups, err := u.appGroupRepo.Fetch(domain.ClusterId(dto.ID))
if err != nil {
return errors.Wrap(err, "Failed to get appGroups")
Expand All @@ -314,14 +313,12 @@ func (u *StackUsecase) Delete(ctx context.Context, dto domain.Stack) (err error)
}
}

appServeApps, err := u.appServeAppRepo.GetAppServeApps(dto.OrganizationId, true)
appsCnt, err := u.appServeAppRepo.GetNumOfAppsOnStack(dto.OrganizationId, dto.ID.String())
if err != nil {
return err
return errors.Wrap(err, "Failed to get numOfAppsOnStack")
}
for _, app := range appServeApps {
if app.TargetClusterId == dto.ID.String() && app.Status != "ERROR" {
return httpErrors.NewBadRequestError(fmt.Errorf("existed appServeApps in %s", dto.OrganizationId), "S_FAILED_DELETE_EXISTED_ASA", "")
}
if appsCnt > 0 {
return httpErrors.NewBadRequestError(fmt.Errorf("existed appServeApps in %s", dto.OrganizationId), "S_FAILED_DELETE_EXISTED_ASA", "")
}

workflow := ""
Expand Down Expand Up @@ -522,8 +519,11 @@ func getStackStatus(cluster domain.Cluster, appGroups []domain.AppGroup) (domain
if appGroup.Status == domain.AppGroupStatus_DELETING {
return domain.StackStatus_APPGROUP_DELETING, appGroup.StatusDesc
}
if appGroup.Status == domain.AppGroupStatus_ERROR {
return domain.StackStatus_APPGROUP_ERROR, appGroup.StatusDesc
if appGroup.Status == domain.AppGroupStatus_INSTALL_ERROR {
return domain.StackStatus_APPGROUP_INSTALL_ERROR, appGroup.StatusDesc
}
if appGroup.Status == domain.AppGroupStatus_DELETE_ERROR {
return domain.StackStatus_APPGROUP_DELETE_ERROR, appGroup.StatusDesc
}
}

Expand All @@ -536,8 +536,11 @@ func getStackStatus(cluster domain.Cluster, appGroups []domain.AppGroup) (domain
if cluster.Status == domain.ClusterStatus_DELETED {
return domain.StackStatus_CLUSTER_DELETED, cluster.StatusDesc
}
if cluster.Status == domain.ClusterStatus_ERROR {
return domain.StackStatus_CLUSTER_ERROR, cluster.StatusDesc
if cluster.Status == domain.ClusterStatus_INSTALL_ERROR {
return domain.StackStatus_CLUSTER_INSTALL_ERROR, cluster.StatusDesc
}
if cluster.Status == domain.ClusterStatus_DELETE_ERROR {
return domain.StackStatus_CLUSTER_DELETE_ERROR, cluster.StatusDesc
}

// workflow 중간 중간 비는 status 처리...
Expand Down
6 changes: 4 additions & 2 deletions pkg/domain/app-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const (
AppGroupStatus_RUNNING
AppGroupStatus_DELETING
AppGroupStatus_DELETED
AppGroupStatus_ERROR
AppGroupStatus_INSTALL_ERROR
AppGroupStatus_DELETE_ERROR
)

var appGroupStatus = [...]string{
Expand All @@ -35,7 +36,8 @@ var appGroupStatus = [...]string{
"RUNNING",
"DELETING",
"DELETED",
"ERROR",
"INSTALL_ERROR",
"DELETE_ERROR",
}

func (m AppGroupStatus) String() string { return appGroupStatus[(m)] }
Expand Down
11 changes: 8 additions & 3 deletions pkg/domain/cloud-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const (
CloudAccountStatus_CREATED
CloudAccountStatus_DELETING
CloudAccountStatus_DELETED
CloudAccountStatus_ERROR
CloudAccountStatus_CREATE_ERROR
CloudAccountStatus_DELETE_ERROR
)

var cloudAccountStatus = [...]string{
Expand All @@ -31,7 +32,8 @@ var cloudAccountStatus = [...]string{
"CREATED",
"DELETING",
"DELETED",
"ERROR",
"CREATE_ERROR",
"DELETE_ERROR",
}

func (m CloudAccountStatus) String() string { return cloudAccountStatus[(m)] }
Expand All @@ -41,7 +43,7 @@ func (m CloudAccountStatus) FromString(s string) CloudAccountStatus {
return CloudAccountStatus(i)
}
}
return CloudAccountStatus_ERROR
return CloudAccountStatus_PENDING
}

// 내부
Expand All @@ -59,6 +61,7 @@ type CloudAccount struct {
SessionToken string
Status CloudAccountStatus
StatusDesc string
CreatedIAM bool
CreatorId uuid.UUID
Creator User
UpdatorId uuid.UUID
Expand All @@ -77,6 +80,7 @@ type CloudAccountResponse struct {
Clusters int `json:"clusters"`
Status string `json:"status"`
AwsAccountId string `json:"awsAccountId"`
CreatedIAM bool `json:"createdIAM"`
Creator SimpleUserResponse `json:"creator"`
Updator SimpleUserResponse `json:"updator"`
CreatedAt time.Time `json:"createdAt"`
Expand All @@ -90,6 +94,7 @@ type SimpleCloudAccountResponse struct {
Description string `json:"description"`
CloudService string `json:"cloudService"`
AwsAccountId string `json:"awsAccountId"`
CreatedIAM bool `json:"createdIAM"`
Clusters int `json:"clusters"`
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/domain/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const (
ClusterStatus_RUNNING
ClusterStatus_DELETING
ClusterStatus_DELETED
ClusterStatus_ERROR
ClusterStatus_INSTALL_ERROR
ClusterStatus_DELETE_ERROR
)

var clusterStatus = [...]string{
Expand All @@ -35,7 +36,8 @@ var clusterStatus = [...]string{
"RUNNING",
"DELETING",
"DELETED",
"ERROR",
"INSTALL_ERROR",
"DELETE_ERROR",
}

func (m ClusterStatus) String() string { return clusterStatus[(m)] }
Expand All @@ -45,7 +47,7 @@ func (m ClusterStatus) FromString(s string) ClusterStatus {
return ClusterStatus(i)
}
}
return ClusterStatus_ERROR
return ClusterStatus_PENDING
}

// model
Expand Down
Loading