Skip to content

Commit

Permalink
Merge fabric and controller model code. Fixes #2205
Browse files Browse the repository at this point in the history
  • Loading branch information
plorenz committed Jul 9, 2024
1 parent e59b169 commit 20fbb63
Show file tree
Hide file tree
Showing 155 changed files with 3,425 additions and 3,639 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package network
package datastructures

import (
"github.com/openziti/storage/objectz"
Expand Down
5 changes: 3 additions & 2 deletions controller/api_impl/circuit_api_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package api_impl

import (
"github.com/openziti/ziti/controller/api"
"github.com/openziti/ziti/controller/model"
"github.com/openziti/ziti/controller/network"

"github.com/openziti/ziti/controller/rest_model"
Expand All @@ -44,7 +45,7 @@ func (factory *CircuitLinkFactoryIml) Links(entity LinkEntity) rest_model.Links
return links
}

func MapCircuitToRestModel(n *network.Network, _ api.RequestContext, circuit *network.Circuit) (*rest_model.CircuitDetail, error) {
func MapCircuitToRestModel(n *network.Network, _ api.RequestContext, circuit *model.Circuit) (*rest_model.CircuitDetail, error) {
path := &rest_model.Path{}
for _, node := range circuit.Path.Nodes {
path.Nodes = append(path.Nodes, ToEntityRef(node.Name, node, RouterLinkFactory))
Expand All @@ -54,7 +55,7 @@ func MapCircuitToRestModel(n *network.Network, _ api.RequestContext, circuit *ne
}

var svcEntityRef *rest_model.EntityRef
if svc, _ := n.Services.Read(circuit.ServiceId); svc != nil {
if svc, _ := n.Service.Read(circuit.ServiceId); svc != nil {
svcEntityRef = ToEntityRef(svc.Name, svc, ServiceLinkFactory)
} else {
svcEntityRef = ToEntityRef("<deleted>", deletedEntity(circuit.ServiceId), ServiceLinkFactory)
Expand Down
4 changes: 2 additions & 2 deletions controller/api_impl/inspections_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package api_impl

import (
"github.com/go-openapi/runtime/middleware"
"github.com/openziti/foundation/v2/stringz"
"github.com/openziti/ziti/controller/api"
"github.com/openziti/ziti/controller/network"
"github.com/openziti/ziti/controller/rest_model"
"github.com/openziti/ziti/controller/rest_server/operations"
"github.com/openziti/ziti/controller/rest_server/operations/inspect"
"github.com/openziti/foundation/v2/stringz"
"net/http"
)

Expand All @@ -49,7 +49,7 @@ func (r *InspectRouter) Register(fabricApi *operations.ZitiFabricAPI, wrapper Re
}

func (r *InspectRouter) Inspect(n *network.Network, rc api.RequestContext, request *rest_model.InspectRequest) {
result := n.Managers.Inspections.Inspect(stringz.OrEmpty(request.AppRegex), request.RequestedValues)
result := n.Inspections.Inspect(stringz.OrEmpty(request.AppRegex), request.RequestedValues)
resp := MapInspectResultToRestModel(n, result)
rc.Respond(resp, http.StatusOK)
}
5 changes: 3 additions & 2 deletions controller/api_impl/link_api_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package api_impl

import (
"github.com/openziti/ziti/controller/api"
"github.com/openziti/ziti/controller/model"
"github.com/openziti/ziti/controller/network"
"github.com/openziti/ziti/controller/rest_model"
)
Expand All @@ -41,7 +42,7 @@ func (factory *LinkLinkFactoryIml) Links(entity LinkEntity) rest_model.Links {
return links
}

func MapLinkToRestModel(n *network.Network, _ api.RequestContext, link *network.Link) (*rest_model.LinkDetail, error) {
func MapLinkToRestModel(n *network.Network, _ api.RequestContext, link *model.Link) (*rest_model.LinkDetail, error) {
iteration := int64(link.Iteration)
staticCost := int64(link.StaticCost)
linkStateStr := link.CurrentState().Mode.String()
Expand All @@ -51,7 +52,7 @@ func MapLinkToRestModel(n *network.Network, _ api.RequestContext, link *network.
destRouter := link.GetDest()
if destRouter == nil {
var err error
destRouter, err = n.Routers.Read(link.DstId)
destRouter, err = n.Router.Read(link.DstId)
if err != nil {
return nil, err
}
Expand Down
17 changes: 9 additions & 8 deletions controller/api_impl/router_api_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ package api_impl

import (
"github.com/openziti/ziti/controller/api"
"github.com/openziti/ziti/controller/model"
"github.com/openziti/ziti/controller/network"

"github.com/openziti/ziti/controller/rest_model"

"github.com/openziti/ziti/controller/models"
"github.com/openziti/foundation/v2/stringz"
"github.com/openziti/ziti/controller/models"
)

const EntityNameRouter = "routers"
Expand All @@ -46,8 +47,8 @@ func (factory *RouterLinkFactoryIml) Links(entity LinkEntity) rest_model.Links {
return links
}

func MapCreateRouterToModel(router *rest_model.RouterCreate) *network.Router {
ret := &network.Router{
func MapCreateRouterToModel(router *rest_model.RouterCreate) *model.Router {
ret := &model.Router{
BaseEntity: models.BaseEntity{
Id: stringz.OrEmpty(router.ID),
Tags: TagsOrDefault(router.Tags),
Expand All @@ -62,8 +63,8 @@ func MapCreateRouterToModel(router *rest_model.RouterCreate) *network.Router {
return ret
}

func MapUpdateRouterToModel(id string, router *rest_model.RouterUpdate) *network.Router {
ret := &network.Router{
func MapUpdateRouterToModel(id string, router *rest_model.RouterUpdate) *model.Router {
ret := &model.Router{
BaseEntity: models.BaseEntity{
Tags: TagsOrDefault(router.Tags),
Id: id,
Expand All @@ -78,8 +79,8 @@ func MapUpdateRouterToModel(id string, router *rest_model.RouterUpdate) *network
return ret
}

func MapPatchRouterToModel(id string, router *rest_model.RouterPatch) *network.Router {
ret := &network.Router{
func MapPatchRouterToModel(id string, router *rest_model.RouterPatch) *model.Router {
ret := &model.Router{
BaseEntity: models.BaseEntity{
Tags: TagsOrDefault(router.Tags),
Id: id,
Expand All @@ -96,7 +97,7 @@ func MapPatchRouterToModel(id string, router *rest_model.RouterPatch) *network.R

type RouterModelMapper struct{}

func (RouterModelMapper) ToApi(n *network.Network, _ api.RequestContext, router *network.Router) (interface{}, error) {
func (RouterModelMapper) ToApi(n *network.Network, _ api.RequestContext, router *model.Router) (interface{}, error) {
connected := n.GetConnectedRouter(router.Id)
var restVersionInfo *rest_model.VersionInfo
if connected != nil && connected.VersionInfo != nil {
Expand Down
15 changes: 8 additions & 7 deletions controller/api_impl/router_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/go-openapi/runtime/middleware"
"github.com/openziti/ziti/controller/api"
"github.com/openziti/ziti/controller/fields"
"github.com/openziti/ziti/controller/model"
"github.com/openziti/ziti/controller/network"
"github.com/openziti/ziti/controller/rest_server/operations"
"github.com/openziti/ziti/controller/rest_server/operations/router"
Expand Down Expand Up @@ -71,17 +72,17 @@ func (r *RouterRouter) Register(fabricApi *operations.ZitiFabricAPI, wrapper Req
}

func (r *RouterRouter) ListRouters(n *network.Network, rc api.RequestContext) {
ListWithHandler[*network.Router](n, rc, n.Managers.Routers, RouterModelMapper{})
ListWithHandler[*model.Router](n, rc, n.Managers.Router, RouterModelMapper{})
}

func (r *RouterRouter) Detail(n *network.Network, rc api.RequestContext) {
DetailWithHandler[*network.Router](n, rc, n.Managers.Routers, RouterModelMapper{})
DetailWithHandler[*model.Router](n, rc, n.Managers.Router, RouterModelMapper{})
}

func (r *RouterRouter) Create(n *network.Network, rc api.RequestContext, params router.CreateRouterParams) {
Create(rc, RouterLinkFactory, func() (string, error) {
router := MapCreateRouterToModel(params.Router)
err := n.Routers.Create(router, rc.NewChangeContext())
err := n.Router.Create(router, rc.NewChangeContext())
if err != nil {
return "", err
}
Expand All @@ -90,21 +91,21 @@ func (r *RouterRouter) Create(n *network.Network, rc api.RequestContext, params
}

func (r *RouterRouter) Delete(network *network.Network, rc api.RequestContext) {
DeleteWithHandler(rc, network.Managers.Routers)
DeleteWithHandler(rc, network.Managers.Router)
}

func (r *RouterRouter) Update(n *network.Network, rc api.RequestContext, params router.UpdateRouterParams) {
Update(rc, func(id string) error {
return n.Managers.Routers.Update(MapUpdateRouterToModel(params.ID, params.Router), nil, rc.NewChangeContext())
return n.Managers.Router.Update(MapUpdateRouterToModel(params.ID, params.Router), nil, rc.NewChangeContext())
})
}

func (r *RouterRouter) Patch(n *network.Network, rc api.RequestContext, params router.PatchRouterParams) {
Patch(rc, func(id string, fields fields.UpdatedFields) error {
return n.Managers.Routers.Update(MapPatchRouterToModel(params.ID, params.Router), fields.FilterMaps("tags"), rc.NewChangeContext())
return n.Managers.Router.Update(MapPatchRouterToModel(params.ID, params.Router), fields.FilterMaps("tags"), rc.NewChangeContext())
})
}

func (r *RouterRouter) listManagementTerminators(n *network.Network, rc api.RequestContext) {
ListAssociationWithHandler[*network.Router, *network.Terminator](n, rc, n.Managers.Routers, n.Managers.Terminators, TerminatorModelMapper{})
ListAssociationWithHandler[*model.Router, *model.Terminator](n, rc, n.Managers.Router, n.Managers.Terminator, TerminatorModelMapper{})
}
17 changes: 9 additions & 8 deletions controller/api_impl/service_api_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ package api_impl
import (
"github.com/openziti/ziti/controller/api"
"github.com/openziti/ziti/controller/idgen"
"github.com/openziti/ziti/controller/model"
"github.com/openziti/ziti/controller/network"

"github.com/openziti/ziti/controller/rest_model"

"github.com/openziti/ziti/controller/models"
"github.com/openziti/foundation/v2/stringz"
"github.com/openziti/ziti/controller/models"
)

const EntityNameService = "services"
Expand All @@ -47,8 +48,8 @@ func (factory *ServiceLinkFactoryIml) Links(entity LinkEntity) rest_model.Links
return links
}

func MapCreateServiceToModel(service *rest_model.ServiceCreate) *network.Service {
ret := &network.Service{
func MapCreateServiceToModel(service *rest_model.ServiceCreate) *model.Service {
ret := &model.Service{
BaseEntity: models.BaseEntity{
Tags: TagsOrDefault(service.Tags),
},
Expand All @@ -67,8 +68,8 @@ func MapCreateServiceToModel(service *rest_model.ServiceCreate) *network.Service
return ret
}

func MapUpdateServiceToModel(id string, service *rest_model.ServiceUpdate) *network.Service {
ret := &network.Service{
func MapUpdateServiceToModel(id string, service *rest_model.ServiceUpdate) *model.Service {
ret := &model.Service{
BaseEntity: models.BaseEntity{
Tags: TagsOrDefault(service.Tags),
Id: id,
Expand All @@ -80,8 +81,8 @@ func MapUpdateServiceToModel(id string, service *rest_model.ServiceUpdate) *netw
return ret
}

func MapPatchServiceToModel(id string, service *rest_model.ServicePatch) *network.Service {
ret := &network.Service{
func MapPatchServiceToModel(id string, service *rest_model.ServicePatch) *model.Service {
ret := &model.Service{
BaseEntity: models.BaseEntity{
Tags: TagsOrDefault(service.Tags),
Id: id,
Expand All @@ -95,7 +96,7 @@ func MapPatchServiceToModel(id string, service *rest_model.ServicePatch) *networ

type ServiceModelMapper struct{}

func (ServiceModelMapper) ToApi(_ *network.Network, _ api.RequestContext, service *network.Service) (interface{}, error) {
func (ServiceModelMapper) ToApi(_ *network.Network, _ api.RequestContext, service *model.Service) (interface{}, error) {
return &rest_model.ServiceDetail{
BaseEntity: BaseEntityToRestModel(service, ServiceLinkFactory),
Name: &service.Name,
Expand Down
15 changes: 8 additions & 7 deletions controller/api_impl/service_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/go-openapi/runtime/middleware"
"github.com/openziti/ziti/controller/api"
"github.com/openziti/ziti/controller/fields"
"github.com/openziti/ziti/controller/model"
"github.com/openziti/ziti/controller/network"
"github.com/openziti/ziti/controller/rest_server/operations"
"github.com/openziti/ziti/controller/rest_server/operations/service"
Expand Down Expand Up @@ -71,17 +72,17 @@ func (r *ServiceRouter) Register(fabricApi *operations.ZitiFabricAPI, wrapper Re
}

func (r *ServiceRouter) ListServices(n *network.Network, rc api.RequestContext) {
ListWithHandler[*network.Service](n, rc, n.Managers.Services, ServiceModelMapper{})
ListWithHandler[*model.Service](n, rc, n.Managers.Service, ServiceModelMapper{})
}

func (r *ServiceRouter) Detail(n *network.Network, rc api.RequestContext) {
DetailWithHandler[*network.Service](n, rc, n.Managers.Services, ServiceModelMapper{})
DetailWithHandler[*model.Service](n, rc, n.Managers.Service, ServiceModelMapper{})
}

func (r *ServiceRouter) Create(n *network.Network, rc api.RequestContext, params service.CreateServiceParams) {
Create(rc, ServiceLinkFactory, func() (string, error) {
svc := MapCreateServiceToModel(params.Service)
err := n.Services.Create(svc, rc.NewChangeContext())
err := n.Service.Create(svc, rc.NewChangeContext())
if err != nil {
return "", err
}
Expand All @@ -90,21 +91,21 @@ func (r *ServiceRouter) Create(n *network.Network, rc api.RequestContext, params
}

func (r *ServiceRouter) Delete(network *network.Network, rc api.RequestContext) {
DeleteWithHandler(rc, network.Managers.Services)
DeleteWithHandler(rc, network.Managers.Service)
}

func (r *ServiceRouter) Update(n *network.Network, rc api.RequestContext, params service.UpdateServiceParams) {
Update(rc, func(id string) error {
return n.Managers.Services.Update(MapUpdateServiceToModel(params.ID, params.Service), nil, rc.NewChangeContext())
return n.Managers.Service.Update(MapUpdateServiceToModel(params.ID, params.Service), nil, rc.NewChangeContext())
})
}

func (r *ServiceRouter) Patch(n *network.Network, rc api.RequestContext, params service.PatchServiceParams) {
Patch(rc, func(id string, fields fields.UpdatedFields) error {
return n.Managers.Services.Update(MapPatchServiceToModel(params.ID, params.Service), fields.FilterMaps("tags"), rc.NewChangeContext())
return n.Managers.Service.Update(MapPatchServiceToModel(params.ID, params.Service), fields.FilterMaps("tags"), rc.NewChangeContext())
})
}

func (r *ServiceRouter) listManagementTerminators(n *network.Network, rc api.RequestContext) {
ListAssociationWithHandler[*network.Service, *network.Terminator](n, rc, n.Managers.Services, n.Managers.Terminators, TerminatorModelMapper{})
ListAssociationWithHandler[*model.Service, *model.Terminator](n, rc, n.Managers.Service, n.Managers.Terminator, TerminatorModelMapper{})
}
25 changes: 13 additions & 12 deletions controller/api_impl/terminator_api_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ package api_impl
import (
"fmt"
"github.com/michaelquigley/pfxlog"
"github.com/openziti/foundation/v2/stringz"
"github.com/openziti/ziti/controller/api"
"github.com/openziti/ziti/controller/model"
"github.com/openziti/ziti/controller/models"
"github.com/openziti/ziti/controller/network"
"github.com/openziti/ziti/controller/xt"
"github.com/openziti/ziti/controller/rest_model"
"github.com/openziti/foundation/v2/stringz"
"github.com/openziti/ziti/controller/xt"
)

const EntityNameTerminator = "terminators"

var TerminatorLinkFactory = NewBasicLinkFactory(EntityNameTerminator)

func MapCreateTerminatorToModel(terminator *rest_model.TerminatorCreate) *network.Terminator {
ret := &network.Terminator{
func MapCreateTerminatorToModel(terminator *rest_model.TerminatorCreate) *model.Terminator {
ret := &model.Terminator{
BaseEntity: models.BaseEntity{
Tags: TagsOrDefault(terminator.Tags),
},
Expand All @@ -53,8 +54,8 @@ func MapCreateTerminatorToModel(terminator *rest_model.TerminatorCreate) *networ
return ret
}

func MapUpdateTerminatorToModel(id string, terminator *rest_model.TerminatorUpdate) *network.Terminator {
ret := &network.Terminator{
func MapUpdateTerminatorToModel(id string, terminator *rest_model.TerminatorUpdate) *model.Terminator {
ret := &model.Terminator{
BaseEntity: models.BaseEntity{
Tags: TagsOrDefault(terminator.Tags),
Id: id,
Expand All @@ -74,8 +75,8 @@ func MapUpdateTerminatorToModel(id string, terminator *rest_model.TerminatorUpda
return ret
}

func MapPatchTerminatorToModel(id string, terminator *rest_model.TerminatorPatch) *network.Terminator {
ret := &network.Terminator{
func MapPatchTerminatorToModel(id string, terminator *rest_model.TerminatorPatch) *model.Terminator {
ret := &model.Terminator{
BaseEntity: models.BaseEntity{
Tags: TagsOrDefault(terminator.Tags),
Id: id,
Expand All @@ -97,7 +98,7 @@ func MapPatchTerminatorToModel(id string, terminator *rest_model.TerminatorPatch

type TerminatorModelMapper struct{}

func (TerminatorModelMapper) ToApi(n *network.Network, _ api.RequestContext, terminator *network.Terminator) (interface{}, error) {
func (TerminatorModelMapper) ToApi(n *network.Network, _ api.RequestContext, terminator *model.Terminator) (interface{}, error) {
restModel, err := MapTerminatorToRestModel(n, terminator)

if err != nil {
Expand All @@ -109,13 +110,13 @@ func (TerminatorModelMapper) ToApi(n *network.Network, _ api.RequestContext, ter
return restModel, nil
}

func MapTerminatorToRestModel(n *network.Network, terminator *network.Terminator) (*rest_model.TerminatorDetail, error) {
service, err := n.Managers.Services.Read(terminator.Service)
func MapTerminatorToRestModel(n *network.Network, terminator *model.Terminator) (*rest_model.TerminatorDetail, error) {
service, err := n.Managers.Service.Read(terminator.Service)
if err != nil {
return nil, err
}

router, err := n.Managers.Routers.Read(terminator.Router)
router, err := n.Managers.Router.Read(terminator.Router)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 20fbb63

Please sign in to comment.