|
@@ -19,8 +19,12 @@ package org.apache.hadoop.tracing;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
|
+import org.apache.hadoop.hdfs.HdfsConfiguration;
|
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
|
+import org.apache.hadoop.hdfs.protocol.datatransfer.sasl.SaslDataTransferTestCase;
|
|
|
+import org.apache.hadoop.hdfs.server.datanode.DataNode;
|
|
|
import org.apache.hadoop.net.unix.TemporarySocketDirectory;
|
|
|
+import org.apache.hadoop.security.UserGroupInformation;
|
|
|
import org.apache.htrace.core.Tracer;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Test;
|
|
@@ -28,9 +32,18 @@ import org.junit.Test;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.File;
|
|
|
import java.io.PrintStream;
|
|
|
+import java.security.PrivilegedExceptionAction;
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
|
-public class TestTraceAdmin {
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test cases for TraceAdmin.
|
|
|
+ */
|
|
|
+public class TestTraceAdmin extends SaslDataTransferTestCase {
|
|
|
private static final String NEWLINE = System.getProperty("line.separator");
|
|
|
+ private final static int ONE_DATANODE = 1;
|
|
|
|
|
|
private String runTraceCommand(TraceAdmin trace, String... cmd)
|
|
|
throws Exception {
|
|
@@ -58,6 +71,12 @@ public class TestTraceAdmin {
|
|
|
return "127.0.0.1:" + cluster.getNameNodePort();
|
|
|
}
|
|
|
|
|
|
+ private String getHostPortForDN(MiniDFSCluster cluster, int index) {
|
|
|
+ ArrayList<DataNode> dns = cluster.getDataNodes();
|
|
|
+ assertTrue(index >= 0 && index < dns.size());
|
|
|
+ return "127.0.0.1:" + dns.get(index).getIpcPort();
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testCreateAndDestroySpanReceiver() throws Exception {
|
|
|
Configuration conf = new Configuration();
|
|
@@ -102,4 +121,52 @@ public class TestTraceAdmin {
|
|
|
tempDir.close();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test running hadoop trace commands with -principal option against
|
|
|
+ * Kerberized NN and DN.
|
|
|
+ *
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testKerberizedTraceAdmin() throws Exception {
|
|
|
+ MiniDFSCluster cluster = null;
|
|
|
+ final HdfsConfiguration conf = createSecureConfig(
|
|
|
+ "authentication,privacy");
|
|
|
+ try {
|
|
|
+ cluster = new MiniDFSCluster.Builder(conf)
|
|
|
+ .numDataNodes(ONE_DATANODE)
|
|
|
+ .build();
|
|
|
+ cluster.waitActive();
|
|
|
+ final String nnHost = getHostPortForNN(cluster);
|
|
|
+ final String dnHost = getHostPortForDN(cluster, 0);
|
|
|
+ // login using keytab and run commands
|
|
|
+ UserGroupInformation
|
|
|
+ .loginUserFromKeytabAndReturnUGI(getHdfsPrincipal(), getHdfsKeytab())
|
|
|
+ .doAs(new PrivilegedExceptionAction<Void>() {
|
|
|
+ @Override
|
|
|
+ public Void run() throws Exception {
|
|
|
+ // send trace command to NN
|
|
|
+ TraceAdmin trace = new TraceAdmin();
|
|
|
+ trace.setConf(conf);
|
|
|
+ final String[] nnTraceCmd = new String[] {
|
|
|
+ "-list", "-host", nnHost, "-principal",
|
|
|
+ conf.get(DFSConfigKeys.DFS_NAMENODE_KERBEROS_PRINCIPAL_KEY)};
|
|
|
+ int ret = trace.run(nnTraceCmd);
|
|
|
+ assertEquals(0, ret);
|
|
|
+ // send trace command to DN
|
|
|
+ final String[] dnTraceCmd = new String[] {
|
|
|
+ "-list", "-host", dnHost, "-principal",
|
|
|
+ conf.get(DFSConfigKeys.DFS_DATANODE_KERBEROS_PRINCIPAL_KEY)};
|
|
|
+ ret = trace.run(dnTraceCmd);
|
|
|
+ assertEquals(0, ret);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } finally {
|
|
|
+ if (cluster != null) {
|
|
|
+ cluster.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|