forked from juju/juju
/
shim.go
68 lines (54 loc) · 1.45 KB
/
shim.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
// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package peergrouper
import (
"labix.org/v2/mgo"
"github.com/juju/juju/network"
"github.com/juju/juju/replicaset"
"github.com/juju/juju/state"
)
// This file holds code that translates from State
// to the interface expected internally by the
// worker.
type stateShim struct {
*state.State
mongoPort int
apiPort int
}
func (s *stateShim) Machine(id string) (stateMachine, error) {
m, err := s.State.Machine(id)
if err != nil {
return nil, err
}
return &machineShim{
Machine: m,
mongoPort: s.mongoPort,
apiPort: s.apiPort,
}, nil
}
func (s *stateShim) MongoSession() mongoSession {
return mongoSessionShim{s.State.MongoSession()}
}
func (m *machineShim) APIHostPorts() []network.HostPort {
return network.AddressesWithPort(m.Addresses(), m.apiPort)
}
func (m *machineShim) MongoHostPorts() []network.HostPort {
return network.AddressesWithPort(m.Addresses(), m.mongoPort)
}
type machineShim struct {
*state.Machine
mongoPort int
apiPort int
}
type mongoSessionShim struct {
session *mgo.Session
}
func (s mongoSessionShim) CurrentStatus() (*replicaset.Status, error) {
return replicaset.CurrentStatus(s.session)
}
func (s mongoSessionShim) CurrentMembers() ([]replicaset.Member, error) {
return replicaset.CurrentMembers(s.session)
}
func (s mongoSessionShim) Set(members []replicaset.Member) error {
return replicaset.Set(s.session, members)
}