You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by sz...@apache.org on 2012/04/17 22:31:19 UTC
svn commit: r1327273 - in
/hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs: ./
src/main/java/org/apache/hadoop/hdfs/
src/main/java/org/apache/hadoop/hdfs/server/journalservice/
src/main/webapps/ src/main/webapps/journal/ src/test/java/...
Author: szetszwo
Date: Tue Apr 17 20:31:18 2012
New Revision: 1327273
URL: http://svn.apache.org/viewvc?rev=1327273&view=rev
Log:
HDFS-3283. Add http server to journal service. Contributed by Brandon Li
Added:
hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/journalservice/JournalHttpServer.java
hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/journal/
hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/journal/index.html
hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/journal/journalstatus.jsp
hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/proto-journal-web.xml
hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/journalservice/TestJournalHttpServer.java
Modified:
hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-3092.txt
hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/pom.xml
hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java
hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java
hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java
Modified: hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-3092.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-3092.txt?rev=1327273&r1=1327272&r2=1327273&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-3092.txt (original)
+++ hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-3092.txt Tue Apr 17 20:31:18 2012
@@ -15,6 +15,8 @@ HDFS-3092 branch changes
HDFS-3274. Add a new conf key dfs.journal.edits.dir and use it for
edit log initialization. (Hari Mankude via szetszwo)
+ HDFS-3283. Add http server to journal service. (Brandon Li via szetszwo)
+
IMPROVEMENTS
OPTIMIZATIONS
Modified: hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/pom.xml
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/pom.xml?rev=1327273&r1=1327272&r2=1327273&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/pom.xml (original)
+++ hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/pom.xml Tue Apr 17 20:31:18 2012
@@ -157,6 +157,25 @@
</configuration>
</execution>
<execution>
+ <id>journal</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <compile>false</compile>
+ <workingDirectory>${project.build.directory}/generated-src/main/jsp</workingDirectory>
+ <webFragmentFile>${project.build.directory}/journal-jsp-servlet-definitions.xml</webFragmentFile>
+ <packageName>org.apache.hadoop.hdfs.server.journalservice</packageName>
+ <sources>
+ <directory>${basedir}/src/main/webapps/journal</directory>
+ <includes>
+ <include>*.jsp</include>
+ </includes>
+ </sources>
+ </configuration>
+ </execution>
+ <execution>
<id>datanode</id>
<phase>generate-sources</phase>
<goals>
@@ -263,6 +282,7 @@
<loadfile property="hdfs.servlet.definitions" srcFile="${project.build.directory}/hdfs-jsp-servlet-definitions.xml"/>
<loadfile property="secondary.servlet.definitions" srcFile="${project.build.directory}/secondary-jsp-servlet-definitions.xml"/>
<loadfile property="datanode.servlet.definitions" srcFile="${project.build.directory}/datanode-jsp-servlet-definitions.xml"/>
+ <loadfile property="journal.servlet.definitions" srcFile="${project.build.directory}/journal-jsp-servlet-definitions.xml"/>
<echoproperties destfile="${project.build.directory}/webxml.properties">
<propertyset>
<propertyref regex=".*.servlet.definitions"/>
@@ -278,6 +298,9 @@
<copy file="${basedir}/src/main/webapps/proto-datanode-web.xml"
tofile="${project.build.directory}/webapps/datanode/WEB-INF/web.xml"
filtering="true"/>
+ <copy file="${basedir}/src/main/webapps/proto-journal-web.xml"
+ tofile="${project.build.directory}/webapps/journal/WEB-INF/web.xml"
+ filtering="true"/>
<copy toDir="${project.build.directory}/webapps">
<fileset dir="${basedir}/src/main/webapps">
<exclude name="**/*.jsp"/>
Modified: hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java?rev=1327273&r1=1327272&r2=1327273&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java (original)
+++ hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java Tue Apr 17 20:31:18 2012
@@ -202,8 +202,12 @@ public class DFSConfigKeys extends Commo
public static final String DFS_CLIENT_LOCAL_INTERFACES = "dfs.client.local.interfaces";
// This is a comma separated host:port list of addresses hosting the journal service
- public static final String DFS_JOURNALNODE_ADDRESS_KEY = "dfs.journalnode.addresses";
+ public static final String DFS_JOURNAL_ADDRESS_KEY = "dfs.journalnode.addresses";
public static final String DFS_JOURNAL_EDITS_DIR_KEY = "dfs.journal.edits.dir";
+ public static final String DFS_JOURNAL_HTTPS_PORT_KEY = "dfs.journal.https-port";
+ public static final int DFS_JOURNAL_HTTPS_PORT_DEFAULT = 50510;
+ public static final String DFS_JOURNAL_KRB_HTTPS_USER_NAME_KEY = "dfs.journal.kerberos.https.principal";
+ public static final String DFS_JOURNAL_KEYTAB_FILE_KEY = "dfs.journal.keytab.file";
// Much code in hdfs is not yet updated to use these keys.
public static final String DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_KEY = "dfs.client.block.write.locateFollowingBlock.retries";
Modified: hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java?rev=1327273&r1=1327272&r2=1327273&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java (original)
+++ hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java Tue Apr 17 20:31:18 2012
@@ -1068,7 +1068,7 @@ public class DFSUtil {
public static Collection<InetSocketAddress> getJournalNodeAddresses(
Configuration conf) {
Collection<String> jnames = conf
- .getTrimmedStringCollection(DFS_JOURNALNODE_ADDRESS_KEY);
+ .getTrimmedStringCollection(DFS_JOURNAL_ADDRESS_KEY);
Collection<InetSocketAddress> ret = new ArrayList<InetSocketAddress>();
for (String jname : emptyAsSingletonNull(jnames)) {
if (jname == null) {
Added: hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/journalservice/JournalHttpServer.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/journalservice/JournalHttpServer.java?rev=1327273&view=auto
==============================================================================
--- hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/journalservice/JournalHttpServer.java (added)
+++ hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/journalservice/JournalHttpServer.java Tue Apr 17 20:31:18 2012
@@ -0,0 +1,142 @@
+/**
+ * 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.journalservice;
+
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_ADMIN;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_JOURNAL_HTTPS_PORT_DEFAULT;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_JOURNAL_HTTPS_PORT_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_JOURNAL_KEYTAB_FILE_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_JOURNAL_KRB_HTTPS_USER_NAME_KEY;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.security.PrivilegedExceptionAction;
+
+import javax.servlet.ServletContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hdfs.server.common.JspHelper;
+import org.apache.hadoop.hdfs.server.namenode.NNStorage;
+
+import org.apache.hadoop.http.HttpServer;
+import org.apache.hadoop.net.NetUtils;
+import org.apache.hadoop.security.SecurityUtil;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.authorize.AccessControlList;
+
+/**
+ * Encapsulates the HTTP server started by the Journal Service.
+ */
+@InterfaceAudience.Private
+public class JournalHttpServer {
+
+ private HttpServer httpServer;
+ private InetSocketAddress httpAddress;
+ private String infoBindAddress;
+ private int infoPort;
+ private int imagePort;
+
+ private final Configuration conf;
+
+ public static final Log LOG = LogFactory.getLog(JournalHttpServer.class
+ .getName());
+
+ public static final String NNSTORAGE_ATTRIBUTE_KEY = "name.system.storage";
+ protected static final String NAMENODE_ATTRIBUTE_KEY = "name.node";
+
+ private NNStorage storage = null;
+
+ public JournalHttpServer(Configuration conf, NNStorage storage,
+ InetSocketAddress bindAddress) throws Exception {
+ this.conf = conf;
+ this.storage = storage;
+ this.httpAddress = bindAddress;
+ }
+
+ public void start() throws IOException {
+ infoBindAddress = httpAddress.getHostName();
+
+ // initialize the webserver for uploading files.
+ // Kerberized SSL servers must be run from the host principal...
+ UserGroupInformation httpUGI = UserGroupInformation
+ .loginUserFromKeytabAndReturnUGI(SecurityUtil.getServerPrincipal(
+ conf.get(DFS_JOURNAL_KRB_HTTPS_USER_NAME_KEY),
+ infoBindAddress), conf.get(DFS_JOURNAL_KEYTAB_FILE_KEY));
+ try {
+ httpServer = httpUGI.doAs(new PrivilegedExceptionAction<HttpServer>() {
+ @Override
+ public HttpServer run() throws IOException, InterruptedException {
+ LOG.info("Starting web server as: "
+ + UserGroupInformation.getCurrentUser().getUserName());
+
+ int tmpInfoPort = httpAddress.getPort();
+ httpServer = new HttpServer("journal", infoBindAddress,
+ tmpInfoPort, tmpInfoPort == 0, conf, new AccessControlList(conf
+ .get(DFS_ADMIN, " ")));
+
+ if (UserGroupInformation.isSecurityEnabled()) {
+ SecurityUtil.initKrb5CipherSuites();
+ InetSocketAddress secInfoSocAddr = NetUtils
+ .createSocketAddr(infoBindAddress
+ + ":"
+ + conf.getInt(DFS_JOURNAL_HTTPS_PORT_KEY,
+ DFS_JOURNAL_HTTPS_PORT_DEFAULT));
+ imagePort = secInfoSocAddr.getPort();
+ httpServer.addSslListener(secInfoSocAddr, conf, false, true);
+ }
+ httpServer.setAttribute("journal.node", JournalHttpServer.this);
+ httpServer.setAttribute("name.system.storage", storage);
+ httpServer.setAttribute(JspHelper.CURRENT_CONF, conf);
+ httpServer.start();
+ return httpServer;
+ }
+ });
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+
+ LOG.info("Journal web server init done");
+ // The web-server port can be ephemeral... ensure we have the correct info
+ infoPort = httpServer.getPort();
+ if (!UserGroupInformation.isSecurityEnabled()) {
+ imagePort = infoPort;
+ }
+
+ LOG.info("Journal Web-server up at: " + infoBindAddress + ":"
+ + infoPort);
+ LOG.info("Journal image servlet up at: " + infoBindAddress + ":"
+ + imagePort);
+ }
+
+ public void stop() throws Exception {
+ if (httpServer != null) {
+ httpServer.stop();
+ }
+ }
+
+ public static NNStorage getNNStorageFromContext(ServletContext context) {
+ return (NNStorage) context.getAttribute(NNSTORAGE_ATTRIBUTE_KEY);
+ }
+
+ public static Configuration getConfFromContext(ServletContext context) {
+ return (Configuration) context.getAttribute(JspHelper.CURRENT_CONF);
+ }
+}
Added: hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/journal/index.html
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/journal/index.html?rev=1327273&view=auto
==============================================================================
--- hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/journal/index.html (added)
+++ hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/journal/index.html Tue Apr 17 20:31:18 2012
@@ -0,0 +1,29 @@
+<meta HTTP-EQUIV="REFRESH" content="0;url=journalstatus.jsp"/>
+<html>
+<!--
+ 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.
+-->
+<head><title>Hadoop Administration</title></head>
+
+<body>
+<h1>Hadoop Administration</h1>
+
+<ul>
+ <li><a href="journalstatus.jsp">Status</a></li>
+</ul>
+
+</body>
+</html>
Added: hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/journal/journalstatus.jsp
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/journal/journalstatus.jsp?rev=1327273&view=auto
==============================================================================
--- hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/journal/journalstatus.jsp (added)
+++ hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/journal/journalstatus.jsp Tue Apr 17 20:31:18 2012
@@ -0,0 +1,45 @@
+<%
+/*
+ * 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.
+ */
+%>
+<%@ page
+ contentType="text/html; charset=UTF-8"
+ import="org.apache.hadoop.hdfs.server.common.JspHelper"
+ import="org.apache.hadoop.util.ServletUtil"
+%>
+<%!
+ //for java.io.Serializable
+ private static final long serialVersionUID = 1L;
+%>
+
+<!DOCTYPE html>
+<html>
+<link rel="stylesheet" type="text/css" href="/static/hadoop.css">
+<title>Hadoop JournalNode</title>
+
+<body>
+<h1>JournalNode</h1>
+<%= JspHelper.getVersionTable() %>
+<hr />
+<pre>
+<%= application.getAttribute("journal.node").toString() %>
+</pre>
+
+<br />
+<b><a href="/logs/">Logs</a></b>
+<%= ServletUtil.htmlFooter() %>
Added: hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/proto-journal-web.xml
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/proto-journal-web.xml?rev=1327273&view=auto
==============================================================================
--- hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/proto-journal-web.xml (added)
+++ hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/proto-journal-web.xml Tue Apr 17 20:31:18 2012
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed 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. See accompanying LICENSE file.
+-->
+<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee">
+@journal.servlet.definitions@
+</web-app>
Modified: hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java?rev=1327273&r1=1327272&r2=1327273&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java (original)
+++ hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java Tue Apr 17 20:31:18 2012
@@ -553,7 +553,7 @@ public class TestDFSUtil {
assertEquals(ret.size(), 0);
// Setup single journal node
- conf.set(DFS_JOURNALNODE_ADDRESS_KEY, str1);
+ conf.set(DFS_JOURNAL_ADDRESS_KEY, str1);
ret = DFSUtil.getJournalNodeAddresses(conf);
assertEquals(ret.size(), 1);
for (InetSocketAddress addr : ret) {
@@ -561,7 +561,7 @@ public class TestDFSUtil {
}
// Add two entries now.
- conf.set(DFS_JOURNALNODE_ADDRESS_KEY, "localhost:50200, localhost:50210");
+ conf.set(DFS_JOURNAL_ADDRESS_KEY, "localhost:50200, localhost:50210");
ret = DFSUtil.getJournalNodeAddresses(conf);
assertEquals(ret.size(), 2);
Added: hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/journalservice/TestJournalHttpServer.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/journalservice/TestJournalHttpServer.java?rev=1327273&view=auto
==============================================================================
--- hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/journalservice/TestJournalHttpServer.java (added)
+++ hadoop/common/branches/HDFS-3092/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/journalservice/TestJournalHttpServer.java Tue Apr 17 20:31:18 2012
@@ -0,0 +1,123 @@
+/**
+ * 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.journalservice;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.impl.Log4JLogger;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileUtil;
+import org.apache.hadoop.hdfs.DFSConfigKeys;
+import org.apache.hadoop.hdfs.DFSTestUtil;
+import org.apache.hadoop.hdfs.HdfsConfiguration;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.hadoop.hdfs.server.journalservice.JournalHttpServer;
+import org.apache.hadoop.hdfs.server.namenode.NNStorage;
+import org.apache.hadoop.net.NetUtils;
+import org.apache.log4j.Level;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestJournalHttpServer {
+ public static final Log LOG = LogFactory
+ .getLog(TestJournalHttpServer.class);
+
+ static {
+ ((Log4JLogger) JournalHttpServer.LOG).getLogger().setLevel(Level.ALL);
+ }
+
+ private Configuration conf;
+ private File hdfsDir = null;
+ private File path1;
+
+ @Before
+ public void setUp() throws Exception {
+ HdfsConfiguration.init();
+ conf = new HdfsConfiguration();
+
+ hdfsDir = new File(MiniDFSCluster.getBaseDirectory()).getCanonicalFile();
+ if (hdfsDir.exists() && !FileUtil.fullyDelete(hdfsDir)) {
+ throw new IOException("Could not delete hdfs directory '" + hdfsDir + "'");
+ }
+
+ hdfsDir.mkdirs();
+ // TODO: remove the manual setting storage when JN is fully implemented
+ path1 = new File(hdfsDir, "jn1dir");
+ path1.mkdir();
+ if (!path1.exists()) {
+ throw new IOException("Couldn't create path in "
+ + hdfsDir.getAbsolutePath());
+ }
+
+ System.out.println("configuring hdfsdir is " + hdfsDir.getAbsolutePath()
+ + "; jn1Dir = " + path1.getPath());
+
+ File path1current = new File(path1, "current");
+ path1current.mkdir();
+ if (!path1current.exists()) {
+ throw new IOException("Couldn't create path " + path1current);
+ }
+ }
+
+ /**
+ * Test JN Http Server
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testHttpServer() throws Exception {
+ MiniDFSCluster cluster = null;
+ JournalHttpServer jns1 = null;
+
+ try {
+ cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
+
+ conf.set(DFSConfigKeys.DFS_JOURNAL_EDITS_DIR_KEY, path1.getPath());
+ // TODO: remove the manual setting storage when JN is fully implemented
+ URI uri = new URI(new String("file:" + path1.getPath()));
+ List<URI> editsDirs = new ArrayList<URI>();
+ editsDirs.add(uri);
+ NNStorage storage = new NNStorage(conf, new ArrayList<URI>(), editsDirs);
+ jns1 = new JournalHttpServer(conf, storage,
+ NetUtils.createSocketAddr("localhost:50200"));
+ jns1.start();
+
+ String pageContents = DFSTestUtil.urlGet(new URL(
+ "http://localhost:50200/journalstatus.jsp"));
+ assertTrue(pageContents.contains("JournalNode"));
+
+ } catch (IOException e) {
+ LOG.error("Error in TestHttpServer:", e);
+ assertTrue(e.getLocalizedMessage(), false);
+ } finally {
+ if (jns1 != null)
+ jns1.stop();
+ if (cluster != null)
+ cluster.shutdown();
+ }
+ }
+}