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

Add MCIS status count feature and update MCIS response field #732

Merged
merged 2 commits into from
Sep 14, 2021
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
55 changes: 55 additions & 0 deletions src/api/rest/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5509,6 +5509,9 @@ var doc = `{
"status": {
"type": "string"
},
"statusCount": {
"$ref": "#/definitions/mcis.StatusCountInfo"
},
"targetAction": {
"type": "string"
},
Expand Down Expand Up @@ -5883,6 +5886,55 @@ var doc = `{
}
}
},
"mcis.StatusCountInfo": {
"type": "object",
"properties": {
"countCreating": {
"description": "CountCreating is for counting Creating",
"type": "integer"
},
"countFailed": {
"description": "CountFailed is for counting Failed",
"type": "integer"
},
"countRebooting": {
"description": "CountRebooting is for counting Rebooting",
"type": "integer"
},
"countResuming": {
"description": "CountResuming is for counting Resuming",
"type": "integer"
},
"countRunning": {
"description": "CountRunning is for counting Running",
"type": "integer"
},
"countSuspended": {
"description": "CountSuspended is for counting Suspended",
"type": "integer"
},
"countSuspending": {
"description": "CountSuspending is for counting Suspending",
"type": "integer"
},
"countTerminated": {
"description": "CountTerminated is for counting Terminated",
"type": "integer"
},
"countTerminating": {
"description": "CountTerminating is for counting Terminating",
"type": "integer"
},
"countTotal": {
"description": "CountTotal is for Total VMs",
"type": "integer"
},
"countUndefined": {
"description": "CountUndefined is for counting Undefined",
"type": "integer"
}
}
},
"mcis.TbInspectResourcesResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -5939,6 +5991,9 @@ var doc = `{
"status": {
"type": "string"
},
"statusCount": {
"$ref": "#/definitions/mcis.StatusCountInfo"
},
"targetAction": {
"type": "string"
},
Expand Down
55 changes: 55 additions & 0 deletions src/api/rest/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5494,6 +5494,9 @@
"status": {
"type": "string"
},
"statusCount": {
"$ref": "#/definitions/mcis.StatusCountInfo"
},
"targetAction": {
"type": "string"
},
Expand Down Expand Up @@ -5868,6 +5871,55 @@
}
}
},
"mcis.StatusCountInfo": {
"type": "object",
"properties": {
"countCreating": {
"description": "CountCreating is for counting Creating",
"type": "integer"
},
"countFailed": {
"description": "CountFailed is for counting Failed",
"type": "integer"
},
"countRebooting": {
"description": "CountRebooting is for counting Rebooting",
"type": "integer"
},
"countResuming": {
"description": "CountResuming is for counting Resuming",
"type": "integer"
},
"countRunning": {
"description": "CountRunning is for counting Running",
"type": "integer"
},
"countSuspended": {
"description": "CountSuspended is for counting Suspended",
"type": "integer"
},
"countSuspending": {
"description": "CountSuspending is for counting Suspending",
"type": "integer"
},
"countTerminated": {
"description": "CountTerminated is for counting Terminated",
"type": "integer"
},
"countTerminating": {
"description": "CountTerminating is for counting Terminating",
"type": "integer"
},
"countTotal": {
"description": "CountTotal is for Total VMs",
"type": "integer"
},
"countUndefined": {
"description": "CountUndefined is for counting Undefined",
"type": "integer"
}
}
},
"mcis.TbInspectResourcesResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -5924,6 +5976,9 @@
"status": {
"type": "string"
},
"statusCount": {
"$ref": "#/definitions/mcis.StatusCountInfo"
},
"targetAction": {
"type": "string"
},
Expand Down
40 changes: 40 additions & 0 deletions src/api/rest/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,8 @@ definitions:
type: string
status:
type: string
statusCount:
$ref: '#/definitions/mcis.StatusCountInfo'
targetAction:
type: string
targetStatus:
Expand Down Expand Up @@ -1125,6 +1127,42 @@ definitions:
vpcname:
type: string
type: object
mcis.StatusCountInfo:
properties:
countCreating:
description: CountCreating is for counting Creating
type: integer
countFailed:
description: CountFailed is for counting Failed
type: integer
countRebooting:
description: CountRebooting is for counting Rebooting
type: integer
countResuming:
description: CountResuming is for counting Resuming
type: integer
countRunning:
description: CountRunning is for counting Running
type: integer
countSuspended:
description: CountSuspended is for counting Suspended
type: integer
countSuspending:
description: CountSuspending is for counting Suspending
type: integer
countTerminated:
description: CountTerminated is for counting Terminated
type: integer
countTerminating:
description: CountTerminating is for counting Terminating
type: integer
countTotal:
description: CountTotal is for Total VMs
type: integer
countUndefined:
description: CountUndefined is for counting Undefined
type: integer
type: object
mcis.TbInspectResourcesResponse:
properties:
resourcesOnCsp:
Expand Down Expand Up @@ -1169,6 +1207,8 @@ definitions:
type: string
status:
type: string
statusCount:
$ref: '#/definitions/mcis.StatusCountInfo'
targetAction:
type: string
targetStatus:
Expand Down
40 changes: 40 additions & 0 deletions src/api/rest/docs/v0.4.7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,8 @@ definitions:
type: string
status:
type: string
statusCount:
$ref: '#/definitions/mcis.StatusCountInfo'
targetAction:
type: string
targetStatus:
Expand Down Expand Up @@ -1125,6 +1127,42 @@ definitions:
vpcname:
type: string
type: object
mcis.StatusCountInfo:
properties:
countCreating:
description: CountCreating is for counting Creating
type: integer
countFailed:
description: CountFailed is for counting Failed
type: integer
countRebooting:
description: CountRebooting is for counting Rebooting
type: integer
countResuming:
description: CountResuming is for counting Resuming
type: integer
countRunning:
description: CountRunning is for counting Running
type: integer
countSuspended:
description: CountSuspended is for counting Suspended
type: integer
countSuspending:
description: CountSuspending is for counting Suspending
type: integer
countTerminated:
description: CountTerminated is for counting Terminated
type: integer
countTerminating:
description: CountTerminating is for counting Terminating
type: integer
countTotal:
description: CountTotal is for Total VMs
type: integer
countUndefined:
description: CountUndefined is for counting Undefined
type: integer
type: object
mcis.TbInspectResourcesResponse:
properties:
resourcesOnCsp:
Expand Down Expand Up @@ -1169,6 +1207,8 @@ definitions:
type: string
status:
type: string
statusCount:
$ref: '#/definitions/mcis.StatusCountInfo'
targetAction:
type: string
targetStatus:
Expand Down
70 changes: 62 additions & 8 deletions src/core/mcis/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,12 @@ func TbMcisReqStructLevelValidation(sl validator.StructLevel) {

// TbMcisInfo is struct for MCIS info
type TbMcisInfo struct {
Id string `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
TargetStatus string `json:"targetStatus"`
TargetAction string `json:"targetAction"`
Id string `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
StatusCount StatusCountInfo `json:"statusCount"`
TargetStatus string `json:"targetStatus"`
TargetAction string `json:"targetAction"`

// InstallMonAgent Option for CB-Dragonfly agent installation ([yes/no] default:yes)
InstallMonAgent string `json:"installMonAgent" example:"yes" default:"yes" enums:"yes,no"` // yes or no
Expand Down Expand Up @@ -289,14 +290,52 @@ type GeoLocation struct {
NativeRegion string `json:"nativeRegion"`
}

// StatusCountInfo is struct to count the number of VMs in each status. ex: Running=4, Suspended=8.
type StatusCountInfo struct {

// CountTotal is for Total VMs
CountTotal int `json:"countTotal"`

// CountCreating is for counting Creating
CountCreating int `json:"countCreating"`

// CountRunning is for counting Running
CountRunning int `json:"countRunning"`

// CountFailed is for counting Failed
CountFailed int `json:"countFailed"`

// CountSuspended is for counting Suspended
CountSuspended int `json:"countSuspended"`

// CountRebooting is for counting Rebooting
CountRebooting int `json:"countRebooting"`

// CountTerminated is for counting Terminated
CountTerminated int `json:"countTerminated"`

// CountSuspending is for counting Suspending
CountSuspending int `json:"countSuspending"`

// CountResuming is for counting Resuming
CountResuming int `json:"countResuming"`

// CountTerminating is for counting Terminating
CountTerminating int `json:"countTerminating"`

// CountUndefined is for counting Undefined
CountUndefined int `json:"countUndefined"`
}

// McisStatusInfo is struct to define simple information of MCIS with updated status of all VMs
type McisStatusInfo struct {
Id string `json:"id"`
Name string `json:"name"`

Status string `json:"status"`
TargetStatus string `json:"targetStatus"`
TargetAction string `json:"targetAction"`
Status string `json:"status"`
StatusCount StatusCountInfo `json:"statusCount"`
TargetStatus string `json:"targetStatus"`
TargetAction string `json:"targetAction"`

// InstallMonAgent Option for CB-Dragonfly agent installation ([yes/no] default:yes)
InstallMonAgent string `json:"installMonAgent" example:"[yes, no]"` // yes or no
Expand Down Expand Up @@ -1671,6 +1710,7 @@ func GetMcisInfo(nsId string, mcisId string) (*TbMcisInfo, error) {
// common.PrintJsonPretty(mcisStatus)

mcisObj.Status = mcisStatus.Status
mcisObj.StatusCount = mcisStatus.StatusCount

vmList, err := ListVmId(nsId, mcisId)
if err != nil {
Expand Down Expand Up @@ -4022,6 +4062,19 @@ func GetMcisStatus(nsId string, mcisId string) (*McisStatusInfo, error) {
// mcisStatus.Status = statusFlagStr[9] + proportionStr
// }

// Set mcisStatus.StatusCount
mcisStatus.StatusCount.CountTotal = numVm
mcisStatus.StatusCount.CountFailed = statusFlag[0]
mcisStatus.StatusCount.CountSuspended = statusFlag[1]
mcisStatus.StatusCount.CountRunning = statusFlag[2]
mcisStatus.StatusCount.CountTerminated = statusFlag[3]
mcisStatus.StatusCount.CountCreating = statusFlag[4]
mcisStatus.StatusCount.CountSuspending = statusFlag[5]
mcisStatus.StatusCount.CountResuming = statusFlag[6]
mcisStatus.StatusCount.CountRebooting = statusFlag[7]
mcisStatus.StatusCount.CountTerminating = statusFlag[8]
mcisStatus.StatusCount.CountUndefined = statusFlag[9]

var isDone bool
isDone = true
for _, v := range mcisStatus.Vm {
Expand All @@ -4034,6 +4087,7 @@ func GetMcisStatus(nsId string, mcisId string) (*McisStatusInfo, error) {
mcisStatus.TargetStatus = StatusComplete
mcisTmp.TargetAction = ActionComplete
mcisTmp.TargetStatus = StatusComplete
mcisTmp.StatusCount = mcisStatus.StatusCount
UpdateMcisInfo(nsId, mcisTmp)
}

Expand Down