host_progress_popup.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  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. var date = require('utils/date/date');
  20. var dataUtils = require('utils/data_manipulation');
  21. /**
  22. * Host information shown in the operations popup
  23. * @typedef {Em.Object} wrappedHost
  24. * @property {string} name
  25. * @property {string} publicName
  26. * @property {string} displayName
  27. * @property {number} progress
  28. * @property {boolean} isInProgress
  29. * @property {string} serviceName
  30. * @property {string} status
  31. * @property {number} isVisible
  32. * @property {string} icon
  33. * @property {string} barColor
  34. * @property {string} barWidth
  35. */
  36. /**
  37. * Task information shown in the operations popup
  38. * @typedef {Em.Object} wrappedTask
  39. * @property {string} id
  40. * @property {string} hostName
  41. * @property {string} command
  42. * @property {string} commandDetail
  43. * @property {string} status
  44. * @property {string} role
  45. * @property {string} stderr
  46. * @property {string} stdout
  47. * @property {number} request_id
  48. * @property {boolean} isVisible
  49. * @property {string} startTime
  50. * @property {string} duration
  51. * @property {string} icon
  52. */
  53. /**
  54. * Service information shown in the operations popup
  55. * @typedef {Em.Object} wrappedService
  56. * @property {string} id
  57. * @property {string} displayName
  58. * @property {string} progress
  59. * @property {string} status
  60. * @property {boolean} isRunning
  61. * @property {string} name
  62. * @property {boolean} isVisible
  63. * @property {string} startTime
  64. * @property {string} duration
  65. * @property {string} icon
  66. * @property {string} barColor
  67. * @property {boolean} isInProgress
  68. * @property {string} barWidth
  69. * @property {number} sourceRequestScheduleId
  70. * @property {string} contextCommand
  71. */
  72. /**
  73. * App.HostPopup is for the popup that shows up upon clicking already-performed or currently-in-progress operations
  74. * Allows to abort executing operations
  75. *
  76. * @type {Em.Object}
  77. * @class {HostPopup}
  78. */
  79. App.HostPopup = Em.Object.create({
  80. name: 'hostPopup',
  81. /**
  82. * @type {object[]}
  83. */
  84. servicesInfo: [],
  85. /**
  86. * @type {?wrappedHost[]}
  87. */
  88. hosts: null,
  89. /**
  90. * @type {?object[]}
  91. */
  92. inputData: null,
  93. /**
  94. * @type {string}
  95. */
  96. serviceName: '',
  97. /**
  98. * @type {?Number}
  99. */
  100. currentServiceId: null,
  101. /**
  102. * @type {?Number}
  103. */
  104. previousServiceId: null,
  105. /**
  106. * @type {string}
  107. */
  108. popupHeaderName: '',
  109. operationInfo: null,
  110. /**
  111. * @type {?App.Controller}
  112. */
  113. dataSourceController: null,
  114. /**
  115. * @type {bool}
  116. */
  117. isBackgroundOperations: false,
  118. /**
  119. * @type {?string}
  120. */
  121. currentHostName: null,
  122. /**
  123. * @type {?App.ModalPopup}
  124. */
  125. isPopup: null,
  126. /**
  127. * @type {object}
  128. */
  129. detailedProperties: {
  130. stdout: 'stdout',
  131. stderr: 'stderr',
  132. outputLog: 'output_log',
  133. errorLog: 'error_log'
  134. },
  135. /**
  136. * @type {object}
  137. */
  138. barColorMap: {
  139. 'FAILED': 'progress-danger',
  140. 'ABORTED': 'progress-warning',
  141. 'TIMEDOUT': 'progress-warning',
  142. 'IN_PROGRESS': 'progress-info',
  143. 'COMPLETED': 'progress-success'
  144. },
  145. /**
  146. * map to get css class with styles by service status
  147. *
  148. * @type {object}
  149. */
  150. statusesStyleMap: {
  151. 'FAILED': ['FAILED', 'icon-exclamation-sign', 'progress-danger', false],
  152. 'ABORTED': ['ABORTED', 'icon-minus', 'progress-warning', false],
  153. 'TIMEDOUT': ['TIMEDOUT', 'icon-time', 'progress-warning', false],
  154. 'IN_PROGRESS': ['IN_PROGRESS', 'icon-cogs', 'progress-info', true],
  155. 'COMPLETED': ['SUCCESS', 'icon-ok', 'progress-success', false]
  156. },
  157. /**
  158. * View with "Abort Request"-button
  159. *
  160. * @type {Em.View}
  161. */
  162. abortIcon: Em.View.extend({
  163. tagName: 'i',
  164. classNames: ['abort-icon', 'icon-remove-circle', 'pointer'],
  165. click: function () {
  166. this.get('controller').abortRequest(this.get('servicesInfo'));
  167. return false;
  168. },
  169. didInsertElement: function () {
  170. App.tooltip($(this.get('element')), {
  171. placement: "top",
  172. title: Em.I18n.t('hostPopup.bgop.abortRequest.title')
  173. });
  174. },
  175. willDestroyElement: function () {
  176. $(this.get('element')).tooltip('destroy');
  177. }
  178. }),
  179. /**
  180. * View with status icon (and tooltip on it)
  181. *
  182. * @type {Em.View}
  183. */
  184. statusIcon: Em.View.extend({
  185. tagName: 'i',
  186. classNames: ["service-status"],
  187. classNameBindings: ['servicesInfo.status', 'servicesInfo.icon', 'additionalClass'],
  188. attributeBindings: ['data-original-title'],
  189. 'data-original-title': function () {
  190. return this.get('servicesInfo.status');
  191. }.property('servicesInfo.status'),
  192. didInsertElement: function () {
  193. App.tooltip($(this.get('element')));
  194. },
  195. willDestroyElement: function () {
  196. $(this.get('element')).tooltip('destroy');
  197. }
  198. }),
  199. /**
  200. * Determines if background operation can be aborted depending on its status
  201. *
  202. * @param status
  203. * @returns {boolean}
  204. */
  205. isAbortableByStatus: function (status) {
  206. var statuses = this.get('statusesStyleMap');
  207. return !Em.keys(statuses).contains(status) || status === 'IN_PROGRESS';
  208. },
  209. /**
  210. * Send request to abort operation
  211. *
  212. * @method abortRequest
  213. */
  214. abortRequest: function (serviceInfo) {
  215. var requestName = serviceInfo.get('name');
  216. var self = this;
  217. App.showConfirmationPopup(function () {
  218. serviceInfo.set('isAbortable', false);
  219. return App.ajax.send({
  220. name: 'background_operations.abort_request',
  221. sender: self,
  222. data: {
  223. requestId: serviceInfo.get('id'),
  224. requestName: requestName,
  225. serviceInfo: serviceInfo
  226. },
  227. success: 'abortRequestSuccessCallback',
  228. error: 'abortRequestErrorCallback'
  229. });
  230. }, Em.I18n.t('hostPopup.bgop.abortRequest.confirmation.body').format(requestName));
  231. return false;
  232. },
  233. /**
  234. * Method called on successful sending request to abort operation
  235. *
  236. * @return {App.ModalPopup}
  237. * @method abortRequestSuccessCallback
  238. */
  239. abortRequestSuccessCallback: function (response, request, data) {
  240. return App.ModalPopup.show({
  241. header: Em.I18n.t('hostPopup.bgop.abortRequest.modal.header'),
  242. encodeBody: false,
  243. body: Em.I18n.t('hostPopup.bgop.abortRequest.modal.body').format(data.requestName),
  244. secondary: null
  245. });
  246. },
  247. /**
  248. * Method called on unsuccessful sending request to abort operation
  249. *
  250. * @method abortRequestErrorCallback
  251. */
  252. abortRequestErrorCallback: function (xhr, textStatus, error, opt, data) {
  253. data.serviceInfo.set('isAbortable', this.isAbortableByStatus(data.serviceInfo.status));
  254. App.ajax.defaultErrorHandler(xhr, opt.url, 'PUT', xhr.status);
  255. },
  256. /**
  257. * Entering point of this component
  258. *
  259. * @param {String} serviceName
  260. * @param {Object} controller
  261. * @param {Boolean} isBackgroundOperations
  262. * @param {Integer} requestId
  263. * @method initPopup
  264. */
  265. initPopup: function (serviceName, controller, isBackgroundOperations, requestId) {
  266. if (!isBackgroundOperations) {
  267. this.clearHostPopup();
  268. this.set("popupHeaderName", serviceName);
  269. }
  270. this.setProperties({
  271. currentServiceId: requestId,
  272. serviceName: serviceName,
  273. dataSourceController: controller,
  274. isBackgroundOperations: isBackgroundOperations,
  275. inputData: this.get("dataSourceController.services")
  276. });
  277. if (isBackgroundOperations) {
  278. this.onServiceUpdate();
  279. } else {
  280. this.onHostUpdate();
  281. }
  282. return this.createPopup();
  283. },
  284. /**
  285. * clear info popup data
  286. *
  287. * @method clearHostPopup
  288. */
  289. clearHostPopup: function () {
  290. this.setProperties({
  291. servicesInfo: [],
  292. host: null,
  293. inputData: null,
  294. serviceName: '',
  295. currentServiceId: null,
  296. previousServiceId: null,
  297. popupHeaderName: '',
  298. dataSourceController: null,
  299. currentHostName: null
  300. });
  301. if(this.get('isPopup')) {
  302. this.get('isPopup').remove();
  303. }
  304. },
  305. /**
  306. * Depending on tasks status
  307. *
  308. * @param {object[]} tasks
  309. * @return {*[]} [Status, Icon type, Progressbar color, is IN_PROGRESS]
  310. * @method getStatus
  311. */
  312. getStatus: function (tasks) {
  313. var isCompleted = true;
  314. var tasksLength = tasks.length;
  315. for (var i = 0; i < tasksLength; i++) {
  316. var taskStatus = tasks[i].Tasks.status;
  317. if (taskStatus !== 'COMPLETED') {
  318. isCompleted = false;
  319. }
  320. if (taskStatus === 'FAILED') {
  321. return ['FAILED', 'icon-exclamation-sign', 'progress-danger', false];
  322. }
  323. if (taskStatus === 'ABORTED') {
  324. return ['ABORTED', 'icon-minus', 'progress-warning', false];
  325. }
  326. if (taskStatus === 'TIMEDOUT') {
  327. return ['TIMEDOUT', 'icon-time', 'progress-warning', false];
  328. }
  329. if (taskStatus === 'IN_PROGRESS') {
  330. return ['IN_PROGRESS', 'icon-cogs', 'progress-info', true]
  331. }
  332. }
  333. if (isCompleted) {
  334. return ['SUCCESS', 'icon-ok', 'progress-success', false];
  335. }
  336. return ['PENDING', 'icon-cog', 'progress-info', true];
  337. },
  338. /**
  339. * Progress of host or service depending on tasks status
  340. * If no tasks, progress is 0
  341. *
  342. * @param {?object[]} tasks
  343. * @return {Number} percent of completion
  344. * @method getProgress
  345. */
  346. getProgress: function (tasks) {
  347. if (!tasks || !tasks.length) {
  348. return 0;
  349. }
  350. var groupedByStatus = dataUtils.groupPropertyValues(tasks, 'Tasks.status');
  351. var completedActions = Em.getWithDefault(groupedByStatus, 'COMPLETED.length', 0) +
  352. Em.getWithDefault(groupedByStatus, 'FAILED.length', 0) +
  353. Em.getWithDefault(groupedByStatus, 'ABORTED.length', 0) +
  354. Em.getWithDefault(groupedByStatus, 'TIMEDOUT.length', 0);
  355. var queuedActions = Em.getWithDefault(groupedByStatus, 'QUEUED.length', 0);
  356. var inProgressActions = Em.getWithDefault(groupedByStatus, 'IN_PROGRESS.length', 0);
  357. return Math.ceil((queuedActions * 0.09 + inProgressActions * 0.35 + completedActions ) / tasks.length * 100);
  358. },
  359. /**
  360. * Count number of operations for select box options
  361. *
  362. * @param {?Object[]} obj
  363. * @param {progressPopupCategoryObject[]} categories
  364. * @method setSelectCount
  365. */
  366. setSelectCount: function (obj, categories) {
  367. if (!obj) {
  368. return;
  369. }
  370. var groupedByStatus = dataUtils.groupPropertyValues(obj, 'status');
  371. categories.findProperty("value", 'all').set("count", obj.length);
  372. categories.findProperty("value", 'pending').set("count", Em.getWithDefault(groupedByStatus, 'pending.length', 0) + Em.getWithDefault(groupedByStatus, 'queued.length', 0));
  373. categories.findProperty("value", 'in_progress').set("count", Em.getWithDefault(groupedByStatus, 'in_progress.length', 0));
  374. categories.findProperty("value", 'failed').set("count", Em.getWithDefault(groupedByStatus, 'failed.length', 0));
  375. categories.findProperty("value", 'completed').set("count", Em.getWithDefault(groupedByStatus, 'success.length', 0) + Em.getWithDefault(groupedByStatus, 'completed.length', 0));
  376. categories.findProperty("value", 'aborted').set("count", Em.getWithDefault(groupedByStatus, 'aborted.length', 0));
  377. categories.findProperty("value", 'timedout').set("count", Em.getWithDefault(groupedByStatus, 'timedout.length', 0));
  378. },
  379. /**
  380. * For Background operation popup calculate number of running Operations, and set popup header
  381. *
  382. * @param {bool} isServiceListHidden
  383. * @method setBackgroundOperationHeader
  384. */
  385. setBackgroundOperationHeader: function (isServiceListHidden) {
  386. if (this.get('isBackgroundOperations') && !isServiceListHidden) {
  387. var numRunning = App.router.get('backgroundOperationsController.allOperationsCount');
  388. this.set("popupHeaderName", numRunning + Em.I18n.t('hostPopup.header.postFix').format(numRunning === 1 ? "" : "s"));
  389. }
  390. },
  391. /**
  392. * Create services obj data structure for popup
  393. * Set data for services
  394. *
  395. * @param {bool} isServiceListHidden
  396. * @method onServiceUpdate
  397. */
  398. onServiceUpdate: function (isServiceListHidden) {
  399. if (this.get('isBackgroundOperations') && this.get("inputData")) {
  400. var servicesInfo = this.get("servicesInfo");
  401. var currentServices = [];
  402. this.get("inputData").forEach(function (service, index) {
  403. var updatedService;
  404. var id = service.id;
  405. currentServices.push(id);
  406. var existedService = servicesInfo.findProperty('id', id);
  407. updatedService = existedService;
  408. if (existedService) {
  409. updatedService = this.updateService(existedService, service);
  410. }
  411. else {
  412. updatedService = this.createService(service);
  413. servicesInfo.insertAt(index, updatedService);
  414. }
  415. updatedService.set('isAbortable', App.isAuthorized('SERVICE.START_STOP') && this.isAbortableByStatus(service.status));
  416. }, this);
  417. this.removeOldServices(servicesInfo, currentServices);
  418. this.setBackgroundOperationHeader(isServiceListHidden);
  419. }
  420. },
  421. /**
  422. * Create service object from transmitted data
  423. *
  424. * @param {object} service
  425. * @return {wrappedService}
  426. * @method createService
  427. */
  428. createService: function (service) {
  429. var statuses = this.get('statusesStyleMap');
  430. var pendingStatus = ['PENDING', 'icon-cog', 'progress-info', true];
  431. var status = statuses[service.status] || pendingStatus;
  432. return Em.Object.create({
  433. id: service.id,
  434. displayName: service.displayName,
  435. progress: service.progress,
  436. status: App.format.taskStatus(status[0]),
  437. isRunning: service.isRunning,
  438. name: service.name,
  439. isVisible: true,
  440. startTime: date.startTime(service.startTime),
  441. duration: date.durationSummary(service.startTime, service.endTime),
  442. icon: status[1],
  443. barColor: status[2],
  444. isInProgress: status[3],
  445. barWidth: "width:" + service.progress + "%;",
  446. sourceRequestScheduleId: service.sourceRequestScheduleId,
  447. contextCommand: service.contextCommand
  448. });
  449. },
  450. /**
  451. * Update properties of existed service with new data
  452. *
  453. * @param {wrappedService} service
  454. * @param {object} newData
  455. * @returns {wrappedService}
  456. * @method updateService
  457. */
  458. updateService: function (service, newData) {
  459. var statuses = this.get('statusesStyleMap');
  460. var pendingStatus = ['PENDING', 'icon-cog', 'progress-info', true];
  461. var status = statuses[newData.status] || pendingStatus;
  462. return service.setProperties({
  463. progress: newData.progress,
  464. status: App.format.taskStatus(status[0]),
  465. isRunning: newData.isRunning,
  466. startTime: date.startTime(newData.startTime),
  467. duration: date.durationSummary(newData.startTime, newData.endTime),
  468. icon: status[1],
  469. barColor: status[2],
  470. isInProgress: status[3],
  471. barWidth: "width:" + newData.progress + "%;",
  472. sourceRequestScheduleId: newData.get('sourceRequestScheduleId'),
  473. contextCommand: newData.get('contextCommand')
  474. });
  475. },
  476. /**
  477. * remove old requests
  478. * as API returns 10, or 20 , or 30 ...etc latest request, the requests that absent in response should be removed
  479. *
  480. * @param {wrappedService[]} services
  481. * @param {number[]} currentServicesIds
  482. * @method removeOldServices
  483. */
  484. removeOldServices: function (services, currentServicesIds) {
  485. for (var i = 0, l = services.length; i < l; i++) {
  486. if (!currentServicesIds.contains(services[i].id)) {
  487. services.splice(i, 1);
  488. i--;
  489. l--;
  490. }
  491. }
  492. },
  493. /**
  494. * Wrap task as Ember-object
  495. *
  496. * @param {Object} _task
  497. * @return {wrappedTask}
  498. * @method createTask
  499. */
  500. createTask: function (_task) {
  501. return Em.Object.create({
  502. id: _task.Tasks.id,
  503. hostName: _task.Tasks.host_name,
  504. command: _task.Tasks.command.toLowerCase() === 'service_check' ? '' : _task.Tasks.command.toLowerCase(),
  505. commandDetail: App.format.commandDetail(_task.Tasks.command_detail, _task.Tasks.request_inputs),
  506. status: App.format.taskStatus(_task.Tasks.status),
  507. role: App.format.role(_task.Tasks.role, false),
  508. stderr: _task.Tasks.stderr,
  509. stdout: _task.Tasks.stdout,
  510. request_id: _task.Tasks.request_id,
  511. isVisible: true,
  512. startTime: date.startTime(_task.Tasks.start_time),
  513. duration: date.durationSummary(_task.Tasks.start_time, _task.Tasks.end_time),
  514. icon: function () {
  515. var statusIconMap = {
  516. 'pending': 'icon-cog',
  517. 'queued': 'icon-cog',
  518. 'in_progress': 'icon-cogs',
  519. 'completed': 'icon-ok',
  520. 'failed': 'icon-exclamation-sign',
  521. 'aborted': 'icon-minus',
  522. 'timedout': 'icon-time'
  523. };
  524. return statusIconMap[this.get('status')] || 'icon-cog';
  525. }.property('status')
  526. });
  527. },
  528. /**
  529. * Create hosts and tasks data structure for popup
  530. * Set data for hosts and tasks
  531. *
  532. * @method onHostUpdate
  533. */
  534. onHostUpdate: function () {
  535. var self = this;
  536. if (this.get("inputData")) {
  537. var hostsMap = this._getHostsMap();
  538. var existedHosts = self.get('hosts');
  539. if (existedHosts && existedHosts.length && this.get('currentServiceId') === this.get('previousServiceId')) {
  540. this._processingExistingHostsWithSameService(hostsMap);
  541. }
  542. else {
  543. var hostsArr = this._hostMapProcessing(hostsMap);
  544. hostsArr = hostsArr.sortProperty('name');
  545. hostsArr.setEach("serviceName", this.get("serviceName"));
  546. self.set("hosts", hostsArr);
  547. self.set('previousServiceId', this.get('currentServiceId'));
  548. }
  549. }
  550. var operation = this.get('servicesInfo').findProperty('name', this.get('serviceName'));
  551. this.set('operationInfo', !operation || operation && operation.get('progress') === 100 ? null : operation);
  552. },
  553. /**
  554. * Generate hosts map for further processing <code>inputData</code>
  555. *
  556. * @returns {object}
  557. * @private
  558. * @method _getHostsMap
  559. */
  560. _getHostsMap: function () {
  561. var hostsData;
  562. var hostsMap = {};
  563. var inputData = this.get('inputData');
  564. if (this.get('isBackgroundOperations') && this.get("currentServiceId")) {
  565. //hosts popup for Background Operations
  566. hostsData = inputData.findProperty("id", this.get("currentServiceId"));
  567. }
  568. else {
  569. if (this.get("serviceName")) {
  570. //hosts popup for Wizards
  571. hostsData = inputData.findProperty("name", this.get("serviceName"));
  572. }
  573. }
  574. if (hostsData) {
  575. if (hostsData.hostsMap) {
  576. //hosts data come from Background Operations as object map
  577. hostsMap = hostsData.hostsMap;
  578. }
  579. else {
  580. if (hostsData.hosts) {
  581. //hosts data come from Wizard as array
  582. hostsMap = hostsData.hosts.toMapByProperty('name');
  583. }
  584. }
  585. }
  586. return hostsMap;
  587. },
  588. /**
  589. *
  590. * @param {object} hostsMap
  591. * @returns {wrappedHost[]}
  592. * @private
  593. * @method _hostMapProcessing
  594. */
  595. _hostMapProcessing: function (hostsMap) {
  596. var self = this;
  597. var hostsArr = [];
  598. for (var hostName in hostsMap) {
  599. if (!hostsMap.hasOwnProperty(hostName)) {
  600. continue;
  601. }
  602. var _host = hostsMap[hostName];
  603. var tasks = _host.logTasks;
  604. var hostInfo = Em.Object.create({
  605. name: hostName,
  606. publicName: _host.publicName,
  607. displayName: Em.computed.truncate('name', 43, 40),
  608. progress: 0,
  609. status: App.format.taskStatus("PENDING"),
  610. serviceName: _host.serviceName,
  611. isVisible: true,
  612. icon: "icon-cog",
  613. barColor: "progress-info",
  614. barWidth: "width:0%;"
  615. });
  616. if (tasks.length) {
  617. tasks = tasks.sortProperty('Tasks.id');
  618. var hostStatus = self.getStatus(tasks);
  619. var hostProgress = self.getProgress(tasks);
  620. hostInfo.setProperties({
  621. status: App.format.taskStatus(hostStatus[0]),
  622. icon: hostStatus[1],
  623. barColor: hostStatus[2],
  624. isInProgress: hostStatus[3],
  625. progress: hostProgress,
  626. barWidth: "width:" + hostProgress + "%;"
  627. });
  628. }
  629. hostInfo.set('logTasks', tasks);
  630. hostsArr.push(hostInfo);
  631. }
  632. return hostsArr;
  633. },
  634. /**
  635. *
  636. * @param {object} hostsMap
  637. * @private
  638. * @method _processingExistingHostsWithSameService
  639. */
  640. _processingExistingHostsWithSameService: function (hostsMap) {
  641. var self = this;
  642. var existedHosts = self.get('hosts');
  643. var detailedProperties = this.get('detailedProperties');
  644. var detailedPropertiesKeys = Em.keys(detailedProperties);
  645. existedHosts.forEach(function (host) {
  646. var newHostInfo = hostsMap[host.get('name')];
  647. //update only hosts with changed tasks or currently opened tasks of host
  648. var hostShouldBeUpdated = !this.get('isBackgroundOperations') || newHostInfo.isModified || this.get('currentHostName') === host.get('name');
  649. if (newHostInfo && hostShouldBeUpdated) {
  650. var hostStatus = self.getStatus(newHostInfo.logTasks);
  651. var hostProgress = self.getProgress(newHostInfo.logTasks);
  652. host.setProperties({
  653. status: App.format.taskStatus(hostStatus[0]),
  654. icon: hostStatus[1],
  655. barColor: hostStatus[2],
  656. isInProgress: hostStatus[3],
  657. progress: hostProgress,
  658. barWidth: "width:" + hostProgress + "%;",
  659. logTasks: newHostInfo.logTasks
  660. });
  661. var existTasks = host.get('tasks');
  662. if (existTasks) {
  663. newHostInfo.logTasks.forEach(function (_task) {
  664. var existTask = existTasks.findProperty('id', _task.Tasks.id);
  665. if (existTask) {
  666. var status = _task.Tasks.status;
  667. detailedPropertiesKeys.forEach(function (key) {
  668. var name = detailedProperties[key];
  669. var value = _task.Tasks[name];
  670. if (!Em.isNone(value)) {
  671. existTask.set(key, value);
  672. }
  673. }, this);
  674. existTask.setProperties({
  675. status: App.format.taskStatus(status),
  676. startTime: date.startTime(_task.Tasks.start_time),
  677. duration: date.durationSummary(_task.Tasks.start_time, _task.Tasks.end_time)
  678. });
  679. existTask = self._handleRebalanceHDFS(_task, existTask);
  680. }
  681. else {
  682. existTasks.pushObject(this.createTask(_task));
  683. }
  684. }, this);
  685. }
  686. }
  687. }, this);
  688. },
  689. /**
  690. * Custom processing for "Rebalance HDFS"-task
  691. *
  692. * @param {object} task
  693. * @param {object} existTask
  694. * @returns {object}
  695. * @private
  696. * @method _handleRebalanceHDFS
  697. */
  698. _handleRebalanceHDFS: function (task, existTask) {
  699. var barColorMap = this.get('barColorMap');
  700. var isRebalanceHDFSTask = task.Tasks.command === 'CUSTOM_COMMAND' && task.Tasks.custom_command_name === 'REBALANCEHDFS';
  701. existTask.set('isRebalanceHDFSTask', isRebalanceHDFSTask);
  702. if (isRebalanceHDFSTask) {
  703. var structuredOut = task.Tasks.structured_out || {};
  704. var status = task.Tasks.status;
  705. existTask.setProperties({
  706. dataMoved: structuredOut.dataMoved || '0',
  707. dataLeft: structuredOut.dataLeft || '0',
  708. dataBeingMoved: structuredOut.dataBeingMoved || '0',
  709. barColor: barColorMap[status],
  710. isInProgress: status === 'IN_PROGRESS',
  711. isNotComplete: ['QUEUED', 'IN_PROGRESS'].contains(status),
  712. completionProgressStyle: 'width:' + (structuredOut.completePercent || 0) * 100 + '%;',
  713. command: task.Tasks.command,
  714. custom_command_name: task.Tasks.custom_command_name
  715. });
  716. }
  717. return existTask;
  718. },
  719. /**
  720. * Show popup
  721. *
  722. * @return {App.ModalPopup} PopupObject For testing purposes
  723. */
  724. createPopup: function () {
  725. var self = this;
  726. var isBackgroundOperations = this.get('isBackgroundOperations');
  727. this.set('isPopup', App.ModalPopup.show({
  728. /**
  729. * @type {boolean}
  730. */
  731. isLogWrapHidden: true,
  732. /**
  733. * @type {boolean}
  734. */
  735. isTaskListHidden: true,
  736. /**
  737. * @type {boolean}
  738. */
  739. isHostListHidden: true,
  740. /**
  741. * @type {boolean}
  742. */
  743. isServiceListHidden: false,
  744. /**
  745. * @type {boolean}
  746. */
  747. isHideBodyScroll: true,
  748. /**
  749. * no need to track is it loaded when popup contain only list of hosts
  750. * @type {bool}
  751. */
  752. isLoaded: !isBackgroundOperations,
  753. /**
  754. * is BG-popup opened
  755. * @type {bool}
  756. */
  757. isOpen: false,
  758. /**
  759. * @type {object}
  760. */
  761. detailedProperties: self.get('detailedProperties'),
  762. didInsertElement: function () {
  763. this._super();
  764. this.set('isOpen', true);
  765. },
  766. /**
  767. * @type {Em.View}
  768. */
  769. headerClass: Em.View.extend({
  770. controller: this,
  771. template: Em.Handlebars.compile('{{popupHeaderName}} ' +
  772. '{{#unless view.parentView.isHostListHidden}}{{#if controller.operationInfo.isAbortable}}' +
  773. '{{view controller.abortIcon servicesInfoBinding="controller.operationInfo"}}' +
  774. '{{/if}}{{/unless}}')
  775. }),
  776. /**
  777. * @type {String[]}
  778. */
  779. classNames: ['sixty-percent-width-modal', 'host-progress-popup', 'full-height-modal'],
  780. /**
  781. * for the checkbox: do not show this dialog again
  782. *
  783. * @type {bool}
  784. */
  785. hasFooterCheckbox: true,
  786. /**
  787. * Auto-display BG-popup
  788. *
  789. * @type {bool}
  790. */
  791. isNotShowBgChecked: null,
  792. /**
  793. * Save user pref about auto-display BG-popup
  794. *
  795. * @method updateNotShowBgChecked
  796. */
  797. updateNotShowBgChecked: function () {
  798. var curVal = !this.get('isNotShowBgChecked');
  799. if (!App.get('testMode')) {
  800. App.router.get('userSettingsController').postUserPref('show_bg', curVal);
  801. }
  802. }.observes('isNotShowBgChecked'),
  803. autoHeight: false,
  804. /**
  805. * @method closeModelPopup
  806. */
  807. closeModelPopup: function () {
  808. this.set('isOpen', false);
  809. if (isBackgroundOperations) {
  810. $(this.get('element')).detach();
  811. App.router.get('backgroundOperationsController').set('levelInfo.name', 'REQUESTS_LIST');
  812. } else {
  813. this.hide();
  814. self.set('isPopup', null);
  815. }
  816. },
  817. onPrimary: function () {
  818. this.closeModelPopup();
  819. },
  820. onClose: function () {
  821. this.closeModelPopup();
  822. },
  823. secondary: null,
  824. bodyClass: App.HostProgressPopupBodyView.extend({
  825. controller: self
  826. })
  827. }));
  828. return this.get('isPopup');
  829. }
  830. });