Skip to content

Commit

Permalink
modules: extract github.com/scylladb/scylla-manager/v3/pkg/managercli…
Browse files Browse the repository at this point in the history
…ent as submodule

...so that it can be imported to other project as go get github.com/scylladb/scylla-manager/v3/pkg/managerclient
  • Loading branch information
karol-kokoszka committed Sep 2, 2024
1 parent 7914bb0 commit 0296912
Show file tree
Hide file tree
Showing 45 changed files with 206 additions and 163 deletions.
6 changes: 3 additions & 3 deletions pkg/cmd/sctool/sctool.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"github.com/scylladb/scylla-manager/v3/pkg/command/suspend"
"github.com/scylladb/scylla-manager/v3/pkg/command/tasks"
"github.com/scylladb/scylla-manager/v3/pkg/command/version"
"github.com/scylladb/scylla-manager/v3/pkg/managerclient"
managerclient2 "github.com/scylladb/scylla-manager/v3/pkg/managerclient"
"github.com/spf13/cobra"
)

Expand All @@ -44,15 +44,15 @@ func main() {

cmd := buildCommand()
if err := cmd.Execute(); err != nil {
managerclient.PrintError(cmd.OutOrStderr(), err)
managerclient2.PrintError(cmd.OutOrStderr(), err)
os.Exit(1)
}

os.Exit(0)
}

