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

Delta Between Two Patch Sets: state/charm.go

Issue 5671055: Implementation of the charm state. (Closed)
Left Patch Set: Implementation of the charm state. Created 13 years, 1 month ago
Right Patch Set: Implementation of the charm state. Created 13 years, 1 month 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/export_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 // launchpad.net/juju/state 1 // launchpad.net/juju/state
2 // 2 //
3 // Copyright (c) 2011-2012 Canonical Ltd. 3 // Copyright (c) 2011-2012 Canonical Ltd.
4 package state 4 package state
5 5
6 import ( 6 import (
7 "fmt" 7 "fmt"
8 "launchpad.net/gozk/zookeeper"
9 "launchpad.net/juju/go/charm" 8 "launchpad.net/juju/go/charm"
9 "net/url"
10 ) 10 )
11 11
12 // charmData contains the data stored inside the ZooKeeper charm node. 12 // charmData contains the data stored inside the ZooKeeper charm node.
13 type charmData struct { 13 type charmData struct {
14 Meta *charm.Meta 14 Meta *charm.Meta
15 Config *charm.Config 15 Config *charm.Config
16 BundleURL string `yaml:"url"` 16 BundleURL string `yaml:"url"`
17 } 17 }
18 18
19 // Charm represents the state of a charm in the environment. 19 // Charm represents the state of a charm in the environment.
20 type Charm struct { 20 type Charm struct {
21 st *State 21 st *State
22 zk *zookeeper.Conn
23 url *charm.URL 22 url *charm.URL
24 meta *charm.Meta 23 meta *charm.Meta
25 config *charm.Config 24 config *charm.Config
26 » bundleURL string 25 » bundleURL *url.URL
27 } 26 }
28 27
29 var _ charm.Charm = (*Charm)(nil) 28 var _ charm.Charm = (*Charm)(nil)
30 29
31 func newCharm(st *State, curl *charm.URL, data *charmData) *Charm { 30 func newCharm(st *State, curl *charm.URL, data *charmData) (*Charm, error) {
31 » burl, err := url.Parse(data.BundleURL)
32 » if err != nil {
33 » » return nil, err
34 » }
32 c := &Charm{ 35 c := &Charm{
33 st: st, 36 st: st,
34 url: curl, 37 url: curl,
35 meta: data.Meta, 38 meta: data.Meta,
36 config: data.Config, 39 config: data.Config,
37 » » bundleURL: data.BundleURL, 40 » » bundleURL: burl,
38 } 41 }
39 » return c 42 » return c, nil
40 } 43 }
41 44
42 // URL returns the URL that identifies the charm. 45 // URL returns the URL that identifies the charm.
43 func (c *Charm) URL() *charm.URL { 46 func (c *Charm) URL() *charm.URL {
44 clone := *c.url 47 clone := *c.url
45 return &clone 48 return &clone
46 } 49 }
47 50
48 // Revision returns the monotonically increasing charm· 51 // Revision returns the monotonically increasing charm·
49 // revision number. 52 // revision number.
50 func (c *Charm) Revision() int { 53 func (c *Charm) Revision() int {
51 return c.url.Revision 54 return c.url.Revision
52 } 55 }
53 56
54 // Meta returns the metadata of the charm. 57 // Meta returns the metadata of the charm.
55 func (c *Charm) Meta() *charm.Meta { 58 func (c *Charm) Meta() *charm.Meta {
56 return c.meta 59 return c.meta
57 } 60 }
58 61
59 // Config returns the configuration of the charm. 62 // Config returns the configuration of the charm.
60 func (c *Charm) Config() *charm.Config { 63 func (c *Charm) Config() *charm.Config {
61 return c.config 64 return c.config
62 } 65 }
63 66
64 // BundleURL returns the url to the charm bundle in· 67 // BundleURL returns the url to the charm bundle in·
65 // the provider storage. 68 // the provider storage.
66 func (c *Charm) BundleURL() string { 69 func (c *Charm) BundleURL() *url.URL {
67 return c.bundleURL 70 return c.bundleURL
68 } 71 }
69 72
70 // Charm path returns the full qualified ZooKeeper path for a charm state 73 // Charm path returns the full qualified ZooKeeper path for a charm state
71 // based on the charm URL. 74 // based on the charm URL.
72 func charmPath(curl *charm.URL) (string, error) { 75 func charmPath(curl *charm.URL) (string, error) {
73 if curl.Revision < 0 { 76 if curl.Revision < 0 {
74 return "", fmt.Errorf("charm URL revision is unset") 77 return "", fmt.Errorf("charm URL revision is unset")
75 } 78 }
76 return fmt.Sprintf("/charms/%s", Quote(curl.String())), nil 79 return fmt.Sprintf("/charms/%s", Quote(curl.String())), nil
77 } 80 }
LEFTRIGHT

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