Fix type errors and code cleanup.

This commit is contained in:
Pradyumna Kaushik 2018-06-21 18:33:49 -07:00
parent db69f0268d
commit 277d929950

View file

@ -20,7 +20,11 @@ import (
"fmt" "fmt"
"github.com/paypal/gorealis" "github.com/paypal/gorealis"
"github.com/paypal/gorealis/gen-go/apache/aurora" "github.com/paypal/gorealis/gen-go/apache/aurora"
"github.com/pkg/errors"
"io/ioutil"
"log"
"os" "os"
"time"
) )
type URIJson struct { type URIJson struct {
@ -64,33 +68,21 @@ func (j *JobJson) Validate() bool {
return true return true
} }
type ZKClusterConfig struct { type Config struct {
Name string `json:"name"` Username string `json:"username"`
AgentRoot string `json:"slave_root"` Password string `json:"password"`
AgentRunDir string `json:"slave_run_directory"` SchedUrl string `json:"schedUrl"`
ZK string `json:"zk"` BinTransport bool `json:"bin_transport,omitempty"`
ZKPort int `json:"zk_port"` JsonTransport bool `json:"json_transport,omitempty"`
SchedZKPath string `json:"scheduler_zk_path"` ClusterConfig *realis.Cluster `json:"cluster"`
SchedURI string `json:"scheduler_uri"` Debug bool `json:"debug,omitempty"`
ProxyURL string `json:"proxy_url"`
AuthMechanism string `json:"auth_mechanism"`
}
type ConfigJson struct {
Username string `json:"username"`
Password string `json:"password"`
SchedUrl string `json:"schedUrl"`
BinTransport bool `json:"bin_transport,omitempty"`
JsonTransport bool `json:"json_transport,omitempty"`
ClusterConfig *ZKClusterConfig `json:"zkCluster"`
Debug bool `json:"debug,omitempty"`
} }
// Command-line arguments for config and job JSON files. // Command-line arguments for config and job JSON files.
var configJSONFile, jobJSONFile string var configJSONFile, jobJSONFile string
var job JobJson var job *JobJson
var config ConfigJson var config *Config
// Reading command line arguments and validating. // Reading command line arguments and validating.
// If Aurora scheduler URL not provided, then using zookeeper to locate the leader. // If Aurora scheduler URL not provided, then using zookeeper to locate the leader.
@ -101,9 +93,9 @@ func init() {
flag.Parse() flag.Parse()
job = new(JobJson) job = new(JobJson)
config = new(realis.RealisConfig) config = new(Config)
if jobsFile, jobJSONReadErr := os.Open(*jobJSONFile); jobJSONReadErr != nil { if jobsFile, jobJSONReadErr := os.Open(jobJSONFile); jobJSONReadErr != nil {
flag.Usage() flag.Usage()
fmt.Println("Error reading the job JSON file: ", jobJSONReadErr) fmt.Println("Error reading the job JSON file: ", jobJSONReadErr)
os.Exit(1) os.Exit(1)
@ -121,19 +113,19 @@ func init() {
} }
} }
if configFile, configJSONErr := os.Open(*configJSONFile); configJSONErr { if configFile, configJSONErr := os.Open(configJSONFile); configJSONErr != nil {
flag.Usage() flag.Usage()
fmt.Println("Error reading the config JSON file: ", configJSONErr) fmt.Println("Error reading the config JSON file: ", configJSONErr)
os.Exit(1) os.Exit(1)
} else { } else {
if unmarshallErr := json.NewDecoder(configFile).Decode(config); unmarshallErr { if unmarshallErr := json.NewDecoder(configFile).Decode(config); unmarshallErr != nil {
fmt.Println("Error parsing config JSON file: ", unmarshallErr) fmt.Println("Error parsing config JSON file: ", unmarshallErr)
os.Exit(1) os.Exit(1)
} }
} }
} }
func main() { func CreateRealisClient(config *Config) (realis.Realis, error) {
var transportOption realis.ClientOption var transportOption realis.ClientOption
if config.BinTransport { if config.BinTransport {
transportOption = realis.ThriftBinary() transportOption = realis.ThriftBinary()