Skip to content

Commit

Permalink
Implement creation of managed service instances
Browse files Browse the repository at this point in the history
fixes #3288
fixes #3439

Co-authored-by: Yusmen Zabanov <yusmen.zabanov@sap.com>
Co-authored-by: Georgi Sabev <georgethebeatle@gmail.com>
Co-authored-by: Yusmen Zabanov <yusmen.zabanov@sap.com>
  • Loading branch information
3 people committed Sep 9, 2024
1 parent 8fa70d0 commit 2696091
Show file tree
Hide file tree
Showing 68 changed files with 4,346 additions and 1,294 deletions.
165 changes: 124 additions & 41 deletions api/handlers/fake/cfservice_instance_repository.go

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

26 changes: 13 additions & 13 deletions api/handlers/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ import (
)

const (
JobPath = "/v3/jobs/{guid}"
syncSpaceJobType = "space.apply_manifest"
AppDeleteJobType = "app.delete"
OrgDeleteJobType = "org.delete"
RouteDeleteJobType = "route.delete"
SpaceDeleteJobType = "space.delete"
DomainDeleteJobType = "domain.delete"
RoleDeleteJobType = "role.delete"
ServiceBrokerCreateJobType = "service_broker.create"
ServiceBrokerUpdateJobType = "service_broker.update"
ServiceBrokerDeleteJobType = "service_broker.delete"

JobTimeoutDuration = 120.0
JobPath = "/v3/jobs/{guid}"
syncSpaceJobType = "space.apply_manifest"
AppDeleteJobType = "app.delete"
OrgDeleteJobType = "org.delete"
RouteDeleteJobType = "route.delete"
SpaceDeleteJobType = "space.delete"
DomainDeleteJobType = "domain.delete"
RoleDeleteJobType = "role.delete"
ServiceBrokerCreateJobType = "service_broker.create"
ServiceBrokerUpdateJobType = "service_broker.update"
ServiceBrokerDeleteJobType = "service_broker.delete"
ManagedServiceInstanceCreateJobType = "managed_service_instance.create"
JobTimeoutDuration = 120.0
)

const JobResourceType = "Job"
Expand Down
35 changes: 32 additions & 3 deletions api/handlers/service_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const (

//counterfeiter:generate -o fake -fake-name CFServiceInstanceRepository . CFServiceInstanceRepository
type CFServiceInstanceRepository interface {
CreateServiceInstance(context.Context, authorization.Info, repositories.CreateServiceInstanceMessage) (repositories.ServiceInstanceRecord, error)
CreateUserProvidedServiceInstance(context.Context, authorization.Info, repositories.CreateUPSIMessage) (repositories.ServiceInstanceRecord, error)
CreateManagedServiceInstance(context.Context, authorization.Info, repositories.CreateManagedSIMessage) (repositories.ServiceInstanceRecord, error)
PatchServiceInstance(context.Context, authorization.Info, repositories.PatchServiceInstanceMessage) (repositories.ServiceInstanceRecord, error)
ListServiceInstances(context.Context, authorization.Info, repositories.ListServiceInstanceMessage) ([]repositories.ServiceInstanceRecord, error)
GetServiceInstance(context.Context, authorization.Info, string) (repositories.ServiceInstanceRecord, error)
Expand Down Expand Up @@ -82,9 +83,37 @@ func (h *ServiceInstance) create(r *http.Request) (*routing.Response, error) {
)
}

serviceInstanceRecord, err := h.serviceInstanceRepo.CreateServiceInstance(r.Context(), authInfo, payload.ToServiceInstanceCreateMessage())
if payload.Type == "managed" {
return h.createManagedServiceInstance(r.Context(), logger, authInfo, payload)
}

return h.createUserProvidedServiceInstance(r.Context(), logger, authInfo, payload)
}

func (h *ServiceInstance) createManagedServiceInstance(
ctx context.Context,
logger logr.Logger,
authInfo authorization.Info,
payload payloads.ServiceInstanceCreate,
) (*routing.Response, error) {
serviceInstanceRecord, err := h.serviceInstanceRepo.CreateManagedServiceInstance(ctx, authInfo, payload.ToManagedSICreateMessage())
if err != nil {
return nil, apierrors.LogAndReturn(logger, err, "Failed to create managed service instance", "Service Instance Name", payload.Name)
}

return routing.NewResponse(http.StatusAccepted).
WithHeader("Location", presenter.JobURLForRedirects(serviceInstanceRecord.GUID, presenter.ManagedServiceInstanceCreateOperation, h.serverURL)), nil
}

func (h *ServiceInstance) createUserProvidedServiceInstance(
ctx context.Context,
logger logr.Logger,
authInfo authorization.Info,
payload payloads.ServiceInstanceCreate,
) (*routing.Response, error) {
serviceInstanceRecord, err := h.serviceInstanceRepo.CreateUserProvidedServiceInstance(ctx, authInfo, payload.ToUPSICreateMessage())
if err != nil {
return nil, apierrors.LogAndReturn(logger, err, "Failed to create service instance", "Service Instance Name", serviceInstanceRecord.Name)
return nil, apierrors.LogAndReturn(logger, err, "Failed to create user provided service instance", "Service Instance Name", payload.Name)
}

return routing.NewResponse(http.StatusCreated).WithBody(presenter.ForServiceInstance(serviceInstanceRecord, h.serverURL)), nil
Expand Down
Loading

0 comments on commit 2696091

Please sign in to comment.