(ctx *gin.Context)
| 41 | } |
| 42 | |
| 43 | func DelInstanceHandler(ctx *gin.Context) { |
| 44 | var req ginmodel.SingleInstanceRequest |
| 45 | if err := ctx.Bind(&req); err != nil { |
| 46 | jsonResp := ginmodel.JsonResp{ |
| 47 | Code: -1, |
| 48 | Message: fmt.Sprintf("Invalid Request Data: %s", err.Error()), |
| 49 | } |
| 50 | ctx.JSON(http.StatusBadRequest, jsonResp) |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | instance, err := synchronizer.GetInstanceInfo(req.NodeIndex, req.InstanceID) |
| 55 | |
| 56 | if err != nil { |
| 57 | jsonResp := ginmodel.JsonResp{ |
| 58 | Code: -1, |
| 59 | Message: fmt.Sprintf("Get Instance Info Error: %s", err.Error()), |
| 60 | } |
| 61 | ctx.JSON(http.StatusInternalServerError, jsonResp) |
| 62 | return |
| 63 | } |
| 64 | |
| 65 | for _, connection := range instance.Connections { |
| 66 | if connection.EndNodeIndex == instance.NodeIndex { |
| 67 | err = synchronizer.RemoveLink(instance.NodeIndex, connection.LinkID) |
| 68 | if err != nil { |
| 69 | errMsg := fmt.Sprintf("Delete Link %s Error: %s", connection.LinkID, err.Error()) |
| 70 | logrus.Error(errMsg) |
| 71 | } |
| 72 | } else { |
| 73 | err = synchronizer.RemoveLink(connection.EndNodeIndex, connection.LinkID) |
| 74 | if err != nil { |
| 75 | errMsg := fmt.Sprintf("Delete Link %s Error: %s", connection.LinkID, err.Error()) |
| 76 | logrus.Error(errMsg) |
| 77 | } |
| 78 | err = synchronizer.RemoveLink(instance.NodeIndex, connection.LinkID) |
| 79 | if err != nil { |
| 80 | errMsg := fmt.Sprintf("Delete Link %s Error: %s", connection.LinkID, err.Error()) |
| 81 | logrus.Error(errMsg) |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | err = synchronizer.RemoveInstance(req.NodeIndex, req.InstanceID) |
| 86 | if err != nil { |
| 87 | jsonResp := ginmodel.JsonResp{ |
| 88 | Code: -1, |
| 89 | Message: fmt.Sprintf("Remove Instance Error: %s", err.Error()), |
| 90 | } |
| 91 | ctx.JSON(http.StatusInternalServerError, jsonResp) |
| 92 | return |
| 93 | } |
| 94 | jsonResp := ginmodel.JsonResp{ |
| 95 | Code: 0, |
| 96 | Message: "Success", |
| 97 | } |
| 98 | ctx.JSON(http.StatusOK, jsonResp) |
| 99 | } |
| 100 |
nothing calls this directly
no outgoing calls
no test coverage detected