Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish between regular and extended app describe #298

Merged
merged 3 commits into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cmd/meroxa/root/apps/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ func (d *Deploy) deploy(ctx context.Context, appPath string, l log.Logger) (stri
// creates all resources
output, err := turbineGo.RunDeployApp(ctx, l, appPath, d.appName, fqImageName)
if err != nil {
l.Errorf(ctx, "unable to deploy app; %s", err)
return output, err
}
return output, nil
Expand Down
46 changes: 45 additions & 1 deletion cmd/meroxa/root/apps/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ import (
var (
_ builder.CommandWithDocs = (*Describe)(nil)
_ builder.CommandWithArgs = (*Describe)(nil)
_ builder.CommandWithFlags = (*Describe)(nil)
_ builder.CommandWithClient = (*Describe)(nil)
_ builder.CommandWithLogger = (*Describe)(nil)
_ builder.CommandWithExecute = (*Describe)(nil)
)

type describeApplicationClient interface {
GetApplication(ctx context.Context, nameOrUUID string) (*meroxa.Application, error)
GetResourceByNameOrID(ctx context.Context, nameOrID string) (*meroxa.Resource, error)
GetConnectorByNameOrID(ctx context.Context, nameOrID string) (*meroxa.Connector, error)
GetFunction(ctx context.Context, nameOrUUID string) (*meroxa.Function, error)
}

type Describe struct {
Expand All @@ -45,6 +49,14 @@ type Describe struct {
args struct {
NameOrUUID string
}

flags struct {
Extended bool `long:"extended" usage:"whether to show additional details about the Meroxa Data Application"`
}
}

func (d *Describe) Flags() []builder.Flag {
return builder.BuildFlags(&d.flags)
}

func (d *Describe) Usage() string {
Expand All @@ -58,12 +70,44 @@ func (d *Describe) Docs() builder.Docs {
}

func (d *Describe) Execute(ctx context.Context) error {
extended := d.flags.Extended

app, err := d.client.GetApplication(ctx, d.args.NameOrUUID)
if err != nil {
return err
}

d.logger.Info(ctx, utils.AppTable(app))
output := utils.AppTable(app)
if extended {
resources := make([]*meroxa.Resource, 0)
connectors := make(map[string]*meroxa.Connector)
functions := make([]*meroxa.Function, 0)

for _, id := range app.Resources {
resource, err := d.client.GetResourceByNameOrID(ctx, id.Name.String)
if err != nil {
return err
}
resources = append(resources, resource)
}
for _, id := range app.Connectors {
connector, err := d.client.GetConnectorByNameOrID(ctx, id.Name.String)
if err != nil {
return err
}
connectors[connector.ResourceName] = connector
}
for _, id := range app.Functions {
function, err := d.client.GetFunction(ctx, id.UUID.String)
if err != nil {
return err
}
functions = append(functions, function)
}

output = utils.ExtendedAppTable(app, resources, connectors, functions)
}
d.logger.Info(ctx, output)
d.logger.JSON(ctx, app)

return nil
Expand Down
8 changes: 3 additions & 5 deletions cmd/meroxa/turbine_cli/golang/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"os/exec"
"regexp"

turbinecli "github.com/meroxa/cli/cmd/meroxa/turbine_cli"

"github.com/meroxa/cli/cmd/meroxa/global"
"github.com/meroxa/cli/log"
)
Expand Down Expand Up @@ -37,11 +35,11 @@ func RunDeployApp(ctx context.Context, l log.Logger, appPath, appName, imageName
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("ACCESS_TOKEN=%s", accessToken), fmt.Sprintf("REFRESH_TOKEN=%s", refreshToken))

stdout, err := turbinecli.RunCmdWithErrorDetection(ctx, cmd, l)
stdout, err := cmd.CombinedOutput()
if err == nil {
l.Info(ctx, "deploy complete!")
l.Infof(ctx, "%s\ndeploy complete!", string(stdout))
}
return stdout, err
return string(stdout), err
}

// NeedsToBuild reads from the Turbine application to determine whether it needs to be built or not
Expand Down
7 changes: 0 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ require github.com/cristalhq/jwt/v3 v3.1.0 // indirect
require (
github.com/Microsoft/go-winio v0.5.1 // indirect
github.com/Microsoft/hcsshim v0.9.2 // indirect
github.com/caarlos0/env/v6 v6.7.2 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/containerd/cgroups v1.0.1 // indirect
github.com/containerd/containerd v1.5.9 // indirect
Expand All @@ -58,11 +57,9 @@ require (
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/meroxa/funtime v0.0.0-20220317202106-ddbc84f8a311 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/moby/sys/mount v0.3.0 // indirect
github.com/moby/sys/mountinfo v0.5.0 // indirect
github.com/oklog/run v1.1.1-0.20200508094559-c7096881717e // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/opencontainers/runc v1.1.0 // indirect
Expand All @@ -75,10 +72,6 @@ require (
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/tidwall/gjson v1.14.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/sjson v1.2.4 // indirect
github.com/volatiletech/inflect v0.0.1 // indirect
github.com/volatiletech/randomize v0.0.1 // indirect
github.com/volatiletech/strmangle v0.0.2 // indirect
Expand Down
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44/go.mod h1:bbYlZJ7
github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50=
github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
github.com/caarlos0/env/v6 v6.7.2 h1:Jiy2dBHvNgCfNGMP0hOZW6jHUbiENvP+VWDtLz4n1Kg=
github.com/caarlos0/env/v6 v6.7.2/go.mod h1:FE0jGiAnQqtv2TenJ4KTa8+/T2Ss8kdS5s1VEjasoN0=
github.com/cased/cased-go v1.0.4 h1:7HxJb80Z//e0g8o7yIANh0cqNMqv08UIHvADt1uAeX4=
github.com/cased/cased-go v1.0.4/go.mod h1:ycyzk9B574kc7XGS6UhhlfTD19Q3D23N3irNe+LQ++A=
Expand Down Expand Up @@ -548,7 +547,6 @@ github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7
github.com/manifoldco/promptui v0.8.0 h1:R95mMF+McvXZQ7j1g8ucVZE1gLP3Sv6j9vlF9kyRqQo=
github.com/manifoldco/promptui v0.8.0/go.mod h1:n4zTdgP0vr0S3w7/O/g98U+e0gwLScEXGwov2nIKuGQ=
github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho=
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand All @@ -573,8 +571,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88Jz2VyhSmden33/aXg4oVIY=
github.com/meroxa/funtime v0.0.0-20220113012133-85e6e898fc73/go.mod h1:K2y2GvcA4Cg3dJtckcwYWnwnJzF63FDdtAQI0fToU0Q=
github.com/meroxa/funtime v0.0.0-20220317202106-ddbc84f8a311 h1:v67qa2s4V1ECk1XAxBGHuDIfWA/1ABvSjDw5qRc8q/8=
github.com/meroxa/funtime v0.0.0-20220317202106-ddbc84f8a311/go.mod h1:szKX3ztLrTSq1gaJ7RX5E9gl6uYaa2rBHBv+R/g6l40=
github.com/meroxa/meroxa-go v0.0.0-20220208195203-71ddc3133fab/go.mod h1:HDFszURCM1cOpKE699o5Hs0T2tEIXqY+vFcsur3RiwY=
github.com/meroxa/meroxa-go v0.0.0-20220330051015-d0051c2a233b h1:YSOIZ7AbtRl08XeLoP5LM+b3RJbwOVl0edeuFiQt+EM=
github.com/meroxa/meroxa-go v0.0.0-20220330051015-d0051c2a233b/go.mod h1:BsqYa9jqfyGOAgfkggfK567b2Ahkb+RCH3lXDQGgrh8=
Expand Down Expand Up @@ -620,7 +616,6 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da h1:qiPWuGGr+1GQE6s9NPSK8iggR/6x/V+0snIoOPYsBgc=
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da/go.mod h1:DvuJJ/w1Y59rG8UTDxsMk5U+UJXJwuvUgbiJSm9yhX8=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/oklog/run v1.1.1-0.20200508094559-c7096881717e h1:bxQ+jj+8fdl9112bovUjD/14jj/uboMqjyVoFkqrdGg=
github.com/oklog/run v1.1.1-0.20200508094559-c7096881717e/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
Expand Down Expand Up @@ -796,13 +791,8 @@ github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG
github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I=
github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.13.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.14.0 h1:6aeJ0bzojgWLa82gDQHcx3S0Lr/O51I9bJ5nv6JFx5w=
github.com/tidwall/gjson v1.14.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.4 h1:cuiLzLnaMeBhRmEv00Lpk3tkYrcxpmbU81tAY4Dw0tc=
github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down
122 changes: 80 additions & 42 deletions utils/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"

"github.com/alexeyco/simpletable"

"github.com/meroxa/meroxa-go/pkg/meroxa"
)

Expand Down Expand Up @@ -849,7 +848,7 @@ func AppTable(app *meroxa.Application) string {
},
{
{Align: simpletable.AlignRight, Text: "Git SHA:"},
{Text: app.GitSha},
{Text: strings.TrimSpace(app.GitSha)},
},
{
{Align: simpletable.AlignRight, Text: "Created At:"},
Expand All @@ -873,53 +872,92 @@ func AppTable(app *meroxa.Application) string {
})
}

if len(app.Connectors) != 0 {
names := make([]string, 0)
for _, f := range app.Connectors {
id, err := f.GetNameOrUUID()
if err != nil {
continue
}
names = append(names, id)
}
mainTable.SetStyle(simpletable.StyleCompact)
return mainTable.String()
}

mainTable.Body.Cells = append(mainTable.Body.Cells, []*simpletable.Cell{
{Align: simpletable.AlignRight, Text: "Connectors:"},
{Text: strings.Join(names, ", ")},
})
func ExtendedAppTable(app *meroxa.Application, resources []*meroxa.Resource, connectors map[string]*meroxa.Connector,
functions []*meroxa.Function) string {
mainTable := simpletable.New()
mainTable.Body.Cells = [][]*simpletable.Cell{
{
{Align: simpletable.AlignRight, Text: "UUID:"},
{Text: app.UUID},
},
{
{Align: simpletable.AlignRight, Text: "Name:"},
{Text: app.Name},
},
{
{Align: simpletable.AlignRight, Text: "Language:"},
{Text: app.Language},
},
{
{Align: simpletable.AlignRight, Text: "Git SHA:"},
{Text: strings.TrimSpace(app.GitSha)},
},
{
{Align: simpletable.AlignRight, Text: "Created At:"},
{Text: app.CreatedAt.String()},
},
{
{Align: simpletable.AlignRight, Text: "Updated At:"},
{Text: app.UpdatedAt.String()},
},
{
{Align: simpletable.AlignRight, Text: "State:"},
{Text: strings.Title(string(app.Status.State))},
},
}
if len(app.Functions) != 0 {
names := make([]string, 0)
for _, f := range app.Functions {
id, err := f.GetNameOrUUID()
if err != nil {
continue
}
names = append(names, id)
}
mainTable.SetStyle(simpletable.StyleCompact)
output := mainTable.String()

mainTable.Body.Cells = append(mainTable.Body.Cells, []*simpletable.Cell{
{Align: simpletable.AlignRight, Text: "Functions:"},
{Text: strings.Join(names, ", ")},
})
subTable := extendedResourcesTable(resources, connectors)
if subTable != "" {
output += "\n" + subTable
}
if len(app.Resources) != 0 {
names := make([]string, 0)
for _, f := range app.Resources {
id, err := f.GetNameOrUUID()
if err != nil {
continue
}
names = append(names, id)
subTable = extendedFunctionsTable(functions)
if subTable != "" {
output += "\n" + subTable
}
return output
}

func extendedResourcesTable(resources []*meroxa.Resource, connectors map[string]*meroxa.Connector) string {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm still not sure why, but the typical library used for these tables was giving me lots of issues with nil pointers when trying to format these two subtables, so i just went with a less flexible option

if len(resources) == 0 {
return ""
}
subTable := "\tResources\n"

for _, r := range resources {
c, ok := connectors[r.Name]
if !ok {
panic("internal error")
}

mainTable.Body.Cells = append(mainTable.Body.Cells, []*simpletable.Cell{
{Align: simpletable.AlignRight, Text: "Resources:"},
{Text: strings.Join(names, ", ")},
})
subTable += fmt.Sprintf("\t %s\n", r.Name)
subTable += fmt.Sprintf("\t\t%5s: %s\n", "UUID", r.UUID)
subTable += fmt.Sprintf("\t\t%5s: %s\n", "Type", string(r.Type))
subTable += fmt.Sprintf("\t\t%5s: %s\n", "State", string(c.State))
subTable += fmt.Sprintf("\t\t%5s: %s", "As", string(c.Type))
}
mainTable.SetStyle(simpletable.StyleCompact)
return mainTable.String()

return subTable
}

func extendedFunctionsTable(functions []*meroxa.Function) string {
if len(functions) == 0 {
return ""
}
subTable := "\tFunctions\n"

for _, f := range functions {
subTable += fmt.Sprintf("\t %s\n", f.Name)
subTable += fmt.Sprintf("\t\t%5s: %s\n", "UUID", f.UUID)
subTable += fmt.Sprintf("\t\t%5s: %s\n", "State", f.Status.State)
}

return subTable
}

func truncateString(oldString string, l int) string {
Expand Down
4 changes: 0 additions & 4 deletions vendor/github.com/caarlos0/env/v6/.gitignore

This file was deleted.

8 changes: 0 additions & 8 deletions vendor/github.com/caarlos0/env/v6/.golangci.yml

This file was deleted.

3 changes: 0 additions & 3 deletions vendor/github.com/caarlos0/env/v6/.goreleaser.yml

This file was deleted.

21 changes: 0 additions & 21 deletions vendor/github.com/caarlos0/env/v6/LICENSE.md

This file was deleted.

Loading