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

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

Issue 13355046: worker/apiuniter: State to API migration (Closed)
Left Patch Set: Created 11 years, 7 months ago
Right Patch Set: worker/apiuniter: State to API migration Created 11 years, 7 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 | « worker/apiuniter/charm/charm_test.go ('k') | worker/apiuniter/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 // Copyright 2012, 2013 Canonical Ltd. 1 // Copyright 2012, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package apiuniter 4 package apiuniter
5 5
6 import ( 6 import (
7 "bufio" 7 "bufio"
8 "fmt" 8 "fmt"
9 "io" 9 "io"
10 "os" 10 "os"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // relations contains the context for every relation the unit is a membe r 56 // relations contains the context for every relation the unit is a membe r
57 // of, keyed on relation id. 57 // of, keyed on relation id.
58 relations map[int]*ContextRelation 58 relations map[int]*ContextRelation
59 59
60 // apiAddrs contains the API server addresses. 60 // apiAddrs contains the API server addresses.
61 apiAddrs []string 61 apiAddrs []string
62 } 62 }
63 63
64 func NewHookContext(unit *uniter.Unit, id, uuid string, relationId int, 64 func NewHookContext(unit *uniter.Unit, id, uuid string, relationId int,
65 remoteUnitName string, relations map[int]*ContextRelation, 65 remoteUnitName string, relations map[int]*ContextRelation,
66 » apiAddrs []string) *HookContext { 66 » apiAddrs []string) (*HookContext, error) {
67 ctx := &HookContext{ 67 ctx := &HookContext{
68 unit: unit, 68 unit: unit,
69 id: id, 69 id: id,
70 uuid: uuid, 70 uuid: uuid,
71 relationId: relationId, 71 relationId: relationId,
72 remoteUnitName: remoteUnitName, 72 remoteUnitName: remoteUnitName,
73 relations: relations, 73 relations: relations,
74 apiAddrs: apiAddrs, 74 apiAddrs: apiAddrs,
75 } 75 }
76 // Get and cache the addresses. 76 // Get and cache the addresses.
77 » // We ignore the errors here, becasue we only 77 » var err error
78 » // care if the addresses are set or not, and 78 » ctx.publicAddress, err = unit.PublicAddress()
79 » // we don't want them to change while a hook 79 » if err != nil && params.ErrCode(err) != params.CodeNoAddressSet {
80 » // is executed. 80 » » return nil, err
81 » ctx.publicAddress, _ = unit.PublicAddress() 81 » }
82 » ctx.privateAddress, _ = unit.PrivateAddress() 82 » ctx.privateAddress, err = unit.PrivateAddress()
83 » return ctx 83 » if err != nil && params.ErrCode(err) != params.CodeNoAddressSet {
84 » » return nil, err
85 » }
86 » return ctx, nil
84 } 87 }
85 88
86 func (ctx *HookContext) UnitName() string { 89 func (ctx *HookContext) UnitName() string {
87 return ctx.unit.Name() 90 return ctx.unit.Name()
88 } 91 }
89 92
90 func (ctx *HookContext) PublicAddress() (string, bool) { 93 func (ctx *HookContext) PublicAddress() (string, bool) {
91 return ctx.publicAddress, ctx.publicAddress != "" 94 return ctx.publicAddress, ctx.publicAddress != ""
92 } 95 }
93 96
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 } 377 }
375 } 378 }
376 } 379 }
377 if member { 380 if member {
378 ctx.members[unit] = settings 381 ctx.members[unit] = settings
379 } else { 382 } else {
380 ctx.cache[unit] = settings 383 ctx.cache[unit] = settings
381 } 384 }
382 return settings, nil 385 return settings, nil
383 } 386 }
LEFTRIGHT

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