LEFT | RIGHT |
1 /* | 1 /* |
2 This file is part of the Juju GUI, which lets users view and manage Juju | 2 This file is part of the Juju GUI, which lets users view and manage Juju |
3 environments within a graphical interface (https://launchpad.net/juju-gui). | 3 environments within a graphical interface (https://launchpad.net/juju-gui). |
4 Copyright (C) 2012-2013 Canonical Ltd. | 4 Copyright (C) 2012-2013 Canonical Ltd. |
5 | 5 |
6 This program is free software: you can redistribute it and/or modify it under | 6 This program is free software: you can redistribute it and/or modify it under |
7 the terms of the GNU Affero General Public License version 3, as published by | 7 the terms of the GNU Affero General Public License version 3, as published by |
8 the Free Software Foundation. | 8 the Free Software Foundation. |
9 | 9 |
10 This program is distributed in the hope that it will be useful, but WITHOUT | 10 This program is distributed in the hope that it will be useful, but WITHOUT |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 attribute containing the charm used, and a "units" attribute | 283 attribute containing the charm used, and a "units" attribute |
284 containing a list of the added units. This is asynchronous because we | 284 containing a list of the added units. This is asynchronous because we |
285 often must go over the network to the charm store. | 285 often must go over the network to the charm store. |
286 @param {Object} options An options object. | 286 @param {Object} options An options object. |
287 name: The name of the service to be deployed, defaulting to the charm | 287 name: The name of the service to be deployed, defaulting to the charm |
288 name. | 288 name. |
289 config: The charm configuration options, defaulting to none. | 289 config: The charm configuration options, defaulting to none. |
290 configYAML: The charm configuration options, expressed as a YAML | 290 configYAML: The charm configuration options, expressed as a YAML |
291 string. You may provide only one of config or configYAML. | 291 string. You may provide only one of config or configYAML. |
292 unitCount: The number of units to be deployed. | 292 unitCount: The number of units to be deployed. |
293 @return {undefined} Get the result from the callback. | 293 @return {undefined} All results are passed to the callback. |
294 */ | 294 */ |
295 deploy: function(charmId, callback, options) { | 295 deploy: function(charmId, callback, options) { |
296 if (!this.get('authenticated')) { | 296 if (!this.get('authenticated')) { |
297 return callback(UNAUTHENTICATED_ERROR); | 297 return callback(UNAUTHENTICATED_ERROR); |
298 } | 298 } |
299 if (!options) { | 299 if (!options) { |
300 options = {}; | 300 options = {}; |
301 } | 301 } |
302 var self = this; | 302 var self = this; |
303 this._loadCharm( | 303 this._loadCharm( |
304 charmId, | 304 charmId, |
305 { | 305 { |
306 // On success deploy the successfully-obtained charm. | 306 // On success deploy the successfully-obtained charm. |
307 success: function(charm) { | 307 success: function(charm) { |
308 self._deployFromCharm(charm, callback, options); | 308 self._deployFromCharm(charm, callback, options); |
| 309 }, |
| 310 failure: callback |
| 311 } |
| 312 ); |
| 313 }, |
| 314 |
| 315 /** |
| 316 Set the given service to use the given charm, optionally forcing units in |
| 317 error state to use the charm. |
| 318 |
| 319 @method setCharm |
| 320 @param {String} serviceName The name of the service to set. |
| 321 @param {String} charmId The charm to use. |
| 322 @param {Boolean} force Whether or not to force the issue. |
| 323 @param {Function} callback A call that will receive an object, potentially |
| 324 with an "error" attribute containing a string describing the problem. |
| 325 @return {undefined} All results are passed to the callback. |
| 326 */ |
| 327 setCharm: function(serviceName, charmId, force, callback) { |
| 328 if (!this.get('authenticated')) { |
| 329 return callback(UNAUTHENTICATED_ERROR); |
| 330 } |
| 331 var self = this; |
| 332 var service = this.db.services.getById(serviceName); |
| 333 if (!service) { |
| 334 return callback({error: 'Service "' + serviceName + '" not found.'}); |
| 335 } |
| 336 var serviceInError = this.db.units.get_units_for_service(service) |
| 337 .some(function(unit) { |
| 338 return (/error/).test(unit.agent_state); |
| 339 }); |
| 340 if (serviceInError && !force) { |
| 341 return callback({error: 'Cannot set charm on a service with units in ' + |
| 342 'error without the force flag.'}); |
| 343 } |
| 344 this._loadCharm( |
| 345 charmId, |
| 346 { |
| 347 success: function(charm) { |
| 348 service.set('charm', charm.get('id')); |
| 349 self.changes.services[service.get('id')] = [service, true]; |
| 350 callback({}); |
309 }, | 351 }, |
310 failure: callback | 352 failure: callback |
311 } | 353 } |
312 ); | 354 ); |
313 }, | 355 }, |
314 | 356 |
315 /** | 357 /** |
316 Get a charm from a URL, via charmStore and/or db. Uses callbacks. | 358 Get a charm from a URL, via charmStore and/or db. Uses callbacks. |
317 | 359 |
318 @method _loadCharm | 360 @method _loadCharm |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 | 744 |
703 if (!this.get('authenticated')) { | 745 if (!this.get('authenticated')) { |
704 return UNAUTHENTICATED_ERROR; | 746 return UNAUTHENTICATED_ERROR; |
705 } | 747 } |
706 | 748 |
707 if (service) { | 749 if (service) { |
708 if (!service.get('exposed')) { | 750 if (!service.get('exposed')) { |
709 service.set('exposed', true); | 751 service.set('exposed', true); |
710 this.changes.services[service.get('id')] = [service, true]; | 752 this.changes.services[service.get('id')] = [service, true]; |
711 } else { | 753 } else { |
712 warning = 'Service `' + serviceName + '` was already exposed.'; | 754 warning = 'Service "' + serviceName + '" was already exposed.'; |
713 } | 755 } |
714 } else { | 756 } else { |
715 error = '`' + serviceName + '` is an invalid service name.'; | 757 error = '"' + serviceName + '" is an invalid service name.'; |
716 } | 758 } |
717 | 759 |
718 return { | 760 return { |
719 error: error, | 761 error: error, |
720 warning: warning | 762 warning: warning |
721 }; | 763 }; |
722 }, | 764 }, |
723 | 765 |
724 /** | 766 /** |
725 Unexposes a service from the supplied string. | 767 Unexposes a service from the supplied string. |
726 | 768 |
727 @method unexpose | 769 @method unexpose |
728 @param {String} serviceName The service name. | 770 @param {String} serviceName The service name. |
729 @return {Object} An object containing an `error` and `warning` properties | 771 @return {Object} An object containing an `error` and `warning` properties |
730 which will be undefined if there were no warnings or errors. | 772 which will be undefined if there were no warnings or errors. |
731 */ | 773 */ |
732 unexpose: function(serviceName) { | 774 unexpose: function(serviceName) { |
733 var service = this.db.services.getById(serviceName), | 775 var service = this.db.services.getById(serviceName), |
734 warning, error; | 776 warning, error; |
735 | 777 |
736 if (!this.get('authenticated')) { | 778 if (!this.get('authenticated')) { |
737 return UNAUTHENTICATED_ERROR; | 779 return UNAUTHENTICATED_ERROR; |
738 } | 780 } |
739 if (service) { | 781 if (service) { |
740 if (service.get('exposed')) { | 782 if (service.get('exposed')) { |
741 service.set('exposed', false); | 783 service.set('exposed', false); |
742 this.changes.services[service.get('id')] = [service, true]; | 784 this.changes.services[service.get('id')] = [service, true]; |
743 } else { | 785 } else { |
744 warning = 'Service `' + serviceName + '` is not exposed.'; | 786 warning = 'Service "' + serviceName + '" is not exposed.'; |
745 } | 787 } |
746 } else { | 788 } else { |
747 error = '`' + serviceName + '` is an invalid service name.'; | 789 error = '"' + serviceName + '" is an invalid service name.'; |
748 } | 790 } |
749 | 791 |
750 return { | 792 return { |
751 error: error, | 793 error: error, |
752 warning: warning | 794 warning: warning |
753 }; | 795 }; |
754 }, | 796 }, |
755 | 797 |
756 /** | 798 /** |
757 Add a relation between two services. | 799 Add a relation between two services. |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 exportEnvironment: function() { | 1205 exportEnvironment: function() { |
1164 var self = this, | 1206 var self = this, |
1165 serviceList = this.db.services, | 1207 serviceList = this.db.services, |
1166 relationList = this.db.relations, | 1208 relationList = this.db.relations, |
1167 result = {meta: { | 1209 result = {meta: { |
1168 exportFormat: 1.0 | 1210 exportFormat: 1.0 |
1169 }, | 1211 }, |
1170 services: [], relations: []}, | 1212 services: [], relations: []}, |
1171 blackLists = { | 1213 blackLists = { |
1172 service: ['id', 'aggregated_status', 'clientId', 'initialized', | 1214 service: ['id', 'aggregated_status', 'clientId', 'initialized', |
1173 'destroyed', 'pending'], | 1215 'constraintsStr', 'destroyed', 'pending'], |
1174 relation: ['id', 'relation_id', 'clientId', 'initialized', | 1216 relation: ['id', 'relation_id', 'clientId', 'initialized', |
1175 'destroyed', 'pending'] | 1217 'destroyed', 'pending'] |
1176 }; | 1218 }; |
1177 | 1219 |
1178 if (!this.get('authenticated')) { | 1220 if (!this.get('authenticated')) { |
1179 return UNAUTHENTICATED_ERROR; | 1221 return UNAUTHENTICATED_ERROR; |
1180 } | 1222 } |
1181 | 1223 |
1182 serviceList.each(function(s) { | 1224 serviceList.each(function(s) { |
1183 var serviceData = s.getAttrs(); | 1225 var serviceData = s.getAttrs(); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 Y.namespace('juju.environments').FakeBackend = FakeBackend; | 1390 Y.namespace('juju.environments').FakeBackend = FakeBackend; |
1349 | 1391 |
1350 }, '0.1.0', { | 1392 }, '0.1.0', { |
1351 requires: [ | 1393 requires: [ |
1352 'base', | 1394 'base', |
1353 'js-yaml', | 1395 'js-yaml', |
1354 'juju-models', | 1396 'juju-models', |
1355 'promise' | 1397 'promise' |
1356 ] | 1398 ] |
1357 }); | 1399 }); |
LEFT | RIGHT |