Skip to content

Commit 719e4bc

Browse files
authored
Merge pull request #11 from GwonsooLee/snapshot_goroutine_and_add_fix_command
add fix command & apply goroutine for restoring snapshot
2 parents c159d38 + 18fe9e4 commit 719e4bc

File tree

1,561 files changed

+415
-502474
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,561 files changed

+415
-502474
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ out/
44
*.iml
55
.idea/
66
.vscode/
7+
vendor

cmd/cmd/builder/flag.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ var FlagRegistry = []Flag{
102102
"snapshot restore [repositoryID] [snapshotID] [indexName]",
103103
"snapshot archive [repositoryID] [snapshotID]"},
104104
},
105+
{
106+
Name: "restore-tier",
107+
Usage: "Tier of restore job",
108+
Value: aws.String("Standard"),
109+
DefValue: "Standard",
110+
FlagAddMethod: "StringVar",
111+
DefinedOn: []string{
112+
"snapshot restore [repositoryID] [snapshotID] [indexName]",
113+
},
114+
},
115+
{
116+
Name: "max-concurrent-job",
117+
Usage: "Maximum number of concurrent jobs for restoring snapshot",
118+
Value: aws.Int64(constants.DefaultMaxConcurrentJob),
119+
DefValue: int64(constants.DefaultMaxConcurrentJob),
120+
FlagAddMethod: "Int64Var",
121+
DefinedOn: []string{
122+
"snapshot restore [repositoryID] [snapshotID] [indexName]",
123+
},
124+
},
105125
}
106126

