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 option=terminate for delete mcis #959

Merged
merged 1 commit into from
Nov 11, 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
2 changes: 1 addition & 1 deletion src/api/rest/server/mcis/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func RestPutMcis(c echo.Context) error {
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param option query string false "Option for delete MCIS (support force delete)" Enums(force)
// @Param option query string false "Option for delete MCIS (support force delete)" Enums(terminate,force)
// @Success 200 {object} common.SimpleMsg
// @Failure 404 {object} common.SimpleMsg
// @Router /ns/{nsId}/mcis/{mcisId} [delete]
Expand Down
1 change: 1 addition & 0 deletions src/core/mcis/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type ControlVmResultWrapper struct {

// HandleMcisAction is func to handle actions to MCIS
func HandleMcisAction(nsId string, mcisId string, action string) (string, error) {
action = common.ToLower(action)

err := common.CheckString(nsId)
if err != nil {
Expand Down
37 changes: 24 additions & 13 deletions src/core/mcis/manageInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,8 @@ func UpdateVmInfo(nsId string, mcisId string, vmInfoData TbVmInfo) {
// DelMcis is func to delete MCIS object
func DelMcis(nsId string, mcisId string, option string) error {

option = common.ToLower(option)

err := common.CheckString(nsId)
if err != nil {
common.CBLog.Error(err)
Expand All @@ -1353,18 +1355,27 @@ func DelMcis(nsId string, mcisId string, option string) error {

fmt.Println("[Delete MCIS] " + mcisId)

// // ControlMcis first
// err = ControlMcisAsync(nsId, mcisId, ActionTerminate)
// if err != nil {
// common.CBLog.Error(err)
// if option != "force" {
// return err
// }
// }
// // for deletion, need to wait until termination is finished
// // Sleep for 5 seconds
// fmt.Printf("\n\n[Info] Sleep for 5 seconds for safe MCIS-VMs termination.\n\n")
// time.Sleep(5 * time.Second)
// with terminate option, do MCIS refine and terminate in advance
if strings.EqualFold(option, ActionTerminate) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case in-sensitive 비교 방식 입니다. 사용자 입력을 string으로 받으니, 대소문자를 항상 처리해야 하니 좀 귀찮긴하네요.ㅎ


// ActionRefine
_, err := HandleMcisAction(nsId, mcisId, ActionRefine)
if err != nil {
common.CBLog.Error(err)
return err
}

// ActionTerminate
_, err = HandleMcisAction(nsId, mcisId, ActionTerminate)
if err != nil {
common.CBLog.Error(err)
return err
}
// for deletion, need to wait until termination is finished
// Sleep for 5 seconds
fmt.Printf("\n\n[Info] Sleep for 5 seconds for safe MCIS-VMs termination.\n\n")
time.Sleep(5 * time.Second)
}

// Check MCIS status is Terminated so that approve deletion
mcisStatus, _ := GetMcisStatus(nsId, mcisId)
Expand All @@ -1376,7 +1387,7 @@ func DelMcis(nsId string, mcisId string, option string) error {
}
}
// Check MCIS status is Terminated (not Partial)
if !(!strings.Contains(mcisStatus.Status, "Partial-") && (strings.Contains(mcisStatus.Status, StatusTerminated) || strings.Contains(mcisStatus.Status, StatusUndefined) || strings.Contains(mcisStatus.Status, StatusFailed))) {
if mcisStatus.Id != "" && !(!strings.Contains(mcisStatus.Status, "Partial-") && (strings.Contains(mcisStatus.Status, StatusTerminated) || strings.Contains(mcisStatus.Status, StatusUndefined) || strings.Contains(mcisStatus.Status, StatusFailed))) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아주 드물게 (spider가 중간에 죽는다거나 하는 상황) , mcis 정보에 오류가 포함되어 mcisStatus.Id 가 비어 있는 경우가 있습니다. 이 경우에는 force delete 로 처리되도록 안전옵션을 추가하였습니다.

err := fmt.Errorf("MCIS " + mcisId + " is " + mcisStatus.Status + " and not " + StatusTerminated + "/" + StatusUndefined + "/" + StatusFailed + ", Deletion is not allowed (use option=force for force deletion)")
common.CBLog.Error(err)
if option != "force" {
Expand Down
3 changes: 3 additions & 0 deletions src/core/mcis/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ const (
// ActionReboot is const for Reboot
ActionReboot string = "Reboot"

// ActionRefine is const for Refine
ActionRefine string = "Refine"

// ActionComplete is const for Complete
ActionComplete string = "None"
)
Expand Down