Skip to content

Commit

Permalink
[Feature/tas-e-51] Update destinantion command (cloudfoundry#2259)
Browse files Browse the repository at this point in the history
* Adds new update-destination command

update destination app-protocol for a route
so that the new protocol is used for all
communication from and to the app using that route

* Upgrades bundler version in integration go_ruby app
Co-authored-by: Cristhian Pena <cpena@vmware.com>
Co-authored-by: George Gelashvili <ggelashvili@vmware.com>
  • Loading branch information
jdgonzaleza authored and matt-royal committed Mar 11, 2022
1 parent a3eacad commit 3adeaba
Show file tree
Hide file tree
Showing 16 changed files with 975 additions and 2 deletions.
1 change: 1 addition & 0 deletions actor/v7action/cloud_controller_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ type CloudControllerClient interface {
UpdateApplicationRestart(appGUID string) (resources.Application, ccv3.Warnings, error)
UpdateApplicationStart(appGUID string) (resources.Application, ccv3.Warnings, error)
UpdateApplicationStop(appGUID string) (resources.Application, ccv3.Warnings, error)
UpdateDestination(routeGUID string, destinationGUID string, protocol string) (ccv3.Warnings, error)
UpdateBuildpack(buildpack resources.Buildpack) (resources.Buildpack, ccv3.Warnings, error)
UpdateEnvironmentVariableGroup(group constant.EnvironmentVariableGroupName, envVars resources.EnvironmentVariables) (resources.EnvironmentVariables, ccv3.Warnings, error)
UpdateFeatureFlag(flag resources.FeatureFlag) (resources.FeatureFlag, ccv3.Warnings, error)
Expand Down
4 changes: 4 additions & 0 deletions actor/v7action/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ func (actor Actor) MapRoute(routeGUID string, appGUID string, destinationProtoco
return Warnings(warnings), err
}

func (actor Actor) UpdateDestination(routeGUID string, destinationGUID string, protocol string) (Warnings, error) {
warnings, err := actor.CloudControllerClient.UpdateDestination(routeGUID, destinationGUID, protocol)
return Warnings(warnings), err
}
func (actor Actor) UnmapRoute(routeGUID string, destinationGUID string) (Warnings, error) {
warnings, err := actor.CloudControllerClient.UnmapRoute(routeGUID, destinationGUID)
return Warnings(warnings), err
Expand Down
43 changes: 43 additions & 0 deletions actor/v7action/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,49 @@ var _ = Describe("Route Actions", func() {
})
})

Describe("UpdateDestination", func() {
var (
routeGUID string
destinationGUID string
protocol string

executeErr error
warnings Warnings
)

JustBeforeEach(func() {
warnings, executeErr = actor.UpdateDestination(routeGUID, destinationGUID, protocol)
})

BeforeEach(func() {
routeGUID = "route-guid"
destinationGUID = "destination-guid"
protocol = "http2"
})

When("the cloud controller client errors", func() {
BeforeEach(func() {
fakeCloudControllerClient.UpdateDestinationReturns(ccv3.Warnings{"unmap-route-warning"}, errors.New("unmap-route-error"))
})

It("returns the error and warnings", func() {
Expect(executeErr).To(MatchError(errors.New("unmap-route-error")))
Expect(warnings).To(ConsistOf("unmap-route-warning"))
})
})

When("the cloud controller client succeeds", func() {
BeforeEach(func() {
fakeCloudControllerClient.UpdateDestinationReturns(ccv3.Warnings{"unmap-route-warning"}, nil)
})

It("returns the error and warnings", func() {
Expect(executeErr).ToNot(HaveOccurred())
Expect(warnings).To(ConsistOf("unmap-route-warning"))
})
})
})

Describe("DeleteOrphanedRoutes", func() {
var (
spaceGUID string
Expand Down
82 changes: 82 additions & 0 deletions actor/v7action/v7actionfakes/fake_cloud_controller_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/cloudcontroller/ccv3/internal/api_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const (
PatchApplicationFeaturesRequest = "PatchApplicationFeatures"
PatchEnvironmentVariableGroupRequest = "PatchEnvironmentVariableGroup"
PatchBuildpackRequest = "PatchBuildpack"
PatchDestinationRequest = "PatchDestination"
PatchDomainRequest = "PatchDomain"
PatchFeatureFlagRequest = "PatchFeatureFlag"
PatchOrganizationRelationshipDefaultIsolationSegmentRequest = "PatchOrganizationRelationshipDefaultIsolationSegment"
Expand Down Expand Up @@ -275,6 +276,7 @@ var APIRoutes = map[string]Route{
GetRouteDestinationsRequest: {Path: "/v3/routes/:route_guid/destinations", Method: http.MethodGet},
MapRouteRequest: {Path: "/v3/routes/:route_guid/destinations", Method: http.MethodPost},
UnmapRouteRequest: {Path: "/v3/routes/:route_guid/destinations/:destination_guid", Method: http.MethodDelete},
PatchDestinationRequest: {Path: "/v3/routes/:route_guid/destinations/:destination_guid", Method: http.MethodPatch},
GetSecurityGroupsRequest: {Path: "/v3/security_groups", Method: http.MethodGet},
PostSecurityGroupRequest: {Path: "/v3/security_groups", Method: http.MethodPost},
DeleteSecurityGroupRequest: {Path: "/v3/security_groups/:security_group_guid", Method: http.MethodDelete},
Expand Down
17 changes: 17 additions & 0 deletions api/cloudcontroller/ccv3/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,20 @@ func (client Client) UnmapRoute(routeGUID string, destinationGUID string) (Warni

return warnings, err
}

func (client Client) UpdateDestination(routeGUID string, destinationGUID string, protocol string) (Warnings, error) {
type body struct {
Protocol string `json:"protocol"`
}
requestBody := body{
Protocol: protocol,
}
var responseBody resources.Build
_, warnings, err := client.MakeRequest(RequestParams{
RequestName: internal.PatchDestinationRequest,
URIParams: internal.Params{"route_guid": routeGUID, "destination_guid": destinationGUID},
RequestBody: &requestBody,
ResponseBody: &responseBody,
})
return warnings, err
}
87 changes: 87 additions & 0 deletions api/cloudcontroller/ccv3/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,93 @@ var _ = Describe("Route", func() {
})
})

Describe("UpdateDestination", func() {
var (
routeGUID string
destinationGUID string
protocol string
warnings Warnings
executeErr error
)

JustBeforeEach(func() {
warnings, executeErr = client.UpdateDestination(routeGUID, destinationGUID, protocol)
})

When("the request succeeds", func() {
routeGUID = "route-guid"
destinationGUID = "destination-guid"
protocol = "http2"

expectedBody := fmt.Sprintf(`{
"protocol": "%s"
}`, protocol)

BeforeEach(func() {
server.AppendHandlers(
CombineHandlers(
VerifyRequest(http.MethodPatch, "/v3/routes/route-guid/destinations/destination-guid"),
VerifyJSON(expectedBody),
RespondWith(http.StatusNoContent, nil, http.Header{
"X-Cf-Warnings": {"this is a warning"},
}),
),
)
})

It("returns all warnings", func() {
Expect(executeErr).NotTo(HaveOccurred())
Expect(warnings).To(ConsistOf("this is a warning"))
})
})

When("the cloud controller returns errors and warnings", func() {
BeforeEach(func() {
response := `{
"errors": [
{
"code": 10008,
"detail": "The request is semantically invalid: command presence",
"title": "CF-UnprocessableEntity"
},
{
"code": 10010,
"detail": "Isolation segment not found",
"title": "CF-ResourceNotFound"
}
]
}`
server.AppendHandlers(
CombineHandlers(
VerifyRequest(http.MethodPatch, "/v3/routes/route-guid/destinations/destination-guid"),
RespondWith(http.StatusTeapot, response, http.Header{
"X-Cf-Warnings": {"this is a warning"},
}),
),
)
})

It("returns the error and all warnings", func() {
Expect(executeErr).To(MatchError(ccerror.MultiError{
ResponseCode: http.StatusTeapot,
Errors: []ccerror.V3Error{
{
Code: 10008,
Detail: "The request is semantically invalid: command presence",
Title: "CF-UnprocessableEntity",
},
{
Code: 10010,
Detail: "Isolation segment not found",
Title: "CF-ResourceNotFound",
},
},
}))
Expect(warnings).To(ConsistOf("this is a warning"))
})
})
})

Describe("DeleteOrphanedRoutes", func() {
var (
spaceGUID string
Expand Down
1 change: 1 addition & 0 deletions command/common/command_list_v7.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ type commandList struct {
UnsharePrivateDomain v7.UnsharePrivateDomainCommand `command:"unshare-private-domain" description:"Unshare a private domain with a specific org"`
UnshareService v7.UnshareServiceCommand `command:"unshare-service" description:"Unshare a shared service instance from a space"`
UpdateBuildpack v7.UpdateBuildpackCommand `command:"update-buildpack" description:"Update a buildpack"`
UpdateDestination v7.UpdateDestinationCommand `command:"update-destination" description:"Updates the destination protocol for a route"`
UpdateOrgQuota v7.UpdateOrgQuotaCommand `command:"update-org-quota" alias:"update-quota" description:"Update an existing organization quota"`
UpdateSecurityGroup v7.UpdateSecurityGroupCommand `command:"update-security-group" description:"Update a security group"`
UpdateService v7.UpdateServiceCommand `command:"update-service" description:"Update a service instance"`
Expand Down
1 change: 1 addition & 0 deletions command/common/internal/help_all_display.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var HelpCategoryList = []HelpCategory{
{"routes", "route"},
{"create-route", "check-route", "map-route", "unmap-route", "delete-route"},
{"delete-orphaned-routes"},
{"update-destination"},
},
},
{
Expand Down
1 change: 1 addition & 0 deletions command/v7/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ type Actor interface {
UpdateApplicationLabelsByApplicationName(string, string, map[string]types.NullString) (v7action.Warnings, error)
UpdateBuildpackByNameAndStack(buildpackName string, buildpackStack string, buildpack resources.Buildpack) (resources.Buildpack, v7action.Warnings, error)
UpdateBuildpackLabelsByBuildpackNameAndStack(string, string, map[string]types.NullString) (v7action.Warnings, error)
UpdateDestination(string, string, string) (v7action.Warnings, error)
UpdateDomainLabelsByDomainName(string, map[string]types.NullString) (v7action.Warnings, error)
UpdateManagedServiceInstance(params v7action.UpdateManagedServiceInstanceParams) (chan v7action.PollJobEvent, v7action.Warnings, error)
UpgradeManagedServiceInstance(serviceInstanceName, spaceGUID string) (v7action.Warnings, error)
Expand Down
Loading

0 comments on commit 3adeaba

Please sign in to comment.