host_component_view.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. * Returns message for health tooltip
  63. * in addition to workStatus it also displays passive state of component
  64. * @type {String}
  65. */
  66. componentStatusTooltip: function() {
  67. if (this.get('content.passiveState') != 'OFF') {
  68. return Em.I18n.t('hosts.component.passive.short.mode');
  69. } else {
  70. return this.get('componentTextStatus');
  71. }
  72. }.property('componentTextStatus','content.passiveState'),
  73. /**
  74. * @type {String}
  75. */
  76. passiveImpliedTextStatus: function() {
  77. if(this.get('parentView.content.passiveState') === 'ON') {
  78. return Em.I18n.t('hosts.component.passive.implied.host.mode.tooltip');
  79. }
  80. else
  81. if(this.get('content.service.passiveState') === 'ON') {
  82. return Em.I18n.t('hosts.component.passive.implied.service.mode.tooltip').format(this.get('content.service.serviceName'));
  83. }
  84. return '';
  85. }.property('content.passiveState','parentView.content.passiveState'),
  86. /**
  87. * CSS-class for host component status
  88. * @type {String}
  89. */
  90. statusClass: function () {
  91. //Class when install failed
  92. if (this.get('workStatus') === App.HostComponentStatus.install_failed) {
  93. return 'health-status-color-red icon-cog';
  94. }
  95. //Class when installing
  96. if (this.get('workStatus') === App.HostComponentStatus.installing) {
  97. return 'health-status-color-blue icon-cog';
  98. }
  99. //Class when maintenance
  100. if (this.get('content.passiveState') != "OFF") {
  101. return 'icon-medkit';
  102. }
  103. //For all other cases
  104. return 'health-status-' + App.HostComponentStatus.getKeyName(this.get('workStatus'));
  105. }.property('content.passiveState','workStatus'),
  106. /**
  107. * CSS-class for disabling drop-down menu with list of host component actions
  108. * Disabled if host's <code>healthClass</code> is health-status-DEAD-YELLOW (lost heartbeat)
  109. * @type {String}
  110. */
  111. disabled: function () {
  112. return (this.get('parentView.content.healthClass') === "health-status-DEAD-YELLOW") ? 'disabled' : '';
  113. }.property('parentView.content.healthClass'),
  114. /**
  115. * For Upgrade failed state
  116. * @type {bool}
  117. */
  118. isUpgradeFailed: function () {
  119. return App.HostComponentStatus.getKeyName(this.get('workStatus')) === "upgrade_failed";
  120. }.property("workStatus"),
  121. /**
  122. * For Install failed state
  123. * @type {bool}
  124. */
  125. isInstallFailed: function () {
  126. return App.HostComponentStatus.getKeyName(this.get('workStatus')) === "install_failed";
  127. }.property("workStatus"),
  128. /**
  129. * For Started and Starting states
  130. * @type {bool}
  131. */
  132. isStart: function () {
  133. return (this.get('workStatus') == App.HostComponentStatus.started || this.get('workStatus') == App.HostComponentStatus.starting);
  134. }.property('workStatus'),
  135. /**
  136. * For Installed state
  137. * @type {bool}
  138. */
  139. isStop: function () {
  140. return (this.get('workStatus') == App.HostComponentStatus.stopped);
  141. }.property('workStatus'),
  142. /**
  143. * For Installing state
  144. * @type {bool}
  145. */
  146. isInstalling: function () {
  147. return (this.get('workStatus') == App.HostComponentStatus.installing);
  148. }.property('workStatus'),
  149. /**
  150. * No action available while component is starting/stopping/unknown
  151. * @type {String}
  152. */
  153. noActionAvailable: function () {
  154. var workStatus = this.get('workStatus');
  155. if ([App.HostComponentStatus.starting, App.HostComponentStatus.stopping, App.HostComponentStatus.unknown].contains(workStatus)) {
  156. return "hidden";
  157. }else{
  158. return "";
  159. }
  160. }.property('workStatus'),
  161. /**
  162. * For Stopping or Starting states
  163. * @type {bool}
  164. */
  165. isInProgress: function () {
  166. return (this.get('workStatus') === App.HostComponentStatus.stopping ||
  167. this.get('workStatus') === App.HostComponentStatus.starting);
  168. }.property('workStatus'),
  169. /**
  170. * For OFF <code>passiveState</code> of host component
  171. * @type {bool}
  172. */
  173. isActive: function () {
  174. return (this.get('content.passiveState') == "OFF");
  175. }.property('content.passiveState'),
  176. /**
  177. * For PASSIVE <code>passiveState</code> of host or service
  178. * @type {bool}
  179. */
  180. isImplied: function() {
  181. return (this.get('parentView.content.passiveState') === 'ON' || this.get('content.service.passiveState') === 'ON');
  182. }.property('parentView.content.passiveState', 'content.service.passiveState'),
  183. /**
  184. * Shows whether we need to show Delete button
  185. * @type {bool}
  186. */
  187. isDeletableComponent: function () {
  188. return App.get('components.deletable').contains(this.get('content.componentName'));
  189. }.property('content'),
  190. /**
  191. * Host component with some <code>workStatus</code> can't be deleted (so, disable such action in the dropdown list)
  192. * @type {bool}
  193. */
  194. isDeleteComponentDisabled: function () {
  195. return ![App.HostComponentStatus.stopped, App.HostComponentStatus.unknown, App.HostComponentStatus.install_failed, App.HostComponentStatus.upgrade_failed].contains(this.get('workStatus'));
  196. }.property('workStatus'),
  197. /**
  198. * Check if component may be reassinged to another host
  199. * @type {bool}
  200. */
  201. isReassignable: function () {
  202. return App.supports.reassignMaster && App.get('components.reassignable').contains(this.get('content.componentName')) && App.Host.find().content.length > 1;
  203. }.property('content.componentName'),
  204. /**
  205. * Check if component is restartable
  206. * @type {bool}
  207. */
  208. isRestartableComponent: function() {
  209. return App.get('components.restartable').contains(this.get('content.componentName'));
  210. }.property('content'),
  211. /**
  212. * Host component with some <code>workStatus</code> can't be restarted (so, disable such action in the dropdown list)
  213. * @type {bool}
  214. */
  215. isRestartComponentDisabled: function() {
  216. return ![App.HostComponentStatus.started].contains(this.get('workStatus'));
  217. }.property('workStatus'),
  218. didInsertElement: function () {
  219. App.tooltip($('[rel=componentHealthTooltip]'));
  220. App.tooltip($('[rel=passiveTooltip]'));
  221. if (this.get('isInProgress')) {
  222. this.doBlinking();
  223. }
  224. },
  225. /**
  226. * Do blinking for 1 minute
  227. */
  228. doBlinking: function () {
  229. var workStatus = this.get('workStatus');
  230. var self = this;
  231. var pulsate = [ App.HostComponentStatus.starting, App.HostComponentStatus.stopping, App.HostComponentStatus.installing].contains(workStatus);
  232. if (pulsate && !self.get('isBlinking')) {
  233. self.set('isBlinking', true);
  234. uiEffects.pulsate(self.$('.components-health'), 1000, function () {
  235. self.set('isBlinking', false);
  236. self.doBlinking();
  237. });
  238. }
  239. },
  240. /**
  241. * Start blinking when host component is starting/stopping
  242. */
  243. startBlinking: function () {
  244. this.$('.components-health').stop(true, true);
  245. this.$('.components-health').css({opacity: 1.0});
  246. this.doBlinking();
  247. }.observes('workStatus')
  248. });