upgrade_task_view.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. App.upgradeTaskView = Em.View.extend({
  20. templateName: require('templates/main/admin/stack_upgrade/upgrade_task'),
  21. /**
  22. * view observed directly
  23. * @type {boolean}
  24. */
  25. outsideView: false,
  26. /**
  27. * @type {boolean}
  28. */
  29. showContent: function () {
  30. return this.get('outsideView') || this.get('content.isExpanded');
  31. }.property('content.isExpanded'),
  32. /**
  33. * @type {boolean}
  34. */
  35. errorLogOpened: false,
  36. /**
  37. * @type {boolean}
  38. */
  39. outputLogOpened: false,
  40. /**
  41. * @type {App.upgradeEntity}
  42. * @default null
  43. */
  44. content: null,
  45. /**
  46. * @type {Array}
  47. */
  48. tasks: [],
  49. /**
  50. * poll timer
  51. * @type {number|null}
  52. */
  53. timer: null,
  54. /**
  55. * @type {Array}
  56. */
  57. taskDetailsProperties: ['status', 'stdout', 'stderr', 'error_log', 'host_name', 'output_log'],
  58. didInsertElement: function () {
  59. if (this.get('outsideView')) this.doPolling();
  60. },
  61. /**
  62. * poll for task details when task is expanded
  63. */
  64. doPolling: function () {
  65. var self = this;
  66. if (this.get('content.isExpanded') || this.get('outsideView')) {
  67. this.getTaskDetails();
  68. this.set('timer', setTimeout(function () {
  69. self.doPolling();
  70. }, App.bgOperationsUpdateInterval));
  71. } else {
  72. clearTimeout(this.get('timer'));
  73. }
  74. }.observes('content.isExpanded', 'outsideView'),
  75. /**
  76. * request task details from server
  77. */
  78. getTaskDetails: function () {
  79. App.ajax.send({
  80. name: 'admin.upgrade.task',
  81. sender: this,
  82. data: {
  83. upgradeId: this.get('content.request_id'),
  84. taskId: this.get('content.id')
  85. },
  86. success: 'getTaskDetailsSuccessCallback'
  87. });
  88. },
  89. /**
  90. * success callback of <code>getTaskDetails</code>
  91. * @param {object} data
  92. */
  93. getTaskDetailsSuccessCallback: function (data) {
  94. //TODO change request to get only one task when API ready
  95. var task = data.items[0].upgrade_items[0].tasks[0].Tasks;
  96. this.get('taskDetailsProperties').forEach(function (property) {
  97. this.set('content.' + property, task[property]);
  98. }, this);
  99. },
  100. /**
  101. * open error log in textarea to give ability to cope content
  102. * @param {object} event
  103. */
  104. copyErrLog: function(event) {
  105. this.toggleProperty('errorLogOpened');
  106. },
  107. /**
  108. * open stdout log in textarea to give ability to cope content
  109. * @param {object} event
  110. */
  111. copyOutLog: function(event) {
  112. this.toggleProperty('outputLogOpened');
  113. },
  114. /**
  115. * open error log in new window
  116. */
  117. openErrorLog: function () {
  118. this.openLogWindow(this.get('content.stderr'));
  119. },
  120. /**
  121. * open stdout log in new window
  122. */
  123. openOutLog: function () {
  124. this.openLogWindow(this.get('content.stdout'));
  125. },
  126. /**
  127. * open logs in new window
  128. * @param {string} log
  129. */
  130. openLogWindow: function(log) {
  131. var newWindow = window.open();
  132. var newDocument = newWindow.document;
  133. newDocument.write(log);
  134. newDocument.close();
  135. }
  136. });