diff --git a/flytectl/cmd/create/execution_test.go b/flytectl/cmd/create/execution_test.go index 36166fdf21..65df850ae5 100644 --- a/flytectl/cmd/create/execution_test.go +++ b/flytectl/cmd/create/execution_test.go @@ -32,14 +32,9 @@ func createExecutionSetup() { }, }, } - variableMap := []*core.VariableMapEntry{ - { - Name: "sorted_list1", - Var: &sortedListLiteralType, - }, { - Name: "sorted_list2", - Var: &sortedListLiteralType, - }, + variableMap := map[string]*core.Variable{ + "sorted_list1": &sortedListLiteralType, + "sorted_list2": &sortedListLiteralType, } task1 := &admin.Task{ @@ -61,10 +56,9 @@ func createExecutionSetup() { }, } mockClient.OnGetTaskMatch(ctx, mock.Anything).Return(task1, nil) - parameterMap := []*core.ParameterMapEntry{ - { - Name: "numbers", - Parameter: &core.Parameter{Var: &core.Variable{ + parameterMap := map[string]*core.Parameter{ + "numbers": { + Var: &core.Variable{ Type: &core.LiteralType{ Type: &core.LiteralType_CollectionType{ CollectionType: &core.LiteralType{ @@ -74,42 +68,40 @@ func createExecutionSetup() { }, }, }, - }}, + }, }, - { - Name: "numbers_count", - Parameter: &core.Parameter{Var: &core.Variable{ + "numbers_count": { + Var: &core.Variable{ Type: &core.LiteralType{ Type: &core.LiteralType_Simple{ Simple: core.SimpleType_INTEGER, }, }, - }}, + }, }, - { - Name: "run_local_at_count", - Parameter: &core.Parameter{Var: &core.Variable{ + "run_local_at_count": { + Var: &core.Variable{ Type: &core.LiteralType{ Type: &core.LiteralType_Simple{ Simple: core.SimpleType_INTEGER, }, }, }, - Behavior: &core.Parameter_Default{ - Default: &core.Literal{ - Value: &core.Literal_Scalar{ - Scalar: &core.Scalar{ - Value: &core.Scalar_Primitive{ - Primitive: &core.Primitive{ - Value: &core.Primitive_Integer{ - Integer: 10, - }, + Behavior: &core.Parameter_Default{ + Default: &core.Literal{ + Value: &core.Literal_Scalar{ + Scalar: &core.Scalar{ + Value: &core.Scalar_Primitive{ + Primitive: &core.Primitive{ + Value: &core.Primitive_Integer{ + Integer: 10, }, }, }, }, }, - }}, + }, + }, }, } launchPlan1 := &admin.LaunchPlan{ diff --git a/flytectl/cmd/create/serialization_utils.go b/flytectl/cmd/create/serialization_utils.go index 568ed6dc27..53045d2c9e 100644 --- a/flytectl/cmd/create/serialization_utils.go +++ b/flytectl/cmd/create/serialization_utils.go @@ -11,15 +11,15 @@ import ( // MakeLiteralForVariables builds a map of literals for the provided serialized values. If a provided value does not have // a corresponding variable or if that variable is invalid (e.g. doesn't have Type property populated), it returns an // error. -func MakeLiteralForVariables(serialize map[string]interface{}, variables []*core.VariableMapEntry) (map[string]*core.Literal, error) { +func MakeLiteralForVariables(serialize map[string]interface{}, variables map[string]*core.Variable) (map[string]*core.Literal, error) { types := make(map[string]*core.LiteralType) - for _, e := range variables { - t := e.GetVar().GetType() + for k, v := range variables { + t := v.GetType() if t == nil { - return nil, fmt.Errorf("variable [%v] has nil type", e.GetName()) + return nil, fmt.Errorf("variable [%v] has nil type", k) } - types[e.GetName()] = t + types[k] = t } return MakeLiteralForTypes(serialize, types) @@ -28,15 +28,15 @@ func MakeLiteralForVariables(serialize map[string]interface{}, variables []*core // MakeLiteralForParams builds a map of literals for the provided serialized values. If a provided value does not have // a corresponding parameter or if that parameter is invalid (e.g. doesn't have Type property populated), it returns an // error. -func MakeLiteralForParams(serialize map[string]interface{}, parameters []*core.ParameterMapEntry) (map[string]*core.Literal, error) { +func MakeLiteralForParams(serialize map[string]interface{}, parameters map[string]*core.Parameter) (map[string]*core.Literal, error) { types := make(map[string]*core.LiteralType) - for _, e := range parameters { - if variable := e.GetParameter().GetVar(); variable == nil { - return nil, fmt.Errorf("parameter [%v] has nil Variable", e.GetName()) + for k, v := range parameters { + if variable := v.GetVar(); variable == nil { + return nil, fmt.Errorf("parameter [%v] has nil Variable", k) } else if t := variable.GetType(); t == nil { - return nil, fmt.Errorf("parameter [%v] has nil variable type", e.GetName()) + return nil, fmt.Errorf("parameter [%v] has nil variable type", k) } else { - types[e.GetName()] = t + types[k] = t } } diff --git a/flytectl/cmd/create/serialization_utils_test.go b/flytectl/cmd/create/serialization_utils_test.go index ebe4484472..5c7326493d 100644 --- a/flytectl/cmd/create/serialization_utils_test.go +++ b/flytectl/cmd/create/serialization_utils_test.go @@ -67,16 +67,15 @@ func TestMakeLiteralForParams(t *testing.T) { } t.Run("Happy path", func(t *testing.T) { - inputParams := []*core.ParameterMapEntry{ - { - Name: "a", - Parameter: &core.Parameter{Var: &core.Variable{ + inputParams := map[string]*core.Parameter{ + "a": { + Var: &core.Variable{ Type: &core.LiteralType{ Type: &core.LiteralType_Simple{ Simple: core.SimpleType_STRING, }, }, - }}, + }, }, } @@ -86,11 +85,8 @@ func TestMakeLiteralForParams(t *testing.T) { }) t.Run("Invalid Param", func(t *testing.T) { - inputParams := []*core.ParameterMapEntry{ - { - Name: "a", - Parameter: nil, - }, + inputParams := map[string]*core.Parameter{ + "a": nil, } _, err := MakeLiteralForParams(inputValues, inputParams) @@ -98,10 +94,9 @@ func TestMakeLiteralForParams(t *testing.T) { }) t.Run("Invalid Type", func(t *testing.T) { - inputParams := []*core.ParameterMapEntry{ - { - Name: "a", - Parameter: &core.Parameter{Var: &core.Variable{}}, + inputParams := map[string]*core.Parameter{ + "a": { + Var: &core.Variable{}, }, } @@ -116,14 +111,11 @@ func TestMakeLiteralForVariables(t *testing.T) { } t.Run("Happy path", func(t *testing.T) { - inputVariables := []*core.VariableMapEntry{ - { - Name: "a", - Var: &core.Variable{ - Type: &core.LiteralType{ - Type: &core.LiteralType_Simple{ - Simple: core.SimpleType_STRING, - }, + inputVariables := map[string]*core.Variable{ + "a": { + Type: &core.LiteralType{ + Type: &core.LiteralType_Simple{ + Simple: core.SimpleType_STRING, }, }, }, @@ -135,11 +127,8 @@ func TestMakeLiteralForVariables(t *testing.T) { }) t.Run("Invalid Variable", func(t *testing.T) { - inputVariables := []*core.VariableMapEntry{ - { - Name: "a", - Var: nil, - }, + inputVariables := map[string]*core.Variable{ + "a": nil, } _, err := MakeLiteralForVariables(inputValues, inputVariables) @@ -147,12 +136,9 @@ func TestMakeLiteralForVariables(t *testing.T) { }) t.Run("Invalid Type", func(t *testing.T) { - inputVariables := []*core.VariableMapEntry{ - { - Name: "a", - Var: &core.Variable{ - Type: nil, - }, + inputVariables := map[string]*core.Variable{ + "a": { + Type: nil, }, } diff --git a/flytectl/cmd/get/execution_util.go b/flytectl/cmd/get/execution_util.go index 8469e68e1d..65b72175a5 100644 --- a/flytectl/cmd/get/execution_util.go +++ b/flytectl/cmd/get/execution_util.go @@ -58,8 +58,8 @@ func CreateAndWriteExecConfigForWorkflow(wlp *admin.LaunchPlan, fileName string) return WriteExecConfigToFile(executionConfig, fileName) } -func TaskInputs(task *admin.Task) []*core.VariableMapEntry { - taskInputs := []*core.VariableMapEntry{} +func TaskInputs(task *admin.Task) map[string]*core.Variable { + taskInputs := map[string]*core.Variable{} if task == nil || task.Closure == nil { return taskInputs } @@ -81,10 +81,10 @@ func TaskInputs(task *admin.Task) []*core.VariableMapEntry { func ParamMapForTask(task *admin.Task) (map[string]yaml.Node, error) { taskInputs := TaskInputs(task) paramMap := make(map[string]yaml.Node, len(taskInputs)) - for _, e := range taskInputs { - varTypeValue, err := coreutils.MakeDefaultLiteralForType(e.Var.Type) + for k, v := range taskInputs { + varTypeValue, err := coreutils.MakeDefaultLiteralForType(v.Type) if err != nil { - fmt.Println("error creating default value for literal type ", e.Var.Type) + fmt.Println("error creating default value for literal type ", v.Type) return nil, err } var nativeLiteral interface{} @@ -92,11 +92,11 @@ func ParamMapForTask(task *admin.Task) (map[string]yaml.Node, error) { return nil, err } - if e.Name == e.Var.Description { + if k == v.Description { // a: # a isn't very helpful - paramMap[e.Name], err = getCommentedYamlNode(nativeLiteral, "") + paramMap[k], err = getCommentedYamlNode(nativeLiteral, "") } else { - paramMap[e.Name], err = getCommentedYamlNode(nativeLiteral, e.Var.Description) + paramMap[k], err = getCommentedYamlNode(nativeLiteral, v.Description) } if err != nil { return nil, err @@ -105,8 +105,8 @@ func ParamMapForTask(task *admin.Task) (map[string]yaml.Node, error) { return paramMap, nil } -func WorkflowParams(lp *admin.LaunchPlan) []*core.ParameterMapEntry { - workflowParams := []*core.ParameterMapEntry{} +func WorkflowParams(lp *admin.LaunchPlan) map[string]*core.Parameter { + workflowParams := map[string]*core.Parameter{} if lp == nil || lp.Spec == nil { return workflowParams } @@ -119,10 +119,10 @@ func WorkflowParams(lp *admin.LaunchPlan) []*core.ParameterMapEntry { func ParamMapForWorkflow(lp *admin.LaunchPlan) (map[string]yaml.Node, error) { workflowParams := WorkflowParams(lp) paramMap := make(map[string]yaml.Node, len(workflowParams)) - for _, e := range workflowParams { - varTypeValue, err := coreutils.MakeDefaultLiteralForType(e.Parameter.Var.Type) + for k, v := range workflowParams { + varTypeValue, err := coreutils.MakeDefaultLiteralForType(v.Var.Type) if err != nil { - fmt.Println("error creating default value for literal type ", e.Parameter.Var.Type) + fmt.Println("error creating default value for literal type ", v.Var.Type) return nil, err } var nativeLiteral interface{} @@ -130,16 +130,16 @@ func ParamMapForWorkflow(lp *admin.LaunchPlan) (map[string]yaml.Node, error) { return nil, err } // Override if there is a default value - if paramsDefault, ok := e.Parameter.Behavior.(*core.Parameter_Default); ok { + if paramsDefault, ok := v.Behavior.(*core.Parameter_Default); ok { if nativeLiteral, err = coreutils.ExtractFromLiteral(paramsDefault.Default); err != nil { return nil, err } } - if e.Name == e.Parameter.Var.Description { + if k == v.Var.Description { // a: # a isn't very helpful - paramMap[e.Name], err = getCommentedYamlNode(nativeLiteral, "") + paramMap[k], err = getCommentedYamlNode(nativeLiteral, "") } else { - paramMap[e.Name], err = getCommentedYamlNode(nativeLiteral, e.Parameter.Var.Description) + paramMap[k], err = getCommentedYamlNode(nativeLiteral, v.Var.Description) } if err != nil { diff --git a/flytectl/cmd/get/execution_util_test.go b/flytectl/cmd/get/execution_util_test.go index 5a2c53aee7..2d98c8b834 100644 --- a/flytectl/cmd/get/execution_util_test.go +++ b/flytectl/cmd/get/execution_util_test.go @@ -11,7 +11,7 @@ import ( ) func TestTaskInputs(t *testing.T) { - taskInputs := []*core.VariableMapEntry{} + taskInputs := map[string]*core.Variable{} t.Run("nil task", func(t *testing.T) { retValue := TaskInputs(nil) assert.Equal(t, taskInputs, retValue) @@ -60,14 +60,9 @@ func createTask() *admin.Task { }, } - variableMap := []*core.VariableMapEntry{ - { - Name: "sorted_list1", - Var: &sortedListLiteralType, - }, { - Name: "sorted_list2", - Var: &sortedListLiteralType, - }, + variableMap := map[string]*core.Variable{ + "sorted_list1": &sortedListLiteralType, + "sorted_list2": &sortedListLiteralType, } inputs := &core.VariableMap{ diff --git a/flytectl/cmd/get/launch_plan.go b/flytectl/cmd/get/launch_plan.go index dc19efeaa9..6ef85d6cb3 100644 --- a/flytectl/cmd/get/launch_plan.go +++ b/flytectl/cmd/get/launch_plan.go @@ -104,8 +104,8 @@ var launchplanColumns = []printer.Column{ {Header: "Type", JSONPath: "$.closure.compiledTask.template.type"}, {Header: "State", JSONPath: "$.spec.state"}, {Header: "Schedule", JSONPath: "$.spec.entityMetadata.schedule"}, - {Header: "Inputs", JSONPath: "$.closure.expectedInputs.parameters[0].parameter.var.description"}, - {Header: "Outputs", JSONPath: "$.closure.expectedOutputs.variables[0].var.description"}, + {Header: "Inputs", JSONPath: "$.closure.expectedInputs.parameters." + printer.DefaultFormattedDescriptionsKey + ".var.description"}, + {Header: "Outputs", JSONPath: "$.closure.expectedOutputs.variables." + printer.DefaultFormattedDescriptionsKey + ".description"}, } // Column structure for get all launchplans diff --git a/flytectl/cmd/get/launch_plan_test.go b/flytectl/cmd/get/launch_plan_test.go index cf944cf5e6..e6a7cbec01 100644 --- a/flytectl/cmd/get/launch_plan_test.go +++ b/flytectl/cmd/get/launch_plan_test.go @@ -39,10 +39,9 @@ func getLaunchPlanSetup() { // TODO: migrate to new command context from testutils cmdCtx = cmdCore.NewCommandContext(mockClient, u.MockOutStream) argsLp = []string{"launchplan1"} - parameterMap := []*core.ParameterMapEntry{ - { - Name: "numbers", - Parameter: &core.Parameter{Var: &core.Variable{ + parameterMap := map[string]*core.Parameter{ + "numbers": { + Var: &core.Variable{ Type: &core.LiteralType{ Type: &core.LiteralType_CollectionType{ CollectionType: &core.LiteralType{ @@ -52,21 +51,21 @@ func getLaunchPlanSetup() { }, }, }, - Description: "short desc"}}, + Description: "short desc", + }, }, - { - Name: "numbers_count", - Parameter: &core.Parameter{Var: &core.Variable{ + "numbers_count": { + Var: &core.Variable{ Type: &core.LiteralType{ Type: &core.LiteralType_Simple{ Simple: core.SimpleType_INTEGER, }, - }, Description: "long description will be truncated in table", - }}, + }, + Description: "long description will be truncated in table", + }, }, - { - Name: "run_local_at_count", - Parameter: &core.Parameter{Var: &core.Variable{ + "run_local_at_count": { + Var: &core.Variable{ Type: &core.LiteralType{ Type: &core.LiteralType_Simple{ Simple: core.SimpleType_INTEGER, @@ -74,21 +73,21 @@ func getLaunchPlanSetup() { }, Description: "run_local_at_count", }, - Behavior: &core.Parameter_Default{ - Default: &core.Literal{ - Value: &core.Literal_Scalar{ - Scalar: &core.Scalar{ - Value: &core.Scalar_Primitive{ - Primitive: &core.Primitive{ - Value: &core.Primitive_Integer{ - Integer: 10, - }, + Behavior: &core.Parameter_Default{ + Default: &core.Literal{ + Value: &core.Literal_Scalar{ + Scalar: &core.Scalar{ + Value: &core.Scalar_Primitive{ + Primitive: &core.Primitive{ + Value: &core.Primitive_Integer{ + Integer: 10, }, }, }, }, }, - }}, + }, + }, }, } launchPlan1 := &admin.LaunchPlan{ @@ -258,98 +257,80 @@ func TestGetLaunchPlanFunc(t *testing.T) { }, "spec": { "defaultInputs": { - "parameters": [ - { - "name": "numbers", - "parameter": { - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "short desc" - } + "parameters": { + "numbers": { + "var": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "short desc" } }, - { - "name": "numbers_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "long description will be truncated in table" - } + "numbers_count": { + "var": { + "type": { + "simple": "INTEGER" + }, + "description": "long description will be truncated in table" } }, - { - "name": "run_local_at_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "run_local_at_count" + "run_local_at_count": { + "var": { + "type": { + "simple": "INTEGER" }, - "default": { - "scalar": { - "primitive": { - "integer": "10" - } + "description": "run_local_at_count" + }, + "default": { + "scalar": { + "primitive": { + "integer": "10" } } } } - ] + } } }, "closure": { "expectedInputs": { - "parameters": [ - { - "name": "numbers", - "parameter": { - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "short desc" - } + "parameters": { + "numbers": { + "var": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "short desc" } }, - { - "name": "numbers_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "long description will be truncated in table" - } + "numbers_count": { + "var": { + "type": { + "simple": "INTEGER" + }, + "description": "long description will be truncated in table" } }, - { - "name": "run_local_at_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "run_local_at_count" + "run_local_at_count": { + "var": { + "type": { + "simple": "INTEGER" }, - "default": { - "scalar": { - "primitive": { - "integer": "10" - } + "description": "run_local_at_count" + }, + "default": { + "scalar": { + "primitive": { + "integer": "10" } } } } - ] + } }, "createdAt": "1970-01-01T00:00:01Z" } @@ -361,98 +342,80 @@ func TestGetLaunchPlanFunc(t *testing.T) { }, "spec": { "defaultInputs": { - "parameters": [ - { - "name": "numbers", - "parameter": { - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "short desc" - } + "parameters": { + "numbers": { + "var": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "short desc" } }, - { - "name": "numbers_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "long description will be truncated in table" - } + "numbers_count": { + "var": { + "type": { + "simple": "INTEGER" + }, + "description": "long description will be truncated in table" } }, - { - "name": "run_local_at_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "run_local_at_count" + "run_local_at_count": { + "var": { + "type": { + "simple": "INTEGER" }, - "default": { - "scalar": { - "primitive": { - "integer": "10" - } + "description": "run_local_at_count" + }, + "default": { + "scalar": { + "primitive": { + "integer": "10" } } } } - ] + } } }, "closure": { "expectedInputs": { - "parameters": [ - { - "name": "numbers", - "parameter": { - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "short desc" - } + "parameters": { + "numbers": { + "var": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "short desc" } }, - { - "name": "numbers_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "long description will be truncated in table" - } + "numbers_count": { + "var": { + "type": { + "simple": "INTEGER" + }, + "description": "long description will be truncated in table" } }, - { - "name": "run_local_at_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "run_local_at_count" + "run_local_at_count": { + "var": { + "type": { + "simple": "INTEGER" }, - "default": { - "scalar": { - "primitive": { - "integer": "10" - } + "description": "run_local_at_count" + }, + "default": { + "scalar": { + "primitive": { + "integer": "10" } } } } - ] + } }, "createdAt": "1970-01-01T00:00:00Z" } @@ -477,98 +440,80 @@ func TestGetLaunchPlanFuncLatest(t *testing.T) { }, "spec": { "defaultInputs": { - "parameters": [ - { - "name": "numbers", - "parameter": { - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "short desc" - } + "parameters": { + "numbers": { + "var": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "short desc" } }, - { - "name": "numbers_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "long description will be truncated in table" - } + "numbers_count": { + "var": { + "type": { + "simple": "INTEGER" + }, + "description": "long description will be truncated in table" } }, - { - "name": "run_local_at_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "run_local_at_count" + "run_local_at_count": { + "var": { + "type": { + "simple": "INTEGER" }, - "default": { - "scalar": { - "primitive": { - "integer": "10" - } + "description": "run_local_at_count" + }, + "default": { + "scalar": { + "primitive": { + "integer": "10" } } } } - ] + } } }, "closure": { "expectedInputs": { - "parameters": [ - { - "name": "numbers", - "parameter": { - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "short desc" - } + "parameters": { + "numbers": { + "var": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "short desc" } }, - { - "name": "numbers_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "long description will be truncated in table" - } + "numbers_count": { + "var": { + "type": { + "simple": "INTEGER" + }, + "description": "long description will be truncated in table" } }, - { - "name": "run_local_at_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "run_local_at_count" + "run_local_at_count": { + "var": { + "type": { + "simple": "INTEGER" }, - "default": { - "scalar": { - "primitive": { - "integer": "10" - } + "description": "run_local_at_count" + }, + "default": { + "scalar": { + "primitive": { + "integer": "10" } } } } - ] + } }, "createdAt": "1970-01-01T00:00:01Z" } @@ -592,98 +537,80 @@ func TestGetLaunchPlanWithVersion(t *testing.T) { }, "spec": { "defaultInputs": { - "parameters": [ - { - "name": "numbers", - "parameter": { - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "short desc" - } + "parameters": { + "numbers": { + "var": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "short desc" } }, - { - "name": "numbers_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "long description will be truncated in table" - } + "numbers_count": { + "var": { + "type": { + "simple": "INTEGER" + }, + "description": "long description will be truncated in table" } }, - { - "name": "run_local_at_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "run_local_at_count" + "run_local_at_count": { + "var": { + "type": { + "simple": "INTEGER" }, - "default": { - "scalar": { - "primitive": { - "integer": "10" - } + "description": "run_local_at_count" + }, + "default": { + "scalar": { + "primitive": { + "integer": "10" } } } } - ] + } } }, "closure": { "expectedInputs": { - "parameters": [ - { - "name": "numbers", - "parameter": { - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "short desc" - } + "parameters": { + "numbers": { + "var": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "short desc" } }, - { - "name": "numbers_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "long description will be truncated in table" - } + "numbers_count": { + "var": { + "type": { + "simple": "INTEGER" + }, + "description": "long description will be truncated in table" } }, - { - "name": "run_local_at_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "run_local_at_count" + "run_local_at_count": { + "var": { + "type": { + "simple": "INTEGER" }, - "default": { - "scalar": { - "primitive": { - "integer": "10" - } + "description": "run_local_at_count" + }, + "default": { + "scalar": { + "primitive": { + "integer": "10" } } } } - ] + } }, "createdAt": "1970-01-01T00:00:01Z" } @@ -698,214 +625,7 @@ func TestGetLaunchPlans(t *testing.T) { argsLp = []string{} err = getLaunchPlanFunc(ctx, argsLp, cmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `[ - { - "id": { - "name": "launchplan1", - "version": "v2" - }, - "spec": { - "defaultInputs": { - "parameters": [ - { - "name": "numbers", - "parameter": { - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "short desc" - } - } - }, - { - "name": "numbers_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "long description will be truncated in table" - } - } - }, - { - "name": "run_local_at_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "run_local_at_count" - }, - "default": { - "scalar": { - "primitive": { - "integer": "10" - } - } - } - } - } - ] - } - }, - "closure": { - "expectedInputs": { - "parameters": [ - { - "name": "numbers", - "parameter": { - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "short desc" - } - } - }, - { - "name": "numbers_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "long description will be truncated in table" - } - } - }, - { - "name": "run_local_at_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "run_local_at_count" - }, - "default": { - "scalar": { - "primitive": { - "integer": "10" - } - } - } - } - } - ] - }, - "createdAt": "1970-01-01T00:00:01Z" - } - }, - { - "id": { - "name": "launchplan1", - "version": "v1" - }, - "spec": { - "defaultInputs": { - "parameters": [ - { - "name": "numbers", - "parameter": { - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "short desc" - } - } - }, - { - "name": "numbers_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "long description will be truncated in table" - } - } - }, - { - "name": "run_local_at_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "run_local_at_count" - }, - "default": { - "scalar": { - "primitive": { - "integer": "10" - } - } - } - } - } - ] - } - }, - "closure": { - "expectedInputs": { - "parameters": [ - { - "name": "numbers", - "parameter": { - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "short desc" - } - } - }, - { - "name": "numbers_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "long description will be truncated in table" - } - } - }, - { - "name": "run_local_at_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "run_local_at_count" - }, - "default": { - "scalar": { - "primitive": { - "integer": "10" - } - } - } - } - } - ] - }, - "createdAt": "1970-01-01T00:00:00Z" - } - } -]`) + tearDownAndVerify(t, `[{"id": {"name": "launchplan1","version": "v2"},"spec": {"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}},{"id": {"name": "launchplan1","version": "v1"},"spec": {"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:00Z"}}]`) } func TestGetLaunchPlansWithExecFile(t *testing.T) { @@ -927,98 +647,80 @@ func TestGetLaunchPlansWithExecFile(t *testing.T) { }, "spec": { "defaultInputs": { - "parameters": [ - { - "name": "numbers", - "parameter": { - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "short desc" - } + "parameters": { + "numbers": { + "var": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "short desc" } }, - { - "name": "numbers_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "long description will be truncated in table" - } + "numbers_count": { + "var": { + "type": { + "simple": "INTEGER" + }, + "description": "long description will be truncated in table" } }, - { - "name": "run_local_at_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "run_local_at_count" + "run_local_at_count": { + "var": { + "type": { + "simple": "INTEGER" }, - "default": { - "scalar": { - "primitive": { - "integer": "10" - } + "description": "run_local_at_count" + }, + "default": { + "scalar": { + "primitive": { + "integer": "10" } } } } - ] + } } }, "closure": { "expectedInputs": { - "parameters": [ - { - "name": "numbers", - "parameter": { - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "short desc" - } + "parameters": { + "numbers": { + "var": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "short desc" } }, - { - "name": "numbers_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "long description will be truncated in table" - } + "numbers_count": { + "var": { + "type": { + "simple": "INTEGER" + }, + "description": "long description will be truncated in table" } }, - { - "name": "run_local_at_count", - "parameter": { - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "run_local_at_count" + "run_local_at_count": { + "var": { + "type": { + "simple": "INTEGER" }, - "default": { - "scalar": { - "primitive": { - "integer": "10" - } + "description": "run_local_at_count" + }, + "default": { + "scalar": { + "primitive": { + "integer": "10" } } } } - ] + } }, "createdAt": "1970-01-01T00:00:01Z" } diff --git a/flytectl/cmd/get/task.go b/flytectl/cmd/get/task.go index e3ce88e348..63b490ae82 100644 --- a/flytectl/cmd/get/task.go +++ b/flytectl/cmd/get/task.go @@ -3,8 +3,6 @@ package get import ( "context" - "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" - "github.com/flyteorg/flytectl/cmd/config" taskConfig "github.com/flyteorg/flytectl/cmd/config/subcommand/task" cmdCore "github.com/flyteorg/flytectl/cmd/core" @@ -99,8 +97,8 @@ var taskColumns = []printer.Column{ {Header: "Version", JSONPath: "$.id.version"}, {Header: "Name", JSONPath: "$.id.name"}, {Header: "Type", JSONPath: "$.closure.compiledTask.template.type"}, - {Header: "Inputs", JSONPath: "$.closure.compiledTask.template.interface.inputs.variables[0].var.description"}, - {Header: "Outputs", JSONPath: "$.closure.compiledTask.template.interface.outputs.variables[0].var.description"}, + {Header: "Inputs", JSONPath: "$.closure.compiledTask.template.interface.inputs.variables." + printer.DefaultFormattedDescriptionsKey + ".description"}, + {Header: "Outputs", JSONPath: "$.closure.compiledTask.template.interface.outputs.variables." + printer.DefaultFormattedDescriptionsKey + ".description"}, {Header: "Discoverable", JSONPath: "$.closure.compiledTask.template.metadata.discoverable"}, {Header: "Discovery Version", JSONPath: "$.closure.compiledTask.template.metadata.discoveryVersion"}, {Header: "Created At", JSONPath: "$.closure.createdAt"}, @@ -135,14 +133,6 @@ func TaskToTableProtoMessages(l []*admin.Task) []proto.Message { return messages } -func VariableMapEntriesToMap(mapFieldEntries []*core.VariableMapEntry) (variableMap map[string]*core.Variable) { - variableMap = map[string]*core.Variable{} - for _, e := range mapFieldEntries { - variableMap[e.Name] = e.Var - } - return -} - func getTaskFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { taskPrinter := printer.Printer{} var tasks []*admin.Task diff --git a/flytectl/cmd/get/task_test.go b/flytectl/cmd/get/task_test.go index dfed9cea1f..0133c20f46 100644 --- a/flytectl/cmd/get/task_test.go +++ b/flytectl/cmd/get/task_test.go @@ -54,14 +54,9 @@ func getTaskSetup() { }, Description: "var description", } - variableMap := []*core.VariableMapEntry{ - { - Name: "sorted_list1", - Var: &sortedListLiteralType, - }, { - Name: "sorted_list2", - Var: &sortedListLiteralType, - }, + variableMap := map[string]*core.Variable{ + "sorted_list1": &sortedListLiteralType, + "sorted_list2": &sortedListLiteralType, } task1 := &admin.Task{ @@ -261,30 +256,24 @@ func TestGetTaskFunc(t *testing.T) { "template": { "interface": { "inputs": { - "variables": [ - { - "name": "sorted_list1", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } + "variables": { + "sorted_list1": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "var description" }, - { - "name": "sorted_list2", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } + "sorted_list2": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "var description" } - ] + } } } } @@ -302,30 +291,24 @@ func TestGetTaskFunc(t *testing.T) { "template": { "interface": { "inputs": { - "variables": [ - { - "name": "sorted_list1", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } + "variables": { + "sorted_list1": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "var description" }, - { - "name": "sorted_list2", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } + "sorted_list2": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "var description" } - ] + } } } } @@ -380,30 +363,24 @@ func TestGetTaskFuncLatest(t *testing.T) { "template": { "interface": { "inputs": { - "variables": [ - { - "name": "sorted_list1", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } + "variables": { + "sorted_list1": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "var description" }, - { - "name": "sorted_list2", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } + "sorted_list2": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "var description" } - ] + } } } } @@ -435,30 +412,24 @@ func TestGetTaskWithVersion(t *testing.T) { "template": { "interface": { "inputs": { - "variables": [ - { - "name": "sorted_list1", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } + "variables": { + "sorted_list1": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "var description" }, - { - "name": "sorted_list2", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } + "sorted_list2": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "var description" } - ] + } } } } @@ -476,90 +447,7 @@ func TestGetTasks(t *testing.T) { mockClient.OnGetTaskMatch(ctx, objectGetRequestTask).Return(task2, nil) err = getTaskFunc(ctx, argsTask, cmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `[ - { - "id": { - "name": "task1", - "version": "v2" - }, - "closure": { - "compiledTask": { - "template": { - "interface": { - "inputs": { - "variables": [ - { - "name": "sorted_list1", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } - }, - { - "name": "sorted_list2", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } - } - ] - } - } - } - }, - "createdAt": "1970-01-01T00:00:01Z" - } - }, - { - "id": { - "name": "task1", - "version": "v1" - }, - "closure": { - "compiledTask": { - "template": { - "interface": { - "inputs": { - "variables": [ - { - "name": "sorted_list1", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } - }, - { - "name": "sorted_list2", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } - } - ] - } - } - } - }, - "createdAt": "1970-01-01T00:00:00Z" - } - } -]`) + tearDownAndVerify(t, `[{"id": {"name": "task1","version": "v2"},"closure": {"compiledTask": {"template": {"interface": {"inputs": {"variables": {"sorted_list1": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"},"sorted_list2": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}},{"id": {"name": "task1","version": "v1"},"closure": {"compiledTask": {"template": {"interface": {"inputs": {"variables": {"sorted_list1": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"},"sorted_list2": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"}}}}}},"createdAt": "1970-01-01T00:00:00Z"}}]`) } func TestGetTasksFilters(t *testing.T) { @@ -571,47 +459,7 @@ func TestGetTasksFilters(t *testing.T) { mockClient.OnListTasksMatch(ctx, resourceListFilterRequestTask).Return(taskListFilterResponse, nil) err = getTaskFunc(ctx, argsTask, cmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `{ - "id": { - "name": "task1", - "version": "v1" - }, - "closure": { - "compiledTask": { - "template": { - "interface": { - "inputs": { - "variables": [ - { - "name": "sorted_list1", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } - }, - { - "name": "sorted_list2", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } - } - ] - } - } - } - }, - "createdAt": "1970-01-01T00:00:00Z" - } -}`) + tearDownAndVerify(t, `{"id": {"name": "task1","version": "v1"},"closure": {"compiledTask": {"template": {"interface": {"inputs": {"variables": {"sorted_list1": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"},"sorted_list2": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"}}}}}},"createdAt": "1970-01-01T00:00:00Z"}}`) } func TestGetTaskWithExecFile(t *testing.T) { @@ -636,30 +484,24 @@ func TestGetTaskWithExecFile(t *testing.T) { "template": { "interface": { "inputs": { - "variables": [ - { - "name": "sorted_list1", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } + "variables": { + "sorted_list1": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "var description" }, - { - "name": "sorted_list2", - "var": { - "type": { - "collectionType": { - "simple": "INTEGER" - } - }, - "description": "var description" - } + "sorted_list2": { + "type": { + "collectionType": { + "simple": "INTEGER" + } + }, + "description": "var description" } - ] + } } } } diff --git a/flytectl/cmd/get/workflow.go b/flytectl/cmd/get/workflow.go index f461aac9e3..2670b7f10d 100644 --- a/flytectl/cmd/get/workflow.go +++ b/flytectl/cmd/get/workflow.go @@ -87,8 +87,8 @@ Usage var workflowColumns = []printer.Column{ {Header: "Version", JSONPath: "$.id.version"}, {Header: "Name", JSONPath: "$.id.name"}, - {Header: "Inputs", JSONPath: "$.closure.compiledWorkflow.primary.template.interface.inputs.variables[0].var.description"}, - {Header: "Outputs", JSONPath: "$.closure.compiledWorkflow.primary.template.interface.outputs.variables[0].var.description"}, + {Header: "Inputs", JSONPath: "$.closure.compiledWorkflow.primary.template.interface.inputs.variables." + printer.DefaultFormattedDescriptionsKey + ".description"}, + {Header: "Outputs", JSONPath: "$.closure.compiledWorkflow.primary.template.interface.outputs.variables." + printer.DefaultFormattedDescriptionsKey + ".description"}, {Header: "Created At", JSONPath: "$.closure.createdAt"}, } diff --git a/flytectl/cmd/get/workflow_test.go b/flytectl/cmd/get/workflow_test.go index 54c826d423..46ad846cdd 100644 --- a/flytectl/cmd/get/workflow_test.go +++ b/flytectl/cmd/get/workflow_test.go @@ -38,35 +38,31 @@ func getWorkflowSetup() { Domain: domainValue, }, } - variableMap := []*core.VariableMapEntry{ - { - Name: "var1", - Var: &core.Variable{ - Type: &core.LiteralType{ - Type: &core.LiteralType_CollectionType{ - CollectionType: &core.LiteralType{ - Type: &core.LiteralType_Simple{ - Simple: core.SimpleType_INTEGER, - }, + + variableMap := map[string]*core.Variable{ + "var1": { + Type: &core.LiteralType{ + Type: &core.LiteralType_CollectionType{ + CollectionType: &core.LiteralType{ + Type: &core.LiteralType_Simple{ + Simple: core.SimpleType_INTEGER, }, }, }, - Description: "var1", }, - }, { - Name: "var2", - Var: &core.Variable{ - Type: &core.LiteralType{ - Type: &core.LiteralType_CollectionType{ - CollectionType: &core.LiteralType{ - Type: &core.LiteralType_Simple{ - Simple: core.SimpleType_INTEGER, - }, + Description: "var1", + }, + "var2": { + Type: &core.LiteralType{ + Type: &core.LiteralType_CollectionType{ + CollectionType: &core.LiteralType{ + Type: &core.LiteralType_Simple{ + Simple: core.SimpleType_INTEGER, }, }, }, - Description: "var2 long descriptions probably needs truncate", }, + Description: "var2 long descriptions probably needs truncate", }, } workflow1 = &admin.Workflow{ diff --git a/flytectl/go.mod b/flytectl/go.mod index 1873b540e2..94ef0c7047 100644 --- a/flytectl/go.mod +++ b/flytectl/go.mod @@ -11,7 +11,7 @@ require ( github.com/docker/docker v20.10.7+incompatible github.com/docker/go-connections v0.4.0 github.com/enescakir/emoji v1.0.0 - github.com/flyteorg/flyteidl v0.20.2 + github.com/flyteorg/flyteidl v0.21.0 github.com/flyteorg/flytestdlib v0.3.34 github.com/ghodss/yaml v1.0.0 github.com/golang/protobuf v1.4.3 diff --git a/flytectl/go.sum b/flytectl/go.sum index 1c820fdecf..b482ad192a 100644 --- a/flytectl/go.sum +++ b/flytectl/go.sum @@ -345,8 +345,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= -github.com/flyteorg/flyteidl v0.20.2 h1:3DDj1y9Axmb35SskN/h2nRgohWhGBPGxmJSX7b/Y2rk= -github.com/flyteorg/flyteidl v0.20.2/go.mod h1:576W2ViEyjTpT+kEVHAGbrTP3HARNUZ/eCwrNPmdx9U= +github.com/flyteorg/flyteidl v0.21.0 h1:AwHNusfxJMfRRSDk2QWfb3aIlyLJrFWVGtpXCbCtJ5A= +github.com/flyteorg/flyteidl v0.21.0/go.mod h1:576W2ViEyjTpT+kEVHAGbrTP3HARNUZ/eCwrNPmdx9U= github.com/flyteorg/flytestdlib v0.3.13/go.mod h1:Tz8JCECAbX6VWGwFT6cmEQ+RJpZ/6L9pswu3fzWs220= github.com/flyteorg/flytestdlib v0.3.34 h1:OOuV03X8c1AWInzBU6IRsqpEF6y8WDJngbPcdL4VktY= github.com/flyteorg/flytestdlib v0.3.34/go.mod h1:7cDWkY3v7xsoesFcDdu6DSW5Q2U2W5KlHUbUHSwBG1Q= diff --git a/flytectl/pkg/ext/launch_plan_fetcher_test.go b/flytectl/pkg/ext/launch_plan_fetcher_test.go index e38d0d054e..39d0121c93 100644 --- a/flytectl/pkg/ext/launch_plan_fetcher_test.go +++ b/flytectl/pkg/ext/launch_plan_fetcher_test.go @@ -27,10 +27,9 @@ func getLaunchPlanFetcherSetup() { adminClient = new(mocks.AdminServiceClient) adminFetcherExt = AdminFetcherExtClient{AdminClient: adminClient} - parameterMap := []*core.ParameterMapEntry{ - { - Name: "numbers", - Parameter: &core.Parameter{Var: &core.Variable{ + parameterMap := map[string]*core.Parameter{ + "numbers": { + Var: &core.Variable{ Type: &core.LiteralType{ Type: &core.LiteralType_CollectionType{ CollectionType: &core.LiteralType{ @@ -40,42 +39,40 @@ func getLaunchPlanFetcherSetup() { }, }, }, - }}, + }, }, - { - Name: "numbers_count", - Parameter: &core.Parameter{Var: &core.Variable{ + "numbers_count": { + Var: &core.Variable{ Type: &core.LiteralType{ Type: &core.LiteralType_Simple{ Simple: core.SimpleType_INTEGER, }, }, - }}, + }, }, - { - Name: "run_local_at_count", - Parameter: &core.Parameter{Var: &core.Variable{ + "run_local_at_count": { + Var: &core.Variable{ Type: &core.LiteralType{ Type: &core.LiteralType_Simple{ Simple: core.SimpleType_INTEGER, }, }, }, - Behavior: &core.Parameter_Default{ - Default: &core.Literal{ - Value: &core.Literal_Scalar{ - Scalar: &core.Scalar{ - Value: &core.Scalar_Primitive{ - Primitive: &core.Primitive{ - Value: &core.Primitive_Integer{ - Integer: 10, - }, + Behavior: &core.Parameter_Default{ + Default: &core.Literal{ + Value: &core.Literal_Scalar{ + Scalar: &core.Scalar{ + Value: &core.Scalar_Primitive{ + Primitive: &core.Primitive{ + Value: &core.Primitive_Integer{ + Integer: 10, }, }, }, }, }, - }}, + }, + }, }, } launchPlan1 = &admin.LaunchPlan{ diff --git a/flytectl/pkg/ext/task_fetcher_test.go b/flytectl/pkg/ext/task_fetcher_test.go index 50d14e2144..0bfc9ef8dd 100644 --- a/flytectl/pkg/ext/task_fetcher_test.go +++ b/flytectl/pkg/ext/task_fetcher_test.go @@ -41,14 +41,9 @@ func getTaskFetcherSetup() { }, }, } - variableMap := []*core.VariableMapEntry{ - { - Name: "sorted_list1", - Var: &sortedListLiteralType, - }, { - Name: "sorted_list2", - Var: &sortedListLiteralType, - }, + variableMap := map[string]*core.Variable{ + "sorted_list1": &sortedListLiteralType, + "sorted_list2": &sortedListLiteralType, } task1 := &admin.Task{ diff --git a/flytectl/pkg/ext/workflow_fetcher_test.go b/flytectl/pkg/ext/workflow_fetcher_test.go index c8da9b2373..9ae96612a6 100644 --- a/flytectl/pkg/ext/workflow_fetcher_test.go +++ b/flytectl/pkg/ext/workflow_fetcher_test.go @@ -38,14 +38,9 @@ func getWorkflowFetcherSetup() { }, }, } - variableMap := []*core.VariableMapEntry{ - { - Name: "sorted_list1", - Var: &sortedListLiteralType, - }, { - Name: "sorted_list2", - Var: &sortedListLiteralType, - }, + variableMap := map[string]*core.Variable{ + "sorted_list1": &sortedListLiteralType, + "sorted_list2": &sortedListLiteralType, } var compiledTasks []*core.CompiledTask diff --git a/flytectl/pkg/printer/printer.go b/flytectl/pkg/printer/printer.go index 0f11d15ac7..75d67208eb 100644 --- a/flytectl/pkg/printer/printer.go +++ b/flytectl/pkg/printer/printer.go @@ -6,6 +6,7 @@ import ( "fmt" "net/url" "os" + "sort" "strings" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" @@ -169,37 +170,50 @@ func printJSONYaml(format OutputFormat, v interface{}) error { return nil } -func FormatVariableDescriptions(variableMap []*core.VariableMapEntry) { +func FormatVariableDescriptions(variableMap map[string]*core.Variable) { + keys := make([]string, 0, len(variableMap)) + // sort the keys for testing and consistency with other output formats + for k := range variableMap { + keys = append(keys, k) + } + sort.Strings(keys) + var descriptions []string - for _, e := range variableMap { - if e.Var == nil { - continue - } + for _, k := range keys { + v := variableMap[k] // a: a isn't very helpful - if e.Name != e.Var.Description { - descriptions = append(descriptions, getTruncatedLine(fmt.Sprintf("%s: %s", e.Name, e.Var.Description))) + if k != v.Description { + descriptions = append(descriptions, getTruncatedLine(fmt.Sprintf("%s: %s", k, v.Description))) } else { - descriptions = append(descriptions, getTruncatedLine(e.Name)) + descriptions = append(descriptions, getTruncatedLine(k)) } } - variableMap[0] = &core.VariableMapEntry{Var: &core.Variable{Description: strings.Join(descriptions, "\n")}} + variableMap[DefaultFormattedDescriptionsKey] = &core.Variable{Description: strings.Join(descriptions, "\n")} } -func FormatParameterDescriptions(parameterMap []*core.ParameterMapEntry) { +func FormatParameterDescriptions(parameterMap map[string]*core.Parameter) { + keys := make([]string, 0, len(parameterMap)) + // sort the keys for testing and consistency with other output formats + for k := range parameterMap { + keys = append(keys, k) + } + sort.Strings(keys) + var descriptions []string - for _, e := range parameterMap { - if e.Parameter == nil || e.Parameter.Var == nil { + for _, k := range keys { + v := parameterMap[k] + if v.Var == nil { continue } // a: a isn't very helpful - if e.Name != e.Parameter.Var.Description { - descriptions = append(descriptions, getTruncatedLine(fmt.Sprintf("%s: %s", e.Name, e.Parameter.Var.Description))) + if k != v.Var.Description { + descriptions = append(descriptions, getTruncatedLine(fmt.Sprintf("%s: %s", k, v.Var.Description))) } else { - descriptions = append(descriptions, getTruncatedLine(e.Name)) + descriptions = append(descriptions, getTruncatedLine(k)) } } - parameterMap[0] = &core.ParameterMapEntry{Parameter: &core.Parameter{Var: &core.Variable{Description: strings.Join(descriptions, "\n")}}} + parameterMap[DefaultFormattedDescriptionsKey] = &core.Parameter{Var: &core.Variable{Description: strings.Join(descriptions, "\n")}} } func getTruncatedLine(line string) string { diff --git a/flytectl/pkg/printer/printer_test.go b/flytectl/pkg/printer/printer_test.go index 1d0ee4e15c..6d5441b9af 100644 --- a/flytectl/pkg/printer/printer_test.go +++ b/flytectl/pkg/printer/printer_test.go @@ -150,15 +150,9 @@ func TestPrint(t *testing.T) { }, }, } - variableMap := []*core.VariableMapEntry{ - { - Name: "sorted_list1", - Var: &sortedListLiteralType, - }, - { - Name: "sorted_list2", - Var: &sortedListLiteralType, - }, + variableMap := map[string]*core.Variable{ + "sorted_list1": &sortedListLiteralType, + "sorted_list2": &sortedListLiteralType, } var compiledTasks []*core.CompiledTask @@ -281,26 +275,14 @@ func TestFormatVariableDescriptions(t *testing.T) { barVar := &core.Variable{ Description: "bar", } - variableMap := []*core.VariableMapEntry{ - { - Name: "var1", - Var: fooVar, - }, - { - Name: "var2", - Var: barVar, - }, - { - Name: "foo", - Var: fooVar, - }, - { - Name: "bar", - Var: barVar, - }, + variableMap := map[string]*core.Variable{ + "var1": fooVar, + "var2": barVar, + "foo": fooVar, + "bar": barVar, } FormatVariableDescriptions(variableMap) - assert.Equal(t, "var1: foo\nvar2: bar\nfoo\nbar", variableMap[0].Var.Description) + assert.Equal(t, "bar\nfoo\nvar1: foo\nvar2: bar", variableMap[DefaultFormattedDescriptionsKey].Description) } func TestFormatParameterDescriptions(t *testing.T) { @@ -315,28 +297,13 @@ func TestFormatParameterDescriptions(t *testing.T) { }, } emptyParam := &core.Parameter{} - paramMap := []*core.ParameterMapEntry{ - { - Name: "var1", - Parameter: fooParam, - }, - { - Name: "var2", - Parameter: barParam, - }, - { - Name: "foo", - Parameter: fooParam, - }, - { - Name: "bar", - Parameter: barParam, - }, - { - Name: "empty", - Parameter: emptyParam, - }, + paramMap := map[string]*core.Parameter{ + "var1": fooParam, + "var2": barParam, + "foo": fooParam, + "bar": barParam, + "empty": emptyParam, } FormatParameterDescriptions(paramMap) - assert.Equal(t, "var1: foo\nvar2: bar\nfoo\nbar", paramMap[0].Parameter.Var.Description) + assert.Equal(t, "bar\nfoo\nvar1: foo\nvar2: bar", paramMap[DefaultFormattedDescriptionsKey].Var.Description) } diff --git a/flytectl/pkg/visualize/testdata/compiled_closure_branch_nested.json b/flytectl/pkg/visualize/testdata/compiled_closure_branch_nested.json index 6b7330e1d7..baae3d9926 100644 --- a/flytectl/pkg/visualize/testdata/compiled_closure_branch_nested.json +++ b/flytectl/pkg/visualize/testdata/compiled_closure_branch_nested.json @@ -11,30 +11,24 @@ "metadata": {}, "interface": { "inputs": { - "variables": [ - { - "name": "my_input", - "var": { - "type": { - "simple": "FLOAT" - }, - "description": "my_input" - } + "variables": { + "my_input": { + "type": { + "simple": "FLOAT" + }, + "description": "my_input" } - ] + } }, "outputs": { - "variables": [ - { - "name": "o0", - "var": { - "type": { - "simple": "FLOAT" - }, - "description": "o0" - } + "variables": { + "o0": { + "type": { + "simple": "FLOAT" + }, + "description": "o0" } - ] + } } }, "nodes": [ @@ -233,7 +227,7 @@ ], "error": { "failedNodeId": "inner_fractions", - "message": "Only <0.7 allowed" + "message": "Only \u003c0.7 allowed" } } } @@ -430,30 +424,24 @@ }, "interface": { "inputs": { - "variables": [ - { - "name": "n", - "var": { - "type": { - "simple": "FLOAT" - }, - "description": "n" - } + "variables": { + "n": { + "type": { + "simple": "FLOAT" + }, + "description": "n" } - ] + } }, "outputs": { - "variables": [ - { - "name": "o0", - "var": { - "type": { - "simple": "FLOAT" - }, - "description": "o0" - } + "variables": { + "o0": { + "type": { + "simple": "FLOAT" + }, + "description": "o0" } - ] + } } }, "container": { @@ -509,30 +497,24 @@ }, "interface": { "inputs": { - "variables": [ - { - "name": "n", - "var": { - "type": { - "simple": "FLOAT" - }, - "description": "n" - } + "variables": { + "n": { + "type": { + "simple": "FLOAT" + }, + "description": "n" } - ] + } }, "outputs": { - "variables": [ - { - "name": "o0", - "var": { - "type": { - "simple": "FLOAT" - }, - "description": "o0" - } + "variables": { + "o0": { + "type": { + "simple": "FLOAT" + }, + "description": "o0" } - ] + } } }, "container": { diff --git a/flytectl/pkg/visualize/testdata/compiled_subworkflows.json b/flytectl/pkg/visualize/testdata/compiled_subworkflows.json index b46a334701..8bbf441367 100644 --- a/flytectl/pkg/visualize/testdata/compiled_subworkflows.json +++ b/flytectl/pkg/visualize/testdata/compiled_subworkflows.json @@ -11,48 +11,36 @@ "metadata": {}, "interface": { "inputs": { - "variables": [ - { - "name": "a", - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "a" - } + "variables": { + "a": { + "type": { + "simple": "INTEGER" + }, + "description": "a" } - ] + } }, "outputs": { - "variables": [ - { - "name": "o0", - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "o0" - } + "variables": { + "o0": { + "type": { + "simple": "INTEGER" + }, + "description": "o0" }, - { - "name": "o1", - "var": { - "type": { - "simple": "STRING" - }, - "description": "o1" - } + "o1": { + "type": { + "simple": "STRING" + }, + "description": "o1" }, - { - "name": "o2", - "var": { - "type": { - "simple": "STRING" - }, - "description": "o2" - } + "o2": { + "type": { + "simple": "STRING" + }, + "description": "o2" } - ] + } } }, "nodes": [ @@ -234,39 +222,30 @@ "metadata": {}, "interface": { "inputs": { - "variables": [ - { - "name": "a", - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "a" - } + "variables": { + "a": { + "type": { + "simple": "INTEGER" + }, + "description": "a" } - ] + } }, "outputs": { - "variables": [ - { - "name": "o0", - "var": { - "type": { - "simple": "STRING" - }, - "description": "o0" - } + "variables": { + "o0": { + "type": { + "simple": "STRING" + }, + "description": "o0" }, - { - "name": "o1", - "var": { - "type": { - "simple": "STRING" - }, - "description": "o1" - } + "o1": { + "type": { + "simple": "STRING" + }, + "description": "o1" } - ] + } } }, "nodes": [ @@ -440,39 +419,30 @@ }, "interface": { "inputs": { - "variables": [ - { - "name": "a", - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "a" - } + "variables": { + "a": { + "type": { + "simple": "INTEGER" + }, + "description": "a" } - ] + } }, "outputs": { - "variables": [ - { - "name": "c", - "var": { - "type": { - "simple": "STRING" - }, - "description": "c" - } + "variables": { + "c": { + "type": { + "simple": "STRING" + }, + "description": "c" }, - { - "name": "t1_int_output", - "var": { - "type": { - "simple": "INTEGER" - }, - "description": "t1_int_output" - } + "t1_int_output": { + "type": { + "simple": "INTEGER" + }, + "description": "t1_int_output" } - ] + } } }, "container": { @@ -508,4 +478,5 @@ } } ] -} \ No newline at end of file +} +