Skip to content

Commit

Permalink
allow-taking-sidecar-route-from-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
cl1337 committed Jan 4, 2018
1 parent 6767b18 commit e495c02
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 5 deletions.
13 changes: 8 additions & 5 deletions backend/repository/client_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type configField struct {
ThriftFile string `json:"thriftFile"`
ThriftFileSha string `json:"thriftFileSha"`
ExposedMethods map[string]string `json:"exposedMethods,omitempty"`
SidecarRouter string `json:"sidecarRouter,omitempty"`
}

func correctMethodNaming(key string) string {
Expand All @@ -64,6 +65,7 @@ func NewClientConfigJSON(cfg *ClientConfig) *ClientJSONConfig {
Config: &configField{
ThriftFile: cfg.ThriftFile,
ExposedMethods: cfg.ExposedMethods,
SidecarRouter: cfg.SidecarRouter,
},
}
return cfgJSON
Expand Down Expand Up @@ -95,7 +97,6 @@ func (r *Repository) UpdateClientConfigs(req *ClientConfig, clientCfgDir, thrift
updatedExposedMethod[k] = val
}
cfgJSON.Config.ExposedMethods = updatedExposedMethod

cfgJSON.Config.ThriftFileSha = thriftFileSha
clientPath := filepath.Join(r.absPath(clientCfgDir), cfgJSON.Name)
if err := os.MkdirAll(clientPath, os.ModePerm); err != nil {
Expand Down Expand Up @@ -138,11 +139,11 @@ func validateClientUpdateRequest(req *ClientConfig) error {
return reqerr.NewRequestError(
reqerr.ClientsServiceName, errors.New("invalid request: muttley name is required for tchannel client"))
}
if req.IP == "" || req.Port == 0 {
if len(req.SidecarRouter) < 1 && req.IP == "" {
return reqerr.NewRequestError(
reqerr.ClientsIP, errors.New("invalid request: ip is required"))
}
if req.Port == 0 {
if len(req.SidecarRouter) < 1 && req.Port == 0 {
return reqerr.NewRequestError(
reqerr.ClientsPort, errors.New("invalid request: port is required"))
}
Expand Down Expand Up @@ -195,8 +196,10 @@ func UpdateProductionConfigJSON(req *ClientConfig, productionCfgJSONPath string)
content[prefix+"routingKey"] = req.RoutingKey
}
}
content[prefix+"port"] = req.Port
content[prefix+"ip"] = req.IP
if len(req.SidecarRouter) < 1 {
content[prefix+"port"] = req.Port
content[prefix+"ip"] = req.IP
}
return writeToJSONFile(productionCfgJSONPath, content)
}

Expand Down
17 changes: 17 additions & 0 deletions backend/repository/client_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ func TestUpdateHTTPClientWithoutExposedMethods(t *testing.T) {
testUpdateClientConfig(t, req, "contacts")
}

func TestUpdateTchannelClientWithSidecarRouter(t *testing.T) {
req := &ClientConfig{
Name: "corge",
Type: "tchannel",
ThriftFile: "clients/corge/corge.thrift",
ServiceName: "Corge",
ExposedMethods: map[string]string{
"EchoString": "Corge::echoString",
},
SidecarRouter: "default",
IP: "127.0.0.1",
Timeout: 10000,
TimeoutPerAttempt: 2000,
}
testUpdateClientConfig(t, req, "corge")
}

func TestUpdateTchannelClient(t *testing.T) {
req := &ClientConfig{}
err := readJSONFile(tchannelClientUpdateRequestFile, req)
Expand Down
1 change: 1 addition & 0 deletions backend/repository/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type ClientConfig struct {
Timeout int64 `json:"clientTimeout,omitempty"`
TimeoutPerAttempt int64 `json:"clientTimeoutPerAttempt,omitempty"`
RoutingKey string `json:"routingKey"`
SidecarRouter string `json:"sidecarRouter,omitempty"`
}

// EndpointMiddlewareConfig is the configuration for a middleware instance for a endpoint
Expand Down
73 changes: 73 additions & 0 deletions backend/repository/data/handler/test_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,79 @@
}
}
},
{
"name": "create-diff-sidecar",
"request": {
"method": "POST",
"url": "/create-diff",
"header": {
"gateway-id": "example-gateway"
},
"body": {
"client_updates": [
{
"clientTimeout": 10000,
"clientTimeoutPerAttempt": 2000,
"exposedMethods": {
"Call": "SimpleService::call",
"Compare": "SimpleService::compare",
"DeliberateDiffNoop": "SimpleService::sillyNoop",
"EchoBinary": "SecondService::echoBinary",
"EchoBool": "SecondService::echoBool",
"EchoDouble": "SecondService::echoDouble",
"EchoEnum": "SecondService::echoEnum",
"EchoI16": "SecondService::echoI16",
"EchoI32": "SecondService::echoI32",
"EchoI64": "SecondService::echoI64",
"EchoI8": "SecondService::echoI8",
"EchoString": "SecondService::echoString",
"EchoStringList": "SecondService::echoStringList",
"EchoStringMap": "SecondService::echoStringMap",
"EchoStringSet": "SecondService::echoStringSet",
"EchoStructList": "SecondService::echoStructList",
"EchoStructMap": "SecondService::echoStructMap",
"EchoStructSet": "SecondService::echoStructSet",
"EchoTypedef": "SecondService::echoTypedef",
"Ping": "SimpleService::ping",
"Trans": "SimpleService::trans"
},
"ip": "127.0.0.1",
"name": "baz",
"sidecarRouter": "default",
"serviceName": "Qux",
"thriftFile": "clients/baz/baz.thrift",
"type": "tchannel"
}
],
"endpoint_updates": [
{
"clientId": "baz",
"clientMethod": "Compare",
"endpointId": "baz",
"endpointType": "http",
"handleId": "compare",
"middlewares": [],
"reqHeaderMap": {},
"resHeaderMap": {},
"testFixtures": {},
"thriftFile": "endpoints/baz/baz.thrift",
"thriftFileSha": "{{placeholder}}",
"thriftMethodName": "SimpleService::compare",
"workflowType": "tchannelClient"
}
],
"thrift_files": [
"clients/baz/baz.thrift"
]
}
},
"response": {
"code": 200,
"body": {
"diff_uri": "http://diff-for-example-gateway"
}
}
},
{
"name": "create-diff-managed-thrift",
"request": {
Expand Down

0 comments on commit e495c02

Please sign in to comment.