step9_controller.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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.WizardStep9Controller = Em.Controller.extend({
  20. name: 'wizardStep9Controller',
  21. hosts: [],
  22. progress: '0',
  23. isStepCompleted: false,
  24. isSubmitDisabled: function () {
  25. // return !this.get('isStepCompleted');
  26. return !['STARTED','START FAILED'].contains(this.get('content.cluster.status'));
  27. }.property('content.cluster.status'),
  28. // links to previous steps are enabled iff install failed in installer
  29. togglePreviousSteps: function () {
  30. if ('INSTALL FAILED' === this.get('content.cluster.status') && this.get('content.controllerName') == 'installerController') {
  31. App.router.get('installerController').setStepsEnable();
  32. } else {
  33. App.router.get('installerController').setLowerStepsDisable(9);
  34. }
  35. }.observes('content.cluster.status', 'content.controllerName'),
  36. mockHostData: require('data/mock/step9_hosts'),
  37. mockDataPrefix: '/data/wizard/deploy/5_hosts',
  38. pollDataCounter: 0,
  39. polledData: [],
  40. status: function () {
  41. if (this.hosts.someProperty('status', 'failed')) {
  42. return 'failed';
  43. }
  44. if (this.hosts.someProperty('status', 'warning')) {
  45. if (this.isStepFailed()) {
  46. return 'failed';
  47. } else {
  48. return 'warning';
  49. }
  50. }
  51. if(this.get('progress') == '100') {
  52. this.set('isStepCompleted', true);
  53. return 'success';
  54. }
  55. return 'info';
  56. }.property('hosts.@each.status', 'progress'),
  57. categoryObject: Em.Object.extend({
  58. hostsCount: function () {
  59. var category = this;
  60. var hosts = this.get('controller.hosts').filter(function(_host) {
  61. if(category.get('hostStatus') == 'inProgress'){ // queued, pending, in_progress map to inProgress
  62. return (_host.get('status') !== 'success' && _host.get('status') !== 'failed' && _host.get('status') !== 'warning');
  63. }
  64. return (_host.get('status') == category.get('hostStatus'));
  65. }, this);
  66. return hosts.get('length');
  67. }.property('controller.hosts.@each.status'),
  68. label: function () {
  69. return "%@ (%@)".fmt(this.get('value'), this.get('hostsCount'));
  70. }.property('value', 'hostsCount')
  71. }),
  72. getCategory: function(field, value){
  73. return this.get('categories').find(function(item){
  74. return item.get(field) == value;
  75. });
  76. },
  77. categories: function () {
  78. var self = this;
  79. self.categoryObject.reopen({
  80. controller: self,
  81. isActive: function(){
  82. return this.get('controller.category') == this;
  83. }.property('controller.category'),
  84. itemClass: function(){
  85. return this.get('isActive') ? 'active' : '';
  86. }.property('isActive')
  87. });
  88. var categories = [
  89. self.categoryObject.create({value: Em.I18n.t('common.all'), hostStatus:'all', hostsCount: function () {
  90. return this.get('controller.hosts.length');
  91. }.property('controller.hosts.length') }),
  92. self.categoryObject.create({value: Em.I18n.t('installer.step9.hosts.status.label.inProgress'), hostStatus: 'inProgress'}),
  93. self.categoryObject.create({value: Em.I18n.t('installer.step9.hosts.status.label.warning'), hostStatus: 'warning'}),
  94. self.categoryObject.create({value: Em.I18n.t('common.success'), hostStatus: 'success'}),
  95. self.categoryObject.create({value: Em.I18n.t('common.fail'), hostStatus: 'failed', last: true })
  96. ];
  97. this.set('category', categories.get('firstObject'));
  98. return categories;
  99. }.property(),
  100. category: false,
  101. visibleHosts: function(){
  102. var targetStatus = this.get('category.hostStatus');
  103. var visibleHosts = this.get('hosts').filter(function(_host) {
  104. if (targetStatus == 'all') {
  105. return true;
  106. }
  107. if (targetStatus == 'inProgress') { // queued, pending, in_progress map to inProgress
  108. return (_host.get('status') !== 'success' && _host.get('status') !== 'failed' && _host.get('status') !== 'warning');
  109. }
  110. return (_host.get('status') == targetStatus);
  111. }, this);
  112. return visibleHosts;
  113. }.property('category', 'hosts.@each.status'),
  114. selectCategory: function(event){
  115. this.set('category', event.context);
  116. },
  117. showRetry: function () {
  118. return this.get('content.cluster.status') == 'INSTALL FAILED';
  119. }.property('content.cluster.status'),
  120. // content.cluster.status can be:
  121. // PENDING: set upon successful transition from step 1 to step 2
  122. // INSTALLED: set upon successful completion of install phase as well as successful invocation of start services API
  123. // STARTED: set up on successful completion of start phase
  124. // INSTALL FAILED: set up upon encountering a failure in install phase
  125. // START FAILED: set upon unsuccessful invocation of start services API and also upon encountering a failure
  126. // during start phase
  127. // content.cluster.isCompleted
  128. // set to false upon successful transition from step 1 to step 2
  129. // set to true upon successful start of services in this step
  130. // note: looks like this is the same thing as checking content.cluster.status == 'STARTED'
  131. // navigateStep is called by App.WizardStep9View's didInsertElement and "retry" from router.
  132. navigateStep: function () {
  133. if (App.testMode) {
  134. // this is for repeatedly testing out installs in test mode
  135. this.set('content.cluster.status', 'PENDING');
  136. this.set('content.cluster.isCompleted', false);
  137. }
  138. var clusterStatus = this.get('content.cluster.status');
  139. console.log('navigateStep: clusterStatus = ' + clusterStatus);
  140. if (this.get('content.cluster.isCompleted') === false) {
  141. // the cluster has not yet successfully installed and started
  142. if (clusterStatus === 'INSTALL FAILED') {
  143. this.loadStep();
  144. this.loadLogData(this.get('content.cluster.requestId'));
  145. this.set('isStepCompleted', true);
  146. } else if (clusterStatus === 'START FAILED') {
  147. this.loadStep();
  148. this.loadLogData(this.get('content.cluster.requestId'));
  149. // this.hosts.setEach('status', 'info');
  150. this.set('isStepCompleted', true);
  151. } else {
  152. // handle PENDING, INSTALLED
  153. this.loadStep();
  154. this.loadLogData(this.get('content.cluster.requestId'));
  155. this.startPolling();
  156. }
  157. } else {
  158. // handle STARTED
  159. // the cluster has successfully installed and started
  160. this.loadStep();
  161. this.loadLogData(this.get('content.cluster.requestId'));
  162. this.set('isStepCompleted', true);
  163. this.set('progress', '100');
  164. }
  165. },
  166. clearStep: function () {
  167. this.hosts.clear();
  168. this.set('status', 'info');
  169. this.set('progress', '0');
  170. this.set('isStepCompleted', false);
  171. this.numPolls = 0;
  172. },
  173. loadStep: function () {
  174. console.log("TRACE: Loading step9: Install, Start and Test");
  175. this.clearStep();
  176. this.renderHosts(this.loadHosts());
  177. },
  178. /**
  179. * reset status and message of all hosts when retry install
  180. */
  181. resetHostsForRetry: function(){
  182. var hosts = this.get('content.hosts');
  183. for (var name in hosts) {
  184. hosts[name].status = "pending";
  185. hosts[name].message = 'Waiting';
  186. }
  187. this.set('content.hosts', hosts);
  188. },
  189. loadHosts: function () {
  190. var hostInfo = this.get('content.hosts');
  191. var hosts = new Ember.Set();
  192. for (var index in hostInfo) {
  193. var obj = Em.Object.create(hostInfo[index]);
  194. obj.message = (obj.message) ? obj.message : 'Waiting';
  195. obj.progress = 0;
  196. obj.status = (obj.status) ? obj.status : 'info';
  197. obj.tasks = [];
  198. obj.logTasks = [];
  199. hosts.add(obj);
  200. console.log("TRACE: host name is: " + hostInfo[index].name);
  201. }
  202. return hosts.filterProperty('bootStatus', 'REGISTERED');
  203. },
  204. // sets this.hosts, where each element corresponds to a status and progress info on a host
  205. renderHosts: function (hostsInfo) {
  206. hostsInfo.forEach(function (_hostInfo) {
  207. var hostInfo = App.HostInfo.create({
  208. name: _hostInfo.name,
  209. status: _hostInfo.status,
  210. tasks: _hostInfo.tasks,
  211. logTasks: _hostInfo.logTasks,
  212. message: _hostInfo.message,
  213. progress: _hostInfo.progress
  214. });
  215. console.log('pushing ' + hostInfo.name);
  216. this.hosts.pushObject(hostInfo);
  217. }, this);
  218. },
  219. replacePolledData: function (polledData) {
  220. this.polledData.clear();
  221. this.set('polledData', polledData);
  222. },
  223. displayMessage: function (task) {
  224. var role = App.format.role(task.role);
  225. console.log("In display message with task command value: " + task.command);
  226. switch (task.command) {
  227. case 'INSTALL':
  228. switch (task.status) {
  229. case 'PENDING':
  230. return Em.I18n.t('installer.step9.serviceStatus.install.pending') + role;
  231. case 'QUEUED' :
  232. return Em.I18n.t('installer.step9.serviceStatus.install.queued') + role;
  233. case 'IN_PROGRESS':
  234. return Em.I18n.t('installer.step9.serviceStatus.install.inProgress') + role;
  235. case 'COMPLETED' :
  236. return Em.I18n.t('installer.step9.serviceStatus.install.completed') + role;
  237. case 'FAILED':
  238. return Em.I18n.t('installer.step9.serviceStatus.install.failed') + role;
  239. }
  240. case 'UNINSTALL':
  241. switch (task.status) {
  242. case 'PENDING':
  243. return Em.I18n.t('installer.step9.serviceStatus.uninstall.pending') + role;
  244. case 'QUEUED' :
  245. return Em.I18n.t('installer.step9.serviceStatus.uninstall.queued') + role;
  246. case 'IN_PROGRESS':
  247. return Em.I18n.t('installer.step9.serviceStatus.uninstall.inProgress') + role;
  248. case 'COMPLETED' :
  249. return Em.I18n.t('installer.step9.serviceStatus.uninstall.completed') + role;
  250. case 'FAILED':
  251. return Em.I18n.t('installer.step9.serviceStatus.uninstall.failed') + role;
  252. }
  253. case 'START' :
  254. switch (task.status) {
  255. case 'PENDING':
  256. return Em.I18n.t('installer.step9.serviceStatus.start.pending') + role;
  257. case 'QUEUED' :
  258. return Em.I18n.t('installer.step9.serviceStatus.start.queued') + role;
  259. case 'IN_PROGRESS':
  260. return Em.I18n.t('installer.step9.serviceStatus.start.inProgress') + role;
  261. case 'COMPLETED' :
  262. return role + Em.I18n.t('installer.step9.serviceStatus.start.completed');
  263. case 'FAILED':
  264. return role + Em.I18n.t('installer.step9.serviceStatus.start.failed');
  265. }
  266. case 'STOP' :
  267. switch (task.status) {
  268. case 'PENDING':
  269. return Em.I18n.t('installer.step9.serviceStatus.stop.pending') + role;
  270. case 'QUEUED' :
  271. return Em.I18n.t('installer.step9.serviceStatus.stop.queued') + role;
  272. case 'IN_PROGRESS':
  273. return Em.I18n.t('installer.step9.serviceStatus.stop.inProgress') + role;
  274. case 'COMPLETED' :
  275. return role + Em.I18n.t('installer.step9.serviceStatus.stop.completed');
  276. case 'FAILED':
  277. return role + Em.I18n.t('installer.step9.serviceStatus.stop.failed');
  278. }
  279. case 'EXECUTE' :
  280. switch (task.status) {
  281. case 'PENDING':
  282. return Em.I18n.t('installer.step9.serviceStatus.execute.pending') + role;
  283. case 'QUEUED' :
  284. return Em.I18n.t('installer.step9.serviceStatus.execute.queued') + role;
  285. case 'IN_PROGRESS':
  286. return Em.I18n.t('installer.step9.serviceStatus.execute.inProgress') + role;
  287. case 'COMPLETED' :
  288. return role + Em.I18n.t('installer.step9.serviceStatus.execute.completed');
  289. case 'FAILED':
  290. return role + Em.I18n.t('installer.step9.serviceStatus.execute.failed');
  291. }
  292. case 'ABORT' :
  293. switch (task.status) {
  294. case 'PENDING':
  295. return Em.I18n.t('installer.step9.serviceStatus.abort.pending') + role;
  296. case 'QUEUED' :
  297. return Em.I18n.t('installer.step9.serviceStatus.abort.queued') + role;
  298. case 'IN_PROGRESS':
  299. return Em.I18n.t('installer.step9.serviceStatus.abort.inProgress') + role;
  300. case 'COMPLETED' :
  301. return role + Em.I18n.t('installer.step9.serviceStatus.abort.completed');
  302. case 'FAILED':
  303. return role + Em.I18n.t('installer.step9.serviceStatus.abort.failed');
  304. }
  305. }
  306. },
  307. /**
  308. * run start/check services after installation phase
  309. */
  310. launchStartServices: function () {
  311. var data = '{"RequestInfo": {"context": "'+Em.I18n.t("requestInfo.serviceStartCheck")+'"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}';
  312. var name = 'wizard.step9.installer.launch_start_services';
  313. if (this.get('content.controllerName') === 'addHostController') {
  314. data = '{"HostRoles": {"state": "STARTED"}}';
  315. name = 'wizard.step9.add_host.launch_start_services';
  316. }
  317. if (App.testMode) {
  318. this.numPolls = 6;
  319. }
  320. App.ajax.send({
  321. name: name,
  322. sender: this,
  323. data: {
  324. data: data,
  325. cluster: this.get('content.cluster.name')
  326. },
  327. success: 'launchStartServicesSuccessCallback',
  328. error: 'launchStartServicesErrorCallback'
  329. });
  330. },
  331. launchStartServicesSuccessCallback: function (jsonData) {
  332. console.log("TRACE: Step9 -> In success function for the startService call");
  333. console.log("TRACE: Step9 -> value of the received data is: " + jsonData);
  334. var requestId = jsonData.Requests.id;
  335. console.log('requestId is: ' + requestId);
  336. var clusterStatus = {
  337. status: 'INSTALLED',
  338. requestId: requestId,
  339. isStartError: false,
  340. isCompleted: false
  341. };
  342. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  343. // We need to do recovery if there is a browser crash
  344. App.clusterStatus.setClusterStatus({
  345. clusterState: 'SERVICE_STARTING_3',
  346. localdb: App.db.data
  347. });
  348. this.startPolling();
  349. },
  350. launchStartServicesErrorCallback: function () {
  351. console.log("ERROR");
  352. var clusterStatus = {
  353. status: 'START FAILED',
  354. isStartError: true,
  355. isCompleted: false
  356. };
  357. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  358. },
  359. // marks a host's status as "success" if all tasks are in COMPLETED state
  360. onSuccessPerHost: function (actions, contentHost) {
  361. if (actions.everyProperty('Tasks.status', 'COMPLETED') && this.get('content.cluster.status') === 'INSTALLED') {
  362. contentHost.set('status', 'success');
  363. }
  364. },
  365. // marks a host's status as "warning" if at least one of the tasks is FAILED, ABORTED, or TIMEDOUT and marks host's status as "failed" if at least one master component install task is FAILED.
  366. onErrorPerHost: function (actions, contentHost) {
  367. if (actions.someProperty('Tasks.status', 'FAILED') || actions.someProperty('Tasks.status', 'ABORTED') || actions.someProperty('Tasks.status', 'TIMEDOUT')) {
  368. contentHost.set('status', 'warning');
  369. }
  370. if (this.get('content.cluster.status') === 'PENDING' && actions.someProperty('Tasks.status', 'FAILED')) {
  371. contentHost.set('status', 'failed');
  372. }
  373. },
  374. onInProgressPerHost: function (tasks, contentHost) {
  375. var runningAction = tasks.findProperty('Tasks.status', 'IN_PROGRESS');
  376. if (runningAction === undefined || runningAction === null) {
  377. runningAction = tasks.findProperty('Tasks.status', 'QUEUED');
  378. }
  379. if (runningAction === undefined || runningAction === null) {
  380. runningAction = tasks.findProperty('Tasks.status', 'PENDING');
  381. }
  382. if (runningAction !== null && runningAction !== undefined) {
  383. contentHost.set('message', this.displayMessage(runningAction.Tasks));
  384. }
  385. },
  386. /**
  387. * calculate progress of tasks per host
  388. * @param actions
  389. * @param contentHost
  390. * @return {Number}
  391. */
  392. progressPerHost: function (actions, contentHost) {
  393. var progress = 0;
  394. var actionsPerHost = actions.length;
  395. // TODO: consolidate to a single filter function for better performance
  396. var completedActions = actions.filterProperty('Tasks.status', 'COMPLETED').length
  397. + actions.filterProperty('Tasks.status', 'FAILED').length
  398. + actions.filterProperty('Tasks.status', 'ABORTED').length
  399. + actions.filterProperty('Tasks.status', 'TIMEDOUT').length;
  400. var queuedActions = actions.filterProperty('Tasks.status', 'QUEUED').length;
  401. var inProgressActions = actions.filterProperty('Tasks.status', 'IN_PROGRESS').length;
  402. /** for the install phase (PENDING), % completed per host goes up to 33%; floor(100 / 3)
  403. * for the start phase (INSTALLED), % completed starts from 34%
  404. * when task in queued state means it's completed on 9%
  405. * in progress - 35%
  406. * completed - 100%
  407. */
  408. switch (this.get('content.cluster.status')) {
  409. case 'PENDING':
  410. progress = Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / actionsPerHost * 33);
  411. break;
  412. case 'INSTALLED':
  413. progress = 34 + Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / actionsPerHost * 66);
  414. break;
  415. default:
  416. progress = 100;
  417. break;
  418. }
  419. console.log('INFO: progressPerHost is: ' + progress);
  420. contentHost.set('progress', progress.toString());
  421. return progress;
  422. },
  423. isSuccess: function (polledData) {
  424. return polledData.everyProperty('Tasks.status', 'COMPLETED');
  425. },
  426. //return true if at least 50% of the slave host components for the particular service component fails to install
  427. isStepFailed: function () {
  428. var failed = false;
  429. var polledData = this.get('polledData');
  430. polledData.filterProperty('Tasks.command', 'INSTALL').mapProperty('Tasks.role').uniq().forEach(function (role) {
  431. if (['DATANODE', 'TASKTRACKER', 'HBASE_REGIONSERVER', 'GANGLIA_MONITOR'].contains(role)) {
  432. var actionsPerRole = polledData.filterProperty('Tasks.role', role);
  433. var actionsFailed = actionsPerRole.filterProperty('Tasks.status', 'FAILED');
  434. var actionsAborted = actionsPerRole.filterProperty('Tasks.status', 'ABORTED');
  435. var actionsTimedOut = actionsPerRole.filterProperty('Tasks.status', 'TIMEDOUT');
  436. if ((((actionsFailed.length + actionsAborted.length + actionsTimedOut.length) / actionsPerRole.length) * 100) > 50) {
  437. failed = true;
  438. }
  439. }
  440. }, this);
  441. return failed;
  442. },
  443. // makes a state transition
  444. // PENDING -> INSTALLED
  445. // PENDING -> INSTALL FAILED
  446. // INSTALLED -> STARTED
  447. // INSTALLED -> START_FAILED
  448. // returns true if polling should stop; false otherwise
  449. // polling from ui stops only when no action has 'PENDING', 'QUEUED' or 'IN_PROGRESS' status
  450. finishState: function (polledData) {
  451. var clusterStatus = {};
  452. var requestId = this.get('content.cluster.requestId');
  453. if (this.get('content.cluster.status') === 'INSTALLED') {
  454. if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  455. this.set('progress', '100');
  456. clusterStatus = {
  457. status: 'INSTALLED',
  458. requestId: requestId,
  459. isCompleted: true
  460. };
  461. if (this.isSuccess(polledData)) {
  462. clusterStatus.status = 'STARTED';
  463. var serviceStartTime = new Date().getTime();
  464. var timeToStart = ((parseInt(serviceStartTime) - parseInt(this.get('content.cluster.installStartTime'))) / 60000).toFixed(2);
  465. clusterStatus.installTime = timeToStart;
  466. } else {
  467. clusterStatus.status = 'START FAILED'; // 'START FAILED' implies to step10 that installation was successful but start failed
  468. }
  469. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  470. this.set('isStepCompleted', true);
  471. this.setTasksPerHost();
  472. App.router.get(this.get('content.controllerName')).saveInstalledHosts(this);
  473. return true;
  474. }
  475. } else if (this.get('content.cluster.status') === 'PENDING') {
  476. if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  477. clusterStatus = {
  478. status: 'PENDING',
  479. requestId: requestId,
  480. isCompleted: false
  481. }
  482. if (this.get('status') === 'failed') {
  483. clusterStatus.status = 'INSTALL FAILED';
  484. this.set('progress', '100');
  485. this.get('hosts').setEach('progress', '100');
  486. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  487. this.set('isStepCompleted', true);
  488. } else {
  489. clusterStatus.status = 'INSTALLED';
  490. this.set('progress', '34');
  491. this.launchStartServices();
  492. }
  493. this.setTasksPerHost();
  494. App.router.get(this.get('content.controllerName')).saveInstalledHosts(this);
  495. return true;
  496. }
  497. } else if (this.get('content.cluster.status') === 'INSTALL FAILED' || this.get('content.cluster.status') === 'START FAILED' || this.get('content.cluster.status') === 'STARTED') {
  498. this.set('progress', '100');
  499. return true;
  500. }
  501. return false;
  502. },
  503. setTasksPerHost: function () {
  504. var tasksData = this.get('polledData');
  505. this.get('hosts').forEach(function (_host) {
  506. var tasksPerHost = tasksData.filterProperty('Tasks.host_name', _host.name); // retrieved from polled Data
  507. if (tasksPerHost.length === 0) {
  508. //alert('For testing with mockData follow the sequence: hit referesh,"mockData btn", "pollData btn", again "pollData btn"');
  509. //exit();
  510. }
  511. if (tasksPerHost !== null && tasksPerHost !== undefined && tasksPerHost.length !== 0) {
  512. tasksPerHost.forEach(function (_taskPerHost) {
  513. console.log('In step9 _taskPerHost function.');
  514. //if (_taskPerHost.Tasks.status !== 'PENDING' && _taskPerHost.Tasks.status !== 'QUEUED' && _taskPerHost.Tasks.status !== 'IN_PROGRESS') {
  515. _host.tasks.pushObject(_taskPerHost);
  516. //}
  517. }, this);
  518. }
  519. }, this);
  520. },
  521. logTasksChangesCounter: 0,
  522. // This is done at HostRole level.
  523. setLogTasksStatePerHost: function (tasksPerHost, host) {
  524. console.log('In step9 setTasksStatePerHost function.');
  525. tasksPerHost.forEach(function (_task) {
  526. console.log('In step9 _taskPerHost function.');
  527. //if (_task.Tasks.status !== 'PENDING' && _task.Tasks.status !== 'QUEUED') {
  528. var task = host.logTasks.findProperty('Tasks.id', _task.Tasks.id);
  529. if (task) {
  530. host.logTasks.removeObject(task);
  531. }
  532. host.logTasks.pushObject(_task);
  533. //}
  534. }, this);
  535. this.set('logTasksChangesCounter', this.get('logTasksChangesCounter') + 1);
  536. },
  537. parseHostInfo: function (polledData) {
  538. console.log('TRACE: Entering host info function');
  539. var self = this;
  540. var totalProgress = 0;
  541. var tasksData = polledData.tasks;
  542. console.log("The value of tasksData is: ", tasksData);
  543. if (!tasksData) {
  544. console.log("Step9: ERROR: NO tasks available to process");
  545. }
  546. var requestId = this.get('content.cluster.requestId');
  547. if(polledData.Requests && polledData.Requests.id && polledData.Requests.id!=requestId){
  548. // We dont want to use non-current requestId's tasks data to
  549. // determine the current install status.
  550. // Also, we dont want to keep polling if it is not the
  551. // current requestId.
  552. return false;
  553. }
  554. this.replacePolledData(tasksData);
  555. this.hosts.forEach(function (_host) {
  556. var actionsPerHost = tasksData.filterProperty('Tasks.host_name', _host.name); // retrieved from polled Data
  557. if (actionsPerHost.length === 0) {
  558. _host.set('message', this.t('installer.step9.host.status.nothingToInstall'));
  559. console.log("INFO: No task is hosted on the host");
  560. }
  561. if (actionsPerHost !== null && actionsPerHost !== undefined && actionsPerHost.length !== 0) {
  562. this.setLogTasksStatePerHost(actionsPerHost, _host);
  563. this.onSuccessPerHost(actionsPerHost, _host); // every action should be a success
  564. this.onErrorPerHost(actionsPerHost, _host); // any action should be a failure
  565. this.onInProgressPerHost(actionsPerHost, _host); // current running action for a host
  566. totalProgress += self.progressPerHost(actionsPerHost, _host);
  567. }
  568. }, this);
  569. totalProgress = Math.floor(totalProgress / this.hosts.length);
  570. this.set('progress', totalProgress.toString());
  571. console.log("INFO: right now the progress is: " + this.get('progress'));
  572. return this.finishState(tasksData);
  573. },
  574. startPolling: function () {
  575. this.set('isSubmitDisabled', true);
  576. this.doPolling();
  577. },
  578. numPolls: 0,
  579. getUrl: function (requestId) {
  580. var clusterName = this.get('content.cluster.name');
  581. var requestId = requestId || this.get('content.cluster.requestId');
  582. var url = App.apiPrefix + '/clusters/' + clusterName + '/requests/' + requestId + '?fields=tasks/*';
  583. console.log("URL for step9 is: " + url);
  584. return url;
  585. },
  586. POLL_INTERVAL: 4000,
  587. loadLogData: function(requestId) {
  588. var url = this.getUrl(requestId);
  589. var requestsId = App.db.getCluster().oldRequestsId;
  590. if (App.testMode) {
  591. this.POLL_INTERVAL = 1;
  592. this.numPolls++;
  593. }
  594. requestsId.forEach(function(requestId) {
  595. url = this.getUrl(requestId);
  596. if (App.testMode) {
  597. this.POLL_INTERVAL = 1;
  598. url = this.get('mockDataPrefix') + '/poll_' + this.numPolls + '.json';
  599. }
  600. this.getLogsByRequest(url, false);
  601. }, this);
  602. },
  603. // polling: whether to continue polling for status or not
  604. getLogsByRequest: function(url, polling){
  605. var self = this;
  606. $.ajax({
  607. type: 'GET',
  608. url: url,
  609. async: true,
  610. timeout: App.timeout,
  611. dataType: 'text',
  612. success: function (data) {
  613. console.log("TRACE: In success function for the GET logs data");
  614. console.log("TRACE: STep9 -> The value is: ", jQuery.parseJSON(data));
  615. var result = self.parseHostInfo(jQuery.parseJSON(data));
  616. if (!polling) {
  617. return;
  618. }
  619. if (result !== true) {
  620. window.setTimeout(function () {
  621. self.doPolling();
  622. }, self.POLL_INTERVAL);
  623. } else {
  624. self.stopPolling();
  625. }
  626. },
  627. error: function (request, ajaxOptions, error) {
  628. console.log("TRACE: STep9 -> In error function for the GET logs data");
  629. console.log("TRACE: STep9 -> value of the url is: " + url);
  630. console.log("TRACE: STep9 -> error code status is: " + request.status);
  631. self.stopPolling();
  632. },
  633. statusCode: require('data/statusCodes')
  634. }).retry({times: App.maxRetries, timeout: App.timeout}).then(null,
  635. function () {
  636. App.showReloadPopup();
  637. console.log('Install services all retries failed');
  638. }
  639. );
  640. },
  641. doPolling: function () {
  642. var url = this.getUrl();
  643. if (App.testMode) {
  644. this.numPolls++;
  645. url = this.get('mockDataPrefix') + '/poll_' + this.get('numPolls') + '.json';
  646. }
  647. this.getLogsByRequest(url, true);
  648. },
  649. stopPolling: function () {
  650. //TODO: uncomment following line after the hook up with the API call
  651. // this.set('isStepCompleted',true);
  652. },
  653. submit: function () {
  654. if (!this.get('isSubmitDisabled')) {
  655. App.router.send('next');
  656. }
  657. },
  658. back: function () {
  659. if (!this.get('isSubmitDisabled')) {
  660. App.router.send('back');
  661. }
  662. },
  663. mockBtn: function () {
  664. this.set('isSubmitDisabled', false);
  665. this.hosts.clear();
  666. var hostInfo = this.mockHostData;
  667. this.renderHosts(hostInfo);
  668. },
  669. pollBtn: function () {
  670. this.set('isSubmitDisabled', false);
  671. var data1 = require('data/mock/step9PolledData/pollData_1');
  672. var data2 = require('data/mock/step9PolledData/pollData_2');
  673. var data3 = require('data/mock/step9PolledData/pollData_3');
  674. var data4 = require('data/mock/step9PolledData/pollData_4');
  675. var data5 = require('data/mock/step9PolledData/pollData_5');
  676. var data6 = require('data/mock/step9PolledData/pollData_6');
  677. var data7 = require('data/mock/step9PolledData/pollData_7');
  678. var data8 = require('data/mock/step9PolledData/pollData_8');
  679. var data9 = require('data/mock/step9PolledData/pollData_9');
  680. console.log("TRACE: In pollBtn function data1");
  681. var counter = parseInt(this.get('pollDataCounter')) + 1;
  682. this.set('pollDataCounter', counter.toString());
  683. switch (this.get('pollDataCounter')) {
  684. case '1':
  685. this.parseHostInfo(data1);
  686. break;
  687. case '2':
  688. this.parseHostInfo(data2);
  689. break;
  690. case '3':
  691. this.parseHostInfo(data3);
  692. break;
  693. case '4':
  694. this.parseHostInfo(data4);
  695. break;
  696. case '5':
  697. this.parseHostInfo(data5);
  698. break;
  699. case '6':
  700. this.set('content.cluster.status', 'INSTALLED');
  701. this.parseHostInfo(data6);
  702. break;
  703. case '7':
  704. this.parseHostInfo(data7);
  705. break;
  706. case '8':
  707. this.parseHostInfo(data8);
  708. break;
  709. case '9':
  710. this.parseHostInfo(data9);
  711. break;
  712. default:
  713. break;
  714. }
  715. }
  716. });