Java 类org.apache.hadoop.hdfs.server.common.JspHelper 实例源码

项目:hadoop    文件:NamenodeWebHdfsMethods.java   
private void init(final UserGroupInformation ugi,
    final DelegationParam delegation,
    final UserParam username, final DoAsParam doAsUser,
    final UriFsPathParam path, final HttpOpParam<?> op,
    final Param<?, ?>... parameters) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("HTTP " + op.getValue().getType() + ": " + op + ", " + path
        + ", ugi=" + ugi + ", " + username + ", " + doAsUser
        + Param.toSortedString(", ", parameters));
  }

  //clear content type
  response.setContentType(null);

  // set the remote address, if coming in via a trust proxy server then
  // the address with be that of the proxied client
  REMOTE_ADDRESS.set(JspHelper.getRemoteAddr(request));
}
项目:hadoop    文件:JournalNodeHttpServer.java   
void start() throws IOException {
  final InetSocketAddress httpAddr = getAddress(conf);

  final String httpsAddrString = conf.get(
      DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_DEFAULT);
  InetSocketAddress httpsAddr = NetUtils.createSocketAddr(httpsAddrString);

  HttpServer2.Builder builder = DFSUtil.httpServerTemplateForNNAndJN(conf,
      httpAddr, httpsAddr, "journal",
      DFSConfigKeys.DFS_JOURNALNODE_KERBEROS_INTERNAL_SPNEGO_PRINCIPAL_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_KEYTAB_FILE_KEY);

  httpServer = builder.build();
  httpServer.setAttribute(JN_ATTRIBUTE_KEY, localJournalNode);
  httpServer.setAttribute(JspHelper.CURRENT_CONF, conf);
  httpServer.addInternalServlet("getJournal", "/getJournal",
      GetJournalEditServlet.class, true);
  httpServer.start();
}
项目:aliyun-oss-hadoop-fs    文件:NamenodeWebHdfsMethods.java   
private void init(final UserGroupInformation ugi,
    final DelegationParam delegation,
    final UserParam username, final DoAsParam doAsUser,
    final UriFsPathParam path, final HttpOpParam<?> op,
    final Param<?, ?>... parameters) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("HTTP " + op.getValue().getType() + ": " + op + ", " + path
        + ", ugi=" + ugi + ", " + username + ", " + doAsUser
        + Param.toSortedString(", ", parameters));
  }

  //clear content type
  response.setContentType(null);

  // set the remote address, if coming in via a trust proxy server then
  // the address with be that of the proxied client
  REMOTE_ADDRESS.set(JspHelper.getRemoteAddr(request));
}
项目:aliyun-oss-hadoop-fs    文件:JournalNodeHttpServer.java   
void start() throws IOException {
  final InetSocketAddress httpAddr = getAddress(conf);

  final String httpsAddrString = conf.get(
      DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_DEFAULT);
  InetSocketAddress httpsAddr = NetUtils.createSocketAddr(httpsAddrString);

  HttpServer2.Builder builder = DFSUtil.httpServerTemplateForNNAndJN(conf,
      httpAddr, httpsAddr, "journal",
      DFSConfigKeys.DFS_JOURNALNODE_KERBEROS_INTERNAL_SPNEGO_PRINCIPAL_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_KEYTAB_FILE_KEY);

  httpServer = builder.build();
  httpServer.setAttribute(JN_ATTRIBUTE_KEY, localJournalNode);
  httpServer.setAttribute(JspHelper.CURRENT_CONF, conf);
  httpServer.addInternalServlet("getJournal", "/getJournal",
      GetJournalEditServlet.class, true);
  httpServer.start();
}
项目:big-c    文件:NamenodeWebHdfsMethods.java   
private void init(final UserGroupInformation ugi,
    final DelegationParam delegation,
    final UserParam username, final DoAsParam doAsUser,
    final UriFsPathParam path, final HttpOpParam<?> op,
    final Param<?, ?>... parameters) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("HTTP " + op.getValue().getType() + ": " + op + ", " + path
        + ", ugi=" + ugi + ", " + username + ", " + doAsUser
        + Param.toSortedString(", ", parameters));
  }

  //clear content type
  response.setContentType(null);

  // set the remote address, if coming in via a trust proxy server then
  // the address with be that of the proxied client
  REMOTE_ADDRESS.set(JspHelper.getRemoteAddr(request));
}
项目:big-c    文件:JournalNodeHttpServer.java   
void start() throws IOException {
  final InetSocketAddress httpAddr = getAddress(conf);

  final String httpsAddrString = conf.get(
      DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_DEFAULT);
  InetSocketAddress httpsAddr = NetUtils.createSocketAddr(httpsAddrString);

  HttpServer2.Builder builder = DFSUtil.httpServerTemplateForNNAndJN(conf,
      httpAddr, httpsAddr, "journal",
      DFSConfigKeys.DFS_JOURNALNODE_KERBEROS_INTERNAL_SPNEGO_PRINCIPAL_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_KEYTAB_FILE_KEY);

  httpServer = builder.build();
  httpServer.setAttribute(JN_ATTRIBUTE_KEY, localJournalNode);
  httpServer.setAttribute(JspHelper.CURRENT_CONF, conf);
  httpServer.addInternalServlet("getJournal", "/getJournal",
      GetJournalEditServlet.class, true);
  httpServer.start();
}
项目:hadoop-2.6.0-cdh5.4.3    文件:NamenodeWebHdfsMethods.java   
private void init(final UserGroupInformation ugi,
    final DelegationParam delegation,
    final UserParam username, final DoAsParam doAsUser,
    final UriFsPathParam path, final HttpOpParam<?> op,
    final Param<?, ?>... parameters) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("HTTP " + op.getValue().getType() + ": " + op + ", " + path
        + ", ugi=" + ugi + ", " + username + ", " + doAsUser
        + Param.toSortedString(", ", parameters));
  }

  //clear content type
  response.setContentType(null);

  // set the remote address, if coming in via a trust proxy server then
  // the address with be that of the proxied client
  REMOTE_ADDRESS.set(JspHelper.getRemoteAddr(request));
}
项目:hadoop-2.6.0-cdh5.4.3    文件:NamenodeJspHelper.java   
private void generateNodeDataHeader(JspWriter out, DatanodeDescriptor d,
    String suffix, boolean alive, int nnInfoPort, String nnaddr, String scheme)
    throws IOException {
  // from nn_browsedfscontent.jsp:
  String url = "///" + JspHelper.Url.authority(scheme, d)
      + "/browseDirectory.jsp?namenodeInfoPort=" + nnInfoPort + "&dir="
      + URLEncoder.encode("/", "UTF-8")
      + JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, nnaddr);

  String name = d.getXferAddrWithHostname();
  if (!name.matches("\\d+\\.\\d+.\\d+\\.\\d+.*"))
    name = name.replaceAll("\\.[^.:]*", "");
  int idx = (suffix != null && name.endsWith(suffix)) ? name
      .indexOf(suffix) : -1;

  out.print(rowTxt() + "<td class=\"name\"> <a title=\"" + url
      + "\" href=\"" + url + "\">"
      + ((idx > 0) ? name.substring(0, idx) : name) + "</a>"
      + ((alive) ? "" : "\n") + "<td class=\"address\">" + d.getXferAddr());
}
项目:hadoop-2.6.0-cdh5.4.3    文件:JournalNodeHttpServer.java   
void start() throws IOException {
  final InetSocketAddress httpAddr = getAddress(conf);

  final String httpsAddrString = conf.get(
      DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_DEFAULT);
  InetSocketAddress httpsAddr = NetUtils.createSocketAddr(httpsAddrString);

  HttpServer2.Builder builder = DFSUtil.httpServerTemplateForNNAndJN(conf,
      httpAddr, httpsAddr, "journal",
      DFSConfigKeys.DFS_JOURNALNODE_KERBEROS_INTERNAL_SPNEGO_PRINCIPAL_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_KEYTAB_FILE_KEY);

  httpServer = builder.build();
  httpServer.setAttribute(JN_ATTRIBUTE_KEY, localJournalNode);
  httpServer.setAttribute(JspHelper.CURRENT_CONF, conf);
  httpServer.addInternalServlet("getJournal", "/getJournal",
      GetJournalEditServlet.class, true);
  httpServer.start();
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestNameNodeJspHelper.java   
@Test(timeout = 15000)
public void testNamenodeJspHelperRedirectToRandomDataNode() throws IOException, InterruptedException {
  final String urlPart = "browseDirectory.jsp?namenodeInfoPort=";                     

  ServletContext context = mock(ServletContext.class);
  HttpServletRequest request = mock(HttpServletRequest.class);
  HttpServletResponse resp = mock(HttpServletResponse.class);          

  when(request.getScheme()).thenReturn("http");
  when(request.getParameter(UserParam.NAME)).thenReturn("localuser");
  when(context.getAttribute(NAMENODE_ATTRIBUTE_KEY)).thenReturn(
      cluster.getNameNode());
  when(context.getAttribute(JspHelper.CURRENT_CONF)).thenReturn(conf);    
  ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
  doAnswer(new Answer<String>() {
    @Override
   public String answer(InvocationOnMock invocation) throws Throwable {
      return null;
      }
  }).when(resp).sendRedirect(captor.capture());

  NamenodeJspHelper.redirectToRandomDataNode(context, request, resp);    
  assertTrue(captor.getValue().contains(urlPart));    
}
项目:hadoop-plus    文件:FileChecksumServlets.java   
/** Create a redirection URL */
private URL createRedirectURL(UserGroupInformation ugi, DatanodeID host,
    HttpServletRequest request, NameNode nn) 
    throws IOException {
  final String hostname = host instanceof DatanodeInfo 
      ? ((DatanodeInfo)host).getHostName() : host.getIpAddr();
  final String scheme = request.getScheme();
  final int port = "https".equals(scheme)
      ? (Integer)getServletContext().getAttribute(DFSConfigKeys.DFS_DATANODE_HTTPS_PORT_KEY)
      : host.getInfoPort();
  final String encodedPath = ServletUtil.getRawPath(request, "/fileChecksum");

  String dtParam = "";
  if (UserGroupInformation.isSecurityEnabled()) {
    String tokenString = ugi.getTokens().iterator().next().encodeToUrlString();
    dtParam = JspHelper.getDelegationTokenUrlParam(tokenString);
  }
  String addr = nn.getNameNodeAddressHostPortString();
  String addrParam = JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, addr);

  return new URL(scheme, hostname, port, 
      "/getFileChecksum" + encodedPath + '?' +
      "ugi=" + ServletUtil.encodeQueryValue(ugi.getShortUserName()) + 
      dtParam + addrParam);
}
项目:hadoop-plus    文件:NamenodeJspHelper.java   
private void generateNodeDataHeader(JspWriter out, DatanodeDescriptor d,
    String suffix, boolean alive, int nnHttpPort, String nnaddr)
    throws IOException {
  // from nn_browsedfscontent.jsp:
  String url = HttpConfig.getSchemePrefix() + d.getHostName() + ":"
      + d.getInfoPort()
      + "/browseDirectory.jsp?namenodeInfoPort=" + nnHttpPort + "&dir="
      + URLEncoder.encode("/", "UTF-8")
      + JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, nnaddr);

  String name = d.getXferAddrWithHostname();
  if (!name.matches("\\d+\\.\\d+.\\d+\\.\\d+.*"))
    name = name.replaceAll("\\.[^.:]*", "");
  int idx = (suffix != null && name.endsWith(suffix)) ? name
      .indexOf(suffix) : -1;

  out.print(rowTxt() + "<td class=\"name\"><a title=\"" + d.getXferAddr()
      + "\" href=\"" + url + "\">"
      + ((idx > 0) ? name.substring(0, idx) : name) + "</a>"
      + ((alive) ? "" : "\n"));
}
项目:FlexMap    文件:NamenodeWebHdfsMethods.java   
private void init(final UserGroupInformation ugi,
    final DelegationParam delegation,
    final UserParam username, final DoAsParam doAsUser,
    final UriFsPathParam path, final HttpOpParam<?> op,
    final Param<?, ?>... parameters) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("HTTP " + op.getValue().getType() + ": " + op + ", " + path
        + ", ugi=" + ugi + ", " + username + ", " + doAsUser
        + Param.toSortedString(", ", parameters));
  }

  //clear content type
  response.setContentType(null);

  // set the remote address, if coming in via a trust proxy server then
  // the address with be that of the proxied client
  REMOTE_ADDRESS.set(JspHelper.getRemoteAddr(request));
}
项目:FlexMap    文件:NamenodeJspHelper.java   
private void generateNodeDataHeader(JspWriter out, DatanodeDescriptor d,
    String suffix, boolean alive, int nnInfoPort, String nnaddr, String scheme)
    throws IOException {
  // from nn_browsedfscontent.jsp:
  String url = "///" + JspHelper.Url.authority(scheme, d)
      + "/browseDirectory.jsp?namenodeInfoPort=" + nnInfoPort + "&dir="
      + URLEncoder.encode("/", "UTF-8")
      + JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, nnaddr);

  String name = d.getXferAddrWithHostname();
  if (!name.matches("\\d+\\.\\d+.\\d+\\.\\d+.*"))
    name = name.replaceAll("\\.[^.:]*", "");
  int idx = (suffix != null && name.endsWith(suffix)) ? name
      .indexOf(suffix) : -1;

  out.print(rowTxt() + "<td class=\"name\"> <a title=\"" + url
      + "\" href=\"" + url + "\">"
      + ((idx > 0) ? name.substring(0, idx) : name) + "</a>"
      + ((alive) ? "" : "\n") + "<td class=\"address\">" + d.getXferAddr());
}
项目:FlexMap    文件:JournalNodeHttpServer.java   
void start() throws IOException {
  final InetSocketAddress httpAddr = getAddress(conf);

  final String httpsAddrString = conf.get(
      DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_DEFAULT);
  InetSocketAddress httpsAddr = NetUtils.createSocketAddr(httpsAddrString);

  HttpServer2.Builder builder = DFSUtil.httpServerTemplateForNNAndJN(conf,
      httpAddr, httpsAddr, "journal",
      DFSConfigKeys.DFS_JOURNALNODE_KERBEROS_INTERNAL_SPNEGO_PRINCIPAL_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_KEYTAB_FILE_KEY);

  httpServer = builder.build();
  httpServer.setAttribute(JN_ATTRIBUTE_KEY, localJournalNode);
  httpServer.setAttribute(JspHelper.CURRENT_CONF, conf);
  httpServer.addInternalServlet("getJournal", "/getJournal",
      GetJournalEditServlet.class, true);
  httpServer.start();
}
项目:FlexMap    文件:TestNameNodeJspHelper.java   
@Test(timeout = 15000)
public void testNamenodeJspHelperRedirectToRandomDataNode() throws IOException, InterruptedException {
  final String urlPart = "browseDirectory.jsp?namenodeInfoPort=";                     

  ServletContext context = mock(ServletContext.class);
  HttpServletRequest request = mock(HttpServletRequest.class);
  HttpServletResponse resp = mock(HttpServletResponse.class);          

  when(request.getScheme()).thenReturn("http");
  when(request.getParameter(UserParam.NAME)).thenReturn("localuser");
  when(context.getAttribute(NAMENODE_ATTRIBUTE_KEY)).thenReturn(
      cluster.getNameNode());
  when(context.getAttribute(JspHelper.CURRENT_CONF)).thenReturn(conf);    
  ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
  doAnswer(new Answer<String>() {
    @Override
   public String answer(InvocationOnMock invocation) throws Throwable {
      return null;
      }
  }).when(resp).sendRedirect(captor.capture());

  NamenodeJspHelper.redirectToRandomDataNode(context, request, resp);    
  assertTrue(captor.getValue().contains(urlPart));    
}
项目:hops    文件:NamenodeJspHelper.java   
private void generateNodeDataHeader(JspWriter out, DatanodeDescriptor d,
    String suffix, boolean alive, int nnHttpPort, String nnaddr)
    throws IOException {
  // from nn_browsedfscontent.jsp:
  String url = HttpConfig2.getSchemePrefix() + d.getHostName() + ":" +
      d.getInfoPort() + "/browseDirectory.jsp?namenodeInfoPort=" +
      nnHttpPort + "&dir=" + URLEncoder.encode("/", "UTF-8") +
      JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, nnaddr);

  String name = d.getXferAddrWithHostname();
  if (!name.matches("\\d+\\.\\d+.\\d+\\.\\d+.*")) {
    name = name.replaceAll("\\.[^.:]*", "");
  }
  int idx =
      (suffix != null && name.endsWith(suffix)) ? name.indexOf(suffix) : -1;

  out.print(rowTxt() + "<td class=\"name\"><a title=\"" + d.getXferAddr() +
      "\" href=\"" + url + "\">" +
      ((idx > 0) ? name.substring(0, idx) : name) + "</a>" +
      ((alive) ? "" : "\n"));
}
项目:hadoop-TCP    文件:NamenodeJspHelper.java   
private void generateNodeDataHeader(JspWriter out, DatanodeDescriptor d,
    String suffix, boolean alive, int nnHttpPort, String nnaddr)
    throws IOException {
  // from nn_browsedfscontent.jsp:
  String url = "///" + d.getHostName() + ":"
      + d.getInfoPort()
      + "/browseDirectory.jsp?namenodeInfoPort=" + nnHttpPort + "&dir="
      + URLEncoder.encode("/", "UTF-8")
      + JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, nnaddr);

  String name = d.getXferAddrWithHostname();
  if (!name.matches("\\d+\\.\\d+.\\d+\\.\\d+.*"))
    name = name.replaceAll("\\.[^.:]*", "");
  int idx = (suffix != null && name.endsWith(suffix)) ? name
      .indexOf(suffix) : -1;

  out.print(rowTxt() + "<td class=\"name\"> <a title=\"" + url
      + "\" href=\"" + url + "\">"
      + ((idx > 0) ? name.substring(0, idx) : name) + "</a>"
      + ((alive) ? "" : "\n") + "<td class=\"address\">" + d.getXferAddr());
}
项目:hardfs    文件:NamenodeJspHelper.java   
private void generateNodeDataHeader(JspWriter out, DatanodeDescriptor d,
    String suffix, boolean alive, int nnHttpPort, String nnaddr)
    throws IOException {
  // from nn_browsedfscontent.jsp:
  String url = "///" + d.getHostName() + ":"
      + d.getInfoPort()
      + "/browseDirectory.jsp?namenodeInfoPort=" + nnHttpPort + "&dir="
      + URLEncoder.encode("/", "UTF-8")
      + JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, nnaddr);

  String name = d.getXferAddrWithHostname();
  if (!name.matches("\\d+\\.\\d+.\\d+\\.\\d+.*"))
    name = name.replaceAll("\\.[^.:]*", "");
  int idx = (suffix != null && name.endsWith(suffix)) ? name
      .indexOf(suffix) : -1;

  out.print(rowTxt() + "<td class=\"name\"> <a title=\"" + url
      + "\" href=\"" + url + "\">"
      + ((idx > 0) ? name.substring(0, idx) : name) + "</a>"
      + ((alive) ? "" : "\n") + "<td class=\"address\">" + d.getXferAddr());
}
项目:hadoop-on-lustre2    文件:NamenodeJspHelper.java   
private void generateNodeDataHeader(JspWriter out, DatanodeDescriptor d,
    String suffix, boolean alive, int nnInfoPort, String nnaddr, String scheme)
    throws IOException {
  // from nn_browsedfscontent.jsp:
  String url = "///" + JspHelper.Url.authority(scheme, d)
      + "/browseDirectory.jsp?namenodeInfoPort=" + nnInfoPort + "&dir="
      + URLEncoder.encode("/", "UTF-8")
      + JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, nnaddr);

  String name = d.getXferAddrWithHostname();
  if (!name.matches("\\d+\\.\\d+.\\d+\\.\\d+.*"))
    name = name.replaceAll("\\.[^.:]*", "");
  int idx = (suffix != null && name.endsWith(suffix)) ? name
      .indexOf(suffix) : -1;

  out.print(rowTxt() + "<td class=\"name\"> <a title=\"" + url
      + "\" href=\"" + url + "\">"
      + ((idx > 0) ? name.substring(0, idx) : name) + "</a>"
      + ((alive) ? "" : "\n") + "<td class=\"address\">" + d.getXferAddr());
}
项目:hadoop-on-lustre2    文件:JournalNodeHttpServer.java   
void start() throws IOException {
  final InetSocketAddress httpAddr = getAddress(conf);

  final String httpsAddrString = conf.get(
      DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_DEFAULT);
  InetSocketAddress httpsAddr = NetUtils.createSocketAddr(httpsAddrString);

  HttpServer2.Builder builder = DFSUtil.httpServerTemplateForNNAndJN(conf,
      httpAddr, httpsAddr, "journal",
      DFSConfigKeys.DFS_JOURNALNODE_INTERNAL_SPNEGO_USER_NAME_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_KEYTAB_FILE_KEY);

  httpServer = builder.build();
  httpServer.setAttribute(JN_ATTRIBUTE_KEY, localJournalNode);
  httpServer.setAttribute(JspHelper.CURRENT_CONF, conf);
  httpServer.addInternalServlet("getJournal", "/getJournal",
      GetJournalEditServlet.class, true);
  httpServer.start();
}
项目:hadoop-on-lustre2    文件:TestNameNodeJspHelper.java   
@Test(timeout = 15000)
public void testNamenodeJspHelperRedirectToRandomDataNode() throws IOException, InterruptedException {
  final String urlPart = "browseDirectory.jsp?namenodeInfoPort=";                     

  ServletContext context = mock(ServletContext.class);
  HttpServletRequest request = mock(HttpServletRequest.class);
  HttpServletResponse resp = mock(HttpServletResponse.class);          

  when(request.getScheme()).thenReturn("http");
  when(request.getParameter(UserParam.NAME)).thenReturn("localuser");
  when(context.getAttribute(NAMENODE_ATTRIBUTE_KEY)).thenReturn(
      cluster.getNameNode());
  when(context.getAttribute(JspHelper.CURRENT_CONF)).thenReturn(conf);    
  ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
  doAnswer(new Answer<String>() {
    @Override
   public String answer(InvocationOnMock invocation) throws Throwable {
      return null;
      }
  }).when(resp).sendRedirect(captor.capture());

  NamenodeJspHelper.redirectToRandomDataNode(context, request, resp);    
  assertTrue(captor.getValue().contains(urlPart));    
}
项目:cumulus    文件:MonitorServlet.java   
/**
* Service a GET request as described below.
* Request:
*   GET http://<host>:<port>/monitor?class=...&key=...&... HTTP/1.1
* */
public void doGet(final HttpServletRequest request, final HttpServletResponse response)
    throws IOException {

    final ServletContext context = getServletContext();
    final Configuration conf = 
            (Configuration) context.getAttribute(JspHelper.CURRENT_CONF);
    final UserGroupInformation ugi = getUGI(request, conf);

    System.out.println("[" + new Date().toString() + "]" + 
        request.getRequestURL() + 
            (request.getQueryString() == null ? "" : ("?"+request.getQueryString())));

    try{
        ugi.doAs(new PrivilegedExceptionAction<Void>(){
            public Void run() throws Exception {
                doAll(request, response);
                return null;
            }
        });
    }catch(InterruptedException e){
        throw new IOException(e);
    }
}
项目:cumulus    文件:StreamFile.java   
/** getting a client for connecting to dfs */
protected DFSClient getDFSClient(HttpServletRequest request)
    throws IOException, InterruptedException {
  final Configuration conf =
    (Configuration) getServletContext().getAttribute(JspHelper.CURRENT_CONF);

  UserGroupInformation ugi = getUGI(request, conf);
  DFSClient client = ugi.doAs(new PrivilegedExceptionAction<DFSClient>() {
    @Override
    public DFSClient run() throws IOException {
      return new DFSClient(nameNodeAddr, conf);
    }
  });

  return client;
}
项目:cumulus    文件:FileDataServlet.java   
/** Create a redirection URI */
protected URI createUri(String parent, HdfsFileStatus i, UserGroupInformation ugi,
    ClientProtocol nnproxy, HttpServletRequest request, String dt)
    throws IOException, URISyntaxException {
  String scheme = request.getScheme();
  final DatanodeID host = pickSrcDatanode(parent, i, nnproxy);
  final String hostname;
  if (host instanceof DatanodeInfo) {
    hostname = ((DatanodeInfo)host).getHostName();
  } else {
    hostname = host.getHost();
  }

  String dtParam="";
  if (dt != null) {
    dtParam=JspHelper.getDelegationTokenUrlParam(dt);
  }

  return new URI(scheme, null, hostname,
      "https".equals(scheme)
        ? (Integer)getServletContext().getAttribute("datanode.https.port")
        : host.getInfoPort(),
          "/streamFile" + i.getFullName(parent), 
          "ugi=" + ugi.getShortUserName() + dtParam, null);
}
项目:cumulus    文件:HdfsProxy.java   
private void initialize(Configuration conf) throws IOException {
  sslAddr = getSslAddr(conf);
  String nn = conf.get("hdfsproxy.dfs.namenode.address");
  if (nn == null)
    throw new IOException("HDFS NameNode address is not specified");
  InetSocketAddress nnAddr = NetUtils.createSocketAddr(nn);
  LOG.info("HDFS NameNode is at: " + nnAddr.getHostName() + ":" + nnAddr.getPort());

  Configuration sslConf = new HdfsConfiguration(false);
  sslConf.addResource(conf.get("hdfsproxy.https.server.keystore.resource",
      "ssl-server.xml"));
  // unit testing
  sslConf.set("proxy.http.test.listener.addr",
              conf.get("proxy.http.test.listener.addr"));

  this.server = new ProxyHttpServer(sslAddr, sslConf);
  this.server.setAttribute("proxy.https.port", server.getPort());
  this.server.setAttribute("name.node.address", nnAddr);
  this.server.setAttribute(JspHelper.CURRENT_CONF, new HdfsConfiguration());
  this.server.addGlobalFilter("ProxyFilter", ProxyFilter.class.getName(), null);
  this.server.addServlet("listPaths", "/listPaths/*", ProxyListPathsServlet.class);
  this.server.addServlet("data", "/data/*", ProxyFileDataServlet.class);
  this.server.addServlet("streamFile", "/streamFile/*", ProxyStreamFile.class);
}
项目:hadoop    文件:UserProvider.java   
@Override
public UserGroupInformation getValue(final HttpContext context) {
  final Configuration conf = (Configuration) servletcontext
      .getAttribute(JspHelper.CURRENT_CONF);
  try {
    return JspHelper.getUGI(servletcontext, request, conf,
        AuthenticationMethod.KERBEROS, false);
  } catch (IOException e) {
    throw new SecurityException(
        SecurityUtil.FAILED_TO_GET_UGI_MSG_HEADER + " " + e, e);
  }
}
项目:hadoop    文件:HftpFileSystem.java   
protected String addDelegationTokenParam(String query) throws IOException {
  String tokenString = null;
  if (UserGroupInformation.isSecurityEnabled()) {
    synchronized (this) {
      tokenAspect.ensureTokenInitialized();
      if (delegationToken != null) {
        tokenString = delegationToken.encodeToUrlString();
        return (query + JspHelper.getDelegationTokenUrlParam(tokenString));
      }
    }
  }
  return query;
}
项目:hadoop    文件:FileChecksumServlets.java   
/** Create a redirection URL */
private URL createRedirectURL(UserGroupInformation ugi, DatanodeID host,
    HttpServletRequest request, NameNode nn) 
    throws IOException {
  final String hostname = host instanceof DatanodeInfo 
      ? host.getHostName() : host.getIpAddr();
  final String scheme = request.getScheme();
  int port = host.getInfoPort();
  if ("https".equals(scheme)) {
    final Integer portObject = (Integer) getServletContext().getAttribute(
        DFSConfigKeys.DFS_DATANODE_HTTPS_PORT_KEY);
    if (portObject != null) {
      port = portObject;
    }
  }
  final String encodedPath = ServletUtil.getRawPath(request, "/fileChecksum");

  String dtParam = "";
  if (UserGroupInformation.isSecurityEnabled()) {
    String tokenString = ugi.getTokens().iterator().next().encodeToUrlString();
    dtParam = JspHelper.getDelegationTokenUrlParam(tokenString);
  }
  String addr = nn.getNameNodeAddressHostPortString();
  String addrParam = JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, addr);

  return new URL(scheme, hostname, port, 
      "/getFileChecksum" + encodedPath + '?' +
      "ugi=" + ServletUtil.encodeQueryValue(ugi.getShortUserName()) + 
      dtParam + addrParam);
}
项目:hadoop    文件:StreamFile.java   
protected DFSClient getDFSClient(HttpServletRequest request)
    throws IOException, InterruptedException {
  final Configuration conf =
    (Configuration) getServletContext().getAttribute(JspHelper.CURRENT_CONF);
  UserGroupInformation ugi = getUGI(request, conf);
  final ServletContext context = getServletContext();
  final DataNode datanode = (DataNode) context.getAttribute("datanode");
  return DatanodeJspHelper.getDFSClient(request, datanode, conf, ugi);
}
项目:hadoop    文件:FileDataServlet.java   
/** Create a redirection URL */
private URL createRedirectURL(String path, String encodedPath, HdfsFileStatus status, 
    UserGroupInformation ugi, ClientProtocol nnproxy, HttpServletRequest request, String dt)
    throws IOException {
  String scheme = request.getScheme();
  final LocatedBlocks blks = nnproxy.getBlockLocations(
      status.getFullPath(new Path(path)).toUri().getPath(), 0, 1);
  final Configuration conf = NameNodeHttpServer.getConfFromContext(
      getServletContext());
  final DatanodeID host = pickSrcDatanode(blks, status, conf);
  final String hostname;
  if (host instanceof DatanodeInfo) {
    hostname = host.getHostName();
  } else {
    hostname = host.getIpAddr();
  }

  int port = "https".equals(scheme) ? host.getInfoSecurePort() : host
      .getInfoPort();

  String dtParam = "";
  if (dt != null) {
    dtParam = JspHelper.getDelegationTokenUrlParam(dt);
  }

  // Add namenode address to the url params
  NameNode nn = NameNodeHttpServer.getNameNodeFromContext(
      getServletContext());
  String addr = nn.getNameNodeAddressHostPortString();
  String addrParam = JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, addr);

  return new URL(scheme, hostname, port,
      "/streamFile" + encodedPath + '?' +
      "ugi=" + ServletUtil.encodeQueryValue(ugi.getShortUserName()) +
      dtParam + addrParam);
}
项目:hadoop    文件:FileDataServlet.java   
/** Select a datanode to service this request.
 * Currently, this looks at no more than the first five blocks of a file,
 * selecting a datanode randomly from the most represented.
 * @param conf 
 */
