2020-04-24 23:36:52 +00:00
|
|
|
|
{ config, lib, pkgs, ...}:
|
2021-10-28 06:52:43 +00:00
|
|
|
|
with lib;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
let
|
|
|
|
|
cfg = config.services.hadoop;
|
2021-10-28 06:52:43 +00:00
|
|
|
|
hadoopConf = "${import ./conf.nix { inherit cfg pkgs lib; }}/";
|
|
|
|
|
restartIfChanged = mkOption {
|
|
|
|
|
type = types.bool;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2021-10-28 06:52:43 +00:00
|
|
|
|
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;
|
|
|
|
|
};
|
2022-03-30 09:31:56 +00:00
|
|
|
|
extraFlags = mkOption{
|
|
|
|
|
type = with types; listOf str;
|
|
|
|
|
default = [];
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Extra command line flags to pass to the service";
|
2022-03-30 09:31:56 +00:00
|
|
|
|
example = [
|
|
|
|
|
"-Dcom.sun.management.jmxremote"
|
|
|
|
|
"-Dcom.sun.management.jmxremote.port=8010"
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
extraEnv = mkOption{
|
|
|
|
|
type = with types; attrsOf str;
|
|
|
|
|
default = {};
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Extra environment variables";
|
2022-03-30 09:31:56 +00:00
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
options.services.hadoop.yarn = {
|
2021-10-28 06:52:43 +00:00
|
|
|
|
resourcemanager = {
|
2022-09-09 14:08:57 +00:00
|
|
|
|
enable = mkEnableOption (lib.mdDoc "Hadoop YARN ResourceManager");
|
2022-03-30 09:31:56 +00:00
|
|
|
|
inherit restartIfChanged extraFlags extraEnv;
|
|
|
|
|
|
2021-10-28 06:52:43 +00:00
|
|
|
|
openFirewall = mkOption {
|
|
|
|
|
type = types.bool;
|
2022-03-30 09:31:56 +00:00
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2021-10-28 06:52:43 +00:00
|
|
|
|
Open firewall ports for resourcemanager
|
|
|
|
|
'';
|
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
2021-10-28 06:52:43 +00:00
|
|
|
|
nodemanager = {
|
2022-09-09 14:08:57 +00:00
|
|
|
|
enable = mkEnableOption (lib.mdDoc "Hadoop YARN NodeManager");
|
2022-03-30 09:31:56 +00:00
|
|
|
|
inherit restartIfChanged extraFlags extraEnv;
|
|
|
|
|
|
|
|
|
|
resource = {
|
|
|
|
|
cpuVCores = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Number of vcores that can be allocated for containers.";
|
2022-03-30 09:31:56 +00:00
|
|
|
|
type = with types; nullOr ints.positive;
|
|
|
|
|
default = null;
|
|
|
|
|
};
|
|
|
|
|
maximumAllocationVCores = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "The maximum virtual CPU cores any container can be allocated.";
|
2022-03-30 09:31:56 +00:00
|
|
|
|
type = with types; nullOr ints.positive;
|
|
|
|
|
default = null;
|
|
|
|
|
};
|
|
|
|
|
memoryMB = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Amount of physical memory, in MB, that can be allocated for containers.";
|
2022-03-30 09:31:56 +00:00
|
|
|
|
type = with types; nullOr ints.positive;
|
|
|
|
|
default = null;
|
|
|
|
|
};
|
|
|
|
|
maximumAllocationMB = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "The maximum physical memory any container can be allocated.";
|
2022-03-30 09:31:56 +00:00
|
|
|
|
type = with types; nullOr ints.positive;
|
|
|
|
|
default = null;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useCGroups = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2022-03-30 09:31:56 +00:00
|
|
|
|
Use cgroups to enforce resource limits on containers
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
localDir = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "List of directories to store localized files in.";
|
2022-03-30 09:31:56 +00:00
|
|
|
|
type = with types; nullOr (listOf path);
|
|
|
|
|
example = [ "/var/lib/hadoop/yarn/nm" ];
|
|
|
|
|
default = null;
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-28 06:52:43 +00:00
|
|
|
|
addBinBash = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2021-10-28 06:52:43 +00:00
|
|
|
|
Add /bin/bash. This is needed by the linux container executor's launch script.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
openFirewall = mkOption {
|
|
|
|
|
type = types.bool;
|
2022-03-30 09:31:56 +00:00
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2021-10-28 06:52:43 +00:00
|
|
|
|
Open firewall ports for nodemanager.
|
|
|
|
|
Because containers can listen on any ephemeral port, TCP ports 1024–65535 will be opened.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = mkMerge [
|
2022-03-30 09:31:56 +00:00
|
|
|
|
(mkIf cfg.gatewayRole.enable {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
users.users.yarn = {
|
|
|
|
|
description = "Hadoop YARN user";
|
|
|
|
|
group = "hadoop";
|
|
|
|
|
uid = config.ids.uids.yarn;
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
|
(mkIf cfg.yarn.resourcemanager.enable {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
systemd.services.yarn-resourcemanager = {
|
|
|
|
|
description = "Hadoop YARN ResourceManager";
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-10-28 06:52:43 +00:00
|
|
|
|
inherit (cfg.yarn.resourcemanager) restartIfChanged;
|
2022-03-30 09:31:56 +00:00
|
|
|
|
environment = cfg.yarn.resourcemanager.extraEnv;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
User = "yarn";
|
|
|
|
|
SyslogIdentifier = "yarn-resourcemanager";
|
|
|
|
|
ExecStart = "${cfg.package}/bin/yarn --config ${hadoopConf} " +
|
2022-03-30 09:31:56 +00:00
|
|
|
|
" resourcemanager ${escapeShellArgs cfg.yarn.resourcemanager.extraFlags}";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
Restart = "always";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
2022-03-30 09:31:56 +00:00
|
|
|
|
|
|
|
|
|
services.hadoop.gatewayRole.enable = true;
|
|
|
|
|
|
2021-10-28 06:52:43 +00:00
|
|
|
|
networking.firewall.allowedTCPPorts = (mkIf cfg.yarn.resourcemanager.openFirewall [
|
|
|
|
|
8088 # resourcemanager.webapp.address
|
|
|
|
|
8030 # resourcemanager.scheduler.address
|
|
|
|
|
8031 # resourcemanager.resource-tracker.address
|
|
|
|
|
8032 # resourcemanager.address
|
2021-12-06 16:07:01 +00:00
|
|
|
|
8033 # resourcemanager.admin.address
|
2021-10-28 06:52:43 +00:00
|
|
|
|
]);
|
2020-04-24 23:36:52 +00:00
|
|
|
|
})
|
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
|
(mkIf cfg.yarn.nodemanager.enable {
|
2021-10-28 06:52:43 +00:00
|
|
|
|
# Needed because yarn hardcodes /bin/bash in container start scripts
|
|
|
|
|
# These scripts can't be patched, they are generated at runtime
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
|
(mkIf cfg.yarn.nodemanager.addBinBash "L /bin/bash - - - - /run/current-system/sw/bin/bash")
|
|
|
|
|
];
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
systemd.services.yarn-nodemanager = {
|
|
|
|
|
description = "Hadoop YARN NodeManager";
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-10-28 06:52:43 +00:00
|
|
|
|
inherit (cfg.yarn.nodemanager) restartIfChanged;
|
2022-03-30 09:31:56 +00:00
|
|
|
|
environment = cfg.yarn.nodemanager.extraEnv;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2021-10-28 06:52:43 +00:00
|
|
|
|
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-03-30 09:31:56 +00:00
|
|
|
|
umount /run/wrappers/yarn-nodemanager/cgroup/cpu || true
|
2021-10-28 06:52:43 +00:00
|
|
|
|
rm -rf /run/wrappers/yarn-nodemanager/ || true
|
2022-03-30 09:31:56 +00:00
|
|
|
|
mkdir -p /run/wrappers/yarn-nodemanager/{bin,etc/hadoop,cgroup/cpu}
|
2021-10-28 06:52:43 +00:00
|
|
|
|
cp ${cfg.package}/lib/${cfg.package.untarDir}/bin/container-executor /run/wrappers/yarn-nodemanager/bin/
|
|
|
|
|
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/
|
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
User = "yarn";
|
|
|
|
|
SyslogIdentifier = "yarn-nodemanager";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
PermissionsStartOnly = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
ExecStart = "${cfg.package}/bin/yarn --config ${hadoopConf} " +
|
2022-03-30 09:31:56 +00:00
|
|
|
|
" nodemanager ${escapeShellArgs cfg.yarn.nodemanager.extraFlags}";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
Restart = "always";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
2021-10-28 06:52:43 +00:00
|
|
|
|
|
2022-03-30 09:31:56 +00:00
|
|
|
|
services.hadoop.gatewayRole.enable = true;
|
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
|
services.hadoop.yarnSiteInternal = with cfg.yarn.nodemanager; mkMerge [ ({
|
|
|
|
|
"yarn.nodemanager.local-dirs" = mkIf (localDir!= null) (concatStringsSep "," localDir);
|
2022-03-30 09:31:56 +00:00
|
|
|
|
"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-08-12 12:06:08 +00:00
|
|
|
|
}) (mkIf useCGroups {
|
2022-03-30 09:31:56 +00:00
|
|
|
|
"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-08-12 12:06:08 +00:00
|
|
|
|
})];
|
2022-03-30 09:31:56 +00:00
|
|
|
|
|
2021-10-28 06:52:43 +00:00
|
|
|
|
networking.firewall.allowedTCPPortRanges = [
|
|
|
|
|
(mkIf (cfg.yarn.nodemanager.openFirewall) {from = 1024; to = 65535;})
|
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
];
|
|
|
|
|
}
|