upgrade_group_view.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.upgradeGroupView = Em.View.extend({
  20. templateName: require('templates/main/admin/stack_upgrade/upgrade_group'),
  21. /**
  22. * @type {boolean}
  23. */
  24. isManualDone: false,
  25. /**
  26. * @type {Array}
  27. */
  28. failedStatuses: ['HOLDING_FAILED', 'HOLDING_TIMED_OUT', 'FAILED', 'TIMED_OUT'],
  29. /**
  30. * progress info is a box that show running UpgradeItem
  31. * @type {boolean}
  32. */
  33. showProgressInfo: function () {
  34. return Boolean(this.get('content.isRunning') && this.get('runningItem'));
  35. }.property('content.isRunning', 'runningItem'),
  36. /**
  37. * @type {boolean}
  38. */
  39. isManualProceedDisabled: function () {
  40. return !this.get('isManualDone');
  41. }.property('isManualDone'),
  42. /**
  43. * @type {boolean}
  44. */
  45. showFailedInfo: function () {
  46. return Boolean(this.get('failedStatuses').contains(this.get('content.status')) && this.get('failedItem'));
  47. }.property('content.status', 'failedItem'),
  48. /**
  49. * if upgrade group is in progress it should have currently running item
  50. * @type {object|undefined}
  51. */
  52. runningItem: function () {
  53. return this.get('content.upgradeItems').findProperty('status', 'IN_PROGRESS');
  54. }.property('content.upgradeItems.@each.status'),
  55. /**
  56. * if upgrade group is failed it should have failed item
  57. * @type {object|undefined}
  58. */
  59. failedItem: function () {
  60. return this.get('content.upgradeItems').find(function (item) {
  61. return this.get('failedStatuses').contains(item.get('status'));
  62. }, this);
  63. }.property('content.upgradeItems.@each.status'),
  64. /**
  65. * if upgrade group is manual it should have manual item
  66. * @type {object|undefined}
  67. */
  68. manualItem: function () {
  69. return this.get('content.upgradeItems').findProperty('status', 'HOLDING');
  70. }.property('content.upgradeItems.@each.status'),
  71. /**
  72. * @type {boolean}
  73. */
  74. isManualOpened: function () {
  75. return Boolean(this.get('manualItem'));
  76. }.property('manualItem'),
  77. /**
  78. * indicate whether failed item can be skipped or retried in order to continue Upgrade
  79. * @type {boolean}
  80. */
  81. isHoldingState: function () {
  82. return Boolean(this.get('failedItem.status') && this.get('failedItem.status').contains('HOLDING'));
  83. }.property('failedItem.status'),
  84. /**
  85. * set status to Upgrade item
  86. * @param item
  87. * @param status
  88. */
  89. setUpgradeItemStatus: function(item, status) {
  90. App.ajax.send({
  91. name: 'admin.upgrade.upgradeItem.setState',
  92. sender: this,
  93. data: {
  94. upgradeId: item.get('request_id'),
  95. itemId: item.get('stage_id'),
  96. groupId: item.get('group_id'),
  97. status: status
  98. }
  99. });
  100. },
  101. /**
  102. * set current upgrade item state to FAILED (for HOLDING_FAILED) or TIMED_OUT (for HOLDING_TIMED_OUT)
  103. * in order to ignore fail and continue Upgrade
  104. * @param {object} event
  105. */
  106. continue: function (event) {
  107. this.setUpgradeItemStatus(event.context, event.context.get('status').slice(8));
  108. },
  109. /**
  110. * set current upgrade item state to PENDING in order to retry Upgrade
  111. * @param {object} event
  112. */
  113. retry: function (event) {
  114. this.setUpgradeItemStatus(event.context, 'PENDING');
  115. },
  116. /**
  117. * set current upgrade item state to COMPLETED in order to proceed
  118. * @param {object} event
  119. */
  120. complete: function (event) {
  121. this.setUpgradeItemStatus(event.context, 'COMPLETED');
  122. },
  123. /**
  124. * Only one UpgradeGroup or UpgradeItem could be expanded at a time
  125. * @param {object} event
  126. */
  127. toggleExpanded: function (event) {
  128. var isExpanded = event.context.get('isExpanded');
  129. event.contexts[1].filterProperty('isExpanded').forEach(function (item) {
  130. this.collapseLowerLevels(item);
  131. item.set('isExpanded', false);
  132. }, this);
  133. this.collapseLowerLevels(event.context);
  134. event.context.set('isExpanded', !isExpanded);
  135. },
  136. /**
  137. * collapse sub-entities of current
  138. * @param {App.upgradeEntity} entity
  139. */
  140. collapseLowerLevels: function (entity) {
  141. if (entity.get('isExpanded')) {
  142. if (entity.type === 'ITEM') {
  143. entity.get('tasks').setEach('isExpanded', false);
  144. } else if (entity.type === 'GROUP') {
  145. entity.get('upgradeItems').forEach(function (item) {
  146. this.collapseLowerLevels(item);
  147. item.set('isExpanded', false);
  148. }, this);
  149. }
  150. }
  151. }
  152. });