Skip to content

Commit

Permalink
Apply on-premise model and align with Tumblebug v0.9.11 APIs
Browse files Browse the repository at this point in the history
* Apply onprem model (as known as source model) from cm-model repository
* Replace `defaultResources` API with `sharedResources` API
* Test APIs of recommendation and migration infrastructure
* Update `docker-compose.yaml `
* Update API docs
  • Loading branch information
yunkon-kim committed Sep 9, 2024
1 parent 07662af commit 46ccf2a
Show file tree
Hide file tree
Showing 10 changed files with 427 additions and 1,466 deletions.
665 changes: 131 additions & 534 deletions api/docs.go

Large diffs are not rendered by default.

665 changes: 131 additions & 534 deletions api/swagger.json

Large diffs are not rendered by default.

476 changes: 110 additions & 366 deletions api/swagger.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions deployments/docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ networks:
services:
# cm-beetle
cm-beetle:
image: cloudbaristaorg/cm-beetle:0.2.0
image: cloudbaristaorg/cm-beetle:0.2.1
container_name: cm-beetle
pull_policy: missing
build:
Expand Down Expand Up @@ -55,7 +55,7 @@ services:

# CB-Tumblebug
cb-tumblebug:
image: cloudbaristaorg/cb-tumblebug:0.9.10
image: cloudbaristaorg/cb-tumblebug:0.9.11
container_name: cb-tumblebug
# build:
# context: .
Expand Down
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ module github.com/cloud-barista/cm-beetle

go 1.23.0

// Keep this for cm-model contributors
// replace github.com/cloud-barista/cm-model => ../cm-model

