<?xml version="1.0"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->
<configuration>

<!-- Site specific YARN configuration properties -->
    <property>
        <name>this.resourcemanager.fqdn</name>
        <value><%= node['hadoop']['this.resourcemanager.fqdn'] %></value>
        <!-- <value>${this.cluster.name}-rm.${this.domain}</value> -->
    </property>

    <property>
        <name>yarn.log-aggregation-enable</name>
        <value><%= node['hadoop']['yarn.log-aggregation-enable'] %></value>
    </property>
    <property>
        <name>yarn.resourcemanager.scheduler.class</name>
        <value><%= node['hadoop']['yarn.resourcemanager.scheduler.class'] %></value>
        <description>In case you do not want to use the default scheduler</description>
    </property>
<%
yarn_nodemanager_local_dirs = ''
@active_vol_nums.to_i.times {|vol_num|
  yarn_nodemanager_local_dirs = yarn_nodemanager_local_dirs == '' ? '' : "#{yarn_nodemanager_local_dirs},"
  yarn_nodemanager_local_dirs = "#{yarn_nodemanager_local_dirs}#{node['grid']['vol_root']}/#{vol_num}/var/lib/${user.name}/nm/local"
}
-%>
    <property>
        <name>yarn.nodemanager.local-dirs</name>
        <value><%= yarn_nodemanager_local_dirs %></value>
        <!-- <value>/grid/vol/0/var/lib/${user.name}/nm/local,/grid/vol/1/var/lib/${user.name}/nm/local</value> -->
        <description>the local directories used by the nodemanager
        (default: /tmp/nm-local-dir)</description>
    </property>
    <property>
        <name>yarn.nodemanager.resource.memory-mb</name>
        <value><%= node['hadoop']['yarn.nodemanager.resource.memory-mb'] %></value>
        <description>Amount of physical memory, in MB, that can be allocated
        for containers. (default: 8192)</description>
    </property>
    <property>
        <name>yarn.nodemanager.resource.cpu-cores</name>
        <value><%= node['hadoop']['yarn.nodemanager.resource.cpu-cores'] %></value>
        <description>Number of CPU cores that can be allocated
        for containers. (default: 8)</description>
    </property>
    <property>
        <name>yarn.nodemanager.remote-app-log-dir</name>
        <value><%= node['hadoop']['yarn.nodemanager.remote-app-log-dir'] %></value>
        <description>directory on hdfs where the application logs are moved to
        (default: /tmp/logs)</description>
    </property>
<%
yarn_nodemanager_log_dirs = ''
@active_vol_nums.to_i.times {|vol_num|
  yarn_nodemanager_log_dirs = yarn_nodemanager_log_dirs == '' ? '' : "#{yarn_nodemanager_log_dirs},"
  yarn_nodemanager_log_dirs = "#{yarn_nodemanager_log_dirs}#{node['grid']['vol_root']}/#{vol_num}/var/log/${user.name}/nm"
}
-%>
    <property>
        <name>yarn.nodemanager.log-dirs</name>
        <value><%= yarn_nodemanager_log_dirs %></value>
        <!-- <value>/grid/vol/0/var/log/${user.name}/nm,/grid/vol/1/var/log/${user.name}/nm</value> -->
        <description>the directories used by Nodemanagers as log directories
        (default: /tmp/logs)</description>
    </property>
    <property>
        <name>yarn.nodemanager.aux-services</name>
        <value><%= node['hadoop']['yarn.nodemanager.aux-services'] %></value>
        <description>shuffle service that needs to be set for Map Reduce to run</description>
    </property>
    <property>
        <name>yarn.application.classpath</name>
        <value><%= node['hadoop']['yarn.application.classpath'] %></value>
        <description>Classpath for typical applications.</description>
    </property>

    <property>
        <name>yarn.resourcemanager.nodes.include-path</name>
        <value><%= node['hadoop']['yarn.resourcemanager.nodes.include-path'] %></value>
        <description>Path to file with nodes to include.</description>
    </property>
    <property>
        <name>yarn.resourcemanager.nodes.exclude-path</name>
        <value><%= node['hadoop']['yarn.resourcemanager.nodes.exclude-path'] %></value>
        <description>Path to file with nodes to exclude.</description>
    </property>

    <property>
        <name>yarn.nodemanager.admin-env</name>
        <value><%= node['hadoop']['yarn.nodemanager.admin-env'] %></value>
    </property>

