From 43679fcccd3ed35cf1bf15fe42001106170761a0 Mon Sep 17 00:00:00 2001 From: Aaron Myers Date: Wed, 1 Feb 2012 01:29:06 +0000 Subject: [PATCH] HDFS-2845. SBN should not allow browsing of the file system via web UI. Contributed by Bikas Saha. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-1623@1238897 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-hdfs/CHANGES.HDFS-1623.txt | 2 + .../src/main/webapps/hdfs/corrupt_files.jsp | 9 ++- .../src/main/webapps/hdfs/dfshealth.jsp | 8 ++- .../src/main/webapps/hdfs/dfsnodelist.jsp | 7 +- .../hdfs/server/namenode/ha/TestHAWebUI.java | 70 +++++++++++++++++++ 5 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAWebUI.java diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt index fe88dbbe97..d3a725ba86 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt @@ -143,3 +143,5 @@ HDFS-2691. Fixes for pipeline recovery in an HA cluster: report RBW replicas imm HDFS-2824. Fix failover when prior NN died just after creating an edit log segment. (atm via todd) HDFS-2853. HA: NN fails to start if the shared edits dir is marked required (atm via eli) + +HDFS-2845. SBN should not allow browsing of the file system via web UI. (Bikas Saha via atm) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/corrupt_files.jsp b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/corrupt_files.jsp index a71f40f26e..a4906a5880 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/corrupt_files.jsp +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/corrupt_files.jsp @@ -23,6 +23,7 @@ import="org.apache.hadoop.fs.FileStatus" import="org.apache.hadoop.fs.FileUtil" import="org.apache.hadoop.fs.Path" + import="org.apache.hadoop.ha.HAServiceProtocol.HAServiceState" import="java.util.Collection" import="java.util.Arrays" %> <%!//for java.io.Serializable @@ -30,6 +31,8 @@ <% NameNode nn = NameNodeHttpServer.getNameNodeFromContext(application); FSNamesystem fsn = nn.getNamesystem(); + HAServiceState nnHAState = nn.getServiceState(); + boolean isActive = (nnHAState == HAServiceState.ACTIVE); String namenodeRole = nn.getRole().toString(); String namenodeLabel = nn.getNameNodeAddress().getHostName() + ":" + nn.getNameNodeAddress().getPort(); @@ -46,8 +49,10 @@

<%=namenodeRole%> '<%=namenodeLabel%>'

<%=NamenodeJspHelper.getVersionTable(fsn)%>
-Browse the filesystem -
+<% if (isActive) { %> + Browse the filesystem +
+<% } %> <%=namenodeRole%> Logs
Go back to DFS home diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfshealth.jsp b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfshealth.jsp index 4c65701a1f..81e595d718 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfshealth.jsp +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfshealth.jsp @@ -30,8 +30,10 @@ final NamenodeJspHelper.HealthJsp healthjsp = new NamenodeJspHelper.HealthJsp(); NameNode nn = NameNodeHttpServer.getNameNodeFromContext(application); FSNamesystem fsn = nn.getNamesystem(); + HAServiceState nnHAState = nn.getServiceState(); + boolean isActive = (nnHAState == HAServiceState.ACTIVE); String namenodeRole = nn.getRole().toString(); - String namenodeState = nn.getServiceState().toString(); + String namenodeState = nnHAState.toString(); String namenodeLabel = nn.getNameNodeAddress().getHostName() + ":" + nn.getNameNodeAddress().getPort(); %> @@ -45,7 +47,9 @@

<%=namenodeRole%> '<%=namenodeLabel%>' (<%=namenodeState%>)

<%= NamenodeJspHelper.getVersionTable(fsn) %>
-Browse the filesystem
+<% if (isActive) { %> + Browse the filesystem
+<% } %> <%=namenodeRole%> Logs
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfsnodelist.jsp b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfsnodelist.jsp index 886fbeaa35..35deb05f85 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfsnodelist.jsp +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfsnodelist.jsp @@ -20,6 +20,7 @@ <%@ page contentType="text/html; charset=UTF-8" import="org.apache.hadoop.util.ServletUtil" + import="org.apache.hadoop.ha.HAServiceProtocol.HAServiceState" %> <%! //for java.io.Serializable @@ -30,6 +31,8 @@ final NamenodeJspHelper.NodeListJsp nodelistjsp = new NamenodeJspHelper.NodeList NameNode nn = NameNodeHttpServer.getNameNodeFromContext(application); String namenodeRole = nn.getRole().toString(); FSNamesystem fsn = nn.getNamesystem(); +HAServiceState nnHAState = nn.getServiceState(); +boolean isActive = (nnHAState == HAServiceState.ACTIVE); String namenodeLabel = nn.getNameNodeAddress().getHostName() + ":" + nn.getNameNodeAddress().getPort(); %> @@ -43,7 +46,9 @@ String namenodeLabel = nn.getNameNodeAddress().getHostName() + ":" + nn.getNameN

<%=namenodeRole%> '<%=namenodeLabel%>'

<%= NamenodeJspHelper.getVersionTable(fsn) %>
-Browse the filesystem
+<% if (isActive) { %> + Browse the filesystem
+<% } %> <%=namenodeRole%> Logs
Go back to DFS home
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAWebUI.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAWebUI.java new file mode 100644 index 0000000000..ccb4f5b5cd --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAWebUI.java @@ -0,0 +1,70 @@ +/** + * 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.hdfs.server.namenode.ha; + +import static org.junit.Assert.*; + +import java.net.URL; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hdfs.DFSTestUtil; +import org.apache.hadoop.hdfs.MiniDFSCluster; +import org.apache.hadoop.hdfs.MiniDFSNNTopology; +import org.apache.hadoop.hdfs.server.namenode.NameNode; +import org.junit.Test; + +public class TestHAWebUI { + + /** + * Tests that the web UI of the name node provides a link to browse the file + * system only in active state + * + */ + @Test + public void testLinkToBrowseFilesystem() throws Exception { + Configuration conf = new Configuration(); + + MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf) + .nnTopology(MiniDFSNNTopology.simpleHATopology()).numDataNodes(0) + .build(); + try { + cluster.waitActive(); + + cluster.transitionToActive(0); + String pageContents = DFSTestUtil.urlGet(new URL("http://localhost:" + + NameNode.getHttpAddress(cluster.getConfiguration(0)).getPort() + + "/dfshealth.jsp")); + assertTrue(pageContents.contains("Browse the filesystem")); + + cluster.transitionToStandby(0); + pageContents = DFSTestUtil.urlGet(new URL("http://localhost:" + + NameNode.getHttpAddress(cluster.getConfiguration(0)).getPort() + + "/dfshealth.jsp")); + assertFalse(pageContents.contains("Browse the filesystem")); + + cluster.transitionToActive(0); + pageContents = DFSTestUtil.urlGet(new URL("http://localhost:" + + NameNode.getHttpAddress(cluster.getConfiguration(0)).getPort() + + "/dfshealth.jsp")); + assertTrue(pageContents.contains("Browse the filesystem")); + + } finally { + cluster.shutdown(); + } + } +}