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 CreateSystemMcisDynamic for network probe #1254

Merged
merged 3 commits into from
Nov 6, 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
46 changes: 46 additions & 0 deletions src/api/rest/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6809,6 +6809,52 @@ const docTemplate = `{
}
}
},
"/systemMcis": {
"post": {
"description": "Create System MCIS Dynamically for Special Purpose",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"[Infra service] MCIS Provisioning management"
],
"summary": "Create System MCIS Dynamically for Special Purpose in NS:system-purpose-common-ns",
"parameters": [
{
"enum": [
"probe"
],
"type": "string",
"description": "Option for the purpose of system MCIS",
"name": "option",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/mcis.TbMcisInfo"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/common.SimpleMsg"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/common.SimpleMsg"
}
}
}
}
},
"/{nsId}/checkResource/{resourceType}/{resourceId}": {
"get": {
"description": "Check resources' existence",
Expand Down
46 changes: 46 additions & 0 deletions src/api/rest/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6801,6 +6801,52 @@
}
}
},
"/systemMcis": {
"post": {
"description": "Create System MCIS Dynamically for Special Purpose",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"[Infra service] MCIS Provisioning management"
],
"summary": "Create System MCIS Dynamically for Special Purpose in NS:system-purpose-common-ns",
"parameters": [
{
"enum": [
"probe"
],
"type": "string",
"description": "Option for the purpose of system MCIS",
"name": "option",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/mcis.TbMcisInfo"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/common.SimpleMsg"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/common.SimpleMsg"
}
}
}
}
},
"/{nsId}/checkResource/{resourceType}/{resourceId}": {
"get": {
"description": "Check resources' existence",
Expand Down
30 changes: 30 additions & 0 deletions src/api/rest/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6956,6 +6956,36 @@ paths:
all Clouds to CB-Tumblebug
tags:
- '[Admin] System management'
/systemMcis:
post:
consumes:
- application/json
description: Create System MCIS Dynamically for Special Purpose
parameters:
- description: Option for the purpose of system MCIS
enum:
- probe
in: query
name: option
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/mcis.TbMcisInfo'
"404":
description: Not Found
schema:
$ref: '#/definitions/common.SimpleMsg'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/common.SimpleMsg'
summary: Create System MCIS Dynamically for Special Purpose in NS:system-purpose-common-ns
tags:
- '[Infra service] MCIS Provisioning management'
securityDefinitions:
BasicAuth:
type: basic
Expand Down
31 changes: 31 additions & 0 deletions src/api/rest/server/mcis/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,37 @@ func RestPostRegisterCSPNativeVM(c echo.Context) error {
return c.JSON(http.StatusCreated, result)
}

// RestPostSystemMcis godoc
// @Summary Create System MCIS Dynamically for Special Purpose in NS:system-purpose-common-ns
// @Description Create System MCIS Dynamically for Special Purpose
// @Tags [Infra service] MCIS Provisioning management
// @Accept json
// @Produce json
// @Param option query string false "Option for the purpose of system MCIS" Enums(probe)
// @Success 200 {object} TbMcisInfo
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /systemMcis [post]
func RestPostSystemMcis(c echo.Context) error {

option := c.QueryParam("option")

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

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

common.PrintJsonPretty(*result)

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

// RestPostMcisDynamic godoc
// @Summary Create MCIS Dynamically
// @Description Create MCIS Dynamically from common spec and image
Expand Down
1 change: 1 addition & 0 deletions src/api/rest/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func RunServer(port string) {

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

g.POST("/:nsId/mcisDynamic", rest_mcis.RestPostMcisDynamic)
g.POST("/:nsId/mcis/:mcisId/vmDynamic", rest_mcis.RestPostMcisVmDynamic)
Expand Down
67 changes: 66 additions & 1 deletion src/core/mcis/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,10 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error)
for _, k := range vmRequest {

// subGroup handling
subGroupSize, _ := strconv.Atoi(k.SubGroupSize)
subGroupSize, err := strconv.Atoi(k.SubGroupSize)
if err != nil {
subGroupSize = 1
}
fmt.Printf("subGroupSize: %v\n", subGroupSize)

if subGroupSize > 0 {
Expand Down Expand Up @@ -1203,6 +1206,68 @@ func CheckMcisDynamicReq(req *McisConnectionConfigCandidatesReq) (*CheckMcisDyna
return &mcisReqInfo, err
}

// CreateSystemMcisDynamic is func to create MCIS obeject and deploy requested VMs in a dynamic way
func CreateSystemMcisDynamic(option string) (*TbMcisInfo, error) {
nsId := common.SystemCommonNs
req := &TbMcisDynamicReq{}

// special purpose MCIS
req.Name = option
req.Label = option
req.SystemLabel = option
req.Description = option
req.InstallMonAgent = "no"

switch option {
case "probe":
connections, err := common.GetConnConfigList()
if err != nil {
common.CBLog.Error(err)
return nil, err
}
for _, v := range connections.Connectionconfig {

vmReq := &TbVmDynamicReq{}
vmReq.CommonImage = "ubuntu18.04" // temporal default value. will be changed
vmReq.CommonSpec = "aws-ap-northeast-2-t2-small" // temporal default value. will be changed

deploymentPlan := DeploymentPlan{}
condition := []Operation{}
condition = append(condition, Operation{Operand: v.RegionName})

fmt.Println(" - v.RegionName: " + v.RegionName)

deploymentPlan.Filter.Policy = append(deploymentPlan.Filter.Policy, FilterCondition{Metric: "region", Condition: condition})
deploymentPlan.Limit = "1"
common.PrintJsonPretty(deploymentPlan)

specList, err := RecommendVm(common.SystemCommonNs, deploymentPlan)
if err != nil {
common.CBLog.Error(err)
return nil, err
}
if len(specList) != 0 {
recommendedSpec := specList[0].Id
vmReq.CommonSpec = recommendedSpec

vmReq.Label = vmReq.CommonSpec
vmReq.Name = vmReq.CommonSpec
req.Vm = append(req.Vm, *vmReq)
}
}

default:
err := fmt.Errorf("Not available option. Try (option=probe)")
return nil, err
}
if req.Vm == nil {
err := fmt.Errorf("No VM is defined")
return nil, err
}

return CreateMcisDynamic(nsId, req)
}

// CreateMcisDynamic is func to create MCIS obeject and deploy requested VMs in a dynamic way
func CreateMcisDynamic(nsId string, req *TbMcisDynamicReq) (*TbMcisInfo, error) {

Expand Down
87 changes: 46 additions & 41 deletions src/core/mcis/recommendation.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,59 +90,61 @@ func RecommendVm(nsId string, plan DeploymentPlan) ([]mcir.TbSpecInfo, error) {
fmt.Println("[Filtering specs]")

for _, v := range plan.Filter.Policy {
metric := v.Metric
metric := mcir.ToNamingRuleCompatible(v.Metric)
conditions := v.Condition
for _, condition := range conditions {

operand64, err := strconv.ParseFloat(strings.ReplaceAll(condition.Operand, " ", ""), 32)
operand := float32(operand64)
if err != nil {
common.CBLog.Error(err)
return []mcir.TbSpecInfo{}, err
var operand64 float64
var operand float32
var err error
if metric == "cpu" || metric == "memory" || metric == "cost" {
operand64, err = strconv.ParseFloat(strings.ReplaceAll(condition.Operand, " ", ""), 32)
operand = float32(operand64)
if err != nil {
common.CBLog.Error(err)
return []mcir.TbSpecInfo{}, err
}
}

switch condition.Operator {
case "<=":

switch metric {
case "cpu":
switch metric {
case "cpu":
switch condition.Operator {
case "<=":
u.NumvCPU.Max = operand
case "memory":
u.MemGiB.Max = operand
case "cost":
u.CostPerHour.Max = operand
default:
fmt.Println("[Checking] Not available metric " + metric)
}

case ">=":

switch metric {
case "cpu":
case ">=":
u.NumvCPU.Min = operand
case "memory":
u.MemGiB.Min = operand
case "cost":
u.CostPerHour.Min = operand
default:
fmt.Println("[Checking] Not available metric " + metric)
}

case "==":

switch metric {
case "cpu":
case "==":
u.NumvCPU.Max = operand
u.NumvCPU.Min = operand
case "memory":
}
case "memory":
switch condition.Operator {
case "<=":
u.MemGiB.Max = operand
case ">=":
u.MemGiB.Min = operand
case "==":
u.MemGiB.Max = operand
u.MemGiB.Min = operand
case "cost":
}
case "cost":
switch condition.Operator {
case "<=":
u.CostPerHour.Max = operand
case ">=":
u.CostPerHour.Min = operand
case "==":
u.CostPerHour.Max = operand
u.CostPerHour.Min = operand
default:
fmt.Println("[Checking] Not available metric " + metric)
}
case "region":
u.RegionName = condition.Operand
case "provider":
u.ProviderName = condition.Operand
case "specname":
u.CspSpecName = condition.Operand
default:
fmt.Println("[Checking] Not available metric " + metric)
}
}
}
Expand Down Expand Up @@ -174,16 +176,19 @@ func RecommendVm(nsId string, plan DeploymentPlan) ([]mcir.TbSpecInfo, error) {
case "random":
prioritySpecs, err = RecommendVmRandom(nsId, &filteredSpecs)
default:
// fmt.Println("[Checking] Not available metric " + metric)
prioritySpecs, err = RecommendVmRandom(nsId, &filteredSpecs)
}

}
if plan.Priority.Policy == nil {
prioritySpecs, err = RecommendVmRandom(nsId, &filteredSpecs)
}

// limit the number of items in result list
result := []mcir.TbSpecInfo{}
limitNum, err := strconv.Atoi(plan.Limit)
if err != nil {
limitNum = 65535
limitNum = math.MaxInt
}
for i, v := range prioritySpecs {
result = append(result, v)
Expand Down