host_component.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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.HostComponent = DS.Model.extend({
  20. workStatus: DS.attr('string'),
  21. passiveState: DS.attr('string'),
  22. componentName: DS.attr('string'),
  23. haStatus: DS.attr('string'),
  24. displayNameAdvanced: DS.attr('string'),
  25. staleConfigs: DS.attr('boolean'),
  26. host: DS.belongsTo('App.Host'),
  27. hostName: DS.attr('string'),
  28. service: DS.belongsTo('App.Service'),
  29. adminState: DS.attr('string'),
  30. /**
  31. * Determine if component is client
  32. * @returns {bool}
  33. */
  34. isClient: function () {
  35. return App.get('components.clients').contains(this.get('componentName'));
  36. }.property('componentName'),
  37. /**
  38. * Determine if component is running now
  39. * Based on <code>workStatus</code>
  40. * @returns {bool}
  41. */
  42. isRunning: function () {
  43. return (this.get('workStatus') == 'STARTED' || this.get('workStatus') == 'STARTING');
  44. }.property('workStatus'),
  45. /**
  46. * Formatted <code>componentName</code>
  47. * @returns {String}
  48. */
  49. displayName: function () {
  50. return App.format.role(this.get('componentName'));
  51. }.property('componentName'),
  52. /**
  53. * Determine if component is master
  54. * @returns {bool}
  55. */
  56. isMaster: function () {
  57. return App.get('components.masters').contains(this.get('componentName'));
  58. }.property('componentName', 'App.components.masters'),
  59. /**
  60. * Determine if component is slave
  61. * @returns {bool}
  62. */
  63. isSlave: function () {
  64. return App.get('components.slaves').contains(this.get('componentName'));
  65. }.property('componentName'),
  66. /**
  67. * Only certain components can be deleted.
  68. * They include some from master components,
  69. * some from slave components, and rest from
  70. * client components.
  71. * @returns {bool}
  72. */
  73. isDeletable: function () {
  74. return App.get('components.deletable').contains(this.get('componentName'));
  75. }.property('componentName'),
  76. /**
  77. * A host-component is decommissioning when it is in HDFS service's list of
  78. * decomNodes.
  79. * @returns {bool}
  80. */
  81. isDecommissioning: function () {
  82. var decommissioning = false;
  83. var hostName = this.get('hostName');
  84. var componentName = this.get('componentName');
  85. var hdfsSvc = App.HDFSService.find().objectAt(0);
  86. if (componentName === 'DATANODE' && hdfsSvc) {
  87. var decomNodes = hdfsSvc.get('decommissionDataNodes');
  88. var decomNode = decomNodes != null ? decomNodes.findProperty("hostName", hostName) : null;
  89. decommissioning = decomNode != null;
  90. }
  91. return decommissioning;
  92. }.property('componentName', 'hostName', 'App.router.clusterController.isLoaded', 'App.router.updateController.isUpdated'),
  93. /**
  94. * User friendly host component status
  95. * @returns {String}
  96. */
  97. isActive: function () {
  98. return (this.get('passiveState') == 'OFF');
  99. }.property('passiveState'),
  100. passiveTooltip: function () {
  101. if (!this.get('isActive')) {
  102. return Em.I18n.t('hosts.component.passive.mode');
  103. }
  104. }.property('isActive'),
  105. statusClass: function () {
  106. return this.get('isActive') ? this.get('workStatus') : 'icon-medkit';
  107. }.property('workStatus', 'isActive'),
  108. statusIconClass: function () {
  109. switch (this.get('statusClass')) {
  110. case 'STARTED':
  111. case 'STARTING':
  112. return App.healthIconClassGreen;
  113. break;
  114. case 'INSTALLED':
  115. case 'STOPPING':
  116. return App.healthIconClassRed;
  117. break;
  118. case 'UNKNOWN':
  119. return App.healthIconClassYellow;
  120. break;
  121. default:
  122. return "";
  123. break;
  124. }
  125. }.property('statusClass'),
  126. componentTextStatus: function () {
  127. return App.HostComponentStatus.getTextStatus(this.get("workStatus"));
  128. }.property('workStatus', 'isDecommissioning')
  129. });
  130. App.HostComponent.FIXTURES = [];
  131. App.HostComponentStatus = {
  132. started: "STARTED",
  133. starting: "STARTING",
  134. stopped: "INSTALLED",
  135. stopping: "STOPPING",
  136. install_failed: "INSTALL_FAILED",
  137. installing: "INSTALLING",
  138. upgrade_failed: "UPGRADE_FAILED",
  139. unknown: "UNKNOWN",
  140. disabled: "DISABLED",
  141. init: "INIT",
  142. /**
  143. * Get host component status in "machine" format
  144. * @param {String} value
  145. * @returns {String}
  146. */
  147. getKeyName: function (value) {
  148. switch (value) {
  149. case this.started:
  150. return 'started';
  151. case this.starting:
  152. return 'starting';
  153. case this.stopped:
  154. return 'installed';
  155. case this.stopping:
  156. return 'stopping';
  157. case this.install_failed:
  158. return 'install_failed';
  159. case this.installing:
  160. return 'installing';
  161. case this.upgrade_failed:
  162. return 'upgrade_failed';
  163. case this.disabled:
  164. case this.unknown:
  165. return 'unknown';
  166. }
  167. return 'unknown';
  168. },
  169. /**
  170. * Get user-friendly host component status
  171. * @param {String} value
  172. * @returns {String}
  173. */
  174. getTextStatus: function (value) {
  175. switch (value) {
  176. case this.installing:
  177. return 'Installing...';
  178. case this.install_failed:
  179. return 'Install Failed';
  180. case this.stopped:
  181. return 'Stopped';
  182. case this.started:
  183. return 'Started';
  184. case this.starting:
  185. return 'Starting...';
  186. case this.stopping:
  187. return 'Stopping...';
  188. case this.unknown:
  189. return 'Heartbeat Lost';
  190. case this.upgrade_failed:
  191. return 'Upgrade Failed';
  192. case this.disabled:
  193. return 'Disabled';
  194. case this.init:
  195. return 'Install Pending...';
  196. }
  197. return 'Unknown';
  198. },
  199. /**
  200. * Get list of possible <code>App.HostComponent</code> statuses
  201. * @returns {String[]}
  202. */
  203. getStatusesList: function () {
  204. var ret = [];
  205. for (var st in this) {
  206. if (this.hasOwnProperty(st) && Em.typeOf(this[st]) == 'string') {
  207. ret.push(this[st]);
  208. }
  209. }
  210. return ret;
  211. }
  212. };