/** * 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, /** * List of users. * Will be used for filtering in user column. * Go to App.MainAppsView.userFilterView for more information */ users: function () { return this.get('content').mapProperty("userName").uniq().map(function(userName){ return { name: userName, checked: false }; }); }.property('content.length'), loadRuns:function () { 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.parseDuration(this.duration); this.set("minDuration", minMaxTmp.min); this.set("maxDuration", minMaxTmp.max); }.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"), parseDuration:function(value){ var tmp={ min:"", max:"" }; var compareChar = isNaN(value.charAt(0)) ? value.charAt(0) : false; var compareScale = value.match(/s|m|h/); compareScale = compareScale ? compareScale[0] : ""; var compareValue = compareChar ? parseFloat(value.substr(1, value.length)) : parseFloat(value.substr(0, value.length)); if(isNaN(compareValue)){ return tmp; } switch (compareScale) { case 'h': tmp.min = Math.ceil((parseFloat(compareValue)-0.0001)*1000*60*60); tmp.max = Math.floor((parseFloat(compareValue)+0.0001)*1000*60*60); break; case 'm': tmp.min = Math.ceil((parseFloat(compareValue)-0.001)*1000*60); tmp.max = Math.floor((parseFloat(compareValue)+0.001)*1000*60); break; case 's': tmp.min = Math.ceil((parseFloat(compareValue)-0.01)*1000); tmp.max = Math.floor((parseFloat(compareValue)+0.01)*1000); 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; }, 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.match(/kb|k|mb|m|gb|g/); compareScale = compareScale ? compareScale[0] : ""; var compareValue = compareChar ? parseFloat(value.substr(1, value.length)) : parseFloat(value.substr(0, value.length)); if(isNaN(compareValue)){ return tmp; } switch (compareScale) { case 'g': case 'gb': tmp.min = Math.max(1073741824,Math.ceil((compareValue-0.005)*1073741824)); tmp.max = Math.floor((compareValue+0.005)*1073741824); break; case 'm': case 'mb': 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': case 'kb': 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; }, /** * Create link for server request * @return {String} */ createAppLink:function(){ var link = "/jobhistory/datatable?"; var arr = [ "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" ]; for (var n=0; n