Skip to content

Commit

Permalink
validation: validate resources and groups
Browse files Browse the repository at this point in the history
  • Loading branch information
boz committed Jul 30, 2018
1 parent 7e3e1b5 commit 6aa9641
Show file tree
Hide file tree
Showing 16 changed files with 408 additions and 231 deletions.
5 changes: 3 additions & 2 deletions app/deployment/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
appstate "github.com/ovrclk/akash/state"
"github.com/ovrclk/akash/types"
"github.com/ovrclk/akash/types/code"
"github.com/ovrclk/akash/validation"
tmtypes "github.com/tendermint/abci/types"
"github.com/tendermint/tmlibs/log"
)
Expand Down Expand Up @@ -245,10 +246,10 @@ func (a *app) doCheckCreateTx(state appstate.State, ctx apptypes.Context, tx *ty
}
}

if len(tx.Groups) == 0 {
if err := validation.ValidateGroupSpecs(tx.Groups); err != nil {
return tmtypes.ResponseCheckTx{
Code: code.INVALID_TRANSACTION,
Log: "No groups in deployment",
Log: err.Error(),
}
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/akash/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/ovrclk/akash/txutil"
"github.com/ovrclk/akash/types"
. "github.com/ovrclk/akash/util"
"github.com/ovrclk/akash/validation"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -375,7 +376,7 @@ func manifestValidateResources(session session.Session, mani *types.Manifest, da
if err != nil {
return err
}
return manifest.ValidateWithDeployment(mani, dgroups.Items)
return validation.ValidateManifestWithDeployment(mani, dgroups.Items)
}

func doSendManifest(session session.Session, signer txutil.Signer, daddr []byte, mani *types.Manifest) error {
Expand Down
76 changes: 0 additions & 76 deletions manifest/validate.go

This file was deleted.

4 changes: 2 additions & 2 deletions provider/bidengine/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package bidengine

type config struct {
FulfillmentCPUMax int64 `env:"AKASH_FULFILLMENT_CPU_MAX" envDefault:"1000"`
FulfillmentCPUMax int64 `env:"AKASH_FULFILLMENT_CPU_MAX" envDefault:"1000"`
FulfillmentMemoryMax int64 `env:"AKASH_FULFILLMENT_MEMORY_MAX" envDefault:"1073741824"` // 1Gi
FulfillmentDiskMax int64 `env:"AKASH_FULFILLMENT_DISK_MAX" envDefault:"5368709120"` // 5Gi
FulfillmentDiskMax int64 `env:"AKASH_FULFILLMENT_DISK_MAX" envDefault:"5368709120"` // 5Gi

FulfillmentMemPriceMin int64 `env:"AKASH_MEM_PRICE_MIN" envDefault:"50"`
FulfillmentMemPriceMax int64 `env:"AKASH_MEM_PRICE_MAX" envDefault:"150"`
Expand Down
8 changes: 8 additions & 0 deletions provider/manifest/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ovrclk/akash/types"
"github.com/ovrclk/akash/types/base"
"github.com/ovrclk/akash/util/runner"
"github.com/ovrclk/akash/validation"
)

var ErrNotRunning = errors.New("not running")
Expand Down Expand Up @@ -171,6 +172,13 @@ loop:

case req := <-h.mreqch:

if err := validation.ValidateManifest(req.value.Manifest); err != nil {
h.session.Log().Error("manifest validation failed",
"err", err, "deployment", req.value.Deployment)
req.ch <- err
break
}

manager, err := h.ensureManger(req.value.Deployment)
if err != nil {
h.session.Log().Error("error fetching manager for manifest",
Expand Down
3 changes: 2 additions & 1 deletion provider/manifest/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ovrclk/akash/types"
"github.com/ovrclk/akash/types/base"
"github.com/ovrclk/akash/util/runner"
"github.com/ovrclk/akash/validation"
)

func newManager(h *handler, daddr base.Bytes) (*manager, error) {
Expand Down Expand Up @@ -309,7 +310,7 @@ func (m *manager) validateRequests() {
}

func (m *manager) validateRequest(req manifestRequest) error {
if err := mutil.ValidateWithDeployment(req.value.Manifest, m.data.dgroups); err != nil {
if err := validation.ValidateManifestWithDeployment(req.value.Manifest, m.data.dgroups); err != nil {
return err
}
return mutil.VerifyRequest(req.value, m.data.deployment)
Expand Down
27 changes: 26 additions & 1 deletion sdl/sdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"

"github.com/ovrclk/akash/types"
"github.com/ovrclk/akash/validation"
yaml "gopkg.in/yaml.v2"
)

Expand All @@ -27,5 +28,29 @@ func Read(buf []byte) (SDL, error) {
if err := yaml.Unmarshal(buf, obj); err != nil {
return nil, err
}
return obj, obj.Validate()

if err := obj.Validate(); err != nil {
return nil, err
}

dgroups, err := obj.DeploymentGroups()
if err != nil {
return nil, err
}
if err := validation.ValidateGroupSpecs(dgroups); err != nil {
return nil, err
}

m, err := obj.Manifest()
if err != nil {
return nil, err
}
if err := validation.ValidateManifest(m); err != nil {
return nil, err
}
if err := validation.ValidateManifestWithGroupSpecs(m, dgroups); err != nil {
return nil, err
}

return obj, nil
}
7 changes: 0 additions & 7 deletions sdl/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ func (sdl *v1) Validate() error {
return fmt.Errorf("invalid version: '%v' required", allowedVersion)
}

if _, err := sdl.Manifest(); err != nil {
return err
}

if _, err := sdl.DeploymentGroups(); err != nil {
return err
}
return nil
}

Expand Down
1 change: 1 addition & 0 deletions testutil/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func CreateDeployment(t *testing.T, st state.State, app apptypes.Application, ac

for _, group := range groups.GetItems() {
s := &types.GroupSpec{
Name: group.Name,
Resources: group.Resources,
Requirements: group.Requirements,
}
Expand Down
Loading

0 comments on commit 6aa9641

Please sign in to comment.