vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / hadoop / hadoop.nix
blobcc631bb468106309b8918ed13009b54077cf1a33
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";
7   nodes =
8     let
9       coreSite = {
10         "fs.defaultFS" = "hdfs://ns1";
11       };
12       hdfsSite = {
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";
29       };
30       yarnSite = {
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";
43       };
44     in
45     {
46       zk1 = { ... }: {
47         services.zookeeper.enable = true;
48         networking.firewall.allowedTCPPorts = [ 2181 ];
49       };
51       # HDFS cluster
52       nn1 = { ... }: {
53         services.hadoop = {
54           inherit package coreSite hdfsSite;
55           hdfs.namenode = {
56             enable = true;
57             openFirewall = true;
58           };
59           hdfs.zkfc.enable = true;
60         };
61       };
62       nn2 = { ... }: {
63         services.hadoop = {
64           inherit package coreSite hdfsSite;
65           hdfs.namenode = {
66             enable = true;
67             openFirewall = true;
68           };
69           hdfs.zkfc.enable = true;
70         };
71       };
73       jn1 = { ... }: {
74         services.hadoop = {
75           inherit package coreSite hdfsSite;
76           hdfs.journalnode = {
77             enable = true;
78             openFirewall = true;
79           };
80         };
81       };
82       jn2 = { ... }: {
83         services.hadoop = {
84           inherit package coreSite hdfsSite;
85           hdfs.journalnode = {
86             enable = true;
87             openFirewall = true;
88           };
89         };
90       };
91       jn3 = { ... }: {
92         services.hadoop = {
93           inherit package coreSite hdfsSite;
94           hdfs.journalnode = {
95             enable = true;
96             openFirewall = true;
97           };
98         };
99       };
101       dn1 = { ... }: {
102         virtualisation.diskSize = 4096;
103         services.hadoop = {
104           inherit package coreSite hdfsSite;
105           hdfs.datanode = {
106             enable = true;
107             openFirewall = true;
108           };
109         };
110       };
112       # YARN cluster
113       rm1 = { options, ... }: {
114         services.hadoop = {
115           inherit package coreSite hdfsSite yarnSite;
116           yarn.resourcemanager = {
117             enable = true;
118             openFirewall = true;
119           };
120         };
121       };
122       rm2 = { options, ... }: {
123         services.hadoop = {
124           inherit package coreSite hdfsSite yarnSite;
125           yarn.resourcemanager = {
126             enable = true;
127             openFirewall = true;
128           };
129         };
130       };
131       nm1 = { options, ... }: {
132         virtualisation.memorySize = 2048;
133         services.hadoop = {
134           inherit package coreSite hdfsSite yarnSite;
135           yarn.nodemanager = {
136             enable = true;
137             openFirewall = true;
138           };
139         };
140       };
141       client = { options, ... }: {
142         services.hadoop = {
143           gatewayRole.enable = true;
144           inherit package coreSite hdfsSite yarnSite;
145         };
146       };
147   };
149   testScript = ''
150     start_all()
152     #### HDFS tests ####
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")
208     # test R/W
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")
212     # Test NN failover
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")
225     #### YARN tests ####
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")
243     # Test RM failover
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")
255   '';