Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1367)

Delta Between Two Patch Sets: state/machine.go

Issue 5727045: Continuation of the unit state implementation. (Closed)
Left Patch Set: Continuation of the unit state implementation. Created 12 years ago
Right Patch Set: Continuation of the unit state implementation. Created 12 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | state/service.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // launchpad.net/juju/state
2 //
3 // Copyright (c) 2011-2012 Canonical Ltd.
4
5 package state
6 1
7 import ( 2 import (
8 "fmt" 3 "fmt"
4 "launchpad.net/gozk/zookeeper"
9 "strconv" 5 "strconv"
10 "strings" 6 "strings"
11 ) 7 )
12 8
13 // Machine represents the state of a machine. 9 // Machine represents the state of a machine.
14 type Machine struct { 10 type Machine struct {
15 » st *State 11 » zk *zookeeper.Conn
16 key string 12 key string
17 } 13 }
18 14
19 // Id returns the machine id.
20 func (m *Machine) Id() int {
21 return machineId(m.key)
22 }
23
24 // zkKey returns the ZooKeeper key of the machine.
25 func (m *Machine) zkKey() string {
26 return m.key
27 }
28
29 // zkPath returns the ZooKeeper base path for the machine.
30 func (m *Machine) zkPath() string {
31 return fmt.Sprintf("/machines/%s", m.key)
32 }
33
34 // zkAgentPath returns the ZooKeeper path for the machine agent.
35 func (m *Machine) zkAgentPath() string {
36 return fmt.Sprintf("/machines/%s/agent", m.key)
37 }
38
39 // machineId returns the machine id corresponding to machineKey.
40 func machineId(machineKey string) (id int) {
41 if machineKey == "" {
42 panic("machineId: empty machine key")
43 }
44 i := strings.Index(machineKey, "-")
45 var id64 int64
46 var err error
47 if i >= 0 {
48 id64, err = strconv.ParseInt(machineKey[i+1:], 10, 32)
49 }
50 if i < 0 || err != nil {
51 panic("machineId: invalid machine key: " + machineKey)
52 }
53 return int(id64)
54 }
LEFTRIGHT
« no previous file | state/service.go » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b