host_progress_popup.js 32 KB

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