Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start two CNS servers with different handlers #2650

Merged
merged 42 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
36bbaa0
start two cns servers
paulyufan2 Mar 19, 2024
50acc81
fix linter issues
paulyufan2 Mar 19, 2024
08bb068
fix linter issue
paulyufan2 Mar 19, 2024
b67949e
enhance echo server log
paulyufan2 Mar 19, 2024
bfae5dc
fix Quang's comments
paulyufan2 Mar 25, 2024
0230fce
gofumpt cns service.go
paulyufan2 Mar 25, 2024
a2dac81
fix defaultAPIServerAddress
paulyufan2 Mar 25, 2024
3609723
run servers asynchoronsly
paulyufan2 Mar 26, 2024
0248412
add server_test.go
paulyufan2 Mar 26, 2024
d21068a
fix UT test
paulyufan2 Mar 26, 2024
1a0d47a
enhance log
paulyufan2 Mar 28, 2024
ead70b7
fix log issue
paulyufan2 Mar 28, 2024
6e408c3
fix an issue
paulyufan2 Mar 28, 2024
5c87958
add a check for defaultAPIServerURL
paulyufan2 Mar 28, 2024
5678a1d
fix GetOption func
paulyufan2 Mar 28, 2024
273cf96
enhance comments
paulyufan2 Mar 28, 2024
61bd529
fix defaultAPI URL to 127.0.0.1
paulyufan2 Mar 29, 2024
c727803
fix restapi method in echo server
paulyufan2 Mar 29, 2024
75e3347
remove unnecessary log info
paulyufan2 Mar 29, 2024
2f56c2d
fix comment1
paulyufan2 Apr 2, 2024
70420b4
fix comments
paulyufan2 Apr 2, 2024
dc59e97
add context to control echo server
paulyufan2 Apr 3, 2024
bb97a46
fix TM's comments
paulyufan2 Apr 3, 2024
179d936
do not enable local server if user specifies cnsurl by -c option
paulyufan2 Apr 9, 2024
0d52ef2
add -p port check when getting nodeURL
paulyufan2 Apr 9, 2024
fa517df
fix comments and use -p select from customer to start local server
paulyufan2 Apr 12, 2024
334e6b1
fix a case when customer does not provide -p option
paulyufan2 Apr 12, 2024
a6efa80
fix the issue if customer also does not provide -p and -c option
paulyufan2 Apr 15, 2024
2212ffe
add UTs to launch server with different combinations
paulyufan2 Apr 16, 2024
3081405
fix linter issue for UTs
paulyufan2 Apr 16, 2024
345419a
fix UT linter issues
paulyufan2 Apr 16, 2024
68be7fc
UT needs to stop service
paulyufan2 Apr 16, 2024
abaf171
remove duplicated test case
paulyufan2 Apr 16, 2024
d9294db
comments fix
paulyufan2 Apr 17, 2024
a5479e2
fix linter issue
paulyufan2 Apr 17, 2024
c052c37
fix Tim's comments
paulyufan2 Apr 18, 2024
b2d232c
fix comments
paulyufan2 Apr 29, 2024
b7734d8
Merge branch 'master' into startCnsListeners
paulyufan2 Apr 29, 2024
fcc0383
fix linter issue
paulyufan2 Apr 29, 2024
0893f51
handle type assertion
paulyufan2 Apr 29, 2024
187816b
Adding cnsURL and cnsPort options to test server
timraymond Apr 29, 2024
00d80c7
Merge branch 'master' into startCnsListeners
paulyufan2 Apr 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions cnm/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (plugin *ipamPlugin) getCapabilities(w http.ResponseWriter, r *http.Request
RequiresRequestReplay: requiresRequestReplay,
}

