Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *    http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 var baseParams;
0019 
0020 var curLogLength;
0021 var startByte;
0022 var endByte;
0023 var totalLogLength;
0024 
0025 var byteLength;
0026 
0027 function setLogScroll(oldHeight) {
0028   var logContent = $(".log-content");
0029   logContent.scrollTop(logContent[0].scrollHeight - oldHeight);
0030 }
0031 
0032 function tailLog() {
0033   var logContent = $(".log-content");
0034   logContent.scrollTop(logContent[0].scrollHeight);
0035 }
0036 
0037 function setLogData() {
0038   $('#log-data').html("Showing " + curLogLength + " Bytes: " + startByte
0039     + " - " + endByte + " of " + totalLogLength);
0040 }
0041 
0042 function disableMoreButton() {
0043   var moreBtn = $(".log-more-btn");
0044   moreBtn.attr("disabled", "disabled");
0045   moreBtn.html("Top of Log");
0046 }
0047 
0048 function noNewAlert() {
0049   var alert = $(".no-new-alert");
0050   alert.css("display", "block");
0051   window.setTimeout(function () {alert.css("display", "none");}, 4000);
0052 }
0053 
0054 
0055 function getRESTEndPoint() {
0056   // If the worker is served from the master through a proxy (see doc on spark.ui.reverseProxy), 
0057   // we need to retain the leading ../proxy/<workerid>/ part of the URL when making REST requests.
0058   // Similar logic is contained in executorspage.js function createRESTEndPoint.
0059   var words = document.baseURI.split('/');
0060   var ind = words.indexOf("proxy");
0061   if (ind > 0) {
0062       return words.slice(0, ind + 2).join('/') + "/log";
0063   }
0064   return "/log"
0065 }
0066 
0067 function loadMore() {
0068   var offset = Math.max(startByte - byteLength, 0);
0069   var moreByteLength = Math.min(byteLength, startByte);
0070 
0071   $.ajax({
0072     type: "GET",
0073     url: getRESTEndPoint() + baseParams + "&offset=" + offset + "&byteLength=" + moreByteLength,
0074     success: function (data) {
0075       var oldHeight = $(".log-content")[0].scrollHeight;
0076       var newlineIndex = data.indexOf('\n');
0077       var dataInfo = data.substring(0, newlineIndex).match(/\d+/g);
0078       var retStartByte = dataInfo[0];
0079       var retLogLength = dataInfo[2];
0080 
0081       var cleanData = data.substring(newlineIndex + 1);
0082       if (retStartByte == 0) {
0083         disableMoreButton();
0084       }
0085       $("pre", ".log-content").prepend(cleanData);
0086 
0087       curLogLength = curLogLength + (startByte - retStartByte);
0088       startByte = retStartByte;
0089       totalLogLength = retLogLength;
0090       setLogScroll(oldHeight);
0091       setLogData();
0092     }
0093   });
0094 }
0095 
0096 function loadNew() {
0097   $.ajax({
0098     type: "GET",
0099     url: getRESTEndPoint() + baseParams + "&byteLength=0",
0100     success: function (data) {
0101       var dataInfo = data.substring(0, data.indexOf('\n')).match(/\d+/g);
0102       var newDataLen = dataInfo[2] - totalLogLength;
0103       if (newDataLen != 0) {
0104         $.ajax({
0105           type: "GET",
0106           url: getRESTEndPoint() + baseParams + "&byteLength=" + newDataLen,
0107           success: function (data) {
0108             var newlineIndex = data.indexOf('\n');
0109             var dataInfo = data.substring(0, newlineIndex).match(/\d+/g);
0110             var retStartByte = dataInfo[0];
0111             var retEndByte = dataInfo[1];
0112             var retLogLength = dataInfo[2];
0113 
0114             var cleanData = data.substring(newlineIndex + 1);
0115             $("pre", ".log-content").append(cleanData);
0116 
0117             curLogLength = curLogLength + (retEndByte - retStartByte);
0118             endByte = retEndByte;
0119             totalLogLength = retLogLength;
0120             tailLog();
0121             setLogData();
0122           }
0123         });
0124       } else {
0125         noNewAlert();
0126       }
0127     }
0128   });
0129 }
0130 
0131 function initLogPage(params, logLen, start, end, totLogLen, defaultLen) {
0132   baseParams = params;
0133   curLogLength = logLen;
0134   startByte = start;
0135   endByte = end;
0136   totalLogLength = totLogLen;
0137   byteLength = defaultLen;
0138   tailLog();
0139   if (startByte == 0) {
0140     disableMoreButton();
0141   }
0142 }