step9_view.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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.WizardStep9View = Em.View.extend({
  20. templateName:require('templates/wizard/step9'),
  21. barColor:'',
  22. resultMsg:'',
  23. resultMsgColor:'',
  24. didInsertElement:function () {
  25. var controller = this.get('controller');
  26. this.get('controller.hosts').setEach('status', 'info');
  27. this.onStatus();
  28. controller.navigateStep();
  29. },
  30. barWidth:function () {
  31. var controller = this.get('controller');
  32. var barWidth = 'width: ' + controller.get('progress') + '%;';
  33. return barWidth;
  34. }.property('controller.progress'),
  35. progressMessage: function() {
  36. return Em.I18n.t('installer.step9.overallProgress').format(this.get('controller.progress'));
  37. }.property('controller.progress'),
  38. onStatus:function () {
  39. if (this.get('controller.status') === 'info') {
  40. this.set('resultMsg', '');
  41. this.set('barColor', 'progress-info');
  42. } else if (this.get('controller.status') === 'warning') {
  43. this.set('barColor', 'progress-warning');
  44. this.set('resultMsg', Em.I18n.t('installer.step9.status.warning'));
  45. this.set('resultMsgColor', 'alert-warning');
  46. } else if (this.get('controller.status') === 'failed') {
  47. this.set('barColor', 'progress-danger');
  48. console.log('TRACE: Inside error view step9');
  49. this.set('resultMsg', Em.I18n.t('installer.step9.status.failed'));
  50. this.set('resultMsgColor', 'alert-error');
  51. } else if (this.get('controller.status') === 'success') {
  52. console.log('TRACE: Inside success view step9');
  53. this.set('barColor', 'progress-success');
  54. this.set('resultMsg', Em.I18n.t('installer.step9.status.success'));
  55. this.set('resultMsgColor', 'alert-success');
  56. }
  57. }.observes('controller.status')
  58. });
  59. App.HostStatusView = Em.View.extend({
  60. tagName:'tr',
  61. obj:'null',
  62. barColor:'',
  63. didInsertElement:function () {
  64. var controller = this.get('controller');
  65. this.onStatus();
  66. },
  67. barWidth:function () {
  68. var barWidth = 'width: ' + this.get('obj.progress') + '%;';
  69. return barWidth;
  70. }.property('obj.progress'),
  71. onStatus:function () {
  72. if (this.get('obj.status') === 'info') {
  73. this.set('barColor', 'progress-info');
  74. } else if (this.get('obj.status') === 'warning') {
  75. this.set('barColor', 'progress-warning');
  76. if (this.get('obj.progress') === '100') {
  77. this.set('obj.message', Em.I18n.t('installer.step9.host.status.warning'));
  78. }
  79. } else if (this.get('obj.status') === 'failed') {
  80. this.set('barColor', 'progress-danger');
  81. if (this.get('obj.progress') === '100') {
  82. this.set('obj.message', Em.I18n.t('installer.step9.host.status.failed'));
  83. }
  84. } else if (this.get('obj.status') === 'success') {
  85. this.set('barColor', 'progress-success');
  86. if (this.get('obj.progress') === '100') {
  87. this.set('obj.message', Em.I18n.t('installer.step9.host.status.success'));
  88. }
  89. }
  90. }.observes('obj.status', 'obj.progress'),
  91. isFailed:function () {
  92. if (this.get('controller.isStepCompleted') === true && this.get('obj.status') === 'failed') {
  93. return true;
  94. } else {
  95. return false;
  96. }
  97. }.property('controller.isStepCompleted', 'controller.status'),
  98. isSuccess:function () {
  99. if (this.get('controller.isStepCompleted') === true && this.get('obj.status') === 'success') {
  100. return true;
  101. } else {
  102. return false;
  103. }
  104. }.property('controller.isStepCompleted', 'controller.status'),
  105. isWarning:function () {
  106. if (this.get('controller.isStepCompleted') === true && this.get('obj.status') === 'warning') {
  107. return true;
  108. } else {
  109. return false;
  110. }
  111. }.property('controller.isStepCompleted', 'controller.status'),
  112. isHostCompleted:function () {
  113. return this.get('obj.progress') == 100 || this.get('controller.isStepCompleted');
  114. }.property('controller.isStepCompleted', 'obj.progress'),
  115. hostLogPopup:function (event, context) {
  116. var self = this;
  117. var host = event.context;
  118. App.ModalPopup.show({
  119. header: event.context.get('name'),
  120. classNames: ['sixty-percent-width-modal'],
  121. autoHeight: false,
  122. onPrimary:function () {
  123. this.hide();
  124. },
  125. secondary:null,
  126. bodyClass:Ember.View.extend({
  127. templateName:require('templates/wizard/step9HostTasksLogPopup'),
  128. isLogWrapHidden: true,
  129. showTextArea: false,
  130. isEmptyList:true,
  131. controllerBinding:context,
  132. hostObj:function () {
  133. return this.get('parentView.obj');
  134. }.property('parentView.obj'),
  135. task: null, // set in showTaskLog; contains task info including stdout and stderr
  136. /**
  137. * sort task array by Id
  138. * @param tasks
  139. * @return {Array}
  140. */
  141. sortTasksById: function(tasks){
  142. var result = [];
  143. var id = 1;
  144. for(var i = 0; i < tasks.length; i++){
  145. id = (tasks[i].Tasks.id > id) ? tasks[i].Tasks.id : id;
  146. }
  147. while(id >= 1){
  148. for(var j = 0; j < tasks.length; j++){
  149. if(id == tasks[j].Tasks.id){
  150. result.push(tasks[j]);
  151. }
  152. }
  153. id--;
  154. }
  155. result.reverse();
  156. return result;
  157. },
  158. groupTasksByRole: function (tasks) {
  159. var sortedTasks = [];
  160. var taskRoles = tasks.mapProperty('Tasks.role').uniq();
  161. for (var i = 0; i < taskRoles.length; i++) {
  162. sortedTasks = sortedTasks.concat(tasks.filterProperty('Tasks.role', taskRoles[i]))
  163. }
  164. return sortedTasks;
  165. },
  166. visibleTasks: function () {
  167. var self = this;
  168. self.set("isEmptyList", true);
  169. if (this.get('category.value')) {
  170. var filter = this.get('category.value');
  171. var tasks = this.get('tasks');
  172. tasks.setEach("isVisible", false);
  173. if (filter == "all") {
  174. tasks.setEach("isVisible", true);
  175. }
  176. else if (filter == "pending") {
  177. tasks.filterProperty("status", "pending").setEach("isVisible", true);
  178. tasks.filterProperty("status", "queued").setEach("isVisible", true);
  179. }
  180. else if (filter == "in_progress") {
  181. tasks.filterProperty("status", "in_progress").setEach("isVisible", true);
  182. }
  183. else if (filter == "failed") {
  184. tasks.filterProperty("status", "failed").setEach("isVisible", true);
  185. }
  186. else if (filter == "completed") {
  187. tasks.filterProperty("status", "completed").setEach("isVisible", true);
  188. }
  189. else if (filter == "aborted") {
  190. tasks.filterProperty("status", "aborted").setEach("isVisible", true);
  191. }
  192. else if (filter == "timedout") {
  193. tasks.filterProperty("status", "timedout").setEach("isVisible", true);
  194. }
  195. if (tasks.filterProperty("isVisible", true).length > 0) {
  196. self.set("isEmptyList", false);
  197. }
  198. }
  199. }.observes('category', 'tasks'),
  200. categories: [
  201. Ember.Object.create({value: 'all', label: Em.I18n.t('installer.step9.hostLog.popup.categories.all') }),
  202. Ember.Object.create({value: 'pending', label: Em.I18n.t('installer.step9.hostLog.popup.categories.pending')}),
  203. Ember.Object.create({value: 'in_progress', label: Em.I18n.t('installer.step9.hostLog.popup.categories.in_progress')}),
  204. Ember.Object.create({value: 'failed', label: Em.I18n.t('installer.step9.hostLog.popup.categories.failed') }),
  205. Ember.Object.create({value: 'completed', label: Em.I18n.t('installer.step9.hostLog.popup.categories.completed') }),
  206. Ember.Object.create({value: 'aborted', label: Em.I18n.t('installer.step9.hostLog.popup.categories.aborted') }),
  207. Ember.Object.create({value: 'timedout', label: Em.I18n.t('installer.step9.hostLog.popup.categories.timedout') })
  208. ],
  209. category: null,
  210. tasks: function () {
  211. var tasksArr = [];
  212. var tasks = this.getStartedTasks(host);
  213. tasks = this.sortTasksById(tasks);
  214. tasks = this.groupTasksByRole(tasks);
  215. if (tasks.length) {
  216. tasks.forEach(function (_task) {
  217. var taskInfo = Ember.Object.create({});
  218. taskInfo.set('id', _task.Tasks.id);
  219. taskInfo.set('command', _task.Tasks.command.toLowerCase());
  220. taskInfo.set('status', App.format.taskStatus(_task.Tasks.status));
  221. taskInfo.set('role', App.format.role(_task.Tasks.role));
  222. taskInfo.set('stderr', _task.Tasks.stderr);
  223. taskInfo.set('stdout', _task.Tasks.stdout);
  224. taskInfo.set('isVisible', true);
  225. taskInfo.set('icon', '');
  226. if (taskInfo.get('status') == 'pending' || taskInfo.get('status') == 'queued') {
  227. taskInfo.set('icon', 'icon-cog');
  228. } else if (taskInfo.get('status') == 'in_progress') {
  229. taskInfo.set('icon', 'icon-cogs');
  230. } else if (taskInfo.get('status') == 'completed') {
  231. taskInfo.set('icon', ' icon-ok');
  232. } else if (taskInfo.get('status') == 'failed') {
  233. taskInfo.set('icon', 'icon-exclamation-sign');
  234. } else if (taskInfo.get('status') == 'aborted') {
  235. taskInfo.set('icon', 'icon-minus');
  236. } else if (taskInfo.get('status') == 'timedout') {
  237. taskInfo.set('icon', 'icon-time');
  238. }
  239. tasksArr.push(taskInfo);
  240. }, this);
  241. }
  242. return tasksArr;
  243. }.property('App.router.wizardStep9Controller.logTasksChangesCounter'),
  244. backToTaskList: function(event, context) {
  245. this.destroyClipBoard();
  246. this.set("isLogWrapHidden",true);
  247. },
  248. getStartedTasks:function (host) {
  249. var startedTasks = host.logTasks.filter(function (task) {
  250. return task.Tasks.status;
  251. //return task.Tasks.status != 'PENDING' && task.Tasks.status != 'QUEUED';
  252. });
  253. return startedTasks;
  254. },
  255. openTaskLogInDialog: function(){
  256. newwindow=window.open();
  257. newdocument=newwindow.document;
  258. newdocument.write($(".task-detail-log-info").html());
  259. newdocument.close();
  260. },
  261. openedTaskId: 0,
  262. openedTask: function () {
  263. if (!this.get('openedTaskId')) {
  264. return Ember.Object.create();
  265. }
  266. return this.get('tasks').findProperty('id', this.get('openedTaskId'));
  267. }.property('tasks', 'openedTaskId'),
  268. toggleTaskLog: function (event, context) {
  269. if (this.isLogWrapHidden) {
  270. var taskInfo = event.context;
  271. this.set("isLogWrapHidden", false);
  272. this.set('openedTaskId', taskInfo.id);
  273. $(".modal").scrollTop(0);
  274. $(".modal-body").scrollTop(0);
  275. } else {
  276. this.set("isLogWrapHidden", true);
  277. this.set('openedTaskId', 0);
  278. }
  279. },
  280. textTrigger:function (event) {
  281. if($(".task-detail-log-clipboard").length > 0)
  282. {
  283. this.destroyClipBoard();
  284. }else
  285. {
  286. this.createClipBoard();
  287. };
  288. },
  289. createClipBoard:function(){
  290. $(".task-detail-log-clipboard-wrap").html('<textarea class="task-detail-log-clipboard"></textarea>');
  291. $(".task-detail-log-clipboard")
  292. .html("stderr: \n"+$(".stderr").html()+"\n stdout:\n"+$(".stdout").html())
  293. .css("display","block")
  294. .width($(".task-detail-log-maintext").width())
  295. .height($(".task-detail-log-maintext").height())
  296. .select();
  297. $(".task-detail-log-maintext").css("display","none")
  298. },
  299. destroyClipBoard:function(){
  300. $(".task-detail-log-clipboard").remove();
  301. $(".task-detail-log-maintext").css("display","block");
  302. }
  303. })
  304. });
  305. }
  306. });