Skip to content

Commit fa227d1

Browse files
committed
Remove region from external data
1 parent 2b5f8e7 commit fa227d1

32 files changed

+924
-719
lines changed

cli/cmd/get.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323
"time"
2424

25+
"github.com/cortexlabs/yaml"
2526
"github.com/spf13/cobra"
2627

2728
"github.com/cortexlabs/cortex/pkg/lib/errors"
@@ -412,8 +413,8 @@ func describeAPI(name string, resourcesRes *schema.GetResourcesResponse) (string
412413
out += "Method: POST\n"
413414
out += `Header: "Content-Type: application/json"` + "\n"
414415

415-
if api.Model != nil {
416-
model := ctx.Models[api.ModelName]
416+
if modelName, ok := yaml.ExtractAtSymbolText(api.Model); ok {
417+
model := ctx.Models[modelName]
417418
resIDs := strset.New()
418419
combinedInput := []interface{}{model.Input, model.TrainingInput}
419420
for _, res := range ctx.ExtractCortexResources(combinedInput, resource.ConstantType, resource.RawColumnType, resource.AggregateType, resource.TransformedColumnType) {

docs/apis/apis.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ Serve models at scale and use them to build smarter applications.
77
```yaml
88
- kind: api
99
name: <string> # API name (required)
10-
external_model:
11-
path: <string> # path to a zipped model dir (e.g. s3://my-bucket/model.zip)
12-
region: <string> # S3 region (default: us-west-2)
10+
model: <string> # path to a zipped model dir (e.g. s3://my-bucket/model.zip)
1311
compute:
1412
replicas: <int> # number of replicas to launch (default: 1)
1513
cpu: <string> # CPU request per replica (default: Null)
@@ -24,9 +22,7 @@ See [packaging models](packaging-models.md) for how to create the zipped model.
2422
```yaml
2523
- kind: api
2624
name: my-api
27-
external_model:
28-
path: s3://my-bucket/my-model.zip
29-
region: us-west-2
25+
model: s3://my-bucket/my-model.zip
3026
compute:
3127
replicas: 3
3228
gpu: 2

docs/apis/packaging-models.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ Upload the zipped file to Amazon S3, e.g.
1717
$ aws s3 cp model.zip s3://my-bucket/model.zip
1818
```
1919

20-
Specify `external_model` in an API, e.g.
20+
Specify `model` in an API, e.g.
2121

2222
```yaml
2323
- kind: api
2424
name: my-api
25-
external_model:
26-
path: s3://my-bucket/model.zip
27-
region: us-west-2
25+
model: s3://my-bucket/model.zip
2826
```

docs/apis/tutorial.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ Add to `cortex.yaml`:
3232
```yaml
3333
- kind: api
3434
name: iris-type
35-
external_model:
36-
path: s3://cortex-examples/iris-tensorflow.zip
37-
region: us-west-2
35+
model: s3://cortex-examples/iris-tensorflow.zip
3836
compute:
3937
replicas: 3
4038
```

docs/pipelines/apis.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ Serve models at scale and use them to build smarter applications.
77
```yaml
88
- kind: api
99
name: <string> # API name (required)
10-
model: <string> # reference to a model (e.g. @dnn) (this or external_model must be specified)
11-
external_model: # (this or model must be specified)
12-
path: <string> # path to a zipped model dir (e.g. s3://my-bucket/model.zip)
13-
region: <string> # S3 region (default: us-west-2)
10+
model: <string> # reference to a model (e.g. @dnn) or path to a zipped model dir (e.g. s3://my-bucket/model.zip)
1411
compute:
1512
replicas: <int> # number of replicas to launch (default: 1)
1613
cpu: <string> # CPU request per replica (default: Null)
1714
gpu: <string> # gpu request per replica (default: Null)
1815
mem: <string> # memory request per replica (default: Null)
1916
```
2017
21-
See [packaging models](packaging-models.md) for how to create the zipped model (for use in `external_model`).
18+
See [packaging models](packaging-models.md) for how to create a zipped model (only if using an externally-built models).
2219
2320
## Example
2421

docs/pipelines/constants.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ Constants represent literal values which can be used in other Cortex resources.
88
- kind: constant
99
name: <string> # constant name (required)
1010
type: <output_type> # the type of the constant (optional, will be inferred from value if not specified)
11-
value: <output_value> # a literal value (this or external_model must be specified)
12-
external_model: # (this or value must be specified)
13-
path: <string> # path to a JSON object (e.g. s3://my-bucket/constant.json)
14-
region: <string> # S3 region (default: us-west-2)
11+
value: <output_value> # a literal value (this or path must be specified)
12+
path: <string> # path to a JSON object (e.g. s3://my-bucket/constant.json) (this or value must be specified)
1513

1614
```
1715

docs/pipelines/environments.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Transfer data at scale from data warehouses like S3 into the Cortex environment.
2626
data:
2727
type: csv # file type (required)
2828
path: s3a://<bucket_name>/<file_name> # S3 is currently supported (required)
29-
region: us-west-2 # S3 region (default: us-west-2)
3029
drop_null: <bool> # drop any rows that contain at least 1 null value (default: false)
3130
csv_config: <csv_config> # optional configuration that can be provided
3231
schema:
@@ -65,7 +64,6 @@ csv_config:
6564
data:
6665
type: parquet # file type (required)
6766
path: s3a://<bucket_name>/<file_name> # S3 is currently supported (required)
68-
region: us-west-2 # S3 region (default: us-west-2)
6967
drop_null: <bool> # drop any rows that contain at least 1 null value (default: false)
7068
schema:
7169
- parquet_column_name: <string> # name of the column in the parquet file (required)

docs/pipelines/packaging-models.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ Upload the zipped file to Amazon S3, e.g.
1717
$ aws s3 cp model.zip s3://my-bucket/model.zip
1818
```
1919

20-
Specify `external_model` in an API, e.g.
20+
Specify `model` in an API, e.g.
2121

2222
```yaml
2323
- kind: api
2424
name: my-api
25-
external_model:
26-
path: s3://my-bucket/model.zip
27-
region: us-west-2
25+
model: s3://my-bucket/model.zip
2826
```

examples/iris/cortex.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
- kind: api
55
name: iris-type
6-
external_model:
7-
path: s3://cortex-examples/iris-tensorflow.zip
8-
region: us-west-2
6+
model: s3://cortex-examples/iris-tensorflow.zip
97
compute:
108
replicas: 3

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// replace these lines in go.mod:
66
// github.com/GoogleCloudPlatform/spark-on-k8s-operator v1alpha1-0.5-2.4.0
77
// github.com/argoproj/argo v2.3.0
8-
// github.com/cortexlabs/yaml v2.2.3
8+
// github.com/cortexlabs/yaml v2.2.4
99
// k8s.io/client-go v10.0.0
1010
// k8s.io/api 89a74a8d264df0e993299876a8cde88379b940ee
1111
// k8s.io/apimachinery 2b1284ed4c93a43499e781493253e2ac5959c4fd
@@ -20,8 +20,8 @@ go 1.12
2020
require (
2121
github.com/GoogleCloudPlatform/spark-on-k8s-operator v0.0.0-20181208011959-62db1d66dafa
2222
github.com/argoproj/argo v2.3.0+incompatible
23-
github.com/aws/aws-sdk-go v1.20.7
24-
github.com/cortexlabs/yaml v0.0.0-20190624201412-7f31702857b6
23+
github.com/aws/aws-sdk-go v1.20.8
24+
github.com/cortexlabs/yaml v0.0.0-20190626164117-202ab3a3d475
2525
github.com/davecgh/go-spew v1.1.1
2626
github.com/emicklei/go-restful v2.9.6+incompatible // indirect
2727
github.com/go-openapi/spec v0.19.2 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko
1313
github.com/argoproj/argo v2.3.0+incompatible h1:L1OYZ86Q7NK19ahdl/eJOq78Mlf52wUKGmp7VDNQVz8=
1414
github.com/argoproj/argo v2.3.0+incompatible/go.mod h1:KJ0MB+tuhtAklR4jkPM10mIZXfRA0peTYJ1sLUnFLVU=
1515
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
16-
github.com/aws/aws-sdk-go v1.20.7 h1:fRjZRYJg0wPCA8yaDdb3DeP4rVjjmEiuqYhYoqOaIJg=
17-
github.com/aws/aws-sdk-go v1.20.7/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
16+
github.com/aws/aws-sdk-go v1.20.8 h1:oXnNFH/8PosUvHXqZHYLUn6LCSzHZ/34H52vrB4YhpA=
17+
github.com/aws/aws-sdk-go v1.20.8/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
1818
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
1919
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
2020
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
21-
github.com/cortexlabs/yaml v0.0.0-20190624201412-7f31702857b6 h1:NRxzHeHMTVyPV9yTGoXo3zRPplzVhrLTNzSFLNgpQII=
22-
github.com/cortexlabs/yaml v0.0.0-20190624201412-7f31702857b6/go.mod h1:nuzR4zMPuiBWg1HyZo9bzSZmtdSVjKfn8+RyO7egs0c=
21+
github.com/cortexlabs/yaml v0.0.0-20190626164117-202ab3a3d475 h1:N+pms5TCPH2F/DIX6a+2dgJI/CHweh45pEhGW/+stxQ=
22+
github.com/cortexlabs/yaml v0.0.0-20190626164117-202ab3a3d475/go.mod h1:nuzR4zMPuiBWg1HyZo9bzSZmtdSVjKfn8+RyO7egs0c=
2323
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
2424
github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2525
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

pkg/lib/aws/s3.go

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/aws/aws-sdk-go/aws/endpoints"
2626
"github.com/aws/aws-sdk-go/aws/session"
2727
"github.com/aws/aws-sdk-go/service/s3"
28+
"github.com/aws/aws-sdk-go/service/s3/s3manager"
2829

2930
"github.com/cortexlabs/cortex/pkg/lib/errors"
3031
"github.com/cortexlabs/cortex/pkg/lib/files"
@@ -285,7 +286,21 @@ func SplitS3Path(s3Path string) (string, string, error) {
285286
return bucket, key, nil
286287
}
287288

288-
func IsS3PrefixExternal(bucket string, prefix string, region string) (bool, error) {
289+
func GetBucketRegion(bucket string) (string, error) {
290+
sess := session.Must(session.NewSession())
291+
region, err := s3manager.GetBucketRegion(aws.BackgroundContext(), sess, bucket, endpoints.UsWest2RegionID)
292+
if err != nil {
293+
return "", errors.Wrap(err, bucket)
294+
}
295+
return region, nil
296+
}
297+
298+
func IsS3PrefixExternal(bucket string, prefix string) (bool, error) {
299+
region, err := GetBucketRegion(bucket)
300+
if err != nil {
301+
return false, err
302+
}
303+
289304
sess := session.Must(session.NewSession(&aws.Config{
290305
Region: aws.String(region),
291306
}))
@@ -296,19 +311,24 @@ func IsS3PrefixExternal(bucket string, prefix string, region string) (bool, erro
296311
})
297312

298313
if err != nil {
299-
return false, errors.Wrap(err, prefix)
314+
return false, errors.Wrap(err, bucket, prefix)
300315
}
301316

302317
hasPrefix := *out.KeyCount > 0
303318
return hasPrefix, nil
304319
}
305320

306-
func IsS3FileExternal(bucket string, key string, region string) (bool, error) {
321+
func IsS3FileExternal(bucket string, key string) (bool, error) {
322+
region, err := GetBucketRegion(bucket)
323+
if err != nil {
324+
return false, err
325+
}
326+
307327
sess := session.Must(session.NewSession(&aws.Config{
308328
Region: aws.String(region),
309329
}))
310330

311-
_, err := s3.New(sess).HeadObject(&s3.HeadObjectInput{
331+
_, err = s3.New(sess).HeadObject(&s3.HeadObjectInput{
312332
Bucket: aws.String(bucket),
313333
Key: aws.String(key),
314334
})
@@ -318,16 +338,25 @@ func IsS3FileExternal(bucket string, key string, region string) (bool, error) {
318338
}
319339

320340
if err != nil {
321-
return false, errors.Wrap(err, key)
341+
return false, errors.Wrap(err, bucket, key)
322342
}
323343

324344
return true, nil
325345
}
326346

327-
func IsS3aPrefixExternal(s3aPath string, region string) (bool, error) {
347+
func IsS3aPathPrefixExternal(s3aPath string) (bool, error) {
328348
bucket, prefix, err := SplitS3aPath(s3aPath)
329349
if err != nil {
330350
return false, err
331351
}
332-
return IsS3PrefixExternal(bucket, prefix, region)
352+
return IsS3PrefixExternal(bucket, prefix)
353+
}
354+
355+
func IsS3PathFileExternal(s3Path string) (bool, error) {
356+
bucket, key, err := SplitS3Path(s3Path)
357+
if err != nil {
358+
return false, err
359+
}
360+
361+
return IsS3FileExternal(bucket, key)
333362
}

pkg/operator/api/context/apis.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ type APIs map[string]*API
2525
type API struct {
2626
*userconfig.API
2727
*ComputedResourceFields
28-
Path string `json:"path"`
29-
ModelName string `json:"model_name"` // This removes the @ from userconfig.API.Model, or sets it to userconfig.API.ModelPath if it's external
28+
Path string `json:"path"`
3029
}
3130

3231
func APIPath(apiName string, appName string) string {

pkg/operator/api/context/dependencies.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,11 @@ func (ctx *Context) modelDependencies(model *Model) strset.Set {
151151
}
152152

153153
func (ctx *Context) apiDependencies(api *API) strset.Set {
154-
if api.Model == nil {
154+
modelName, ok := yaml.ExtractAtSymbolText(api.Model)
155+
if !ok {
155156
return strset.New()
156157
}
157-
model := ctx.Models[api.ModelName]
158+
model := ctx.Models[modelName]
158159
return strset.New(model.ID)
159160
}
160161

@@ -210,7 +211,7 @@ func extractCortexResourcesHelper(
210211
return
211212
}
212213

213-
if resourceName, ok := yaml.ExtractAtSymbolText(input); ok {
214+
if resourceName, ok := yaml.ExtractAtSymbolTextInter(input); ok {
214215
for _, res := range validResourcesMap[resourceName] {
215216
foundMatch := false
216217
if len(resourceTypeFilter) == 0 || resourceTypeFilter[res.GetResourceType()] == true {

pkg/operator/api/userconfig/aggregates.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ func (aggregates Aggregates) Validate() error {
108108

109109
func (aggregate *Aggregate) Validate() error {
110110
if aggregate.AggregatorPath == nil && aggregate.Aggregator == "" {
111-
return errors.Wrap(ErrorSpecifyOnlyOneMissing("aggregator", "aggregator_path"), Identify(aggregate))
111+
return errors.Wrap(ErrorSpecifyOnlyOneMissing(AggregatorKey, AggregatorPathKey), Identify(aggregate))
112112
}
113113

114114
if aggregate.AggregatorPath != nil && aggregate.Aggregator != "" {
115-
return errors.Wrap(ErrorSpecifyOnlyOne("aggregator", "aggregator_path"), Identify(aggregate))
115+
return errors.Wrap(ErrorSpecifyOnlyOne(AggregatorKey, AggregatorPathKey), Identify(aggregate))
116116
}
117117

118118
return nil

0 commit comments

Comments
 (0)