Merge lp:~benji/juju-gui/go-resolved into lp:juju-gui/experimental

Proposed by Benji York
Status: Merged
Merged at revision: 562
Proposed branch: lp:~benji/juju-gui/go-resolved
Merge into: lp:juju-gui/experimental
Diff against target: 238 lines (+105/-14)
2 files modified
app/store/env/go.js (+70/-14)
test/test_env_go.js (+35/-0)
To merge this branch: bzr merge lp:~benji/juju-gui/go-resolved
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+159162@code.launchpad.net

Description of the change

Support resolving errors on the Go back-end.

https://codereview.appspot.com/8797043/

To post a comment you must log in.
Revision history for this message
Madison Scott-Clary (makyo) wrote :

LGTM - thanks for the branch.

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

https://codereview.appspot.com/8797043/diff/1/app/store/env/go.js#newcode896
app/store/env/go.js:896: err: !!data.Error,
I know that we usually check if (data.err) in code, but the Error
received is usually a string, correct? If so, we may want to either
leave it as such or make a note for future reference if this winds up in
the notifications list or something.

https://codereview.appspot.com/8797043/

lp:~benji/juju-gui/go-resolved updated
555. By Benji York

fix error noted in review

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

LGTM. Thank you!

Gary

https://codereview.appspot.com/8797043/diff/6001/app/store/env/go.js
File app/store/env/go.js (right):

https://codereview.appspot.com/8797043/diff/6001/app/store/env/go.js#newcode872
app/store/env/go.js:872: Retry: !!retry
Javascript, you so funny.

