step10_controller.js 9.5 KB

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