-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e81358f
commit 172a0eb
Showing
6 changed files
with
343 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/gojek/feast/cli/feast/pkg/printer" | ||
"github.com/gojek/feast/protos/generated/go/feast/core" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// listCmd represents the list command | ||
var getCmd = &cobra.Command{ | ||
Use: "get [resource] [id]", | ||
Short: "Get and print the details of the desired resource.", | ||
Long: `Get and print the details of the desired resource. | ||
Valid resources include: | ||
- entity | ||
- feature | ||
- storage | ||
- job | ||
Examples: | ||
- feast get entity myentity`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
return cmd.Help() | ||
} | ||
|
||
if len(args) != 2 { | ||
return errors.New("invalid number of arguments for list command") | ||
} | ||
|
||
initConn() | ||
err := get(args[0], args[1]) | ||
if err != nil { | ||
return fmt.Errorf("failed to list %s: %v", args[0], err) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(getCmd) | ||
} | ||
|
||
func get(resource string, id string) error { | ||
ctx := context.Background() | ||
|
||
switch resource { | ||
case "feature": | ||
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, storage, jobs]", resource) | ||
} | ||
} | ||
|
||
func getFeature(ctx context.Context, cli core.UIServiceClient, id string) error { | ||
response, err := cli.GetFeature(ctx, &core.UIServiceTypes_GetFeatureRequest{Id: id}) | ||
if err != nil { | ||
return err | ||
} | ||
printer.PrintFeatureDetail(response.GetFeature()) | ||
return nil | ||
} | ||
|
||
func getEntity(ctx context.Context, cli core.UIServiceClient, id string) error { | ||
response, err := cli.GetEntity(ctx, &core.UIServiceTypes_GetEntityRequest{Id: id}) | ||
if err != nil { | ||
return err | ||
} | ||
printer.PrintEntityDetail(response.GetEntity()) | ||
return nil | ||
} | ||
|
||
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 { | ||
return err | ||
} | ||
printer.PrintJobDetail(response.GetJob()) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package printer | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/protobuf/ptypes/timestamp" | ||
|
||
"github.com/gojek/feast/protos/generated/go/feast/core" | ||
"github.com/gojek/feast/protos/generated/go/feast/specs" | ||
"github.com/gojek/feast/protos/generated/go/feast/types" | ||
) | ||
|
||
func TestPrintFeature(t *testing.T) { | ||
tt := []struct { | ||
name string | ||
input *core.UIServiceTypes_FeatureDetail | ||
expected string | ||
}{ | ||
{ | ||
name: "with storage", | ||
input: &core.UIServiceTypes_FeatureDetail{ | ||
Spec: &specs.FeatureSpec{ | ||
Id: "test.none.test_feature_two", | ||
Owner: "[email protected]", | ||
Name: "test_feature_two", | ||
Description: "testing feature", | ||
Uri: "https://github.com/bob/example", | ||
Granularity: types.Granularity_NONE, | ||
ValueType: types.ValueType_INT64, | ||
Entity: "test", | ||
DataStores: &specs.DataStores{ | ||
Serving: &specs.DataStore{ | ||
Id: "REDIS", | ||
}, | ||
Warehouse: &specs.DataStore{ | ||
Id: "BIGQUERY", | ||
}, | ||
}, | ||
}, | ||
BigqueryView: "bqurl", | ||
Jobs: []string{"job1", "job2"}, | ||
LastUpdated: ×tamp.Timestamp{Seconds: 1}, | ||
Created: ×tamp.Timestamp{Seconds: 1}, | ||
}, | ||
expected: `Id: test.none.test_feature_two | ||
Entity: test | ||
Owner: [email protected] | ||
Description: testing feature | ||
ValueType: INT64 | ||
Uri: https://github.com/bob/example | ||
DataStores: | ||
Serving: REDIS | ||
Warehouse: BIGQUERY | ||
Created: 1970-01-01T07:30:01+07:30 | ||
LastUpdated: 1970-01-01T07:30:01+07:30 | ||
Related Jobs: | ||
- job1 | ||
- job2`, | ||
}, { | ||
name: "no storage", | ||
input: &core.UIServiceTypes_FeatureDetail{ | ||
Spec: &specs.FeatureSpec{ | ||
Id: "test.none.test_feature_two", | ||
Owner: "[email protected]", | ||
Name: "test_feature_two", | ||
Description: "testing feature", | ||
Uri: "https://github.com/bob/example", | ||
Granularity: types.Granularity_NONE, | ||
ValueType: types.ValueType_INT64, | ||
Entity: "test", | ||
}, | ||
BigqueryView: "bqurl", | ||
Jobs: []string{"job1", "job2"}, | ||
LastUpdated: ×tamp.Timestamp{Seconds: 1}, | ||
Created: ×tamp.Timestamp{Seconds: 1}, | ||
}, | ||
expected: `Id: test.none.test_feature_two | ||
Entity: test | ||
Owner: [email protected] | ||
Description: testing feature | ||
ValueType: INT64 | ||
Uri: https://github.com/bob/example | ||
Created: 1970-01-01T07:30:01+07:30 | ||
LastUpdated: 1970-01-01T07:30:01+07:30 | ||
Related Jobs: | ||
- job1 | ||
- job2`, | ||
}, | ||
} | ||
|
||
for _, tc := range tt { | ||
t.Run(tc.name, func(t *testing.T) { | ||
out := PrintFeatureDetail(tc.input) | ||
if out != tc.expected { | ||
t.Errorf("Expected output:\n%s \nActual:\n%s \n", tc.expected, out) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestPrintEntity(t *testing.T) { | ||
entityDetail := &core.UIServiceTypes_EntityDetail{ | ||
Spec: &specs.EntitySpec{ | ||
Name: "test", | ||
Description: "my test entity", | ||
Tags: []string{"tag1", "tag2"}, | ||
}, | ||
Jobs: []string{"job1", "job2"}, | ||
LastUpdated: ×tamp.Timestamp{Seconds: 1}, | ||
} | ||
out := PrintEntityDetail(entityDetail) | ||
expected := `Name: test | ||
Description: my test entity | ||
Tags: tag1,tag2 | ||
LastUpdated: 1970-01-01T07:30:01+07:30 | ||
Related Jobs: | ||
- job1 | ||
- job2` | ||
if out != expected { | ||
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: ×tamp.Timestamp{Seconds: 1}, | ||
} | ||
out := PrintStorageDetail(storageDetail) | ||
expected := `Id: REDIS1 | ||
Type: redis | ||
Options: | ||
option1: value1 | ||
option2: value2 | ||
LastUpdated: 1970-01-01T07:30:01+07:30` | ||
if out != expected { | ||
t.Errorf("Expected output:\n%s \nActual:\n%s \n", expected, out) | ||
} | ||
} |
Oops, something went wrong.