https://codereview.appspot.com/8797043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/store/env/go.js'
2--- app/store/env/go.js 2013-04-15 12:24:16 +0000
3+++ app/store/env/go.js 2013-04-16 14:42:29 +0000
4@@ -194,7 +194,9 @@
5 // change in delta events based on the deltas we got.
6 var deltas = [];
7 data.Response.Deltas.forEach(function(delta) {
8- var kind = delta[0], operation = delta[1], entityInfo = delta[2];
9+ var kind = delta[0],
10+ operation = delta[1],
11+ entityInfo = delta[2];
12 deltas.push([kind + 'Info', operation, entityInfo]);
13 });
14 this.fire('delta', {data: {result: deltas}});
15@@ -385,7 +387,7 @@
16 add_unit: function(service, numUnits, callback) {
17 var intermediateCallback;
18 if (callback) {
19- // Curry the callback, service and numUnits. No context is passed.
20+ // Capture the callback, service and numUnits. No context is passed.
21 intermediateCallback = Y.bind(this.handleAddUnit, null,
22 callback, service, numUnits);
23 }
24@@ -438,7 +440,7 @@
25 remove_units: function(unit_names, callback) {
26 var intermediateCallback;
27 if (callback) {
28- // Curry the callback and unit_names. No context is passed.
29+ // Capture the callback and unit_names. No context is passed.
30 intermediateCallback = Y.bind(this.handleRemoveUnits, null,
31 callback, unit_names);
32 }
33@@ -485,7 +487,7 @@
34 expose: function(service, callback) {
35 var intermediateCallback;
36 if (callback) {
37- // Curry the callback and service. No context is passed.
38+ // Capture the callback and service. No context is passed.
39 intermediateCallback = Y.bind(this.handleServiceCalls, null,
40 callback, service);
41 }
42@@ -511,7 +513,7 @@
43 unexpose: function(service, callback) {
44 var intermediateCallback;
45 if (callback) {
46- // Curry the callback and service. No context is passed.
47+ // Capture the callback and service. No context is passed.
48 intermediateCallback = Y.bind(
49 this.handleServiceCalls, null, callback, service);
50 }
51@@ -558,7 +560,7 @@
52 update_annotations: function(entity, type, data, callback) {
53 var intermediateCallback;
54 if (callback) {
55- // Curry the callback and entity. No context is passed.
56+ // Capture the callback and entity. No context is passed.
57 intermediateCallback = Y.bind(this.handleSetAnnotations, null,
58 callback, entity);
59 }
60@@ -587,7 +589,7 @@
61 remove_annotations: function(entity, type, keys, callback) {
62 var intermediateCallback;
63 if (callback) {
64- // Curry the callback and entity. No context is passed.
65+ // Capture the callback and entity. No context is passed.
66 intermediateCallback = Y.bind(this.handleSetAnnotations, null,
67 callback, entity);
68 }
69@@ -637,7 +639,7 @@
70 get_annotations: function(entity, type, callback) {
71 var intermediateCallback;
72 if (callback) {
73- // Curry the callback and entity. No context is passed.
74+ // Capture the callback and entity. No context is passed.
75 intermediateCallback = Y.bind(this.handleGetAnnotations, null,
76 callback, entity);
77 }
78@@ -685,7 +687,7 @@
79 get_service: function(serviceName, callback) {
80 var intermediateCallback;
81 if (callback) {
82- // Curry the callback and serviceName. No context is passed.
83+ // Capture the callback and serviceName. No context is passed.
84 intermediateCallback = Y.bind(this.handleGetService, null,
85 callback, serviceName);
86 }
87@@ -742,7 +744,7 @@
88 set_config: function(serviceName, config, data, callback) {
89 var intermediateCallback, sendData;
90 if (callback) {
91- // Curry the callback and serviceName. No context is passed.
92+ // Capture the callback and serviceName. No context is passed.
93 intermediateCallback = Y.bind(this.handleServiceCalls, null,
94 callback, serviceName);
95 }
96@@ -774,7 +776,7 @@
97 destroy_service: function(service, callback) {
98 var intermediateCallback;
99 if (callback) {
100- // Curry the callback and service. No context is passed.
101+ // Capture the callback and service. No context is passed.
102 intermediateCallback = Y.bind(this.handleServiceCalls, null,
103 callback, service);
104 }
105@@ -801,7 +803,7 @@
106 set_constraints: function(serviceName, constraints, callback) {
107 var intermediateCallback, sendData;
108 if (callback) {
109- // Curry the callback and serviceName. No context is passed.
110+ // Capture the callback and serviceName. No context is passed.
111 intermediateCallback = Y.bind(this.handleSetConstraints, null,
112 callback, serviceName);
113 }
114@@ -843,6 +845,60 @@
115 },
116
117 /**
118+ Mark the given unit or relation problem as resolved.
119+
120+ @method resolved
121+ @param {String} unitName The unit name.
122+ @param {String} relationName The relation name (ignored).
123+ @param {Boolean} retry Whether or not to retry the unit/relation.
124+ @param {Function} callback A callable that must be called once the
125+ operation is performed.
126+ @return {undefined} Sends a message to the server only.
127+ */
128+ resolved: function(unitName, relationName, retry, callback) {
129+ // Resolving a unit/relation pair is not supported by the Go back-end, so
130+ // relationName is ignored here.
131+ var intermediateCallback, sendData;
132+ if (callback) {
133+ // Capture the callback and relationName. No context is passed.
134+ intermediateCallback = Y.bind(this.handleResolved, null, callback,
135+ unitName);
136+ }
137+ sendData = {
138+ Type: 'Client',
139+ Request: 'Resolved',
140+ Params: {
141+ UnitName: unitName,
142+ Retry: !!retry
143+ }
144+ };
145+ this._send_rpc(sendData, intermediateCallback);
146+ },
147+
148+ /**
149+ Transform the data returned from juju-core call to Resolved into that
150+ suitable for the user callback.
151+
152+ @method handleResolved
153+ @static
154+ @param {Function} userCallback The callback originally submitted by the
155+ call site.
156+ @param {String} unitName The name of the unit. Passed in since it is not
157+ part of the response.
158+ @param {Object} data The response returned by the server.
159+ @return {undefined} Nothing.
160+ */
161+ handleResolved: function(userCallback, unitName, data) {
162+ // Translate the callback data and call the user's callback.
163+ console.log(userCallback);
164+ userCallback({
165+ op: 'resolved',
166+ err: data.Error,
167+ unit_name: unitName
168+ });
169+ },
170+
171+ /**
172 Add a relation between two services.
173
174 @method add_relation
175@@ -933,7 +989,7 @@
176 var endpoint_b = endpointToName(endpointB);
177 var intermediateCallback;
178 if (callback) {
179- // Curry the endpoints. No context is passed.
180+ // Capture the endpoints. No context is passed.
181 intermediateCallback = Y.bind(this.handleRemoveRelation, null,
182 callback, endpoint_a, endpoint_b);
183 }
184@@ -984,7 +1040,7 @@
185 // callback is not provided, we can leave intermediateCallback undefined.
186 var intermediateCallback;
187 if (callback) {
188- // Curry the callback and service. No context is passed.
189+ // Capture the callback and service. No context is passed.
190 intermediateCallback = Y.bind(this.handleCharmInfo, null, callback);
191 }
192 this._send_rpc({
193
194=== modified file 'test/test_env_go.js'
195--- test/test_env_go.js 2013-04-12 20:49:24 +0000
196+++ test/test_env_go.js 2013-04-16 14:42:29 +0000
197@@ -1181,6 +1181,41 @@
198 assert.equal(subscribers[0].args, null);
199 });
200
201+ it('can resolve a problem with a unit', function() {
202+ var unit_name = 'mysql/0';
203+ env.resolved(unit_name);
204+ msg = conn.last_message();
205+ assert.equal(msg.Type, 'Client');
206+ assert.equal(msg.Request, 'Resolved');
207+ assert.equal(msg.Params.UnitName, 'mysql/0');
208+ assert.isFalse(msg.Params.Retry);
209+ });
210+
211+ it('can retry a problem with a unit', function() {
212+ var unit_name = 'mysql/0';
213+ env.resolved(unit_name, null, true);
214+ msg = conn.last_message();
215+ assert.equal(msg.Type, 'Client');
216+ assert.equal(msg.Request, 'Resolved');
217+ assert.equal(msg.Params.UnitName, 'mysql/0');
218+ assert.isTrue(msg.Params.Retry);
219+ });
220+
221+ it('can provide a callback', function(done) {
222+ var unit_name = 'mysql/0';
223+ env.resolved(unit_name, null, true, function(result) {
224+ assert.equal(result.op, 'resolved');
225+ assert.equal(result.err, 'badness');
226+ done();
227+ });
228+ msg = conn.last_message();
229+ env.dispatch_result({
230+ RequestId: msg.RequestId,
231+ Error: 'badness',
232+ Response: {}
233+ });
234+ });
235+
236 });
237
238 })();

Subscribers

People subscribed via source and target branches