func buildCommand() *cobra.Command {
var client managerclient.Client
var client managerclient2.Client

backupCmd := backup.NewCommand(&client)
backupCmd.AddCommand(
Expand Down
18 changes: 9 additions & 9 deletions pkg/command/backup/backupvalidate/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/pkg/errors"
"github.com/scylladb/scylla-manager/v3/pkg/command/flag"
"github.com/scylladb/scylla-manager/v3/pkg/managerclient"
managerclient2 "github.com/scylladb/scylla-manager/v3/pkg/managerclient"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)
Expand All @@ -21,23 +21,23 @@ var updateRes []byte

type command struct {
flag.TaskBase
client *managerclient.Client
client *managerclient2.Client

cluster string
location []string
deleteOrphanedFiles bool
parallel int
}

func NewCommand(client *managerclient.Client) *cobra.Command {
func NewCommand(client *managerclient2.Client) *cobra.Command {
cmd := newCommand(client, false)
updateCmd := newCommand(client, true)
cmd.AddCommand(&updateCmd.Command)

return &cmd.Command
}

func newCommand(client *managerclient.Client, update bool) *command {
func newCommand(client *managerclient2.Client, update bool) *command {
var (
cmd = &command{
client: client,
Expand Down Expand Up @@ -74,20 +74,20 @@ func (cmd *command) init() {

func (cmd *command) run(args []string) error {
var (
task *managerclient.Task
task *managerclient2.Task
ok bool
)

if cmd.Update() {
a := managerclient.ValidateBackupTask
a := managerclient2.ValidateBackupTask
if len(args) > 0 {
a = args[0]
}
taskType, taskID, err := cmd.client.TaskSplit(cmd.Context(), cmd.cluster, a)
if err != nil {
return err
}
if taskType != managerclient.ValidateBackupTask {
if taskType != managerclient2.ValidateBackupTask {
return fmt.Errorf("can't handle %s task", taskType)
}
task, err = cmd.client.GetTask(cmd.Context(), cmd.cluster, taskType, taskID)
Expand All @@ -96,7 +96,7 @@ func (cmd *command) run(args []string) error {
}
ok = cmd.UpdateTask(task)
} else {
task = cmd.CreateTask(managerclient.ValidateBackupTask)
task = cmd.CreateTask(managerclient2.ValidateBackupTask)
}

props := task.Properties.(map[string]interface{})
Expand Down Expand Up @@ -128,6 +128,6 @@ func (cmd *command) run(args []string) error {
return errors.New("nothing to do")
}

fmt.Fprintln(cmd.OutOrStdout(), managerclient.TaskID(task))
fmt.Fprintln(cmd.OutOrStdout(), managerclient2.TaskID(task))
return nil
}
18 changes: 9 additions & 9 deletions pkg/command/backup/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/pkg/errors"
"github.com/scylladb/scylla-manager/v3/pkg/command/flag"
"github.com/scylladb/scylla-manager/v3/pkg/managerclient"
managerclient2 "github.com/scylladb/scylla-manager/v3/pkg/managerclient"
"github.com/spf13/cobra"
"go.uber.org/atomic"
"gopkg.in/yaml.v2"
Expand All @@ -23,7 +23,7 @@ var updateRes []byte

type command struct {
flag.TaskBase
client *managerclient.Client
client *managerclient2.Client

cluster string
dc []string
Expand All @@ -39,15 +39,15 @@ type command struct {
purgeOnly bool
}

func NewCommand(client *managerclient.Client) *cobra.Command {
func NewCommand(client *managerclient2.Client) *cobra.Command {
cmd := newCommand(client, false)
updateCmd := newCommand(client, true)
cmd.AddCommand(&updateCmd.Command)

Check failure on line 45 in pkg/command/backup/cmd.go

View workflow job for this annotation

GitHub Actions / Various checks

cmd.AddCommand undefined (type *command has no field or method AddCommand) (typecheck)

return &cmd.Command

Check failure on line 47 in pkg/command/backup/cmd.go

View workflow job for this annotation

GitHub Actions / Various checks

cmd.Command undefined (type *command has no field or method Command) (typecheck)
}

func newCommand(client *managerclient.Client, update bool) *command {
func newCommand(client *managerclient2.Client, update bool) *command {
var (
cmd = &command{
client: client,
Expand Down Expand Up @@ -92,20 +92,20 @@ func (cmd *command) init() {

func (cmd *command) run(args []string) error {
var (
task *managerclient.Task
task *managerclient2.Task
ok bool
)

if cmd.Update() {
a := managerclient.BackupTask
a := managerclient2.BackupTask
if len(args) > 0 {
a = args[0]
}
taskType, taskID, err := cmd.client.TaskSplit(cmd.Context(), cmd.cluster, a)
if err != nil {
return err
}
if taskType != managerclient.BackupTask {
if taskType != managerclient2.BackupTask {
return fmt.Errorf("can't handle %s task", taskType)
}
task, err = cmd.client.GetTask(cmd.Context(), cmd.cluster, taskType, taskID)
Expand All @@ -114,7 +114,7 @@ func (cmd *command) run(args []string) error {
}
ok = cmd.UpdateTask(task)
} else {
task = cmd.CreateTask(managerclient.BackupTask)
task = cmd.CreateTask(managerclient2.BackupTask)
}

props := task.Properties.(map[string]interface{})
Expand Down Expand Up @@ -192,6 +192,6 @@ func (cmd *command) run(args []string) error {
return errors.New("nothing to do")
}

fmt.Fprintln(cmd.OutOrStdout(), managerclient.TaskID(task))
fmt.Fprintln(cmd.OutOrStdout(), managerclient2.TaskID(task))
return nil
}
8 changes: 4 additions & 4 deletions pkg/command/cluster/clusteradd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/pkg/errors"
"github.com/scylladb/scylla-manager/v3/pkg/command/flag"
"github.com/scylladb/scylla-manager/v3/pkg/managerclient"
managerclient2 "github.com/scylladb/scylla-manager/v3/pkg/managerclient"
"github.com/scylladb/scylla-manager/v3/pkg/util/clipper"
"github.com/scylladb/scylla-manager/v3/pkg/util/fsutil"
"github.com/spf13/cobra"
Expand All @@ -21,7 +21,7 @@ var res []byte

type command struct {
cobra.Command
client *managerclient.Client
client *managerclient2.Client

id string
name string
Expand All @@ -38,7 +38,7 @@ type command struct {
forceNonSSLSessionPort bool
}

func NewCommand(client *managerclient.Client) *cobra.Command {
func NewCommand(client *managerclient2.Client) *cobra.Command {
cmd := &command{
client: client,
}
Expand Down Expand Up @@ -84,7 +84,7 @@ func (cmd *command) run() error {
}
}

c := &managerclient.Cluster{
c := &managerclient2.Cluster{
ID: cmd.id,
Name: cmd.name,
Labels: cmd.label.NewLabels(),
Expand Down
8 changes: 4 additions & 4 deletions pkg/command/info/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"

"github.com/scylladb/scylla-manager/v3/pkg/command/flag"
"github.com/scylladb/scylla-manager/v3/pkg/managerclient"
managerclient2 "github.com/scylladb/scylla-manager/v3/pkg/managerclient"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)
Expand All @@ -17,14 +17,14 @@ var res []byte

type command struct {
cobra.Command
client *managerclient.Client
client *managerclient2.Client

cluster string
limit int
cause bool
}

func NewCommand(client *managerclient.Client) *cobra.Command {
func NewCommand(client *managerclient2.Client) *cobra.Command {
cmd := &command{
client: client,
Command: cobra.Command{
Expand Down Expand Up @@ -66,7 +66,7 @@ func (cmd *command) run(args []string) error {
return fmt.Errorf("expected exactly 1 task, got %d", len(tasks.TaskListItemSlice))
}

ti := managerclient.TaskInfo{
ti := managerclient2.TaskInfo{
TaskListItem: tasks.TaskListItemSlice[0],
}
if err := ti.Render(w); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/command/info/cmd_integration_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"regexp"
"testing"

"github.com/scylladb/scylla-manager/v3/pkg/managerclient"
managerclient2 "github.com/scylladb/scylla-manager/v3/pkg/managerclient"
"github.com/scylladb/scylla-manager/v3/swagger/gen/scylla-manager/models"
)

Expand All @@ -22,7 +22,7 @@ const (
)

func TestSctoolInfoLabelsIntegrationAPITest(t *testing.T) {
client, err := managerclient.NewClient("http://localhost:5080/api/v1")
client, err := managerclient2.NewClient("http://localhost:5080/api/v1")
if err != nil {
t.Fatalf("Unable to create managerclient to consume manager HTTP API, err = {%v}", err)
}
Expand All @@ -41,7 +41,7 @@ func TestSctoolInfoLabelsIntegrationAPITest(t *testing.T) {
}
}()

taskID, err := client.CreateTask(context.Background(), clusterID, &managerclient.Task{
taskID, err := client.CreateTask(context.Background(), clusterID, &managerclient2.Task{
Type: "repair",
Enabled: true,
Labels: map[string]string{
Expand All @@ -53,7 +53,7 @@ func TestSctoolInfoLabelsIntegrationAPITest(t *testing.T) {
t.Logf("Failed to create task, err = {%v}", err)
}

if err := client.UpdateTask(context.Background(), clusterID, &managerclient.Task{
if err := client.UpdateTask(context.Background(), clusterID, &managerclient2.Task{
ID: taskID.String(),
Type: "repair",
Enabled: true,
Expand Down
8 changes: 4 additions & 4 deletions pkg/command/legacy/task/taskdelete/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
_ "embed"

"github.com/scylladb/scylla-manager/v3/pkg/command/flag"
"github.com/scylladb/scylla-manager/v3/pkg/managerclient"
managerclient2 "github.com/scylladb/scylla-manager/v3/pkg/managerclient"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)
Expand All @@ -16,12 +16,12 @@ var res []byte

type command struct {
cobra.Command
client *managerclient.Client
client *managerclient2.Client

cluster string
}

func NewCommand(client *managerclient.Client) *cobra.Command {
func NewCommand(client *managerclient2.Client) *cobra.Command {
cmd := &command{
client: client,
Command: cobra.Command{
Expand All @@ -46,7 +46,7 @@ func (cmd *command) init() {
}

func (cmd *command) run(args []string) error {
taskType, taskID, _, err := managerclient.TaskSplit(args[0])
taskType, taskID, _, err := managerclient2.TaskSplit(args[0])
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/command/legacy/task/taskhistory/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
_ "embed"

"github.com/scylladb/scylla-manager/v3/pkg/command/flag"
"github.com/scylladb/scylla-manager/v3/pkg/managerclient"
managerclient2 "github.com/scylladb/scylla-manager/v3/pkg/managerclient"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)
Expand All @@ -16,13 +16,13 @@ var res []byte

type command struct {
cobra.Command
client *managerclient.Client
client *managerclient2.Client

cluster string
limit int
}

func NewCommand(client *managerclient.Client) *cobra.Command {
func NewCommand(client *managerclient2.Client) *cobra.Command {
cmd := &command{
client: client,
Command: cobra.Command{
Expand All @@ -48,7 +48,7 @@ func (cmd *command) init() {
}

func (cmd *command) run(args []string) error {
taskType, taskID, _, err := managerclient.TaskSplit(args[0])
taskType, taskID, _, err := managerclient2.TaskSplit(args[0])
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 0296912

Please sign in to comment.