-
Notifications
You must be signed in to change notification settings - Fork 1
/
operator_manager.go
68 lines (53 loc) · 1.9 KB
/
operator_manager.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
//go:generate mockgen -source=$GOFILE -destination=operator_manager_mock.go -package=$GOPACKAGE -write_package_comment=false
package operation
import (
"context"
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
"golang.org/x/sync/errgroup"
)
type IOperatorManager interface {
SetOperatorCollection(stackName *string, stackResourceSummaries []types.StackResourceSummary)
CheckResourceCounts() error
GetLogicalResourceIds() []string
DeleteResourceCollection(ctx context.Context) error
}
var _ IOperatorManager = (*OperatorManager)(nil)
type OperatorManager struct {
operatorCollection IOperatorCollection
}
func NewOperatorManager(operatorCollection IOperatorCollection) *OperatorManager {
return &OperatorManager{
operatorCollection: operatorCollection,
}
}
func (m *OperatorManager) SetOperatorCollection(stackName *string, stackResourceSummaries []types.StackResourceSummary) {
m.operatorCollection.SetOperatorCollection(stackName, stackResourceSummaries)
}
func (m *OperatorManager) getOperatorResourcesLength() int {
var length int
for _, operator := range m.operatorCollection.GetOperators() {
length += operator.GetResourcesLength()
}
return length
}
func (m *OperatorManager) CheckResourceCounts() error {
logicalResourceIdsLength := len(m.operatorCollection.GetLogicalResourceIds())
operatorResourcesLength := m.getOperatorResourcesLength()
if logicalResourceIdsLength != operatorResourcesLength {
return m.operatorCollection.RaiseUnsupportedResourceError()
}
return nil
}
func (m *OperatorManager) GetLogicalResourceIds() []string {
return m.operatorCollection.GetLogicalResourceIds()
}
func (m *OperatorManager) DeleteResourceCollection(ctx context.Context) error {
eg, ctx := errgroup.WithContext(ctx)
for _, operator := range m.operatorCollection.GetOperators() {
operator := operator
eg.Go(func() error {
return operator.DeleteResources(ctx)
})
}
return eg.Wait()
}