diff --git a/flytectl/cmd/config/subcommand/execution/config_flags.go b/flytectl/cmd/config/subcommand/execution/config_flags.go index 7f07f23bf7..9f47f721f9 100755 --- a/flytectl/cmd/config/subcommand/execution/config_flags.go +++ b/flytectl/cmd/config/subcommand/execution/config_flags.go @@ -54,6 +54,7 @@ func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags.StringVar(&DefaultConfig.Filter.SortBy, fmt.Sprintf("%v%v", prefix, "filter.sortBy"), DefaultConfig.Filter.SortBy, "Specifies which field to sort results ") cmdFlags.Int32Var(&DefaultConfig.Filter.Limit, fmt.Sprintf("%v%v", prefix, "filter.limit"), DefaultConfig.Filter.Limit, "Specifies the limit") cmdFlags.BoolVar(&DefaultConfig.Filter.Asc, fmt.Sprintf("%v%v", prefix, "filter.asc"), DefaultConfig.Filter.Asc, "Specifies the sorting order. By default flytectl sort result in descending order") + cmdFlags.Int32Var(&DefaultConfig.Filter.Page, fmt.Sprintf("%v%v", prefix, "filter.page"), DefaultConfig.Filter.Page, "Specifies the page number, in case there are multiple pages of results") cmdFlags.BoolVar(&DefaultConfig.Details, fmt.Sprintf("%v%v", prefix, "details"), DefaultConfig.Details, "gets node execution details. Only applicable for single execution name i.e get execution name --details") cmdFlags.StringVar(&DefaultConfig.NodeID, fmt.Sprintf("%v%v", prefix, "nodeID"), DefaultConfig.NodeID, "get task executions for given node name.") return cmdFlags diff --git a/flytectl/cmd/config/subcommand/execution/config_flags_test.go b/flytectl/cmd/config/subcommand/execution/config_flags_test.go index 57fc69dd42..ea72babe75 100755 --- a/flytectl/cmd/config/subcommand/execution/config_flags_test.go +++ b/flytectl/cmd/config/subcommand/execution/config_flags_test.go @@ -155,6 +155,20 @@ func TestConfig_SetFlags(t *testing.T) { } }) }) + t.Run("Test_filter.page", func(t *testing.T) { + + t.Run("Override", func(t *testing.T) { + testValue := "1" + + cmdFlags.Set("filter.page", testValue) + if vInt32, err := cmdFlags.GetInt32("filter.page"); err == nil { + testDecodeJson_Config(t, fmt.Sprintf("%v", vInt32), &actual.Filter.Page) + + } else { + assert.FailNow(t, err.Error()) + } + }) + }) t.Run("Test_details", func(t *testing.T) { t.Run("Override", func(t *testing.T) { diff --git a/flytectl/cmd/config/subcommand/launchplan/config_flags.go b/flytectl/cmd/config/subcommand/launchplan/config_flags.go index e41777eebc..3348bff7ee 100755 --- a/flytectl/cmd/config/subcommand/launchplan/config_flags.go +++ b/flytectl/cmd/config/subcommand/launchplan/config_flags.go @@ -57,5 +57,6 @@ func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags.StringVar(&DefaultConfig.Filter.SortBy, fmt.Sprintf("%v%v", prefix, "filter.sortBy"), DefaultConfig.Filter.SortBy, "Specifies which field to sort results ") cmdFlags.Int32Var(&DefaultConfig.Filter.Limit, fmt.Sprintf("%v%v", prefix, "filter.limit"), DefaultConfig.Filter.Limit, "Specifies the limit") cmdFlags.BoolVar(&DefaultConfig.Filter.Asc, fmt.Sprintf("%v%v", prefix, "filter.asc"), DefaultConfig.Filter.Asc, "Specifies the sorting order. By default flytectl sort result in descending order") + cmdFlags.Int32Var(&DefaultConfig.Filter.Page, fmt.Sprintf("%v%v", prefix, "filter.page"), DefaultConfig.Filter.Page, "Specifies the page number, in case there are multiple pages of results") return cmdFlags } diff --git a/flytectl/cmd/config/subcommand/launchplan/config_flags_test.go b/flytectl/cmd/config/subcommand/launchplan/config_flags_test.go index d2ccb2715d..afcd0597dd 100755 --- a/flytectl/cmd/config/subcommand/launchplan/config_flags_test.go +++ b/flytectl/cmd/config/subcommand/launchplan/config_flags_test.go @@ -197,4 +197,18 @@ func TestConfig_SetFlags(t *testing.T) { } }) }) + t.Run("Test_filter.page", func(t *testing.T) { + + t.Run("Override", func(t *testing.T) { + testValue := "1" + + cmdFlags.Set("filter.page", testValue) + if vInt32, err := cmdFlags.GetInt32("filter.page"); err == nil { + testDecodeJson_Config(t, fmt.Sprintf("%v", vInt32), &actual.Filter.Page) + + } else { + assert.FailNow(t, err.Error()) + } + }) + }) } diff --git a/flytectl/cmd/config/subcommand/project/config_flags.go b/flytectl/cmd/config/subcommand/project/config_flags.go index ca18dca630..ec92b98635 100755 --- a/flytectl/cmd/config/subcommand/project/config_flags.go +++ b/flytectl/cmd/config/subcommand/project/config_flags.go @@ -54,5 +54,6 @@ func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags.StringVar(&DefaultConfig.Filter.SortBy, fmt.Sprintf("%v%v", prefix, "filter.sortBy"), DefaultConfig.Filter.SortBy, "Specifies which field to sort results ") cmdFlags.Int32Var(&DefaultConfig.Filter.Limit, fmt.Sprintf("%v%v", prefix, "filter.limit"), DefaultConfig.Filter.Limit, "Specifies the limit") cmdFlags.BoolVar(&DefaultConfig.Filter.Asc, fmt.Sprintf("%v%v", prefix, "filter.asc"), DefaultConfig.Filter.Asc, "Specifies the sorting order. By default flytectl sort result in descending order") + cmdFlags.Int32Var(&DefaultConfig.Filter.Page, fmt.Sprintf("%v%v", prefix, "filter.page"), DefaultConfig.Filter.Page, "Specifies the page number, in case there are multiple pages of results") return cmdFlags } diff --git a/flytectl/cmd/config/subcommand/project/config_flags_test.go b/flytectl/cmd/config/subcommand/project/config_flags_test.go index 52668bcf14..78bd4ca726 100755 --- a/flytectl/cmd/config/subcommand/project/config_flags_test.go +++ b/flytectl/cmd/config/subcommand/project/config_flags_test.go @@ -155,4 +155,18 @@ func TestConfig_SetFlags(t *testing.T) { } }) }) + t.Run("Test_filter.page", func(t *testing.T) { + + t.Run("Override", func(t *testing.T) { + testValue := "1" + + cmdFlags.Set("filter.page", testValue) + if vInt32, err := cmdFlags.GetInt32("filter.page"); err == nil { + testDecodeJson_Config(t, fmt.Sprintf("%v", vInt32), &actual.Filter.Page) + + } else { + assert.FailNow(t, err.Error()) + } + }) + }) } diff --git a/flytectl/cmd/config/subcommand/task/config_flags.go b/flytectl/cmd/config/subcommand/task/config_flags.go index 3138439017..ee181f076f 100755 --- a/flytectl/cmd/config/subcommand/task/config_flags.go +++ b/flytectl/cmd/config/subcommand/task/config_flags.go @@ -57,5 +57,6 @@ func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags.StringVar(&DefaultConfig.Filter.SortBy, fmt.Sprintf("%v%v", prefix, "filter.sortBy"), DefaultConfig.Filter.SortBy, "Specifies which field to sort results ") cmdFlags.Int32Var(&DefaultConfig.Filter.Limit, fmt.Sprintf("%v%v", prefix, "filter.limit"), DefaultConfig.Filter.Limit, "Specifies the limit") cmdFlags.BoolVar(&DefaultConfig.Filter.Asc, fmt.Sprintf("%v%v", prefix, "filter.asc"), DefaultConfig.Filter.Asc, "Specifies the sorting order. By default flytectl sort result in descending order") + cmdFlags.Int32Var(&DefaultConfig.Filter.Page, fmt.Sprintf("%v%v", prefix, "filter.page"), DefaultConfig.Filter.Page, "Specifies the page number, in case there are multiple pages of results") return cmdFlags } diff --git a/flytectl/cmd/config/subcommand/task/config_flags_test.go b/flytectl/cmd/config/subcommand/task/config_flags_test.go index 844d031a5a..52651e144c 100755 --- a/flytectl/cmd/config/subcommand/task/config_flags_test.go +++ b/flytectl/cmd/config/subcommand/task/config_flags_test.go @@ -197,4 +197,18 @@ func TestConfig_SetFlags(t *testing.T) { } }) }) + t.Run("Test_filter.page", func(t *testing.T) { + + t.Run("Override", func(t *testing.T) { + testValue := "1" + + cmdFlags.Set("filter.page", testValue) + if vInt32, err := cmdFlags.GetInt32("filter.page"); err == nil { + testDecodeJson_Config(t, fmt.Sprintf("%v", vInt32), &actual.Filter.Page) + + } else { + assert.FailNow(t, err.Error()) + } + }) + }) } diff --git a/flytectl/cmd/config/subcommand/workflow/config_flags.go b/flytectl/cmd/config/subcommand/workflow/config_flags.go index 29bc7fca54..f0f1064aff 100755 --- a/flytectl/cmd/config/subcommand/workflow/config_flags.go +++ b/flytectl/cmd/config/subcommand/workflow/config_flags.go @@ -56,5 +56,6 @@ func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags.StringVar(&DefaultConfig.Filter.SortBy, fmt.Sprintf("%v%v", prefix, "filter.sortBy"), DefaultConfig.Filter.SortBy, "Specifies which field to sort results ") cmdFlags.Int32Var(&DefaultConfig.Filter.Limit, fmt.Sprintf("%v%v", prefix, "filter.limit"), DefaultConfig.Filter.Limit, "Specifies the limit") cmdFlags.BoolVar(&DefaultConfig.Filter.Asc, fmt.Sprintf("%v%v", prefix, "filter.asc"), DefaultConfig.Filter.Asc, "Specifies the sorting order. By default flytectl sort result in descending order") + cmdFlags.Int32Var(&DefaultConfig.Filter.Page, fmt.Sprintf("%v%v", prefix, "filter.page"), DefaultConfig.Filter.Page, "Specifies the page number, in case there are multiple pages of results") return cmdFlags } diff --git a/flytectl/cmd/config/subcommand/workflow/config_flags_test.go b/flytectl/cmd/config/subcommand/workflow/config_flags_test.go index 4011d8e4f3..46d13aeb87 100755 --- a/flytectl/cmd/config/subcommand/workflow/config_flags_test.go +++ b/flytectl/cmd/config/subcommand/workflow/config_flags_test.go @@ -183,4 +183,18 @@ func TestConfig_SetFlags(t *testing.T) { } }) }) + t.Run("Test_filter.page", func(t *testing.T) { + + t.Run("Override", func(t *testing.T) { + testValue := "1" + + cmdFlags.Set("filter.page", testValue) + if vInt32, err := cmdFlags.GetInt32("filter.page"); err == nil { + testDecodeJson_Config(t, fmt.Sprintf("%v", vInt32), &actual.Filter.Page) + + } else { + assert.FailNow(t, err.Error()) + } + }) + }) } diff --git a/flytectl/cmd/get/execution.go b/flytectl/cmd/get/execution.go index 3dcf3f34ae..9f8f6a66d7 100644 --- a/flytectl/cmd/get/execution.go +++ b/flytectl/cmd/get/execution.go @@ -30,15 +30,19 @@ Retrieve executions by name within the project and domain: Retrieve all the executions with filters: :: - - flytectl get execution -p flytesnacks -d development --filter.fieldSelector="execution.phase in (FAILED;SUCCEEDED),execution.duration<200" - + flytectl get execution -p flytesnacks -d development --filter.fieldSelector="execution.phase in (FAILED;SUCCEEDED),execution.duration<200" + + Retrieve executions as per the specified limit and sorting parameters: :: - + flytectl get execution -p flytesnacks -d development --filter.sortBy=created_at --filter.limit=1 --filter.asc - + +Retrieves all the executions on other pages. +:: + + flytectl get -p flytesnacks -d development execution --filter.limit=10 --filter.page=2 Retrieve executions within the project and domain in YAML format: diff --git a/flytectl/cmd/get/launch_plan.go b/flytectl/cmd/get/launch_plan.go index 531504d41c..d228ed3459 100644 --- a/flytectl/cmd/get/launch_plan.go +++ b/flytectl/cmd/get/launch_plan.go @@ -42,20 +42,24 @@ Retrieve a particular version of the launch plan by name within the project and Retrieve all the launch plans with filters: :: - + flytectl get launchplan -p flytesnacks -d development --filter.fieldSelector="name=core.basic.lp.go_greet" - + Retrieve launch plans entity search across all versions with filters: :: - + flytectl get launchplan -p flytesnacks -d development k8s_spark.dataframe_passing.my_smart_schema --filter.fieldSelector="version=v1" - - + + Retrieve all the launch plans with limit and sorting: :: - + flytectl get launchplan -p flytesnacks -d development --filter.sortBy=created_at --filter.limit=1 --filter.asc - + +Retrieves all the launch plans on other pages. +:: + + flytectl get -p flytesnacks -d development launchplan --filter.limit=10 --filter.page=2 Retrieve all launch plans within the project and domain in YAML format: diff --git a/flytectl/cmd/get/project.go b/flytectl/cmd/get/project.go index 4912d4b5fc..2718a54a9c 100644 --- a/flytectl/cmd/get/project.go +++ b/flytectl/cmd/get/project.go @@ -30,14 +30,19 @@ Retrieve project by name: Retrieve all the projects with filters: :: - + flytectl get project --filter.fieldSelector="project.name=flytesnacks" - + Retrieve all the projects with limit and sorting: :: - + flytectl get project --filter.sortBy=created_at --filter.limit=1 --filter.asc +Retrieves all the projects on other pages. +:: + + flytectl get project --filter.limit=10 --filter.page=2 + Retrieve all the projects in yaml format: :: diff --git a/flytectl/cmd/get/task.go b/flytectl/cmd/get/task.go index c1f103dea4..43eec8b1a3 100644 --- a/flytectl/cmd/get/task.go +++ b/flytectl/cmd/get/task.go @@ -41,19 +41,24 @@ Retrieve particular version of task by name within project and domain: Retrieve all the tasks with filters: :: - - flytectl get task -p flytesnacks -d development --filter.fieldSelector="task.name=k8s_spark.pyspark_pi.print_every_time,task.version=v1" - + + flytectl get task -p flytesnacks -d development --filter.fieldSelector="task.name=k8s_spark.pyspark_pi.print_every_time,task.version=v1" + Retrieve a specific task with filters: :: - - flytectl get task -p flytesnacks -d development k8s_spark.pyspark_pi.print_every_time --filter.fieldSelector="task.version=v1,created_at>=2021-05-24T21:43:12.325335Z" - + + flytectl get task -p flytesnacks -d development k8s_spark.pyspark_pi.print_every_time --filter.fieldSelector="task.version=v1,created_at>=2021-05-24T21:43:12.325335Z" + Retrieve all the tasks with limit and sorting: :: - + flytectl get -p flytesnacks -d development task --filter.sortBy=created_at --filter.limit=1 --filter.asc +Retrieves all the task on other pages. +:: + + flytectl get -p flytesnacks -d development task --filter.limit=10 --filter.page=2 + Retrieve all the tasks within project and domain in yaml format: :: diff --git a/flytectl/cmd/get/workflow.go b/flytectl/cmd/get/workflow.go index 0b80e652e3..5d3c7364b9 100644 --- a/flytectl/cmd/get/workflow.go +++ b/flytectl/cmd/get/workflow.go @@ -43,19 +43,24 @@ Retrieve particular version of workflow by name within project and domain: Retrieve all the workflows with filters: :: - + flytectl get workflow -p flytesnacks -d development --filter.fieldSelector="workflow.name=k8s_spark.dataframe_passing.my_smart_schema" - + Retrieve specific workflow with filters: :: - + flytectl get workflow -p flytesnacks -d development k8s_spark.dataframe_passing.my_smart_schema --filter.fieldSelector="workflow.version=v1" - + Retrieve all the workflows with limit and sorting: :: - + flytectl get -p flytesnacks -d development workflow --filter.sortBy=created_at --filter.limit=1 --filter.asc +Retrieves all the workflows on other pages. +:: + + flytectl get -p flytesnacks -d development workflow --filter.limit=10 --filter.page 2 + Retrieve all the workflows within project and domain in yaml format: :: diff --git a/flytectl/pkg/filters/type.go b/flytectl/pkg/filters/type.go index 6dabc0904d..1a46a4fa2c 100644 --- a/flytectl/pkg/filters/type.go +++ b/flytectl/pkg/filters/type.go @@ -4,6 +4,7 @@ var ( DefaultLimit int32 = 100 DefaultFilter = Filters{ Limit: DefaultLimit, + Page: 1, SortBy: "created_at", Asc: false, } @@ -12,7 +13,7 @@ var ( type Filters struct { FieldSelector string `json:"fieldSelector" pflag:",Specifies the Field selector"` SortBy string `json:"sortBy" pflag:",Specifies which field to sort results "` - // TODO: Support paginated queries - Limit int32 `json:"limit" pflag:",Specifies the limit"` - Asc bool `json:"asc" pflag:",Specifies the sorting order. By default flytectl sort result in descending order"` + Limit int32 `json:"limit" pflag:",Specifies the limit"` + Asc bool `json:"asc" pflag:",Specifies the sorting order. By default flytectl sort result in descending order"` + Page int32 `json:"page" pflag:",Specifies the page number, in case there are multiple pages of results"` } diff --git a/flytectl/pkg/filters/util.go b/flytectl/pkg/filters/util.go index 2c2515326a..6d2501e4d5 100644 --- a/flytectl/pkg/filters/util.go +++ b/flytectl/pkg/filters/util.go @@ -1,6 +1,8 @@ package filters import ( + "strconv" + "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" ) @@ -11,6 +13,7 @@ func BuildResourceListRequestWithName(c Filters, project, domain, name string) ( } request := &admin.ResourceListRequest{ Limit: uint32(c.Limit), + Token: getToken(c), Filters: fieldSelector, Id: &admin.NamedEntityIdentifier{ Project: project, @@ -33,6 +36,7 @@ func BuildProjectListRequest(c Filters) (*admin.ProjectListRequest, error) { } request := &admin.ProjectListRequest{ Limit: uint32(c.Limit), + Token: getToken(c), Filters: fieldSelector, SortBy: buildSortingRequest(c), } @@ -52,3 +56,11 @@ func buildSortingRequest(c Filters) *admin.Sort { } return nil } + +func getToken(c Filters) string { + token := int(c.Page-1) * int(c.Limit) + if token <= 0 { + return "" + } + return strconv.Itoa(token) +} diff --git a/flytectl/pkg/filters/util_test.go b/flytectl/pkg/filters/util_test.go index 6edcc79786..98cb98985c 100644 --- a/flytectl/pkg/filters/util_test.go +++ b/flytectl/pkg/filters/util_test.go @@ -47,11 +47,13 @@ func TestProjectListRequestFunc(t *testing.T) { config.GetConfig().Domain = domain filter := Filters{ Limit: 100, + Page: 2, SortBy: "created_at", } request, err := BuildProjectListRequest(filter) expectedResponse := &admin.ProjectListRequest{ Limit: 100, + Token: "100", Filters: "", SortBy: &admin.Sort{ Key: "created_at", @@ -80,6 +82,7 @@ func TestListRequestWithNameFunc(t *testing.T) { filter := Filters{ Limit: 100, SortBy: "created_at", + Page: 1, } request, err := BuildResourceListRequestWithName(filter, project, domain, name) expectedResponse := &admin.ResourceListRequest{