This repository has been archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
/
check_children_status.go
133 lines (128 loc) · 3.26 KB
/
check_children_status.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package broker
import (
"context"
"errors"
"time"
"github.com/Azure/open-service-broker-azure/pkg/service"
log "github.com/Sirupsen/logrus"
"github.com/deis/async"
)
func (b *broker) doCheckChildrenStatuses(
_ context.Context,
task async.Task,
) ([]async.Task, error) {
instanceID, ok := task.GetArgs()["instanceID"]
if !ok {
return nil, errors.New(`missing required argument "instanceID"`)
}
instance, ok, err := b.store.GetInstance(instanceID)
if !ok {
return nil, b.handleDeprovisioningError(
instanceID,
"checkChildrenStatuses",
nil,
"error loading persisted instance",
)
}
if err != nil {
return nil, b.handleDeprovisioningError(
instanceID,
"checkChildrenStatuses",
err,
"error loading persisted instance",
)
}
childCount, err := b.store.GetInstanceChildCountByAlias(instance.Alias)
if err != nil {
log.WithFields(log.Fields{
"step": "checkChildrenStatuses",
"instanceID": instanceID,
"error": err,
}).Error(
"deprovisioning error: error determining child count",
)
return nil, b.handleDeprovisioningError(
instance,
"checkChildrenStatuses",
err,
"error determining child count",
)
}
if childCount > 0 {
//Put this task back into the queue
log.WithFields(log.Fields{
"instanceID": instanceID,
"provisionedChildren": childCount,
}).Debug("children not deprovisioned, will wait again")
return []async.Task{
async.NewDelayedTask(
"checkChildrenStatuses",
map[string]string{
"instanceID": instanceID,
},
time.Minute*1,
),
}, nil
}
serviceManager := instance.Service.GetServiceManager()
var deprovisioner service.Deprovisioner
deprovisioner, err = serviceManager.GetDeprovisioner(instance.Plan)
if err != nil {
log.WithFields(log.Fields{
"instanceID": instanceID,
"serviceID": instance.ServiceID,
"planID": instance.PlanID,
"error": err,
}).Error(
"deprovisioning error: error retrieving deprovisioner for " +
"service and plan",
)
return nil, b.handleDeprovisioningError(
instance,
"checkChildrenStatuses",
err,
"error retrieving deprovisioner for service and service",
)
}
deprovisionFirstStep, ok := deprovisioner.GetFirstStepName()
if !ok {
log.WithFields(log.Fields{
"instanceID": instanceID,
"serviceID": instance.ServiceID,
"planID": instance.PlanID,
}).Error(
"pre-deprovisioning error: no steps found for deprovisioning " +
"service and plan",
)
return nil, b.handleDeprovisioningError(
instance,
"checkChildrenStatuses",
nil,
"error: no steps found for deprovisioning service and plan",
)
}
// Update the status
instance.Status = service.InstanceStateDeprovisioning
if err = b.store.WriteInstance(instance); err != nil {
return nil, b.handleDeprovisioningError(
instance,
"checkChildrenStatuses",
err,
"error: error updating instance status",
)
}
// Put the real deprovision task into the queue
log.WithFields(log.Fields{
"step": "checkChildrenStatuses",
"instanceID": instanceID,
}).Debug("children deprovisioned, sending start deprovision task")
return []async.Task{
async.NewTask(
"executeDeprovisioningStep",
map[string]string{
"stepName": deprovisionFirstStep,
"instanceID": instanceID,
},
),
}, nil
}