Skip to content

Commit

Permalink
Restructure resolve command (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrutiparabgoogle authored Jul 27, 2021
1 parent 61ab12e commit 8ee4136
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
20 changes: 7 additions & 13 deletions cmd/registry/cmd/resolve/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
},
Expand Down
22 changes: 17 additions & 5 deletions cmd/registry/cmd/resolve/resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ 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"
"github.com/apigee/registry/rpc"
"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"
)
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 8ee4136

Please sign in to comment.