-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.go
58 lines (48 loc) · 1.62 KB
/
controller.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
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package state
import (
"fmt"
"github.com/juju/errors"
"github.com/juju/utils/clock"
names "gopkg.in/juju/names.v2"
mgo "gopkg.in/mgo.v2"
jujucontroller "github.com/juju/juju/controller"
"github.com/juju/juju/mongo"
)
const (
// controllerSettingsGlobalKey is the key for the controller and its settings.
controllerSettingsGlobalKey = "controllerSettings"
// controllerGlobalKey is the key for controller.
controllerGlobalKey = "c"
)
// controllerKey will return the key for a given controller using the
// controller uuid and the controllerGlobalKey.
func controllerKey(controllerUUID string) string {
return fmt.Sprintf("%s#%s", controllerGlobalKey, controllerUUID)
}
// Controller encapsulates state for the Juju controller as a whole,
// as opposed to model specific functionality.
type Controller struct {
clock clock.Clock
controllerModelTag names.ModelTag
controllerTag names.ControllerTag
mongoInfo *mongo.MongoInfo
session *mgo.Session
policy Policy
newPolicy NewPolicyFunc
runTransactionObserver RunTransactionObserverFunc
}
// Close the connection to the database.
func (ctlr *Controller) Close() error {
ctlr.session.Close()
return nil
}
// ControllerConfig returns the config values for the controller.
func (st *State) ControllerConfig() (jujucontroller.Config, error) {
settings, err := readSettings(st, controllersC, controllerSettingsGlobalKey)
if err != nil {
return nil, errors.Trace(err)
}
return settings.Map(), nil
}