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