step9_view.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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.WizardStep9View = Em.View.extend({
  20. templateName:require('templates/wizard/step9'),
  21. barColor:'',
  22. resultMsg:'',
  23. resultMsgColor:'',
  24. didInsertElement:function () {
  25. var controller = this.get('controller');
  26. this.get('controller.hosts').setEach('status', 'info');
  27. this.onStatus();
  28. controller.navigateStep();
  29. },
  30. barWidth:function () {
  31. var controller = this.get('controller');
  32. var barWidth = 'width: ' + controller.get('progress') + '%;';
  33. return barWidth;
  34. }.property('controller.progress'),
  35. onStatus:function () {
  36. if (this.get('controller.status') === 'info') {
  37. this.set('resultMsg', '');
  38. this.set('barColor', 'progress-info');
  39. } else if (this.get('controller.status') === 'warning') {
  40. this.set('barColor', 'progress-warning');
  41. this.set('resultMsg', Em.I18n.t('installer.step9.status.warning'));
  42. this.set('resultMsgColor', 'alert-warning');
  43. } else if (this.get('controller.status') === 'failed') {
  44. this.set('barColor', 'progress-danger');
  45. console.log('TRACE: Inside error view step9');
  46. this.set('resultMsg', Em.I18n.t('installer.step9.status.failed'));
  47. this.set('resultMsgColor', 'alert-error');
  48. } else if (this.get('controller.status') === 'success') {
  49. console.log('TRACE: Inside success view step9');
  50. this.set('barColor', 'progress-success');
  51. this.set('resultMsg', Em.I18n.t('installer.step9.status.success'));
  52. this.set('resultMsgColor', 'alert-success');
  53. }
  54. }.observes('controller.status')
  55. });
  56. App.HostStatusView = Em.View.extend({
  57. tagName:'tr',
  58. obj:'null',
  59. barColor:'',
  60. didInsertElement:function () {
  61. var controller = this.get('controller');
  62. this.onStatus();
  63. },
  64. barWidth:function () {
  65. var barWidth = 'width: ' + this.get('obj.progress') + '%;';
  66. return barWidth;
  67. }.property('obj.progress'),
  68. onStatus:function () {
  69. if (this.get('obj.status') === 'info') {
  70. this.set('barColor', 'progress-info');
  71. } else if (this.get('obj.status') === 'warning') {
  72. this.set('barColor', 'progress-warning');
  73. if (this.get('obj.progress') === '100') {
  74. this.set('obj.message', Em.I18n.t('installer.step9.host.status.warning'));
  75. }
  76. } else if (this.get('obj.status') === 'failed') {
  77. this.set('barColor', 'progress-danger');
  78. if (this.get('obj.progress') === '100') {
  79. this.set('obj.message', Em.I18n.t('installer.step9.host.status.failed'));
  80. }
  81. } else if (this.get('obj.status') === 'success') {
  82. this.set('barColor', 'progress-success');
  83. if (this.get('obj.progress') === '100') {
  84. this.set('obj.message', Em.I18n.t('installer.step9.host.status.success'));
  85. }
  86. }
  87. }.observes('obj.status', 'obj.progress'),
  88. isFailed:function () {
  89. if (this.get('controller.isStepCompleted') === true && this.get('obj.status') === 'failed') {
  90. return true;
  91. } else {
  92. return false;
  93. }
  94. }.property('controller.isStepCompleted', 'controller.status'),
  95. isSuccess:function () {
  96. if (this.get('controller.isStepCompleted') === true && this.get('obj.status') === 'success') {
  97. return true;
  98. } else {
  99. return false;
  100. }
  101. }.property('controller.isStepCompleted', 'controller.status'),
  102. isWarning:function () {
  103. if (this.get('controller.isStepCompleted') === true && this.get('obj.status') === 'warning') {
  104. return true;
  105. } else {
  106. return false;
  107. }
  108. }.property('controller.isStepCompleted', 'controller.status'),
  109. isHostCompleted:function () {
  110. return this.get('obj.progress') == 100 || this.get('controller.isStepCompleted');
  111. }.property('controller.isStepCompleted', 'obj.progress'),
  112. hostLogPopup:function (event, context) {
  113. var self = this;
  114. var host = event.context;
  115. App.ModalPopup.show({
  116. header:Em.I18n.t('installer.step9.hostLog.popup.header') + event.context.get('name'),
  117. onPrimary:function () {
  118. this.hide();
  119. },
  120. secondary:null,
  121. controllerBinding:context,
  122. bodyClass:Ember.View.extend({
  123. templateName:require('templates/wizard/step9HostTasksLogPopup'),
  124. hostObj:function () {
  125. return this.get('parentView.obj');
  126. }.property('parentView.obj'),
  127. startedTasks:[], // initialized in didInsertElement
  128. task: null, // set in showTaskLog; contains task info including stdout and stderr
  129. /**
  130. * sort task array by request Id
  131. * @param tasks
  132. * @return {Array}
  133. */
  134. sortTasksByRequest: function(tasks){
  135. var result = [];
  136. var requestId = 1;
  137. for(var i = 0; i < tasks.length; i++){
  138. requestId = (tasks[i].Tasks.request_id > requestId) ? tasks[i].Tasks.request_id : requestId;
  139. }
  140. while(requestId >= 1){
  141. for(var j = 0; j < tasks.length; j++){
  142. if(requestId == tasks[j].Tasks.request_id){
  143. result.push(tasks[j]);
  144. }
  145. }
  146. requestId--;
  147. }
  148. result.reverse();
  149. return result;
  150. },
  151. roles:function () {
  152. var roleArr = [];
  153. var tasks = this.getStartedTasks(host);
  154. tasks = this.sortTasksByRequest(tasks);
  155. if (tasks.length) {
  156. var _roles = tasks.mapProperty('Tasks.role').uniq();
  157. _roles.forEach(function (_role) {
  158. var taskInfos = [];
  159. var roleObj = {};
  160. roleObj.roleName = App.format.role(_role);
  161. tasks.filterProperty('Tasks.role', _role).forEach(function (_task) {
  162. var taskInfo = Ember.Object.create({
  163. isTextArea:false,
  164. buttonLabel:function () {
  165. return (this.get('isTextArea')) ? 'Press CTRL+C' : 'Click to highlight';
  166. }.property('isTextArea')
  167. });
  168. taskInfo.set('requestId', _task.Tasks.request_id);
  169. taskInfo.set('command', _task.Tasks.command.toLowerCase());
  170. taskInfo.set('status', App.format.taskStatus(_task.Tasks.status));
  171. taskInfo.set('url', _task.href);
  172. taskInfo.set('isLogHidden', false);
  173. taskInfos.pushObject(taskInfo);
  174. }, this);
  175. roleObj.taskInfos = taskInfos;
  176. roleArr.pushObject(roleObj);
  177. }, this);
  178. }
  179. return roleArr;
  180. }.property('startedTasks.@each'),
  181. didInsertElement: function () {debugger;
  182. console.log('The value of event context is: ' + host.name);
  183. this.get('roles').forEach(function (role) {
  184. role.taskInfos.forEach(function (task) {
  185. task.set('isLogHidden', true);
  186. });
  187. });
  188. $(this.get('element')).find('.content-area').each(function (index, value) {
  189. var button = $(value).find('.textTrigger');
  190. $(value).mouseenter(
  191. function () {
  192. var element = $(this);
  193. element.css('border', '1px solid #dcdcdc');
  194. button.css('visibility', 'visible');
  195. }).mouseleave(
  196. function () {
  197. var element = $(this);
  198. element.css('border', 'none');
  199. button.css('visibility', 'hidden');
  200. })
  201. });
  202. },
  203. getStartedTasks:function (host) {
  204. var startedTasks = host.logTasks.filter(function (task) {
  205. return task.Tasks.status != 'PENDING' && task.Tasks.status != 'QUEUED';
  206. });
  207. return startedTasks;
  208. },
  209. toggleTaskLog:function (event, context) {
  210. var taskInfo = event.context;
  211. if (taskInfo.get('isLogHidden')) {
  212. var url = (App.testMode) ? '/data/wizard/deploy/task_log.json' : taskInfo.url;
  213. $.ajax({
  214. url:url,
  215. dataType:'text',
  216. timeout:App.timeout,
  217. success:function (data) {
  218. var task = $.parseJSON(data);
  219. taskInfo.set('stdout', task.Tasks.stdout);
  220. taskInfo.set('stderr', task.Tasks.stderr);
  221. taskInfo.set('isLogHidden', false);
  222. taskInfo.set('isTextArea', false);
  223. },
  224. error:function () {
  225. alert('Failed to retrieve task log');
  226. }
  227. });
  228. } else {
  229. taskInfo.set('isLogHidden', true);
  230. }
  231. },
  232. textTrigger:function (event) {
  233. var task = event.context;
  234. task.set('isTextArea', !task.get('isTextArea'));
  235. },
  236. textArea:Em.TextArea.extend({
  237. didInsertElement:function () {
  238. var element = $(this.get('element'));
  239. element.width($(this.get('parentView').get('element')).width() - 10);
  240. element.height($(this.get('parentView').get('element')).height());
  241. element.select();
  242. element.css('resize', 'none');
  243. this.$().flexible();
  244. },
  245. readOnly:true,
  246. value:function () {
  247. var taskInfo = this.get('content');
  248. var content = "";
  249. content += this.get('role').role + " " + taskInfo.command + " log " + taskInfo.status + "\n";
  250. content += "stderr: " + taskInfo.stderr + "\n";
  251. content += "stdout: " + taskInfo.stdout + "\n";
  252. return content;
  253. }.property('content')
  254. })
  255. })
  256. });
  257. }
  258. });