private DatanodeID pickSrcDatanode(LocatedBlocks blks, HdfsFileStatus i,
    Configuration conf) throws IOException {
  if (i.getLen() == 0 || blks.getLocatedBlocks().size() <= 0) {
    // pick a random datanode
    NameNode nn = NameNodeHttpServer.getNameNodeFromContext(
        getServletContext());
    return NamenodeJspHelper.getRandomDatanode(nn);
  }
  return JspHelper.bestNode(blks, conf);
}
项目:hadoop    文件:DatanodeJspHelper.java   
/** Get DFSClient for a namenode corresponding to the BPID from a datanode */
public static DFSClient getDFSClient(final HttpServletRequest request,
    final DataNode datanode, final Configuration conf,
    final UserGroupInformation ugi) throws IOException, InterruptedException {
  final String nnAddr = request.getParameter(JspHelper.NAMENODE_ADDRESS);
  return getDFSClient(ugi, nnAddr, conf);
}
项目:hadoop    文件:TestStreamFile.java   
private void setUpForDoGetTest(MiniDFSCluster cluster, Path testFile) {

    Mockito.doReturn(CONF).when(mockServletContext).getAttribute(
        JspHelper.CURRENT_CONF);
    Mockito.doReturn(NetUtils.getHostPortString(NameNode.getAddress(CONF)))
      .when(mockHttpServletRequest).getParameter("nnaddr");
    Mockito.doReturn(testFile.toString()).when(mockHttpServletRequest)
      .getPathInfo();
    Mockito.doReturn("/streamFile"+testFile.toString()).when(mockHttpServletRequest)
      .getRequestURI();
  }
