Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
Refactored as per discussion but this results in circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
pmahindrakar-oss committed Mar 18, 2021
1 parent e679d2b commit eb468e2
Show file tree
Hide file tree
Showing 16 changed files with 856 additions and 359 deletions.
110 changes: 20 additions & 90 deletions cmd/create/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ package create
import (
"context"
"fmt"
"strings"

cmdCore "github.com/flyteorg/flytectl/cmd/core"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"

"github.com/google/uuid"
)

const (
Expand Down Expand Up @@ -86,112 +81,47 @@ Usage

//go:generate pflags ExecutionConfig --default-var executionConfig

// ProjectConfig Config hold configuration for project create flags.
// ExecutionConfig hold configuration for create execution flags and configuration of the actual task or workflow to be launched.
type ExecutionConfig struct {
File string `json:"file,omitempty" pflag:",file for the execution params.If not specified defaults to <<workflow/task>_name>.inputs.yaml"`
GenExecSpecFile bool `json:"genExecSpecFile,omitempty" pflag:",bool flag to indicate the generation of execution spec file."`
Workflow string `json:"workflow,omitempty" pflag:",workflow name for which execution needs to be launched.Either an execution can be for task or workflow."`
SourceDomain string `json:"sourceDomain" pflag:",domain from where the workflow or task needs to be fetched for creating the execution.This is mandatory if file is not specified."`
SourceProject string `json:"sourceProject" pflag:",project from where the workflow or task needs to be fetched for creating the execution.This is mandatory if file is not specified."`
TargetDomain string `json:"targetDomain" pflag:",project where execution needs to be created.If not specified sourceDomain would be used."`
TargetProject string `json:"targetProject" pflag:",project where execution needs to be created.If not specified sourceProject would be used."`
Task string `json:"task,omitempty" pflag:",task name for which execution needs to be launched.Either an execution can be for task or workflow."`
KubeServiceAcct string `json:"kubeServiceAcct" pflag:",kubernetes service account AuthRole for launching execution."`
IamRoleURN string `json:"iamRoleURN" pflag:",iam role URN AuthRole for launching execution."`
Version string `json:"version" pflag:",version of the launch plan or task to be fetched for execution.If not specified it would use the latest version."`
Inputs map[string]interface{} `json:"inputs" pflag:",inputs in the form of key value pair to be passed for launching task or workflow.If the value is array then pass it using comma separated values."`
// pflag section
File string `json:"file,omitempty" pflag:",file for the execution params.If not specified defaults to <<workflow/task>_name>.execution_spec.yaml"`
TargetDomain string `json:"targetDomain" pflag:",project where execution needs to be created.If not specified configured domain would be used."`
TargetProject string `json:"targetProject" pflag:",project where execution needs to be created.If not specified configured project would be used."`
KubeServiceAcct string `json:"kubeServiceAcct" pflag:",kubernetes service account AuthRole for launching execution."`
IamRoleARN string `json:"iamRoleARN" pflag:",iam role ARN AuthRole for launching execution."`
// Non plfag section is read from the execution config generated by get task/launchplan
Workflow string `json:"workflow,omitempty"`
Task string `json:"task,omitempty"`
Version string `json:"version"`
Inputs map[string]interface{} `json:"inputs"`
}

type ExecutionParams struct {
name string
fileName string
isTask bool
isConfigFromFile bool
name string
isTask bool
}

var (
executionConfig = &ExecutionConfig{
IamRoleURN: "example: arn:aws:iam::12345678:role/defaultrole",
}
executionConfig = &ExecutionConfig{}
)

func createExecutionCommand(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error {
var execParams *ExecutionParams
var err error
if execParams, err = getConfigAndValidate(); err != nil {
if execParams, err = readConfigAndValidate(); err != nil {
return err
}
var lp *admin.LaunchPlan
var task *admin.Task
var authRole *admin.AuthRole
var ID *core.Identifier
var executionRequest *admin.ExecutionCreateRequest
if execParams.isTask {
if task, err = getTask(ctx, execParams.name, cmdCtx); err != nil {
if executionRequest, err = createExecutionRequestForTask(ctx, execParams.name, cmdCtx); err != nil {
return err
}
if executionConfig.KubeServiceAcct != "" {
authRole = &admin.AuthRole{Method: &admin.AuthRole_KubernetesServiceAccount{
KubernetesServiceAccount: executionConfig.KubeServiceAcct}}
} else {
authRole = &admin.AuthRole{Method: &admin.AuthRole_AssumableIamRole{
AssumableIamRole: executionConfig.IamRoleURN}}
}
ID = &core.Identifier{
ResourceType: core.ResourceType_TASK,
Project: executionConfig.TargetProject,
Domain: executionConfig.TargetDomain,
Name: task.Id.Name,
Version: task.Id.Version,
}
} else {
if lp, err = getLaunchPlan(ctx, execParams.name, cmdCtx, executionConfig); err != nil {
if executionRequest, err = createExecutionRequestForWorkflow(ctx, execParams.name, cmdCtx); err != nil {
return err
}
ID = lp.Id
}

if !execParams.isConfigFromFile && executionConfig.GenExecSpecFile {
if err = updateInputsForExecution(execParams, lp, task); err != nil {
return err
}
if err = writeExecConfigToFile(execParams.fileName); err != nil {
return err
}
fmt.Printf("execution spec written to file %v\n", execParams.fileName)
fmt.Printf("run followup command\nflytectl create execution --file %v\n", execParams.fileName)
return nil
}
// Convert to Literal map
var deserializedVal map[string]*core.Literal
fmt.Printf("%v", executionConfig.Inputs)
if execParams.isTask {
if deserializedVal, err = MakeLiteralForVariables(executionConfig.Inputs, task.Closure.CompiledTask.Template.Interface.Inputs.Variables); err != nil {
fmt.Printf("%v", err)
return err
}
} else {
if deserializedVal, err = MakeLiteralForParams(executionConfig.Inputs, lp.Spec.DefaultInputs.Parameters); err != nil {
return err
}
}
var inputs = &core.LiteralMap{
Literals: deserializedVal,
}
exec, _err := cmdCtx.AdminClient().CreateExecution(ctx, &admin.ExecutionCreateRequest{
Project: executionConfig.TargetProject,
Domain: executionConfig.TargetDomain,
Name: "f" + strings.ReplaceAll(uuid.New().String(), "-", "")[:19],
Spec: &admin.ExecutionSpec{
LaunchPlan: ID,
Metadata: &admin.ExecutionMetadata{
Mode: admin.ExecutionMetadata_MANUAL,
Principal: "sdk",
Nesting: 0,
},
AuthRole: authRole,
},
Inputs: inputs,
})
exec, _err := cmdCtx.AdminClient().CreateExecution(ctx, executionRequest)
if _err != nil {
return _err
}
Expand Down
Loading

0 comments on commit eb468e2

Please sign in to comment.