summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/cluster
diff options
context:
space:
mode:
authorillustris <rharikrishnan95@gmail.com>2023-02-11 19:47:13 +0530
committerillustris <rharikrishnan95@gmail.com>2023-02-11 20:07:28 +0530
commit8f1c823ab0c4662867144be8a0b7e80665789218 (patch)
tree6fa6ff68835c58a0cbef3f78edfa520661f44ad0 /nixos/modules/services/cluster
parent5d4dea59c1589914e8c44e58597a3f5a4d4d423f (diff)
nixos/hbase: add thrift and rest servers
Diffstat (limited to 'nixos/modules/services/cluster')
-rw-r--r--nixos/modules/services/cluster/hadoop/hbase.nix218
1 files changed, 115 insertions, 103 deletions
diff --git a/nixos/modules/services/cluster/hadoop/hbase.nix b/nixos/modules/services/cluster/hadoop/hbase.nix
index 97951ebfe334..51f11817bacf 100644
--- a/nixos/modules/services/cluster/hadoop/hbase.nix
+++ b/nixos/modules/services/cluster/hadoop/hbase.nix
@@ -5,11 +5,89 @@ let
cfg = config.services.hadoop;
hadoopConf = "${import ./conf.nix { inherit cfg pkgs lib; }}/";
mkIfNotNull = x: mkIf (x != null) x;
+ # generic hbase role options
+ hbaseRoleOption = name: extraOpts: {
+ enable = mkEnableOption (mdDoc "HBase ${name}");
+
+ openFirewall = mkOption {
+ type = types.bool;
+ default = false;
+ description = mdDoc "Open firewall ports for HBase ${name}.";
+ };
+
+ restartIfChanged = mkOption {
+ type = types.bool;
+ default = false;
+ description = mdDoc "Restart ${name} con config change.";
+ };
+
+ extraFlags = mkOption {
+ type = with types; listOf str;
+ default = [];
+ description = mdDoc "Extra flags for the ${name} service.";
+ };
+
+ environment = mkOption {
+ type = with types; attrsOf str;
+ default = {};
+ description = mdDoc "Environment variables passed to ${name}.";
+ };
+ } // extraOpts;
+ # generic hbase role configs
+ hbaseRoleConfig = name: ports: (mkIf cfg.hbase."${name}".enable {
+ services.hadoop.gatewayRole = {
+ enable = true;
+ enableHbaseCli = mkDefault true;
+ };
+
+ systemd.services."hbase-${toLower name}" = {
+ description = "HBase ${name}";
+ wantedBy = [ "multi-user.target" ];
+ path = with cfg; [ hbase.package ] ++ optional
+ (with cfg.hbase.master; enable && initHDFS) package;
+ preStart = mkIf (with cfg.hbase.master; enable && initHDFS)
+ (concatStringsSep "\n" (
+ map (x: "HADOOP_USER_NAME=hdfs hdfs --config /etc/hadoop-conf ${x}")[
+ "dfsadmin -safemode wait"
+ "dfs -mkdir -p ${cfg.hbase.rootdir}"
+ "dfs -chown hbase ${cfg.hbase.rootdir}"
+ ]
+ ));
+
+ inherit (cfg.hbase."${name}") environment;
+ script = concatStringsSep " " (
+ [
+ "hbase --config /etc/hadoop-conf/"
+ "${toLower name} start"
+ ]
+ ++ cfg.hbase."${name}".extraFlags
+ ++ map (x: "--${toLower x} ${toString cfg.hbase.${name}.${x}}")
+ (filter (x: hasAttr x cfg.hbase.${name}) ["port" "infoPort"])
+ );
+
+ serviceConfig = {
+ User = "hbase";
+ SyslogIdentifier = "hbase-${toLower name}";
+ Restart = "always";
+ };
+ };
+
+ services.hadoop.hbaseSiteInternal."hbase.rootdir" = cfg.hbase.rootdir;
+
+ networking = {
+ firewall.allowedTCPPorts = mkIf cfg.hbase."${name}".openFirewall ports;
+ hosts = mkIf (with cfg.hbase.regionServer; enable && overrideHosts) {
+ "127.0.0.2" = mkForce [ ];
+ "::1" = mkForce [ ];
+ };
+ };
+
+ });
in
{
options.services.hadoop = {
- gatewayRole.enableHbaseCli = mkEnableOption (lib.mdDoc "HBase CLI tools");
+ gatewayRole.enableHbaseCli = mkEnableOption (mdDoc "HBase CLI tools");
hbaseSiteDefault = mkOption {
default = {
@@ -21,7 +99,7 @@ in
"hbase.cluster.distributed" = "true";
};
type = types.attrsOf types.anything;
- description = lib.mdDoc ''
+ description = mdDoc ''
Default options for hbase-site.xml
'';
};
@@ -30,7 +108,7 @@ in
type = with types; attrsOf anything;
example = literalExpression ''
'';
- description = lib.mdDoc ''
+ description = mdDoc ''
Additional options and overrides for hbase-site.xml
<https://github.com/apache/hbase/blob/rel/2.4.11/hbase-common/src/main/resources/hbase-default.xml>
'';
@@ -39,7 +117,7 @@ in
default = {};
type = with types; attrsOf anything;
internal = true;
- description = lib.mdDoc ''
+ description = mdDoc ''
Internal option to add configs to hbase-site.xml based on module options
'';
};
@@ -50,11 +128,11 @@ in
type = types.package;
default = pkgs.hbase;
defaultText = literalExpression "pkgs.hbase";
- description = lib.mdDoc "HBase package";
+ description = mdDoc "HBase package";
};
rootdir = mkOption {
- description = lib.mdDoc ''
+ description = mdDoc ''
This option will set "hbase.rootdir" in hbase-site.xml and determine
the directory shared by region servers and into which HBase persists.
The URL should be 'fully-qualified' to include the filesystem scheme.
@@ -68,7 +146,7 @@ in
default = "/hbase";
};
zookeeperQuorum = mkOption {
- description = lib.mdDoc ''
+ description = mdDoc ''
This option will set "hbase.zookeeper.quorum" in hbase-site.xml.
Comma separated list of servers in the ZooKeeper ensemble.
'';
@@ -76,107 +154,36 @@ in
example = "zk1.internal,zk2.internal,zk3.internal";
default = null;
};
- master = {
- enable = mkEnableOption (lib.mdDoc "HBase Master");
- initHDFS = mkEnableOption (lib.mdDoc "initialization of the hbase directory on HDFS");
-
- openFirewall = mkOption {
- type = types.bool;
- default = false;
- description = lib.mdDoc ''
- Open firewall ports for HBase master.
- '';
+ } // (let
+ ports = port: infoPort: {
+ port = mkOption {
+ type = types.int;
+ default = port;
+ description = mdDoc "RPC port";
};
- };
- regionServer = {
- enable = mkEnableOption (lib.mdDoc "HBase RegionServer");
-
- overrideHosts = mkOption {
- type = types.bool;
- default = true;
- description = lib.mdDoc ''
- Remove /etc/hosts entries for "127.0.0.2" and "::1" defined in nixos/modules/config/networking.nix
- Regionservers must be able to resolve their hostnames to their IP addresses, through PTR records
- or /etc/hosts entries.
-
- '';
+ infoPort = mkOption {
+ type = types.int;
+ default = infoPort;
+ description = mdDoc "web UI port";
};
-
- openFirewall = mkOption {
- type = types.bool;
- default = false;
- description = lib.mdDoc ''
- Open firewall ports for HBase master.
- '';
- };
- };
- };
- };
-
- config = mkMerge [
- (mkIf cfg.hbase.master.enable {
- services.hadoop.gatewayRole = {
- enable = true;
- enableHbaseCli = mkDefault true;
};
-
- systemd.services.hbase-master = {
- description = "HBase master";
- wantedBy = [ "multi-user.target" ];
-
- preStart = mkIf cfg.hbase.master.initHDFS ''
- HADOOP_USER_NAME=hdfs ${cfg.package}/bin/hdfs --config ${hadoopConf} dfsadmin -safemode wait
- HADOOP_USER_NAME=hdfs ${cfg.package}/bin/hdfs --config ${hadoopConf} dfs -mkdir -p ${cfg.hbase.rootdir}
- HADOOP_USER_NAME=hdfs ${cfg.package}/bin/hdfs --config ${hadoopConf} dfs -chown hbase ${cfg.hbase.rootdir}
+ in mapAttrs hbaseRoleOption {
+ master.initHDFS = mkEnableOption (mdDoc "initialization of the hbase directory on HDFS");
+ regionServer.overrideHosts = mkOption {
+ type = types.bool;
+ default = true;
+ description = mdDoc ''
+ Remove /etc/hosts entries for "127.0.0.2" and "::1" defined in nixos/modules/config/networking.nix
+ Regionservers must be able to resolve their hostnames to their IP addresses, through PTR records
+ or /etc/hosts entries.
'';
-
- serviceConfig = {
- User = "hbase";
- SyslogIdentifier = "hbase-master";
- ExecStart = "${cfg.hbase.package}/bin/hbase --config ${hadoopConf} " +
- "master start";
- Restart = "always";
- };
};
+ thrift = ports 9090 9095;
+ rest = ports 8080 8085;
+ });
+ };
- services.hadoop.hbaseSiteInternal."hbase.rootdir" = cfg.hbase.rootdir;
-
- networking.firewall.allowedTCPPorts = mkIf cfg.hbase.master.openFirewall [
- 16000 16010
- ];
-
- })
-
- (mkIf cfg.hbase.regionServer.enable {
- services.hadoop.gatewayRole = {
- enable = true;
- enableHbaseCli = mkDefault true;
- };
-
- systemd.services.hbase-regionserver = {
- description = "HBase RegionServer";
- wantedBy = [ "multi-user.target" ];
- serviceConfig = {
- User = "hbase";
- SyslogIdentifier = "hbase-regionserver";
- ExecStart = "${cfg.hbase.package}/bin/hbase --config /etc/hadoop-conf/ " +
- "regionserver start";
- Restart = "always";
- };
- };
-
- services.hadoop.hbaseSiteInternal."hbase.rootdir" = cfg.hbase.rootdir;
-
- networking = {
- firewall.allowedTCPPorts = mkIf cfg.hbase.regionServer.openFirewall [
- 16020 16030
- ];
- hosts = mkIf cfg.hbase.regionServer.overrideHosts {
- "127.0.0.2" = mkForce [ ];
- "::1" = mkForce [ ];
- };
- };
- })
+ config = mkMerge ([
(mkIf cfg.gatewayRole.enable {
@@ -192,5 +199,10 @@ in
isSystemUser = true;
};
})
- ];
+ ] ++ (mapAttrsToList hbaseRoleConfig {
+ master = [ 16000 16010 ];
+ regionServer = [ 16020 16030 ];
+ thrift = with cfg.hbase.thrift; [ port infoPort ];
+ rest = with cfg.hbase.rest; [ port infoPort ];
+ }));
}