host_component_view.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. App.HostComponentView = Em.View.extend({
  21. templateName: require('templates/main/host/details/host_component'),
  22. /**
  23. * @type {App.HostComponent}
  24. */
  25. content: null,
  26. /**
  27. * @type {App.HostComponent}
  28. */
  29. hostComponent: function () {
  30. var hostComponent = null;
  31. var serviceComponent = this.get('content');
  32. var host = App.router.get('mainHostDetailsController.content');
  33. if (host) {
  34. hostComponent = host.get('hostComponents').findProperty('componentName', serviceComponent.get('componentName'));
  35. }
  36. return hostComponent;
  37. }.property('content', 'App.router.mainHostDetailsController.content'),
  38. /**
  39. * @type {String}
  40. */
  41. workStatus: function () {
  42. var workStatus = this.get('content.workStatus');
  43. var hostComponent = this.get('hostComponent');
  44. if (hostComponent) {
  45. workStatus = hostComponent.get('workStatus');
  46. }
  47. return workStatus;
  48. }.property('content.workStatus', 'hostComponent.workStatus'),
  49. /**
  50. * Return host component text status
  51. * @type {String}
  52. */
  53. componentTextStatus: function () {
  54. var componentTextStatus = this.get('content.componentTextStatus');
  55. var hostComponent = this.get('hostComponent');
  56. if (hostComponent) {
  57. componentTextStatus = hostComponent.get('componentTextStatus');
  58. }
  59. return componentTextStatus;
  60. }.property('content.passiveState','workStatus'),
  61. /**
  62. * CSS-class for host component status
  63. * @type {String}
  64. */
  65. statusClass: function () {
  66. //Class when install failed
  67. if (this.get('workStatus') === App.HostComponentStatus.install_failed) {
  68. return 'health-status-color-red icon-cog';
  69. }
  70. //Class when installing
  71. if (this.get('workStatus') === App.HostComponentStatus.installing) {
  72. return 'health-status-color-blue icon-cog';
  73. }
  74. //For all other cases
  75. return 'health-status-' + App.HostComponentStatus.getKeyName(this.get('workStatus'));
  76. }.property('workStatus'),
  77. /**
  78. * CSS-icon-class for host component status
  79. * @type {String}
  80. */
  81. statusIconClass: function () {
  82. return Em.getWithDefault({
  83. 'health-status-started': App.healthIconClassGreen,
  84. 'health-status-starting': App.healthIconClassGreen,
  85. 'health-status-installed': App.healthIconClassRed,
  86. 'health-status-stopping': App.healthIconClassRed,
  87. 'health-status-unknown': App.healthIconClassYellow,
  88. 'health-status-DEAD-ORANGE': App.healthIconClassOrange
  89. }, this.get('statusClass'), '');
  90. }.property('statusClass'),
  91. /**
  92. * CSS-class for disabling drop-down menu with list of host component actions
  93. * Disabled if host's <code>healthClass</code> is health-status-DEAD-YELLOW (lost heartbeat)
  94. * @type {String}
  95. */
  96. disabled: function () {
  97. return (this.get('parentView.content.healthClass') === "health-status-DEAD-YELLOW") ? 'disabled' : '';
  98. }.property('parentView.content.healthClass'),
  99. /**
  100. * For Upgrade failed state
  101. * @type {bool}
  102. */
  103. isUpgradeFailed: function () {
  104. return App.HostComponentStatus.getKeyName(this.get('workStatus')) === "upgrade_failed";
  105. }.property("workStatus"),
  106. /**
  107. * For Install failed state
  108. * @type {bool}
  109. */
  110. isInstallFailed: function () {
  111. return App.HostComponentStatus.getKeyName(this.get('workStatus')) === "install_failed";
  112. }.property("workStatus"),
  113. /**
  114. * For Started and Starting states
  115. * @type {bool}
  116. */
  117. isStart: function () {
  118. return [App.HostComponentStatus.started, App.HostComponentStatus.starting].contains(this.get('workStatus'));
  119. }.property('workStatus'),
  120. /**
  121. * For Installed state
  122. * @type {bool}
  123. */
  124. isStop: function () {
  125. return (this.get('workStatus') == App.HostComponentStatus.stopped);
  126. }.property('workStatus'),
  127. /**
  128. * For Installing state
  129. * @type {bool}
  130. */
  131. isInstalling: function () {
  132. return (this.get('workStatus') == App.HostComponentStatus.installing);
  133. }.property('workStatus'),
  134. /**
  135. * For Init state
  136. * @type {bool}
  137. */
  138. isInit: function() {
  139. return this.get('workStatus') == App.HostComponentStatus.init;
  140. }.property('workStatus'),
  141. /**
  142. * No action available while component is starting/stopping/unknown
  143. * @type {String}
  144. */
  145. noActionAvailable: function () {
  146. var workStatus = this.get('workStatus');
  147. return [App.HostComponentStatus.starting, App.HostComponentStatus.stopping,
  148. App.HostComponentStatus.unknown, App.HostComponentStatus.disabled].contains(workStatus) ? "hidden" : '';
  149. }.property('workStatus'),
  150. /**
  151. * For Stopping or Starting states
  152. * @type {bool}
  153. */
  154. isInProgress: function () {
  155. return (this.get('workStatus') === App.HostComponentStatus.stopping ||
  156. this.get('workStatus') === App.HostComponentStatus.starting);
  157. }.property('workStatus'),
  158. /**
  159. * For OFF <code>passiveState</code> of host component
  160. * @type {bool}
  161. */
  162. isActive: function () {
  163. return (this.get('content.passiveState') == "OFF");
  164. }.property('content.passiveState'),
  165. /**
  166. * For PASSIVE <code>passiveState</code> of host or service
  167. * @type {bool}
  168. */
  169. isImplied: function() {
  170. return (this.get('parentView.content.passiveState') === 'ON' || this.get('content.service.passiveState') === 'ON');
  171. }.property('parentView.content.passiveState', 'content.service.passiveState'),
  172. /**
  173. * Shows whether we need to show Delete button
  174. * @type {bool}
  175. */
  176. isDeletableComponent: function () {
  177. return App.get('components.deletable').contains(this.get('content.componentName'));
  178. }.property('content'),
  179. /**
  180. * Host component with some <code>workStatus</code> can't be deleted (so, disable such action in the dropdown list)
  181. * @type {bool}
  182. */
  183. isDeleteComponentDisabled: function () {
  184. return !(this.get('isComponentRecommissionAvailable') || [App.HostComponentStatus.stopped, App.HostComponentStatus.unknown, App.HostComponentStatus.install_failed, App.HostComponentStatus.upgrade_failed, App.HostComponentStatus.init].contains(this.get('workStatus')));
  185. }.property('workStatus','isComponentRecommissionAvailable'),
  186. /**
  187. * Check if component may be reassinged to another host
  188. * @type {bool}
  189. */
  190. isReassignable: function () {
  191. return App.supports.reassignMaster && App.get('components.reassignable').contains(this.get('content.componentName')) && App.Host.find().content.length > 1;
  192. }.property('content.componentName'),
  193. /**
  194. * Check if component is restartable
  195. * @type {bool}
  196. */
  197. isRestartableComponent: function() {
  198. return App.get('components.restartable').contains(this.get('content.componentName'));
  199. }.property('content'),
  200. /**
  201. * Host component with some <code>workStatus</code> can't be restarted (so, disable such action in the dropdown list)
  202. * @type {bool}
  203. */
  204. isRestartComponentDisabled: function() {
  205. return ![App.HostComponentStatus.started].contains(this.get('workStatus'));
  206. }.property('workStatus'),
  207. /**
  208. * Check if component configs can be refreshed
  209. * @type {bool}
  210. */
  211. isRefreshConfigsAllowed: function() {
  212. return App.get('components.refreshConfigsAllowed').contains(this.get('content.componentName'));
  213. }.property('content'),
  214. didInsertElement: function () {
  215. App.tooltip($('[rel=componentHealthTooltip]'));
  216. App.tooltip($('[rel=passiveTooltip]'));
  217. if (this.get('isInProgress')) {
  218. this.doBlinking();
  219. }
  220. },
  221. /**
  222. * Do blinking for 1 minute
  223. */
  224. doBlinking: function () {
  225. var workStatus = this.get('workStatus');
  226. var self = this;
  227. var pulsate = [ App.HostComponentStatus.starting, App.HostComponentStatus.stopping, App.HostComponentStatus.installing].contains(workStatus);
  228. if (pulsate && !self.get('isBlinking')) {
  229. self.set('isBlinking', true);
  230. uiEffects.pulsate(self.$('.components-health'), 1000, function () {
  231. self.set('isBlinking', false);
  232. self.doBlinking();
  233. });
  234. }
  235. },
  236. /**
  237. * Start blinking when host component is starting/stopping
  238. */
  239. startBlinking: function () {
  240. this.$('.components-health').stop(true, true);
  241. this.$('.components-health').css({opacity: 1.0});
  242. this.doBlinking();
  243. }.observes('workStatus')
  244. });