/**
+ * 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',
+ Params: {UnitNames: unit_names}
+ }, intermediateCallback);
+ },
+
+ /**
+ * Transform the data returned from the juju-core remove_units call
into
+ * that suitable for the user callback.
+ *
+ * @method handleRemoveUnits
+ * @static
+ * @param {Function} userCallback The callback originally submitted by
the
+ * call site.
+ * @param {Array} unitNames The names of the removed units. Passed in
+ * since it is not part of the response.
+ * @param {Object} data The response returned by the server.
+ * @return {undefined} Nothing.
+ */
+ handleRemoveUnits: function(userCallback, unitNames, data) {
+ var transformedData = {
+ err: data.Error,
+ unit_names: unitNames
+ };
+ userCallback(transformedData);
+ },
+
+ /**
* Expose the given service.
*
* @method expose
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 env_go. js'
=== modified file 'test/test_
--- 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() { units([ 'django/ 2', 'django/3']); message( ); Units', deepEqual( expected, last_message); units([ 'django/ 2', 'django/3'], function(data) { deepEqual( ['django/ 2', 'django/3'], data.unit_names); isUndefined( data.err) ; units([ 'django/ 2'], function(data) { deepEqual( ['django/ 2'], data.unit_names); strictEqual( 'unit django/2 does not exist', data.err);
env.expose( 'apache' ); message( );
+ env.remove_
+ var last_message = conn.last_
+ var expected = {
+ Type: 'Client',
+ Request: 'DestroyService
+ RequestId: 1,
+ Params: {UnitNames: ['django/2', 'django/3']}
+ };
+ assert.
+ });
+
+ it('successfully removes units from a service', function(done) {
+ env.remove_
+ assert.
+ assert.
+ done();
+ });
+ // Mimic response.
+ conn.msg({
+ RequestId: 1,
+ Response: {}
+ });
+ });
+
+ it('handles failures removing units from a service', function(done) {
+ env.remove_
+ assert.
+ assert.
+ done();
+ });
+ // Mimic response.
+ conn.msg({
+ RequestId: 1,
+ Error: 'unit django/2 does not exist'
+ });
+ });
+
it('sends the correct expose message', function() {
var last_message = conn.last_
Index: app/store/env/go.js env/go. js'
=== modified file 'app/store/
--- 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 @@
},
/** unit_names, callback) { lback; lback = Y.bind( this.handleRemo veUnits, null, Units', lback); userCallback, unitNames, data) { transformedData );
+ * 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(
+ var intermediateCal
+ if (callback) {
+ // Curry the callback and unit_names. No context is passed.
+ intermediateCal
+ callback, unit_names);
+ }
+ this._send_rpc({
+ Type: 'Client',
+ Request: 'DestroyService
+ Params: {UnitNames: unit_names}
+ }, intermediateCal
+ },
+
+ /**
+ * Transform the data returned from the juju-core remove_units call
into
+ * that suitable for the user callback.
+ *
+ * @method handleRemoveUnits
+ * @static
+ * @param {Function} userCallback The callback originally submitted by
the
+ * call site.
+ * @param {Array} unitNames The names of the removed units. Passed in
+ * since it is not part of the response.
+ * @param {Object} data The response returned by the server.
+ * @return {undefined} Nothing.
+ */
+ handleRemoveUnits: function(
+ var transformedData = {
+ err: data.Error,
+ unit_names: unitNames
+ };
+ userCallback(
+ },
+
+ /**
* Expose the given service.
*
* @method expose