forked from cloudfoundry-attic/app-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
executor_service.go
39 lines (31 loc) · 1.18 KB
/
executor_service.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
package services_bbs
import (
"time"
"github.com/cloudfoundry-incubator/runtime-schema/bbs/shared"
"github.com/cloudfoundry-incubator/runtime-schema/models"
"github.com/cloudfoundry/storeadapter"
)
func (bbs *ServicesBBS) MaintainExecutorPresence(heartbeatInterval time.Duration, executorPresence models.ExecutorPresence) (Presence, <-chan bool, error) {
presence := NewPresence(bbs.store, shared.ExecutorSchemaPath(executorPresence.ExecutorID), executorPresence.ToJSON())
status, err := presence.Maintain(heartbeatInterval)
return presence, status, err
}
func (bbs *ServicesBBS) GetAllExecutors() ([]models.ExecutorPresence, error) {
node, err := bbs.store.ListRecursively(shared.ExecutorSchemaRoot)
if err == storeadapter.ErrorKeyNotFound {
return []models.ExecutorPresence{}, nil
}
if err != nil {
return nil, err
}
var executorPresences []models.ExecutorPresence
for _, node := range node.ChildNodes {
executorPresence, err := models.NewExecutorPresenceFromJSON(node.Value)
if err != nil {
bbs.logger.Error("failed-to-unmarshal-executors-json", err)
continue
}
executorPresences = append(executorPresences, executorPresence)
}
return executorPresences, nil
}