Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* 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.
*/
package org.apache.hadoop.mapred;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/** The servlet that outputs svg graphics for map / reduce task
* statuses
*/
public class TaskGraphServlet extends HttpServlet {
private static final long serialVersionUID = -1365683739392460020L;
/**height of the graph w/o margins*/
public static final int width = 600;
/**height of the graph w/o margins*/
public static final int height = 200;
/**margin space on y axis */
public static final int ymargin = 20;
/**margin space on x axis */
public static final int xmargin = 80;
private static final float oneThird = 1f / 3f;
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("image/svg+xml");
JobTracker tracker =
(JobTracker) getServletContext().getAttribute("job.tracker");
String jobIdStr = request.getParameter("jobid");
if(jobIdStr == null)
return;
JobID jobId = JobID.forName(jobIdStr);
final boolean isMap = "map".equalsIgnoreCase(request.getParameter("type"));
final TaskReport[] reports = isMap? tracker.getMapTaskReports(jobId)
: tracker.getReduceTaskReports(jobId);
if(reports == null || reports.length == 0) {
return;
}
final int numTasks = reports.length;
int tasksPerBar = (int)Math.ceil(numTasks / 600d);
int numBars = (int) Math.ceil((double)numTasks / tasksPerBar);
int w = Math.max(600, numBars);
int barWidth = Math.min(10, w / numBars); //min 1px, max 10px
int barsPerNotch = (int)Math.ceil(10d / barWidth);
w = w + numBars / barsPerNotch;
int totalWidth = w + 2 * xmargin;
//draw a white rectangle
final PrintWriter out = response.getWriter();
out.print("\n" +
"\n" +
"\n\n"+
"");
}
/**Computes average progress per bar*/
private float getMapAvarageProgress(int tasksPerBar, int index
, TaskReport[] reports ) {
float progress = 0f;
int k=0;
for(;k < tasksPerBar && index + k < reports.length; k++) {
progress += reports[index + k].getProgress();
}
progress /= k;
return progress;
}
/**Computes average progresses per bar*/
private float[] getReduceAvarageProgresses(int tasksPerBar, int index
, TaskReport[] reports ) {
float[] progresses = new float[] {0,0,0};
int k=0;
for(;k < tasksPerBar && index + k < reports.length; k++) {
float progress = reports[index+k].getProgress();
for(int j=0; progress > 0 ; j++, progress -= oneThird) {
if(progress > oneThird)
progresses[j] += 1f;
else
progresses[j] += progress * 3 ;
}
}
for(int j=0; j<3; j++) { progresses[j] /= k;}
return progresses;
}
private void printRect(PrintWriter out, int width, int height
, int x, int y, String color) throws IOException {
if(height > 0) {
out.print("\n");
}
}
private void printLine(PrintWriter out, int x1, int x2
, int y1, int y2, String color) throws IOException {
out.print("\n");
}
private void printText(PrintWriter out, int x, int y, String text
, String anchor) throws IOException {
out.print("");
out.print(text); out.print("\n");
}
}