1 # This test is very comprehensive. It tests whether all hadoop services work well with each other.
2 # Run this when updating the Hadoop package or making significant changes to the hadoop module.
3 # For a more basic test, see hdfs.nix and yarn.nix
4 import ../make-test-python.nix ({ package, ... }: {
5 name = "hadoop-combined";
10 "fs.defaultFS" = "hdfs://ns1";
13 # HA Quorum Journal Manager configuration
14 "dfs.nameservices" = "ns1";
15 "dfs.ha.namenodes.ns1" = "nn1,nn2";
16 "dfs.namenode.shared.edits.dir.ns1" = "qjournal://jn1:8485;jn2:8485;jn3:8485/ns1";
17 "dfs.namenode.rpc-address.ns1.nn1" = "nn1:8020";
18 "dfs.namenode.rpc-address.ns1.nn2" = "nn2:8020";
19 "dfs.namenode.servicerpc-address.ns1.nn1" = "nn1:8022";
20 "dfs.namenode.servicerpc-address.ns1.nn2" = "nn2:8022";
21 "dfs.namenode.http-address.ns1.nn1" = "nn1:9870";
22 "dfs.namenode.http-address.ns1.nn2" = "nn2:9870";
24 # Automatic failover configuration
25 "dfs.client.failover.proxy.provider.ns1" = "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider";
26 "dfs.ha.automatic-failover.enabled.ns1" = "true";
27 "dfs.ha.fencing.methods" = "shell(true)";
28 "ha.zookeeper.quorum" = "zk1:2181";
31 "yarn.resourcemanager.zk-address" = "zk1:2181";
32 "yarn.resourcemanager.ha.enabled" = "true";
33 "yarn.resourcemanager.ha.rm-ids" = "rm1,rm2";
34 "yarn.resourcemanager.hostname.rm1" = "rm1";
35 "yarn.resourcemanager.hostname.rm2" = "rm2";
36 "yarn.resourcemanager.ha.automatic-failover.enabled" = "true";
37 "yarn.resourcemanager.cluster-id" = "cluster1";
38 # yarn.resourcemanager.webapp.address needs to be defined even though yarn.resourcemanager.hostname is set. This shouldn't be necessary, but there's a bug in
39 # hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/amfilter/AmFilterInitializer.java:70
40 # that causes AM containers to fail otherwise.
41 "yarn.resourcemanager.webapp.address.rm1" = "rm1:8088";
42 "yarn.resourcemanager.webapp.address.rm2" = "rm2:8088";
47 services.zookeeper.enable = true;
48 networking.firewall.allowedTCPPorts = [ 2181 ];
54 inherit package coreSite hdfsSite;
59 hdfs.zkfc.enable = true;
64 inherit package coreSite hdfsSite;
69 hdfs.zkfc.enable = true;
75 inherit package coreSite hdfsSite;
84 inherit package coreSite hdfsSite;
93 inherit package coreSite hdfsSite;
102 virtualisation.diskSize = 4096;
104 inherit package coreSite hdfsSite;
113 rm1 = { options, ... }: {
115 inherit package coreSite hdfsSite yarnSite;
116 yarn.resourcemanager = {
122 rm2 = { options, ... }: {
124 inherit package coreSite hdfsSite yarnSite;
125 yarn.resourcemanager = {
131 nm1 = { options, ... }: {
132 virtualisation.memorySize = 2048;
134 inherit package coreSite hdfsSite yarnSite;
141 client = { options, ... }: {
143 gatewayRole.enable = true;
144 inherit package coreSite hdfsSite yarnSite;
154 zk1.wait_for_unit("network.target")
155 jn1.wait_for_unit("network.target")
156 jn2.wait_for_unit("network.target")
157 jn3.wait_for_unit("network.target")
158 nn1.wait_for_unit("network.target")
159 nn2.wait_for_unit("network.target")
160 dn1.wait_for_unit("network.target")
162 zk1.wait_for_unit("zookeeper")
163 jn1.wait_for_unit("hdfs-journalnode")
164 jn2.wait_for_unit("hdfs-journalnode")
165 jn3.wait_for_unit("hdfs-journalnode")
167 zk1.wait_for_open_port(2181)
168 jn1.wait_for_open_port(8480)
169 jn1.wait_for_open_port(8485)
170 jn2.wait_for_open_port(8480)
171 jn2.wait_for_open_port(8485)
173 # Namenodes must be stopped before initializing the cluster
174 nn1.succeed("systemctl stop hdfs-namenode")
175 nn2.succeed("systemctl stop hdfs-namenode")
176 nn1.succeed("systemctl stop hdfs-zkfc")
177 nn2.succeed("systemctl stop hdfs-zkfc")
179 # Initialize zookeeper for failover controller
180 nn1.succeed("sudo -u hdfs systemd-cat hdfs zkfc -formatZK")
182 # Format NN1 and start it
183 nn1.succeed("sudo -u hdfs systemd-cat hadoop namenode -format")
184 nn1.succeed("systemctl start hdfs-namenode")
185 nn1.wait_for_open_port(9870)
186 nn1.wait_for_open_port(8022)
187 nn1.wait_for_open_port(8020)
189 # Bootstrap NN2 from NN1 and start it
190 nn2.succeed("sudo -u hdfs systemd-cat hdfs namenode -bootstrapStandby")
191 nn2.succeed("systemctl start hdfs-namenode")
192 nn2.wait_for_open_port(9870)
193 nn2.wait_for_open_port(8022)
194 nn2.wait_for_open_port(8020)
195 nn1.succeed("systemd-cat netstat -tulpne")
197 # Start failover controllers
198 nn1.succeed("systemctl start hdfs-zkfc")
199 nn2.succeed("systemctl start hdfs-zkfc")
201 # DN should have started by now, but confirm anyway
202 dn1.wait_for_unit("hdfs-datanode")
203 # Print states of namenodes
204 client.succeed("sudo -u hdfs systemd-cat hdfs haadmin -getAllServiceState")
205 # Wait for cluster to exit safemode
206 client.succeed("sudo -u hdfs hdfs dfsadmin -safemode wait")
207 client.succeed("sudo -u hdfs systemd-cat hdfs haadmin -getAllServiceState")
209 client.succeed("echo testfilecontents | sudo -u hdfs hdfs dfs -put - /testfile")
210 assert "testfilecontents" in client.succeed("sudo -u hdfs hdfs dfs -cat /testfile")
213 nn1.succeed("systemctl stop hdfs-namenode")
214 assert "active" in client.succeed("sudo -u hdfs hdfs haadmin -getAllServiceState")
215 client.succeed("sudo -u hdfs systemd-cat hdfs haadmin -getAllServiceState")
216 assert "testfilecontents" in client.succeed("sudo -u hdfs hdfs dfs -cat /testfile")
218 nn1.succeed("systemctl start hdfs-namenode")
219 nn1.wait_for_open_port(9870)
220 nn1.wait_for_open_port(8022)
221 nn1.wait_for_open_port(8020)
222 assert "standby" in client.succeed("sudo -u hdfs hdfs haadmin -getAllServiceState")
223 client.succeed("sudo -u hdfs systemd-cat hdfs haadmin -getAllServiceState")
227 rm1.wait_for_unit("network.target")
228 rm2.wait_for_unit("network.target")
229 nm1.wait_for_unit("network.target")
231 rm1.wait_for_unit("yarn-resourcemanager")
232 rm1.wait_for_open_port(8088)
233 rm2.wait_for_unit("yarn-resourcemanager")
234 rm2.wait_for_open_port(8088)
236 nm1.wait_for_unit("yarn-nodemanager")
237 nm1.wait_for_open_port(8042)
238 nm1.wait_for_open_port(8040)
239 client.wait_until_succeeds("yarn node -list | grep Nodes:1")
240 client.succeed("sudo -u yarn systemd-cat yarn rmadmin -getAllServiceState")
241 client.succeed("sudo -u yarn systemd-cat yarn node -list")
244 rm1.succeed("systemctl stop yarn-resourcemanager")
245 assert "standby" not in client.succeed("sudo -u yarn yarn rmadmin -getAllServiceState")
246 client.succeed("sudo -u yarn systemd-cat yarn rmadmin -getAllServiceState")
247 rm1.succeed("systemctl start yarn-resourcemanager")
248 rm1.wait_for_unit("yarn-resourcemanager")
249 rm1.wait_for_open_port(8088)
250 assert "standby" in client.succeed("sudo -u yarn yarn rmadmin -getAllServiceState")
251 client.succeed("sudo -u yarn systemd-cat yarn rmadmin -getAllServiceState")
253 assert "Estimated value of Pi is" in client.succeed("HADOOP_USER_NAME=hdfs yarn jar $(readlink $(which yarn) | sed -r 's~bin/yarn~share/hadoop/mapreduce/hadoop-mapreduce-examples-*.jar~g') pi 2 10")
254 assert "SUCCEEDED" in client.succeed("yarn application -list -appStates FINISHED")