host_progress_popup.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  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 (App.get('isClusterUser')) return;
  267. if (!isBackgroundOperations) {
  268. this.clearHostPopup();
  269. this.set("popupHeaderName", serviceName);
  270. }
  271. this.setProperties({
  272. currentServiceId: requestId,
  273. serviceName: serviceName,
  274. dataSourceController: controller,
  275. isBackgroundOperations: isBackgroundOperations,
  276. inputData: this.get("dataSourceController.services")
  277. });
  278. if (isBackgroundOperations) {
  279. this.onServiceUpdate();
  280. } else {
  281. this.onHostUpdate();
  282. }
  283. return this.createPopup();
  284. },
  285. /**
  286. * clear info popup data
  287. *
  288. * @method clearHostPopup
  289. */
  290. clearHostPopup: function () {
  291. this.setProperties({
  292. servicesInfo: [],
  293. host: null,
  294. inputData: null,
  295. serviceName: '',
  296. currentServiceId: null,
  297. previousServiceId: null,
  298. popupHeaderName: '',
  299. dataSourceController: null,
  300. currentHostName: null
  301. });
  302. if(this.get('isPopup')) {
  303. this.get('isPopup').remove();
  304. }
  305. },
  306. /**
  307. * Depending on tasks status
  308. *
  309. * @param {object[]} tasks
  310. * @return {*[]} [Status, Icon type, Progressbar color, is IN_PROGRESS]
  311. * @method getStatus
  312. */
  313. getStatus: function (tasks) {
  314. var isCompleted = true;
  315. var tasksLength = tasks.length;
  316. for (var i = 0; i < tasksLength; i++) {
  317. var taskStatus = tasks[i].Tasks.status;
  318. if (taskStatus !== 'COMPLETED') {
  319. isCompleted = false;
  320. }
  321. if (taskStatus === 'FAILED') {
  322. return ['FAILED', 'icon-exclamation-sign', 'progress-danger', false];
  323. }
  324. if (taskStatus === 'ABORTED') {
  325. return ['ABORTED', 'icon-minus', 'progress-warning', false];
  326. }
  327. if (taskStatus === 'TIMEDOUT') {
  328. return ['TIMEDOUT', 'icon-time', 'progress-warning', false];
  329. }
  330. if (taskStatus === 'IN_PROGRESS') {
  331. return ['IN_PROGRESS', 'icon-cogs', 'progress-info', true]
  332. }
  333. }
  334. if (isCompleted) {
  335. return ['SUCCESS', 'icon-ok', 'progress-success', false];
  336. }
  337. return ['PENDING', 'icon-cog', 'progress-info', true];
  338. },
  339. /**
  340. * Progress of host or service depending on tasks status
  341. * If no tasks, progress is 0
  342. *
  343. * @param {?object[]} tasks
  344. * @return {Number} percent of completion
  345. * @method getProgress
  346. */
  347. getProgress: function (tasks) {
  348. if (!tasks || !tasks.length) {
  349. return 0;
  350. }
  351. var groupedByStatus = dataUtils.groupPropertyValues(tasks, 'Tasks.status');
  352. var completedActions = Em.getWithDefault(groupedByStatus, 'COMPLETED.length', 0) +
  353. Em.getWithDefault(groupedByStatus, 'FAILED.length', 0) +
  354. Em.getWithDefault(groupedByStatus, 'ABORTED.length', 0) +
  355. Em.getWithDefault(groupedByStatus, 'TIMEDOUT.length', 0);
  356. var queuedActions = Em.getWithDefault(groupedByStatus, 'QUEUED.length', 0);
  357. var inProgressActions = Em.getWithDefault(groupedByStatus, 'IN_PROGRESS.length', 0);
  358. return Math.ceil((queuedActions * 0.09 + inProgressActions * 0.35 + completedActions ) / tasks.length * 100);
  359. },
  360. /**
  361. * Count number of operations for select box options
  362. *
  363. * @param {?Object[]} obj
  364. * @param {progressPopupCategoryObject[]} categories
  365. * @method setSelectCount
  366. */
  367. setSelectCount: function (obj, categories) {
  368. if (!obj) {
  369. return;
  370. }
  371. var groupedByStatus = dataUtils.groupPropertyValues(obj, 'status');
  372. categories.findProperty("value", 'all').set("count", obj.length);
  373. categories.findProperty("value", 'pending').set("count", Em.getWithDefault(groupedByStatus, 'pending.length', 0) + Em.getWithDefault(groupedByStatus, 'queued.length', 0));
  374. categories.findProperty("value", 'in_progress').set("count", Em.getWithDefault(groupedByStatus, 'in_progress.length', 0));
  375. categories.findProperty("value", 'failed').set("count", Em.getWithDefault(groupedByStatus, 'failed.length', 0));
  376. categories.findProperty("value", 'completed').set("count", Em.getWithDefault(groupedByStatus, 'success.length', 0) + Em.getWithDefault(groupedByStatus, 'completed.length', 0));
  377. categories.findProperty("value", 'aborted').set("count", Em.getWithDefault(groupedByStatus, 'aborted.length', 0));
  378. categories.findProperty("value", 'timedout').set("count", Em.getWithDefault(groupedByStatus, 'timedout.length', 0));
  379. },
  380. /**
  381. * For Background operation popup calculate number of running Operations, and set popup header
  382. *
  383. * @param {bool} isServiceListHidden
  384. * @method setBackgroundOperationHeader
  385. */
  386. setBackgroundOperationHeader: function (isServiceListHidden) {
  387. if (this.get('isBackgroundOperations') && !isServiceListHidden) {
  388. var numRunning = App.router.get('backgroundOperationsController.allOperationsCount');
  389. this.set("popupHeaderName", numRunning + Em.I18n.t('hostPopup.header.postFix').format(numRunning === 1 ? "" : "s"));
  390. }
  391. },
  392. /**
  393. * Create services obj data structure for popup
  394. * Set data for services
  395. *
  396. * @param {bool} isServiceListHidden
  397. * @method onServiceUpdate
  398. */
  399. onServiceUpdate: function (isServiceListHidden) {
  400. if (this.get('isBackgroundOperations') && this.get("inputData")) {
  401. var servicesInfo = this.get("servicesInfo");
  402. var currentServices = [];
  403. this.get("inputData").forEach(function (service, index) {
  404. var updatedService;
  405. var id = service.id;
  406. currentServices.push(id);
  407. var existedService = servicesInfo.findProperty('id', id);
  408. updatedService = existedService;
  409. if (existedService) {
  410. updatedService = this.updateService(existedService, service);
  411. }
  412. else {
  413. updatedService = this.createService(service);
  414. servicesInfo.insertAt(index, updatedService);
  415. }
  416. updatedService.set('isAbortable', App.isAuthorized('SERVICE.START_STOP') && this.isAbortableByStatus(service.status));
  417. }, this);
  418. this.removeOldServices(servicesInfo, currentServices);
  419. this.setBackgroundOperationHeader(isServiceListHidden);
  420. }
  421. },
  422. /**
  423. * Create service object from transmitted data
  424. *
  425. * @param {object} service
  426. * @return {wrappedService}
  427. * @method createService
  428. */
  429. createService: function (service) {
  430. var statuses = this.get('statusesStyleMap');
  431. var pendingStatus = ['PENDING', 'icon-cog', 'progress-info', true];
  432. var status = statuses[service.status] || pendingStatus;
  433. return Em.Object.create({
  434. id: service.id,
  435. displayName: service.displayName,
  436. progress: service.progress,
  437. status: App.format.taskStatus(status[0]),
  438. isRunning: service.isRunning,
  439. name: service.name,
  440. isVisible: true,
  441. startTime: date.startTime(service.startTime),
  442. duration: date.durationSummary(service.startTime, service.endTime),
  443. icon: status[1],
  444. barColor: status[2],
  445. isInProgress: status[3],
  446. barWidth: "width:" + service.progress + "%;",
  447. sourceRequestScheduleId: service.sourceRequestScheduleId,
  448. contextCommand: service.contextCommand
  449. });
  450. },
  451. /**
  452. * Update properties of existed service with new data
  453. *
  454. * @param {wrappedService} service
  455. * @param {object} newData
  456. * @returns {wrappedService}
  457. * @method updateService
  458. */
  459. updateService: function (service, newData) {
  460. var statuses = this.get('statusesStyleMap');
  461. var pendingStatus = ['PENDING', 'icon-cog', 'progress-info', true];
  462. var status = statuses[newData.status] || pendingStatus;
  463. return service.setProperties({
  464. progress: newData.progress,
  465. status: App.format.taskStatus(status[0]),
  466. isRunning: newData.isRunning,
  467. startTime: date.startTime(newData.startTime),
  468. duration: date.durationSummary(newData.startTime, newData.endTime),
  469. icon: status[1],
  470. barColor: status[2],
  471. isInProgress: status[3],
  472. barWidth: "width:" + newData.progress + "%;",
  473. sourceRequestScheduleId: newData.get('sourceRequestScheduleId'),
  474. contextCommand: newData.get('contextCommand')
  475. });
  476. },
  477. /**
  478. * remove old requests
  479. * as API returns 10, or 20 , or 30 ...etc latest request, the requests that absent in response should be removed
  480. *
  481. * @param {wrappedService[]} services
  482. * @param {number[]} currentServicesIds
  483. * @method removeOldServices
  484. */
  485. removeOldServices: function (services, currentServicesIds) {
  486. for (var i = 0, l = services.length; i < l; i++) {
  487. if (!currentServicesIds.contains(services[i].id)) {
  488. services.splice(i, 1);
  489. i--;
  490. l--;
  491. }
  492. }
  493. },
  494. /**
  495. * Wrap task as Ember-object
  496. *
  497. * @param {Object} _task
  498. * @return {wrappedTask}
  499. * @method createTask
  500. */
  501. createTask: function (_task) {
  502. return Em.Object.create({
  503. id: _task.Tasks.id,
  504. hostName: _task.Tasks.host_name,
  505. command: _task.Tasks.command.toLowerCase() === 'service_check' ? '' : _task.Tasks.command.toLowerCase(),
  506. commandDetail: App.format.commandDetail(_task.Tasks.command_detail, _task.Tasks.request_inputs),
  507. status: App.format.taskStatus(_task.Tasks.status),
  508. role: App.format.role(_task.Tasks.role, false),
  509. stderr: _task.Tasks.stderr,
  510. stdout: _task.Tasks.stdout,
  511. request_id: _task.Tasks.request_id,
  512. isVisible: true,
  513. startTime: date.startTime(_task.Tasks.start_time),
  514. duration: date.durationSummary(_task.Tasks.start_time, _task.Tasks.end_time),
  515. icon: function () {
  516. var statusIconMap = {
  517. 'pending': 'icon-cog',
  518. 'queued': 'icon-cog',
  519. 'in_progress': 'icon-cogs',
  520. 'completed': 'icon-ok',
  521. 'failed': 'icon-exclamation-sign',
  522. 'aborted': 'icon-minus',
  523. 'timedout': 'icon-time'
  524. };
  525. return statusIconMap[this.get('status')] || 'icon-cog';
  526. }.property('status')
  527. });
  528. },
  529. /**
  530. * Create hosts and tasks data structure for popup
  531. * Set data for hosts and tasks
  532. *
  533. * @method onHostUpdate
  534. */
  535. onHostUpdate: function () {
  536. var self = this;
  537. if (this.get("inputData")) {
  538. var hostsMap = this._getHostsMap();
  539. var existedHosts = self.get('hosts');
  540. if (existedHosts && existedHosts.length && this.get('currentServiceId') === this.get('previousServiceId')) {
  541. this._processingExistingHostsWithSameService(hostsMap);
  542. }
  543. else {
  544. var hostsArr = this._hostMapProcessing(hostsMap);
  545. hostsArr = hostsArr.sortProperty('name');
  546. hostsArr.setEach("serviceName", this.get("serviceName"));
  547. self.set("hosts", hostsArr);
  548. self.set('previousServiceId', this.get('currentServiceId'));
  549. }
  550. }
  551. var operation = this.get('servicesInfo').findProperty('name', this.get('serviceName'));
  552. this.set('operationInfo', !operation || operation && operation.get('progress') === 100 ? null : operation);
  553. },
  554. /**
  555. * Generate hosts map for further processing <code>inputData</code>
  556. *
  557. * @returns {object}
  558. * @private
  559. * @method _getHostsMap
  560. */
  561. _getHostsMap: function () {
  562. var hostsData;
  563. var hostsMap = {};
  564. var inputData = this.get('inputData');
  565. if (this.get('isBackgroundOperations') && this.get("currentServiceId")) {
  566. //hosts popup for Background Operations
  567. hostsData = inputData.findProperty("id", this.get("currentServiceId"));
  568. }
  569. else {
  570. if (this.get("serviceName")) {
  571. //hosts popup for Wizards
  572. hostsData = inputData.findProperty("name", this.get("serviceName"));
  573. }
  574. }
  575. if (hostsData) {
  576. if (hostsData.hostsMap) {
  577. //hosts data come from Background Operations as object map
  578. hostsMap = hostsData.hostsMap;
  579. }
  580. else {
  581. if (hostsData.hosts) {
  582. //hosts data come from Wizard as array
  583. hostsMap = hostsData.hosts.toMapByProperty('name');
  584. }
  585. }
  586. }
  587. return hostsMap;
  588. },
  589. /**
  590. *
  591. * @param {object} hostsMap
  592. * @returns {wrappedHost[]}
  593. * @private
  594. * @method _hostMapProcessing
  595. */
  596. _hostMapProcessing: function (hostsMap) {
  597. var self = this;
  598. var hostsArr = [];
  599. for (var hostName in hostsMap) {
  600. if (!hostsMap.hasOwnProperty(hostName)) {
  601. continue;
  602. }
  603. var _host = hostsMap[hostName];
  604. var tasks = _host.logTasks;
  605. var hostInfo = Em.Object.create({
  606. name: hostName,
  607. publicName: _host.publicName,
  608. displayName: Em.computed.truncate('name', 43, 40),
  609. progress: 0,
  610. status: App.format.taskStatus("PENDING"),
  611. serviceName: _host.serviceName,
  612. isVisible: true,
  613. icon: "icon-cog",
  614. barColor: "progress-info",
  615. barWidth: "width:0%;"
  616. });
  617. if (tasks.length) {
  618. tasks = tasks.sortProperty('Tasks.id');
  619. var hostStatus = self.getStatus(tasks);
  620. var hostProgress = self.getProgress(tasks);
  621. hostInfo.setProperties({
  622. status: App.format.taskStatus(hostStatus[0]),
  623. icon: hostStatus[1],
  624. barColor: hostStatus[2],
  625. isInProgress: hostStatus[3],
  626. progress: hostProgress,
  627. barWidth: "width:" + hostProgress + "%;"
  628. });
  629. }
  630. hostInfo.set('logTasks', tasks);
  631. hostsArr.push(hostInfo);
  632. }
  633. return hostsArr;
  634. },
  635. /**
  636. *
  637. * @param {object} hostsMap
  638. * @private
  639. * @method _processingExistingHostsWithSameService
  640. */
  641. _processingExistingHostsWithSameService: function (hostsMap) {
  642. var self = this;
  643. var existedHosts = self.get('hosts');
  644. var detailedProperties = this.get('detailedProperties');
  645. var detailedPropertiesKeys = Em.keys(detailedProperties);
  646. existedHosts.forEach(function (host) {
  647. var newHostInfo = hostsMap[host.get('name')];
  648. //update only hosts with changed tasks or currently opened tasks of host
  649. var hostShouldBeUpdated = !this.get('isBackgroundOperations') || newHostInfo.isModified || this.get('currentHostName') === host.get('name');
  650. if (newHostInfo && hostShouldBeUpdated) {
  651. var hostStatus = self.getStatus(newHostInfo.logTasks);
  652. var hostProgress = self.getProgress(newHostInfo.logTasks);
  653. host.setProperties({
  654. status: App.format.taskStatus(hostStatus[0]),
  655. icon: hostStatus[1],
  656. barColor: hostStatus[2],
  657. isInProgress: hostStatus[3],
  658. progress: hostProgress,
  659. barWidth: "width:" + hostProgress + "%;",
  660. logTasks: newHostInfo.logTasks
  661. });
  662. var existTasks = host.get('tasks');
  663. if (existTasks) {
  664. newHostInfo.logTasks.forEach(function (_task) {
  665. var existTask = existTasks.findProperty('id', _task.Tasks.id);
  666. if (existTask) {
  667. var status = _task.Tasks.status;
  668. detailedPropertiesKeys.forEach(function (key) {
  669. var name = detailedProperties[key];
  670. var value = _task.Tasks[name];
  671. if (!Em.isNone(value)) {
  672. existTask.set(key, value);
  673. }
  674. }, this);
  675. existTask.setProperties({
  676. status: App.format.taskStatus(status),
  677. startTime: date.startTime(_task.Tasks.start_time),
  678. duration: date.durationSummary(_task.Tasks.start_time, _task.Tasks.end_time)
  679. });
  680. existTask = self._handleRebalanceHDFS(_task, existTask);
  681. }
  682. else {
  683. existTasks.pushObject(this.createTask(_task));
  684. }
  685. }, this);
  686. }
  687. }
  688. }, this);
  689. },
  690. /**
  691. * Custom processing for "Rebalance HDFS"-task
  692. *
  693. * @param {object} task
  694. * @param {object} existTask
  695. * @returns {object}
  696. * @private
  697. * @method _handleRebalanceHDFS
  698. */
  699. _handleRebalanceHDFS: function (task, existTask) {
  700. var barColorMap = this.get('barColorMap');
  701. var isRebalanceHDFSTask = task.Tasks.command === 'CUSTOM_COMMAND' && task.Tasks.custom_command_name === 'REBALANCEHDFS';
  702. existTask.set('isRebalanceHDFSTask', isRebalanceHDFSTask);
  703. if (isRebalanceHDFSTask) {
  704. var structuredOut = task.Tasks.structured_out || {};
  705. var status = task.Tasks.status;
  706. existTask.setProperties({
  707. dataMoved: structuredOut.dataMoved || '0',
  708. dataLeft: structuredOut.dataLeft || '0',
  709. dataBeingMoved: structuredOut.dataBeingMoved || '0',
  710. barColor: barColorMap[status],
  711. isInProgress: status === 'IN_PROGRESS',
  712. isNotComplete: ['QUEUED', 'IN_PROGRESS'].contains(status),
  713. completionProgressStyle: 'width:' + (structuredOut.completePercent || 0) * 100 + '%;',
  714. command: task.Tasks.command,
  715. custom_command_name: task.Tasks.custom_command_name
  716. });
  717. }
  718. return existTask;
  719. },
  720. /**
  721. * Show popup
  722. *
  723. * @return {App.ModalPopup} PopupObject For testing purposes
  724. */
  725. createPopup: function () {
  726. var self = this;
  727. var isBackgroundOperations = this.get('isBackgroundOperations');
  728. this.set('isPopup', App.ModalPopup.show({
  729. /**
  730. * @type {boolean}
  731. */
  732. isLogWrapHidden: true,
  733. /**
  734. * @type {boolean}
  735. */
  736. isTaskListHidden: true,
  737. /**
  738. * @type {boolean}
  739. */
  740. isHostListHidden: true,
  741. /**
  742. * @type {boolean}
  743. */
  744. isServiceListHidden: false,
  745. /**
  746. * @type {boolean}
  747. */
  748. isHideBodyScroll: true,
  749. /**
  750. * no need to track is it loaded when popup contain only list of hosts
  751. * @type {bool}
  752. */
  753. isLoaded: !isBackgroundOperations,
  754. /**
  755. * is BG-popup opened
  756. * @type {bool}
  757. */
  758. isOpen: false,
  759. /**
  760. * @type {object}
  761. */
  762. detailedProperties: self.get('detailedProperties'),
  763. isVisible: function() {
  764. return !(App.get('isClusterUser') && isBackgroundOperations);
  765. }.property('App.isClusterUser'),
  766. didInsertElement: function () {
  767. this._super();
  768. this.set('isOpen', true);
  769. },
  770. /**
  771. * @type {Em.View}
  772. */
  773. headerClass: Em.View.extend({
  774. controller: this,
  775. template: Em.Handlebars.compile('{{popupHeaderName}} ' +
  776. '{{#unless view.parentView.isHostListHidden}}{{#if controller.operationInfo.isAbortable}}' +
  777. '{{view controller.abortIcon servicesInfoBinding="controller.operationInfo"}}' +
  778. '{{/if}}{{/unless}}')
  779. }),
  780. /**
  781. * @type {String[]}
  782. */
  783. classNames: ['sixty-percent-width-modal', 'host-progress-popup', 'full-height-modal'],
  784. /**
  785. * for the checkbox: do not show this dialog again
  786. *
  787. * @type {bool}
  788. */
  789. hasFooterCheckbox: true,
  790. /**
  791. * Auto-display BG-popup
  792. *
  793. * @type {bool}
  794. */
  795. isNotShowBgChecked: null,
  796. /**
  797. * Save user pref about auto-display BG-popup
  798. *
  799. * @method updateNotShowBgChecked
  800. */
  801. updateNotShowBgChecked: function () {
  802. var curVal = !this.get('isNotShowBgChecked');
  803. if (!App.get('testMode')) {
  804. App.router.get('userSettingsController').postUserPref('show_bg', curVal);
  805. }
  806. }.observes('isNotShowBgChecked'),
  807. autoHeight: false,
  808. /**
  809. * @method closeModelPopup
  810. */
  811. closeModelPopup: function () {
  812. this.set('isOpen', false);
  813. if (isBackgroundOperations) {
  814. $(this.get('element')).detach();
  815. App.router.get('backgroundOperationsController').set('levelInfo.name', 'REQUESTS_LIST');
  816. } else {
  817. this.hide();
  818. self.set('isPopup', null);
  819. }
  820. },
  821. onPrimary: function () {
  822. this.closeModelPopup();
  823. },
  824. onClose: function () {
  825. this.closeModelPopup();
  826. },
  827. secondary: null,
  828. bodyClass: App.HostProgressPopupBodyView.extend({
  829. controller: self
  830. })
  831. }));
  832. return this.get('isPopup');
  833. }
  834. });