host_progress_popup.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  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. servicesInfo: null,
  24. hosts: null,
  25. inputData: null,
  26. serviceName: "",
  27. currentServiceId: null,
  28. previousServiceId: null,
  29. popupHeaderName: "",
  30. serviceController: null,
  31. showServices: false,
  32. currentHostName: null,
  33. isPopup: null,
  34. /**
  35. * Sort object array
  36. * @param array
  37. * @param p
  38. * @return {*}
  39. */
  40. sortArray: function (array, p) {
  41. return array.sort(function (a, b) {
  42. return (a[p] > b[p]) ? 1 : (a[p] < b[p]) ? -1 : 0;
  43. });
  44. },
  45. /**
  46. * Entering point of this component
  47. * @param serviceName
  48. * @param controller
  49. * @param showServices
  50. */
  51. initPopup: function (serviceName, controller, showServices) {
  52. if (!showServices) {
  53. this.clearHostPopup();
  54. this.set("popupHeaderName", serviceName);
  55. }
  56. this.set("serviceName", serviceName);
  57. this.set("serviceController", controller);
  58. this.set("showServices", showServices);
  59. this.set("inputData", this.get("serviceController.services"));
  60. if(this.get('showServices')){
  61. this.onServiceUpdate();
  62. } else {
  63. this.onHostUpdate();
  64. }
  65. return this.createPopup();
  66. },
  67. clearHostPopup: function () {
  68. this.set('servicesInfo', null);
  69. this.set('hosts', null);
  70. this.set('inputData', null);
  71. this.set('serviceName', "");
  72. this.set('currentServiceId', null);
  73. this.set('previousServiceId', null);
  74. this.set('popupHeaderName', "");
  75. this.set('serviceController', null);
  76. this.set('showServices', false);
  77. this.set('currentHostName', null);
  78. this.get('isPopup')?this.get('isPopup').remove():null;
  79. },
  80. /**
  81. * Depending on tasks status
  82. * @param tasks
  83. * @return {Array} [Status, Icon type, Progressbar color, is IN_PROGRESS]
  84. */
  85. getStatus: function(tasks){
  86. var isCompleted = true;
  87. var status;
  88. var tasksLength = tasks.length;
  89. var isFailed = false;
  90. var isAborted = false;
  91. var isTimedout = false;
  92. var isInProgress = false;
  93. for (var i = 0; i < tasksLength; i++) {
  94. if (tasks[i].Tasks.status !== 'COMPLETED') {
  95. isCompleted = false;
  96. }
  97. if(tasks[i].Tasks.status === 'FAILED'){
  98. isFailed = true;
  99. }
  100. if (tasks[i].Tasks.status === 'ABORTED') {
  101. isAborted = true;
  102. }
  103. if (tasks[i].Tasks.status === 'TIMEDOUT') {
  104. isTimedout = true;
  105. }
  106. if (tasks[i].Tasks.status === 'IN_PROGRESS') {
  107. isInProgress = true;
  108. }
  109. }
  110. if (isFailed) {
  111. status = ['FAILED', 'icon-exclamation-sign', 'progress-danger', false];
  112. } else if (isAborted) {
  113. status = ['CANCELLED', 'icon-minus', 'progress-warning', false];
  114. } else if (isTimedout) {
  115. status = ['TIMEDOUT', 'icon-time', 'progress-warning', false];
  116. } else if (isInProgress) {
  117. status = ['IN_PROGRESS', 'icon-cogs', 'progress-info', true];
  118. }
  119. if(status){
  120. return status;
  121. } else if(isCompleted){
  122. return ['SUCCESS', 'icon-ok', 'progress-success', false];
  123. } else {
  124. return ['PENDING', 'icon-cog', 'progress-info', true];
  125. }
  126. },
  127. /**
  128. * Progress of host or service depending on tasks status
  129. * @param tasks
  130. * @return {Number} percent of completion
  131. */
  132. getProgress: function (tasks) {
  133. var completedActions = 0;
  134. var queuedActions = 0;
  135. var inProgressActions = 0;
  136. tasks.forEach(function(task){
  137. if(['COMPLETED', 'FAILED', 'ABORTED', 'TIMEDOUT'].contains(task.Tasks.status)){
  138. completedActions++;
  139. } else if(task.Tasks.status === 'QUEUED'){
  140. queuedActions++;
  141. } else if(task.Tasks.status === 'IN_PROGRESS'){
  142. inProgressActions++;
  143. }
  144. });
  145. return Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / tasks.length * 100);
  146. },
  147. /**
  148. * Count number of operations for select box options
  149. * @param obj
  150. * @param categories
  151. */
  152. setSelectCount: function (obj, categories) {
  153. if (!obj) return;
  154. var countAll = obj.length;
  155. var countPending = 0;
  156. var countInProgress = 0;
  157. var countFailed = 0;
  158. var countCompleted = 0;
  159. var countAborted = 0;
  160. var countTimedout = 0;
  161. obj.forEach(function(item){
  162. switch (item.status){
  163. case 'pending':
  164. countPending++;
  165. break;
  166. case 'queued':
  167. countPending++;
  168. break;
  169. case 'in_progress':
  170. countInProgress++;
  171. break;
  172. case 'failed':
  173. countFailed++;
  174. break;
  175. case 'success':
  176. countCompleted++;
  177. break;
  178. case 'completed':
  179. countCompleted++;
  180. break;
  181. case 'aborted':
  182. countAborted++;
  183. break;
  184. case 'timedout':
  185. countTimedout++;
  186. break;
  187. }
  188. }, this);
  189. categories.findProperty("value", 'all').set("count", countAll);
  190. categories.findProperty("value", 'pending').set("count", countPending);
  191. categories.findProperty("value", 'in_progress').set("count", countInProgress);
  192. categories.findProperty("value", 'failed').set("count", countFailed);
  193. categories.findProperty("value", 'completed').set("count", countCompleted);
  194. categories.findProperty("value", 'aborted').set("count", countAborted);
  195. categories.findProperty("value", 'timedout').set("count", countTimedout);
  196. },
  197. /**
  198. * For Background operation popup calculate number of running Operations, and set popup header
  199. */
  200. setBackgroundOperationHeader: function () {
  201. if (this.get("showServices")) {
  202. var numRunning = App.router.get('backgroundOperationsController.allOperationsCount');
  203. this.set("popupHeaderName", numRunning + Em.I18n.t('hostPopup.header.postFix'));
  204. } else {
  205. this.set("popupHeaderName", this.get("serviceName"));
  206. }
  207. },
  208. /**
  209. * Create services obj data structure for popup
  210. * Set data for services
  211. */
  212. onServiceUpdate: function () {
  213. if (this.get('showServices') && this.get("inputData")) {
  214. var self = this;
  215. var allNewServices = [];
  216. this.set("servicesInfo", null);
  217. this.get("inputData").forEach(function (service) {
  218. var newService = Ember.Object.create({
  219. id: service.id,
  220. displayName: service.displayName,
  221. detailMessage: service.detailMessage,
  222. message: service.message,
  223. progress: 0,
  224. status: App.format.taskStatus("PENDING"),
  225. name: service.name,
  226. isVisible: true,
  227. icon: 'icon-cog',
  228. barColor: 'progress-info',
  229. barWidth: 'width:0%;'
  230. });
  231. var allTasks = service.tasks;
  232. if (allTasks.length > 0) {
  233. var status = self.getStatus(allTasks);
  234. var progress = self.getProgress(allTasks);
  235. newService.set('status', App.format.taskStatus(status[0]));
  236. newService.set('icon', status[1]);
  237. newService.set('barColor', status[2]);
  238. newService.set('isInProgress', status[3]);
  239. newService.set('progress', progress);
  240. newService.set('barWidth', "width:" + progress + "%;");
  241. }
  242. allNewServices.push(newService);
  243. });
  244. self.set('servicesInfo', allNewServices);
  245. if (this.get("serviceName") == "") this.setBackgroundOperationHeader();
  246. }
  247. },
  248. /**
  249. * update icon of task depending on its status
  250. * @param taskInfo
  251. */
  252. updateTaskIcon: function(taskInfo){
  253. if (taskInfo.get('status') == 'pending' || taskInfo.get('status') == 'queued') {
  254. taskInfo.set('icon', 'icon-cog');
  255. } else if (taskInfo.get('status') == 'in_progress') {
  256. taskInfo.set('icon', 'icon-cogs');
  257. } else if (taskInfo.get('status') == 'completed') {
  258. taskInfo.set('icon', ' icon-ok');
  259. } else if (taskInfo.get('status') == 'failed') {
  260. taskInfo.set('icon', 'icon-exclamation-sign');
  261. } else if (taskInfo.get('status') == 'aborted') {
  262. taskInfo.set('icon', 'icon-minus');
  263. } else if (taskInfo.get('status') == 'timedout') {
  264. taskInfo.set('icon', 'icon-time');
  265. }
  266. },
  267. /**
  268. * Create hosts and tasks data structure for popup
  269. * Set data for hosts and tasks
  270. */
  271. onHostUpdate: function () {
  272. var self = this;
  273. if (this.get("inputData")) {
  274. var hostsArr = [];
  275. var hostsData = this.get("inputData");
  276. var hostsMap = {};
  277. if (!this.get("showServices") || this.get("serviceName")) {
  278. if (this.get("currentServiceId") != null) {
  279. hostsData = hostsData.findProperty("id", this.get("currentServiceId"));
  280. } else {
  281. hostsData = hostsData.findProperty("name", this.get("serviceName"));
  282. }
  283. if (hostsData) {
  284. if (hostsData.hostsMap) {
  285. hostsMap = hostsData.hostsMap;
  286. } else if (hostsData.hosts) {
  287. //hosts data come from wizard as array
  288. hostsData.hosts.forEach(function (_host) {
  289. hostsMap[_host.name] = _host;
  290. });
  291. }
  292. }
  293. }
  294. var existedHosts = self.get('hosts');
  295. if (existedHosts && this.get('currentServiceId') === this.get('previousServiceId')) {
  296. existedHosts.forEach(function (host) {
  297. var newHostInfo = hostsMap[host.get('name')];
  298. if (newHostInfo) {
  299. var hostStatus = self.getStatus(newHostInfo.logTasks);
  300. var hostProgress = self.getProgress(newHostInfo.logTasks);
  301. host.set('status', App.format.taskStatus(hostStatus[0]));
  302. host.set('icon', hostStatus[1]);
  303. host.set('barColor', hostStatus[2]);
  304. host.set('isInProgress', hostStatus[3]);
  305. host.set('progress', hostProgress);
  306. host.set('barWidth', "width:" + hostProgress + "%;");
  307. var existTasks = host.get('tasks');
  308. var newTasks = newHostInfo.logTasks;
  309. if (existTasks && newTasks && existTasks.length == newTasks.length) {
  310. // Same number of source and destinations
  311. var existTaskMap = {};
  312. var newTaskMap = {};
  313. host.get('tasks').forEach(function (taskInfo) {
  314. var id = taskInfo.get('id');
  315. existTaskMap[id] = taskInfo;
  316. });
  317. var newTasksArray = [];
  318. newTasks.forEach(function (newTask) {
  319. var existTask = existTaskMap[newTask.Tasks.id];
  320. if (existTask) {
  321. // reuse
  322. existTask.set('status', App.format.taskStatus(newTask.Tasks.status));
  323. existTask.set('stderr', newTask.Tasks.stderr);
  324. existTask.set('stdout', newTask.Tasks.stdout);
  325. self.updateTaskIcon(existTask);
  326. delete existTaskMap[newTask.Tasks.id];
  327. } else {
  328. // create new
  329. var taskInfo = Ember.Object.create({
  330. id: newTask.Tasks.id,
  331. hostName: newHostInfo.publicName,
  332. command: newTask.Tasks.command.toLowerCase(),
  333. status: App.format.taskStatus(newTask.Tasks.status),
  334. role: App.format.role(newTask.Tasks.role),
  335. stderr: newTask.Tasks.stderr,
  336. stdout: newTask.Tasks.stdout,
  337. isVisible: true,
  338. icon: 'icon-cogs'
  339. });
  340. self.updateTaskIcon(taskInfo);
  341. newTasksArray.push(taskInfo);
  342. }
  343. });
  344. for (var id in existTaskMap) {
  345. host.get('tasks').removeObject(existTaskMap[id]);
  346. }
  347. if (newTasksArray.length) {
  348. host.get('tasks').pushObjects(newTasksArray);
  349. }
  350. } else {
  351. // Tasks have changed
  352. var tasksArr = [];
  353. newTasks.forEach(function (newTask) {
  354. var taskInfo = Ember.Object.create({
  355. id: newTask.Tasks.id,
  356. hostName: newHostInfo.publicName,
  357. command: newTask.Tasks.command.toLowerCase(),
  358. status: App.format.taskStatus(newTask.Tasks.status),
  359. role: App.format.role(newTask.Tasks.role),
  360. stderr: newTask.Tasks.stderr,
  361. stdout: newTask.Tasks.stdout,
  362. isVisible: true,
  363. icon: 'icon-cogs'
  364. });
  365. self.updateTaskIcon(taskInfo);
  366. tasksArr.push(taskInfo);
  367. });
  368. host.set('tasks', tasksArr);
  369. }
  370. }
  371. }, this);
  372. } else {
  373. for (var hostName in hostsMap) {
  374. var _host = hostsMap[hostName];
  375. var tasks = _host.logTasks;
  376. var hostInfo = Ember.Object.create({
  377. name: hostName,
  378. publicName: _host.publicName,
  379. progress: 0,
  380. status: App.format.taskStatus("PENDING"),
  381. serviceName: _host.serviceName,
  382. isVisible: true,
  383. icon: "icon-cog",
  384. barColor: "progress-info",
  385. barWidth: "width:0%;"
  386. });
  387. var tasksArr = [];
  388. if (tasks.length) {
  389. tasks = self.sortTasksById(tasks);
  390. var hostStatus = self.getStatus(tasks);
  391. var hostProgress = self.getProgress(tasks);
  392. hostInfo.set('status', App.format.taskStatus(hostStatus[0]));
  393. hostInfo.set('icon', hostStatus[1]);
  394. hostInfo.set('barColor', hostStatus[2]);
  395. hostInfo.set('isInProgress', hostStatus[3]);
  396. hostInfo.set('progress', hostProgress);
  397. hostInfo.set('barWidth', "width:" + hostProgress + "%;");
  398. tasks.forEach(function (_task) {
  399. var taskInfo = Ember.Object.create({
  400. id: _task.Tasks.id,
  401. hostName: _host.publicName,
  402. command: _task.Tasks.command.toLowerCase(),
  403. status: App.format.taskStatus(_task.Tasks.status),
  404. role: App.format.role(_task.Tasks.role),
  405. stderr: _task.Tasks.stderr,
  406. stdout: _task.Tasks.stdout,
  407. isVisible: true,
  408. icon: 'icon-cogs'
  409. });
  410. this.updateTaskIcon(taskInfo);
  411. tasksArr.push(taskInfo);
  412. }, this);
  413. }
  414. hostInfo.set('tasks', tasksArr);
  415. hostsArr.push(hostInfo);
  416. }
  417. //sort hosts by name
  418. this.sortArray(hostsArr, "name");
  419. hostsArr.setEach("serviceName", this.get("serviceName"));
  420. self.set("hosts", hostsArr);
  421. self.set('previousServiceId', this.get('currentServiceId'));
  422. }
  423. }
  424. },
  425. /**
  426. * Sort tasks by it`s id
  427. * @param tasks
  428. * @return {Array}
  429. */
  430. sortTasksById: function (tasks) {
  431. return tasks.sort(function (a, b) {
  432. return (a.Tasks.id > b.Tasks.id) ? 1 : (a.Tasks.id < b.Tasks.id) ? -1 : 0;
  433. });
  434. },
  435. /**
  436. * Show popup
  437. * @return PopupObject For testing purposes
  438. */
  439. createPopup: function () {
  440. var self = this;
  441. var hostsInfo = this.get("hosts");
  442. var servicesInfo = this.get("servicesInfo");
  443. var showServices = this.get('showServices');
  444. var categoryObject = Em.Object.extend({
  445. value: '',
  446. count: 0,
  447. labelPath: '',
  448. label: function(){
  449. return Em.I18n.t(this.get('labelPath')).format(this.get('count'));
  450. }.property('count')
  451. });
  452. self.set('isPopup', App.ModalPopup.show({
  453. //no need to track is it loaded when popup contain only list of hosts
  454. isLoaded: !showServices,
  455. isOpen: false,
  456. didInsertElement: function(){
  457. this.set('isOpen', true);
  458. },
  459. headerClass: Ember.View.extend({
  460. controller: this,
  461. template: Ember.Handlebars.compile('{{popupHeaderName}}')
  462. }),
  463. classNames: ['sixty-percent-width-modal'],
  464. autoHeight: false,
  465. closeModelPopup: function () {
  466. this.set('isOpen', false);
  467. if(showServices){
  468. $(this.get('element')).detach();
  469. } else {
  470. this.hide();
  471. self.set('isPopup', null);
  472. }
  473. },
  474. onPrimary: function () {
  475. this.closeModelPopup();
  476. },
  477. onClose: function () {
  478. this.closeModelPopup();
  479. },
  480. secondary: null,
  481. bodyClass: Ember.View.extend({
  482. templateName: require('templates/common/host_progress_popup'),
  483. isLogWrapHidden: true,
  484. isTaskListHidden: true,
  485. isHostListHidden: true,
  486. isServiceListHidden: false,
  487. showTextArea: false,
  488. isServiceEmptyList: true,
  489. isHostEmptyList: true,
  490. isTasksEmptyList: true,
  491. controller: this,
  492. hosts: self.get("hosts"),
  493. services: self.get('servicesInfo'),
  494. tasks: function () {
  495. if (!this.get('controller.currentHostName')) return [];
  496. if (this.get('hosts') && this.get('hosts').length) {
  497. var currentHost = this.get('hosts').findProperty('name', this.get('controller.currentHostName'));
  498. if (currentHost) {
  499. return currentHost.get('tasks');
  500. }
  501. }
  502. return [];
  503. }.property('hosts.@each.tasks', 'hosts.@each.tasks.@each.status'),
  504. didInsertElement: function () {
  505. this.setOnStart();
  506. },
  507. /**
  508. * Preset values on init
  509. */
  510. setOnStart: function () {
  511. if (this.get("controller.showServices")) {
  512. this.get('controller').setSelectCount(this.get("services"), this.get('categories'));
  513. } else {
  514. this.set("isHostListHidden", false);
  515. this.set("isServiceListHidden", true);
  516. }
  517. },
  518. /**
  519. * force popup to show list of operations
  520. */
  521. resetState: function(){
  522. if(this.get('parentView.isOpen')){
  523. this.set('isLogWrapHidden', true);
  524. this.set('isTaskListHidden', true);
  525. this.set('isHostListHidden', true);
  526. this.set('isServiceListHidden', false);
  527. this.get("controller").setBackgroundOperationHeader();
  528. this.setOnStart();
  529. }
  530. }.observes('parentView.isOpen'),
  531. /**
  532. * When popup is opened, and data after polling has changed, update this data in component
  533. */
  534. updateHostInfo: function () {
  535. if(!this.get('parentView.isOpen')) return;
  536. this.set('parentView.isLoaded', false);
  537. this.get("controller").set("inputData", this.get("controller.serviceController.services"));
  538. this.get("controller").onServiceUpdate();
  539. this.get("controller").onHostUpdate();
  540. this.set('parentView.isLoaded', true);
  541. //push hosts into view when none or all hosts are loaded
  542. if(this.get('hosts') == null || this.get('hosts').length === this.get("controller.hosts").length){
  543. this.set("hosts", this.get("controller.hosts"));
  544. }
  545. this.set("services", this.get("controller.servicesInfo"));
  546. }.observes("controller.serviceController.serviceTimestamp"),
  547. /**
  548. * Depending on service filter, set which services should be shown
  549. */
  550. visibleServices: function () {
  551. if (this.get("services")) {
  552. this.set("isServiceEmptyList", true);
  553. if (this.get('serviceCategory.value')) {
  554. var filter = this.get('serviceCategory.value');
  555. var services = this.get('services');
  556. this.set("isServiceEmptyList", this.setVisibility(filter, services));
  557. }
  558. }
  559. }.observes('serviceCategory', 'services'),
  560. /**
  561. * Depending on hosts filter, set which hosts should be shown
  562. */
  563. visibleHosts: function () {
  564. this.set("isHostEmptyList", true);
  565. if (this.get('hostCategory.value') && this.get('hosts')) {
  566. var filter = this.get('hostCategory.value');
  567. var hosts = this.get('hosts');
  568. this.set("isHostEmptyList", this.setVisibility(filter, hosts));
  569. }
  570. }.observes('hostCategory', 'hosts'),
  571. /**
  572. * Depending on tasks filter, set which tasks should be shown
  573. */
  574. visibleTasks: function () {
  575. this.set("isTasksEmptyList", true);
  576. if (this.get('taskCategory.value') && this.get('tasks')) {
  577. var filter = this.get('taskCategory.value');
  578. var tasks = this.get('tasks');
  579. this.set("isTasksEmptyList", this.setVisibility(filter, tasks));
  580. }
  581. }.observes('taskCategory', 'tasks'),
  582. /**
  583. * Depending on selected filter type, set object visibility value
  584. * @param filter
  585. * @param obj
  586. * @return {Boolean} isEmptyList
  587. */
  588. setVisibility: function (filter, obj) {
  589. var isEmptyList = true;
  590. if (filter == "all") {
  591. obj.setEach("isVisible", true);
  592. isEmptyList = !(obj.length > 0);
  593. } else {
  594. obj.forEach(function(item){
  595. if (filter == "pending") {
  596. item.set('isVisible', ["pending", "queued"].contains(item.status));
  597. } else if (filter == "in_progress") {
  598. item.set('isVisible', ["in_progress", "upgrading"].contains(item.status));
  599. } else if (filter == "failed") {
  600. item.set('isVisible', (item.status === "failed"));
  601. } else if (filter == "completed") {
  602. item.set('isVisible', ["completed", "success"].contains(item.status));
  603. } else if (filter == "aborted") {
  604. item.set('isVisible', (item.status === "aborted"));
  605. } else if (filter == "timedout") {
  606. item.set('isVisible', (item.status === "timedout"));
  607. }
  608. isEmptyList = (isEmptyList) ? !item.get('isVisible') : false;
  609. })
  610. }
  611. return isEmptyList;
  612. },
  613. /**
  614. * Select box, display names and values
  615. */
  616. categories: [
  617. categoryObject.create({value: 'all', labelPath: 'hostPopup.status.category.all'}),
  618. categoryObject.create({value: 'pending', labelPath: 'hostPopup.status.category.pending'}),
  619. categoryObject.create({value: 'in_progress', labelPath: 'hostPopup.status.category.inProgress'}),
  620. categoryObject.create({value: 'failed', labelPath: 'hostPopup.status.category.failed'}),
  621. categoryObject.create({value: 'completed', labelPath: 'hostPopup.status.category.success'}),
  622. categoryObject.create({value: 'aborted', labelPath: 'hostPopup.status.category.aborted'}),
  623. categoryObject.create({value: 'timedout', labelPath: 'hostPopup.status.category.timedout'})
  624. ],
  625. /**
  626. * Selected option is binded to this values
  627. */
  628. serviceCategory: null,
  629. hostCategory: null,
  630. taskCategory: null,
  631. /**
  632. * Depending on currently viewed tab, call setSelectCount function
  633. */
  634. updateSelectView: function () {
  635. if (!this.get('isHostListHidden')) {
  636. //since lazy loading used for hosts, we need to get hosts info directly from controller, that always contains entire array of data
  637. this.get('controller').setSelectCount(this.get("controller.hosts"), this.get('categories'));
  638. } else if (!this.get('isTaskListHidden')) {
  639. this.get('controller').setSelectCount(this.get("tasks"), this.get('categories'));
  640. } else if (!this.get('isServiceListHidden')) {
  641. this.get('controller').setSelectCount(this.get("services"), this.get('categories'));
  642. }
  643. }.observes('hosts', 'isTaskListHidden', 'isHostListHidden', 'services.length', 'services.@each.status'),
  644. /**
  645. * Onclick handler for button <-Tasks
  646. * @param event
  647. * @param context
  648. */
  649. backToTaskList: function (event, context) {
  650. this.destroyClipBoard();
  651. this.set("openedTaskId", 0);
  652. this.set("isLogWrapHidden", true);
  653. this.set("isTaskListHidden", false);
  654. },
  655. /**
  656. * Onclick handler for button <-Hosts
  657. * @param event
  658. * @param context
  659. */
  660. backToHostList: function (event, context) {
  661. this.set("isHostListHidden", false);
  662. this.set("isTaskListHidden", true);
  663. this.set("tasks", null);
  664. this.get("controller").set("popupHeaderName", this.get("controller.serviceName"));
  665. },
  666. /**
  667. * Onclick handler for button <-Services
  668. * @param event
  669. * @param context
  670. */
  671. backToServiceList: function (event, context) {
  672. this.get("controller").set("serviceName", "");
  673. this.set("isHostListHidden", true);
  674. this.set("isServiceListHidden", false);
  675. this.set("isTaskListHidden", true);
  676. this.set("tasks", null);
  677. this.set("hosts", null);
  678. this.get("controller").setBackgroundOperationHeader();
  679. },
  680. /**
  681. * Onclick handler for selected Service
  682. * @param event
  683. * @param context
  684. */
  685. gotoHosts: function (event, context) {
  686. this.get("controller").set("serviceName", event.context.get("name"));
  687. this.get("controller").set("currentServiceId", event.context.get("id"));
  688. this.get("controller").onHostUpdate();
  689. var servicesInfo = this.get("controller.hosts");
  690. if (servicesInfo.length) {
  691. this.get("controller").set("popupHeaderName", event.context.get("name"));
  692. }
  693. //apply lazy loading on cluster with more than 100 nodes
  694. if (servicesInfo.length > 100) {
  695. this.set('hosts', servicesInfo.slice(0, 50));
  696. } else {
  697. this.set('hosts', servicesInfo);
  698. }
  699. this.set("isServiceListHidden", true);
  700. this.set("isHostListHidden", false);
  701. $(".modal").scrollTop(0);
  702. $(".modal-body").scrollTop(0);
  703. if (servicesInfo.length > 100) {
  704. Ember.run.next(this, function(){
  705. this.set('hosts', this.get('hosts').concat(servicesInfo.slice(50, servicesInfo.length)));
  706. });
  707. }
  708. },
  709. /**
  710. * Onclick handler for selected Host
  711. * @param event
  712. * @param context
  713. */
  714. gotoTasks: function (event, context) {
  715. var taskInfo = event.context.tasks;
  716. if (taskInfo.length) {
  717. this.get("controller").set("popupHeaderName", taskInfo.objectAt(0).hostName);
  718. this.get("controller").set("currentHostName", taskInfo.objectAt(0).hostName);
  719. }
  720. this.set('tasks', taskInfo);
  721. this.set("isHostListHidden", true);
  722. this.set("isTaskListHidden", false);
  723. $(".modal").scrollTop(0);
  724. $(".modal-body").scrollTop(0);
  725. },
  726. /**
  727. * Onclick handler for selected Task
  728. */
  729. openTaskLogInDialog: function () {
  730. if ($(".task-detail-log-clipboard").length > 0) {
  731. this.destroyClipBoard();
  732. }
  733. var newWindow = window.open();
  734. var newDocument = newWindow.document;
  735. newDocument.write($(".task-detail-log-info").html());
  736. newDocument.close();
  737. },
  738. openedTaskId: 0,
  739. /**
  740. * Return task detail info of opened task
  741. */
  742. openedTask: function () {
  743. if (!this.get('openedTaskId')) {
  744. return Ember.Object.create();
  745. }
  746. return this.get('tasks').findProperty('id', this.get('openedTaskId'));
  747. }.property('tasks', 'tasks.@each.stderr', 'tasks.@each.stdout', 'openedTaskId'),
  748. /**
  749. * Onclick event for show task detail info
  750. * @param event
  751. * @param context
  752. */
  753. toggleTaskLog: function (event, context) {
  754. var taskInfo = event.context;
  755. this.set("isLogWrapHidden", false);
  756. if ($(".task-detail-log-clipboard").length > 0) {
  757. this.destroyClipBoard();
  758. }
  759. this.set("isHostListHidden", true);
  760. this.set("isTaskListHidden", true);
  761. this.set('openedTaskId', taskInfo.id);
  762. $(".modal").scrollTop(0);
  763. $(".modal-body").scrollTop(0);
  764. },
  765. /**
  766. * Onclick event for copy to clipboard button
  767. * @param event
  768. */
  769. textTrigger: function (event) {
  770. if ($(".task-detail-log-clipboard").length > 0) {
  771. this.destroyClipBoard();
  772. } else {
  773. this.createClipBoard();
  774. }
  775. },
  776. /**
  777. * Create Clip Board
  778. */
  779. createClipBoard: function () {
  780. $(".task-detail-log-clipboard-wrap").html('<textarea class="task-detail-log-clipboard"></textarea>');
  781. $(".task-detail-log-clipboard")
  782. .html("stderr: \n" + $(".stderr").html() + "\n stdout:\n" + $(".stdout").html())
  783. .css("display", "block")
  784. .width($(".task-detail-log-maintext").width())
  785. .height($(".task-detail-log-maintext").height())
  786. .select();
  787. $(".task-detail-log-maintext").css("display", "none")
  788. },
  789. /**
  790. * Destroy Clip Board
  791. */
  792. destroyClipBoard: function () {
  793. $(".task-detail-log-clipboard").remove();
  794. $(".task-detail-log-maintext").css("display", "block");
  795. }
  796. })
  797. }));
  798. return self.get('isPopup');
  799. }
  800. });