<% if node['hadoop']['with_security'] then -%>
    <property>
        <name>yarn.acl.enable</name>
        <value><%= node['hadoop']['yarn.acl.enable'] %></value>
    </property>
    <property>
        <name>yarn.admin.acl</name>
        <value><%= node['hadoop']['yarn.admin.acl'] %></value>
    </property>
    <property>
        <name>yarn.resourcemanager.principal</name>
        <value><%= node['hadoop']['yarn.resourcemanager.principal'] %></value>
        <!-- <value>yarn/_HOST@${this.realm}</value> -->
    </property>
    <property>
        <name>yarn.resourcemanager.keytab</name>
        <value><%= node['hadoop']['yarn.resourcemanager.keytab'] %></value>
    </property>
    <property>
        <name>yarn.nodemanager.principal</name>
        <value><%= node['hadoop']['yarn.nodemanager.principal'] %></value>
        <!-- <value>yarn/_HOST@${this.realm}</value> -->
    </property>
    <property>
        <name>yarn.nodemanager.keytab</name>
        <value><%= node['hadoop']['yarn.nodemanager.keytab'] %></value>
    </property>

    <property>
        <name>yarn.nodemanager.container-executor.class</name>
        <value><%= node['hadoop']['yarn.nodemanager.container-executor.class'] %></value>
    </property>
    <property>
        <name>yarn.nodemanager.linux-container-executor.group</name>
        <value><%= node['hadoop']['yarn.nodemanager.linux-container-executor.group'] %></value>
    </property>
    <property>
        <name>yarn.nodemanager.linux-container-executor.resources-handler.class</name>
        <value><%= node['hadoop']['yarn.nodemanager.linux-container-executor.resources-handler.class'] %></value>
        <description>The class which should help the LCE handle resources.</description>
    </property>
    <property>
        <name>yarn.nodemanager.linux-container-executor.cgroups.hierarchy</name>
        <value><%= node['hadoop']['yarn.nodemanager.linux-container-executor.cgroups.hierarchy'] %></value>
        <description>The cgroups hierarchy under which to place YARN proccesses (cannot contain commas).
        If yarn.nodemanager.linux-container-executor.cgroups.mount is false (that is, if cgroups have
        been pre-configured), then this cgroups hierarchy must already exist and be writable by the
        NodeManager user, otherwise the NodeManager may fail.
        Only used when the LCE resources handler is set to the CgroupsLCEResourcesHandler.</description>
    </property>
    <property>
        <name>yarn.nodemanager.linux-container-executor.cgroups.mount</name>
        <value><%= node['hadoop']['yarn.nodemanager.linux-container-executor.cgroups.mount'] %></value>
        <description>Whether the LCE should attempt to mount cgroups if not found.
        Only used when the LCE resources handler is set to the CgroupsLCEResourcesHandler.</description>
    </property>
    <property>
        <name>yarn.nodemanager.linux-container-executor.cgroups.mount-path</name>
        <value><%= node['hadoop']['yarn.nodemanager.linux-container-executor.cgroups.mount-path'] %></value>
        <description>Where the LCE should attempt to mount cgroups if not found. Common locations
        include /sys/fs/cgroup and /cgroup; the default location can vary depending on the Linux
        distribution in use. This path must exist before the NodeManager is launched.
        Only used when the LCE resources handler is set to the CgroupsLCEResourcesHandler, and
        yarn.nodemanager.linux-container-executor.cgroups.mount is true.</description>
    </property>

    <property>
        <name>yarn.resourcemanager.webapp.spnego-principal</name>
        <value><%= node['hadoop']['yarn.resourcemanager.webapp.spnego-principal'] %></value>
        <!-- <value>HTTP/_HOST@${this.realm}</value> -->
    </property>
    <property>
        <name>yarn.resourcemanager.webapp.spnego-keytab-file</name>
        <value><%= node['hadoop']['yarn.resourcemanager.webapp.spnego-keytab-file'] %></value>
    </property>
    <property>
        <name>yarn.nodemanager.webapp.spnego-principal</name>
        <value><%= node['hadoop']['yarn.nodemanager.webapp.spnego-principal'] %></value>
        <!-- <value>HTTP/_HOST@${this.realm}</value> -->
    </property>
    <property>
        <name>yarn.nodemanager.webapp.spnego-keytab-file</name>
        <value><%= node['hadoop']['yarn.nodemanager.webapp.spnego-keytab-file'] %></value>
    </property>
<% end -%>
<%
this_file = 'mapred-site.xml'
if defined? node['hadoop']['extra_configs'][this_file] \
  && node['hadoop']['extra_configs'][this_file] != nil then
  node['hadoop']['extra_configs'][this_file].each do |key,value|
-%>
    <property>
        <name><%= key %></name>
        <value><%= value %></value>
    </property>
<%
  end
end 
-%>
</configuration>
