decommissionable.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 uiEffects = require('utils/ui_effects');
  20. /**
  21. * Mixin for <code>App.HostComponentView</code>
  22. * Contains code for processing components with allowed decommission
  23. * @type {Em.Mixin}
  24. */
  25. App.Decommissionable = Em.Mixin.create({
  26. /**
  27. * Should be redeclared in views that use this mixin
  28. * @type {String}
  29. */
  30. componentForCheckDecommission: '',
  31. /**
  32. * Received from server object with data about decommission
  33. * @type {Object}
  34. */
  35. decommissionedStatusObject: null,
  36. /**
  37. * Received from server desired_admin_state value
  38. * @type {String}
  39. */
  40. desiredAdminState: null,
  41. /**
  42. * Is component in decommission process right know
  43. * @type {bool}
  44. */
  45. isComponentDecommissioning: null,
  46. /**
  47. * May conponent be decommissioned
  48. * @type {bool}
  49. */
  50. isComponentDecommissionAvailable: null,
  51. /**
  52. * May component be recommissioned
  53. * @type {bool}
  54. */
  55. isComponentRecommissionAvailable: null,
  56. /**
  57. * Recalculated component status based on decommission
  58. * @type {string}
  59. */
  60. statusClass: function () {
  61. //Class when install failed
  62. if (this.get('workStatus') === App.HostComponentStatus.install_failed) {
  63. return 'health-status-color-red icon-cog';
  64. }
  65. //Class when installing
  66. if (this.get('workStatus') === App.HostComponentStatus.installing) {
  67. return 'health-status-color-blue icon-cog';
  68. }
  69. //Class when maintenance
  70. if (this.get('content.passiveState') != "OFF") {
  71. return 'icon-medkit';
  72. }
  73. if (this.get('isComponentRecommissionAvailable') && (this.get('isStart') || this.get('workStatus') == 'INSTALLED')) {
  74. return 'health-status-DEAD-ORANGE';
  75. }
  76. //For all other cases
  77. return 'health-status-' + App.HostComponentStatus.getKeyName(this.get('workStatus'));
  78. }.property('content.passiveState','workStatus', 'isComponentRecommissionAvailable', 'isComponentDecommissioning'),
  79. /**
  80. * Return host component text status
  81. * @type {String}
  82. */
  83. componentTextStatus: function () {
  84. var componentTextStatus = this.get('content.componentTextStatus');
  85. var hostComponent = this.get('hostComponent');
  86. if (hostComponent) {
  87. componentTextStatus = hostComponent.get('componentTextStatus');
  88. if(this.get('isComponentRecommissionAvailable')){
  89. if(this.get('isComponentDecommissioning')){
  90. componentTextStatus = Em.I18n.t('hosts.host.decommissioning');
  91. } else {
  92. componentTextStatus = Em.I18n.t('hosts.host.decommissioned');
  93. }
  94. }
  95. }
  96. return componentTextStatus;
  97. }.property('content.passiveState','workStatus','isComponentRecommissionAvailable','isComponentDecommissioning'),
  98. /**
  99. * For Stopping or Starting states, also for decommissioning
  100. * @type {bool}
  101. */
  102. isInProgress: function () {
  103. return (this.get('workStatus') === App.HostComponentStatus.stopping ||
  104. this.get('workStatus') === App.HostComponentStatus.starting) ||
  105. this.get('isDecommissioning');
  106. }.property('workStatus', 'isDecommissioning'),
  107. /**
  108. * Get desired_admin_state status from server
  109. */
  110. getDesiredAdminState: function(){
  111. return App.ajax.send({
  112. name: 'host.host_component.slave_desired_admin_state',
  113. sender: this,
  114. data: {
  115. hostName: this.get('content.host.hostName'),
  116. componentName: this.get('content.componentName')
  117. },
  118. success: 'getDesiredAdminStateSuccessCallback',
  119. error: 'getDesiredAdminStateErrorCallback'
  120. });
  121. },
  122. /**
  123. * Set received value or null to <code>desiredAdminState</code>
  124. * @param {Object} response
  125. * @returns {String|null}
  126. */
  127. getDesiredAdminStateSuccessCallback: function (response) {
  128. var status = response.HostRoles.desired_admin_state;
  129. if ( status != null) {
  130. this.set('desiredAdminState', status);
  131. return status;
  132. }
  133. return null;
  134. },
  135. /**
  136. * Set null to <code>desiredAdminState</code> if server returns error
  137. * @returns {null}
  138. */
  139. getDesiredAdminStateErrorCallback: function () {
  140. this.set('desiredAdminState', null);
  141. return null;
  142. },
  143. /**
  144. * Get component decommission status from server
  145. * @returns {$.ajax}
  146. */
  147. getDecommissionStatus: function() {
  148. return App.ajax.send({
  149. name: 'host.host_component.decommission_status',
  150. sender: this,
  151. data: {
  152. hostName: this.get('content.host.hostName'),
  153. componentName: this.get('componentForCheckDecommission'),
  154. serviceName: this.get('content.service.serviceName')
  155. },
  156. success: 'getDecommissionStatusSuccessCallback',
  157. error: 'getDecommissionStatusErrorCallback'
  158. });
  159. },
  160. /**
  161. * Set received value or null to <code>decommissionedStatusObject</code>
  162. * @param {Object} response
  163. * @returns {Object|null}
  164. */
  165. getDecommissionStatusSuccessCallback: function (response) {
  166. var statusObject = response.ServiceComponentInfo;
  167. if ( statusObject != null) {
  168. this.set('decommissionedStatusObject', statusObject);
  169. return statusObject;
  170. }
  171. return null;
  172. },
  173. /**
  174. * Set null to <code>decommissionedStatusObject</code> if server returns error
  175. * @returns {null}
  176. */
  177. getDecommissionStatusErrorCallback: function () {
  178. this.set('decommissionedStatusObject', null);
  179. return null;
  180. },
  181. /**
  182. * Do blinking for 1 minute
  183. */
  184. doBlinking: function () {
  185. var workStatus = this.get('workStatus');
  186. var self = this;
  187. var pulsate = [App.HostComponentStatus.starting, App.HostComponentStatus.stopping, App.HostComponentStatus.installing].contains(workStatus);
  188. if (!pulsate) {
  189. var component = this.get('content');
  190. if (component && workStatus != "INSTALLED") {
  191. pulsate = this.get('isDecommissioning');
  192. }
  193. }
  194. if (pulsate && !self.get('isBlinking')) {
  195. self.set('isBlinking', true);
  196. uiEffects.pulsate(self.$('.components-health'), 1000, function () {
  197. self.set('isBlinking', false);
  198. self.doBlinking();
  199. });
  200. }
  201. },
  202. /**
  203. * Start blinking when host component is starting/stopping/decommissioning
  204. */
  205. startBlinking: function () {
  206. this.$('.components-health').stop(true, true);
  207. this.$('.components-health').css({opacity: 1.0});
  208. this.doBlinking();
  209. }.observes('workStatus','isComponentRecommissionAvailable', 'isDecommissioning'),
  210. /**
  211. * Should be redeclared in views that use this mixin
  212. */
  213. loadComponentDecommissionStatus: function() {},
  214. didInsertElement: function() {
  215. this._super();
  216. this.loadComponentDecommissionStatus();
  217. },
  218. /**
  219. * Update Decommission status only one time when component was changed
  220. */
  221. updateDecommissionStatus: function() {
  222. Em.run.once(this, 'loadComponentDecommissionStatus');
  223. }.observes('content.workStatus', 'content.passiveState')
  224. });