diff --git a/control/command.go b/control/command.go new file mode 100644 index 00000000..68cd9f22 --- /dev/null +++ b/control/command.go @@ -0,0 +1,152 @@ +// Copyright 2017 CoreOS, Inc. +// +// 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 control + +import ( + "fmt" + "io/ioutil" + "path/filepath" + "strings" + "time" + + "github.com/coreos/dbtester/remotestorage" + "github.com/spf13/cobra" +) + +// Command implements 'control' command. +var Command = &cobra.Command{ + Use: "control", + Short: "Controls tests.", + RunE: commandFunc, +} + +var configPath string + +func init() { + Command.PersistentFlags().StringVarP(&configPath, "config", "c", "", "YAML configuration file path.") +} + +func commandFunc(cmd *cobra.Command, args []string) error { + cfg, err := ReadConfig(configPath) + if err != nil { + return err + } + switch cfg.Database { + case "etcdv2": + case "etcdv3": + case "zk", "zookeeper": + case "zetcd": + case "consul": + case "cetcd": + default: + return fmt.Errorf("%q is not supported", cfg.Database) + } + if !cfg.Step2.SkipStressDatabase { + switch cfg.Step2.BenchType { + case "write": + case "read": + case "read-oneshot": + default: + return fmt.Errorf("%q is not supported", cfg.Step2.BenchType) + } + } + + bts, err := ioutil.ReadFile(cfg.GoogleCloudStorageKeyPath) + if err != nil { + return err + } + cfg.GoogleCloudStorageKey = string(bts) + + cfg.PeerIPString = strings.Join(cfg.PeerIPs, "___") // protoc sorts the 'repeated' type data + cfg.AgentEndpoints = make([]string, len(cfg.PeerIPs)) + cfg.DatabaseEndpoints = make([]string, len(cfg.PeerIPs)) + for i := range cfg.PeerIPs { + cfg.AgentEndpoints[i] = fmt.Sprintf("%s:%d", cfg.PeerIPs[i], cfg.AgentPort) + } + for i := range cfg.PeerIPs { + cfg.DatabaseEndpoints[i] = fmt.Sprintf("%s:%d", cfg.PeerIPs[i], cfg.DatabasePort) + } + + println() + if !cfg.Step1.SkipStartDatabase { + plog.Info("step 1: starting databases...") + if err = step1(cfg); err != nil { + return err + } + } + + if !cfg.Step2.SkipStressDatabase { + println() + time.Sleep(5 * time.Second) + plog.Info("step 2: starting tests...") + if err = step2(cfg); err != nil { + return err + } + } + + println() + time.Sleep(5 * time.Second) + if err := step3(cfg); err != nil { + return err + } + + { + u, err := remotestorage.NewGoogleCloudStorage([]byte(cfg.GoogleCloudStorageKey), cfg.GoogleCloudProjectName) + if err != nil { + plog.Fatal(err) + } + srcCSVResultPath := cfg.ResultPathTimeSeries + dstCSVResultPath := filepath.Base(cfg.ResultPathTimeSeries) + if !strings.HasPrefix(dstCSVResultPath, cfg.TestName) { + dstCSVResultPath = fmt.Sprintf("%s-%s", cfg.TestName, dstCSVResultPath) + } + dstCSVResultPath = filepath.Join(cfg.GoogleCloudStorageSubDirectory, dstCSVResultPath) + + var uerr error + for k := 0; k < 15; k++ { + if uerr = u.UploadFile(cfg.GoogleCloudStorageBucketName, srcCSVResultPath, dstCSVResultPath); uerr != nil { + plog.Printf("#%d: UploadFile error %v", k, uerr) + time.Sleep(2 * time.Second) + continue + } + break + } + } + { + u, err := remotestorage.NewGoogleCloudStorage([]byte(cfg.GoogleCloudStorageKey), cfg.GoogleCloudProjectName) + if err != nil { + plog.Fatal(err) + } + + srcCSVResultPath := cfg.ResultPathLog + dstCSVResultPath := filepath.Base(cfg.ResultPathLog) + if !strings.HasPrefix(dstCSVResultPath, cfg.TestName) { + dstCSVResultPath = fmt.Sprintf("%s-%s", cfg.TestName, dstCSVResultPath) + } + dstCSVResultPath = filepath.Join(cfg.GoogleCloudStorageSubDirectory, dstCSVResultPath) + + var uerr error + for k := 0; k < 15; k++ { + if uerr = u.UploadFile(cfg.GoogleCloudStorageBucketName, srcCSVResultPath, dstCSVResultPath); uerr != nil { + plog.Printf("#%d: UploadFile error %v", k, uerr) + time.Sleep(2 * time.Second) + continue + } + break + } + } + + return nil +} diff --git a/control/config.go b/control/config.go index 82aabab5..4e803438 100644 --- a/control/config.go +++ b/control/config.go @@ -1,4 +1,4 @@ -// Copyright 2016 CoreOS, Inc. +// Copyright 2017 CoreOS, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/control/config_test.go b/control/config_test.go index dbad2530..bc241388 100644 --- a/control/config_test.go +++ b/control/config_test.go @@ -1,4 +1,4 @@ -// Copyright 2016 CoreOS, Inc. +// Copyright 2017 CoreOS, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/control/doc.go b/control/doc.go index 3b3c4ebf..88b8ff32 100644 --- a/control/doc.go +++ b/control/doc.go @@ -1,4 +1,4 @@ -// Copyright 2016 CoreOS, Inc. +// Copyright 2017 CoreOS, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/control/io.go b/control/io.go index 471c4492..89015c74 100644 --- a/control/io.go +++ b/control/io.go @@ -1,4 +1,4 @@ -// Copyright 2016 CoreOS, Inc. +// Copyright 2017 CoreOS, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/control/logger.go b/control/logger.go index 32e8c807..0ad4f396 100644 --- a/control/logger.go +++ b/control/logger.go @@ -1,4 +1,4 @@ -// Copyright 2016 CoreOS, Inc. +// Copyright 2017 CoreOS, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/control/control.go b/control/step.go similarity index 80% rename from control/control.go rename to control/step.go index fe5e5476..45551346 100644 --- a/control/control.go +++ b/control/step.go @@ -1,4 +1,4 @@ -// Copyright 2016 CoreOS, Inc. +// Copyright 2017 CoreOS, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,16 +16,11 @@ package control import ( "fmt" - "io/ioutil" "os" - "path/filepath" - "strings" "sync" "time" "github.com/coreos/dbtester/agent" - "github.com/coreos/dbtester/remotestorage" - "github.com/spf13/cobra" "golang.org/x/net/context" "golang.org/x/time/rate" "google.golang.org/grpc" @@ -35,133 +30,6 @@ import ( consulapi "github.com/hashicorp/consul/api" ) -var ( - // Command implements 'control' command. - Command = &cobra.Command{ - Use: "control", - Short: "Controls tests.", - RunE: commandFunc, - } - configPath string -) - -func init() { - Command.PersistentFlags().StringVarP(&configPath, "config", "c", "", "YAML configuration file path.") -} - -func commandFunc(cmd *cobra.Command, args []string) error { - cfg, err := ReadConfig(configPath) - if err != nil { - return err - } - switch cfg.Database { - case "etcdv2": - case "etcdv3": - case "zk", "zookeeper": - case "zetcd": - case "consul": - case "cetcd": - default: - return fmt.Errorf("%q is not supported", cfg.Database) - } - if !cfg.Step2.SkipStressDatabase { - switch cfg.Step2.BenchType { - case "write": - case "read": - case "read-oneshot": - default: - return fmt.Errorf("%q is not supported", cfg.Step2.BenchType) - } - } - - bts, err := ioutil.ReadFile(cfg.GoogleCloudStorageKeyPath) - if err != nil { - return err - } - cfg.GoogleCloudStorageKey = string(bts) - - cfg.PeerIPString = strings.Join(cfg.PeerIPs, "___") // protoc sorts the 'repeated' type data - cfg.AgentEndpoints = make([]string, len(cfg.PeerIPs)) - cfg.DatabaseEndpoints = make([]string, len(cfg.PeerIPs)) - for i := range cfg.PeerIPs { - cfg.AgentEndpoints[i] = fmt.Sprintf("%s:%d", cfg.PeerIPs[i], cfg.AgentPort) - } - for i := range cfg.PeerIPs { - cfg.DatabaseEndpoints[i] = fmt.Sprintf("%s:%d", cfg.PeerIPs[i], cfg.DatabasePort) - } - - println() - if !cfg.Step1.SkipStartDatabase { - plog.Info("step 1: starting databases...") - if err = step1(cfg); err != nil { - return err - } - } - - if !cfg.Step2.SkipStressDatabase { - println() - time.Sleep(5 * time.Second) - plog.Info("step 2: starting tests...") - if err = step2(cfg); err != nil { - return err - } - } - - println() - time.Sleep(5 * time.Second) - if err := step3(cfg); err != nil { - return err - } - - { - u, err := remotestorage.NewGoogleCloudStorage([]byte(cfg.GoogleCloudStorageKey), cfg.GoogleCloudProjectName) - if err != nil { - plog.Fatal(err) - } - srcCSVResultPath := cfg.ResultPathTimeSeries - dstCSVResultPath := filepath.Base(cfg.ResultPathTimeSeries) - if !strings.HasPrefix(dstCSVResultPath, cfg.TestName) { - dstCSVResultPath = fmt.Sprintf("%s-%s", cfg.TestName, dstCSVResultPath) - } - dstCSVResultPath = filepath.Join(cfg.GoogleCloudStorageSubDirectory, dstCSVResultPath) - - var uerr error - for k := 0; k < 15; k++ { - if uerr = u.UploadFile(cfg.GoogleCloudStorageBucketName, srcCSVResultPath, dstCSVResultPath); uerr != nil { - plog.Printf("#%d: UploadFile error %v", k, uerr) - time.Sleep(2 * time.Second) - continue - } - break - } - } - { - u, err := remotestorage.NewGoogleCloudStorage([]byte(cfg.GoogleCloudStorageKey), cfg.GoogleCloudProjectName) - if err != nil { - plog.Fatal(err) - } - - srcCSVResultPath := cfg.ResultPathLog - dstCSVResultPath := filepath.Base(cfg.ResultPathLog) - if !strings.HasPrefix(dstCSVResultPath, cfg.TestName) { - dstCSVResultPath = fmt.Sprintf("%s-%s", cfg.TestName, dstCSVResultPath) - } - dstCSVResultPath = filepath.Join(cfg.GoogleCloudStorageSubDirectory, dstCSVResultPath) - - var uerr error - for k := 0; k < 15; k++ { - if uerr = u.UploadFile(cfg.GoogleCloudStorageBucketName, srcCSVResultPath, dstCSVResultPath); uerr != nil { - plog.Printf("#%d: UploadFile error %v", k, uerr) - time.Sleep(2 * time.Second) - continue - } - break - } - } - - return nil -} - func step1(cfg Config) error { return bcastReq(cfg, agent.Request_Start) } type values struct { diff --git a/control/timeseries.go b/control/timeseries.go index 57066ff4..b596279f 100644 --- a/control/timeseries.go +++ b/control/timeseries.go @@ -1,4 +1,4 @@ -// Copyright 2016 CoreOS, Inc. +// Copyright 2017 CoreOS, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/control/timeseries_test.go b/control/timeseries_test.go index f3b34905..b0d107cb 100644 --- a/control/timeseries_test.go +++ b/control/timeseries_test.go @@ -1,4 +1,4 @@ -// Copyright 2016 CoreOS, Inc. +// Copyright 2017 CoreOS, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/control/util.go b/control/util.go index 8fcde386..5dac0ff6 100644 --- a/control/util.go +++ b/control/util.go @@ -1,4 +1,4 @@ -// Copyright 2015 CoreOS, Inc. +// Copyright 2017 CoreOS, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License.