Hadoop Web项目使用Ajax监控Mapreduce过程

来源:互联网 发布:西安java开发培训机构 编辑:程序博客网 时间:2024/06/05 16:25

adoop Web项目的改进版,新增Ajax技术。Ajax主要是在浏览器中输入hdfs路径时的后台检查和在监控任务执行状态时使用Ajax去和后台交互,获取job信息。

项目代码下载

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /2013年资料/6月/17日/Hadoop Web项目使用Ajax监控Mapreduce过程

整个项目的思路大概如下:

获取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

原创粉丝点击