2018-05-20 21:09:31 -04:00
|
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
lib,
|
|
|
|
|
pkgs,
|
|
|
|
|
...
|
|
|
|
|
}:
|
|
|
|
|
let
|
|
|
|
|
cfg = config.services.hadoop;
|
2021-10-21 02:01:12 +05:30
|
|
|
|
hadoopConf = "${import ./conf.nix { inherit cfg pkgs lib; }}/";
|
2024-12-08 13:18:23 +01:00
|
|
|
|
restartIfChanged = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
2021-10-21 02:01:12 +05:30
|
|
|
|
description = ''
|
|
|
|
|
Automatically restart the service on config change.
|
|
|
|
|
This can be set to false to defer restarts on clusters running critical applications.
|
|
|
|
|
Please consider the security implications of inadvertently running an older version,
|
|
|
|
|
and the possibility of unexpected behavior caused by inconsistent versions across a cluster when disabling this option.
|
|
|
|
|
'';
|
|
|
|
|
default = false;
|
|
|
|
|
};
|
2024-12-08 13:18:23 +01:00
|
|
|
|
extraFlags = lib.mkOption {
|
|
|
|
|
type = with lib.types; listOf str;
|
2022-03-02 12:50:01 +05:30
|
|
|
|
default = [ ];
|
|
|
|
|
description = "Extra command line flags to pass to the service";
|
|
|
|
|
example = [
|
|
|
|
|
"-Dcom.sun.management.jmxremote"
|
|
|
|
|
"-Dcom.sun.management.jmxremote.port=8010"
|
|
|
|
|
];
|
|
|
|
|
};
|
2024-12-08 13:18:23 +01:00
|
|
|
|
extraEnv = lib.mkOption {
|
|
|
|
|
type = with lib.types; attrsOf str;
|
2022-03-02 12:50:01 +05:30
|
|
|
|
default = { };
|
|
|
|
|
description = "Extra environment variables";
|
|
|
|
|
};
|
2018-05-20 21:09:31 -04:00
|
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
options.services.hadoop.yarn = {
|
2021-10-21 02:01:12 +05:30
|
|
|
|
resourcemanager = {
|
2024-12-08 13:18:23 +01:00
|
|
|
|
enable = lib.mkEnableOption "Hadoop YARN ResourceManager";
|
2022-03-02 12:50:01 +05:30
|
|
|
|
inherit restartIfChanged extraFlags extraEnv;
|
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
|
openFirewall = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
2022-01-08 16:19:15 +05:30
|
|
|
|
default = false;
|
2021-10-21 02:01:12 +05:30
|
|
|
|
description = ''
|
|
|
|
|
Open firewall ports for resourcemanager
|
|
|
|
|
'';
|
|
|
|
|
};
|
2018-05-20 21:09:31 -04:00
|
|
|
|
};
|
2021-10-21 02:01:12 +05:30
|
|
|
|
nodemanager = {
|
2024-12-08 13:18:23 +01:00
|
|
|
|
enable = lib.mkEnableOption "Hadoop YARN NodeManager";
|
2022-03-02 12:50:01 +05:30
|
|
|
|
inherit restartIfChanged extraFlags extraEnv;
|
|
|
|
|
|
|
|
|
|
resource = {
|
2024-12-08 13:18:23 +01:00
|
|
|
|
cpuVCores = lib.mkOption {
|
2022-03-02 12:50:01 +05:30
|
|
|
|
description = "Number of vcores that can be allocated for containers.";
|
2024-12-08 13:18:23 +01:00
|
|
|
|
type = with lib.types; nullOr ints.positive;
|
2022-03-02 12:50:01 +05:30
|
|
|
|
default = null;
|
|
|
|
|
};
|
2024-12-08 13:18:23 +01:00
|
|
|
|
maximumAllocationVCores = lib.mkOption {
|
2022-03-02 12:50:01 +05:30
|
|
|
|
description = "The maximum virtual CPU cores any container can be allocated.";
|
2024-12-08 13:18:23 +01:00
|
|
|
|
type = with lib.types; nullOr ints.positive;
|
2022-03-02 12:50:01 +05:30
|
|
|
|
default = null;
|
|
|
|
|
};
|
2024-12-08 13:18:23 +01:00
|
|
|
|
memoryMB = lib.mkOption {
|
2022-03-02 12:50:01 +05:30
|
|
|
|
description = "Amount of physical memory, in MB, that can be allocated for containers.";
|
2024-12-08 13:18:23 +01:00
|
|
|
|
type = with lib.types; nullOr ints.positive;
|
2022-03-02 12:50:01 +05:30
|
|
|
|
default = null;
|
|
|
|
|
};
|
2024-12-08 13:18:23 +01:00
|
|
|
|
maximumAllocationMB = lib.mkOption {
|
2022-03-02 12:50:01 +05:30
|
|
|
|
description = "The maximum physical memory any container can be allocated.";
|
2024-12-08 13:18:23 +01:00
|
|
|
|
type = with lib.types; nullOr ints.positive;
|
2022-03-02 12:50:01 +05:30
|
|
|
|
default = null;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
|
useCGroups = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
2022-03-02 12:50:01 +05:30
|
|
|
|
default = true;
|
|
|
|
|
description = ''
|
|
|
|
|
Use cgroups to enforce resource limits on containers
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
|
localDir = lib.mkOption {
|
2022-03-02 12:50:01 +05:30
|
|
|
|
description = "List of directories to store localized files in.";
|
2024-12-08 13:18:23 +01:00
|
|
|
|
type = with lib.types; nullOr (listOf path);
|
2022-03-02 12:50:01 +05:30
|
|
|
|
example = [ "/var/lib/hadoop/yarn/nm" ];
|
|
|
|
|
default = null;
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
|
addBinBash = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
2021-10-21 02:01:12 +05:30
|
|
|
|
default = true;
|
|
|
|
|
description = ''
|
|
|
|
|
Add /bin/bash. This is needed by the linux container executor's launch script.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2024-12-08 13:18:23 +01:00
|
|
|
|
openFirewall = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
2022-01-08 16:19:15 +05:30
|
|
|
|
default = false;
|
2021-10-21 02:01:12 +05:30
|
|
|
|
description = ''
|
|
|
|
|
Open firewall ports for nodemanager.
|
|
|
|
|
Because containers can listen on any ephemeral port, TCP ports 1024–65535 will be opened.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2018-05-20 21:09:31 -04:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
|
config = lib.mkMerge [
|
|
|
|
|
(lib.mkIf cfg.gatewayRole.enable {
|
2018-07-02 17:57:31 +02:00
|
|
|
|
users.users.yarn = {
|
2018-05-20 21:09:31 -04:00
|
|
|
|
description = "Hadoop YARN user";
|
|
|
|
|
group = "hadoop";
|
|
|
|
|
uid = config.ids.uids.yarn;
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
|
(lib.mkIf cfg.yarn.resourcemanager.enable {
|
2019-08-13 21:52:01 +00:00
|
|
|
|
systemd.services.yarn-resourcemanager = {
|
2018-05-20 21:09:31 -04:00
|
|
|
|
description = "Hadoop YARN ResourceManager";
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-10-21 02:01:12 +05:30
|
|
|
|
inherit (cfg.yarn.resourcemanager) restartIfChanged;
|
2022-03-02 12:50:01 +05:30
|
|
|
|
environment = cfg.yarn.resourcemanager.extraEnv;
|
2018-05-20 21:09:31 -04:00
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
User = "yarn";
|
|
|
|
|
SyslogIdentifier = "yarn-resourcemanager";
|
|
|
|
|
ExecStart =
|
|
|
|
|
"${cfg.package}/bin/yarn --config ${hadoopConf} "
|
2024-12-08 13:18:23 +01:00
|
|
|
|
+ " resourcemanager ${lib.escapeShellArgs cfg.yarn.resourcemanager.extraFlags}";
|
2021-10-21 02:01:12 +05:30
|
|
|
|
Restart = "always";
|
2018-05-20 21:09:31 -04:00
|
|
|
|
};
|
|
|
|
|
};
|
2022-02-27 11:52:18 +05:30
|
|
|
|
|
|
|
|
|
services.hadoop.gatewayRole.enable = true;
|
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
|
networking.firewall.allowedTCPPorts = (
|
|
|
|
|
lib.mkIf cfg.yarn.resourcemanager.openFirewall [
|
2021-10-21 02:01:12 +05:30
|
|
|
|
8088 # resourcemanager.webapp.address
|
|
|
|
|
8030 # resourcemanager.scheduler.address
|
|
|
|
|
8031 # resourcemanager.resource-tracker.address
|
|
|
|
|
8032 # resourcemanager.address
|
2021-11-02 11:59:58 +05:30
|
|
|
|
8033 # resourcemanager.admin.address
|
2021-10-21 02:01:12 +05:30
|
|
|
|
]
|
|
|
|
|
);
|
2018-05-20 21:09:31 -04:00
|
|
|
|
})
|
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
|
(lib.mkIf cfg.yarn.nodemanager.enable {
|
2021-10-21 02:01:12 +05:30
|
|
|
|
# Needed because yarn hardcodes /bin/bash in container start scripts
|
|
|
|
|
# These scripts can't be patched, they are generated at runtime
|
|
|
|
|
systemd.tmpfiles.rules = [
|
2024-12-08 13:18:23 +01:00
|
|
|
|
(lib.mkIf cfg.yarn.nodemanager.addBinBash "L /bin/bash - - - - /run/current-system/sw/bin/bash")
|
2021-10-21 02:01:12 +05:30
|
|
|
|
];
|
|
|
|
|
|
2019-08-13 21:52:01 +00:00
|
|
|
|
systemd.services.yarn-nodemanager = {
|
2018-05-20 21:09:31 -04:00
|
|
|
|
description = "Hadoop YARN NodeManager";
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-10-21 02:01:12 +05:30
|
|
|
|
inherit (cfg.yarn.nodemanager) restartIfChanged;
|
2022-03-02 12:50:01 +05:30
|
|
|
|
environment = cfg.yarn.nodemanager.extraEnv;
|
2018-05-20 21:09:31 -04:00
|
|
|
|
|
2021-10-21 02:01:12 +05:30
|
|
|
|
preStart = ''
|
|
|
|
|
# create log dir
|
|
|
|
|
mkdir -p /var/log/hadoop/yarn/nodemanager
|
|
|
|
|
chown yarn:hadoop /var/log/hadoop/yarn/nodemanager
|
|
|
|
|
|
|
|
|
|
# set up setuid container executor binary
|
2022-02-28 20:41:43 +05:30
|
|
|
|
umount /run/wrappers/yarn-nodemanager/cgroup/cpu || true
|
2021-10-21 02:01:12 +05:30
|
|
|
|
rm -rf /run/wrappers/yarn-nodemanager/ || true
|
2022-02-28 20:41:43 +05:30
|
|
|
|
mkdir -p /run/wrappers/yarn-nodemanager/{bin,etc/hadoop,cgroup/cpu}
|
2023-09-22 16:34:07 +05:30
|
|
|
|
cp ${cfg.package}/bin/container-executor /run/wrappers/yarn-nodemanager/bin/
|
2021-10-21 02:01:12 +05:30
|
|
|
|
chgrp hadoop /run/wrappers/yarn-nodemanager/bin/container-executor
|
|
|
|
|
chmod 6050 /run/wrappers/yarn-nodemanager/bin/container-executor
|
|
|
|
|
cp ${hadoopConf}/container-executor.cfg /run/wrappers/yarn-nodemanager/etc/hadoop/
|
|
|
|
|
'';
|
2018-05-20 21:09:31 -04:00
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
User = "yarn";
|
|
|
|
|
SyslogIdentifier = "yarn-nodemanager";
|
2021-10-21 02:01:12 +05:30
|
|
|
|
PermissionsStartOnly = true;
|
2018-05-20 21:09:31 -04:00
|
|
|
|
ExecStart =
|
|
|
|
|
"${cfg.package}/bin/yarn --config ${hadoopConf} "
|
2024-12-08 13:18:23 +01:00
|
|
|
|
+ " nodemanager ${lib.escapeShellArgs cfg.yarn.nodemanager.extraFlags}";
|
2021-10-21 02:01:12 +05:30
|
|
|
|
Restart = "always";
|
2018-05-20 21:09:31 -04:00
|
|
|
|
};
|
|
|
|
|
};
|
2021-10-21 02:01:12 +05:30
|
|
|
|
|
2022-02-27 11:52:18 +05:30
|
|
|
|
services.hadoop.gatewayRole.enable = true;
|
|
|
|
|
|
2022-05-13 10:55:16 +05:30
|
|
|
|
services.hadoop.yarnSiteInternal =
|
|
|
|
|
with cfg.yarn.nodemanager;
|
2024-12-13 21:19:06 +05:30
|
|
|
|
lib.mkMerge [
|
2022-05-13 10:55:16 +05:30
|
|
|
|
({
|
2024-12-13 21:19:06 +05:30
|
|
|
|
"yarn.nodemanager.local-dirs" = lib.mkIf (localDir != null) (concatStringsSep "," localDir);
|
2022-03-02 12:50:01 +05:30
|
|
|
|
"yarn.scheduler.maximum-allocation-vcores" = resource.maximumAllocationVCores;
|
|
|
|
|
"yarn.scheduler.maximum-allocation-mb" = resource.maximumAllocationMB;
|
|
|
|
|
"yarn.nodemanager.resource.cpu-vcores" = resource.cpuVCores;
|
|
|
|
|
"yarn.nodemanager.resource.memory-mb" = resource.memoryMB;
|
2022-05-13 10:55:16 +05:30
|
|
|
|
})
|
2024-12-14 00:28:13 +05:30
|
|
|
|
(lib.mkIf useCGroups (
|
|
|
|
|
lib.warnIf (lib.versionOlder cfg.package.version "3.5.0")
|
|
|
|
|
''
|
|
|
|
|
hadoop < 3.5.0 does not support cgroup v2
|
|
|
|
|
setting `services.hadoop.yarn.nodemanager.useCGroups = false` is recommended
|
|
|
|
|
see: https://issues.apache.org/jira/browse/YARN-11669
|
|
|
|
|
''
|
|
|
|
|
{
|
|
|
|
|
"yarn.nodemanager.linux-container-executor.cgroups.hierarchy" = "/hadoop-yarn";
|
|
|
|
|
"yarn.nodemanager.linux-container-executor.resources-handler.class" =
|
|
|
|
|
"org.apache.hadoop.yarn.server.nodemanager.util.CgroupsLCEResourcesHandler";
|
|
|
|
|
"yarn.nodemanager.linux-container-executor.cgroups.mount" = "true";
|
|
|
|
|
"yarn.nodemanager.linux-container-executor.cgroups.mount-path" =
|
|
|
|
|
"/run/wrappers/yarn-nodemanager/cgroup";
|
|
|
|
|
}
|
|
|
|
|
))
|
2022-05-13 10:55:16 +05:30
|
|
|
|
];
|
2022-03-02 12:50:01 +05:30
|
|
|
|
|
2021-10-21 02:01:12 +05:30
|
|
|
|
networking.firewall.allowedTCPPortRanges = [
|
2024-12-08 13:18:23 +01:00
|
|
|
|
(lib.mkIf (cfg.yarn.nodemanager.openFirewall) {
|
|
|
|
|
from = 1024;
|
|
|
|
|
to = 65535;
|
|
|
|
|
})
|
2021-10-21 02:01:12 +05:30
|
|
|
|
];
|
2018-05-20 21:09:31 -04:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
];
|
|
|
|
|
}
|