Skip to content
9 changes: 4 additions & 5 deletions hadoop-hdds/common/src/main/resources/ozone-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2935,11 +2935,10 @@
<description>
The base dir for HTTP Jetty server to extract contents. If this property
is not configured, by default, Jetty will create a directory inside the
directory named by the java.io.tmpdir System property(/tmp by default).
While in production environment, it's strongly suggested to instruct Jetty
to use a different parent directory by setting this property to the name
of the desired parent directory. The value of the property will be used to
set Jetty context attribute 'org.eclipse.jetty.webapp.basetempdir'.
directory named by the ${ozone.metadata.dirs}/webserver. While in production environment,
it's strongly suggested instructing Jetty to use a different parent directory by
setting this property to the name of the desired parent directory. The value of the
property will be used to set Jetty context attribute 'org.eclipse.jetty.webapp.basetempdir'.
The directory named by this property must exist and be writeable.
</description>
</property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Optional;
import java.util.OptionalInt;

import com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdds.DFSConfigKeysLegacy;
import org.apache.hadoop.hdds.HddsConfigKeys;
Expand All @@ -43,6 +44,7 @@
import static org.apache.hadoop.hdds.HddsUtils.getHostNameFromConfigKeys;
import static org.apache.hadoop.hdds.HddsUtils.getPortNumberFromConfigKeys;
import static org.apache.hadoop.hdds.HddsUtils.createDir;
import static org.apache.hadoop.hdds.server.ServerUtils.getOzoneMetaDirPath;
import static org.apache.hadoop.hdds.server.http.HttpConfig.getHttpPolicy;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ADMINISTRATORS;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ADMINISTRATORS_GROUPS;
Expand Down Expand Up @@ -70,6 +72,7 @@ public abstract class BaseHttpServer {
static final String PROMETHEUS_SINK = "PROMETHEUS_SINK";
private static final String JETTY_BASETMPDIR =
"org.eclipse.jetty.webapp.basetempdir";
public static final String SERVER_DIR = "/webserver";

private HttpServer2 httpServer;
private final MutableConfigurationSource conf;
Expand Down Expand Up @@ -178,14 +181,22 @@ public BaseHttpServer(MutableConfigurationSource conf, String name)
}

String baseDir = conf.get(OzoneConfigKeys.OZONE_HTTP_BASEDIR);
if (!StringUtils.isEmpty(baseDir)) {
createDir(baseDir);
httpServer.getWebAppContext().setAttribute(JETTY_BASETMPDIR, baseDir);
LOG.info("HTTP server of {} uses base directory {}", name, baseDir);

if (StringUtils.isEmpty(baseDir)) {
baseDir = getOzoneMetaDirPath(conf) + SERVER_DIR;
}
createDir(baseDir);
httpServer.getWebAppContext().setAttribute(JETTY_BASETMPDIR, baseDir);
LOG.info("HTTP server of {} uses base directory {}", name, baseDir);
}
}

@VisibleForTesting
public String getJettyBaseTmpDir() {
return httpServer.getWebAppContext().getAttribute(JETTY_BASETMPDIR)
.toString();
}

