Skip to content

Commit

Permalink
Merge pull request #2 from zhilingc/tims-single-stores
Browse files Browse the repository at this point in the history
Add list storage functions back in, mark as deprecated
  • Loading branch information
tims authored May 8, 2019
2 parents fcc8b44 + 46ee1eb commit 83ed6c4
Show file tree
Hide file tree
Showing 7 changed files with 393 additions and 50 deletions.
14 changes: 13 additions & 1 deletion cli/feast/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ func get(resource string, id string) error {
return getFeature(ctx, core.NewUIServiceClient(coreConn), id)
case "entity":
return getEntity(ctx, core.NewUIServiceClient(coreConn), id)
case "storage":
return getStorage(ctx, core.NewUIServiceClient(coreConn), id)
case "job":
return getJob(ctx, core.NewJobServiceClient(coreConn), id)
default:
return fmt.Errorf("invalid resource %s: please choose one of [features, entities, jobs]", resource)
return fmt.Errorf("invalid resource %s: please choose one of [features, entities, storage, jobs]", resource)
}
}

Expand All @@ -78,6 +80,16 @@ func getEntity(ctx context.Context, cli core.UIServiceClient, id string) error {
return nil
}

// This function is deprecated, and may be removed in subsequent versions.
func getStorage(ctx context.Context, cli core.UIServiceClient, id string) error {
response, err := cli.GetStorage(ctx, &core.UIServiceTypes_GetStorageRequest{Id: id})
if err != nil {
return err
}
printer.PrintStorageDetail(response.GetStorage())
return nil
}

func getJob(ctx context.Context, cli core.JobServiceClient, id string) error {
response, err := cli.GetJob(ctx, &core.JobServiceTypes_GetJobRequest{Id: id})
if err != nil {
Expand Down
22 changes: 21 additions & 1 deletion cli/feast/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ func list(resource string) error {
return listEntities(ctx, core.NewCoreServiceClient(coreConn))
case "jobs":
return listJobs(ctx, core.NewJobServiceClient(coreConn))
case "storage":
return listStorage(ctx, core.NewCoreServiceClient(coreConn))
default:
return fmt.Errorf("invalid resource %s: please choose one of [features, entities, jobs]", resource)
return fmt.Errorf("invalid resource %s: please choose one of [features, storage, entities, jobs]", resource)
}
}

Expand Down Expand Up @@ -129,3 +131,21 @@ func listJobs(ctx context.Context, cli core.JobServiceClient) error {
w.Flush()
return nil
}

// This function is deprecated, and may be removed in subsequent versions.
func listStorage(ctx context.Context, cli core.CoreServiceClient) error {
response, err := cli.ListStorage(ctx, &empty.Empty{})
if err != nil {
return err
}
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 2, ' ', 0)
fmt.Fprintf(w, "ID\tTYPE\n")
fmt.Fprintf(w, "--\t----\t\n")
for _, feat := range response.GetStorageSpecs() {
fmt.Fprintf(w, strings.Join(
[]string{feat.Id, feat.Type}, "\t")+"\n")
}
w.Flush()
return nil
}
36 changes: 36 additions & 0 deletions cli/feast/cmd/mock/core_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions cli/feast/pkg/printer/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,22 @@ func PrintEntityDetail(entityDetail *core.UIServiceTypes_EntityDetail) string {
fmt.Println(out)
return out
}

// PrintStorageDetail prints the details about the feature.
// Prints and returns the resultant formatted string.
// This function is deprecated, and may be removed in subsequent versions.
func PrintStorageDetail(storageDetail *core.UIServiceTypes_StorageDetail) string {
spec := storageDetail.GetSpec()
lines := []string{
fmt.Sprintf("%s:\t%s", "Id", spec.GetId()),
fmt.Sprintf("%s:\t%s", "Type", spec.GetType()),
fmt.Sprintf("Options:"),
}
for k, v := range spec.GetOptions() {
lines = append(lines, fmt.Sprintf(" %s: %s", k, v))
}
lines = append(lines, fmt.Sprintf("%s:\t%s", "LastUpdated", timeutil.FormatToRFC3339(*storageDetail.GetLastUpdated())))
out := strings.Join(lines, "\n")
fmt.Println(out)
return out
}
25 changes: 25 additions & 0 deletions cli/feast/pkg/printer/specs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,28 @@ Related Jobs:
t.Errorf("Expected output:\n%s \nActual:\n%s \n", expected, out)
}
}

func TestPrintStorage(t *testing.T) {
storageDetail := &core.UIServiceTypes_StorageDetail{
Spec: &specs.StorageSpec{
Id: "REDIS1",
Type: "redis",
Options: map[string]string{
"option1": "value1",
"option2": "value2",
},
},
LastUpdated: &timestamp.Timestamp{Seconds: 1},
}
out := PrintStorageDetail(storageDetail)
expected := fmt.Sprintf(`Id: REDIS1
Type: redis
Options:
option1: value1
option2: value2
LastUpdated: %s`,
timeutil.FormatToRFC3339(timestamp.Timestamp{Seconds: 1}))
if out != expected {
t.Errorf("Expected output:\n%s \nActual:\n%s \n", expected, out)
}
}
29 changes: 29 additions & 0 deletions protos/feast/core/CoreService.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ service CoreService {
*/
rpc ListEntities(google.protobuf.Empty) returns (CoreServiceTypes.ListEntitiesResponse) {};

/*
Get storage specs specified in request.
This process returns a list of storage specs.
*/
rpc GetStorage(CoreServiceTypes.GetStorageRequest) returns (CoreServiceTypes.GetStorageResponse){
option deprecated = true;
};

/*
Get all storage specs.
This process returns a list of storage specs.
*/
rpc ListStorage(google.protobuf.Empty) returns (CoreServiceTypes.ListStorageResponse) {
option deprecated = true;
};

/*
Get features specified in request.
This process returns a list of feature specs.
Expand Down Expand Up @@ -99,6 +115,19 @@ message CoreServiceTypes {
repeated feast.specs.FeatureSpec features = 1;
}

// Storage spec retrieval
message GetStorageRequest {
repeated string ids = 1;
}

message GetStorageResponse {
repeated feast.specs.StorageSpec storageSpecs = 1;
}

message ListStorageResponse {
repeated feast.specs.StorageSpec storageSpecs = 1;
}

// Entity registration response
message ApplyEntityResponse {
string entityName = 1;
Expand Down
Loading

0 comments on commit 83ed6c4

Please sign in to comment.