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

Support credential selection for dynamic MCIS creation #1069

Merged
merged 5 commits into from
Apr 22, 2022
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
856 changes: 428 additions & 428 deletions assets/cloudspec.csv

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions src/api/rest/server/mcis/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,36 @@ func RestPostMcisDynamic(c echo.Context) error {
return c.JSON(http.StatusCreated, result)
}

// RestPostMcisDynamicCheckRequest godoc
// @Summary Check avaiable ConnectionConfig list for creating MCIS Dynamically
// @Description Check avaiable ConnectionConfig list before create MCIS Dynamically from common spec and image
// @Tags [Infra service] MCIS Provisioning management
// @Accept json
// @Produce json
// @Param mcisReq body McisConnectionConfigCandidatesReq true "Details for MCIS dynamic request information"
// @Success 200 {object} CheckMcisDynamicReqInfo
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /mcisDynamicCheckRequest [post]
func RestPostMcisDynamicCheckRequest(c echo.Context) error {

req := &mcis.McisConnectionConfigCandidatesReq{}
if err := c.Bind(req); err != nil {
return err
}

result, err := mcis.CheckMcisDynamicReq(req)
if err != nil {
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}

//fmt.Printf("%+v\n", *result)
common.PrintJsonPretty(*result)

return c.JSON(http.StatusOK, result)
}

