/
tenant_cascade.go
59 lines (51 loc) · 1.86 KB
/
tenant_cascade.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
package cascade
import (
"github.com/Peripli/service-manager/pkg/query"
"github.com/Peripli/service-manager/pkg/types"
)
type TenantCascade struct {
*types.Tenant
}
func (tc *TenantCascade) CleanDuplicates(children CascadeChildren) {
// cleaning instances that will be under platforms or brokers
instances, found := children[types.ServiceInstanceType]
if !found || instances.Len() == 0 {
return
}
tenantScopedBrokerPlanIDs := make(map[string]bool)
brokers, found := children[types.ServiceBrokerType]
if found {
for i := 0; i < brokers.Len(); i++ {
broker := brokers.ItemAt(i).(*types.ServiceBroker)
for _, service := range broker.Services {
for _, plan := range service.Plans {
tenantScopedBrokerPlanIDs[plan.ID] = true
}
}
}
}
tenantScopedPlatformIDs := make(map[string]bool)
platforms, found := children[types.PlatformType]
if found {
for i := 0; i < platforms.Len(); i++ {
tenantScopedPlatformIDs[platforms.ItemAt(i).GetID()] = true
}
}
filteredServiceInstances := types.ServiceInstances{}
for i := 0; i < instances.Len(); i++ {
instance := instances.ItemAt(i).(*types.ServiceInstance)
_, isTenantScopedBrokerInstance := tenantScopedBrokerPlanIDs[instance.ServicePlanID]
_, isTenantScopedPlatformInstance := tenantScopedPlatformIDs[instance.PlatformID]
if !isTenantScopedBrokerInstance && !isTenantScopedPlatformInstance {
filteredServiceInstances.Add(instance)
}
}
children[types.ServiceInstanceType] = &filteredServiceInstances
}
func (tc *TenantCascade) GetChildrenCriterion() ChildrenCriterion {
return ChildrenCriterion{
types.PlatformType: {{query.ByLabel(query.EqualsOperator, tc.TenantIdentifier, tc.ID)}},
types.ServiceBrokerType: {{query.ByLabel(query.EqualsOperator, tc.TenantIdentifier, tc.ID)}},
types.ServiceInstanceType: {{query.ByLabel(query.EqualsOperator, tc.TenantIdentifier, tc.ID)}},
}
}