/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var App = require('app'); var misc = require('utils/misc'); var date = require('utils/date'); App.MainAppsController = Em.ArrayController.extend({ name:'mainAppsController', content: [], loaded : false, loading : false, loadRuns:function () { console.log("--------------------loadRuns"); this.set('loading', true); var self = this; //var runsUrl = App.testMode ? "/data/apps/runs.json" : App.apiPrefix + "/jobhistory/workflow?orderBy=startTime&sortDir=DESC&limit=" + App.maxRunsForAppBrowser; var runsUrl = App.testMode ? "/data/apps/runs.json" : App.apiPrefix + this.get("runUrl"); App.HttpClient.get(runsUrl, App.runsMapper, { complete:function (jqXHR, textStatus) { self.set('loading', false); self.set('loaded', true); } }); }, //Pagination Object paginationObject:{ iTotalDisplayRecords :null, iTotalRecords:null, startIndex:null, endIndex:null }, /* Set number of filtered jobs when switching to all jobs */ iTotalDisplayRecordsObserver:function(){ if(this.get("filterObject.allFilterActivated")){ //this.set("paginationObject.filteredDisplayRecords","-10"); this.set("filterObject.allFilterActivated", false); }else{ this.set("filterObject.filteredDisplayRecords",this.get("paginationObject.iTotalDisplayRecords")); } }.observes("paginationObject.iTotalDisplayRecords"), //Filter object filterObject : Ember.Object.create({ sSearch_0:"", sSearch_1:"", sSearch_2:"", sSearch_3:"", minJobs:"", maxJobs:"", minInputBytes:"", maxInputBytes:"", minOutputBytes:"", maxOutputBytes:"", minDuration:"", maxDuration:"", minStartTime:"", maxStartTime:"", sSearch:"", iDisplayLength:"", iDisplayStart:"", iSortCol_0:"", sSortDir_0:"", allFilterActivated:false, filteredDisplayRecords:null, viewType:"all", viewTypeClickEvent:false, /** * Direct binding to job filter field */ runType:"", onRunTypeChange:function(){ if(this.runType == "MapReduce"){ this.set("sSearch_2","mr"); }else if(this.runType == "Hive"){ this.set("sSearch_2","hive"); }else if(this.runType == "Pig"){ this.set("sSearch_2","pig"); }else{ this.set("sSearch_2",""); } }.observes("runType"), /** * Direct binding to job filter field */ jobs:"", onJobsChange:function(){ var minMaxTmp = this.parseNumber(this.jobs); this.set("minJobs", minMaxTmp.min); this.set("maxJobs", minMaxTmp.max); }.observes("jobs"), /** * Direct binding to Input filter field */ input:"", onInputChange:function(){ var minMaxTmp = this.parseBandWidth(this.input); this.set("minInputBytes", minMaxTmp.min); this.set("maxInputBytes", minMaxTmp.max); }.observes("input"), /** * Direct binding to Output filter field */ output:"", onOutputChange:function(){ var minMaxTmp = this.parseBandWidth(this.output); this.set("minOutputBytes", minMaxTmp.min); this.set("maxOutputBytes", minMaxTmp.max); }.observes("output"), /** * Direct binding to Duration filter field */ duration:"", onDurationChange:function(){ var minMaxTmp = this.parseNumber(this.duration); if(parseFloat(minMaxTmp.min) == parseFloat(minMaxTmp.max)){ this.set("minDuration" ,Math.ceil((parseFloat(minMaxTmp.min)-0.01)*1000)); this.set("maxDuration" ,Math.floor((parseFloat(minMaxTmp.max)+0.01)*1000)); }else{ this.set("minDuration", parseFloat(minMaxTmp.min)*1000); this.set("maxDuration", parseFloat(minMaxTmp.max)*1000); } }.observes("duration"), /** * Direct binding to Run Date filter field */ runDate:"", onRunDateChange:function(){ var minMaxTmp = this.parseDate(this.runDate); this.set("minStartTime", minMaxTmp.min); this.set("maxStartTime", minMaxTmp.max); }.observes("runDate"), parseDate:function(value){ var tmp={ min:"", max:"" }; var nowTime = new Date().getTime(); switch (value){ case 'Any': break; case 'Past 1 Day': tmp.min= nowTime - 86400000; break; case 'Past 2 Days': tmp.min= nowTime - 172800000; break; case 'Past 7 Days': tmp.min= nowTime - 604800000; break; case 'Past 14 Days': tmp.min= nowTime - 1209600000; break; case 'Past 30 Days': tmp.min= nowTime - 2592000000; break; case 'Running Now': tmp.min= nowTime; break; } return tmp; }, parseBandWidth:function(value){ var tmp={ min:"", max:"" }; var compareChar = isNaN(value.charAt(0)) ? value.charAt(0) : false; var compareScale = value.charAt(value.length - 1); var compareValue = compareChar ? parseFloat(value.substr(1, value.length)) : parseFloat(value.substr(0, value.length)); if(isNaN(compareValue)){ return tmp; } switch (compareScale) { case 'g': tmp.min = Math.max(1073741824,Math.ceil((compareValue-0.005)*1073741824)); tmp.max = Math.floor((compareValue+0.005)*1073741824); break; case 'm': tmp.min = Math.max(1048576,Math.ceil((compareValue-0.05)*1048576)); tmp.max = Math.min(1073741823,Math.floor((compareValue+0.05)*1048576)); break; case 'k': tmp.min = Math.max(1024,Math.ceil((compareValue-0.05)*1024)); tmp.max = Math.min(1048575,Math.floor((compareValue+0.05)*1024)); break; default: tmp.min = Math.max(1024,Math.ceil((compareValue-0.05)*1024)); tmp.max = Math.min(1048575,Math.floor((compareValue+0.05)*1024)); } switch (compareChar) { case '<': tmp.min=""; break; case '>': tmp.max=""; break; } return tmp; }, parseNumber:function(value){ var tmp={ min:"", max:"" }; switch (value.charAt(0)) { case '<': tmp.max=value.substr(1); break; case '>': tmp.min=value.substr(1); break; case '=': tmp.min=value.substr(1); tmp.max=value.substr(1); break; default: tmp.min=value; tmp.max=value; } return tmp; }, createAppLink:function(){ var link = "/jobhistory/datatable?"; if(this.sSearch_0){ link += "sSearch_0=" + this.sSearch_0 + "&"; } if(this.sSearch_1){ link += "sSearch_1=" + this.sSearch_1 + "&"; } if(this.sSearch_2 && this.sSearch_2 != "Any"){ link += "sSearch_2=" + this.sSearch_2 + "&"; } if(this.sSearch_3){ link += "sSearch_3=" + this.sSearch_3 + "&"; } if(this.minJobs){ link += "minJobs=" + this.minJobs + "&"; } if(this.maxJobs){ link += "maxJobs=" + this.maxJobs + "&"; } if(this.minInputBytes){ link += "minInputBytes=" + this.minInputBytes + "&"; } if(this.maxInputBytes){ link += "maxInputBytes=" + this.maxInputBytes + "&"; } if(this.minOutputBytes){ link += "minOutputBytes=" + this.minOutputBytes + "&"; } if(this.maxOutputBytes){ link += "maxOutputBytes=" + this.maxOutputBytes + "&"; } if(this.minDuration){ link += "minDuration=" + this.minDuration + "&"; } if(this.maxDuration){ link += "maxDuration=" + this.maxDuration + "&"; } if(this.minStartTime){ link += "minStartTime=" + this.minStartTime + "&"; } if(this.maxStartTime){ link += "maxStartTime=" + this.maxStartTime + "&"; } if(this.sSearch){ link += "sSearch=" + this.sSearch + "&"; } if(this.iDisplayLength){ link += "iDisplayLength=" + this.iDisplayLength + "&"; } if(this.iDisplayStart){ link += "iDisplayStart=" + this.iDisplayStart + "&"; } if(this.iSortCol_0){ link += "iSortCol_0=" + this.iSortCol_0 + "&"; } if(this.sSortDir_0){ link += "sSortDir_0=" + this.sSortDir_0 + "&"; } link = link.slice(0,link.length-1); var valueInString=link.match(/&/g); if(!this.get("viewTypeClickEvent")) if(valueInString != null){ this.set("viewType","filtered"); }else{ this.set("viewType","all"); } return link; } }), runUrl : "/jobhistory/datatable", runTimeout : null, valueObserver: function(){ var link = this.get('filterObject').createAppLink(); if(this.get("filterObject.viewType") == "filtered"){ this.set("runUrl", link); }else{ this.set("runUrl", "/jobhistory/datatable?iDisplayLength="+this.get('filterObject.iDisplayLength')); } var timeout = this.get('runTimeout'); var self = this; clearTimeout(timeout); timeout = setTimeout(function(){ console.log(self.get("runUrl")); self.loadRuns(); }, 300); this.set('runTimeout', timeout); }.observes( 'filterObject.sSearch_0', 'filterObject.sSearch_1', 'filterObject.sSearch_2', 'filterObject.sSearch_3', 'filterObject.minJobs', 'filterObject.maxJobs', 'filterObject.minInputBytes', 'filterObject.maxInputBytes', 'filterObject.minOutputBytes', 'filterObject.maxOutputBytes', 'filterObject.minDuration', 'filterObject.maxDuration', 'filterObject.minStartTime', 'filterObject.maxStartTime', 'filterObject.sSearch', 'filterObject.iDisplayLength', 'filterObject.iDisplayStart', 'filterObject.iSortCol_0', 'filterObject.sSortDir_0', 'filterObject.viewType' ), serverData: null, summary: null, /** * Observer for summary data from server */ summaryInfo: function(){ var tmp; var summary = this.get('serverData'); if(!summary){ tmp = { 'jobs': { 'avg': 'undefined', 'min': 'undefined', 'max': 'undefined' }, 'input': { 'avg': 'undefined', 'min': 'undefined', 'max': 'undefined' }, 'output': { 'avg': 'undefined', 'min': 'undefined', 'max': 'undefined' }, 'duration': { 'avg': 'undefined', 'min': 'undefined', 'max': 'undefined' }, 'times': { 'oldest': 'undefined', 'youngest': 'undefined' } }; }else{ tmp = { 'jobs': { 'avg': summary.jobs.avg.toFixed(2), 'min': summary.jobs.min, 'max': summary.jobs.max }, 'input': { 'avg': misc.formatBandwidth(summary.input.avg), 'min': misc.formatBandwidth(summary.input.min), 'max': misc.formatBandwidth(summary.input.max) }, 'output': { 'avg': misc.formatBandwidth(summary.output.avg), 'min': misc.formatBandwidth(summary.output.min), 'max': misc.formatBandwidth(summary.output.max) }, 'duration': { 'avg': date.timingFormat(Math.round(summary.duration.avg)), 'min': date.timingFormat(summary.duration.min), 'max': date.timingFormat(summary.duration.max) }, 'times': { 'oldest': new Date(summary.times.oldest).toDateString(), 'youngest': new Date(summary.times.youngest).toDateString() } }; } this.set("summary",tmp); }.observes('serverData'), columnsName: Ember.ArrayController.create({ content: [ { name: 'App ID', index: 0 }, { name: 'Name', index: 1 }, { name: 'Type', index: 2 }, { name: 'User', index: 3 }, { name: 'Jobs', index: 4 }, { name: 'Input', index: 5 }, { name: 'Output', index: 6 }, { name: 'Duration', index: 7 }, { name: 'Run Date', index: 8 } ] }) })