// RestPostMcisVm godoc
// @Summary Create VM in specified MCIS
// @Description Create VM in specified MCIS
Expand Down
5 changes: 2 additions & 3 deletions src/api/rest/server/mcis/recommendation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ import (
// @Tags [Infra service] MCIS Provisioning management
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(common)
// @Param deploymentPlan body mcis.DeploymentPlan false "Recommend MCIS plan (filter and priority)"
// @Success 200 {object} []mcir.TbSpecInfo
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/mcisRecommendVm [post]
// @Router /mcisRecommendVm [post]
func RestRecommendVm(c echo.Context) error {

nsId := c.Param("nsId")
nsId := common.SystemCommonNs

u := &mcis.DeploymentPlan{}
if err := c.Bind(u); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions src/api/rest/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ func RunServer(port string) {
g.POST("/:nsId/mcis", rest_mcis.RestPostMcis)
g.POST("/:nsId/registerCspVm", rest_mcis.RestPostRegisterCSPNativeVM)

e.POST("/tumblebug/mcisRecommendVm", rest_mcis.RestRecommendVm)
e.POST("/tumblebug/mcisDynamicCheckRequest", rest_mcis.RestPostMcisDynamicCheckRequest)

g.POST("/:nsId/mcisDynamic", rest_mcis.RestPostMcisDynamic)
g.GET("/:nsId/mcis/:mcisId", rest_mcis.RestGetMcis)
g.GET("/:nsId/mcis", rest_mcis.RestGetAllMcis)
Expand All @@ -178,8 +181,6 @@ func RunServer(port string) {

//g.POST("/:nsId/mcis/recommend", rest_mcis.RestPostMcisRecommend)

g.POST("/:nsId/mcisRecommendVm", rest_mcis.RestRecommendVm)

g.GET("/:nsId/control/mcis/:mcisId", rest_mcis.RestGetControlMcis)
g.GET("/:nsId/control/mcis/:mcisId/vm/:vmId", rest_mcis.RestGetControlMcisVm)

Expand Down
2 changes: 2 additions & 0 deletions src/core/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const (
StrVNet string = "vNet"
StrSubnet string = "subnet"
StrDefaultResourceName string = "-systemdefault-"
// SystemCommonNs is const for SystemCommon NameSpace ID
SystemCommonNs string = "system-purpose-common-ns"
)

var StartTime string
Expand Down
34 changes: 21 additions & 13 deletions src/core/mcir/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1673,12 +1673,11 @@ func LoadCommonResource() (common.IdList, error) {
var waitSpecImg sync.WaitGroup
var wait sync.WaitGroup

// Check 'common' namespace. Create one if not.
commonNsId := "common"
_, err := common.GetNs(commonNsId)
// Check common namespace. Create one if not.
_, err := common.GetNs(common.SystemCommonNs)
if err != nil {
nsReq := common.NsReq{}
nsReq.Name = commonNsId
nsReq.Name = common.SystemCommonNs
nsReq.Description = "Namespace for common resources"
_, nsErr := common.CreateNs(&nsReq)
if nsErr != nil {
Expand Down Expand Up @@ -1711,8 +1710,8 @@ func LoadCommonResource() (common.IdList, error) {
common.RandomSleep(20)
specReqTmp := TbSpecReq{}
// [0]connectionName, [1]cspSpecName, [2]CostPerHour, [3]evaluationScore01, ..., [12]evaluationScore10
specReqTmp.ConnectionName = row[0]
specReqTmp.CspSpecName = row[1]
specReqTmp.ConnectionName = row[2]
specReqTmp.CspSpecName = row[3]
// Give a name for spec object by combining ConnectionName and CspSpecName
// To avoid naming-rule violation, modify the string
specReqTmp.Name = specReqTmp.ConnectionName + "-" + specReqTmp.CspSpecName
Expand All @@ -1724,7 +1723,7 @@ func LoadCommonResource() (common.IdList, error) {
common.PrintJsonPretty(specReqTmp)

// Register Spec object
_, err1 := RegisterSpecWithCspSpecName(commonNsId, &specReqTmp)
_, err1 := RegisterSpecWithCspSpecName(common.SystemCommonNs, &specReqTmp)
if err1 != nil {
common.CBLog.Error(err1)
// If already exist, error will occur
Expand All @@ -1733,27 +1732,36 @@ func LoadCommonResource() (common.IdList, error) {
}
specObjId := specReqTmp.Name

// Update registered Spec object with ProviderName
providerName := row[0]

// Update registered Spec object with RegionName
regionName := row[1]

// Update registered Spec object with Cost info
costPerHour, err2 := strconv.ParseFloat(strings.ReplaceAll(row[2], " ", ""), 32)
costPerHour, err2 := strconv.ParseFloat(strings.ReplaceAll(row[4], " ", ""), 32)
if err2 != nil {
common.CBLog.Error(err2)
// If already exist, error will occur. Even if error, do not return here to update information
// return err
}

evaluationScore01, err2 := strconv.ParseFloat(strings.ReplaceAll(row[3], " ", ""), 32)
evaluationScore01, err2 := strconv.ParseFloat(strings.ReplaceAll(row[5], " ", ""), 32)
if err2 != nil {
common.CBLog.Error(err2)
// If already exist, error will occur. Even if error, do not return here to update information
// return err
}

specUpdateRequest :=
TbSpecInfo{CostPerHour: float32(costPerHour),
TbSpecInfo{
ProviderName: providerName,
RegionName: regionName,
CostPerHour: float32(costPerHour),
EvaluationScore01: float32(evaluationScore01),
}

updatedSpecInfo, err3 := UpdateSpec(commonNsId, specObjId, specUpdateRequest)
updatedSpecInfo, err3 := UpdateSpec(common.SystemCommonNs, specObjId, specUpdateRequest)
if err3 != nil {
common.CBLog.Error(err3)
// If already exist, error will occur
Expand Down Expand Up @@ -1823,7 +1831,7 @@ func LoadCommonResource() (common.IdList, error) {
common.PrintJsonPretty(imageReqTmp)

// Register Spec object
_, err1 := RegisterImageWithId(commonNsId, &imageReqTmp)
_, err1 := RegisterImageWithId(common.SystemCommonNs, &imageReqTmp)
if err1 != nil {
common.CBLog.Error(err1)
// If already exist, error will occur
Expand All @@ -1836,7 +1844,7 @@ func LoadCommonResource() (common.IdList, error) {

imageUpdateRequest := TbImageInfo{GuestOS: osType}

updatedImageInfo, err2 := UpdateImage(commonNsId, imageObjId, imageUpdateRequest)
updatedImageInfo, err2 := UpdateImage(common.SystemCommonNs, imageObjId, imageUpdateRequest)
if err2 != nil {
common.CBLog.Error(err2)
//return err
Expand Down
95 changes: 60 additions & 35 deletions src/core/mcir/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ type TbSpecInfo struct { // Tumblebug
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
ConnectionName string `json:"connectionName,omitempty"`
ProviderName string `json:"providerName,omitempty"`
RegionName string `json:"regionName,omitempty"`
CspSpecName string `json:"cspSpecName,omitempty"`
OsType string `json:"osType,omitempty"`
NumvCPU uint16 `json:"numvCPU,omitempty"`
Expand Down Expand Up @@ -122,6 +124,43 @@ type TbSpecInfo struct { // Tumblebug
SystemLabel string `json:"systemLabel,omitempty" example:"Managed by CB-Tumblebug" default:""`
}

// FilterSpecsByRangeRequest is for 'FilterSpecsByRange'
type FilterSpecsByRangeRequest struct {
Id string `json:"id"`
Name string `json:"name"`
ConnectionName string `json:"connectionName"`
ProviderName string `json:"providerName"`
RegionName string `json:"regionName"`
CspSpecName string `json:"cspSpecName"`
OsType string `json:"osType"`
NumvCPU Range `json:"numvCPU"`
NumCore Range `json:"numcore"`
MemGiB Range `json:"memGiB"`
StorageGiB Range `json:"storageGiB"`
Description string `json:"description"`
CostPerHour Range `json:"costPerHour"`
NumStorage Range `json:"numStorage"`
MaxNumStorage Range `json:"maxNumStorage"`
MaxTotalStorageTiB Range `json:"maxTotalStorageTiB"`
NetBwGbps Range `json:"netBwGbps"`
EbsBwMbps Range `json:"ebsBwMbps"`
GpuModel string `json:"gpuModel"`
NumGpu Range `json:"numGpu"`
GpuMemGiB Range `json:"gpuMemGiB"`
GpuP2p string `json:"gpuP2p"`
EvaluationStatus string `json:"evaluationStatus"`
EvaluationScore01 Range `json:"evaluationScore01"`
EvaluationScore02 Range `json:"evaluationScore02"`
EvaluationScore03 Range `json:"evaluationScore03"`
EvaluationScore04 Range `json:"evaluationScore04"`
EvaluationScore05 Range `json:"evaluationScore05"`
EvaluationScore06 Range `json:"evaluationScore06"`
EvaluationScore07 Range `json:"evaluationScore07"`
EvaluationScore08 Range `json:"evaluationScore08"`
EvaluationScore09 Range `json:"evaluationScore09"`
EvaluationScore10 Range `json:"evaluationScore10"`
}

// ConvertSpiderSpecToTumblebugSpec accepts an Spider spec object, converts to and returns an TB spec object
func ConvertSpiderSpecToTumblebugSpec(spiderSpec SpiderSpecInfo) (TbSpecInfo, error) {
if spiderSpec.Name == "" {
Expand All @@ -134,6 +173,7 @@ func ConvertSpiderSpecToTumblebugSpec(spiderSpec SpiderSpecInfo) (TbSpecInfo, er

tumblebugSpec.Name = spiderSpec.Name
tumblebugSpec.CspSpecName = spiderSpec.Name
tumblebugSpec.RegionName = spiderSpec.Region
tempUint64, _ := strconv.ParseUint(spiderSpec.VCpu.Count, 10, 16)
tumblebugSpec.NumvCPU = uint16(tempUint64)
tempFloat64, _ := strconv.ParseFloat(spiderSpec.Mem, 32)
Expand Down Expand Up @@ -569,6 +609,16 @@ func FilterSpecs(nsId string, filter TbSpecInfo) ([]TbSpecInfo, error) {
filter.ConnectionName = ToNamingRuleCompatible(filter.ConnectionName)
sqlQuery = sqlQuery.And("ConnectionName LIKE ?", "%"+filter.ConnectionName+"%")
}
if filter.RegionName != "" {
//sqlQuery += " AND `regionName` LIKE '%" + filter.RegionName + "%'"
filter.RegionName = ToNamingRuleCompatible(filter.RegionName)
sqlQuery = sqlQuery.And("RegionName LIKE ?", "%"+filter.RegionName+"%")
}
if filter.ProviderName != "" {
//sqlQuery += " AND `providerName` LIKE '%" + filter.ProviderName + "%'"
filter.ProviderName = ToNamingRuleCompatible(filter.ProviderName)
sqlQuery = sqlQuery.And("ProviderName LIKE ?", "%"+filter.ProviderName+"%")
}
if filter.CspSpecName != "" {
//sqlQuery += " AND `cspSpecName` LIKE '%" + filter.CspSpecName + "%'"
filter.CspSpecName = ToNamingRuleCompatible(filter.CspSpecName)
Expand Down Expand Up @@ -703,41 +753,6 @@ type Range struct {
Max float32 `json:"max"`
}

// FilterSpecsByRangeRequest is for 'FilterSpecsByRange'
type FilterSpecsByRangeRequest struct {
Id string `json:"id"`
Name string `json:"name"`
ConnectionName string `json:"connectionName"`
CspSpecName string `json:"cspSpecName"`
OsType string `json:"osType"`
NumvCPU Range `json:"numvCPU"`
NumCore Range `json:"numcore"`
MemGiB Range `json:"memGiB"`
StorageGiB Range `json:"storageGiB"`
Description string `json:"description"`
CostPerHour Range `json:"costPerHour"`
NumStorage Range `json:"numStorage"`
MaxNumStorage Range `json:"maxNumStorage"`
MaxTotalStorageTiB Range `json:"maxTotalStorageTiB"`
NetBwGbps Range `json:"netBwGbps"`
EbsBwMbps Range `json:"ebsBwMbps"`
GpuModel string `json:"gpuModel"`
NumGpu Range `json:"numGpu"`
GpuMemGiB Range `json:"gpuMemGiB"`
GpuP2p string `json:"gpuP2p"`
EvaluationStatus string `json:"evaluationStatus"`
EvaluationScore01 Range `json:"evaluationScore01"`
EvaluationScore02 Range `json:"evaluationScore02"`
EvaluationScore03 Range `json:"evaluationScore03"`
EvaluationScore04 Range `json:"evaluationScore04"`
EvaluationScore05 Range `json:"evaluationScore05"`
EvaluationScore06 Range `json:"evaluationScore06"`
EvaluationScore07 Range `json:"evaluationScore07"`
EvaluationScore08 Range `json:"evaluationScore08"`
EvaluationScore09 Range `json:"evaluationScore09"`
EvaluationScore10 Range `json:"evaluationScore10"`
}

// FilterSpecsByRange accepts criteria ranges for filtering, and returns the list of filtered TB spec objects
func FilterSpecsByRange(nsId string, filter FilterSpecsByRangeRequest) ([]TbSpecInfo, error) {

Expand Down Expand Up @@ -767,6 +782,16 @@ func FilterSpecsByRange(nsId string, filter FilterSpecsByRangeRequest) ([]TbSpec
filter.ConnectionName = ToNamingRuleCompatible(filter.ConnectionName)
sqlQuery = sqlQuery.And("ConnectionName LIKE ?", "%"+filter.ConnectionName+"%")
}
if filter.RegionName != "" {
//sqlQuery += " AND `regionName` LIKE '%" + filter.RegionName + "%'"
filter.RegionName = ToNamingRuleCompatible(filter.RegionName)
sqlQuery = sqlQuery.And("RegionName LIKE ?", "%"+filter.RegionName+"%")
}
if filter.ProviderName != "" {
//sqlQuery += " AND `providerName` LIKE '%" + filter.ProviderName + "%'"
filter.ProviderName = ToNamingRuleCompatible(filter.ProviderName)
sqlQuery = sqlQuery.And("ProviderName LIKE ?", "%"+filter.ProviderName+"%")
}
if filter.CspSpecName != "" {
//sqlQuery += " AND `cspSpecName` LIKE '%" + filter.CspSpecName + "%'"
filter.CspSpecName = ToNamingRuleCompatible(filter.CspSpecName)
Expand Down
Loading