decommissionable.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. * Is component in decommission process right know
  33. * @type {bool}
  34. */
  35. isComponentDecommissioning: null,
  36. /**
  37. * May conponent be decommissioned
  38. * @type {bool}
  39. */
  40. isComponentDecommissionAvailable: null,
  41. /**
  42. * May component be recommissioned
  43. * @type {bool}
  44. */
  45. isComponentRecommissionAvailable: null,
  46. /**
  47. * Component with stopped masters can't be docommissioned
  48. * @type {bool}
  49. */
  50. isComponentDecommissionDisable: function() {
  51. var masterComponent = this.get('content.service.hostComponents').findProperty('componentName', this.get('componentForCheckDecommission'));
  52. if (masterComponent && masterComponent.get('workStatus') != App.HostComponentStatus.started) return true;
  53. return this.get('content.service.workStatus') != App.HostComponentStatus.started;
  54. }.property('content.service.workStatus', 'content.service.hostComponents.@each.workStatus'),
  55. /**
  56. * @override App.HostComponentView.isRestartableComponent
  57. */
  58. isRestartableComponent: function() {
  59. return this.get('isComponentDecommissionAvailable') && App.get('components.restartable').contains(this.get('content.componentName'));
  60. }.property('isComponentDecommissionAvailable'),
  61. /**
  62. * Tooltip message shows if decommission/recommission is disabled
  63. * when masters for current component is down
  64. */
  65. decommissionTooltipMessage: function() {
  66. if (this.get('isComponentDecommissionDisable') && (this.get('isComponentRecommissionAvailable') || this.get('isComponentDecommissionAvailable'))) {
  67. var decom = this.get('isComponentRecommissionAvailable') ? Em.I18n.t('common.recommission') : Em.I18n.t('common.decommission');
  68. return Em.I18n.t('hosts.decommission.tooltip.warning').format(decom, App.format.role(this.get('componentForCheckDecommission')));
  69. }
  70. }.property('isComponentDecommissionDisable', 'isComponentRecommissionAvailable', 'isComponentDecommissionAvailable', 'componentForCheckDecommission'),
  71. /**
  72. * Recalculated component status based on decommission
  73. * @type {string}
  74. */
  75. statusClass: function () {
  76. //Class when install failed
  77. if (this.get('workStatus') === App.HostComponentStatus.install_failed) {
  78. return 'health-status-color-red icon-cog';
  79. }
  80. //Class when installing
  81. if (this.get('workStatus') === App.HostComponentStatus.installing) {
  82. return 'health-status-color-blue icon-cog';
  83. }
  84. if (this.get('isComponentRecommissionAvailable') && (this.get('isStart') || this.get('workStatus') == 'INSTALLED')) {
  85. return 'health-status-DEAD-ORANGE';
  86. }
  87. //For all other cases
  88. return 'health-status-' + App.HostComponentStatus.getKeyName(this.get('workStatus'));
  89. }.property('workStatus', 'isComponentRecommissionAvailable', 'isComponentDecommissioning'),
  90. /**
  91. * Return host component text status
  92. * @type {String}
  93. */
  94. componentTextStatus: function () {
  95. var componentTextStatus = this.get('content.componentTextStatus');
  96. var hostComponent = this.get('hostComponent');
  97. if (hostComponent) {
  98. componentTextStatus = hostComponent.get('componentTextStatus');
  99. if(this.get('isComponentRecommissionAvailable')){
  100. if(this.get('isComponentDecommissioning')){
  101. componentTextStatus = Em.I18n.t('hosts.host.decommissioning');
  102. } else {
  103. componentTextStatus = Em.I18n.t('hosts.host.decommissioned');
  104. }
  105. }
  106. }
  107. return componentTextStatus;
  108. }.property('workStatus','isComponentRecommissionAvailable','isComponentDecommissioning'),
  109. /**
  110. * For Stopping or Starting states, also for decommissioning
  111. * @type {bool}
  112. */
  113. isInProgress: function () {
  114. return (this.get('workStatus') === App.HostComponentStatus.stopping ||
  115. this.get('workStatus') === App.HostComponentStatus.starting) ||
  116. this.get('isDecommissioning');
  117. }.property('workStatus', 'isDecommissioning'),
  118. /**
  119. * load Recommission/Decommission status of component
  120. */
  121. loadComponentDecommissionStatus: function () {
  122. return this.getDesiredAdminState();
  123. },
  124. /**
  125. * Get desired_admin_state status from server
  126. */
  127. getDesiredAdminState: function(){
  128. return App.ajax.send({
  129. name: 'host.host_component.slave_desired_admin_state',
  130. sender: this,
  131. data: {
  132. hostName: this.get('content.hostName'),
  133. componentName: this.get('content.componentName')
  134. },
  135. success: 'getDesiredAdminStateSuccessCallback',
  136. error: 'getDesiredAdminStateErrorCallback'
  137. });
  138. },
  139. /**
  140. * pass received value or null to <code>setDesiredAdminState</code>
  141. * @param {Object} response
  142. * @returns {String|null}
  143. */
  144. getDesiredAdminStateSuccessCallback: function (response) {
  145. var status = response.HostRoles.desired_admin_state;
  146. if (status != null) {
  147. this.setDesiredAdminState(status);
  148. return status;
  149. }
  150. return null;
  151. },
  152. /**
  153. * error callback of <code>getDesiredAdminState</code>
  154. */
  155. getDesiredAdminStateErrorCallback: Em.K,
  156. /**
  157. * compute decommission state by desiredAdminState
  158. * @param {Object} status
  159. */
  160. setDesiredAdminState: Em.K,
  161. /**
  162. * Get component decommission status from server
  163. * @returns {$.ajax}
  164. */
  165. getDecommissionStatus: function() {
  166. return App.ajax.send({
  167. name: 'host.host_component.decommission_status',
  168. sender: this,
  169. data: {
  170. hostName: this.get('content.hostName'),
  171. componentName: this.get('componentForCheckDecommission'),
  172. serviceName: this.get('content.service.serviceName')
  173. },
  174. success: 'getDecommissionStatusSuccessCallback',
  175. error: 'getDecommissionStatusErrorCallback'
  176. });
  177. },
  178. /**
  179. * pass received value or null to <code>setDecommissionStatus</code>
  180. * @param {Object} response
  181. * @returns {Object|null}
  182. */
  183. getDecommissionStatusSuccessCallback: function (response) {
  184. var statusObject = response.ServiceComponentInfo;
  185. if ( statusObject != null) {
  186. statusObject.component_state = response.host_components[0].HostRoles.state;
  187. this.setDecommissionStatus(statusObject);
  188. return statusObject;
  189. }
  190. return null;
  191. },
  192. /**
  193. * Set null to <code>decommissionedStatusObject</code> if server returns error
  194. * @returns {null}
  195. */
  196. getDecommissionStatusErrorCallback: Em.K,
  197. /**
  198. * compute decommission state by component info
  199. * @param {Object} status
  200. */
  201. setDecommissionStatus: Em.K,
  202. /**
  203. * set decommission and recommission flags according to status
  204. * @param status
  205. */
  206. setStatusAs: function (status) {
  207. switch (status) {
  208. case "INSERVICE":
  209. this.set('isComponentRecommissionAvailable', false);
  210. this.set('isComponentDecommissioning', false);
  211. this.set('isComponentDecommissionAvailable', this.get('isStart'));
  212. break;
  213. case "DECOMMISSIONING":
  214. this.set('isComponentRecommissionAvailable', true);
  215. this.set('isComponentDecommissioning', true);
  216. this.set('isComponentDecommissionAvailable', false);
  217. break;
  218. case "DECOMMISSIONED":
  219. this.set('isComponentRecommissionAvailable', true);
  220. this.set('isComponentDecommissioning', false);
  221. this.set('isComponentDecommissionAvailable', false);
  222. break;
  223. case "RS_DECOMMISSIONED":
  224. this.set('isComponentRecommissionAvailable', true);
  225. this.set('isComponentDecommissioning', this.get('isStart'));
  226. this.set('isComponentDecommissionAvailable', false);
  227. break;
  228. }
  229. },
  230. /**
  231. * Do blinking for 1 minute
  232. */
  233. doBlinking: function () {
  234. var workStatus = this.get('workStatus');
  235. var self = this;
  236. var pulsate = [App.HostComponentStatus.starting, App.HostComponentStatus.stopping, App.HostComponentStatus.installing].contains(workStatus);
  237. if (!pulsate) {
  238. var component = this.get('content');
  239. if (component && workStatus != "INSTALLED") {
  240. pulsate = this.get('isDecommissioning');
  241. }
  242. }
  243. if (pulsate && !self.get('isBlinking')) {
  244. self.set('isBlinking', true);
  245. uiEffects.pulsate(self.$('.components-health'), 1000, function () {
  246. self.set('isBlinking', false);
  247. self.doBlinking();
  248. });
  249. }
  250. },
  251. /**
  252. * Start blinking when host component is starting/stopping/decommissioning
  253. */
  254. startBlinking: function () {
  255. this.$('.components-health').stop(true, true);
  256. this.$('.components-health').css({opacity: 1.0});
  257. this.doBlinking();
  258. }.observes('workStatus','isComponentRecommissionAvailable', 'isDecommissioning'),
  259. didInsertElement: function() {
  260. this._super();
  261. this.loadComponentDecommissionStatus();
  262. },
  263. /**
  264. * Update Decommission status only one time when component was changed
  265. */
  266. updateDecommissionStatus: function() {
  267. Em.run.once(this, 'loadComponentDecommissionStatus');
  268. }.observes('content.workStatus', 'content.passiveState'),
  269. decommissionView: Em.View.extend({
  270. templateName: require('templates/main/host/decommission'),
  271. text: function() {
  272. return this.get('parentView.isComponentDecommissionAvailable') ? Em.I18n.t('common.decommission') : Em.I18n.t('common.recommission');
  273. }.property('parentView.isComponentDecommissionAvailable'),
  274. didInsertElement: function() {
  275. this._super();
  276. App.tooltip($("[rel='decommissionTooltip']"));
  277. },
  278. click: function() {
  279. if (!this.get('parentView.isComponentDecommissionDisable')) {
  280. if (this.get('parentView.isComponentDecommissionAvailable')) {
  281. this.get('controller').decommission(this.get('parentView.content'));
  282. } else {
  283. this.get('controller').recommission(this.get('parentView.content'));
  284. }
  285. }
  286. }
  287. })
  288. });