Merge lp:~frankban/juju-gui/bug-1168308-add-unit into lp:juju-gui/experimental

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 543
Proposed branch: lp:~frankban/juju-gui/bug-1168308-add-unit
Merge into: lp:juju-gui/experimental
Diff against target: 121 lines (+100/-0)
2 files modified
app/store/env/go.js (+59/-0)
test/test_env_go.js (+41/-0)
To merge this branch: bzr merge lp:~frankban/juju-gui/bug-1168308-add-unit
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+158573@code.launchpad.net

Description of the change

Implement add_unit in GoEnvironment.

https://codereview.appspot.com/8706043/

To post a comment you must log in.
Revision history for this message
Francesco Banconi (frankban) wrote :

Reviewers: mp+158573_code.launchpad.net,

Message:
Please take a look.

Description:
Implement add_unit in GoEnvironment.

https://code.launchpad.net/~frankban/juju-gui/bug-1168308-add-unit/+merge/158573

(do not edit description out of merge proposal)

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

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

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

LGTM. Thank you for doing this, and especially for finding the need.

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

https://codereview.appspot.com/8706043/diff/1/app/store/env/go.js#newcode403
app/store/env/go.js:403: * @method handleAddUnit
Trivial: add @static? <shrug>

https://codereview.appspot.com/8706043/

543. By Francesco Banconi

Changes as per review.

544. By Francesco Banconi

Merged trunk.

Revision history for this message
Francesco Banconi (frankban) wrote :

*** Submitted:

Implement add_unit in GoEnvironment.

R=gary.poster, benji
CC=
https://codereview.appspot.com/8706043

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

https://codereview.appspot.com/8706043/diff/1/app/store/env/go.js#newcode403
app/store/env/go.js:403: * @method handleAddUnit
On 2013/04/12 12:13:26, gary.poster wrote:
> Trivial: add @static? <shrug>

Done.

https://codereview.appspot.com/8706043/

Revision history for this message
Francesco Banconi (frankban) wrote :

Hi Gary and Benji, thanks for the reviews.

https://codereview.appspot.com/8706043/

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-10 15:08:53 +0000
3+++ app/store/env/go.js 2013-04-12 14:38:41 +0000
4@@ -368,6 +368,65 @@
5 },
6
7 /**
8+ * Add units to the provided service.
9+ *
10+ * @method add_unit
11+ * @param {String} service The service to be scaled up.
12+ * @param {Integer} numUnits The number of units to be added.
13+ * @param {Function} callback A callable that must be called once the
14+ * operation is performed. It will receive an object with an "err"
15+ * attribute containing a string describing the problem (if an error
16+ * occurred), or with the following attributes if everything went well:
17+ * - service_name: the name of the service;
18+ * - num_units: the number of units added;
19+ * - result: a list containing the names of the added units.
20+ * @return {undefined} Sends a message to the server only.
21+ */
22+ add_unit: function(service, numUnits, callback) {
23+ var intermediateCallback;
24+ if (callback) {
25+ // Curry the callback, service and numUnits. No context is passed.
26+ intermediateCallback = Y.bind(this.handleAddUnit, null,
27+ callback, service, numUnits);
28+ }
29+ this._send_rpc({
30+ Type: 'Client',
31+ Request: 'AddServiceUnits',
32+ Params: {ServiceName: service, NumUnits: numUnits}
33+ }, intermediateCallback);
34+ },
35+
36+ /**
37+ * Transform the data returned from the juju-core add_unit call into that
38+ * suitable for the user callback.
39+ *
40+ * @method handleAddUnit
41+ * @static
42+ * @param {Function} userCallback The callback originally submitted by the
43+ * call site.
44+ * @param {String} service The name of the service. Passed in since it
45+ * is not part of the response.
46+ * @param {Integer} numUnits The number of added units.
47+ * @param {Object} data The response returned by the server.
48+ * @return {undefined} Nothing.
49+ */
50+ handleAddUnit: function(userCallback, service, numUnits, data) {
51+ var transformedData = {
52+ err: data.Error,
53+ service_name: service
54+ };
55+ if (data.Error) {
56+ transformedData.num_units = numUnits;
57+ } else {
58+ var units = data.Response.Units;
59+ transformedData.result = units;
60+ transformedData.num_units = units.length;
61+ }
62+ // Call the original user callback.
63+ userCallback(transformedData);
64+ },
65+
66+ /**
67 * Expose the given service.
68 *
69 * @method expose
70
71=== modified file 'test/test_env_go.js'
72--- test/test_env_go.js 2013-04-10 15:08:53 +0000
73+++ test/test_env_go.js 2013-04-12 14:38:41 +0000
74@@ -206,6 +206,47 @@
75 assert.equal('envname', env.get('environmentName'));
76 });
77
78+ it('sends the correct AddServiceUnits message', function() {
79+ env.add_unit('django', 3);
80+ var last_message = conn.last_message();
81+ var expected = {
82+ Type: 'Client',
83+ Request: 'AddServiceUnits',
84+ RequestId: 1,
85+ Params: {ServiceName: 'django', NumUnits: 3}
86+ };
87+ assert.deepEqual(expected, last_message);
88+ });
89+
90+ it('successfully adds units to a service', function(done) {
91+ env.add_unit('django', 2, function(data) {
92+ assert.strictEqual('django', data.service_name);
93+ assert.strictEqual(2, data.num_units);
94+ assert.deepEqual(['django/2', 'django/3'], data.result);
95+ assert.isUndefined(data.err);
96+ done();
97+ });
98+ // Mimic response.
99+ conn.msg({
100+ RequestId: 1,
101+ Response: {Units: ['django/2', 'django/3']}
102+ });
103+ });
104+
105+ it('handles failures adding units to a service', function(done) {
106+ env.add_unit('django', 0, function(data) {
107+ assert.strictEqual('django', data.service_name);
108+ assert.strictEqual(0, data.num_units);
109+ assert.strictEqual('must add at least one unit', data.err);
110+ done();
111+ });
112+ // Mimic response.
113+ conn.msg({
114+ RequestId: 1,
115+ Error: 'must add at least one unit'
116+ });
117+ });
118+
119 it('sends the correct expose message', function() {
120 env.expose('apache');
121 var last_message = conn.last_message();

Subscribers

People subscribed via source and target branches