step10_controller.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. * Show message about required Nagios restart if installWizard used and Nagios is installed
  27. * @type {bool}
  28. */
  29. isNagiosRestartRequired: function () {
  30. return this.get('content.controllerName') !== 'installerController' && App.Service.find('NAGIOS').get('isLoaded');
  31. }.property(),
  32. /**
  33. * Clear <code>clusterInfo</code>
  34. * @method clearStep
  35. */
  36. clearStep: function () {
  37. this.get('clusterInfo').clear();
  38. },
  39. /**
  40. * @method loadStep
  41. */
  42. loadStep: function () {
  43. console.log("TRACE: Loading step10: Summary Page");
  44. this.clearStep();
  45. this.loadInstalledHosts(this.loadRegisteredHosts());
  46. var installFlag = true;
  47. var startFlag = true;
  48. if (this.get('content.controllerName') == 'installerController') {
  49. installFlag = this.loadMasterComponents();
  50. startFlag = this.loadStartedServices();
  51. }
  52. if (installFlag && startFlag) {
  53. this.loadInstallTime();
  54. }
  55. },
  56. /**
  57. * Get list of clusterInfo object about registered hosts
  58. * @returns {{id: number, color: string, displayStatement: string, status: array}}
  59. * @method loadRegisteredHosts
  60. */
  61. loadRegisteredHosts: function () {
  62. var masterHosts = this.get('content.masterComponentHosts').mapProperty('hostName').uniq();
  63. var slaveHosts = this.get('content.slaveComponentHosts');
  64. var hostObj = [];
  65. slaveHosts.forEach(function (_hosts) {
  66. hostObj = hostObj.concat(_hosts.hosts);
  67. }, this);
  68. slaveHosts = hostObj.mapProperty('hostName').uniq();
  69. var registeredHosts = App.Host.find().mapProperty('hostName').concat(masterHosts.concat(slaveHosts)).uniq();
  70. var registerHostsStatement = Em.I18n.t('installer.step10.hostsSummary').format(registeredHosts.length);
  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 successStatement = Em.I18n.t('installer.step10.servicesSummary').format(succeededHosts.length) + ((succeededHosts.length > 1) ? Em.I18n.t('installer.step8.hosts') : Em.I18n.t('installer.step8.host'));
  98. this.get('clusterInfo').findProperty('id', 1).get('status').pushObject(Em.Object.create({
  99. id: 1,
  100. color: 'text-success',
  101. displayStatement: successStatement
  102. }));
  103. }
  104. if (warnedHosts.length) {
  105. var warnStatement = warnedHosts.length + Em.I18n.t('installer.step10.warnings');
  106. this.get('clusterInfo').findProperty('id', 1).get('status').pushObject(Em.Object.create({
  107. id: 2,
  108. color: 'text-warning',
  109. displayStatement: warnStatement,
  110. statements: []
  111. }));
  112. warnedHosts.forEach(function (_host) {
  113. var clusterState = '';
  114. if (this.get('content.cluster.status') === 'INSTALL FAILED') {
  115. clusterState = Em.I18n.t('installer.step10.clusterState.installing');
  116. }
  117. else {
  118. if (this.get('content.cluster.status') === 'START FAILED') {
  119. clusterState = Em.I18n.t('installer.step10.clusterState.starting');
  120. }
  121. }
  122. var self = this;
  123. Em.A([
  124. {Tst: 'FAILED', st: 'failed'},
  125. {Tst: 'ABORTED', st: 'aborted'},
  126. {Tst: 'TIMEDOUT', st: 'timedout'}
  127. ]).forEach(function (s) {
  128. _host.tasks.filterProperty('Tasks.status', s.Tst).forEach(function (_task) {
  129. var statement = clusterState + App.format.role(_task.Tasks.role) + Em.I18n.t('installer.step10.taskStatus.failed') + _host.name;
  130. self.get('clusterInfo').findProperty('id', 1).get('status').findProperty('id', 2).get('statements').pushObject(Em.Object.create({
  131. status: s.st,
  132. color: 'text-info',
  133. displayStatement: statement
  134. }));
  135. });
  136. });
  137. }, this);
  138. }
  139. },
  140. /**
  141. * Push info about installed/failed master components to <code>clusterInfo</code>
  142. * @returns {bool}
  143. * @method loadMasterComponents
  144. */
  145. loadMasterComponents: function () {
  146. var components = this.get('content.masterComponentHosts');
  147. if (this.get('content.cluster.status') === 'INSTALL FAILED') {
  148. this.get('clusterInfo').pushObject(Em.Object.create({
  149. id: 2,
  150. displayStatement: Em.I18n.t('installer.step10.installStatus.failed'),
  151. color: 'text-error',
  152. status: []
  153. }));
  154. return false;
  155. }
  156. else {
  157. this.get('clusterInfo').pushObject(Em.Object.create({
  158. id: 2,
  159. displayStatement: Em.I18n.t('installer.step10.installStatus.installed'),
  160. color: 'text-success',
  161. status: []
  162. }));
  163. }
  164. console.log('STEP10 master components: ' + JSON.stringify(components));
  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', 'NAGIOS_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. if (this.get('content.cluster.status') === 'STARTED') {
  196. this.get('clusterInfo').pushObject(Em.Object.create({
  197. id: 3,
  198. color: 'text-success',
  199. displayStatement: Em.I18n.t('installer.step10.startStatus.started'),
  200. status: []
  201. }));
  202. this.get('clusterInfo').pushObject(Em.Object.create({
  203. id: 4,
  204. color: 'text-success',
  205. displayStatement: Em.I18n.t('installer.step10.startStatus.passed'),
  206. status: []
  207. }));
  208. return true;
  209. } else {
  210. this.get('clusterInfo').pushObject(Em.Object.create({
  211. id: 3,
  212. color: 'text-error',
  213. displayStatement: Em.I18n.t('installer.step10.startStatus.failed'),
  214. status: []
  215. }));
  216. return false;
  217. }
  218. },
  219. /**
  220. * Push install time to <code>clusterInfo</code>
  221. * @method loadInstallTime
  222. */
  223. loadInstallTime: function () {
  224. var statement, time;
  225. if (this.get('content.cluster.installTime')) {
  226. time = this.calculateInstallTime(this.get('content.cluster.installTime'));
  227. if (time.minutes !== 0) {
  228. statement = Em.I18n.t('installer.step10.installTime.minutes').format(time.minutes, time.seconds);
  229. } else {
  230. statement = Em.I18n.t('installer.step10.installTime.seconds').format(time.seconds);
  231. }
  232. this.get('clusterInfo').pushObject(Em.Object.create({
  233. id: 5,
  234. color: 'text-info',
  235. displayStatement: statement,
  236. status: []
  237. }));
  238. }
  239. },
  240. /**
  241. * Get used time for install process
  242. * @param {number} installTime
  243. * @returns {{minutes: *, seconds: *}}
  244. * @method calculateInstallTime
  245. */
  246. calculateInstallTime: function (installTime) {
  247. var secondsPerMinute = 60;
  248. var minutes = Math.floor(installTime);
  249. var seconds = Math.floor((installTime - minutes) * secondsPerMinute);
  250. return {
  251. minutes: minutes,
  252. seconds: seconds
  253. }
  254. }
  255. });