at master 7.3 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.services.hadoop; 9 hadoopConf = "${import ./conf.nix { inherit cfg pkgs lib; }}/"; 10 mkIfNotNull = x: lib.mkIf (x != null) x; 11 # generic hbase role options 12 hbaseRoleOption = 13 name: extraOpts: 14 { 15 enable = lib.mkEnableOption "HBase ${name}"; 16 17 openFirewall = lib.mkOption { 18 type = lib.types.bool; 19 default = false; 20 description = "Open firewall ports for HBase ${name}."; 21 }; 22 23 restartIfChanged = lib.mkOption { 24 type = lib.types.bool; 25 default = false; 26 description = "Restart ${name} con config change."; 27 }; 28 29 extraFlags = lib.mkOption { 30 type = with lib.types; listOf str; 31 default = [ ]; 32 example = lib.literalExpression ''[ "--backup" ]''; 33 description = "Extra flags for the ${name} service."; 34 }; 35 36 environment = lib.mkOption { 37 type = with lib.types; attrsOf str; 38 default = { }; 39 example = lib.literalExpression '' 40 { 41 HBASE_MASTER_OPTS = "-Dcom.sun.management.jmxremote.ssl=true"; 42 } 43 ''; 44 description = "Environment variables passed to ${name}."; 45 }; 46 } 47 // extraOpts; 48 # generic hbase role configs 49 hbaseRoleConfig = 50 name: ports: 51 (lib.mkIf cfg.hbase."${name}".enable { 52 services.hadoop.gatewayRole = { 53 enable = true; 54 enableHbaseCli = lib.mkDefault true; 55 }; 56 57 systemd.services."hbase-${lib.toLower name}" = { 58 description = "HBase ${name}"; 59 wantedBy = [ "multi-user.target" ]; 60 path = 61 with cfg; 62 [ hbase.package ] ++ lib.optional (with cfg.hbase.master; enable && initHDFS) package; 63 preStart = lib.mkIf (with cfg.hbase.master; enable && initHDFS) ( 64 lib.concatStringsSep "\n" ( 65 map (x: "HADOOP_USER_NAME=hdfs hdfs --config /etc/hadoop-conf ${x}") [ 66 "dfsadmin -safemode wait" 67 "dfs -mkdir -p ${cfg.hbase.rootdir}" 68 "dfs -chown hbase ${cfg.hbase.rootdir}" 69 ] 70 ) 71 ); 72 73 inherit (cfg.hbase."${name}") environment; 74 script = lib.concatStringsSep " " ( 75 [ 76 "hbase --config /etc/hadoop-conf/" 77 "${lib.toLower name} start" 78 ] 79 ++ cfg.hbase."${name}".extraFlags 80 ++ map (x: "--${lib.toLower x} ${toString cfg.hbase.${name}.${x}}") ( 81 lib.filter (x: lib.hasAttr x cfg.hbase.${name}) [ 82 "port" 83 "infoPort" 84 ] 85 ) 86 ); 87 88 serviceConfig = { 89 User = "hbase"; 90 SyslogIdentifier = "hbase-${lib.toLower name}"; 91 Restart = "always"; 92 }; 93 }; 94 95 services.hadoop.hbaseSiteInternal."hbase.rootdir" = cfg.hbase.rootdir; 96 97 networking = { 98 firewall.allowedTCPPorts = lib.mkIf cfg.hbase."${name}".openFirewall ports; 99 hosts = lib.mkIf (with cfg.hbase.regionServer; enable && overrideHosts) { 100 "127.0.0.2" = lib.mkForce [ ]; 101 "::1" = lib.mkForce [ ]; 102 }; 103 }; 104 105 }); 106in 107{ 108 options.services.hadoop = { 109 110 gatewayRole.enableHbaseCli = lib.mkEnableOption "HBase CLI tools"; 111 112 hbaseSiteDefault = lib.mkOption { 113 default = { 114 "hbase.regionserver.ipc.address" = "0.0.0.0"; 115 "hbase.master.ipc.address" = "0.0.0.0"; 116 "hbase.master.info.bindAddress" = "0.0.0.0"; 117 "hbase.regionserver.info.bindAddress" = "0.0.0.0"; 118 119 "hbase.cluster.distributed" = "true"; 120 }; 121 type = lib.types.attrsOf lib.types.anything; 122 description = '' 123 Default options for hbase-site.xml 124 ''; 125 }; 126 hbaseSite = lib.mkOption { 127 default = { }; 128 type = with lib.types; attrsOf anything; 129 example = lib.literalExpression '' 130 { 131 "hbase.hregion.max.filesize" = 20*1024*1024*1024; 132 "hbase.table.normalization.enabled" = "true"; 133 } 134 ''; 135 description = '' 136 Additional options and overrides for hbase-site.xml 137 <https://github.com/apache/hbase/blob/rel/2.4.11/hbase-common/src/main/resources/hbase-default.xml> 138 ''; 139 }; 140 hbaseSiteInternal = lib.mkOption { 141 default = { }; 142 type = with lib.types; attrsOf anything; 143 internal = true; 144 description = '' 145 Internal option to add configs to hbase-site.xml based on module options 146 ''; 147 }; 148 149 hbase = { 150 151 package = lib.mkPackageOption pkgs "hbase" { }; 152 153 rootdir = lib.mkOption { 154 description = '' 155 This option will set "hbase.rootdir" in hbase-site.xml and determine 156 the directory shared by region servers and into which HBase persists. 157 The URL should be 'fully-qualified' to include the filesystem scheme. 158 If a core-site.xml is provided, the FS scheme defaults to the value 159 of "fs.defaultFS". 160 161 Filesystems other than HDFS (like S3, QFS, Swift) are also supported. 162 ''; 163 type = lib.types.str; 164 example = "hdfs://nameservice1/hbase"; 165 default = "/hbase"; 166 }; 167 zookeeperQuorum = lib.mkOption { 168 description = '' 169 This option will set "hbase.zookeeper.quorum" in hbase-site.xml. 170 Comma separated list of servers in the ZooKeeper ensemble. 171 ''; 172 type = with lib.types; nullOr commas; 173 example = "zk1.internal,zk2.internal,zk3.internal"; 174 default = null; 175 }; 176 } 177 // ( 178 let 179 ports = port: infoPort: { 180 port = lib.mkOption { 181 type = lib.types.port; 182 default = port; 183 description = "RPC port"; 184 }; 185 infoPort = lib.mkOption { 186 type = lib.types.port; 187 default = infoPort; 188 description = "web UI port"; 189 }; 190 }; 191 in 192 lib.mapAttrs hbaseRoleOption { 193 master.initHDFS = lib.mkEnableOption "initialization of the hbase directory on HDFS"; 194 regionServer.overrideHosts = lib.mkOption { 195 type = lib.types.bool; 196 default = true; 197 description = '' 198 Remove /etc/hosts entries for "127.0.0.2" and "::1" defined in nixos/modules/config/networking.nix 199 Regionservers must be able to resolve their hostnames to their IP addresses, through PTR records 200 or /etc/hosts entries. 201 ''; 202 }; 203 thrift = ports 9090 9095; 204 rest = ports 8080 8085; 205 } 206 ); 207 }; 208 209 config = lib.mkMerge ( 210 [ 211 212 (lib.mkIf cfg.gatewayRole.enable { 213 214 environment.systemPackages = lib.mkIf cfg.gatewayRole.enableHbaseCli [ cfg.hbase.package ]; 215 216 services.hadoop.hbaseSiteInternal = with cfg.hbase; { 217 "hbase.zookeeper.quorum" = mkIfNotNull zookeeperQuorum; 218 }; 219 220 users.users.hbase = { 221 description = "Hadoop HBase user"; 222 group = "hadoop"; 223 isSystemUser = true; 224 }; 225 }) 226 ] 227 ++ (lib.mapAttrsToList hbaseRoleConfig { 228 master = [ 229 16000 230 16010 231 ]; 232 regionServer = [ 233 16020 234 16030 235 ]; 236 thrift = with cfg.hbase.thrift; [ 237 port 238 infoPort 239 ]; 240 rest = with cfg.hbase.rest; [ 241 port 242 infoPort 243 ]; 244 }) 245 ); 246}