Skip to content

HDDS-1651. Create a http.policy config for Ozone #930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Optional;
import java.util.TimeZone;

import org.apache.hadoop.HadoopIllegalArgumentException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Unused import.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for using dfs.http..policy to reduce redundant config knobs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank You @eyanghwx for review.
I also feel the same. Can we close this as won't Fix?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank You @eyanghwx for the confirmation.
I will close this as Won't fix.

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.conf.Configuration;
Expand All @@ -42,6 +43,8 @@
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.SCMSecurityProtocol;
import org.apache.hadoop.hdds.scm.protocolPB.ScmBlockLocationProtocolPB;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.http.HttpConfig.Policy;
import org.apache.hadoop.ipc.Client;
import org.apache.hadoop.ipc.ProtobufRpcEngine;
import org.apache.hadoop.ipc.RPC;
Expand All @@ -56,6 +59,7 @@
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ENABLED;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ENABLED_DEFAULT;

import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.apache.hadoop.security.UserGroupInformation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -426,6 +430,14 @@ public static long getUtcTime() {
return Calendar.getInstance(UTC_ZONE).getTimeInMillis();
}

public static Policy getHttpPolicy(Configuration conf) {
String policyStr = conf.get(OzoneConfigKeys.OZONE_HTTP_POLICY,
DFSConfigKeys.DFS_HTTP_POLICY_DEFAULT);
Policy policy = Policy.fromString(policyStr);
conf.set("dfs.http.policy", policy.name());
return policy;
}

/**
* Retrieve the socket address that should be used by clients to connect
* to the SCM for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public final class OzoneConfigKeys {
"dfs.container.ratis.ipc";
public static final int DFS_CONTAINER_RATIS_IPC_PORT_DEFAULT = 9858;

public static final String OZONE_HTTP_POLICY = "ozone.http.policy";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This newly added property should be used during HTTP server start.
That part is missing.

/**
* When set to true, allocate a random free port for ozone container, so that
* a mini cluster is able to launch multiple containers on a node.
Expand Down
10 changes: 10 additions & 0 deletions hadoop-hdds/common/src/main/resources/ozone-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2487,4 +2487,14 @@
The number of Recon Tasks that are waiting on updates from OM.
</description>
</property>
<property>
<name>ozone.http.policy</name>
<value>HTTP_ONLY</value>
<description>This configures the HTTP endpoint for Ozone daemons:
The following values are supported:
- HTTP_ONLY : Service is provided only on http
- HTTPS_ONLY : Service is provided only on https
- HTTP_AND_HTTPS : Service is provided both on http and https
</description>
</property>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DFSUtil;
import org.apache.hadoop.hdds.conf.HddsConfServlet;
Expand Down Expand Up @@ -65,7 +66,7 @@ public abstract class BaseHttpServer {
public BaseHttpServer(Configuration conf, String name) throws IOException {
this.name = name;
this.conf = conf;
policy = DFSUtil.getHttpPolicy(conf);
policy = HddsUtils.getHttpPolicy(conf);
if (isEnabled()) {
this.httpAddress = getHttpBindAddress();
this.httpsAddress = getHttpsBindAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.hadoop.http.HttpConfig;
import org.apache.hadoop.http.HttpConfig.Policy;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.AfterClass;
Expand Down Expand Up @@ -91,7 +92,8 @@ public TestOzoneManagerHttpServer(Policy policy) {
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, sslConfDir);
}

@Test public void testHttpPolicy() throws Exception {
@Test
public void testHttpPolicy() throws Exception {
conf.set(DFSConfigKeys.DFS_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");
Expand Down Expand Up @@ -119,6 +121,34 @@ public TestOzoneManagerHttpServer(Policy policy) {
}
}

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

OzoneManagerHttpServer server = null;
try {
server = new OzoneManagerHttpServer(conf, null);
server.start();

Assert.assertTrue(implies(policy.isHttpEnabled(),
canAccess("http", server.getHttpAddress())));
Assert.assertTrue(implies(policy.isHttpEnabled() &&
!policy.isHttpsEnabled(),
!canAccess("https", server.getHttpsAddress())));

Assert.assertTrue(implies(policy.isHttpsEnabled(),
canAccess("https", server.getHttpsAddress())));
Assert.assertTrue(implies(policy.isHttpsEnabled(),
!canAccess("http", server.getHttpsAddress())));

} finally {
if (server != null) {
server.stop();
}
}
}
private static boolean canAccess(String scheme, InetSocketAddress addr) {
if (addr == null) {
return false;
Expand Down