107127
func (fl *Flag) flag() *pflag.Flag {

cmd/cmd/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func NewRootCommand(out, stderr io.Writer) *cobra.Command {
4444
rootCmd.AddCommand(NewCatCommand())
4545
rootCmd.AddCommand(NewVersionCommand())
4646
rootCmd.AddCommand(NewDiagCommand())
47+
rootCmd.AddCommand(NewFixCommand())
4748
rootCmd.AddCommand(NewIndexCommand())
4849
rootCmd.AddCommand(NewClusterCommand())
4950
rootCmd.AddCommand(NewUpdateCommand())

cmd/cmd/fix.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
copyright 2020 the Escli authors
3+
4+
licensed under the apache license, version 2.0 (the "license");
5+
you may not use this file except in compliance with the license.
6+
you may obtain a copy of the license at
7+
8+
http://www.apache.org/licenses/license-2.0
9+
10+
unless required by applicable law or agreed to in writing, software
11+
distributed under the license is distributed on an "as is" basis,
12+
without warranties or conditions of any kind, either express or implied.
13+
see the license for the specific language governing permissions and
14+
limitations under the license.
15+
*/
16+
17+
package cmd
18+
19+
import (
20+
"context"
21+
"io"
22+
23+
"github.com/spf13/cobra"
24+
25+
"github.com/DevopsArtFactory/escli/cmd/cmd/builder"
26+
"github.com/DevopsArtFactory/escli/internal/executor"
27+
)
28+
29+
func NewFixCommand() *cobra.Command {
30+
return builder.NewCmd("fix").
31+
WithDescription("fix old configuration or settings of escli yaml file").
32+
NoArgs(funcFixCommand)
33+
}
34+
35+
func funcFixCommand(ctx context.Context, out io.Writer) error {
36+
return executor.RunExecutorWithoutCheckingConfig(ctx, func(executor executor.Executor) error {
37+
return executor.Runner.Fix(out)
38+
})
39+
}

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
module github.com/DevopsArtFactory/escli
22

3-
go 1.14
3+
go 1.16
44

55
require (
66
github.com/AlecAivazis/survey/v2 v2.0.5
77
github.com/GoogleContainerTools/skaffold v1.17.2 // indirect
88
github.com/aws/aws-sdk-go v1.36.5
99
github.com/blang/semver v3.5.1+incompatible
10+
github.com/cheggaaa/pb/v3 v3.0.8
1011
github.com/elastic/go-elasticsearch v0.0.0
1112
github.com/enescakir/emoji v1.0.0
1213
github.com/fatih/color v1.10.0
@@ -17,6 +18,6 @@ require (
1718
github.com/spf13/cobra v1.1.1
1819
github.com/spf13/pflag v1.0.5
1920
github.com/spf13/viper v1.7.1
20-
gopkg.in/yaml.v2 v2.3.0
21+
gopkg.in/yaml.v2 v2.3.0 // indirect
2122
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
2223
)

go.sum

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdko
9595
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
9696
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
9797
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
98+
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
99+
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
98100
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
99101
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
100102
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
@@ -162,6 +164,8 @@ github.com/cespare/xxhash/v2 v2.1.0/go.mod h1:dgIUBU3pDso/gPgZ1osOZ0iQf77oPR28Tj
162164
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
163165
github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5/go.mod h1:/iP1qXHoty45bqomnu2LM+VVyAEdWN+vtSHGlQgyxbw=
164166
github.com/checkpoint-restore/go-criu/v4 v4.1.0/go.mod h1:xUQBLp4RLc5zJtWY++yjOoMoB5lihDt7fai+75m+rGw=
167+
github.com/cheggaaa/pb/v3 v3.0.8 h1:bC8oemdChbke2FHIIGy9mn4DPJ2caZYQnfbRqwmdCoA=
168+
github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/ow1EJTA=
165169
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
166170
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
167171
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
@@ -571,6 +575,8 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
571575
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
572576
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
573577
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
578+
github.com/mattn/go-runewidth v0.0.12 h1:Y41i/hVW3Pgwr8gV+J23B9YEY0zxjptBuCWEaxmAOow=
579+
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
574580
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
575581
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
576582
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88Jz2VyhSmden33/aXg4oVIY=
@@ -723,6 +729,9 @@ github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqn
723729
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
724730
github.com/rhysd/go-github-selfupdate v1.2.3 h1:iaa+J202f+Nc+A8zi75uccC8Wg3omaM7HDeimXA22Ag=
725731
github.com/rhysd/go-github-selfupdate v1.2.3/go.mod h1:mp/N8zj6jFfBQy/XMYoWsmfzxazpPAODuqarmPDe2Rg=
732+
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
733+
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
734+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
726735
github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM=
727736
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
728737
github.com/rogpeppe/fastuuid v1.1.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
@@ -1071,6 +1080,8 @@ golang.org/x/sys v0.0.0-20200922070232-aee5d888a860/go.mod h1:h1NjWce9XRLGQEsW7w
10711080
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
10721081
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88=
10731082
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1083+
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 h1:F5Gozwx4I1xtr/sr/8CFbb57iKi3297KFs0QDbGN60A=
1084+
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
10741085
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
10751086
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
10761087
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

internal/builder/builder.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ import (
2626
)
2727

2828
type Flags struct {
29-
Force bool `json:"force"`
30-
TroubledOnly bool `json:"troubled-only"`
31-
RepoOnly bool `json:"repo-only"`
32-
WithRepo string `json:"with-repo"`
33-
Region string `json:"region"`
34-
SortBy string `json:"sort-by"`
29+
Force bool `json:"force"`
30+
TroubledOnly bool `json:"troubled-only"`
31+
RepoOnly bool `json:"repo-only"`
32+
WithRepo string `json:"with-repo"`
33+
Region string `json:"region"`
34+
SortBy string `json:"sort-by"`
35+
RestoreTier string `json:"restore-tier"`
36+
MaxConcurrentJob int64 `json:"max-concurrent-job"`
3537
}
3638

3739
func ParseFlags() (*Flags, error) {

internal/client/s3.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ func (c Client) HeadObject(bucket *string, key *string) (*s3.HeadObjectOutput, e
6464
return resp, nil
6565
}
6666

67-
func (c Client) RestoreObject(bucket *string, key *string) error {
67+
func (c Client) RestoreObject(bucket *string, key *string, restoreTier string) error {
6868
_, err := c.S3Client.RestoreObject(&s3.RestoreObjectInput{
6969
Bucket: bucket,
7070
Key: key,
7171
RestoreRequest: &s3.RestoreRequest{
7272
Days: aws.Int64(10),
7373
GlacierJobParameters: &s3.GlacierJobParameters{
74-
Tier: aws.String("Standard"),
74+
Tier: aws.String(restoreTier),
7575
},
7676
},
7777
})

internal/config/config.go

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,31 @@ limitations under the license.
1717
package config
1818

1919
import (
20+
"fmt"
2021
"io/ioutil"
2122

23+
"github.com/fatih/color"
2224
"github.com/spf13/viper"
2325
"gopkg.in/yaml.v3"
2426

2527
"github.com/DevopsArtFactory/escli/internal/schema"
28+
"github.com/DevopsArtFactory/escli/internal/util"
2629
)
2730

2831
func GetConfig() (*schema.Config, error) {
2932
var configs []schema.Config
3033

31-
yamlFile, err := ioutil.ReadFile(viper.GetString("cfgFile"))
34+
filePath := viper.GetString("cfgFile")
35+
yamlFile, err := ioutil.ReadFile(filePath)
3236
if err != nil {
3337
return nil, err
3438
}
3539

3640
err = yaml.Unmarshal(yamlFile, &configs)
3741
if err != nil {
42+
if old, err := detectOldConfig(); err == nil && old {
43+
return nil, fmt.Errorf("you are using old version configuration. please run `escli fix` to migrate configuration")
44+
}
3845
return nil, err
3946
}
4047

@@ -49,6 +56,78 @@ func GetConfig() (*schema.Config, error) {
4956
return &configs[0], nil
5057
}
5158

59+
func detectConfig() (bool, error) {
60+
var config []schema.Config
61+
filePath := viper.GetString("cfgFile")
62+
yamlFile, err := ioutil.ReadFile(filePath)
63+
if err != nil {
64+
return false, err
65+
}
66+
err = yaml.Unmarshal(yamlFile, &config)
67+
if err != nil {
68+
return false, err
69+
}
70+
71+
return true, err
72+
}
73+
74+
func detectOldConfig() (bool, error) {
75+
var config schema.OldConfig
76+
filePath := viper.GetString("cfgFile")
77+
yamlFile, err := ioutil.ReadFile(filePath)
78+
if err != nil {
79+
return false, err
80+
}
81+
err = yaml.Unmarshal(yamlFile, &config)
82+
if err != nil {
83+
return false, err
84+
}
85+
86+
return true, err
87+
}
88+
89+
func GetOldConfig() (*schema.OldConfig, error) {
90+
var config schema.OldConfig
91+
92+
filePath := viper.GetString("cfgFile")
93+
yamlFile, err := ioutil.ReadFile(filePath)
94+
if err != nil {
95+
return nil, err
96+
}
97+
98+
err = yaml.Unmarshal(yamlFile, &config)
99+
if err != nil {
100+
if new, err := detectConfig(); err == nil && new {
101+
color.Green("your configuration is already updated")
102+
return nil, nil
103+
}
104+
return nil, err
105+
}
106+
107+
return &config, nil
108+
}
109+
110+
func ConvertToNewConfig(oc *schema.OldConfig) error {
111+
cfgFile := viper.GetString("cfgFile")
112+
113+
profile, err := util.AskProfile()
114+
if err != nil {
115+
return err
116+
}
117+
118+
c := SetInitConfig(profile, oc.ElasticSearchURL, oc.AWSRegion)
119+
y, err := yaml.Marshal(c)
120+
if err != nil {
121+
return err
122+
}
123+
124+
if err := util.CreateFile(cfgFile, string(y)); err != nil {
125+
return err
126+
}
127+
128+
return nil
129+
}
130+
52131
func GetDefaultConfig() (*schema.Config, error) {
53132
profile := &schema.Config{}
54133

internal/constants/constants.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ const (
3030

3131
GetClusterSetting = 0
3232
PutClusterSetting = 3
33+
34+
HardLimitMaxConcurrentJob = 100
35+
DefaultMaxConcurrentJob = 50
3336
)
3437

3538
var (
3639
ConfigDirectoryPath = HomeDir() + "/.escli"
3740
BaseFilePath = ConfigDirectoryPath + "/config.yaml"
41+
ValidRestoreTier = []string{"Standard", "Bulk", "Expedited"}
3842
)
3943

4044
// Get Home Directory

0 commit comments

Comments
 (0)