upgrade_wizard_view.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. App.upgradeWizardView = Em.View.extend({
  20. controllerBinding: 'App.router.mainAdminStackAndUpgradeController',
  21. templateName: require('templates/main/admin/stack_upgrade/stack_upgrade_wizard'),
  22. /**
  23. * @type {Array}
  24. */
  25. failedStatuses: ['HOLDING_FAILED', 'HOLDING_TIMED_OUT', 'FAILED', 'TIMED_OUT'],
  26. /**
  27. * @type {Array}
  28. */
  29. activeStatuses: ['HOLDING_FAILED', 'HOLDING_TIMED_OUT', 'FAILED', 'TIMED_OUT', 'HOLDING', 'IN_PROGRESS'],
  30. /**
  31. * update timer
  32. * @type {number|null}
  33. * @default null
  34. */
  35. updateTimer: null,
  36. /**
  37. * @type {boolean}
  38. */
  39. isLoaded: false,
  40. /**
  41. * @type {boolean}
  42. */
  43. isDetailsOpened: false,
  44. /**
  45. * @type {boolean}
  46. */
  47. outsideView: true,
  48. /**
  49. * progress value is rounded to floor
  50. * @type {number}
  51. */
  52. overallProgress: function () {
  53. return Math.floor(this.get('controller.upgradeData.Upgrade.progress_percent'));
  54. }.property('controller.upgradeData.Upgrade.progress_percent'),
  55. /**
  56. * upgrade groups, reversed and PENDING ones are hidden
  57. * @type {Array}
  58. */
  59. upgradeGroups: function () {
  60. if (Em.isNone(this.get('controller.upgradeData.upgradeGroups'))) return [];
  61. var upgradeGroups = this.get('controller.upgradeData.upgradeGroups');
  62. upgradeGroups.reverse();
  63. return upgradeGroups;
  64. }.property('controller.upgradeData.upgradeGroups'),
  65. /**
  66. * currently active group
  67. * @type {object|undefined}
  68. */
  69. activeGroup: function () {
  70. return this.get('upgradeGroups').find(function (item) {
  71. return this.get('activeStatuses').contains(item.get('status'));
  72. }, this);
  73. }.property('upgradeGroups.@each.status'),
  74. /**
  75. * if upgrade group is in progress it should have currently running item
  76. * @type {object|undefined}
  77. */
  78. runningItem: function () {
  79. return this.get('activeGroup.upgradeItems') && this.get('activeGroup.upgradeItems').findProperty('status', 'IN_PROGRESS');
  80. }.property('activeGroup.upgradeItems.@each.status'),
  81. /**
  82. * if upgrade group is failed it should have failed item
  83. * @type {object|undefined}
  84. */
  85. failedItem: function () {
  86. return this.get('activeGroup.upgradeItems') && this.get('activeGroup.upgradeItems').find(function (item) {
  87. return this.get('failedStatuses').contains(item.get('status'));
  88. }, this);
  89. }.property('activeGroup.upgradeItems.@each.status'),
  90. /**
  91. * details of currently active task
  92. * @type {object|undefined}
  93. */
  94. taskDetails: function () {
  95. if (this.get('runningItem')) {
  96. return this.get('runningItem').get('tasks').findProperty('status', 'IN_PROGRESS');
  97. } else if (this.get('failedItem')) {
  98. return this.get('failedItem').get('tasks').find(function (task) {
  99. return this.get('failedStatuses').contains(task.get('status'));
  100. }, this);
  101. }
  102. }.property('failedItem.tasks.@each.status', 'runningItem.tasks.@each.status'),
  103. /**
  104. * indicate whether failed item can be skipped or retried in order to continue Upgrade
  105. * @type {boolean}
  106. */
  107. isHoldingState: function () {
  108. return Boolean(this.get('failedItem.status') && this.get('failedItem.status').contains('HOLDING'));
  109. }.property('failedItem.status'),
  110. /**
  111. * @type {boolean}
  112. */
  113. isManualDone: false,
  114. /**
  115. * @type {boolean}
  116. */
  117. isManualProceedDisabled: function () {
  118. return !this.get('isManualDone');
  119. }.property('isManualDone'),
  120. /**
  121. * if upgrade group is manual it should have manual item
  122. * @type {object|undefined}
  123. */
  124. manualItem: function () {
  125. return this.get('activeGroup.upgradeItems') && this.get('activeGroup.upgradeItems').findProperty('status', 'HOLDING');
  126. }.property('activeGroup.upgradeItems.@each.status'),
  127. /**
  128. * label of Upgrade status
  129. * @type {string}
  130. */
  131. upgradeStatusLabel: function() {
  132. switch (this.get('controller.upgradeData.Upgrade.request_status')) {
  133. case 'QUEUED':
  134. case 'PENDING':
  135. case 'IN_PROGRESS':
  136. return Em.I18n.t('admin.stackUpgrade.state.inProgress');
  137. case 'COMPLETED':
  138. return Em.I18n.t('admin.stackUpgrade.state.completed');
  139. case 'ABORTED':
  140. case 'TIMED_OUT':
  141. case 'FAILED':
  142. case 'HOLDING_FAILED':
  143. case 'HOLDING_TIMED_OUT':
  144. case 'HOLDING':
  145. return Em.I18n.t('admin.stackUpgrade.state.paused');
  146. default:
  147. return ""
  148. }
  149. }.property('controller.upgradeData.Upgrade.request_status'),
  150. /**
  151. * toggle details box
  152. */
  153. toggleDetails: function () {
  154. this.toggleProperty('isDetailsOpened');
  155. },
  156. /**
  157. * start polling upgrade data
  158. */
  159. startPolling: function () {
  160. var self = this;
  161. if (App.get('clusterName')) {
  162. this.get('controller').loadUpgradeData().done(function () {
  163. self.set('isLoaded', true);
  164. });
  165. this.doPolling();
  166. }
  167. }.observes('App.clusterName'),
  168. /**
  169. * start polling upgrade data
  170. */
  171. willInsertElement: function () {
  172. this.startPolling();
  173. },
  174. /**
  175. * stop polling upgrade data
  176. */
  177. willDestroyElement: function () {
  178. clearTimeout(this.get('updateTimer'));
  179. this.set('isLoaded', false);
  180. },
  181. /**
  182. * load upgrade data with time interval
  183. */
  184. doPolling: function () {
  185. var self = this;
  186. this.set('updateTimer', setTimeout(function () {
  187. self.get('controller').loadUpgradeData();
  188. self.doPolling();
  189. }, App.bgOperationsUpdateInterval));
  190. },
  191. /**
  192. * set status to Upgrade item
  193. * @param item
  194. * @param status
  195. */
  196. setUpgradeItemStatus: function(item, status) {
  197. return App.ajax.send({
  198. name: 'admin.upgrade.upgradeItem.setState',
  199. sender: this,
  200. data: {
  201. upgradeId: item.get('request_id'),
  202. itemId: item.get('stage_id'),
  203. groupId: item.get('group_id'),
  204. status: status
  205. }
  206. }).done(function () {
  207. item.set('status', status);
  208. });
  209. },
  210. /**
  211. * set current upgrade item state to FAILED (for HOLDING_FAILED) or TIMED_OUT (for HOLDING_TIMED_OUT)
  212. * in order to ignore fail and continue Upgrade
  213. * @param {object} event
  214. */
  215. continue: function (event) {
  216. this.setUpgradeItemStatus(event.context, event.context.get('status').slice(8));
  217. },
  218. /**
  219. * set current upgrade item state to PENDING in order to retry Upgrade
  220. * @param {object} event
  221. */
  222. retry: function (event) {
  223. this.setUpgradeItemStatus(event.context, 'PENDING');
  224. },
  225. /**
  226. * set current upgrade item state to COMPLETED in order to proceed
  227. * @param {object} event
  228. */
  229. complete: function (event) {
  230. this.setUpgradeItemStatus(event.context, 'COMPLETED');
  231. }
  232. });