From 1474fe3bb6390ac2f5cb7d5ab7409d29062f526e Mon Sep 17 00:00:00 2001 From: Adam Bozanich Date: Mon, 30 Jul 2018 16:54:26 -0700 Subject: [PATCH] sdl: lookup pricing by compute profile name * add `akash deployment validate ` * use micro akash instead of milli akash fixes #339 --- _docs/deployment.yml | 13 +++++---- _integration/cmp/account.go | 9 ++++--- _run/kube/deployment.yml | 2 +- _run/multi/deployment.yml | 2 +- cmd/akash/deployment.go | 21 +++++++++++++++ denom/denom.go | 4 +-- sdl/_testdata/profile-svc-name-mismatch.yml | 30 +++++++++++++++++++++ sdl/_testdata/simple.yml | 2 +- sdl/v1.go | 4 +-- sdl/v1_test.go | 15 ++++++++++- validation/pricing.go | 6 +++-- 11 files changed, 87 insertions(+), 21 deletions(-) create mode 100644 sdl/_testdata/profile-svc-name-mismatch.yml diff --git a/_docs/deployment.yml b/_docs/deployment.yml index 92d1d19255..e9cf7551a4 100644 --- a/_docs/deployment.yml +++ b/_docs/deployment.yml @@ -74,17 +74,16 @@ profiles: attributes: region: us-west pricing: - web: .001 - db-master: 0.05 - db-slave: 0.05 - db-pool: 0.03 + web: 0.000010 + db: 0.000050 + db-pool: 0.000030 eastcoast: attributes: region: us-east pricing: - web: .003 - db-slave: 0.06 - db-pool: 0.04 + web: 0.000030 + db: 0.000060 + db-pool: 0.000040 deployment: diff --git a/_integration/cmp/account.go b/_integration/cmp/account.go index ae4ce344c1..4972aac1ff 100644 --- a/_integration/cmp/account.go +++ b/_integration/cmp/account.go @@ -1,7 +1,7 @@ package cmp import ( - "strconv" + "fmt" "github.com/ovrclk/gestalt" g "github.com/ovrclk/gestalt/builder" @@ -18,8 +18,9 @@ func accountBalance(key key, amount int64) gestalt.Component { } func accountSendTo(from key, to key, amount int64) gestalt.Component { + value := fmt.Sprintf("%0.06f", float64(amount)/float64(1000000)) return akash("send-to", - "send", strconv.FormatInt(amount, 10), to.addr.Var(), "-k", from.name.Name()). + "send", value, to.addr.Var(), "-k", from.name.Name()). WithMeta(g.Require(to.addr.Name())) } @@ -32,6 +33,6 @@ func groupAccountSend(key key) gestalt.Component { Run(accountBalance(key, start)). Run(accountSendTo(key, other, amount)). Run(g.Retry(5). - Run(accountBalance(key, start-1000*amount))). - Run(accountBalance(other, 1000*amount)) + Run(accountBalance(key, start-amount))). + Run(accountBalance(other, amount)) } diff --git a/_run/kube/deployment.yml b/_run/kube/deployment.yml index a36e6b7de1..338c5ec092 100644 --- a/_run/kube/deployment.yml +++ b/_run/kube/deployment.yml @@ -24,7 +24,7 @@ profiles: attributes: region: us-west pricing: - web: .101 + web: .002000 deployment: web: diff --git a/_run/multi/deployment.yml b/_run/multi/deployment.yml index 69ebce83f0..3545886e27 100644 --- a/_run/multi/deployment.yml +++ b/_run/multi/deployment.yml @@ -24,7 +24,7 @@ profiles: attributes: region: us-west pricing: - web: .1 + web: .000100 deployment: web: diff --git a/cmd/akash/deployment.go b/cmd/akash/deployment.go index 502ebbd044..f1069d33bf 100644 --- a/cmd/akash/deployment.go +++ b/cmd/akash/deployment.go @@ -32,6 +32,7 @@ func deploymentCommand() *cobra.Command { cmd.AddCommand(closeDeploymentCommand()) cmd.AddCommand(statusDeploymentCommand()) cmd.AddCommand(sendManifestCommand()) + cmd.AddCommand(validateDeploymentCommand()) return cmd } @@ -371,6 +372,26 @@ func sendManifest(session session.Session, cmd *cobra.Command, args []string) er return doSendManifest(session, signer, depAddr.ID(), mani) } +func validateDeploymentCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "validate ", + Short: "validate deployment file", + Args: cobra.ExactArgs(1), + RunE: session.WithSession(doValidateDeploymentCommand), + } + + return cmd +} + +func doValidateDeploymentCommand(session session.Session, cmd *cobra.Command, args []string) error { + _, err := sdl.ReadFile(args[0]) + if err != nil { + return err + } + fmt.Println("ok") + return nil +} + func manifestValidateResources(session session.Session, mani *types.Manifest, daddr []byte) error { dgroups, err := session.QueryClient().DeploymentGroupsForDeployment(session.Ctx(), daddr) if err != nil { diff --git a/denom/denom.go b/denom/denom.go index 788929f12f..7f30fad1ca 100644 --- a/denom/denom.go +++ b/denom/denom.go @@ -5,7 +5,7 @@ import ( ) const ( - miliAkashPerAkash = 1000 + microAkashPerAkash = 1000000 ) // ToBase converts a unit of currency to its equivalent value in base denomination @@ -14,6 +14,6 @@ func ToBase(sval string) (uint64, error) { if err != nil { return 0, err } - amount := akash * miliAkashPerAkash + amount := akash * microAkashPerAkash return uint64(amount), nil } diff --git a/sdl/_testdata/profile-svc-name-mismatch.yml b/sdl/_testdata/profile-svc-name-mismatch.yml new file mode 100644 index 0000000000..ce48c7960a --- /dev/null +++ b/sdl/_testdata/profile-svc-name-mismatch.yml @@ -0,0 +1,30 @@ +--- +version: "1.0" + +services: + webapp: + image: quay.io/ovrclk/demo-app + expose: + - port: 80 + as: 80 + to: + - global: true + +profiles: + compute: + web: + cpu: "100m" + memory: "512Mi" + disk: "512Mi" + placement: + san-jose: + attributes: + region: sjc + pricing: + web: 0.000025 + +deployment: + webapp: + san-jose: + profile: web + count: 1 diff --git a/sdl/_testdata/simple.yml b/sdl/_testdata/simple.yml index 27ad108316..aa2f6437bd 100644 --- a/sdl/_testdata/simple.yml +++ b/sdl/_testdata/simple.yml @@ -22,7 +22,7 @@ profiles: attributes: region: us-west pricing: - web: .8 + web: 0.005000 deployment: web: diff --git a/sdl/v1.go b/sdl/v1.go index 3ecbe826cf..7630e0687c 100644 --- a/sdl/v1.go +++ b/sdl/v1.go @@ -119,9 +119,9 @@ func (sdl *v1) DeploymentGroups() ([]*types.GroupSpec, error) { return nil, fmt.Errorf("%v.%v: no placement profile named %v", svcName, placementName, placementName) } - price, ok := infra.Pricing[svcName] + price, ok := infra.Pricing[svcdepl.Profile] if !ok { - return nil, fmt.Errorf("%v.%v: no pricing for service %v", svcName, placementName, svcName) + return nil, fmt.Errorf("%v.%v: no pricing for profile %v", svcName, placementName, svcdepl.Profile) } group := groups[placementName] diff --git a/sdl/v1_test.go b/sdl/v1_test.go index 776bfd5615..1bff35a6d5 100644 --- a/sdl/v1_test.go +++ b/sdl/v1_test.go @@ -40,7 +40,7 @@ func Test_v1_Parse_simple(t *testing.T) { assert.Equal(t, types.ResourceGroup{ Count: 2, - Price: 800, + Price: 0x1388, Unit: types.ResourceUnit{ CPU: 100, Memory: 128 * unit.Mi, @@ -73,3 +73,16 @@ func Test_v1_Parse_simple(t *testing.T) { }, mani.GetGroups()[0]) } + +func Test_v1_Parse_ProfileNameNotServiceName(t *testing.T) { + sdl, err := sdl.ReadFile("./_testdata/profile-svc-name-mismatch.yml") + require.NoError(t, err) + + dgroups, err := sdl.DeploymentGroups() + require.NoError(t, err) + assert.Len(t, dgroups, 1) + + mani, err := sdl.Manifest() + require.NoError(t, err) + assert.Len(t, mani.Groups, 1) +} diff --git a/validation/pricing.go b/validation/pricing.go index 278fdeaed4..67af377508 100644 --- a/validation/pricing.go +++ b/validation/pricing.go @@ -21,9 +21,11 @@ func validateResourceListPricing(config config, rlist types.ResourceList) error price += int64(resource.Price * uint64(resource.Count)) } - if price*unit.Gi < mem*config.MinGroupMemPrice { + minprice := int64(float64(mem*config.MinGroupMemPrice) / float64(unit.Gi)) + + if price < minprice { return fmt.Errorf("group %v: price too low (%v >= %v fails)", - rlist.GetName(), price*unit.Gi, mem*config.MinGroupMemPrice) + rlist.GetName(), price, minprice) } return nil }