apps_controller.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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 misc = require('utils/misc');
  20. var date = require('utils/date');
  21. App.MainAppsController = Em.ArrayController.extend({
  22. name:'mainAppsController',
  23. content: [],
  24. loaded : false,
  25. loading : false,
  26. /**
  27. * List of users.
  28. * Will be used for filtering in user column.
  29. * Go to App.MainAppsView.userFilterView for more information
  30. */
  31. users: function () {
  32. return this.get('content').mapProperty("userName").uniq().map(function(userName){
  33. return {
  34. name: userName,
  35. checked: false
  36. };
  37. });
  38. }.property('content.length'),
  39. loadRuns:function () {
  40. this.set('loading', true);
  41. var self = this;
  42. //var runsUrl = App.testMode ? "/data/apps/runs.json" : App.apiPrefix + "/jobhistory/workflow?orderBy=startTime&sortDir=DESC&limit=" + App.maxRunsForAppBrowser;
  43. var runsUrl;
  44. if (App.testMode) {
  45. runsUrl = App.get('isHadoop2Stack') ? "/data/apps/runs2.json" : "/data/apps/runs.json";
  46. } else {
  47. runsUrl = App.apiPrefix + this.get("runUrl");
  48. }
  49. App.HttpClient.get(runsUrl, App.runsMapper, {
  50. complete:function (jqXHR, textStatus) {
  51. self.set('loading', false);
  52. self.set('loaded', true);
  53. }
  54. });
  55. },
  56. //Pagination Object
  57. paginationObject:{
  58. iTotalDisplayRecords :0,
  59. iTotalRecords:0,
  60. startIndex:0,
  61. endIndex:0
  62. },
  63. /*
  64. Set number of filtered jobs when switching to all jobs
  65. */
  66. iTotalDisplayRecordsObserver:function(){
  67. if(this.get("filterObject.allFilterActivated")){
  68. this.set("filterObject.allFilterActivated", false);
  69. }else{
  70. this.set("filterObject.filteredDisplayRecords",this.get("paginationObject.iTotalDisplayRecords"));
  71. }
  72. }.observes("paginationObject.iTotalDisplayRecords"),
  73. //Filter object
  74. filterObject : Ember.Object.create({
  75. sSearch_0:"",
  76. sSearch_1:"",
  77. sSearch_2:"",
  78. sSearch_3:"",
  79. minJobs:"",
  80. maxJobs:"",
  81. minDuration:"",
  82. maxDuration:"",
  83. minStartTime:"",
  84. maxStartTime:"",
  85. sSearch:"",
  86. iDisplayLength:"",
  87. iDisplayStart:"",
  88. iSortCol_0:"",
  89. sSortDir_0:"",
  90. tagSearch:"",
  91. allFilterActivated:false,
  92. filteredDisplayRecords:null,
  93. viewType:"all",
  94. viewTypeClickEvent:false,
  95. /**
  96. * Direct binding to job filter field
  97. */
  98. runType:"",
  99. onRunTypeChange: function () {
  100. if (this.runType == "MapReduce") {
  101. if (!App.testMode && !App.get('isHadoop2Stack')) {
  102. this.set("sSearch_2", "mr");
  103. } else {
  104. this.set("sSearch_2", "mapreduce");
  105. }
  106. } else if (this.runType == "Hive") {
  107. this.set("sSearch_2", "hive");
  108. } else if (this.runType == "Pig") {
  109. this.set("sSearch_2", "pig");
  110. } else if (this.runType == "Yarn") {
  111. this.set("sSearch_2", "yarn");
  112. } else {
  113. this.set("sSearch_2", "");
  114. }
  115. }.observes("runType"),
  116. /**
  117. * Direct binding to job filter field
  118. */
  119. jobs:"",
  120. onJobsChange:function(){
  121. var minMaxTmp = this.parseNumber(this.jobs);
  122. this.set("minJobs", minMaxTmp.min);
  123. this.set("maxJobs", minMaxTmp.max);
  124. }.observes("jobs"),
  125. /**
  126. * Direct binding to Duration filter field
  127. */
  128. duration:"",
  129. onDurationChange:function(){
  130. var minMaxTmp = this.parseDuration(this.duration);
  131. this.set("minDuration", minMaxTmp.min);
  132. this.set("maxDuration", minMaxTmp.max);
  133. }.observes("duration"),
  134. /**
  135. * Direct binding to Run Date filter field
  136. */
  137. runDate:"",
  138. onRunDateChange:function(){
  139. var minMaxTmp = this.parseDate(this.runDate);
  140. this.set("minStartTime", minMaxTmp.min);
  141. this.set("maxStartTime", minMaxTmp.max);
  142. }.observes("runDate"),
  143. parseDuration:function(value){
  144. var tmp={
  145. min:"",
  146. max:""
  147. };
  148. var compareChar = isNaN(value.charAt(0)) ? value.charAt(0) : false;
  149. var compareScale = value.match(/s|m|h/);
  150. compareScale = compareScale ? compareScale[0] : "";
  151. var compareValue = compareChar ? parseFloat(value.substr(1, value.length)) : parseFloat(value.substr(0, value.length));
  152. if(isNaN(compareValue)){
  153. return tmp;
  154. }
  155. switch (compareScale) {
  156. case 'h':
  157. tmp.min = Math.ceil((parseFloat(compareValue)-0.0001)*1000*60*60);
  158. tmp.max = Math.floor((parseFloat(compareValue)+0.0001)*1000*60*60);
  159. break;
  160. case 'm':
  161. tmp.min = Math.ceil((parseFloat(compareValue)-0.001)*1000*60);
  162. tmp.max = Math.floor((parseFloat(compareValue)+0.001)*1000*60);
  163. break;
  164. case 's':
  165. tmp.min = Math.ceil((parseFloat(compareValue)-0.01)*1000);
  166. tmp.max = Math.floor((parseFloat(compareValue)+0.01)*1000);
  167. break;
  168. default:
  169. tmp.min = Math.ceil((parseFloat(compareValue)-0.01)*1000);
  170. tmp.max = Math.floor((parseFloat(compareValue)+0.01)*1000);
  171. }
  172. switch (compareChar) {
  173. case '<':
  174. tmp.min="";
  175. break;
  176. case '>':
  177. tmp.max="";
  178. break;
  179. }
  180. return tmp;
  181. },
  182. parseDate:function(value){
  183. var tmp={
  184. min:"",
  185. max:""
  186. };
  187. var nowTime = new Date().getTime();
  188. switch (value){
  189. case 'Any':
  190. break;
  191. case 'Past 1 Day':
  192. tmp.min= nowTime - 86400000;
  193. break;
  194. case 'Past 2 Days':
  195. tmp.min= nowTime - 172800000;
  196. break;
  197. case 'Past 7 Days':
  198. tmp.min= nowTime - 604800000;
  199. break;
  200. case 'Past 14 Days':
  201. tmp.min= nowTime - 1209600000;
  202. break;
  203. case 'Past 30 Days':
  204. tmp.min= nowTime - 2592000000;
  205. break;
  206. case 'Running Now':
  207. tmp.min= nowTime;
  208. break;
  209. }
  210. return tmp;
  211. },
  212. parseBandWidth:function(value){
  213. var tmp={
  214. min:"",
  215. max:""
  216. };
  217. var compareChar = isNaN(value.charAt(0)) ? value.charAt(0) : false;
  218. var compareScale = value.match(/kb|k|mb|m|gb|g/);
  219. compareScale = compareScale ? compareScale[0] : "";
  220. var compareValue = compareChar ? parseFloat(value.substr(1, value.length)) : parseFloat(value.substr(0, value.length));
  221. if(isNaN(compareValue)){
  222. return tmp;
  223. }
  224. switch (compareScale) {
  225. case 'g': case 'gb':
  226. tmp.min = Math.max(1073741824,Math.ceil((compareValue-0.005)*1073741824));
  227. tmp.max = Math.floor((compareValue+0.005)*1073741824);
  228. break;
  229. case 'm': case 'mb':
  230. tmp.min = Math.max(1048576,Math.ceil((compareValue-0.05)*1048576));
  231. tmp.max = Math.min(1073741823,Math.floor((compareValue+0.05)*1048576));
  232. break;
  233. case 'k': case 'kb':
  234. tmp.min = Math.max(1024,Math.ceil((compareValue-0.05)*1024));
  235. tmp.max = Math.min(1048575,Math.floor((compareValue+0.05)*1024));
  236. break;
  237. default:
  238. tmp.min = Math.max(1024,Math.ceil((compareValue-0.05)*1024));
  239. tmp.max = Math.min(1048575,Math.floor((compareValue+0.05)*1024));
  240. }
  241. switch (compareChar) {
  242. case '<':
  243. tmp.min="";
  244. break;
  245. case '>':
  246. tmp.max="";
  247. break;
  248. }
  249. return tmp;
  250. },
  251. parseNumber:function(value){
  252. var tmp={
  253. min:"",
  254. max:""
  255. };
  256. switch (value.charAt(0)) {
  257. case '<':
  258. tmp.max=value.substr(1);
  259. break;
  260. case '>':
  261. tmp.min=value.substr(1);
  262. break;
  263. case '=':
  264. tmp.min=value.substr(1);
  265. tmp.max=value.substr(1);
  266. break;
  267. default:
  268. tmp.min=value;
  269. tmp.max=value;
  270. }
  271. return tmp;
  272. },
  273. /**
  274. * Create link for server request
  275. * @return {String}
  276. */
  277. createAppLink:function(){
  278. var link = "/jobhistory/datatable?";
  279. var arr = [
  280. "sSearch_0", "sSearch_1", "sSearch_2", "sSearch_3", "minJobs",
  281. "maxJobs", "minDuration", "maxDuration", "minStartTime",
  282. "maxStartTime", "sSearch", "iDisplayLength", "iDisplayStart",
  283. "iSortCol_0", "sSortDir_0", "tagSearch"
  284. ];
  285. var notFilterFields = ["iDisplayLength", "iDisplayStart", "iSortCol_0", "sSortDir_0"];
  286. var filtersUsed = false;
  287. for (var n=0; n<arr.length;n++) {
  288. if(this.get(arr[n])){
  289. link += arr[n] + "=" + this.get(arr[n]) + "&";
  290. if (!notFilterFields.contains(arr[n])) {
  291. filtersUsed = true;
  292. }
  293. }
  294. };
  295. link = link.slice(0,link.length-1);
  296. if(!this.get("viewTypeClickEvent")) {
  297. this.set('viewType', filtersUsed?'filtered':'all');
  298. }
  299. return link;
  300. }
  301. }),
  302. /**
  303. * reset all filters in table
  304. *
  305. */
  306. clearFilters: function () {
  307. var obj=this.get("filterObject");
  308. obj.set("sSearch","");
  309. obj.set("sSearch_0","");
  310. obj.set("sSearch_1","");
  311. obj.set("sSearch_2","");
  312. obj.set("sSearch_3","");
  313. obj.set("runType","Any");
  314. obj.set("jobs","");
  315. obj.set("duration","");
  316. obj.set("runDate","Any");
  317. obj.set("tagSearch","");
  318. },
  319. runUrl : "/jobhistory/datatable",
  320. runTimeout : null,
  321. valueObserver: function(){
  322. if(this.get('filterObject.iDisplayLength') > this.get('content.length')) {
  323. this.set('filterObject.iDisplayStart', 0);
  324. }
  325. var link = this.get('filterObject').createAppLink();
  326. if(this.get("filterObject.viewType") == "filtered"){
  327. this.set("runUrl", link);
  328. }else{
  329. this.set("runUrl", "/jobhistory/datatable?iDisplayStart=" + this.get('filterObject.iDisplayStart') + "&iDisplayLength=" + this.get('filterObject.iDisplayLength') +
  330. '&iSortCol_0=' + this.get('filterObject.iSortCol_0') + '&sSortDir_0=' + this.get('filterObject.sSortDir_0'));
  331. }
  332. var timeout = this.get('runTimeout');
  333. var self = this;
  334. clearTimeout(timeout);
  335. timeout = setTimeout(function(){
  336. console.log(self.get("runUrl"));
  337. self.loadRuns();
  338. }, 300);
  339. this.set('runTimeout', timeout);
  340. }.observes(
  341. 'filterObject.sSearch_0',
  342. 'filterObject.sSearch_1',
  343. 'filterObject.sSearch_2',
  344. 'filterObject.sSearch_3',
  345. 'filterObject.minJobs',
  346. 'filterObject.maxJobs',
  347. 'filterObject.minDuration',
  348. 'filterObject.maxDuration',
  349. 'filterObject.minStartTime',
  350. 'filterObject.maxStartTime',
  351. 'filterObject.sSearch',
  352. 'filterObject.iDisplayLength',
  353. 'filterObject.iDisplayStart',
  354. 'filterObject.iSortCol_0',
  355. 'filterObject.sSortDir_0',
  356. 'filterObject.viewType',
  357. 'filterObject.tagSearch'
  358. ),
  359. serverData: "",
  360. summary: null,
  361. /**
  362. * Observer for summary data from server
  363. */
  364. summaryInfo: function(){
  365. var tmp;
  366. var summary = this.get('serverData');
  367. if(!summary){
  368. tmp = {
  369. 'jobs': {
  370. 'avg': '-',
  371. 'min': '-',
  372. 'max': '-'
  373. },
  374. 'duration': {
  375. 'avg': '-',
  376. 'min': '-',
  377. 'max': '-'
  378. },
  379. 'times': {
  380. 'oldest': '-',
  381. 'youngest': '-'
  382. }
  383. };
  384. }else{
  385. tmp = {
  386. 'jobs': {
  387. 'avg': summary.jobs.avg.toFixed(2),
  388. 'min': summary.jobs.min,
  389. 'max': summary.jobs.max
  390. },
  391. 'duration': {
  392. 'avg': date.timingFormat(Math.round(summary.duration.avg)),
  393. 'min': date.timingFormat(summary.duration.min),
  394. 'max': date.timingFormat(summary.duration.max)
  395. },
  396. 'times': {
  397. 'oldest': new Date(summary.times.oldest).toDateString(),
  398. 'youngest': new Date(summary.times.youngest).toDateString()
  399. }
  400. };
  401. }
  402. this.set("summary",tmp);
  403. }.observes('serverData'),
  404. columnsName: Ember.ArrayController.create({
  405. content: [
  406. { name: Em.I18n.t('apps.table.column.appId'), index: 0 },
  407. { name: Em.I18n.t('common.name'), index: 1 },
  408. { name: Em.I18n.t('common.type'), index: 2 },
  409. { name: Em.I18n.t('common.user'), index: 3 },
  410. { name: Em.I18n.t('common.tags'), index: 4 },
  411. { name: Em.I18n.t('apps.avgTable.jobs'), index: 5 },
  412. { name: Em.I18n.t('apps.avgTable.duration'), index: 6 },
  413. { name: Em.I18n.t('apps.table.column.runDate'), index: 7 }
  414. ]
  415. })
  416. })