Skip to content

Commit

Permalink
allow fabric only testing to set fabric management as default API
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpmartinez committed Sep 17, 2024
1 parent 1daac1d commit 22a800b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
6 changes: 5 additions & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ func (c *Controller) initWeb() {
logrus.WithError(err).Fatalf("failed to create health checks api factory")
}

if err = c.xweb.GetRegistry().Add(webapis.NewFabricManagementApiFactory(c.config.Id, c.network, &c.xmgmts)); err != nil {
fabricManagementFactory := webapis.NewFabricManagementApiFactory(c.config.Id, c.network, &c.xmgmts)
if err = c.xweb.GetRegistry().Add(fabricManagementFactory); err != nil {
logrus.WithError(err).Fatalf("failed to create management api factory")
}

Expand Down Expand Up @@ -327,6 +328,9 @@ func (c *Controller) initWeb() {
}

webapis.OverrideRequestWrapper(webapis.NewFabricApiWrapper(c.env))
} else {
// if no edge we need 1 default API, make the fabric api the default
fabricManagementFactory.MakeDefault = true
}
c.xwebInitialized.MarkInitialized()
}
Expand Down
26 changes: 17 additions & 9 deletions controller/webapis/fabric-management-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ const (
var _ xweb.ApiHandlerFactory = &FabricManagementApiFactory{}

type FabricManagementApiFactory struct {
InitFunc func(managementApi *FabricManagementApiHandler) error
network *network.Network
nodeId identity.Identity
xmgmts *concurrenz.CopyOnWriteSlice[xmgmt.Xmgmt]
InitFunc func(managementApi *FabricManagementApiHandler) error
network *network.Network
nodeId identity.Identity
xmgmts *concurrenz.CopyOnWriteSlice[xmgmt.Xmgmt]
MakeDefault bool
}

func (factory *FabricManagementApiFactory) Validate(_ *xweb.InstanceConfig) error {
Expand All @@ -58,9 +59,10 @@ func (factory *FabricManagementApiFactory) Validate(_ *xweb.InstanceConfig) erro
func NewFabricManagementApiFactory(nodeId identity.Identity, network *network.Network, xmgmts *concurrenz.CopyOnWriteSlice[xmgmt.Xmgmt]) *FabricManagementApiFactory {
pfxlog.Logger().Infof("initializing management api factory with %d xmgmt instances", len(xmgmts.Value()))
return &FabricManagementApiFactory{
network: network,
nodeId: nodeId,
xmgmts: xmgmts,
network: network,
nodeId: nodeId,
xmgmts: xmgmts,
MakeDefault: false,
}
}

Expand Down Expand Up @@ -88,7 +90,7 @@ func (factory *FabricManagementApiFactory) New(_ *xweb.ServerConfig, options map
router.Register(fabricAPI, requestWrapper)
}

managementApiHandler, err := NewFabricManagementApiHandler(fabricAPI, options)
managementApiHandler, err := NewFabricManagementApiHandler(fabricAPI, factory.MakeDefault, options)

if err != nil {
return nil, err
Expand All @@ -105,10 +107,11 @@ func (factory *FabricManagementApiFactory) New(_ *xweb.ServerConfig, options map
return managementApiHandler, nil
}

func NewFabricManagementApiHandler(fabricApi *operations.ZitiFabricAPI, options map[interface{}]interface{}) (*FabricManagementApiHandler, error) {
func NewFabricManagementApiHandler(fabricApi *operations.ZitiFabricAPI, isDefault bool, options map[interface{}]interface{}) (*FabricManagementApiHandler, error) {
managementApi := &FabricManagementApiHandler{
fabricApi: fabricApi,
options: options,
isDefault: isDefault,
}

managementApi.handler = managementApi.newHandler()
Expand All @@ -125,6 +128,7 @@ type FabricManagementApiHandler struct {
wsUrl string
options map[interface{}]interface{}
bindHandler channel.BindHandler
isDefault bool
}

func (managementApi *FabricManagementApiHandler) Binding() string {
Expand Down Expand Up @@ -156,6 +160,10 @@ func (managementApi *FabricManagementApiHandler) newHandler() http.Handler {
return requestWrapper.WrapHttpHandler(innerManagementHandler)
}

func (managementApi *FabricManagementApiHandler) IsDefault() bool {
return managementApi.isDefault
}

func (managementApi *FabricManagementApiHandler) handleWebSocket(writer http.ResponseWriter, request *http.Request) {
log := pfxlog.Logger()
log.Debug("handling mgmt channel websocket upgrade")
Expand Down

0 comments on commit 22a800b

Please sign in to comment.