step10_controller.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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.WizardStep10Controller = Em.Controller.extend({
  20. /**
  21. * List of data about installed cluster components (hosts, services etc)
  22. * @type {Ember.Object[]}
  23. */
  24. clusterInfo: [],
  25. /**
  26. * is Add service wizard the ongoing wizard
  27. * @type {bool}
  28. */
  29. isAddServiceWizard: Em.computed.equal('content.controllerName', 'addServiceController'),
  30. /**
  31. * Clear <code>clusterInfo</code>
  32. * @method clearStep
  33. */
  34. clearStep: function () {
  35. this.get('clusterInfo').clear();
  36. },
  37. /**
  38. * @method loadStep
  39. */
  40. loadStep: function () {
  41. this.clearStep();
  42. this.loadInstalledHosts(this.loadRegisteredHosts());
  43. var installFlag = true;
  44. var startFlag = true;
  45. if (this.get('content.controllerName') == 'installerController') {
  46. installFlag = this.loadMasterComponents();
  47. startFlag = this.loadStartedServices();
  48. }
  49. if (installFlag && startFlag) {
  50. this.loadInstallTime();
  51. }
  52. },
  53. /**
  54. * Get list of clusterInfo object about registered hosts
  55. * @returns {{id: number, color: string, displayStatement: string, status: array}}
  56. * @method loadRegisteredHosts
  57. */
  58. loadRegisteredHosts: function () {
  59. var masterHosts = this.get('content.masterComponentHosts').mapProperty('hostName').uniq();
  60. var slaveHosts = this.get('content.slaveComponentHosts');
  61. var hostObj = [];
  62. slaveHosts.forEach(function (_hosts) {
  63. hostObj = hostObj.concat(_hosts.hosts);
  64. }, this);
  65. slaveHosts = hostObj.mapProperty('hostName').uniq();
  66. var registeredHosts = App.Host.find().mapProperty('hostName').concat(masterHosts.concat(slaveHosts)).uniq();
  67. var registerHostsStatement = Em.I18n.t('installer.step10.hostsSummary').format(registeredHosts.length);
  68. if (this.get('content.controllerName') === 'addHostController') {
  69. registerHostsStatement = Em.I18n.t('installer.step10.hostsSummary').format(Object.keys(this.get('content.hosts') || {}).length);
  70. }
  71. var registerHostsObj = Em.Object.create({
  72. id: 1,
  73. color: 'text-info',
  74. displayStatement: registerHostsStatement,
  75. status: []
  76. });
  77. this.get('clusterInfo').pushObject(registerHostsObj);
  78. return registerHostsObj;
  79. },
  80. /**
  81. * Push info about installed hosts to <code>clusterInfo</code>
  82. * @method loadInstalledHosts
  83. */
  84. loadInstalledHosts: function () {
  85. var hosts = this.get('content.hosts');
  86. var hostsInfo = [];
  87. for (var index in hosts) {
  88. if (hosts.hasOwnProperty(index)) {
  89. hostsInfo.pushObject(hosts[index]);
  90. }
  91. }
  92. var succeededHosts = hostsInfo.filterProperty('status', 'success');
  93. var warnedHosts = hostsInfo.filter(function(host) {
  94. return ['warning', 'failed'].contains(host.status);
  95. });
  96. if (succeededHosts.length) {
  97. var successMessage = this.get('content.cluster.status') === 'START_SKIPPED' ? Em.I18n.t('installer.step10.installed') : Em.I18n.t('installer.step10.installedAndStarted');
  98. var successStatement = successMessage.format(succeededHosts.length) + ((succeededHosts.length > 1) ? Em.I18n.t('installer.step8.hosts') : Em.I18n.t('installer.step8.host'));
  99. this.get('clusterInfo').findProperty('id', 1).get('status').pushObject(Em.Object.create({
  100. id: 1,
  101. color: 'text-success',
  102. displayStatement: successStatement
  103. }));
  104. }
  105. if (warnedHosts.length) {
  106. var warnStatement = warnedHosts.length + Em.I18n.t('installer.step10.warnings');
  107. this.get('clusterInfo').findProperty('id', 1).get('status').pushObject(Em.Object.create({
  108. id: 2,
  109. color: 'text-warning',
  110. displayStatement: warnStatement,
  111. statements: []
  112. }));
  113. warnedHosts.forEach(function (_host) {
  114. var clusterState = '';
  115. if (this.get('content.cluster.status') === 'INSTALL FAILED') {
  116. clusterState = Em.I18n.t('installer.step10.clusterState.installing');
  117. }
  118. else {
  119. if (this.get('content.cluster.status') === 'START FAILED') {
  120. clusterState = Em.I18n.t('installer.step10.clusterState.starting');
  121. }
  122. }
  123. var self = this;
  124. Em.A([
  125. {Tst: 'FAILED', st: 'failed'},
  126. {Tst: 'ABORTED', st: 'aborted'},
  127. {Tst: 'TIMEDOUT', st: 'timedout'}
  128. ]).forEach(function (s) {
  129. _host.tasks.filterProperty('Tasks.status', s.Tst).forEach(function (_task) {
  130. var statement = clusterState + App.format.role(_task.Tasks.role) + Em.I18n.t('installer.step10.taskStatus.failed') + _host.name;
  131. self.get('clusterInfo').findProperty('id', 1).get('status').findProperty('id', 2).get('statements').pushObject(Em.Object.create({
  132. status: s.st,
  133. color: 'text-info',
  134. displayStatement: statement
  135. }));
  136. });
  137. });
  138. }, this);
  139. }
  140. },
  141. /**
  142. * Push info about installed/failed master components to <code>clusterInfo</code>
  143. * @returns {bool}
  144. * @method loadMasterComponents
  145. */
  146. loadMasterComponents: function () {
  147. var components = this.get('content.masterComponentHosts');
  148. if (this.get('content.cluster.status') === 'INSTALL FAILED') {
  149. this.get('clusterInfo').pushObject(Em.Object.create({
  150. id: 2,
  151. displayStatement: Em.I18n.t('installer.step10.installStatus.failed'),
  152. color: 'text-error',
  153. status: []
  154. }));
  155. return false;
  156. }
  157. else {
  158. this.get('clusterInfo').pushObject(Em.Object.create({
  159. id: 2,
  160. displayStatement: Em.I18n.t('installer.step10.installStatus.installed'),
  161. color: 'text-success',
  162. status: []
  163. }));
  164. }
  165. components.forEach(function (_component) {
  166. var component = Em.Object.create(_component);
  167. if (['NAMENODE', 'SECONDARY_NAMENODE', 'JOBTRACKER', 'HISTORYSERVER', 'RESOURCEMANAGER', 'HBASE_MASTER',
  168. 'HIVE_SERVER', 'OOZIE_SERVER', 'GANGLIA_SERVER'].contains(component.component)) {
  169. this.loadMasterComponent(component);
  170. }
  171. }, this);
  172. return true;
  173. },
  174. /**
  175. * Push component info to <code>clusterInfo</code>
  176. * @param {Ember.Object} component
  177. * @method loadMasterComponent
  178. */
  179. loadMasterComponent: function (component) {
  180. if (component.get('hostName')) {
  181. var statement = Em.I18n.t('installer.step10.master.installedOn').format(component.get('display_name'), component.get('hostName'));
  182. this.get('clusterInfo').findProperty('id', 2).get('status').pushObject(Em.Object.create({
  183. id: 1,
  184. color: 'text-info',
  185. displayStatement: statement
  186. }));
  187. }
  188. },
  189. /**
  190. * Push info about installed/started/failed services to <code>clusterInfo</code>
  191. * @returns {bool}
  192. * @method loadStartedServices
  193. */
  194. loadStartedServices: function () {
  195. var status = this.get('content.cluster.status');
  196. if (status === 'STARTED') {
  197. this.get('clusterInfo').pushObject(Em.Object.create({
  198. id: 3,
  199. color: 'text-success',
  200. displayStatement: Em.I18n.t('installer.step10.startStatus.started'),
  201. status: []
  202. }));
  203. this.get('clusterInfo').pushObject(Em.Object.create({
  204. id: 4,
  205. color: 'text-success',
  206. displayStatement: Em.I18n.t('installer.step10.startStatus.passed'),
  207. status: []
  208. }));
  209. return true;
  210. } else if (status === 'START_SKIPPED') {
  211. this.get('clusterInfo').pushObject(Em.Object.create({
  212. id: 3,
  213. color: 'text-warning',
  214. displayStatement: Em.I18n.t('installer.step10.startStatus.skipped'),
  215. status: []
  216. }));
  217. return false
  218. } else {
  219. this.get('clusterInfo').pushObject(Em.Object.create({
  220. id: 3,
  221. color: 'text-error',
  222. displayStatement: Em.I18n.t('installer.step10.startStatus.failed'),
  223. status: []
  224. }));
  225. return false;
  226. }
  227. },
  228. /**
  229. * Push install time to <code>clusterInfo</code>
  230. * @method loadInstallTime
  231. */
  232. loadInstallTime: function () {
  233. var statement, time;
  234. if (this.get('content.cluster.installTime')) {
  235. time = this.calculateInstallTime(this.get('content.cluster.installTime'));
  236. if (time.minutes !== 0) {
  237. statement = Em.I18n.t('installer.step10.installTime.minutes').format(time.minutes, time.seconds);
  238. } else {
  239. statement = Em.I18n.t('installer.step10.installTime.seconds').format(time.seconds);
  240. }
  241. this.get('clusterInfo').pushObject(Em.Object.create({
  242. id: 5,
  243. color: 'text-info',
  244. displayStatement: statement,
  245. status: []
  246. }));
  247. }
  248. },
  249. /**
  250. * Get used time for install process
  251. * @param {number} installTime
  252. * @returns {{minutes: *, seconds: *}}
  253. * @method calculateInstallTime
  254. */
  255. calculateInstallTime: function (installTime) {
  256. var secondsPerMinute = 60;
  257. var minutes = Math.floor(installTime);
  258. var seconds = Math.floor((installTime - minutes) * secondsPerMinute);
  259. return {
  260. minutes: minutes,
  261. seconds: seconds
  262. }
  263. }
  264. });