/**
* Return a HttpServer.Builder that the OzoneManager/SCM/Datanode/S3Gateway/
* Recon to initialize their HTTP / HTTPS server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public class TestStorageContainerManagerHttpServer {
public static void setUp() throws Exception {
File base = new File(BASEDIR);
FileUtil.fullyDelete(base);
base.mkdirs();
File ozoneMetadataDirectory = new File(BASEDIR, "metadata");
ozoneMetadataDirectory.mkdirs();
conf = new OzoneConfiguration();
keystoresDir = new File(BASEDIR).getAbsolutePath();
sslConfDir = KeyStoreTestUtil.getClasspathDir(
Expand All @@ -68,6 +69,8 @@ public static void setUp() throws Exception {
KeyStoreTestUtil.getClientSSLConfigFileName());
conf.set(OzoneConfigKeys.OZONE_SERVER_HTTPS_KEYSTORE_RESOURCE_KEY,
KeyStoreTestUtil.getServerSSLConfigFileName());
conf.set(OzoneConfigKeys.OZONE_METADATA_DIRS,
ozoneMetadataDirectory.getAbsolutePath());
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.server.http.BaseHttpServer;
import org.apache.hadoop.hdfs.web.URLConnectionFactory;
import org.apache.hadoop.http.HttpConfig;
import org.apache.hadoop.http.HttpConfig.Policy;
Expand All @@ -40,6 +41,7 @@
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
Expand All @@ -55,6 +57,7 @@ public class TestOzoneManagerHttpServer {
private static String sslConfDir;
private static OzoneConfiguration conf;
private static URLConnectionFactory connectionFactory;
private static File ozoneMetadataDirectory;

@Parameters public static Collection<Object[]> policy() {
Object[][] params = new Object[][] {
Expand All @@ -74,7 +77,12 @@ public TestOzoneManagerHttpServer(Policy policy) {
@BeforeClass public static void setUp() throws Exception {
File base = new File(BASEDIR);
FileUtil.fullyDelete(base);
base.mkdirs();

// Create metadata directory
ozoneMetadataDirectory = new File(BASEDIR, "metadata");
ozoneMetadataDirectory.mkdirs();

// Initialize the OzoneConfiguration
conf = new OzoneConfiguration();
keystoresDir = new File(BASEDIR).getAbsolutePath();
sslConfDir = KeyStoreTestUtil.getClasspathDir(
Expand All @@ -86,6 +94,14 @@ public TestOzoneManagerHttpServer(Policy policy) {
KeyStoreTestUtil.getClientSSLConfigFileName());
conf.set(OzoneConfigKeys.OZONE_SERVER_HTTPS_KEYSTORE_RESOURCE_KEY,
KeyStoreTestUtil.getServerSSLConfigFileName());

// Set up OM HTTP and HTTPS addresses
conf.set(OzoneConfigKeys.OZONE_METADATA_DIRS,
ozoneMetadataDirectory.getAbsolutePath());
conf.set(OMConfigKeys.OZONE_OM_HTTP_ADDRESS_KEY, "localhost:0");
conf.set(OMConfigKeys.OZONE_OM_HTTPS_ADDRESS_KEY, "localhost:0");
conf.set(OMConfigKeys.OZONE_OM_HTTP_BIND_HOST_KEY, "localhost");
conf.set(OMConfigKeys.OZONE_OM_HTTPS_BIND_HOST_KEY, "localhost");
}

@AfterClass public static void tearDown() throws Exception {
Expand All @@ -96,11 +112,6 @@ public TestOzoneManagerHttpServer(Policy policy) {

@Test public void testHttpPolicy() throws Exception {
conf.set(OzoneConfigKeys.OZONE_HTTP_POLICY_KEY, policy.name());
conf.set(OMConfigKeys.OZONE_OM_HTTP_ADDRESS_KEY, "localhost:0");
conf.set(OMConfigKeys.OZONE_OM_HTTPS_ADDRESS_KEY, "localhost:0");
conf.set(OMConfigKeys.OZONE_OM_HTTP_BIND_HOST_KEY, "localhost");
conf.set(OMConfigKeys.OZONE_OM_HTTPS_BIND_HOST_KEY, "localhost");

OzoneManagerHttpServer server = null;
try {
server = new OzoneManagerHttpServer(conf, null);
Expand All @@ -117,7 +128,30 @@ public TestOzoneManagerHttpServer(Policy policy) {
canAccess("https", server.getHttpsAddress())));
Assert.assertTrue(implies(policy.isHttpsEnabled(),
!canAccess("http", server.getHttpsAddress())));
} finally {
if (server != null) {
server.stop();
}
}
}

@Test
// Verify if jetty-dir will be created inside ozoneMetadataDirectory path
public void testJettyDirectoryCreation() throws Exception {
OzoneManagerHttpServer server = null;
try {
server = new OzoneManagerHttpServer(conf, null);
DefaultMetricsSystem.initialize("TestOzoneManagerHttpServer");
server.start();
// Checking if the /webserver directory does get created
File webServerDir =
new File(ozoneMetadataDirectory, BaseHttpServer.SERVER_DIR);
Assert.assertTrue(webServerDir.exists());
// Verify that the jetty directory is set correctly
String expectedJettyDirLocation =
ozoneMetadataDirectory.getAbsolutePath() + BaseHttpServer.SERVER_DIR;
Assertions.assertEquals(expectedJettyDirLocation,
server.getJettyBaseTmpDir());
} finally {
if (server != null) {
server.stop();
Expand Down