Skip to content

Commit

Permalink
v8(services): unbind-route-service cmd use V3 API (#2107)
Browse files Browse the repository at this point in the history
* v8(services): unbind-route-service cmd use V3 API

[#175143303](https://www.pivotaltracker.com/story/show/175143303)
[#175143298](https://www.pivotaltracker.com/story/show/175143298)
[#175143301](https://www.pivotaltracker.com/story/show/175143301)

* Fixed capitalization in error

Co-authored-by: Felisia Martini <[email protected]>
  • Loading branch information
blgm and FelisiaM authored Nov 9, 2020
1 parent e3856be commit bef0232
Show file tree
Hide file tree
Showing 18 changed files with 1,491 additions and 63 deletions.
7 changes: 7 additions & 0 deletions actor/actionerror/route_binding_not_found_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package actionerror

type RouteBindingNotFoundError struct{}

func (e RouteBindingNotFoundError) Error() string {
return "Route binding not found."
}
1 change: 1 addition & 0 deletions actor/v7action/cloud_controller_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type CloudControllerClient interface {
DeleteOrphanedRoutes(spaceGUID string) (ccv3.JobURL, ccv3.Warnings, error)
DeleteRole(roleGUID string) (ccv3.JobURL, ccv3.Warnings, error)
DeleteRoute(routeGUID string) (ccv3.JobURL, ccv3.Warnings, error)
DeleteRouteBinding(guid string) (ccv3.JobURL, ccv3.Warnings, error)
DeleteSecurityGroup(securityGroupGUID string) (ccv3.JobURL, ccv3.Warnings, error)
DeleteServiceCredentialBinding(guid string) (ccv3.JobURL, ccv3.Warnings, error)
DeleteServiceBroker(serviceBrokerGUID string) (ccv3.JobURL, ccv3.Warnings, error)
Expand Down
104 changes: 95 additions & 9 deletions actor/v7action/route_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,24 @@ type CreateRouteBindingParams struct {
Parameters types.OptionalObject
}

type DeleteRouteBindingParams struct {
SpaceGUID string
ServiceInstanceName string
DomainName string
Hostname string
Path string
}

type getRouteForBindingParams struct {
SpaceGUID string
DomainName string
Hostname string
Path string
}

func (actor Actor) CreateRouteBinding(params CreateRouteBindingParams) (chan PollJobEvent, Warnings, error) {
var (
serviceInstance resources.ServiceInstance
domain resources.Domain
route resources.Route
jobURL ccv3.JobURL
stream chan PollJobEvent
Expand All @@ -33,15 +47,56 @@ func (actor Actor) CreateRouteBinding(params CreateRouteBindingParams) (chan Pol
return
},
func() (warnings ccv3.Warnings, err error) {
domain, warnings, err = actor.getDomainByName(params.DomainName)
route, warnings, err = actor.getRouteForBinding(getRouteForBindingParams{
SpaceGUID: params.SpaceGUID,
DomainName: params.DomainName,
Hostname: params.Hostname,
Path: params.Path,
})
return
},
func() (warnings ccv3.Warnings, err error) {
route, warnings, err = actor.getRouteForBinding(params, domain)
jobURL, warnings, err = actor.createRouteBinding(serviceInstance.GUID, route.GUID, params.Parameters)
return
},
func() (warnings ccv3.Warnings, err error) {
jobURL, warnings, err = actor.createRouteBinding(serviceInstance.GUID, route.GUID, params.Parameters)
stream = actor.PollJobToEventStream(jobURL)
return
},
)

return stream, Warnings(warnings), err
}

func (actor Actor) DeleteRouteBinding(params DeleteRouteBindingParams) (chan PollJobEvent, Warnings, error) {
var (
serviceInstance resources.ServiceInstance
route resources.Route
binding resources.RouteBinding
jobURL ccv3.JobURL
stream chan PollJobEvent
)

warnings, err := railway.Sequentially(
func() (warnings ccv3.Warnings, err error) {
serviceInstance, _, warnings, err = actor.getServiceInstanceByNameAndSpace(params.ServiceInstanceName, params.SpaceGUID)
return
},
func() (warnings ccv3.Warnings, err error) {
route, warnings, err = actor.getRouteForBinding(getRouteForBindingParams{
SpaceGUID: params.SpaceGUID,
DomainName: params.DomainName,
Hostname: params.Hostname,
Path: params.Path,
})
return
},
func() (warnings ccv3.Warnings, err error) {
binding, warnings, err = actor.getRouteBinding(serviceInstance.GUID, route.GUID)
return
},
func() (warnings ccv3.Warnings, err error) {
jobURL, warnings, err = actor.CloudControllerClient.DeleteRouteBinding(binding.GUID)
return
},
func() (warnings ccv3.Warnings, err error) {
Expand Down Expand Up @@ -69,12 +124,43 @@ func (actor Actor) createRouteBinding(serviceInstanceGUID, routeGUID string, par
}
}

func (actor Actor) getRouteForBinding(params CreateRouteBindingParams, domain resources.Domain) (resources.Route, ccv3.Warnings, error) {
routes, warnings, err := actor.CloudControllerClient.GetRoutes(
ccv3.Query{Key: ccv3.DomainGUIDFilter, Values: []string{domain.GUID}},
ccv3.Query{Key: ccv3.HostsFilter, Values: []string{params.Hostname}},
ccv3.Query{Key: ccv3.PathsFilter, Values: []string{params.Path}},
func (actor Actor) getRouteBinding(serviceInstanceGUID, routeGUID string) (resources.RouteBinding, ccv3.Warnings, error) {
bindings, _, warnings, err := actor.CloudControllerClient.GetRouteBindings(
ccv3.Query{Key: ccv3.RouteGUIDFilter, Values: []string{routeGUID}},
ccv3.Query{Key: ccv3.ServiceInstanceGUIDFilter, Values: []string{serviceInstanceGUID}},
)

switch {
case err != nil:
return resources.RouteBinding{}, warnings, err
case len(bindings) == 0:
return resources.RouteBinding{}, warnings, actionerror.RouteBindingNotFoundError{}
default:
return bindings[0], warnings, nil
}
}

func (actor Actor) getRouteForBinding(params getRouteForBindingParams) (resources.Route, ccv3.Warnings, error) {
var (
domain resources.Domain
routes []resources.Route
)

warnings, err := railway.Sequentially(
func() (warnings ccv3.Warnings, err error) {
domain, warnings, err = actor.getDomainByName(params.DomainName)
return
},
func() (warnings ccv3.Warnings, err error) {
routes, warnings, err = actor.CloudControllerClient.GetRoutes(
ccv3.Query{Key: ccv3.DomainGUIDFilter, Values: []string{domain.GUID}},
ccv3.Query{Key: ccv3.HostsFilter, Values: []string{params.Hostname}},
ccv3.Query{Key: ccv3.PathsFilter, Values: []string{params.Path}},
)
return
},
)

switch {
case err != nil:
return resources.Route{}, warnings, err
Expand Down
Loading

0 comments on commit bef0232

Please sign in to comment.