host_component.js 6.4 KB

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