apps_controller.js 13 KB

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