diff --git a/pkg/operator/api/userconfig/apis.go b/pkg/operator/api/userconfig/apis.go index 3421c9f742..a7b5a79490 100644 --- a/pkg/operator/api/userconfig/apis.go +++ b/pkg/operator/api/userconfig/apis.go @@ -206,9 +206,9 @@ func (api *API) UserConfigStr() string { return sb.String() } -func (apis APIs) Validate() error { +func (apis APIs) Validate(projectFileMap map[string][]byte) error { for _, api := range apis { - if err := api.Validate(); err != nil { + if err := api.Validate(projectFileMap); err != nil { return err } } @@ -226,7 +226,7 @@ func (apis APIs) Validate() error { return nil } -func (api *API) Validate() error { +func (api *API) Validate(projectFileMap map[string][]byte) error { awsClient, err := aws.NewFromS3Path(api.Model, false) if err != nil { return err @@ -269,6 +269,12 @@ func (api *API) Validate() error { return errors.Wrap(ErrorTFServingOptionsForTFOnly(api.ModelFormat), Identify(api)) } + if api.RequestHandler != nil { + if _, ok := projectFileMap[*api.RequestHandler]; !ok { + return errors.Wrap(ErrorImplDoesNotExist(*api.RequestHandler), Identify(api), RequestHandlerKey) + } + } + if err := api.Compute.Validate(); err != nil { return errors.Wrap(err, Identify(api), ComputeKey) } diff --git a/pkg/operator/api/userconfig/config.go b/pkg/operator/api/userconfig/config.go index 6b5f3d158c..2be02c1a0c 100644 --- a/pkg/operator/api/userconfig/config.go +++ b/pkg/operator/api/userconfig/config.go @@ -22,6 +22,7 @@ import ( cr "github.com/cortexlabs/cortex/pkg/lib/configreader" "github.com/cortexlabs/cortex/pkg/lib/errors" "github.com/cortexlabs/cortex/pkg/lib/files" + "github.com/cortexlabs/cortex/pkg/lib/zip" "github.com/cortexlabs/cortex/pkg/operator/api/resource" ) @@ -35,13 +36,18 @@ var typeFieldValidation = &cr.StructFieldValidation{ Nil: true, } -func (config *Config) Validate() error { +func (config *Config) Validate(projectBytes []byte) error { if err := config.App.Validate(); err != nil { return err } + projectFileMap, err := zip.UnzipMemToMem(projectBytes) + if err != nil { + return err + } + if config.APIs != nil { - if err := config.APIs.Validate(); err != nil { + if err := config.APIs.Validate(projectFileMap); err != nil { return err } } @@ -49,7 +55,7 @@ func (config *Config) Validate() error { return nil } -func New(filePath string, configBytes []byte, validate bool) (*Config, error) { +func New(filePath string, configBytes []byte) (*Config, error) { var err error configData, err := cr.ReadYAMLBytes(configBytes) @@ -109,11 +115,6 @@ func New(filePath string, configBytes []byte, validate bool) (*Config, error) { return nil, ErrorMissingAppDefinition() } - if validate { - if err := config.Validate(); err != nil { - return nil, err - } - } return config, nil } @@ -123,7 +124,7 @@ func ReadAppName(filePath string, relativePath string) (string, error) { return "", errors.Wrap(err, relativePath, ErrorReadConfig().Error()) } - config, err := New(relativePath, configBytes, false) + config, err := New(relativePath, configBytes) if err != nil { return "", err } diff --git a/pkg/operator/context/apis.go b/pkg/operator/context/apis.go index 1cb0c1698b..5af9f79dd4 100644 --- a/pkg/operator/context/apis.go +++ b/pkg/operator/context/apis.go @@ -36,9 +36,13 @@ func getAPIs(config *userconfig.Config, deploymentVersion string, projectID stri buf.WriteString(s.Obj(apiConfig.Tracker)) buf.WriteString(apiConfig.ModelFormat.String()) buf.WriteString(deploymentVersion) - buf.WriteString(projectID) buf.WriteString(strings.TrimSuffix(apiConfig.Model, "/")) + if apiConfig.RequestHandler != nil { + buf.WriteString(projectID) + buf.WriteString(*apiConfig.RequestHandler) + } + id := hash.Bytes(buf.Bytes()) apis[apiConfig.Name] = &context.API{ diff --git a/pkg/operator/context/context.go b/pkg/operator/context/context.go index 0ecc1dd0ce..d145f5dfd7 100644 --- a/pkg/operator/context/context.go +++ b/pkg/operator/context/context.go @@ -60,6 +60,7 @@ func New( ) ctx.ProjectID = hash.Bytes(projectBytes) + ctx.ProjectKey = filepath.Join(consts.ProjectsDir, ctx.ProjectID+".zip") if err = config.AWS.UploadBytesToS3(projectBytes, ctx.ProjectKey); err != nil { return nil, err diff --git a/pkg/operator/endpoints/deploy.go b/pkg/operator/endpoints/deploy.go index 00d3279916..9dda4cbe5a 100644 --- a/pkg/operator/endpoints/deploy.go +++ b/pkg/operator/endpoints/deploy.go @@ -47,15 +47,21 @@ func Deploy(w http.ResponseWriter, r *http.Request) { return } - userconf, err := userconfig.New("cortex.yaml", configBytes, true) + projectBytes, err := files.ReadReqFile(r, "project.zip") + if err != nil { + RespondError(w, errors.WithStack(err)) + return + } + + userconf, err := userconfig.New("cortex.yaml", configBytes) if err != nil { RespondError(w, err) return } - projectBytes, err := files.ReadReqFile(r, "project.zip") + err = userconf.Validate(projectBytes) if err != nil { - RespondError(w, errors.WithStack(err)) + RespondError(w, err) return }