upgrade_task_view.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. * @return {$.ajax|null}
  78. */
  79. getTaskDetails: function () {
  80. if (Em.isNone(this.get('content'))) return null;
  81. return App.ajax.send({
  82. name: 'admin.upgrade.task',
  83. sender: this,
  84. data: {
  85. upgradeId: this.get('content.request_id'),
  86. taskId: this.get('content.id')
  87. },
  88. success: 'getTaskDetailsSuccessCallback'
  89. });
  90. },
  91. /**
  92. * success callback of <code>getTaskDetails</code>
  93. * @param {object} data
  94. */
  95. getTaskDetailsSuccessCallback: function (data) {
  96. //TODO change request to get only one task when API ready
  97. var task = data.items[0].upgrade_items[0].tasks[0].Tasks;
  98. this.get('taskDetailsProperties').forEach(function (property) {
  99. this.set('content.' + property, task[property]);
  100. }, this);
  101. },
  102. /**
  103. * open error log in textarea to give ability to cope content
  104. * @param {object} event
  105. */
  106. copyErrLog: function(event) {
  107. this.toggleProperty('errorLogOpened');
  108. },
  109. /**
  110. * open stdout log in textarea to give ability to cope content
  111. * @param {object} event
  112. */
  113. copyOutLog: function(event) {
  114. this.toggleProperty('outputLogOpened');
  115. },
  116. /**
  117. * open error log in new window
  118. */
  119. openErrorLog: function () {
  120. this.openLogWindow(this.get('content.stderr'));
  121. },
  122. /**
  123. * open stdout log in new window
  124. */
  125. openOutLog: function () {
  126. this.openLogWindow(this.get('content.stdout'));
  127. },
  128. /**
  129. * open logs in new window
  130. * @param {string} log
  131. */
  132. openLogWindow: function(log) {
  133. var newWindow = window.open();
  134. var newDocument = newWindow.document;
  135. newDocument.write(log);
  136. newDocument.close();
  137. }
  138. });