Merge lp:~makyo/juju-gui/go-remove-units-1168310 into lp:juju-gui/experimental

Proposed by Madison Scott-Clary
Status: Merged
Merged at revision: 546
Proposed branch: lp:~makyo/juju-gui/go-remove-units-1168310
Merge into: lp:juju-gui/experimental
Diff against target: 103 lines (+82/-0)
2 files modified
app/store/env/go.js (+44/-0)
test/test_env_go.js (+38/-0)
To merge this branch: bzr merge lp:~makyo/juju-gui/go-remove-units-1168310
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+158688@code.launchpad.net

Description of the change

Implement remove_units in go env

https://codereview.appspot.com/8721043/

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

Reviewers: mp+158688_code.launchpad.net,

Message:
Please take a look.

Description:
Implement remove_units in go env

https://code.launchpad.net/~makyo/juju-gui/go-remove-units-1168310/+merge/158688

(do not edit description out of merge proposal)

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

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

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: test/test_env_go.js
=== modified file 'test/test_env_go.js'
--- test/test_env_go.js 2013-04-12 11:33:12 +0000
+++ test/test_env_go.js 2013-04-12 17:40:34 +0000
@@ -247,6 +247,44 @@
        });
      });

+ it('sends the correct DestroyServiceUnits message', function() {
+ env.remove_units(['django/2', 'django/3']);
+ var last_message = conn.last_message();
+ var expected = {
+ Type: 'Client',
+ Request: 'DestroyServiceUnits',
+ RequestId: 1,
+ Params: {UnitNames: ['django/2', 'django/3']}
+ };
+ assert.deepEqual(expected, last_message);
+ });
+
+ it('successfully removes units from a service', function(done) {
+ env.remove_units(['django/2', 'django/3'], function(data) {
+ assert.deepEqual(['django/2', 'django/3'], data.unit_names);
+ assert.isUndefined(data.err);
+ done();
+ });
+ // Mimic response.
+ conn.msg({
+ RequestId: 1,
+ Response: {}
+ });
+ });
+
+ it('handles failures removing units from a service', function(done) {
+ env.remove_units(['django/2'], function(data) {
+ assert.deepEqual(['django/2'], data.unit_names);
+ assert.strictEqual('unit django/2 does not exist', data.err);
+ done();
+ });
+ // Mimic response.
+ conn.msg({
+ RequestId: 1,
+ Error: 'unit django/2 does not exist'
+ });
+ });
+
      it('sends the correct expose message', function() {
        env.expose('apache');
        var last_message = conn.last_message();

Index: app/store/env/go.js
=== modified file 'app/store/env/go.js'
--- app/store/env/go.js 2013-04-12 12:30:52 +0000
+++ app/store/env/go.js 2013-04-12 17:40:34 +0000
@@ -427,6 +427,50 @@
      },

      /**
+ * Remove units from a service.
+ *
+ * @method remove_units
+ * @param {Array} unit_names The units to be removed.
+ * @param {Function} callback A callable that must be called once the
+ operation is performed.
+ * @return {undefined} Sends a message to the server only.
+ */
+ remove_units: function(unit_names, callback) {
+ var intermediateCallback;
+ if (callback) {
+ // Curry the callback and unit_names. No context is passed.
+ intermediateCallback = Y.bind(this.handleRemoveUnits, null,
+ callback, unit_names);
+ }
+ this._send_rpc({
+ Type: 'Client',
+ Request: 'DestroyServiceUnits',
+ ...

Read more...

Revision history for this message
Jeff Pihach (hatch) wrote :

LGTM - let there be remove_units!

https://codereview.appspot.com/8721043/

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

LGTM with a couple of small documentation requests.

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

https://codereview.appspot.com/8721043/diff/1/app/store/env/go.js#newcode435
app/store/env/go.js:435: operation is performed.
Many methods list the items that will be passed to the callable here. I
find that pretty helpful.

https://codereview.appspot.com/8721043/diff/1/app/store/env/go.js#newcode436
app/store/env/go.js:436: * @return {undefined} Sends a message to the
server only.
rick_h claims yuidoc doesn't need this content-free @return. Might be
worth removing and seeing. I'd like to see them go away if we really
don't require them.

https://codereview.appspot.com/8721043/

Revision history for this message
Madison Scott-Clary (makyo) wrote :

*** Submitted:

Implement remove_units in go env

R=jeff.pihach, bac
CC=
https://codereview.appspot.com/8721043

https://codereview.appspot.com/8721043/

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-12 12:30:52 +0000
3+++ app/store/env/go.js 2013-04-12 17:47:32 +0000
4@@ -427,6 +427,50 @@
5 },
6
7 /**
8+ * Remove units from a service.
9+ *
10+ * @method remove_units
11+ * @param {Array} unit_names The units to be removed.
12+ * @param {Function} callback A callable that must be called once the
13+ operation is performed.
14+ * @return {undefined} Sends a message to the server only.
15+ */
16+ remove_units: function(unit_names, callback) {
17+ var intermediateCallback;
18+ if (callback) {
19+ // Curry the callback and unit_names. No context is passed.
20+ intermediateCallback = Y.bind(this.handleRemoveUnits, null,
21+ callback, unit_names);
22+ }
23+ this._send_rpc({
24+ Type: 'Client',
25+ Request: 'DestroyServiceUnits',
26+ Params: {UnitNames: unit_names}
27+ }, intermediateCallback);
28+ },
29+
30+ /**
31+ * Transform the data returned from the juju-core remove_units call into
32+ * that suitable for the user callback.
33+ *
34+ * @method handleRemoveUnits
35+ * @static
36+ * @param {Function} userCallback The callback originally submitted by the
37+ * call site.
38+ * @param {Array} unitNames The names of the removed units. Passed in
39+ * since it is not part of the response.
40+ * @param {Object} data The response returned by the server.
41+ * @return {undefined} Nothing.
42+ */
43+ handleRemoveUnits: function(userCallback, unitNames, data) {
44+ var transformedData = {
45+ err: data.Error,
46+ unit_names: unitNames
47+ };
48+ userCallback(transformedData);
49+ },
50+
51+ /**
52 * Expose the given service.
53 *
54 * @method expose
55
56=== modified file 'test/test_env_go.js'
57--- test/test_env_go.js 2013-04-12 11:33:12 +0000
58+++ test/test_env_go.js 2013-04-12 17:47:32 +0000
59@@ -247,6 +247,44 @@
60 });
61 });
62
63+ it('sends the correct DestroyServiceUnits message', function() {
64+ env.remove_units(['django/2', 'django/3']);
65+ var last_message = conn.last_message();
66+ var expected = {
67+ Type: 'Client',
68+ Request: 'DestroyServiceUnits',
69+ RequestId: 1,
70+ Params: {UnitNames: ['django/2', 'django/3']}
71+ };
72+ assert.deepEqual(expected, last_message);
73+ });
74+
75+ it('successfully removes units from a service', function(done) {
76+ env.remove_units(['django/2', 'django/3'], function(data) {
77+ assert.deepEqual(['django/2', 'django/3'], data.unit_names);
78+ assert.isUndefined(data.err);
79+ done();
80+ });
81+ // Mimic response.
82+ conn.msg({
83+ RequestId: 1,
84+ Response: {}
85+ });
86+ });
87+
88+ it('handles failures removing units from a service', function(done) {
89+ env.remove_units(['django/2'], function(data) {
90+ assert.deepEqual(['django/2'], data.unit_names);
91+ assert.strictEqual('unit django/2 does not exist', data.err);
92+ done();
93+ });
94+ // Mimic response.
95+ conn.msg({
96+ RequestId: 1,
97+ Error: 'unit django/2 does not exist'
98+ });
99+ });
100+
101 it('sends the correct expose message', function() {
102 env.expose('apache');
103 var last_message = conn.last_message();

Subscribers

People subscribed via source and target branches