stack_and_upgrade_controller.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var stringUtils = require('utils/string_utils');
  20. App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage, {
  21. name: 'mainAdminStackAndUpgradeController',
  22. /**
  23. * @type {Object|null}
  24. */
  25. serviceToInstall: null,
  26. /**
  27. * @type {object}
  28. * @default null
  29. */
  30. upgradeData: null,
  31. /**
  32. * @type {number}
  33. * @default null
  34. */
  35. upgradeId: null,
  36. /**
  37. * @type {string}
  38. * @default null
  39. */
  40. upgradeVersion: null,
  41. /**
  42. * version that currently applied to server
  43. * @type {Object|null}
  44. */
  45. currentVersion: null,
  46. /**
  47. * versions to which cluster could be upgraded
  48. * @type {Array}
  49. */
  50. targetVersions: [],
  51. /**
  52. * restore data from localStorage
  53. */
  54. init: function () {
  55. ['upgradeId', 'upgradeVersion'].forEach(function (property) {
  56. if (this.getDBProperty(property)) {
  57. this.set(property, this.getDBProperty(property));
  58. }
  59. }, this);
  60. },
  61. /**
  62. * @type {Array}
  63. */
  64. services: function() {
  65. return App.StackService.find().map(function(s) {
  66. s.set('isInstalled', App.Service.find().someProperty('serviceName', s.get('serviceName')));
  67. return s;
  68. });
  69. }.property('App.router.clusterController.isLoaded'),
  70. /**
  71. * launch Add Service wizard
  72. * @param event
  73. */
  74. goToAddService: function (event) {
  75. this.set('serviceToInstall', event.context);
  76. App.get('router').transitionTo('main.serviceAdd');
  77. },
  78. /**
  79. * call to fetch cluster stack versions
  80. * @return {$.ajax}
  81. */
  82. loadVersionsInfo: function () {
  83. return App.ajax.send({
  84. name: 'admin.stack_versions.all',
  85. sender: this,
  86. data: {},
  87. success: 'loadVersionsInfoSuccessCallback'
  88. });
  89. },
  90. /**
  91. * parse stack versions and
  92. * set <code>currentVersion</code>
  93. * set <code>targetVersions</code>
  94. * @param data
  95. */
  96. loadVersionsInfoSuccessCallback: function (data) {
  97. var versions = this.parseVersionsData(data);
  98. var current = versions.findProperty('state', 'CURRENT');
  99. var targetVersions = versions.without(current).filter(function (version) {
  100. //Only higher versions that have already been installed to all the hosts are shown
  101. return (version.state === 'INSTALLED' &&
  102. stringUtils.compareVersions(version.repository_version, current.repository_version) === 1);
  103. });
  104. this.set('currentVersion', current);
  105. this.set('targetVersions', targetVersions);
  106. },
  107. /**
  108. * parse ClusterStackVersions data to form common structure
  109. * @param {object} data
  110. * @return {Array}
  111. */
  112. parseVersionsData: function (data) {
  113. return data.items.map(function (item) {
  114. item.ClusterStackVersions.repository_name = item.repository_versions[0].RepositoryVersions.display_name;
  115. item.ClusterStackVersions.repository_id = item.repository_versions[0].RepositoryVersions.id;
  116. item.ClusterStackVersions.repository_version = item.repository_versions[0].RepositoryVersions.repository_version;
  117. return item.ClusterStackVersions;
  118. });
  119. },
  120. /**
  121. * load upgrade tasks by upgrade id
  122. * @return {$.Deferred}
  123. * @param {boolean} onlyState
  124. */
  125. loadUpgradeData: function (onlyState) {
  126. var upgradeId = this.get('upgradeId');
  127. var deferred = $.Deferred();
  128. if (Em.isNone(upgradeId)) {
  129. deferred.resolve();
  130. console.log('Upgrade in INIT state');
  131. } else {
  132. App.ajax.send({
  133. name: (onlyState) ? 'admin.upgrade.state' : 'admin.upgrade.data',
  134. sender: this,
  135. data: {
  136. id: upgradeId
  137. },
  138. success: 'loadUpgradeDataSuccessCallback'
  139. }).then(deferred.resolve);
  140. }
  141. return deferred.promise();
  142. },
  143. /**
  144. * parse and push upgrade tasks to controller
  145. * @param data
  146. */
  147. loadUpgradeDataSuccessCallback: function (data) {
  148. App.set('upgradeState', data.Upgrade.request_status);
  149. if (data.upgrade_groups) {
  150. this.set("upgradeData", data);
  151. }
  152. },
  153. /**
  154. * make call to start downgrade process
  155. */
  156. downgrade: function () {
  157. //TODO start downgrade
  158. },
  159. /**
  160. * make call to start upgrade process and show popup with current progress
  161. * @param {object} version
  162. */
  163. upgrade: function (version) {
  164. App.ajax.send({
  165. name: 'admin.upgrade.start',
  166. sender: this,
  167. data: {
  168. version: version.value
  169. },
  170. success: 'upgradeSuccessCallback'
  171. });
  172. this.set('upgradeVersion', version.label);
  173. this.setDBProperty('upgradeVersion', version.label);
  174. },
  175. /**
  176. * success callback of <code>upgrade()</code>
  177. * @param {object} data
  178. */
  179. upgradeSuccessCallback: function (data) {
  180. this.set('upgradeId', data.resources[0].Upgrade.request_id);
  181. this.setDBProperty('upgradeId', data.resources[0].Upgrade.request_id);
  182. App.clusterStatus.setClusterStatus({
  183. clusterName: App.get('clusterName'),
  184. clusterState: 'DEFAULT',
  185. localdb: App.db.data
  186. });
  187. this.openUpgradeDialog();
  188. },
  189. /**
  190. * make call to resume upgrade process and show popup with current progress
  191. */
  192. resumeUpgrade: function () {
  193. //TODO resume upgrade
  194. },
  195. /**
  196. * make call to stop upgrade process
  197. */
  198. stopUpgrade: function () {
  199. //TODO stop upgrade
  200. },
  201. /**
  202. * make call to finish upgrade process
  203. */
  204. finalize: function () {
  205. //TODO execute finalize
  206. this.finish();
  207. },
  208. /**
  209. * finish upgrade wizard
  210. * clean auxiliary data
  211. */
  212. finish: function () {
  213. this.set('upgradeId', null);
  214. this.setDBProperty('upgradeId', undefined);
  215. App.set('upgradeState', 'INIT');
  216. this.set('upgradeVersion', null);
  217. this.setDBProperty('upgradeVersion', undefined);
  218. App.clusterStatus.setClusterStatus({
  219. clusterName: App.get('clusterName'),
  220. clusterState: 'DEFAULT',
  221. localdb: App.db.data
  222. });
  223. },
  224. /**
  225. * show dialog with tasks of upgrade
  226. * @return {App.ModalPopup}
  227. */
  228. openUpgradeDialog: function () {
  229. App.router.transitionTo('admin.stackUpgrade');
  230. }
  231. });