require (
github.com/cloud-barista/cb-tumblebug v0.9.10
github.com/cloud-barista/cm-honeybee/agent v0.0.0-20240704080504-526db6b80b90
github.com/cloud-barista/cb-tumblebug v0.9.11
github.com/cloud-barista/cm-model v0.0.1
github.com/fsnotify/fsnotify v1.7.0
github.com/go-playground/validator/v10 v10.22.0
github.com/go-resty/resty/v2 v2.13.1
Expand Down Expand Up @@ -70,5 +73,7 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/gc/v3 v3.0.0-20240304020402-f0dba7c97c2b // indirect
modernc.org/libc v1.50.9 // indirect
modernc.org/sqlite v1.29.10 // indirect
xorm.io/builder v0.3.13 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGq
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/cloud-barista/cb-tumblebug v0.9.10 h1:mnXLczjwi6FMwmrZ0n1LMdvFfDFKbz9MJp3jHDJ78Zk=
github.com/cloud-barista/cb-tumblebug v0.9.10/go.mod h1:uXi+JmmdU+cqcIqpMgfomzZNbNdrLQ+WZgK9ZlOGjY0=
github.com/cloud-barista/cm-honeybee/agent v0.0.0-20240704080504-526db6b80b90 h1:qGFG4sMqwKw06Y0ZzK4L2Bm6M/WHNnLQGZ3r6qUAhR8=
github.com/cloud-barista/cm-honeybee/agent v0.0.0-20240704080504-526db6b80b90/go.mod h1:+h6UB1Z2qrpfizIillcppLuh8zRlmjLSpkl63XGi1Wc=
github.com/cloud-barista/cb-tumblebug v0.9.11 h1:PLqQ+OD4+Nec1xTHJ3Qde7C74t2XiY5D43UemMg838A=
github.com/cloud-barista/cb-tumblebug v0.9.11/go.mod h1:uXi+JmmdU+cqcIqpMgfomzZNbNdrLQ+WZgK9ZlOGjY0=
github.com/cloud-barista/cm-model v0.0.1 h1:tcj5KHacQYuoLgvcuFoA+Cp23pbQg1xoAYNGtVRJXiU=
github.com/cloud-barista/cm-model v0.0.1/go.mod h1:gSuMhQxD813KIdSvkp8uGptYOeyDik749sYcICZjhj8=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
15 changes: 15 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ github.com/cloud-barista/cb-tumblebug v0.0.0-20230724172618-8f225d0127e8/go.mod
github.com/cloud-barista/cm-beetle/src v0.0.0-20230724172618-8f225d0127e8/go.mod h1:XQuz7L64MNUu04FmG5gB0z41VcrfaLuQP80EGyQTDgo=
github.com/cloud-barista/cm-honeybee v0.1.3 h1:G9Gb2NiiDtw9nRn7v56bpUM5FEfyBYJ8kgIKxZJZSkI=
github.com/cloud-barista/cm-honeybee v0.1.3/go.mod h1:A0Qm1CY4O1hAMxDRnEWjXACztP2D2y/U9GNNJvYzyzM=
github.com/cloud-barista/cm-model v0.0.0-20240909022259-4ca4411340d6 h1:lxU1vjbUW3W3be+WTI91WX4KrXD5cDmBMFAvUhqh9cQ=
github.com/cloud-barista/cm-model v0.0.0-20240909022259-4ca4411340d6/go.mod h1:GRtJ+4HdzKwfZySj9/99fnmyfFeaoyA2P+NKvTtFNUY=
github.com/cloud-barista/mc-terrarium v0.0.6-0.20240516045927-43023b6a0e18/go.mod h1:qey9GFrJidyJ3tVfeL/gcImgWLqsF64j/fVmBfaddDI=
github.com/cloud-barista/mc-terrarium v0.0.7/go.mod h1:qey9GFrJidyJ3tVfeL/gcImgWLqsF64j/fVmBfaddDI=
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
Expand Down Expand Up @@ -366,6 +368,7 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg=
github.com/google/pprof v0.0.0-20230323073829-e72429f035bd/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk=
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
github.com/google/s2a-go v0.1.3/go.mod h1:Ej+mSEMGRnqRzjc7VtF+jdBwYG5fuJfiZ8ELkjEwM0A=
github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -408,6 +411,7 @@ github.com/jollaman999/utils v1.0.10/go.mod h1:fb4x+o0k105MFIBBaNRN+tat7F3Rbkoln
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knqyf263/go-rpmdb v0.0.0-20231206071317-a8af76a6220f/go.mod h1:9LQcoMCMQ9vrF7HcDtXfvqGO4+ddxFQ8+YF/0CVGDww=
github.com/knqyf263/go-rpmdb v0.1.0/go.mod h1:9LQcoMCMQ9vrF7HcDtXfvqGO4+ddxFQ8+YF/0CVGDww=
github.com/knqyf263/go-rpmdb v0.1.1/go.mod h1:9LQcoMCMQ9vrF7HcDtXfvqGO4+ddxFQ8+YF/0CVGDww=
Expand Down Expand Up @@ -520,14 +524,18 @@ go.etcd.io/etcd/client/v2 v2.305.12/go.mod h1:aQ/yhsxMu+Oht1FOupSr60oBvcS9cKXHrz
go.etcd.io/etcd/client/v3 v3.5.12/go.mod h1:tSbBCakoWmmddL+BKVAJHa9km+O/E+bumDe9mSbPiqw=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0/go.mod h1:Mjt1i1INqiaoZOMGR1RIUJN+i3ChKoFRqzrRQhlkbs0=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0/go.mod h1:vy+2G/6NvVMpwGX/NyLqcC41fxepnuKHk16E6IZUcJc=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0/go.mod h1:XLZfZboOJWHNKUv7eH0inh0E9VV6eWDFB/9yJyTLPp0=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel v1.26.0/go.mod h1:UmLkJHUAidDval2EICqBMbnAd0/m2vmpf/dAM+fvFs4=
go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.22.0/go.mod h1:hYwym2nDEeZfG/motx0p7L7J1N1vyzIThemQsb4g2qY=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
go.opentelemetry.io/otel/metric v1.26.0/go.mod h1:SY+rHOI4cEawI9a7N1A4nIg/nTQXe1ccCNWYOJUrpX4=
go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak=
go.opentelemetry.io/otel/sdk v1.22.0/go.mod h1:iu7luyVGYovrRpe2fmj3CVKouQNdTOkxtLzPvPz1DOc=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
go.opentelemetry.io/otel/trace v1.26.0/go.mod h1:4iDxvGDQuUkHve82hJJ8UqrwswHYsZuWCBllGV2U2y0=
go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
Expand Down Expand Up @@ -583,8 +591,15 @@ howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=
howett.net/plist v1.0.1/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=
lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
modernc.org/cc/v3 v3.40.0/go.mod h1:/bTg4dnWkSXowUO6ssQKnOV0yMVxDYNIsIrzqTFDGH0=
modernc.org/cc/v3 v3.41.0/go.mod h1:Ni4zjJYJ04CDOhG7dn640WGfwBzfE0ecX8TyMB0Fv0Y=
modernc.org/cc/v4 v4.21.2/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ=
modernc.org/ccgo/v3 v3.16.13/go.mod h1:2Quk+5YgpImhPjv2Qsob1DnZ/4som1lJTodubIcoUkY=
modernc.org/ccgo/v3 v3.17.0/go.mod h1:Sg3fwVpmLvCUTaqEUjiBDAvshIaKDB0RXaf+zgqFu8I=
modernc.org/ccgo/v4 v4.17.8/go.mod h1:buJnJ6Fn0tyAdP/dqePbrrvLyr6qslFfTbFrCuaYvtA=
modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ=
modernc.org/gc/v2 v2.4.1/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU=
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss=
pault.ag/go/modprobe v0.1.2/go.mod h1:afr2STC/2Maz/qi4+Bma1s0dszZgO/PcM8AKar9DWhM=
pault.ag/go/topsort v0.1.1/go.mod h1:r1kc/L0/FZ3HhjezBIPaNVhkqv8L0UJ9bxRuHRVZ0q4=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
8 changes: 5 additions & 3 deletions pkg/api/rest/controller/recommendation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
// cloudmodel "github.com/cloud-barista/cm-beetle/pkg/api/rest/model/cloud/infra"
// "github.com/cloud-barista/cm-beetle/pkg/api/rest/model/onprem/infra"

"github.com/cloud-barista/cm-honeybee/agent/pkg/api/rest/model/onprem/infra"
// "github.com/cloud-barista/cm-honeybee/agent/pkg/api/rest/model/onprem/infra"
onprem "github.com/cloud-barista/cm-model/infra/onprem"

"github.com/cloud-barista/cm-beetle/pkg/core/common"
"github.com/cloud-barista/cm-beetle/pkg/core/recommendation"
Expand All @@ -38,7 +39,8 @@ import (
// }

type RecommendInfraRequest struct {
Servers []infra.Infra `json:"servers" validate:"required"`
// Servers []infra.Infra `json:"servers" validate:"required"`
onprem.OnPremInfra
}

type RecommendInfraResponse struct {
Expand Down Expand Up @@ -70,7 +72,7 @@ func RecommendInfra(c echo.Context) error {
log.Trace().Msgf("req: %v\n", req)

// Process
recommendedInfraInfo, err := recommendation.Recommend(req.Servers)
recommendedInfraInfo, err := recommendation.Recommend(req.OnPremInfra)
recommendedInfraInfo.TargetInfra.Name = "mmci01"

// Ouput
Expand Down
10 changes: 5 additions & 5 deletions pkg/core/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ func DeleteVMInfra(nsId, infraId string) (common.SimpleMsg, error) {

// delete the infrastructure with terminate option
method = "DELETE"
url = fmt.Sprintf("%s/ns/%s/defaultResources", epTumblebug, nsId)
options = ""
if options != "" {
url += "?" + options
}
url = fmt.Sprintf("%s/ns/%s/sharedResources", epTumblebug, nsId)
// options = ""
// if options != "" {
// url += "?" + options
// }

// Set request body
requestBody = common.NoBody
Expand Down
33 changes: 17 additions & 16 deletions pkg/core/recommendation/recommendation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import (

// cloudmodel "github.com/cloud-barista/cm-beetle/pkg/api/rest/model/cloud/infra"

"github.com/cloud-barista/cm-honeybee/agent/pkg/api/rest/model/onprem/infra"
// "github.com/cloud-barista/cm-honeybee/agent/pkg/api/rest/model/onprem/infra"
// "github.com/cloud-barista/cm-beetle/pkg/api/rest/model/onprem/infra"

onprem "github.com/cloud-barista/cm-model/infra/onprem"

"github.com/cloud-barista/cm-beetle/pkg/config"
"github.com/cloud-barista/cm-beetle/pkg/core/common"
"github.com/cloud-barista/cm-beetle/pkg/similarity"
"github.com/go-resty/resty/v2"
"github.com/rs/zerolog/log"
)

func Recommend(srcInfra []infra.Infra) (RecommendedInfraInfo, error) {
func Recommend(srcInfra onprem.OnPremInfra) (RecommendedInfraInfo, error) {

var emptyResp RecommendedInfraInfo
var recommendedInfraInfo RecommendedInfraInfo
Expand Down Expand Up @@ -103,7 +105,7 @@ func Recommend(srcInfra []infra.Infra) (RecommendedInfraInfo, error) {
}`

// Recommand VMs
for _, server := range srcInfra {
for _, server := range srcInfra.Servers {

// Set VM info
recommendedVm := tbmodel.TbVmDynamicReq{
Expand All @@ -112,7 +114,7 @@ func Recommend(srcInfra []infra.Infra) (RecommendedInfraInfo, error) {
CommonSpec: "", // Search and set an appropriate VM spec
Description: "a recommended virtual machine",
Label: "rehosted-vm",
Name: fmt.Sprintf("rehosted-%s", server.Compute.OS.Node.Hostname),
Name: fmt.Sprintf("rehosted-%s", server.Hostname),
RootDiskSize: "", // TBD
RootDiskType: "", // TBD
SubGroupSize: "",
Expand All @@ -124,11 +126,11 @@ func Recommend(srcInfra []infra.Infra) (RecommendedInfraInfo, error) {
*/

// Extract server info from source computing infra info
cores := server.Compute.ComputeResource.CPU.Cores
memory := MBtoGiB(float64(server.Compute.ComputeResource.Memory.Size))
cores := server.CPU.Cores
memory := MBtoGiB(float64(server.Memory.TotalSize))

coresMax := cores << 1
var coresMin uint
var coresMin uint32
if cores > 1 {
coresMin = cores >> 1
} else {
Expand All @@ -146,13 +148,12 @@ func Recommend(srcInfra []infra.Infra) (RecommendedInfraInfo, error) {
providerName := "aws"
regionName := "ap-northeast-2"

osVendor := server.Compute.OS.OS.Vendor
osVersion := server.Compute.OS.OS.Release
osNameWithVersion := strings.ToLower(osVendor + osVersion)
osNameAndVersion := server.OS.Name + " " + server.OS.Version
osNameWithVersion := strings.ToLower(osNameAndVersion)

log.Debug().
Uint("coreLowerLimit", coresMin).
Uint("coreUpperLimit", coresMax).
Uint32("coreLowerLimit", coresMin).
Uint32("coreUpperLimit", coresMax).
Uint32("memoryLowerLimit (GiB)", memoryMin).
Uint32("memoryUpperLimit (GiB)", memoryMax).
Str("providerName", providerName).
Expand Down Expand Up @@ -265,10 +266,10 @@ func Recommend(srcInfra []infra.Infra) (RecommendedInfraInfo, error) {
}

keywords := fmt.Sprintf("%s %s %s %s",
server.Compute.OS.OS.Vendor,
server.Compute.OS.OS.Version,
server.Compute.OS.OS.Architecture,
server.Compute.ComputeResource.RootDisk.Type)
server.OS.Name,
server.OS.Version,
server.CPU.Architecture,
server.RootDisk.Type)
log.Debug().Msg("keywords for the VM OS image recommendation: " + keywords)

// Select VM OS image via LevenshteinDistance-based text similarity
Expand Down

0 comments on commit 46ccf2a

Please sign in to comment.