Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhenghui Wang committed Jul 7, 2017
1 parent 177f82d commit 71a53ac
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
26 changes: 8 additions & 18 deletions backend/repository/client_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sort"

"github.com/pkg/errors"
"github.com/uber/zanzibar/codegen"
)

// ClientJSONConfig defines the JSON content of the configuration file.
Expand All @@ -44,7 +45,7 @@ type configField struct {
}

// NewClientConfigJSON converts ClientConfig to ClientJSONConfig.
func NewClientConfigJSON(cfg ClientConfig) *ClientJSONConfig {
func NewClientConfigJSON(cfg *ClientConfig) *ClientJSONConfig {
cfgJSON := &ClientJSONConfig{
Name: cfg.Name,
Type: string(cfg.Type),
Expand All @@ -61,7 +62,7 @@ func (r *Repository) UpdateClientConfigs(req *ClientConfig, clientCfgDir, thrift
if err := validateClientUpdateRequest(req); err != nil {
return err
}
cfgJSON := NewClientConfigJSON(*req)
cfgJSON := NewClientConfigJSON(req)
cfgJSON.Config.ThriftFileSha = thriftFileSha
clientPath := filepath.Join(r.absPath(clientCfgDir), cfgJSON.Name)
r.Lock()
Expand All @@ -85,7 +86,7 @@ func validateClientUpdateRequest(req *ClientConfig) error {
if len(req.ExposedMethods) == 0 {
return errors.New("invalid request: no method is exposed for the client")
}
if req.Type == "tchannel" && req.MuttleyName == "" {
if req.Type == "tchannel" && req.ServiceName == "" {
return errors.New("invalid request: muttley name is required for tchannel client")
}
if req.IP == "" || req.Port == 0 {
Expand All @@ -100,17 +101,6 @@ func validateClientUpdateRequest(req *ClientConfig) error {
return nil
}

type clientModuleJSONConfig struct {
Name string `json:"name"`
Type string `json:"type"`
Config interface{} `json:"config"`
Dependencies dependencies `json:"dependencies"`
}

type dependencies struct {
Client []string `json:"client"`
}

// WriteClientModuleJSON writes the JSON file for the module to contain all clients.
func WriteClientModuleJSON(clientCfgDir string) error {
files, err := ioutil.ReadDir(clientCfgDir)
Expand All @@ -124,11 +114,11 @@ func WriteClientModuleJSON(clientCfgDir string) error {
}
}
sort.Strings(subDirs)
content := &clientModuleJSONConfig{
content := &codegen.ClientClassConfig{
Name: "clients",
Type: "init",
Config: struct{}{},
Dependencies: dependencies{
Config: map[string]interface{}{},
Dependencies: codegen.ClientDependencies{
Client: subDirs,
},
}
Expand All @@ -144,7 +134,7 @@ func UpdateProductionConfigJSON(req *ClientConfig, productionCfgJSONPath string)
// Update fields related to a client.
prefix := "clients." + req.Name + "."
if req.Type == "tchannel" {
content[prefix+"serviceName"] = req.MuttleyName
content[prefix+"serviceName"] = req.ServiceName
content[prefix+"timeout"] = req.Timeout
content[prefix+"timeoutPerAttempt"] = req.TimeoutPerAttempt
}
Expand Down
4 changes: 2 additions & 2 deletions backend/repository/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type ClientConfig struct {
Name string `json:"name"`
Type ProtocolType `json:"type"`
ThriftFile string `json:"thriftFile,omitempty"`
MuttleyName string `json:"muttleyName,omitempty"`
ServiceName string `json:"serviceName,omitempty"`
ExposedMethods map[string]string `json:"exposedMethods,omitempty"`
IP string `json:"ip,omitempty"`
Port int64 `json:"port,omitempty"`
Expand Down Expand Up @@ -286,7 +286,7 @@ func clientConfig(spec *codegen.ClientSpec, productionCfgJSON map[string]interfa
return clientConfig, nil
}
// tchannel related fields.
clientConfig.MuttleyName, err = convStrVal(productionCfgJSON, prefix+"serviceName")
clientConfig.ServiceName, err = convStrVal(productionCfgJSON, prefix+"serviceName")
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion backend/repository/data/client/baz_client_update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "baz",
"type": "tchannel",
"thriftFile": "clients/baz/baz.thrift",
"muttleyName": "Qux",
"serviceName": "Qux",
"exposedMethods": {
"Call": "SimpleService::call",
"Compare": "SimpleService::compare",
Expand Down
2 changes: 1 addition & 1 deletion backend/repository/data/gateway_config_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"name": "baz",
"type": "tchannel",
"thriftFile": "clients/baz/baz.thrift",
"muttleyName": "Qux",
"serviceName": "Qux",
"exposedMethods": {
"Call": "SimpleService::call",
"Compare": "SimpleService::compare",
Expand Down
12 changes: 9 additions & 3 deletions codegen/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,15 @@ type ModuleClassConfig struct {
// ClientClassConfig represents the specific config for
// a client. This is a downcast of the moduleClassConfig.
type ClientClassConfig struct {
Name string `json:"name"`
Type string `json:"type"`
Config map[string]interface{} `json:"config"`
Name string `json:"name"`
Type string `json:"type"`
Config map[string]interface{} `json:"config"`
Dependencies ClientDependencies `json:"dependencies"`
}

// ClientDependencies lists all depedencies of a client.
type ClientDependencies struct {
Client []string `json:"client"`
}

// NewClientSpec creates a client spec from a json file.
Expand Down

0 comments on commit 71a53ac

Please sign in to comment.