forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_service_instance.go
70 lines (53 loc) · 2.7 KB
/
update_service_instance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package composite
import (
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/actor/v2action"
)
//go:generate counterfeiter . GetServiceInstanceActor
type GetServiceInstanceActor interface {
GetServiceInstanceByNameAndSpace(name string, spaceGUID string) (v2action.ServiceInstance, v2action.Warnings, error)
}
//go:generate counterfeiter . GetServicePlanActor
type GetServicePlanActor interface {
GetServicePlan(servicePlanGUID string) (v2action.ServicePlan, v2action.Warnings, error)
}
//go:generate counterfeiter . UpdateServiceInstanceMaintenanceInfoActor
type UpdateServiceInstanceMaintenanceInfoActor interface {
UpdateServiceInstanceMaintenanceInfo(serviceInsrtanceGUID string, maintenanceInfo v2action.MaintenanceInfo) (v2action.Warnings, error)
}
//go:generate counterfeiter . GetAPIVersionActor
type GetAPIVersionActor interface {
CloudControllerAPIVersion() string
}
type UpdateServiceInstanceCompositeActor struct {
GetServiceInstanceActor GetServiceInstanceActor
GetServicePlanActor GetServicePlanActor
UpdateServiceInstanceMaintenanceInfoActor UpdateServiceInstanceMaintenanceInfoActor
GetAPIVersionActor GetAPIVersionActor
}
// UpgradeServiceInstance requests update on the service instance with the `maintenance_info` available on the plan
func (c UpdateServiceInstanceCompositeActor) UpgradeServiceInstance(serviceInstance v2action.ServiceInstance) (v2action.Warnings, error) {
servicePlan, warnings, err := c.GetServicePlanActor.GetServicePlan(serviceInstance.ServicePlanGUID)
if err != nil {
return warnings, err
}
if !upgradeIsAvailable(serviceInstance, servicePlan) {
return warnings, actionerror.ServiceUpgradeNotAvailableError{}
}
updateWarnings, err := c.UpdateServiceInstanceMaintenanceInfoActor.UpdateServiceInstanceMaintenanceInfo(
serviceInstance.GUID,
v2action.MaintenanceInfo(servicePlan.MaintenanceInfo),
)
return append(warnings, updateWarnings...), err
}
// GetServiceInstanceByNameAndSpace gets the service instance by name and space guid provided
func (c UpdateServiceInstanceCompositeActor) GetServiceInstanceByNameAndSpace(name string, spaceGUID string) (v2action.ServiceInstance, v2action.Warnings, error) {
return c.GetServiceInstanceActor.GetServiceInstanceByNameAndSpace(name, spaceGUID)
}
// CloudControllerAPIVersion returns the CloudController API version
func (c UpdateServiceInstanceCompositeActor) CloudControllerAPIVersion() string {
return c.GetAPIVersionActor.CloudControllerAPIVersion()
}
func upgradeIsAvailable(serviceInstance v2action.ServiceInstance, servicePlan v2action.ServicePlan) bool {
return serviceInstance.MaintenanceInfo.Version != servicePlan.MaintenanceInfo.Version
}