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