step9_controller.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. }.property('isStepCompleted'),
  27. mockHostData:require('data/mock/step9_hosts'),
  28. pollData_1:require('data/mock/step9_pollData_1'),
  29. pollData_2:require('data/mock/step9_pollData_2'),
  30. pollDataCounter:0,
  31. status:function () {
  32. if (this.hosts.everyProperty('status', 'success')) {
  33. return 'success';
  34. } else if (this.hosts.someProperty('status', 'failed')) {
  35. return 'failed';
  36. } else if (this.hosts.someProperty('status', 'warning')) {
  37. return 'warning';
  38. } else {
  39. return 'info';
  40. }
  41. }.property('hosts.@each.status'),
  42. navigateStep:function () {
  43. this.loadStep();
  44. //TODO: uncomment following line after the hook up with the API call
  45. if (this.get('content.cluster.isCompleted') === false) {
  46. //this.startPolling();
  47. } else {
  48. this.set('isStepCompleted', true);
  49. this.set('progress', '100');
  50. }
  51. },
  52. clearStep:function () {
  53. this.hosts.clear();
  54. this.set('status', 'info');
  55. this.set('progress', '0');
  56. this.set('isStepCompleted', false);
  57. },
  58. loadStep:function () {
  59. console.log("TRACE: Loading step9: Install, Start and Test");
  60. this.clearStep();
  61. this.renderHosts(this.loadHosts());
  62. },
  63. loadHosts:function () {
  64. var hostInfo = [];
  65. hostInfo = this.get('content.hostsInfo');
  66. var hosts = new Ember.Set();
  67. for (var index in hostInfo) {
  68. hosts.add(hostInfo[index]);
  69. console.log("TRACE: host name is: " + hostInfo[index].name);
  70. }
  71. return hosts.filterProperty('bootStatus', 'success');
  72. },
  73. renderHosts:function (hostsInfo) {
  74. var self = this;
  75. hostsInfo.forEach(function (_hostInfo) {
  76. var hostInfo = App.HostInfo.create({
  77. name:_hostInfo.name,
  78. status:_hostInfo.status,
  79. message:_hostInfo.message,
  80. progress:_hostInfo.progress
  81. });
  82. console.log('pushing ' + hostInfo.name);
  83. self.hosts.pushObject(hostInfo);
  84. });
  85. },
  86. onSuccessPerHost:function (actions, contentHost) {
  87. if (actions.everyProperty('status', 'completed')) {
  88. contentHost.set('status', 'success');
  89. }
  90. },
  91. onWarningPerHost:function (actions, contentHost) {
  92. if (actions.findProperty('status', 'failed') || actions.findProperty('status', 'aborted')) {
  93. contentHost.set('status', 'warning');
  94. this.set('status', 'warning');
  95. }
  96. },
  97. onInProgressPerHost:function (actions, contentHost) {
  98. var runningAction = actions.findProperty('status', 'inprogress');
  99. if (runningAction !== null && runningAction !== undefined) {
  100. contentHost.set('message', runningAction.message);
  101. }
  102. },
  103. progressPerHost:function (actions, contentHost) {
  104. var totalProgress = 0;
  105. var actionsPerHost = actions.length;
  106. var completedActions = actions.filterProperty('status', 'completed').length
  107. + actions.filterProperty('status', 'failed').length +
  108. actions.filterProperty('status', 'aborted').length;
  109. var progress = Math.floor((completedActions / actionsPerHost) * 100);
  110. console.log('INFO: progressPerHost is: ' + progress);
  111. contentHost.set('progress', progress.toString());
  112. return progress;
  113. },
  114. isSuccess:function (polledData) {
  115. return polledData.everyProperty('status', 'success');
  116. },
  117. isStepFailed:function (polledData) {
  118. var self = this;
  119. var result = false;
  120. polledData.forEach(function (_polledData) {
  121. var successFactor = _polledData.sf;
  122. var actionsPerRole = polledData.filterProperty('role', _polledData.role);
  123. var actionsFailed = actionsPerRole.filterProperty('status', 'failed');
  124. var actionsAborted = actionsPerRole.filterProperty('status', 'aborted');
  125. if ((((actionsFailed.length + actionsAborted.length) / actionsPerRole.length) * 100) <= successFactor) {
  126. console.log('TRACE: Entering success factor and result is failed');
  127. result = true;
  128. }
  129. });
  130. return result;
  131. },
  132. getFailedHostsForFailedRoles:function (polledData) {
  133. var hostArr = new Ember.Set();
  134. polledData.forEach(function (_polledData) {
  135. var successFactor = _polledData.sf;
  136. var actionsPerRole = polledData.filterProperty('role', _polledData.role);
  137. var actionsFailed = actionsPerRole.filterProperty('status', 'failed');
  138. var actionsAborted = actionsPerRole.filterProperty('status', 'aborted');
  139. if ((((actionsFailed.length + actionsAborted.length) / actionsPerRole.length) * 100) <= successFactor) {
  140. actionsFailed.forEach(function (_actionFailed) {
  141. hostArr.add(_actionFailed.name);
  142. });
  143. actionsAborted.forEach(function (_actionFailed) {
  144. hostArr.add(_actionFailed.name);
  145. });
  146. }
  147. });
  148. return hostArr;
  149. },
  150. setHostsStatus:function (hosts, status) {
  151. var self = this;
  152. hosts.forEach(function (_host) {
  153. var host = self.hosts.findProperty('name', _host);
  154. host.set('status', status);
  155. });
  156. },
  157. // polling from ui stops only when no action has 'pending', 'queued' or 'inprogress' status
  158. finishStep:function (polledData) {
  159. var self = this;
  160. if (!polledData.someProperty('status', 'pending') && !polledData.someProperty('status', 'queued') && !polledData.someProperty('status', 'inprogress')) {
  161. this.set('progress', '100');
  162. if (this.isSuccess(polledData)) {
  163. this.set('status', 'success');
  164. } else {
  165. if (this.isStepFailed(polledData)) {
  166. self.set('status', 'failed');
  167. this.setHostsStatus(this.getFailedHostsForFailedRoles(polledData), 'failed');
  168. }
  169. }
  170. this.set('isStepCompleted', true);
  171. }
  172. },
  173. parseHostInfo:function (polledData) {
  174. console.log('TRACE: Entering host info function');
  175. var self = this;
  176. var result = false;
  177. var totalProgress = 0;
  178. this.hosts.forEach(function (_content) {
  179. var actions = polledData.filterProperty('name', _content.name);
  180. if (actions.length === 0) {
  181. alert('For testing with mockData follow the sequence: hit referesh,"mockData btn", "pollData btn", again "pollData btn"');
  182. //exit();
  183. }
  184. if (actions !== null && actions !== undefined && actions.length !== 0) {
  185. this.onSuccessPerHost(actions, _content); // every action should be a success
  186. this.onWarningPerHost(actions, _content); // any action should be a faliure
  187. this.onInProgressPerHost(actions, _content); // current running action for a host
  188. totalProgress = totalProgress + self.progressPerHost(actions, _content);
  189. }
  190. }, this);
  191. totalProgress = Math.floor(totalProgress / this.hosts.length);
  192. this.set('progress', totalProgress.toString());
  193. console.log("INFO: right now the progress is: " + this.get('progress'));
  194. this.finishStep(polledData);
  195. return this.get('isStepCompleted');
  196. },
  197. retry:function () {
  198. if (this.get('isSubmitDisabled')) {
  199. return;
  200. }
  201. this.hosts.clear();
  202. this.renderHosts(this.loadHosts());
  203. //this.startPolling();
  204. },
  205. startPolling:function () {
  206. this.set('isSubmitDisabled', true);
  207. this.doPolling();
  208. },
  209. doPolling:function () {
  210. var self = this;
  211. $.ajax({
  212. type:'GET',
  213. url:'/ambari_server/api/polling',
  214. async:false,
  215. timeout:5000,
  216. success:function (data) {
  217. console.log("TRACE: In success function for the GET bootstrap call");
  218. var result = self.parseHostInfo(data);
  219. if (result !== true) {
  220. window.setTimeout(self.doPolling, 3000);
  221. } else {
  222. self.stopPolling();
  223. }
  224. },
  225. error:function () {
  226. console.log("ERROR");
  227. self.stopPolling();
  228. },
  229. statusCode:{
  230. 404:function () {
  231. console.log("URI not found.");
  232. }
  233. },
  234. dataType:'application/json'
  235. });
  236. },
  237. stopPolling:function () {
  238. //TODO: uncomment following line after the hook up with the API call
  239. // this.set('isStepCompleted',true);
  240. },
  241. submit:function () {
  242. if (!this.get('isSubmitDisabled')) {
  243. this.set('content.cluster.status', this.get('status'));
  244. this.set('content.cluster.isCompleted', true);
  245. App.router.send('next');
  246. }
  247. },
  248. back:function () {
  249. if (!this.get('isSubmitDisabled')) {
  250. App.router.send('back');
  251. }
  252. },
  253. hostLogPopup:function (event) {
  254. App.ModalPopup.show({
  255. header:Em.I18n.t('installer.step3.hostLog.popup.header'),
  256. onPrimary:function () {
  257. this.hide();
  258. },
  259. bodyClass:Ember.View.extend({
  260. templateName:require('templates/installer/step3HostLogPopup')
  261. })
  262. });
  263. },
  264. mockBtn:function () {
  265. this.set('isSubmitDisabled', false);
  266. this.hosts.clear();
  267. var hostInfo = this.mockHostData;
  268. this.renderHosts(hostInfo);
  269. },
  270. pollBtn:function () {
  271. this.set('isSubmitDisabled', false);
  272. var data1 = this.pollData_1;
  273. var data2 = this.pollData_2;
  274. if ((this.get('pollDataCounter') / 2) === 0) {
  275. console.log("TRACE: In pollBtn function data1");
  276. var counter = parseInt(this.get('pollDataCounter')) + 1;
  277. this.set('pollDataCounter', counter.toString());
  278. this.parseHostInfo(data1);
  279. } else {
  280. console.log("TRACE: In pollBtn function data2");
  281. var counter = parseInt(this.get('pollDataCounter')) + 1;
  282. this.set('pollDataCounter', counter.toString());
  283. this.parseHostInfo(data2);
  284. }
  285. }
  286. });