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

Fix object information for MCIS provisioning #949

Merged
merged 4 commits into from
Nov 9, 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/grpc/server/mcis/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (s *MCISService) CreateMcisVMGroup(ctx context.Context, req *pb.TbVmGroupCr
return nil, gc.ConvGrpcStatusErr(err, "", "MCISService.CreateMcisVMGroup()")
}

result, err := mcis.CorePostMcisGroupVm(req.NsId, req.McisId, &mcisObj)
result, err := mcis.CreateMcisGroupVm(req.NsId, req.McisId, &mcisObj)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "MCISService.CreateMcisVMGroup()")
}
Expand Down
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 @@ -632,7 +632,7 @@ func RestPostMcisVmGroup(c echo.Context) error {
}
common.PrintJsonPretty(*vmInfoData)

result, err := mcis.CorePostMcisGroupVm(nsId, mcisId, vmInfoData)
result, err := mcis.CreateMcisGroupVm(nsId, mcisId, vmInfoData)
if err != nil {
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
Expand Down
6 changes: 6 additions & 0 deletions src/core/mcir/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ import (
validator "github.com/go-playground/validator/v10"
)

// SpiderImageReqInfoWrapper struct is ...
type SpiderImageReqInfoWrapper struct { // Spider
ConnectionName string
ReqInfo SpiderImageInfo
}

// SpiderImageInfo struct is ...
type SpiderImageInfo struct { // Spider
// Fields for request
Name string
Expand All @@ -46,13 +48,15 @@ type SpiderImageInfo struct { // Spider
KeyValueList []common.KeyValue
}

// TbImageReq struct is for image create request
type TbImageReq struct {
Name string `json:"name" validate:"required"`
ConnectionName string `json:"connectionName" validate:"required"`
CspImageId string `json:"cspImageId" validate:"required"`
Description string `json:"description"`
}

// TbImageReqStructLevelValidation func is for Validation
func TbImageReqStructLevelValidation(sl validator.StructLevel) {

u := sl.Current().Interface().(TbImageReq)
Expand All @@ -64,6 +68,7 @@ func TbImageReqStructLevelValidation(sl validator.StructLevel) {
}
}

// TbImageInfo struct is for image object
type TbImageInfo struct {
Namespace string `json:"namespace,omitempty"` // required to save in RDB
Id string `json:"id,omitempty"`
Expand Down Expand Up @@ -277,6 +282,7 @@ func RegisterImageWithInfo(nsId string, content *TbImageInfo) (TbImageInfo, erro
return *content, nil
}

// SpiderImageList is struct for Spider Image List
type SpiderImageList struct {
Image []SpiderImageInfo `json:"image"`
}
Expand Down
61 changes: 4 additions & 57 deletions src/core/mcis/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,61 +481,6 @@ func CorePostMcisVm(nsId string, mcisId string, vmInfoData *TbVmInfo) (*TbVmInfo
return vmInfoData, nil
}

// CorePostMcisGroupVm is func for a wrapper for CreateMcisGroupVm
func CorePostMcisGroupVm(nsId string, mcisId string, vmReq *TbVmReq) (*TbMcisInfo, error) {

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

err = common.CheckString(mcisId)
if err != nil {
temp := &TbMcisInfo{}
common.CBLog.Error(err)
return temp, err
}

// returns InvalidValidationError for bad validation input, nil or ValidationErrors ( []FieldError )
err = validate.Struct(vmReq)
if err != nil {

// this check is only needed when your code could produce
// an invalid value for validation such as interface with nil
// value most including myself do not usually have code like this.
if _, ok := err.(*validator.InvalidValidationError); ok {
fmt.Println(err)
return nil, err
}

// for _, err := range err.(validator.ValidationErrors) {

// fmt.Println(err.Namespace()) // can differ when a custom TagNameFunc is registered or
// fmt.Println(err.Field()) // by passing alt name to ReportError like below
// fmt.Println(err.StructNamespace())
// fmt.Println(err.StructField())
// fmt.Println(err.Tag())
// fmt.Println(err.ActualTag())
// fmt.Println(err.Kind())
// fmt.Println(err.Type())
// fmt.Println(err.Value())
// fmt.Println(err.Param())
// fmt.Println()
// }

return nil, err
}

content, err := CreateMcisGroupVm(nsId, mcisId, vmReq)
if err != nil {
common.CBLog.Error(err)
return content, err
}
return content, nil
}

// CreateMcisGroupVm is func to create MCIS groupVM
func CreateMcisGroupVm(nsId string, mcisId string, vmRequest *TbVmReq) (*TbMcisInfo, error) {

Expand Down Expand Up @@ -907,6 +852,8 @@ func CreateMcis(nsId string, req *TbMcisReq) (*TbMcisInfo, error) {
vmInfoData.VmUserAccount = k.VmUserAccount
vmInfoData.VmUserPassword = k.VmUserPassword

vmInfoData.Label = k.Label

// Avoid concurrent requests to CSP.
time.Sleep(time.Duration(i) * time.Second)

Expand Down Expand Up @@ -973,12 +920,12 @@ func CreateMcis(nsId string, req *TbMcisReq) (*TbMcisInfo, error) {
}
}

mcisTmp, err = GetMcisObject(nsId, mcisId)
mcisResult, err := GetMcisInfo(nsId, mcisId)
if err != nil {
common.CBLog.Error(err)
return nil, err
}
return &mcisTmp, nil
return mcisResult, nil
}

// CreateMcisDynamic is func to create MCIS obeject and deploy requested VMs in a dynamic way
Expand Down