-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
miscellaneous cobras #14069
Merged
ajm188
merged 11 commits into
vitessio:main
from
planetscale:andrew/miscellaneous-cobras
Sep 27, 2023
Merged
miscellaneous cobras #14069
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dddaac9
sort testdata map so i can make sure i have them all
2e19df7
add topo2topo flags
5e634af
migrate topo2topo to cobra
3e22c5c
add vtgateclienttest flags
e603fc1
migrate vtgateclienttest to cobra
28b288d
migrate vttestserver to cobra
13175a5
fix tests
8054456
migrate vttlstest to cobra
434dfef
move datadir so tests work
961af53
migrate vtexplain to cobra
408a2cc
add help and example
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,158 @@ | ||
/* | ||
Copyright 2023 The Vitess Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cli | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"vitess.io/vitess/go/acl" | ||
"vitess.io/vitess/go/vt/grpccommon" | ||
"vitess.io/vitess/go/vt/logutil" | ||
"vitess.io/vitess/go/vt/servenv" | ||
"vitess.io/vitess/go/vt/topo" | ||
"vitess.io/vitess/go/vt/topo/helpers" | ||
) | ||
|
||
var ( | ||
fromImplementation string | ||
fromServerAddress string | ||
fromRoot string | ||
toImplementation string | ||
toServerAddress string | ||
toRoot string | ||
compare bool | ||
doKeyspaces bool | ||
doShards bool | ||
doShardReplications bool | ||
doTablets bool | ||
doRoutingRules bool | ||
|
||
Main = &cobra.Command{ | ||
Use: "topo2topo", | ||
Short: "topo2topo copies Vitess topology data from one topo server to another.", | ||
Long: `topo2topo copies Vitess topology data from one topo server to another. | ||
It can also be used to compare data between two topologies.`, | ||
Args: cobra.NoArgs, | ||
PreRunE: servenv.CobraPreRunE, | ||
RunE: run, | ||
} | ||
) | ||
|
||
func init() { | ||
servenv.MoveFlagsToCobraCommand(Main) | ||
|
||
Main.Flags().StringVar(&fromImplementation, "from_implementation", fromImplementation, "topology implementation to copy data from") | ||
Main.Flags().StringVar(&fromServerAddress, "from_server", fromServerAddress, "topology server address to copy data from") | ||
Main.Flags().StringVar(&fromRoot, "from_root", fromRoot, "topology server root to copy data from") | ||
Main.Flags().StringVar(&toImplementation, "to_implementation", toImplementation, "topology implementation to copy data to") | ||
Main.Flags().StringVar(&toServerAddress, "to_server", toServerAddress, "topology server address to copy data to") | ||
Main.Flags().StringVar(&toRoot, "to_root", toRoot, "topology server root to copy data to") | ||
Main.Flags().BoolVar(&compare, "compare", compare, "compares data between topologies") | ||
Main.Flags().BoolVar(&doKeyspaces, "do-keyspaces", doKeyspaces, "copies the keyspace information") | ||
Main.Flags().BoolVar(&doShards, "do-shards", doShards, "copies the shard information") | ||
Main.Flags().BoolVar(&doShardReplications, "do-shard-replications", doShardReplications, "copies the shard replication information") | ||
Main.Flags().BoolVar(&doTablets, "do-tablets", doTablets, "copies the tablet information") | ||
Main.Flags().BoolVar(&doRoutingRules, "do-routing-rules", doRoutingRules, "copies the routing rules") | ||
|
||
acl.RegisterFlags(Main.Flags()) | ||
grpccommon.RegisterFlags(Main.Flags()) | ||
} | ||
|
||
func run(cmd *cobra.Command, args []string) error { | ||
defer logutil.Flush() | ||
servenv.Init() | ||
|
||
fromTS, err := topo.OpenServer(fromImplementation, fromServerAddress, fromRoot) | ||
if err != nil { | ||
return fmt.Errorf("Cannot open 'from' topo %v: %w", fromImplementation, err) | ||
} | ||
toTS, err := topo.OpenServer(toImplementation, toServerAddress, toRoot) | ||
if err != nil { | ||
return fmt.Errorf("Cannot open 'to' topo %v: %w", toImplementation, err) | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
if compare { | ||
return compareTopos(ctx, fromTS, toTS) | ||
} | ||
|
||
return copyTopos(ctx, fromTS, toTS) | ||
} | ||
|
||
func copyTopos(ctx context.Context, fromTS, toTS *topo.Server) error { | ||
if doKeyspaces { | ||
if err := helpers.CopyKeyspaces(ctx, fromTS, toTS); err != nil { | ||
return err | ||
} | ||
} | ||
if doShards { | ||
if err := helpers.CopyShards(ctx, fromTS, toTS); err != nil { | ||
return err | ||
} | ||
} | ||
if doShardReplications { | ||
if err := helpers.CopyShardReplications(ctx, fromTS, toTS); err != nil { | ||
return err | ||
} | ||
} | ||
if doTablets { | ||
if err := helpers.CopyTablets(ctx, fromTS, toTS); err != nil { | ||
return err | ||
} | ||
} | ||
if doRoutingRules { | ||
if err := helpers.CopyRoutingRules(ctx, fromTS, toTS); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func compareTopos(ctx context.Context, fromTS, toTS *topo.Server) (err error) { | ||
if doKeyspaces { | ||
err = helpers.CompareKeyspaces(ctx, fromTS, toTS) | ||
if err != nil { | ||
return fmt.Errorf("Compare keyspaces failed: %w", err) | ||
} | ||
} | ||
if doShards { | ||
err = helpers.CompareShards(ctx, fromTS, toTS) | ||
if err != nil { | ||
return fmt.Errorf("Compare shards failed: %w", err) | ||
} | ||
} | ||
if doShardReplications { | ||
err = helpers.CompareShardReplications(ctx, fromTS, toTS) | ||
if err != nil { | ||
return fmt.Errorf("Compare shard replications failed: %w", err) | ||
} | ||
} | ||
if doTablets { | ||
err = helpers.CompareTablets(ctx, fromTS, toTS) | ||
if err != nil { | ||
return fmt.Errorf("Compare tablets failed: %w", err) | ||
} | ||
} | ||
|
||
fmt.Println("Topologies are in sync") | ||
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,37 @@ | ||
/* | ||
Copyright 2023 The Vitess Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"vitess.io/vitess/go/cmd/internal/docgen" | ||
"vitess.io/vitess/go/cmd/topo2topo/cli" | ||
) | ||
|
||
func main() { | ||
var dir string | ||
cmd := cobra.Command{ | ||
Use: "docgen [-d <dir>]", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return docgen.GenerateMarkdownTree(cli.Main, dir) | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVarP(&dir, "dir", "d", "doc", "output directory to write documentation") | ||
_ = cmd.Execute() | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the reason for calling this as
main
package and notdocgen
package?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's an executable, see https://github.com/vitessio/website/blob/prod/tools/cobradocs/version.go#L79