Skip to content

Commit

Permalink
Merge pull request #1201 from seokho-son/main
Browse files Browse the repository at this point in the history
  • Loading branch information
jihoon-seo authored Oct 13, 2022
2 parents efd7b4c + 588554e commit a63144d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/api/grpc/server/mcis/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (s *MCISService) DeleteMcis(ctx context.Context, req *pb.TbMcisQryRequest)

logger.Debug("calling MCISService.DeleteMcis()")

err := mcis.DelMcis(req.NsId, req.McisId, req.Option)
_, err := mcis.DelMcis(req.NsId, req.McisId, req.Option)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "MCISService.DeleteMcis()")
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/rest/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ var doc = `{
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.SimpleMsg"
"$ref": "#/definitions/common.IdList"
}
},
"404": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/rest/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,7 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.SimpleMsg"
"$ref": "#/definitions/common.IdList"
}
},
"404": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/rest/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3472,7 +3472,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/common.SimpleMsg'
$ref: '#/definitions/common.IdList'
"404":
description: Not Found
schema:
Expand Down
7 changes: 3 additions & 4 deletions src/api/rest/server/mcis/manageInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func RestPutMcis(c echo.Context) error {
// @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(terminate,force)
// @Success 200 {object} common.SimpleMsg
// @Success 200 {object} common.IdList
// @Failure 404 {object} common.SimpleMsg
// @Router /ns/{nsId}/mcis/{mcisId} [delete]
func RestDelMcis(c echo.Context) error {
Expand All @@ -203,15 +203,14 @@ func RestDelMcis(c echo.Context) error {
mcisId := c.Param("mcisId")
option := c.QueryParam("option")

err := mcis.DelMcis(nsId, mcisId, option)
output, err := mcis.DelMcis(nsId, mcisId, option)
if err != nil {
common.CBLog.Error(err)
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}

mapA := map[string]string{"message": "Deleted the MCIS " + mcisId}
return c.JSON(http.StatusOK, &mapA)
return c.JSON(http.StatusOK, output)
}

// RestDelAllMcis godoc
Expand Down
49 changes: 33 additions & 16 deletions src/core/mcis/manageInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1655,26 +1655,28 @@ func AttachDetachDataDisk(nsId string, mcisId string, vmId string, command strin
// [Delete MCIS and VM object]

// DelMcis is func to delete MCIS object
func DelMcis(nsId string, mcisId string, option string) error {
func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) {

option = common.ToLower(option)
deletedResources := common.IdList{}
deleteStatus := " [Done]"

err := common.CheckString(nsId)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}

err = common.CheckString(mcisId)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}
check, _ := CheckMcis(nsId, mcisId)

if !check {
err := fmt.Errorf("The mcis " + mcisId + " does not exist.")
return err
return deletedResources, err
}

fmt.Println("[Delete MCIS] " + mcisId)
Expand All @@ -1685,7 +1687,7 @@ func DelMcis(nsId string, mcisId string, option string) error {
err := fmt.Errorf("MCIS " + mcisId + " status nil, Deletion is not allowed (use option=force for force deletion)")
common.CBLog.Error(err)
if option != "force" {
return err
return deletedResources, err
}
}

Expand All @@ -1698,14 +1700,14 @@ func DelMcis(nsId string, mcisId string, option string) error {
_, err := HandleMcisAction(nsId, mcisId, ActionRefine, true)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}

// ActionTerminate
_, err = HandleMcisAction(nsId, mcisId, ActionTerminate, true)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}
// for deletion, need to wait until termination is finished
// Sleep for 5 seconds
Expand All @@ -1721,7 +1723,7 @@ func DelMcis(nsId string, mcisId string, option string) error {
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" {
return err
return deletedResources, err
}
}

Expand All @@ -1731,7 +1733,7 @@ func DelMcis(nsId string, mcisId string, option string) error {
vmList, err := ListVmId(nsId, mcisId)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}

// delete vms info
Expand All @@ -1743,13 +1745,13 @@ func DelMcis(nsId string, mcisId string, option string) error {
vmInfo, err := GetVmObject(nsId, mcisId, v)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}

err = common.CBStore.Delete(vmKey)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}

_, err = mcir.UpdateAssociatedObjectList(nsId, common.StrImage, vmInfo.ImageId, common.StrDelete, vmKey)
Expand All @@ -1768,32 +1770,47 @@ func DelMcis(nsId string, mcisId string, option string) error {
for _, v2 := range vmInfo.DataDiskIds {
mcir.UpdateAssociatedObjectList(nsId, common.StrDataDisk, v2, common.StrDelete, vmKey)
}
deletedResources.IdList = append(deletedResources.IdList, "VM: "+v+deleteStatus)
}

// delete vm group info
vmGroupList, err := ListVmGroupId(nsId, mcisId)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}
for _, v := range vmGroupList {
vmGroupKey := common.GenMcisVmGroupKey(nsId, mcisId, v)
fmt.Println(vmGroupKey)
err := common.CBStore.Delete(vmGroupKey)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}
deletedResources.IdList = append(deletedResources.IdList, "vmGroup: "+v+deleteStatus)
}

// delete associated CSP NLBs
forceFlag := "false"
if option == "force" {
forceFlag = "true"
}
output, err := DelAllNLB(nsId, mcisId, "", forceFlag)
if err != nil {
common.CBLog.Error(err)
return deletedResources, err
}
deletedResources.IdList = append(deletedResources.IdList, output.IdList...)

// delete mcis info
err = common.CBStore.Delete(key)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}
deletedResources.IdList = append(deletedResources.IdList, "MCIS: "+mcisId+deleteStatus)

return nil
return deletedResources, nil
}

// DelMcisVm is func to delete VM object
Expand Down Expand Up @@ -1890,7 +1907,7 @@ func CoreDelAllMcis(nsId string, option string) (string, error) {
}

for _, v := range mcisList {
err := DelMcis(nsId, v, option)
_, err := DelMcis(nsId, v, option)
if err != nil {
common.CBLog.Error(err)
return "", fmt.Errorf("Failed to delete All MCISs")
Expand Down

0 comments on commit a63144d

Please sign in to comment.