-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/get workflow,Task,Domain,Project (#9)
- Loading branch information
Showing
15 changed files
with
352 additions
and
598 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,30 @@ | ||
# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES. | ||
# ONLY EDIT THIS FILE FROM WITHIN THE 'LYFT/BOILERPLATE' REPOSITORY: | ||
# | ||
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst | ||
|
||
run: | ||
skip-dirs: | ||
- pkg/client | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
- deadcode | ||
- errcheck | ||
- gas | ||
- goconst | ||
- goimports | ||
- golint | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- misspell | ||
- nakedret | ||
- staticcheck | ||
- structcheck | ||
- typecheck | ||
- unconvert | ||
- unparam | ||
- unused | ||
- varcheck |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package core | ||
package cmdcore | ||
|
||
import ( | ||
"io" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package core | ||
package cmdcore | ||
|
||
import "context" | ||
|
||
|
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,56 @@ | ||
package get | ||
|
||
import ( | ||
"context" | ||
"github.com/lyft/flytectl/cmd/config" | ||
"encoding/json" | ||
cmdCore "github.com/lyft/flytectl/cmd/core" | ||
"github.com/lyft/flytectl/pkg/printer" | ||
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/admin" | ||
"github.com/lyft/flytestdlib/logger" | ||
) | ||
|
||
type PrintableProject struct { | ||
Id string `header:"Id"` | ||
Name string `header:"Name"` | ||
Description string `header:"Description"` | ||
} | ||
|
||
var tableStructure = map[string]string{ | ||
"Id" : "$.id", | ||
"Name" : "$.name", | ||
"Description" : "$.description", | ||
} | ||
|
||
|
||
func getProjectsFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { | ||
adminPrinter := printer.Printer{} | ||
|
||
transformProject := func(jsonbody [] byte)(interface{},error){ | ||
results := PrintableProject{} | ||
if err := json.Unmarshal(jsonbody, &results); err != nil { | ||
return results,err | ||
} | ||
return results,nil | ||
} | ||
if len(args) == 1 { | ||
projects, err := cmdCtx.AdminClient().ListProjects(ctx, &admin.ProjectListRequest{}) | ||
if err != nil { | ||
return err | ||
} | ||
logger.Debugf(ctx, "Retrieved %v projects", len(projects.Projects)) | ||
for _, v := range projects.Projects { | ||
if v.Name == args[0] { | ||
adminPrinter.Print(config.GetConfig().Output, projects.Projects,tableStructure,transformProject) | ||
} | ||
} | ||
return nil | ||
} | ||
projects, err := cmdCtx.AdminClient().ListProjects(ctx, &admin.ProjectListRequest{}) | ||
if err != nil { | ||
return err | ||
} | ||
logger.Debugf(ctx, "Retrieved %v projects", len(projects.Projects)) | ||
adminPrinter.Print(config.GetConfig().Output, projects.Projects,tableStructure,transformProject) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package get | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/lyft/flytectl/cmd/config" | ||
cmdCore "github.com/lyft/flytectl/cmd/core" | ||
"github.com/lyft/flytectl/pkg/printer" | ||
"github.com/lyft/flytestdlib/logger" | ||
|
||
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/admin" | ||
) | ||
|
||
type PrintableTask struct { | ||
Version string `header:"Version"` | ||
Name string `header:"Name"` | ||
Type string `header:"Type"` | ||
Discoverable bool `header:"Discoverable"` | ||
DiscoveryVersion string `header:"DiscoveryVersion"` | ||
} | ||
|
||
var taskStructure = map[string]string{ | ||
"Version" : "$.id.version", | ||
"Name" : "$.id.name", | ||
"Type" : "$.closure.compiledTask.template.type", | ||
"Discoverable" : "$.closure.compiledTask.template.metadata.discoverable", | ||
"DiscoveryVersion" : "$.closure.compiledTask.template.metadata.discovery_version", | ||
} | ||
|
||
var transformTask = func(jsonbody [] byte)(interface{},error){ | ||
results := PrintableTask{} | ||
if err := json.Unmarshal(jsonbody, &results); err != nil { | ||
return results,err | ||
} | ||
return results,nil | ||
} | ||
|
||
func getTaskFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { | ||
if config.GetConfig().Project == "" { | ||
return fmt.Errorf("Please set project name to get domain") | ||
} | ||
if config.GetConfig().Domain == "" { | ||
return fmt.Errorf("Please set project name to get workflow") | ||
} | ||
taskPrinter := printer.Printer{ | ||
} | ||
|
||
if len(args) == 1 { | ||
task, err := cmdCtx.AdminClient().ListTasks(ctx, &admin.ResourceListRequest{ | ||
Id: &admin.NamedEntityIdentifier{ | ||
Project: config.GetConfig().Project, | ||
Domain: config.GetConfig().Domain, | ||
Name: args[0], | ||
}, | ||
Limit: 10, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
logger.Debugf(ctx, "Retrieved Task", task.Tasks) | ||
|
||
taskPrinter.Print(config.GetConfig().Output, task.Tasks,taskStructure,transformTask) | ||
return nil | ||
} | ||
|
||
tasks, err := cmdCtx.AdminClient().ListTaskIds(ctx, &admin.NamedEntityIdentifierListRequest{ | ||
Project: config.GetConfig().Project, | ||
Domain: config.GetConfig().Domain, | ||
Limit: 3, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
logger.Debugf(ctx, "Retrieved %v Task", len(tasks.Entities)) | ||
taskPrinter.Print(config.GetConfig().Output, tasks.Entities,entityStructure,transformTaskEntity) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package get | ||
|
||
import "encoding/json" | ||
|
||
type PrintableNamedEntityIdentifier struct { | ||
Name string `header:"Name"` | ||
Project string `header:"Project"` | ||
Domain string `header:"Domain"` | ||
} | ||
|
||
var entityStructure = map[string]string{ | ||
"Domain" : "$.domain", | ||
"Name" : "$.name", | ||
"Project" : "$.project", | ||
} | ||
|
||
var transformTaskEntity = func(jsonbody [] byte)(interface{},error){ | ||
results := PrintableNamedEntityIdentifier{} | ||
if err := json.Unmarshal(jsonbody, &results); err != nil { | ||
return results,err | ||
} | ||
return results,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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package get | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/lyft/flytectl/cmd/config" | ||
cmdCore "github.com/lyft/flytectl/cmd/core" | ||
"github.com/lyft/flytectl/pkg/printer" | ||
"github.com/lyft/flytestdlib/logger" | ||
|
||
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/admin" | ||
) | ||
|
||
var workflowStructure = map[string]string{ | ||
"Version" : "$.id.version", | ||
"Name" : "$.id.name", | ||
} | ||
|
||
type PrintableWorkflow struct { | ||
Name string `header:"Name"` | ||
Version string `header:"Version"` | ||
} | ||
|
||
var transformWorkflow = func(jsonbody [] byte)(interface{},error){ | ||
results := PrintableWorkflow{} | ||
if err := json.Unmarshal(jsonbody, &results); err != nil { | ||
return results,err | ||
} | ||
return results,nil | ||
} | ||
|
||
|
||
func getWorkflowFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { | ||
if config.GetConfig().Project == "" { | ||
return fmt.Errorf("Please set project name to get domain") | ||
} | ||
if config.GetConfig().Domain == "" { | ||
return fmt.Errorf("Please set project name to get workflow") | ||
} | ||
adminPrinter := printer.Printer{ | ||
} | ||
if len(args) > 0 { | ||
workflows, err := cmdCtx.AdminClient().ListWorkflows(ctx, &admin.ResourceListRequest{ | ||
Id: &admin.NamedEntityIdentifier{ | ||
Project: config.GetConfig().Project, | ||
Domain: config.GetConfig().Domain, | ||
Name: args[0], | ||
}, | ||
Limit: 10, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
logger.Debugf(ctx, "Retrieved %v workflows", len(workflows.Workflows)) | ||
|
||
adminPrinter.Print(config.GetConfig().Output, workflows.Workflows,workflowStructure,transformWorkflow) | ||
return nil | ||
} | ||
workflows, err := cmdCtx.AdminClient().ListWorkflowIds(ctx, &admin.NamedEntityIdentifierListRequest{ | ||
Project: config.GetConfig().Project, | ||
Domain: config.GetConfig().Domain, | ||
Limit: 10, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
logger.Debugf(ctx, "Retrieved %v workflows", len(workflows.Entities)) | ||
|
||
adminPrinter.Print(config.GetConfig().Output, workflows.Entities,entityStructure,transformTaskEntity) | ||
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
Oops, something went wrong.