HDFS-10437. ReconfigurationProtocol not covered by HDFSPolicyProvider. (Arpit Agarwal)

This commit is contained in:
Arpit Agarwal 2016-06-18 16:16:54 -07:00
parent b726b5c52c
commit bd33cc0179
3 changed files with 22 additions and 18 deletions

View File

@ -179,6 +179,9 @@ public class CommonConfigurationKeys extends CommonConfigurationKeysPublic {
public static final String public static final String
HADOOP_SECURITY_SERVICE_AUTHORIZATION_DATANODE_LIFELINE = HADOOP_SECURITY_SERVICE_AUTHORIZATION_DATANODE_LIFELINE =
"security.datanode.lifeline.protocol.acl"; "security.datanode.lifeline.protocol.acl";
public static final String
HADOOP_SECURITY_SERVICE_AUTHORIZATION_RECONFIGURATION =
"security.reconfiguration.protocol.acl";
public static final String public static final String
SECURITY_HA_SERVICE_PROTOCOL_ACL = "security.ha.service.protocol.acl"; SECURITY_HA_SERVICE_PROTOCOL_ACL = "security.ha.service.protocol.acl";
public static final String public static final String

View File

@ -23,6 +23,7 @@ import org.apache.hadoop.ha.HAServiceProtocol;
import org.apache.hadoop.ha.ZKFCProtocol; import org.apache.hadoop.ha.ZKFCProtocol;
import org.apache.hadoop.hdfs.protocol.ClientDatanodeProtocol; import org.apache.hadoop.hdfs.protocol.ClientDatanodeProtocol;
import org.apache.hadoop.hdfs.protocol.ClientProtocol; import org.apache.hadoop.hdfs.protocol.ClientProtocol;
import org.apache.hadoop.hdfs.protocol.ReconfigurationProtocol;
import org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocol; import org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocol;
import org.apache.hadoop.hdfs.server.protocol.DatanodeLifelineProtocol; import org.apache.hadoop.hdfs.server.protocol.DatanodeLifelineProtocol;
import org.apache.hadoop.hdfs.server.protocol.DatanodeProtocol; import org.apache.hadoop.hdfs.server.protocol.DatanodeProtocol;
@ -80,7 +81,10 @@ public class HDFSPolicyProvider extends PolicyProvider {
TraceAdminProtocol.class), TraceAdminProtocol.class),
new Service( new Service(
CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_AUTHORIZATION_DATANODE_LIFELINE, CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_AUTHORIZATION_DATANODE_LIFELINE,
DatanodeLifelineProtocol.class) DatanodeLifelineProtocol.class),
new Service(
CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_AUTHORIZATION_RECONFIGURATION,
ReconfigurationProtocol.class)
}; };
@Override @Override

View File

@ -23,10 +23,12 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import com.google.common.collect.Sets;
import org.apache.commons.lang.ClassUtils; import org.apache.commons.lang.ClassUtils;
import org.apache.hadoop.hdfs.protocol.ReconfigurationProtocol;
import org.apache.hadoop.hdfs.qjournal.server.JournalNodeRpcServer; import org.apache.hadoop.hdfs.qjournal.server.JournalNodeRpcServer;
import org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer; import org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer;
import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNode;
@ -57,7 +59,7 @@ public class TestHDFSPolicyProvider {
private static final Logger LOG = private static final Logger LOG =
LoggerFactory.getLogger(TestHDFSPolicyProvider.class); LoggerFactory.getLogger(TestHDFSPolicyProvider.class);
private static List<Class<?>> policyProviderProtocols; private static Set<Class<?>> policyProviderProtocols;
private static final Comparator<Class<?>> CLASS_NAME_COMPARATOR = private static final Comparator<Class<?>> CLASS_NAME_COMPARATOR =
new Comparator<Class<?>>() { new Comparator<Class<?>>() {
@ -75,11 +77,10 @@ public class TestHDFSPolicyProvider {
@BeforeClass @BeforeClass
public static void initialize() { public static void initialize() {
Service[] services = new HDFSPolicyProvider().getServices(); Service[] services = new HDFSPolicyProvider().getServices();
policyProviderProtocols = new ArrayList<>(services.length); policyProviderProtocols = new HashSet<>(services.length);
for (Service service : services) { for (Service service : services) {
policyProviderProtocols.add(service.getProtocol()); policyProviderProtocols.add(service.getProtocol());
} }
Collections.sort(policyProviderProtocols, CLASS_NAME_COMPARATOR);
} }
public TestHDFSPolicyProvider(Class<?> rpcServerClass) { public TestHDFSPolicyProvider(Class<?> rpcServerClass) {
@ -98,29 +99,25 @@ public class TestHDFSPolicyProvider {
@Test @Test
public void testPolicyProviderForServer() { public void testPolicyProviderForServer() {
List<?> ifaces = ClassUtils.getAllInterfaces(rpcServerClass); List<?> ifaces = ClassUtils.getAllInterfaces(rpcServerClass);
List<Class<?>> serverProtocols = new ArrayList<>(ifaces.size()); Set<Class<?>> serverProtocols = new HashSet<>(ifaces.size());
for (Object obj : ifaces) { for (Object obj : ifaces) {
Class<?> iface = (Class<?>)obj; Class<?> iface = (Class<?>)obj;
// ReconfigurationProtocol is not covered in HDFSPolicyProvider if (iface.getSimpleName().endsWith("Protocol")) {
// currently, so we have a special case to skip it. This needs follow-up
// investigation.
if (iface.getSimpleName().endsWith("Protocol") &&
iface != ReconfigurationProtocol.class) {
serverProtocols.add(iface); serverProtocols.add(iface);
} }
} }
Collections.sort(serverProtocols, CLASS_NAME_COMPARATOR);
LOG.info("Running test {} for RPC server {}. Found server protocols {} " LOG.info("Running test {} for RPC server {}. Found server protocols {} "
+ "and policy provider protocols {}.", testName.getMethodName(), + "and policy provider protocols {}.", testName.getMethodName(),
rpcServerClass.getName(), serverProtocols, policyProviderProtocols); rpcServerClass.getName(), serverProtocols, policyProviderProtocols);
assertFalse("Expected to find at least one protocol in server.", assertFalse("Expected to find at least one protocol in server.",
serverProtocols.isEmpty()); serverProtocols.isEmpty());
final Set<Class<?>> differenceSet =
Sets.difference(serverProtocols, policyProviderProtocols);
assertTrue( assertTrue(
String.format("Expected all protocols for server %s to be defined in " String.format("Following protocols for server %s are not defined in "
+ "%s. Server contains protocols %s. Policy provider contains " + "%s: %s",
+ "protocols %s.", rpcServerClass.getName(), rpcServerClass.getName(), HDFSPolicyProvider.class.getName(),
HDFSPolicyProvider.class.getName(), serverProtocols, Arrays.toString(differenceSet.toArray())),
policyProviderProtocols), differenceSet.isEmpty());
policyProviderProtocols.containsAll(serverProtocols));
} }
} }