step10_controller.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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: function () {
  30. return this.get('content.controllerName') === 'addServiceController';
  31. }.property('content.controllerName'),
  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. if (this.get('content.controllerName') === 'addHostController') {
  72. registerHostsStatement = Em.I18n.t('installer.step10.hostsSummary').format(Object.keys(this.get('content.hosts') || {}).length);
  73. }
  74. var registerHostsObj = Em.Object.create({
  75. id: 1,
  76. color: 'text-info',
  77. displayStatement: registerHostsStatement,
  78. status: []
  79. });
  80. this.get('clusterInfo').pushObject(registerHostsObj);
  81. return registerHostsObj;
  82. },
  83. /**
  84. * Push info about installed hosts to <code>clusterInfo</code>
  85. * @method loadInstalledHosts
  86. */
  87. loadInstalledHosts: function () {
  88. var hosts = this.get('content.hosts');
  89. var hostsInfo = [];
  90. for (var index in hosts) {
  91. if (hosts.hasOwnProperty(index)) {
  92. hostsInfo.pushObject(hosts[index]);
  93. }
  94. }
  95. var succeededHosts = hostsInfo.filterProperty('status', 'success');
  96. var warnedHosts = hostsInfo.filter(function(host) {
  97. return ['warning', 'failed'].contains(host.status);
  98. });
  99. if (succeededHosts.length) {
  100. var successMessage = this.get('content.cluster.status') === 'START_SKIPPED' ? Em.I18n.t('installer.step10.installed') : Em.I18n.t('installer.step10.installedAndStarted');
  101. var successStatement = successMessage.format(succeededHosts.length) + ((succeededHosts.length > 1) ? Em.I18n.t('installer.step8.hosts') : Em.I18n.t('installer.step8.host'));
  102. this.get('clusterInfo').findProperty('id', 1).get('status').pushObject(Em.Object.create({
  103. id: 1,
  104. color: 'text-success',
  105. displayStatement: successStatement
  106. }));
  107. }
  108. if (warnedHosts.length) {
  109. var warnStatement = warnedHosts.length + Em.I18n.t('installer.step10.warnings');
  110. this.get('clusterInfo').findProperty('id', 1).get('status').pushObject(Em.Object.create({
  111. id: 2,
  112. color: 'text-warning',
  113. displayStatement: warnStatement,
  114. statements: []
  115. }));
  116. warnedHosts.forEach(function (_host) {
  117. var clusterState = '';
  118. if (this.get('content.cluster.status') === 'INSTALL FAILED') {
  119. clusterState = Em.I18n.t('installer.step10.clusterState.installing');
  120. }
  121. else {
  122. if (this.get('content.cluster.status') === 'START FAILED') {
  123. clusterState = Em.I18n.t('installer.step10.clusterState.starting');
  124. }
  125. }
  126. var self = this;
  127. Em.A([
  128. {Tst: 'FAILED', st: 'failed'},
  129. {Tst: 'ABORTED', st: 'aborted'},
  130. {Tst: 'TIMEDOUT', st: 'timedout'}
  131. ]).forEach(function (s) {
  132. _host.tasks.filterProperty('Tasks.status', s.Tst).forEach(function (_task) {
  133. var statement = clusterState + App.format.role(_task.Tasks.role) + Em.I18n.t('installer.step10.taskStatus.failed') + _host.name;
  134. self.get('clusterInfo').findProperty('id', 1).get('status').findProperty('id', 2).get('statements').pushObject(Em.Object.create({
  135. status: s.st,
  136. color: 'text-info',
  137. displayStatement: statement
  138. }));
  139. });
  140. });
  141. }, this);
  142. }
  143. },
  144. /**
  145. * Push info about installed/failed master components to <code>clusterInfo</code>
  146. * @returns {bool}
  147. * @method loadMasterComponents
  148. */
  149. loadMasterComponents: function () {
  150. var components = this.get('content.masterComponentHosts');
  151. if (this.get('content.cluster.status') === 'INSTALL FAILED') {
  152. this.get('clusterInfo').pushObject(Em.Object.create({
  153. id: 2,
  154. displayStatement: Em.I18n.t('installer.step10.installStatus.failed'),
  155. color: 'text-error',
  156. status: []
  157. }));
  158. return false;
  159. }
  160. else {
  161. this.get('clusterInfo').pushObject(Em.Object.create({
  162. id: 2,
  163. displayStatement: Em.I18n.t('installer.step10.installStatus.installed'),
  164. color: 'text-success',
  165. status: []
  166. }));
  167. }
  168. console.log('STEP10 master components: ' + JSON.stringify(components));
  169. components.forEach(function (_component) {
  170. var component = Em.Object.create(_component);
  171. if (['NAMENODE', 'SECONDARY_NAMENODE', 'JOBTRACKER', 'HISTORYSERVER', 'RESOURCEMANAGER', 'HBASE_MASTER',
  172. 'HIVE_SERVER', 'OOZIE_SERVER', 'GANGLIA_SERVER'].contains(component.component)) {
  173. this.loadMasterComponent(component);
  174. }
  175. }, this);
  176. return true;
  177. },
  178. /**
  179. * Push component info to <code>clusterInfo</code>
  180. * @param {Ember.Object} component
  181. * @method loadMasterComponent
  182. */
  183. loadMasterComponent: function (component) {
  184. if (component.get('hostName')) {
  185. var statement = Em.I18n.t('installer.step10.master.installedOn').format(component.get('display_name'), component.get('hostName'));
  186. this.get('clusterInfo').findProperty('id', 2).get('status').pushObject(Em.Object.create({
  187. id: 1,
  188. color: 'text-info',
  189. displayStatement: statement
  190. }));
  191. }
  192. },
  193. /**
  194. * Push info about installed/started/failed services to <code>clusterInfo</code>
  195. * @returns {bool}
  196. * @method loadStartedServices
  197. */
  198. loadStartedServices: function () {
  199. var status = this.get('content.cluster.status');
  200. if (status === 'STARTED') {
  201. this.get('clusterInfo').pushObject(Em.Object.create({
  202. id: 3,
  203. color: 'text-success',
  204. displayStatement: Em.I18n.t('installer.step10.startStatus.started'),
  205. status: []
  206. }));
  207. this.get('clusterInfo').pushObject(Em.Object.create({
  208. id: 4,
  209. color: 'text-success',
  210. displayStatement: Em.I18n.t('installer.step10.startStatus.passed'),
  211. status: []
  212. }));
  213. return true;
  214. } else if (status === 'START_SKIPPED') {
  215. this.get('clusterInfo').pushObject(Em.Object.create({
  216. id: 3,
  217. color: 'text-warning',
  218. displayStatement: Em.I18n.t('installer.step10.startStatus.skipped'),
  219. status: []
  220. }));
  221. return false
  222. } else {
  223. this.get('clusterInfo').pushObject(Em.Object.create({
  224. id: 3,
  225. color: 'text-error',
  226. displayStatement: Em.I18n.t('installer.step10.startStatus.failed'),
  227. status: []
  228. }));
  229. return false;
  230. }
  231. },
  232. /**
  233. * Push install time to <code>clusterInfo</code>
  234. * @method loadInstallTime
  235. */
  236. loadInstallTime: function () {
  237. var statement, time;
  238. if (this.get('content.cluster.installTime')) {
  239. time = this.calculateInstallTime(this.get('content.cluster.installTime'));
  240. if (time.minutes !== 0) {
  241. statement = Em.I18n.t('installer.step10.installTime.minutes').format(time.minutes, time.seconds);
  242. } else {
  243. statement = Em.I18n.t('installer.step10.installTime.seconds').format(time.seconds);
  244. }
  245. this.get('clusterInfo').pushObject(Em.Object.create({
  246. id: 5,
  247. color: 'text-info',
  248. displayStatement: statement,
  249. status: []
  250. }));
  251. }
  252. },
  253. /**
  254. * Get used time for install process
  255. * @param {number} installTime
  256. * @returns {{minutes: *, seconds: *}}
  257. * @method calculateInstallTime
  258. */
  259. calculateInstallTime: function (installTime) {
  260. var secondsPerMinute = 60;
  261. var minutes = Math.floor(installTime);
  262. var seconds = Math.floor((installTime - minutes) * secondsPerMinute);
  263. return {
  264. minutes: minutes,
  265. seconds: seconds
  266. }
  267. }
  268. });