apps_controller.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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.parseDuration(this.duration);
  130. this.set("minDuration", minMaxTmp.min);
  131. this.set("maxDuration", minMaxTmp.max);
  132. }.observes("duration"),
  133. /**
  134. * Direct binding to Run Date filter field
  135. */
  136. runDate:"",
  137. onRunDateChange:function(){
  138. var minMaxTmp = this.parseDate(this.runDate);
  139. this.set("minStartTime", minMaxTmp.min);
  140. this.set("maxStartTime", minMaxTmp.max);
  141. }.observes("runDate"),
  142. parseDuration:function(value){
  143. var tmp={
  144. min:"",
  145. max:""
  146. };
  147. var compareChar = isNaN(value.charAt(0)) ? value.charAt(0) : false;
  148. var compareScale = value.match(/s|m|h/);
  149. compareScale = compareScale ? compareScale[0] : "";
  150. var compareValue = compareChar ? parseFloat(value.substr(1, value.length)) : parseFloat(value.substr(0, value.length));
  151. if(isNaN(compareValue)){
  152. return tmp;
  153. }
  154. switch (compareScale) {
  155. case 'h':
  156. tmp.min = Math.ceil((parseFloat(compareValue)-0.0001)*1000*60*60);
  157. tmp.max = Math.floor((parseFloat(compareValue)+0.0001)*1000*60*60);
  158. break;
  159. case 'm':
  160. tmp.min = Math.ceil((parseFloat(compareValue)-0.001)*1000*60);
  161. tmp.max = Math.floor((parseFloat(compareValue)+0.001)*1000*60);
  162. break;
  163. case 's':
  164. tmp.min = Math.ceil((parseFloat(compareValue)-0.01)*1000);
  165. tmp.max = Math.floor((parseFloat(compareValue)+0.01)*1000);
  166. break;
  167. default:
  168. tmp.min = Math.max(1024,Math.ceil((compareValue-0.05)*1024));
  169. tmp.max = Math.min(1048575,Math.floor((compareValue+0.05)*1024));
  170. }
  171. switch (compareChar) {
  172. case '<':
  173. tmp.min="";
  174. break;
  175. case '>':
  176. tmp.max="";
  177. break;
  178. }
  179. return tmp;
  180. },
  181. parseDate:function(value){
  182. var tmp={
  183. min:"",
  184. max:""
  185. };
  186. var nowTime = new Date().getTime();
  187. switch (value){
  188. case 'Any':
  189. break;
  190. case 'Past 1 Day':
  191. tmp.min= nowTime - 86400000;
  192. break;
  193. case 'Past 2 Days':
  194. tmp.min= nowTime - 172800000;
  195. break;
  196. case 'Past 7 Days':
  197. tmp.min= nowTime - 604800000;
  198. break;
  199. case 'Past 14 Days':
  200. tmp.min= nowTime - 1209600000;
  201. break;
  202. case 'Past 30 Days':
  203. tmp.min= nowTime - 2592000000;
  204. break;
  205. case 'Running Now':
  206. tmp.min= nowTime;
  207. break;
  208. }
  209. return tmp;
  210. },
  211. parseBandWidth:function(value){
  212. var tmp={
  213. min:"",
  214. max:""
  215. };
  216. var compareChar = isNaN(value.charAt(0)) ? value.charAt(0) : false;
  217. var compareScale = value.match(/kb|k|mb|m|gb|g/);
  218. compareScale = compareScale ? compareScale[0] : "";
  219. var compareValue = compareChar ? parseFloat(value.substr(1, value.length)) : parseFloat(value.substr(0, value.length));
  220. if(isNaN(compareValue)){
  221. return tmp;
  222. }
  223. switch (compareScale) {
  224. case 'g': case 'gb':
  225. tmp.min = Math.max(1073741824,Math.ceil((compareValue-0.005)*1073741824));
  226. tmp.max = Math.floor((compareValue+0.005)*1073741824);
  227. break;
  228. case 'm': case 'mb':
  229. tmp.min = Math.max(1048576,Math.ceil((compareValue-0.05)*1048576));
  230. tmp.max = Math.min(1073741823,Math.floor((compareValue+0.05)*1048576));
  231. break;
  232. case 'k': case 'kb':
  233. tmp.min = Math.max(1024,Math.ceil((compareValue-0.05)*1024));
  234. tmp.max = Math.min(1048575,Math.floor((compareValue+0.05)*1024));
  235. break;
  236. default:
  237. tmp.min = Math.max(1024,Math.ceil((compareValue-0.05)*1024));
  238. tmp.max = Math.min(1048575,Math.floor((compareValue+0.05)*1024));
  239. }
  240. switch (compareChar) {
  241. case '<':
  242. tmp.min="";
  243. break;
  244. case '>':
  245. tmp.max="";
  246. break;
  247. }
  248. return tmp;
  249. },
  250. parseNumber:function(value){
  251. var tmp={
  252. min:"",
  253. max:""
  254. };
  255. switch (value.charAt(0)) {
  256. case '<':
  257. tmp.max=value.substr(1);
  258. break;
  259. case '>':
  260. tmp.min=value.substr(1);
  261. break;
  262. case '=':
  263. tmp.min=value.substr(1);
  264. tmp.max=value.substr(1);
  265. break;
  266. default:
  267. tmp.min=value;
  268. tmp.max=value;
  269. }
  270. return tmp;
  271. },
  272. createAppLink:function(){
  273. var link = "/jobhistory/datatable?";
  274. if(this.sSearch_0){
  275. link += "sSearch_0=" + this.sSearch_0 + "&";
  276. }
  277. if(this.sSearch_1){
  278. link += "sSearch_1=" + this.sSearch_1 + "&";
  279. }
  280. if(this.sSearch_2 && this.sSearch_2 != "Any"){
  281. link += "sSearch_2=" + this.sSearch_2 + "&";
  282. }
  283. if(this.sSearch_3){
  284. link += "sSearch_3=" + this.sSearch_3 + "&";
  285. }
  286. if(this.minJobs){
  287. link += "minJobs=" + this.minJobs + "&";
  288. }
  289. if(this.maxJobs){
  290. link += "maxJobs=" + this.maxJobs + "&";
  291. }
  292. if(this.minInputBytes){
  293. link += "minInputBytes=" + this.minInputBytes + "&";
  294. }
  295. if(this.maxInputBytes){
  296. link += "maxInputBytes=" + this.maxInputBytes + "&";
  297. }
  298. if(this.minOutputBytes){
  299. link += "minOutputBytes=" + this.minOutputBytes + "&";
  300. }
  301. if(this.maxOutputBytes){
  302. link += "maxOutputBytes=" + this.maxOutputBytes + "&";
  303. }
  304. if(this.minDuration){
  305. link += "minDuration=" + this.minDuration + "&";
  306. }
  307. if(this.maxDuration){
  308. link += "maxDuration=" + this.maxDuration + "&";
  309. }
  310. if(this.minStartTime){
  311. link += "minStartTime=" + this.minStartTime + "&";
  312. }
  313. if(this.maxStartTime){
  314. link += "maxStartTime=" + this.maxStartTime + "&";
  315. }
  316. if(this.sSearch){
  317. link += "sSearch=" + this.sSearch + "&";
  318. }
  319. if(this.iDisplayLength){
  320. link += "iDisplayLength=" + this.iDisplayLength + "&";
  321. }
  322. if(this.iDisplayStart){
  323. link += "iDisplayStart=" + this.iDisplayStart + "&";
  324. }
  325. if(this.iSortCol_0){
  326. link += "iSortCol_0=" + this.iSortCol_0 + "&";
  327. }
  328. if(this.sSortDir_0){
  329. link += "sSortDir_0=" + this.sSortDir_0 + "&";
  330. }
  331. link = link.slice(0,link.length-1);
  332. var valueInString=link.match(/&/g);
  333. if(!this.get("viewTypeClickEvent"))
  334. if(valueInString != null){
  335. this.set("viewType","filtered");
  336. }else{
  337. this.set("viewType","all");
  338. }
  339. return link;
  340. }
  341. }),
  342. runUrl : "/jobhistory/datatable",
  343. runTimeout : null,
  344. valueObserver: function(){
  345. var link = this.get('filterObject').createAppLink();
  346. if(this.get("filterObject.viewType") == "filtered"){
  347. this.set("runUrl", link);
  348. }else{
  349. this.set("runUrl", "/jobhistory/datatable?iDisplayLength="+this.get('filterObject.iDisplayLength'));
  350. }
  351. var timeout = this.get('runTimeout');
  352. var self = this;
  353. clearTimeout(timeout);
  354. timeout = setTimeout(function(){
  355. console.log(self.get("runUrl"));
  356. self.loadRuns();
  357. }, 300);
  358. this.set('runTimeout', timeout);
  359. }.observes(
  360. 'filterObject.sSearch_0',
  361. 'filterObject.sSearch_1',
  362. 'filterObject.sSearch_2',
  363. 'filterObject.sSearch_3',
  364. 'filterObject.minJobs',
  365. 'filterObject.maxJobs',
  366. 'filterObject.minInputBytes',
  367. 'filterObject.maxInputBytes',
  368. 'filterObject.minOutputBytes',
  369. 'filterObject.maxOutputBytes',
  370. 'filterObject.minDuration',
  371. 'filterObject.maxDuration',
  372. 'filterObject.minStartTime',
  373. 'filterObject.maxStartTime',
  374. 'filterObject.sSearch',
  375. 'filterObject.iDisplayLength',
  376. 'filterObject.iDisplayStart',
  377. 'filterObject.iSortCol_0',
  378. 'filterObject.sSortDir_0',
  379. 'filterObject.viewType'
  380. ),
  381. serverData: null,
  382. summary: null,
  383. /**
  384. * Observer for summary data from server
  385. */
  386. summaryInfo: function(){
  387. var tmp;
  388. var summary = this.get('serverData');
  389. if(!summary){
  390. tmp = {
  391. 'jobs': {
  392. 'avg': 'undefined',
  393. 'min': 'undefined',
  394. 'max': 'undefined'
  395. },
  396. 'input': {
  397. 'avg': 'undefined',
  398. 'min': 'undefined',
  399. 'max': 'undefined'
  400. },
  401. 'output': {
  402. 'avg': 'undefined',
  403. 'min': 'undefined',
  404. 'max': 'undefined'
  405. },
  406. 'duration': {
  407. 'avg': 'undefined',
  408. 'min': 'undefined',
  409. 'max': 'undefined'
  410. },
  411. 'times': {
  412. 'oldest': 'undefined',
  413. 'youngest': 'undefined'
  414. }
  415. };
  416. }else{
  417. tmp = {
  418. 'jobs': {
  419. 'avg': summary.jobs.avg.toFixed(2),
  420. 'min': summary.jobs.min,
  421. 'max': summary.jobs.max
  422. },
  423. 'input': {
  424. 'avg': misc.formatBandwidth(summary.input.avg),
  425. 'min': misc.formatBandwidth(summary.input.min),
  426. 'max': misc.formatBandwidth(summary.input.max)
  427. },
  428. 'output': {
  429. 'avg': misc.formatBandwidth(summary.output.avg),
  430. 'min': misc.formatBandwidth(summary.output.min),
  431. 'max': misc.formatBandwidth(summary.output.max)
  432. },
  433. 'duration': {
  434. 'avg': date.timingFormat(Math.round(summary.duration.avg)),
  435. 'min': date.timingFormat(summary.duration.min),
  436. 'max': date.timingFormat(summary.duration.max)
  437. },
  438. 'times': {
  439. 'oldest': new Date(summary.times.oldest).toDateString(),
  440. 'youngest': new Date(summary.times.youngest).toDateString()
  441. }
  442. };
  443. }
  444. this.set("summary",tmp);
  445. }.observes('serverData'),
  446. columnsName: Ember.ArrayController.create({
  447. content: [
  448. { name: 'App ID', index: 0 },
  449. { name: 'Name', index: 1 },
  450. { name: 'Type', index: 2 },
  451. { name: 'User', index: 3 },
  452. { name: 'Jobs', index: 4 },
  453. { name: 'Input', index: 5 },
  454. { name: 'Output', index: 6 },
  455. { name: 'Duration', index: 7 },
  456. { name: 'Run Date', index: 8 }
  457. ]
  458. })
  459. })