Skip to content

Commit

Permalink
sdl: lookup pricing by compute profile name
Browse files Browse the repository at this point in the history
 * add `akash deployment validate <deployment.yml>`
 * use micro akash instead of milli akash

fixes #339
  • Loading branch information
boz committed Jul 31, 2018
1 parent 16ad5d5 commit 1474fe3
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 21 deletions.
13 changes: 6 additions & 7 deletions _docs/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
9 changes: 5 additions & 4 deletions _integration/cmp/account.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmp

import (
"strconv"
"fmt"

"github.com/ovrclk/gestalt"
g "github.com/ovrclk/gestalt/builder"
Expand All @@ -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()))
}

Expand All @@ -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))
}
2 changes: 1 addition & 1 deletion _run/kube/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ profiles:
attributes:
region: us-west
pricing:
web: .101
web: .002000

deployment:
web:
Expand Down
2 changes: 1 addition & 1 deletion _run/multi/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ profiles:
attributes:
region: us-west
pricing:
web: .1
web: .000100

deployment:
web:
Expand Down
21 changes: 21 additions & 0 deletions cmd/akash/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func deploymentCommand() *cobra.Command {
cmd.AddCommand(closeDeploymentCommand())
cmd.AddCommand(statusDeploymentCommand())
cmd.AddCommand(sendManifestCommand())
cmd.AddCommand(validateDeploymentCommand())

return cmd
}
Expand Down Expand Up @@ -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 <deployment-file>",
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 {
Expand Down
4 changes: 2 additions & 2 deletions denom/denom.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

const (
miliAkashPerAkash = 1000
microAkashPerAkash = 1000000
)

// ToBase converts a unit of currency to its equivalent value in base denomination
Expand All @@ -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
}
30 changes: 30 additions & 0 deletions sdl/_testdata/profile-svc-name-mismatch.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion sdl/_testdata/simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ profiles:
attributes:
region: us-west
pricing:
web: .8
web: 0.005000

deployment:
web:
Expand Down
4 changes: 2 additions & 2 deletions sdl/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 14 additions & 1 deletion sdl/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
6 changes: 4 additions & 2 deletions validation/pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 1474fe3

Please sign in to comment.