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

Delta Between Two Patch Sets: worker/uniter/context.go

Issue 8322043: state: add environment persistency with UUID (Closed)
Left Patch Set: Created 12 years ago
Right Patch Set: state: add environment persistency with UUID Created 11 years, 12 months 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 | « trivial/uuid.go ('k') | worker/uniter/context_test.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 package uniter 1 package uniter
2 2
3 import ( 3 import (
4 "bufio" 4 "bufio"
5 "fmt" 5 "fmt"
6 "io" 6 "io"
7 "launchpad.net/juju-core/log" 7 "launchpad.net/juju-core/log"
8 "launchpad.net/juju-core/state" 8 "launchpad.net/juju-core/state"
9 "launchpad.net/juju-core/trivial"
10 "launchpad.net/juju-core/worker/uniter/jujuc" 9 "launchpad.net/juju-core/worker/uniter/jujuc"
11 "os" 10 "os"
12 "os/exec" 11 "os/exec"
13 "path/filepath" 12 "path/filepath"
14 "sort" 13 "sort"
15 "sync" 14 "sync"
16 "time" 15 "time"
17 ) 16 )
18 17
19 // HookContext is the implementation of jujuc.Context. 18 // HookContext is the implementation of jujuc.Context.
20 type HookContext struct { 19 type HookContext struct {
21 unit *state.Unit 20 unit *state.Unit
22 21
23 // config holds the service configuration. 22 // config holds the service configuration.
24 config map[string]interface{} 23 config map[string]interface{}
25 24
26 // id identifies the context. 25 // id identifies the context.
27 id string 26 id string
28 27
29 // uuid is the universally unique identifier of the environment. 28 // uuid is the universally unique identifier of the environment.
30 » uuid trivial.UUID 29 » uuid string
31 30
32 // relationId identifies the relation for which a relation hook is 31 // relationId identifies the relation for which a relation hook is
33 // executing. If it is -1, the context is not running a relation hook; 32 // executing. If it is -1, the context is not running a relation hook;
34 // otherwise, its value must be a valid key into the relations map. 33 // otherwise, its value must be a valid key into the relations map.
35 relationId int 34 relationId int
36 35
37 // remoteUnitName identifies the changing unit of the executing relation 36 // remoteUnitName identifies the changing unit of the executing relation
38 // hook. It will be empty if the context is not running a relation hook, 37 // hook. It will be empty if the context is not running a relation hook,
39 // or if it is running a relation-broken hook. 38 // or if it is running a relation-broken hook.
40 remoteUnitName string 39 remoteUnitName string
41 40
42 // relations contains the context for every relation the unit is a membe r 41 // relations contains the context for every relation the unit is a membe r
43 // of, keyed on relation id. 42 // of, keyed on relation id.
44 relations map[int]*ContextRelation 43 relations map[int]*ContextRelation
45 } 44 }
46 45
47 func NewHookContext(unit *state.Unit, id string, uuid trivial.UUID, relationId i nt, 46 func NewHookContext(unit *state.Unit, id, uuid string, relationId int,
48 remoteUnitName string, relations map[int]*ContextRelation) *HookContext { 47 remoteUnitName string, relations map[int]*ContextRelation) *HookContext {
49 return &HookContext{ 48 return &HookContext{
50 unit: unit, 49 unit: unit,
51 id: id, 50 id: id,
52 uuid: uuid, 51 uuid: uuid,
53 relationId: relationId, 52 relationId: relationId,
54 remoteUnitName: remoteUnitName, 53 remoteUnitName: remoteUnitName,
55 relations: relations, 54 relations: relations,
56 } 55 }
57 } 56 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // into ctx. 112 // into ctx.
114 func (ctx *HookContext) hookVars(charmDir, toolsDir, socketPath string) []string { 113 func (ctx *HookContext) hookVars(charmDir, toolsDir, socketPath string) []string {
115 vars := []string{ 114 vars := []string{
116 "APT_LISTCHANGES_FRONTEND=none", 115 "APT_LISTCHANGES_FRONTEND=none",
117 "DEBIAN_FRONTEND=noninteractive", 116 "DEBIAN_FRONTEND=noninteractive",
118 "PATH=" + toolsDir + ":" + os.Getenv("PATH"), 117 "PATH=" + toolsDir + ":" + os.Getenv("PATH"),
119 "CHARM_DIR=" + charmDir, 118 "CHARM_DIR=" + charmDir,
120 "JUJU_CONTEXT_ID=" + ctx.id, 119 "JUJU_CONTEXT_ID=" + ctx.id,
121 "JUJU_AGENT_SOCKET=" + socketPath, 120 "JUJU_AGENT_SOCKET=" + socketPath,
122 "JUJU_UNIT_NAME=" + ctx.unit.Name(), 121 "JUJU_UNIT_NAME=" + ctx.unit.Name(),
123 » » "JUJU_ENV_UUID=" + ctx.uuid.String(), 122 » » "JUJU_ENV_UUID=" + ctx.uuid,
124 } 123 }
125 if r, found := ctx.HookRelation(); found { 124 if r, found := ctx.HookRelation(); found {
126 vars = append(vars, "JUJU_RELATION="+r.Name()) 125 vars = append(vars, "JUJU_RELATION="+r.Name())
127 vars = append(vars, "JUJU_RELATION_ID="+r.FakeId()) 126 vars = append(vars, "JUJU_RELATION_ID="+r.FakeId())
128 name, _ := ctx.RemoteUnitName() 127 name, _ := ctx.RemoteUnitName()
129 vars = append(vars, "JUJU_REMOTE_UNIT="+name) 128 vars = append(vars, "JUJU_REMOTE_UNIT="+name)
130 } 129 }
131 return vars 130 return vars
132 } 131 }
133 132
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 } 332 }
334 } 333 }
335 } 334 }
336 if member { 335 if member {
337 ctx.members[unit] = settings 336 ctx.members[unit] = settings
338 } else { 337 } else {
339 ctx.cache[unit] = settings 338 ctx.cache[unit] = settings
340 } 339 }
341 return settings, nil 340 return settings, nil
342 } 341 }
LEFTRIGHT

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