step10_controller.js 10 KB

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