step10_controller.js 9.6 KB

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