Merge lp:~bac/juju-gui/1096230 into lp:juju-gui/experimental

Proposed by Brad Crittenden
Status: Merged
Merged at revision: 306
Proposed branch: lp:~bac/juju-gui/1096230
Merge into: lp:juju-gui/experimental
Diff against target: 205 lines (+94/-15)
2 files modified
app/store/env.js (+52/-1)
test/test_env.js (+42/-14)
To merge this branch: bzr merge lp:~bac/juju-gui/1096230
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+142513@code.launchpad.net

Description of the change

Add support for _annotation calls to env.

The calls update_annotations, get_annotations, and remove_annotations are
added to the env object.

As a drive-by, in test_env.js the unnecessary use of async calls was
eliminated by removing the 'done' parameter. Leaving it in place where not
required was confusing.

https://codereview.appspot.com/7064060/

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Reviewers: mp+142513_code.launchpad.net,

Message:
Please take a look.

Description:
Add support for _annotation calls to env.

The calls update_annotations, get_annotations, and remove_annotations
are
added to the env object.

As a drive-by, in test_env.js the unnecessary use of async calls was
eliminated by removing the 'done' parameter. Leaving it in place where
not
required was confusing.

https://code.launchpad.net/~bac/juju-gui/1096230/+merge/142513

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/7064060/

Affected files:
   A [revision details]
   M app/store/env.js
   M test/test_env.js

Revision history for this message
Gary Poster (gary) wrote :

Land with changes.

Looks good to me. Thank you!

Gary

https://codereview.appspot.com/7064060/diff/1/app/store/env.js
File app/store/env.js (right):

https://codereview.appspot.com/7064060/diff/1/app/store/env.js#newcode276
app/store/env.js:276: * @param {Object} entity The name of a machine,
unit, service, or
Would be nice to specify what the name of these things is--examples.

https://codereview.appspot.com/7064060/diff/1/app/store/env.js#newcode307
app/store/env.js:307: * environment.
You don't describe the keys argument. Given that it appears to be
optional, it would be particularly nice to document.

https://codereview.appspot.com/7064060/

lp:~bac/juju-gui/1096230 updated
307. By Brad Crittenden

Updated function documentation.

308. By Brad Crittenden

Updated use of environment entity in annotation command documentation.

Revision history for this message
Brad Crittenden (bac) wrote :
Revision history for this message
Kapil Thangavelu (hazmat) wrote :

lgtm, one minor of note

https://codereview.appspot.com/7064060/diff/5001/app/store/env.js
File app/store/env.js (right):

https://codereview.appspot.com/7064060/diff/5001/app/store/env.js#newcode296
app/store/env.js:296: * callback. The invocation of this command
returns nothing.
the doc string should also have a note that annotations come back in the
delta stream so explicit fetching should be rarely be needed or unesc.

https://codereview.appspot.com/7064060/

lp:~bac/juju-gui/1096230 updated
309. By Brad Crittenden

Updated doc for get_annotations to note it is rarely required to be used.

310. By Brad Crittenden

Fixed typo

Revision history for this message
Brad Crittenden (bac) wrote :

*** Submitted:

Add support for _annotation calls to env.

The calls update_annotations, get_annotations, and remove_annotations
are
added to the env object.

As a drive-by, in test_env.js the unnecessary use of async calls was
eliminated by removing the 'done' parameter. Leaving it in place where
not
required was confusing.

R=gary.poster, hazmat
CC=
https://codereview.appspot.com/7064060

