From 8ee4136d925bb8a00f0d98f29f4a1d7e47ad0929 Mon Sep 17 00:00:00 2001 From: shrutiparabgoogle <78754132+shrutiparabgoogle@users.noreply.github.com> Date: Tue, 27 Jul 2021 16:49:22 -0700 Subject: [PATCH] Restructure resolve command (#240) --- cmd/registry/cmd/resolve/resolve.go | 20 +++++++------------- cmd/registry/cmd/resolve/resolve_test.go | 22 +++++++++++++++++----- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/cmd/registry/cmd/resolve/resolve.go b/cmd/registry/cmd/resolve/resolve.go index 586983a77..18117263b 100644 --- a/cmd/registry/cmd/resolve/resolve.go +++ b/cmd/registry/cmd/resolve/resolve.go @@ -16,8 +16,8 @@ package resolve import ( "context" - "fmt" "log" + "strings" "github.com/apigee/registry/cmd/registry/controller" "github.com/apigee/registry/cmd/registry/core" @@ -64,19 +64,13 @@ func Command(ctx context.Context) *cobra.Command { log.Printf("Generated %d actions. Starting Execution...", len(actions)) - taskQueue := make(chan core.Task, 1024) - for i := 0; i < 64; i++ { - core.WaitGroup().Add(1) - go core.Worker(ctx, taskQueue) - } - defer core.WaitGroup().Wait() - defer close(taskQueue) + for _, a := range actions { + log.Printf("Executing action: %s", a) + rootCmd := cmd.Root() + rootCmd.SetArgs(strings.Fields(a)) - // Submit tasks to taskQueue - for i, a := range actions { - taskQueue <- &controller.ExecCommandTask{ - Action: a, - TaskID: fmt.Sprintf("task%d", i), + if err := rootCmd.Execute(); err != nil { + log.Printf("Error executing action: %s", err) } } }, diff --git a/cmd/registry/cmd/resolve/resolve_test.go b/cmd/registry/cmd/resolve/resolve_test.go index 15710b7db..f6d833e3b 100644 --- a/cmd/registry/cmd/resolve/resolve_test.go +++ b/cmd/registry/cmd/resolve/resolve_test.go @@ -22,6 +22,7 @@ import ( "path/filepath" "testing" + "github.com/apigee/registry/cmd/registry/cmd/compute" "github.com/apigee/registry/cmd/registry/cmd/upload" "github.com/apigee/registry/cmd/registry/core" "github.com/apigee/registry/connection" @@ -29,6 +30,7 @@ import ( "github.com/apigee/registry/server/names" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" + "github.com/spf13/cobra" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -193,11 +195,21 @@ func TestResolve(t *testing.T) { t.Fatalf("Failed to upload the manifest: %s", err) } - // Call the controller update command - resolveCmd := Command(ctx) - args = []string{"projects/" + testProject + "/artifacts/test-manifest"} - resolveCmd.SetArgs(args) - if err = resolveCmd.Execute(); err != nil { + // Set up the root command for resolve actions + // This is required because the resolve command expects + // itself to have a root, that root commaand should support + // all the actions mentioned in the config file + var rootCmd = &cobra.Command{ + Use: "registry", + Short: "test command", + } + rootCmd.AddCommand(compute.Command(ctx)) + rootCmd.AddCommand(Command(ctx)) + + // Call the resolve command + args = []string{"resolve", "projects/" + testProject + "/artifacts/test-manifest"} + rootCmd.SetArgs(args) + if err = rootCmd.Execute(); err != nil { t.Fatalf("Execute() with args %v returned error: %s", args, err) }