hadoop web项目使用ajax监控mapreduce过程

项目代码可以在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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值