项目:aliyun-oss-hadoop-fs    文件:UserProvider.java   
@Override
public UserGroupInformation getValue(final HttpContext context) {
  final Configuration conf = (Configuration) servletcontext
      .getAttribute(JspHelper.CURRENT_CONF);
  try {
    return JspHelper.getUGI(servletcontext, request, conf,
        AuthenticationMethod.KERBEROS, false);
  } catch (IOException e) {
    throw new SecurityException(
        SecurityUtil.FAILED_TO_GET_UGI_MSG_HEADER + " " + e, e);
  }
}
项目:aliyun-oss-hadoop-fs    文件:SecondaryNameNode.java   
/**
 * Start the web server.
 */
@VisibleForTesting
public void startInfoServer() throws IOException {
  final InetSocketAddress httpAddr = getHttpAddress(conf);
  final String httpsAddrString = conf.getTrimmed(
      DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTPS_ADDRESS_KEY,
      DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTPS_ADDRESS_DEFAULT);
  InetSocketAddress httpsAddr = NetUtils.createSocketAddr(httpsAddrString);

  HttpServer2.Builder builder = DFSUtil.httpServerTemplateForNNAndJN(conf,
      httpAddr, httpsAddr, "secondary", DFSConfigKeys.
          DFS_SECONDARY_NAMENODE_KERBEROS_INTERNAL_SPNEGO_PRINCIPAL_KEY,
      DFSConfigKeys.DFS_SECONDARY_NAMENODE_KEYTAB_FILE_KEY);

  infoServer = builder.build();
  infoServer.setAttribute("secondary.name.node", this);
  infoServer.setAttribute("name.system.image", checkpointImage);
  infoServer.setAttribute(JspHelper.CURRENT_CONF, conf);
  infoServer.addInternalServlet("imagetransfer", ImageServlet.PATH_SPEC,
      ImageServlet.class, true);
  infoServer.start();

  LOG.info("Web server init done");

  HttpConfig.Policy policy = DFSUtil.getHttpPolicy(conf);
  int connIdx = 0;
  if (policy.isHttpEnabled()) {
    InetSocketAddress httpAddress =
        infoServer.getConnectorAddress(connIdx++);
    conf.set(DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_KEY,
        NetUtils.getHostPortString(httpAddress));
  }

  if (policy.isHttpsEnabled()) {
    InetSocketAddress httpsAddress =
        infoServer.getConnectorAddress(connIdx);
    conf.set(DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTPS_ADDRESS_KEY,
        NetUtils.getHostPortString(httpsAddress));
  }
}
项目:aliyun-oss-hadoop-fs    文件:DataNodeUGIProvider.java   
private UserGroupInformation nonTokenUGI(String usernameFromQuery,
    String doAsUserFromQuery, String remoteUser) throws IOException {

  UserGroupInformation ugi = UserGroupInformation
      .createRemoteUser(remoteUser);
  JspHelper.checkUsername(ugi.getShortUserName(), usernameFromQuery);
  if (doAsUserFromQuery != null) {
    // create and attempt to authorize a proxy user
    ugi = UserGroupInformation.createProxyUser(doAsUserFromQuery, ugi);
  }
  return ugi;
}
项目:big-c    文件:UserProvider.java   
@Override
public UserGroupInformation getValue(final HttpContext context) {
  final Configuration conf = (Configuration) servletcontext
      .getAttribute(JspHelper.CURRENT_CONF);
  try {
    return JspHelper.getUGI(servletcontext, request, conf,
        AuthenticationMethod.KERBEROS, false);
  } catch (IOException e) {
    throw new SecurityException(
        SecurityUtil.FAILED_TO_GET_UGI_MSG_HEADER + " " + e, e);
  }
}
项目:big-c    文件:HftpFileSystem.java   
protected String addDelegationTokenParam(String query) throws IOException {
  String tokenString = null;
  if (UserGroupInformation.isSecurityEnabled()) {
    synchronized (this) {
      tokenAspect.ensureTokenInitialized();
      if (delegationToken != null) {
        tokenString = delegationToken.encodeToUrlString();
        return (query + JspHelper.getDelegationTokenUrlParam(tokenString));
      }
    }
  }
  return query;
}
项目:big-c    文件:FileChecksumServlets.java   
/** Create a redirection URL */
private URL createRedirectURL(UserGroupInformation ugi, DatanodeID host,
    HttpServletRequest request, NameNode nn) 
    throws IOException {
  final String hostname = host instanceof DatanodeInfo 
      ? host.getHostName() : host.getIpAddr();
  final String scheme = request.getScheme();
  int port = host.getInfoPort();
  if ("https".equals(scheme)) {
    final Integer portObject = (Integer) getServletContext().getAttribute(
        DFSConfigKeys.DFS_DATANODE_HTTPS_PORT_KEY);
    if (portObject != null) {
      port = portObject;
    }
  }
  final String encodedPath = ServletUtil.getRawPath(request, "/fileChecksum");

  String dtParam = "";
  if (UserGroupInformation.isSecurityEnabled()) {
    String tokenString = ugi.getTokens().iterator().next().encodeToUrlString();
    dtParam = JspHelper.getDelegationTokenUrlParam(tokenString);
  }
  String addr = nn.getNameNodeAddressHostPortString();
  String addrParam = JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, addr);

  return new URL(scheme, hostname, port, 
      "/getFileChecksum" + encodedPath + '?' +
      "ugi=" + ServletUtil.encodeQueryValue(ugi.getShortUserName()) + 
      dtParam + addrParam);
}