err := plugin.Listener.Encode(w, &resp)
err := common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -135,7 +135,7 @@ func (plugin *ipamPlugin) getDefaultAddressSpaces(w http.ResponseWriter, r *http
resp.LocalDefaultAddressSpace = localId
resp.GlobalDefaultAddressSpace = globalId

err := plugin.Listener.Encode(w, &resp)
err := common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -145,7 +145,7 @@ func (plugin *ipamPlugin) requestPool(w http.ResponseWriter, r *http.Request) {
var req RequestPoolRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand All @@ -163,7 +163,7 @@ func (plugin *ipamPlugin) requestPool(w http.ResponseWriter, r *http.Request) {
poolId = ipam.NewAddressPoolId(req.AddressSpace, poolId, "").String()
resp := RequestPoolResponse{PoolID: poolId, Pool: subnet, Data: data}

err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -173,7 +173,7 @@ func (plugin *ipamPlugin) releasePool(w http.ResponseWriter, r *http.Request) {
var req ReleasePoolRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand All @@ -195,7 +195,7 @@ func (plugin *ipamPlugin) releasePool(w http.ResponseWriter, r *http.Request) {
// Encode response.
resp := ReleasePoolResponse{}

err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -205,7 +205,7 @@ func (plugin *ipamPlugin) getPoolInfo(w http.ResponseWriter, r *http.Request) {
var req GetPoolInfoRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand Down Expand Up @@ -234,7 +234,7 @@ func (plugin *ipamPlugin) getPoolInfo(w http.ResponseWriter, r *http.Request) {
resp.UnhealthyAddresses = append(resp.UnhealthyAddresses, addr.String())
}

err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -244,7 +244,7 @@ func (plugin *ipamPlugin) requestAddress(w http.ResponseWriter, r *http.Request)
var req RequestAddressRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand Down Expand Up @@ -275,7 +275,7 @@ func (plugin *ipamPlugin) requestAddress(w http.ResponseWriter, r *http.Request)
data := make(map[string]string)
resp := RequestAddressResponse{Address: addr, Data: data}

err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -285,7 +285,7 @@ func (plugin *ipamPlugin) releaseAddress(w http.ResponseWriter, r *http.Request)
var req ReleaseAddressRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand All @@ -307,7 +307,7 @@ func (plugin *ipamPlugin) releaseAddress(w http.ResponseWriter, r *http.Request)
// Encode response.
resp := ReleaseAddressResponse{}

err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
30 changes: 15 additions & 15 deletions cnm/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (plugin *netPlugin) getCapabilities(w http.ResponseWriter, r *http.Request)
log.Request(plugin.Name, &req, nil)

resp := getCapabilitiesResponse{Scope: plugin.scope}
err := plugin.Listener.Encode(w, &resp)
err := common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -138,7 +138,7 @@ func (plugin *netPlugin) createNetwork(w http.ResponseWriter, r *http.Request) {
var req createNetworkRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand Down Expand Up @@ -182,7 +182,7 @@ func (plugin *netPlugin) createNetwork(w http.ResponseWriter, r *http.Request) {

// Encode response.
resp := createNetworkResponse{}
err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -192,7 +192,7 @@ func (plugin *netPlugin) deleteNetwork(w http.ResponseWriter, r *http.Request) {
var req deleteNetworkRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand All @@ -207,7 +207,7 @@ func (plugin *netPlugin) deleteNetwork(w http.ResponseWriter, r *http.Request) {

// Encode response.
resp := deleteNetworkResponse{}
err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -217,7 +217,7 @@ func (plugin *netPlugin) createEndpoint(w http.ResponseWriter, r *http.Request)
var req createEndpointRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand Down Expand Up @@ -256,7 +256,7 @@ func (plugin *netPlugin) createEndpoint(w http.ResponseWriter, r *http.Request)
// Encode response.
resp := createEndpointResponse{}

err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -266,7 +266,7 @@ func (plugin *netPlugin) deleteEndpoint(w http.ResponseWriter, r *http.Request)
var req deleteEndpointRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand All @@ -281,7 +281,7 @@ func (plugin *netPlugin) deleteEndpoint(w http.ResponseWriter, r *http.Request)

// Encode response.
resp := deleteEndpointResponse{}
err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -291,7 +291,7 @@ func (plugin *netPlugin) join(w http.ResponseWriter, r *http.Request) {
var req joinRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand All @@ -315,7 +315,7 @@ func (plugin *netPlugin) join(w http.ResponseWriter, r *http.Request) {
Gateway: ep.Gateways[0].String(),
}

err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -325,7 +325,7 @@ func (plugin *netPlugin) leave(w http.ResponseWriter, r *http.Request) {
var req leaveRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand All @@ -340,7 +340,7 @@ func (plugin *netPlugin) leave(w http.ResponseWriter, r *http.Request) {

// Encode response.
resp := leaveResponse{}
err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -350,7 +350,7 @@ func (plugin *netPlugin) endpointOperInfo(w http.ResponseWriter, r *http.Request
var req endpointOperInfoRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand All @@ -365,7 +365,7 @@ func (plugin *netPlugin) endpointOperInfo(w http.ResponseWriter, r *http.Request

// Encode response.
resp := endpointOperInfoResponse{Value: epInfo.Data}
err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
4 changes: 2 additions & 2 deletions cnm/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ func (plugin *Plugin) activate(w http.ResponseWriter, r *http.Request) {
log.Request(plugin.Name, &req, nil)

resp := ActivateResponse{Implements: plugin.Listener.GetEndpoints()}
err := plugin.Listener.Encode(w, &resp)
err := common.Encode(w, &resp)

log.Response(plugin.Name, &resp, 0, "Success", err)
}

// SendErrorResponse sends and logs an error response.
func (plugin *Plugin) SendErrorResponse(w http.ResponseWriter, errMsg error) {
resp := errorResponse{errMsg.Error()}
err := plugin.Listener.Encode(w, &resp)
err := common.Encode(w, &resp)

log.Response(plugin.Name, &resp, 0, "Success", err)
}
10 changes: 9 additions & 1 deletion cns/common/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,16 @@ type ServiceConfig struct {
Listener *acn.Listener
ErrChan chan<- error
Store store.KeyValueStore
Server server
ChannelMode string
TlsSettings tls.TlsSettings
TLSSettings tls.TlsSettings
}

// server struct to store primaryInterfaceIP from VM, port where customer provides by -p and temporary flag EnableLocalServer
type server struct {
PrimaryInterfaceIP string
Port string
EnableLocalServer bool // TODO: Remove this flag once -c option gets deprecated
}

// NewService creates a new Service object.
Expand Down
Loading
Loading