https://codereview.appspot.com/7064060/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/store/env.js'
2--- app/store/env.js 2013-01-07 21:38:42 +0000
3+++ app/store/env.js 2013-01-09 14:59:22 +0000
4@@ -268,9 +268,60 @@
5 get_endpoints: function(services, callback) {
6 this._send_rpc({'op': 'get_endpoints', 'service_names': services},
7 callback);
8+ },
9+
10+ /**
11+ * Update the annotations for an entity by name.
12+ *
13+ * @param {Object} entity The name of a machine, unit, service, or
14+ * environment, e.g. '0', 'mysql/0', or 'mysql'. To specify the
15+ * environment as the entity the magic string 'env' is used.
16+ * @param {Object} data A dictionary of key, value pairs.
17+ * @return {undefined} Nothing.
18+ */
19+ update_annotations: function(entity, data, callback) {
20+ this._send_rpc({
21+ op: 'update_annotations',
22+ entity: entity,
23+ data: data}, callback);
24+ },
25+
26+ /**
27+ * Get the annotations for an entity by name.
28+ *
29+ * Note that the annotations are returned as part of the delta stream, so
30+ * the explicit use of this command should rarely be needed.
31+ *
32+ * @param {Object} entity The name of a machine, unit, service, or
33+ * environment, e.g. '0', 'mysql/0', or 'mysql'. To specify the
34+ * environment as the entity the magic string 'env' is used.
35+ * @return {Object} A dictionary of key,value pairs is returned in the
36+ * callback. The invocation of this command returns nothing.
37+ */
38+ get_annotations: function(entity, callback) {
39+ this._send_rpc({
40+ op: 'get_annotations',
41+ entity: entity}, callback);
42+ },
43+
44+ /**
45+ * Remove the annotations for an entity by name.
46+ *
47+ * @param {Object} entity The name of a machine, unit, service, or
48+ * environment, e.g. '0', 'mysql/0', or 'mysql'. To specify the
49+ * environment as the entity the magic string 'env' is used.
50+ * @param {Object} keys An optional list of annotation key names for the
51+ * annotations to be deleted. If no keys are passed, all annotations
52+ * for the entity will be removed.
53+ * @return {undefined} Nothing.
54+ */
55+ remove_annotations: function(entity, keys, callback) {
56+ this._send_rpc({
57+ op: 'remove_annotations',
58+ entity: entity,
59+ keys: keys || []}, callback);
60 }
61
62-
63 });
64
65
66
67=== modified file 'test/test_env.js'
68--- test/test_env.js 2012-10-14 16:30:50 +0000
69+++ test/test_env.js 2013-01-09 14:59:22 +0000
70@@ -31,15 +31,14 @@
71 done();
72 });
73
74- it('can deploy a service', function(done) {
75+ it('can deploy a service', function() {
76 env.deploy('precise/mysql');
77 msg = conn.last_message();
78 msg.op.should.equal('deploy');
79 msg.charm_url.should.equal('precise/mysql');
80- done();
81 });
82
83- it('can deploy a service with a config file', function(done) {
84+ it('can deploy a service with a config file', function() {
85 /*jshint multistr:true */
86 var config_raw = 'tuning-level: \nexpert-mojo';
87 /*jshint multistr:false */
88@@ -48,16 +47,14 @@
89 msg.op.should.equal('deploy');
90 msg.charm_url.should.equal('precise/mysql');
91 msg.config_raw.should.equal(config_raw);
92- done();
93 });
94
95- it('can add a unit', function(done) {
96+ it('can add a unit', function() {
97 env.add_unit('mysql', 3);
98 msg = conn.last_message();
99 msg.op.should.equal('add_unit');
100 msg.service_name.should.equal('mysql');
101 msg.num_units.should.equal(3);
102- done();
103 });
104
105 it('can accept a callback on its methods', function(done) {
106@@ -76,7 +73,7 @@
107 'result': {'id': 'cs:precise/mysql'}});
108 });
109
110- it('can resolve a problem with a unit', function(done) {
111+ it('can resolve a problem with a unit', function() {
112 var unit_name = 'mysql/0';
113 env.resolved(unit_name);
114 msg = conn.last_message();
115@@ -84,10 +81,9 @@
116 msg.unit_name.should.equal(unit_name);
117 var _ = expect(msg.relation_name).to.not.exist;
118 msg.retry.should.equal(false);
119- done();
120 });
121
122- it('can resolve a problem with a unit relation', function(done) {
123+ it('can resolve a problem with a unit relation', function() {
124 var unit_name = 'mysql/0';
125 var rel_name = 'relation-0000000000';
126 env.resolved(unit_name, rel_name);
127@@ -96,10 +92,9 @@
128 msg.unit_name.should.equal(unit_name);
129 msg.relation_name.should.equal(rel_name);
130 msg.retry.should.equal(false);
131- done();
132 });
133
134- it('can retry a problem with a unit', function(done) {
135+ it('can retry a problem with a unit', function() {
136 var unit_name = 'mysql/0';
137 env.resolved(unit_name, null, true);
138 msg = conn.last_message();
139@@ -107,7 +102,6 @@
140 msg.unit_name.should.equal(unit_name);
141 var _ = expect(msg.relation_name).to.not.exist;
142 msg.retry.should.equal(true);
143- done();
144 });
145
146 it('can retry a problem with a unit using a callback', function(done) {
147@@ -124,7 +118,7 @@
148 request_id: msg.request_id});
149 });
150
151- it('will populate the provider type and default series', function(done) {
152+ it('will populate the provider type and default series', function() {
153 var providerType = 'super provider',
154 defaultSeries = 'oneiric',
155 evt =
156@@ -141,7 +135,6 @@
157 // After the message arrives the provider type is set.
158 assert.equal(env.get('providerType'), providerType);
159 assert.equal(env.get('defaultSeries'), defaultSeries);
160- done();
161 });
162
163 it('can get endpoints for a service', function() {
164@@ -151,6 +144,41 @@
165 msg.service_names.should.eql(['mysql']);
166 });
167
168+ it('can update annotations', function() {
169+ var unit_name = 'mysql/0';
170+ env.update_annotations(unit_name, {name: 'A'});
171+ msg = conn.last_message();
172+ msg.op.should.equal('update_annotations');
173+ msg.entity.should.equal(unit_name);
174+ msg.data.name.should.equal('A');
175+ });
176+
177+ it('can get annotations', function() {
178+ var unit_name = 'mysql/0';
179+ env.get_annotations(unit_name);
180+ msg = conn.last_message();
181+ msg.op.should.equal('get_annotations');
182+ msg.entity.should.equal(unit_name);
183+ });
184+
185+ it('can remove annotations with specified keys', function() {
186+ var unit_name = 'mysql/0';
187+ var keys = ['key1', 'key2'];
188+ env.remove_annotations(unit_name, keys);
189+ msg = conn.last_message();
190+ msg.op.should.equal('remove_annotations');
191+ msg.entity.should.equal(unit_name);
192+ msg.keys.should.eql(keys);
193+ });
194+
195+ it('can remove annotations with no specified keys', function() {
196+ var unit_name = 'mysql/0';
197+ env.remove_annotations(unit_name);
198+ msg = conn.last_message();
199+ msg.op.should.equal('remove_annotations');
200+ msg.entity.should.equal(unit_name);
201+ msg.keys.should.eql([]);
202+ });
203
204 });
205 })();

Subscribers

People subscribed via source and target branches