host_progress_popup.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. /**
  20. * App.HostPopup is for the popup that shows up upon clicking already-performed or currently-in-progress operations
  21. */
  22. App.HostPopup = Em.Object.create({
  23. hosts: null,
  24. inputData:null,
  25. serviceName:"",
  26. popupHeaderName:"",
  27. serviceController:null,
  28. updateTimeOut:100,
  29. initPopup: function (serviceName,controller) {
  30. this.set("serviceName", serviceName);
  31. this.set("serviceController", controller);
  32. this.set("inputData", null);
  33. this.set("inputData", this.get("serviceController.services"));
  34. this.set("popupHeaderName",serviceName);
  35. this.createPopup();
  36. },
  37. getHostStatus:function(tasks){
  38. if (tasks.everyProperty('Tasks.status', 'COMPLETED')) {
  39. return ['SUCCESS','icon-ok','progress-info'];
  40. }
  41. if (tasks.someProperty('Tasks.status', 'FAILED')) {
  42. return ['FAILED','icon-exclamation-sign','progress-danger'];
  43. }
  44. if (tasks.someProperty('Tasks.status', 'ABORTED')) {
  45. return ['CANCELLED','icon-minus','progress-warning'];
  46. }
  47. if (tasks.someProperty('Tasks.status', 'TIMEDOUT')) {
  48. return ['TIMEDOUT','icon-time','progress-warning'];
  49. }
  50. if (tasks.someProperty('Tasks.status', 'IN_PROGRESS') || tasks.someProperty('Tasks.status', 'UPGRADING')) {
  51. return ['IN_PROGRESS','icon-cogs','progress-info'];
  52. }
  53. return ['PENDING','icon-cog','progress-info'];
  54. },
  55. getHostProgress:function(tasks){
  56. var progress = 0;
  57. var actionsNumber = tasks.length;
  58. var completedActions = tasks.filterProperty('Tasks.status', 'COMPLETED').length
  59. + tasks.filterProperty('Tasks.status', 'FAILED').length
  60. + tasks.filterProperty('Tasks.status', 'ABORTED').length
  61. + tasks.filterProperty('Tasks.status', 'TIMEDOUT').length;
  62. var queuedActions = tasks.filterProperty('Tasks.status', 'QUEUED').length;
  63. var inProgressActions = tasks.filterProperty('Tasks.status', 'UPGRADING').length;
  64. progress = Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / actionsNumber * 100);
  65. console.log('--------INFO: progressPerHost is: ' + progress);
  66. return progress;
  67. },
  68. onHostUpdate: function () {
  69. var self=this;
  70. if(this.get("inputData")){
  71. var hostsArr = [];
  72. var hostsData = this.get("inputData").filterProperty("name" , this.get("serviceName")).objectAt(0);
  73. var hosts = hostsData.hosts;
  74. }
  75. if (hosts) {
  76. hosts.forEach(function (_host) {
  77. var tasks = _host.logTasks;
  78. var hostInfo = Ember.Object.create({});
  79. hostInfo.set('name', _host.name);
  80. hostInfo.set('publicName', _host.publicName);
  81. hostInfo.set('progress', 0);
  82. hostInfo.set('status', App.format.taskStatus("PENDING"));
  83. hostInfo.set('serviceName', hostsData.name);
  84. hostInfo.set('isVisible', true);
  85. hostInfo.set('icon', "icon-cog");
  86. hostInfo.set('barColor', "progress-info");
  87. hostInfo.set('barWidth', "width:0%;");
  88. tasks = self.sortTasksById(tasks);
  89. tasks = self.groupTasksByRole(tasks);
  90. var tasksArr = [];
  91. if (tasks.length) {
  92. var hostStatus = self.getHostStatus(tasks);
  93. var hostProgress= self.getHostProgress(tasks);
  94. hostInfo.set('status', App.format.taskStatus(hostStatus[0]));
  95. hostInfo.set('icon', hostStatus[1]);
  96. hostInfo.set('barColor', hostStatus[2]);
  97. hostInfo.set('progress', hostProgress);
  98. hostInfo.set('barWidth', "width:"+hostProgress+"%;");
  99. tasks.forEach(function (_task) {
  100. var taskInfo = Ember.Object.create({});
  101. taskInfo.set('id', _task.Tasks.id);
  102. taskInfo.set('hostName', _host.name);
  103. taskInfo.set('command', _task.Tasks.command.toLowerCase());
  104. taskInfo.set('status', App.format.taskStatus(_task.Tasks.status));
  105. taskInfo.set('role', App.format.role(_task.Tasks.role));
  106. taskInfo.set('stderr', _task.Tasks.stderr);
  107. taskInfo.set('stdout', _task.Tasks.stdout);
  108. taskInfo.set('isVisible', true);
  109. taskInfo.set('icon', 'icon-cogs');
  110. if (taskInfo.get('status') == 'pending' || taskInfo.get('status') == 'queued') {
  111. taskInfo.set('icon', 'icon-cog');
  112. } else if (taskInfo.get('status') == 'in_progress') {
  113. taskInfo.set('icon', 'icon-cogs');
  114. } else if (taskInfo.get('status') == 'completed') {
  115. taskInfo.set('icon', ' icon-ok');
  116. } else if (taskInfo.get('status') == 'failed') {
  117. taskInfo.set('icon', 'icon-exclamation-sign');
  118. } else if (taskInfo.get('status') == 'aborted') {
  119. taskInfo.set('icon', 'icon-minus');
  120. } else if (taskInfo.get('status') == 'timedout') {
  121. taskInfo.set('icon', 'icon-time');
  122. }
  123. tasksArr.push(taskInfo);
  124. }, this);
  125. }
  126. hostInfo.set('tasks', tasksArr);
  127. hostsArr.push(hostInfo);
  128. }, this);
  129. }
  130. self.set("hosts",hostsArr);
  131. }.observes("this.inputData"),
  132. sortTasksById: function(tasks){
  133. var result = [];
  134. var id = 1;
  135. for(var i = 0; i < tasks.length; i++){
  136. id = (tasks[i].Tasks.id > id) ? tasks[i].Tasks.id : id;
  137. }
  138. while(id >= 1){
  139. for(var j = 0; j < tasks.length; j++){
  140. if(id == tasks[j].Tasks.id){
  141. result.push(tasks[j]);
  142. }
  143. }
  144. id--;
  145. }
  146. result.reverse();
  147. return result;
  148. },
  149. groupTasksByRole: function (tasks) {
  150. var sortedTasks = [];
  151. var taskRoles = tasks.mapProperty('Tasks.role').uniq();
  152. for (var i = 0; i < taskRoles.length; i++) {
  153. sortedTasks = sortedTasks.concat(tasks.filterProperty('Tasks.role', taskRoles[i]))
  154. }
  155. return sortedTasks;
  156. },
  157. createPopup: function () {
  158. var self = this;
  159. var hostsInfo = this.get("hosts");
  160. return App.ModalPopup.show({
  161. headerClass: Ember.View.extend({
  162. controller: this,
  163. template:Ember.Handlebars.compile('{{popupHeaderName}}')
  164. }),
  165. classNames: ['sixty-percent-width-modal'],
  166. autoHeight: false,
  167. onPrimary: function () {
  168. this.hide();
  169. },
  170. secondary: null,
  171. bodyClass: Ember.View.extend({
  172. templateName: require('templates/common/host_progress_popup'),
  173. isLogWrapHidden: true,
  174. isTaskListHidden: true,
  175. isHostListHidden: false,
  176. showTextArea: false,
  177. isHostEmptyList: true,
  178. isTasksEmptyList: true,
  179. controller:this,
  180. hosts:hostsInfo,
  181. tasks:null,
  182. didInsertElement:function(){
  183. this.setSelectCount(this.get("hosts"));
  184. },
  185. updateHostInfo:function(){
  186. this.get("controller").set("inputData", null);
  187. this.get("controller").set("inputData", this.get("controller.serviceController.services"));
  188. this.set("hosts", this.get("controller.hosts"));
  189. }.observes("this.controller.serviceController.serviceTimestamp"),
  190. visibleHosts: function () {
  191. this.set("isHostEmptyList", true);
  192. if (this.get('hostCategory.value')) {
  193. var filter = this.get('hostCategory.value');
  194. var hosts = this.get('hosts');
  195. hosts.setEach("isVisible", false);
  196. this.setVisability(filter,hosts);
  197. if (hosts.filterProperty("isVisible", true).length > 0) {
  198. this.set("isHostEmptyList", false);
  199. }
  200. }
  201. }.observes('hostCategory', 'hosts'),
  202. visibleTasks: function () {
  203. this.set("isTasksEmptyList", true);
  204. if (this.get('taskCategory.value')&&this.get('tasks')) {
  205. var filter = this.get('taskCategory.value');
  206. var tasks = this.get('tasks');
  207. this.setVisability(filter,tasks);
  208. if (tasks.filterProperty("isVisible", true).length > 0) {
  209. this.set("isTasksEmptyList", false);
  210. }
  211. }
  212. }.observes('taskCategory', 'tasks'),
  213. setVisability: function(filter,obj){
  214. obj.setEach("isVisible", false);
  215. if (filter == "all") {
  216. obj.setEach("isVisible", true);
  217. }
  218. else if (filter == "pending") {
  219. obj.filterProperty("status", "pending").setEach("isVisible", true);
  220. obj.filterProperty("status", "queued").setEach("isVisible", true);
  221. }
  222. else if (filter == "in_progress") {
  223. obj.filterProperty("status", "in_progress").setEach("isVisible", true);
  224. obj.filterProperty("status", "upgrading").setEach("isVisible", true);
  225. }
  226. else if (filter == "failed") {
  227. obj.filterProperty("status", "failed").setEach("isVisible", true);
  228. }
  229. else if (filter == "completed") {
  230. obj.filterProperty("status", "completed").setEach("isVisible", true);
  231. obj.filterProperty("status", "success").setEach("isVisible", true);
  232. }
  233. else if (filter == "aborted") {
  234. obj.filterProperty("status", "aborted").setEach("isVisible", true);
  235. }
  236. else if (filter == "timedout") {
  237. obj.filterProperty("status", "timedout").setEach("isVisible", true);
  238. }
  239. },
  240. categories: [
  241. Ember.Object.create({value: 'all', label: Em.I18n.t('installer.step9.hostLog.popup.categories.all') }),
  242. Ember.Object.create({value: 'pending', label: Em.I18n.t('installer.step9.hostLog.popup.categories.pending')}),
  243. Ember.Object.create({value: 'in_progress', label: Em.I18n.t('installer.step9.hostLog.popup.categories.in_progress')}),
  244. Ember.Object.create({value: 'failed', label: Em.I18n.t('installer.step9.hostLog.popup.categories.failed') }),
  245. Ember.Object.create({value: 'completed', label: Em.I18n.t('installer.step9.hostLog.popup.categories.completed') }),
  246. Ember.Object.create({value: 'aborted', label: Em.I18n.t('installer.step9.hostLog.popup.categories.aborted') }),
  247. Ember.Object.create({value: 'timedout', label: Em.I18n.t('installer.step9.hostLog.popup.categories.timedout') })
  248. ],
  249. hostCategory: null,
  250. taskCategory: null,
  251. setSelectCount:function(obj){
  252. if(!obj) return;
  253. var countAll = obj.length;
  254. var countPending = obj.filterProperty("status",'pending').length;
  255. var countInProgress = obj.filterProperty("status",'in_progress').length;
  256. var countFailed = obj.filterProperty("status",'failed').length;
  257. var countCompleted = obj.filterProperty("status",'success').length + obj.filterProperty("status",'completed').length;
  258. var countAborted = obj.filterProperty("status",'aborted').length;
  259. var countTimedout = obj.filterProperty("status",'timedout').length;
  260. this.categories.filterProperty("value",'all').objectAt(0).set("label","All ("+countAll+")");
  261. this.categories.filterProperty("value",'pending').objectAt(0).set("label","Pending ("+countPending+")");
  262. this.categories.filterProperty("value",'in_progress').objectAt(0).set("label","In Progress ("+countInProgress+")");
  263. this.categories.filterProperty("value",'failed').objectAt(0).set("label","Failed ("+countFailed+")");
  264. this.categories.filterProperty("value",'completed').objectAt(0).set("label","Success ("+countCompleted+")");
  265. this.categories.filterProperty("value",'aborted').objectAt(0).set("label","Aborted ("+countAborted+")");
  266. this.categories.filterProperty("value",'timedout').objectAt(0).set("label","Timedout ("+countTimedout+")");
  267. },
  268. updateSelectView:function(){
  269. if(!this.get('isHostListHidden')){
  270. this.setSelectCount(this.get("hosts"))
  271. }else if(!this.get('isTaskListHidden')){
  272. this.setSelectCount(this.get("tasks"))
  273. }
  274. }.observes('hosts','isTaskListHidden','isHostListHidden'),
  275. backToTaskList: function (event, context) {
  276. this.destroyClipBoard();
  277. this.set("openedTaskId",0);
  278. this.set("isLogWrapHidden", true);
  279. this.set("isTaskListHidden", false);
  280. },
  281. backToHostList: function (event, context) {
  282. this.set("isHostListHidden", false);
  283. this.set("isTaskListHidden", true);
  284. this.set("tasks", null);
  285. this.get("controller").set("popupHeaderName",this.get("controller.serviceName"));
  286. },
  287. gotoTasks: function(event, context){
  288. var taskInfo = event.context.tasks;
  289. if(taskInfo.length){
  290. this.get("controller").set("popupHeaderName", taskInfo.objectAt(0).hostName);
  291. }
  292. this.set('tasks', taskInfo);
  293. this.set("isHostListHidden", true);
  294. this.set("isTaskListHidden", false);
  295. $(".modal").scrollTop(0);
  296. $(".modal-body").scrollTop(0);
  297. },
  298. openTaskLogInDialog: function () {
  299. newwindow = window.open();
  300. newdocument = newwindow.document;
  301. newdocument.write($(".task-detail-log-info").html());
  302. newdocument.close();
  303. },
  304. openedTaskId: 0,
  305. openedTask: function () {
  306. if (!this.get('openedTaskId')) {
  307. return Ember.Object.create();
  308. }
  309. return this.get('tasks').findProperty('id', this.get('openedTaskId'));
  310. }.property('tasks', 'openedTaskId'),
  311. toggleTaskLog: function (event, context) {
  312. var taskInfo = event.context;
  313. this.set("isLogWrapHidden", false);
  314. this.set("isHostListHidden", true);
  315. this.set("isTaskListHidden", true);
  316. this.set('openedTaskId', taskInfo.id);
  317. $(".modal").scrollTop(0);
  318. $(".modal-body").scrollTop(0);
  319. },
  320. textTrigger: function (event) {
  321. if ($(".task-detail-log-clipboard").length > 0) {
  322. this.destroyClipBoard();
  323. } else {
  324. this.createClipBoard();
  325. }
  326. },
  327. createClipBoard: function () {
  328. $(".task-detail-log-clipboard-wrap").html('<textarea class="task-detail-log-clipboard"></textarea>');
  329. $(".task-detail-log-clipboard")
  330. .html("stderr: \n" + $(".stderr").html() + "\n stdout:\n" + $(".stdout").html())
  331. .css("display", "block")
  332. .width($(".task-detail-log-maintext").width())
  333. .height($(".task-detail-log-maintext").height())
  334. .select();
  335. $(".task-detail-log-maintext").css("display", "none")
  336. },
  337. destroyClipBoard: function () {
  338. $(".task-detail-log-clipboard").remove();
  339. $(".task-detail-log-maintext").css("display", "block");
  340. }
  341. })
  342. });
  343. }
  344. });