项目代码可以在http://download.csdn.net/detail/fansy1990/5590951 下载;
Hadoop集群版本:1.0.4 ,结合myeclipse开发;
此次的hadoop web项目是前次的改进版,增加了ajax技术,主要用在了路径的检查(字符串检查和hdfs交互)以及在监控mapreduce过程时和后台交互获得job信息;
整个项目的思路大概如下:
获取job信息的jsp如下:
- <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
- <%@ page import ="util.*" %>
- <%@ page import ="org.apache.hadoop.conf.*" %>
- <html>
- <script language='javascript'>
- timeId = setInterval("myrefresh()",2000);
- var xmlHttpShow;
- function createXMLHttpInRequest(){
- if(window.XMLHttpRequest){
- xmlHttpShow=new XMLHttpRequest();
- }else{
- xmlHttpShow=new ActiveXObject("Microsoft.XMLHTTP");
- }
- }
- function myrefresh(){
- // alert("ok");
- if(document.getElementById("redProgress").innerText.indexOf("100.0%")==0){
- clearInterval(timeId);
- }
- createXMLHttpInRequest();
- var url="validate/get_progress.jsp?time="+new Date().getTime();
- xmlHttpShow.open("get",url,true);
- // 把方法地址赋值给xmlHttp的onreadystatechange属性
- xmlHttpShow.onreadystatechange=showcallback;
- xmlHttpShow.send(null);
- }
- function showcallback(){
- var progress=xmlHttpShow.responseText;
- var a=progress.indexOf(",");
- var length=progress.length;
- document.getElementById("mapProgress").innerText=progress.substring(0,a);
- document.getElementById("redProgress").innerText=progress.substring(a+1,length);
- }
- </script>
- <head>
- <title>My JSP 'bottom_print.jsp' starting page</title>
- </head>
- <%
- String jobName=request.getParameter("jobName");
- %>
- <body>
- <h3>Map Reduce Progress</h3> <br>
- <table border="1">
- <tr>
- <th>Job Name</th>
- <td><%=jobName %></td>
- </tr>
- <tr>
- <th>Map Progress</th>
- <td id="mapProgress">0.00%</td>
- </tr>
- <tr>
- <th>Reduce Progress</th>
- <td id="redProgress">0.00%</td>
- </tr>
- </table>
- </body>
- </html>
配置Hadoop集群的文件在:src/util/Utils.java文件里面;
分享,快乐,成长
转载请注明出处:http://blog.csdn.net/fansy1990