<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  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.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
    <property>
        <name>this.jobhistory.fqdn</name>
        <value><%= node['hadoop']['this.jobhistory.fqdn'] %></value>
        <!-- <value>${this.cluster.name}-jt.${this.domain}</value> -->
        <!-- <value>${this.cluster.name}-jh.${this.domain}</value> -->
    </property>

<%
install_flavor = node['hadoop']['install_flavor']
if install_flavor == 'apache' \
  || install_flavor == 'hdp' \
  || (install_flavor == 'cdh' && node['hadoop']['cdh']['resource_negotiator_framework'] == 'YARN') then
-%>
    <property>
        <name>mapreduce.framework.name</name>
        <value><%= node['hadoop']['mapreduce.framework.name'] %></value>
        <description>The runtime framework for executing MapReduce jobs.
        Can be one of local, classic or yarn.
        (default: local)
        </description>
    </property>
    <property>
        <name>yarn.app.mapreduce.am.staging-dir</name>
        <value><%= node['hadoop']['yarn.app.mapreduce.am.staging-dir'] %></value>
    </property>
    <property>
        <name>mapreduce.jobhistory.intermediate-done-dir</name>
        <value><%= node['hadoop']['mapreduce.jobhistory.intermediate-done-dir'] %></value>
        <!-- NG: <value>/user</value> -->
    </property>
    <property>
        <name>mapreduce.jobhistory.done-dir</name>
        <value><%= node['hadoop']['mapreduce.jobhistory.done-dir'] %></value>
    </property>

<%
mapred_local_dir = ''
@active_vol_nums.to_i.times {|vol_num|
  mapred_local_dir = mapred_local_dir == '' ? '' : "#{mapred_local_dir},"
  mapred_local_dir = "#{mapred_local_dir}#{node['grid']['vol_root']}/#{vol_num}/var/lib/mapred/local"
}
-%>
    <!-- NOT necessary.
    <property>
        <name>mapreduce.cluster.local.dir</name>
        <value><%= mapred_local_dir %></value>
        <description>
          The local directory where MapReduce stores intermediate data files.
          May be a comma-separated list of directories on different devices in order to spread disk i/o.
          Directories that do not exist are ignored.
        </description>
    </property>
    -->
<%
mapred_temp_dir = ''
@active_vol_nums.to_i.times {|vol_num|
  mapred_temp_dir = mapred_temp_dir == '' ? '' : "#{mapred_temp_dir},"
  mapred_temp_dir = "#{mapred_temp_dir}#{node['grid']['vol_root']}/#{vol_num}/tmp/mapred"
}
-%>
    <!-- NOT necessary.
    <property>
        <name>mapreduce.cluster.temp.dir</name>
        <value><%= mapred_temp_dir %></value>
        <description>
          A shared directory for temporary files.
        </description>
    </property>
    -->

  <% if node['hadoop']['with_security'] then -%>
    <property>
        <name>mapreduce.jobhistory.principal</name>
        <value><%= node['hadoop']['mapreduce.jobhistory.principal'] %></value>
        <!-- <value>mapred/_HOST@${this.realm}</value> -->
    </property>
    <property>
        <name>mapreduce.jobhistory.keytab</name>
        <value><%= node['hadoop']['mapreduce.jobhistory.keytab'] %></value>
    </property>

    <property>
        <name>mapreduce.jobhistory.webapp.spnego-principal</name>
        <value><%= node['hadoop']['mapreduce.jobhistory.webapp.spnego-principal'] %></value>
        <!-- <value>HTTP/_HOST@${this.realm}</value> -->
    </property>
    <property>
        <name>mapreduce.jobhistory.webapp.spnego-keytab-file</name>
        <value><%= node['hadoop']['mapreduce.jobhistory.webapp.spnego-keytab-file'] %></value>
    </property>
  <% end -%>
<%
elsif install_flavor == 'cdh' \
  && node['hadoop']['cdh']['resource_negotiator_framework'] == 'MRv1' then
-%>
    <!-- CDH4 MRv1 -->
    <property>
        <name>this.jobtracker.fqdn</name>
        <value><%= node['hadoop']['this.jobtracker.fqdn'] %></value>
        <!-- <value>${this.cluster.name}-jt.${this.domain}</value> -->
    </property>

    <property>
        <name>mapred.job.tracker</name>
        <value><%= node['hadoop']['mapred.job.tracker'] %></value>
    </property>
    <property>
        <name>mapred.system.dir</name>
        <value><%= node['hadoop']['mapred.system.dir'] %></value>
    </property>
    <property>
        <name>mapreduce.jobtracker.staging.root.dir</name>
        <value><%= node['hadoop']['mapreduce.jobtracker.staging.root.dir'] %></value>
    </property>

    <property>
        <name>mapred.job.tracker.persist.jobstatus.active</name>
        <value><%= node['hadoop']['mapred.job.tracker.persist.jobstatus.active'] %></value>
        <description>Indicates if persistency of job status information is
          active or not. (default: false)
        </description>
    </property>
    <property>
        <name>mapred.job.tracker.persist.jobstatus.hours</name>
        <value><%= node['hadoop']['mapred.job.tracker.persist.jobstatus.hours'] %></value>
        <description>The number of hours job status information is persisted in DFS.
          The job status information will be available after it drops of the memory
          queue and between jobtracker restarts. With a zero value the job status
          information is not persisted at all in DFS. (default: 0)
        </description>
    </property>
    <property>
        <name>mapred.job.tracker.persist.jobstatus.dir</name>
        <value><%= node['hadoop']['mapred.job.tracker.persist.jobstatus.dir'] %></value>
        <description>The directory where the job status information is persisted
          in a file system to be available after it drops of the memory queue and
          between jobtracker restarts. (default: /jobtracker/jobsInfo)
        </description>
    </property>

    <property>
        <name>hadoop.job.history.location</name>
        <value><%= node['hadoop']['hadoop.job.history.location'] %></value>
        <description>hdfs:// is UNusable.</description>
    </property>
    <property>
        <name>mapred.job.tracker.history.completed.location</name>
        <value><%= node['hadoop']['mapred.job.tracker.history.completed.location'] %></value>
    </property>

<%
mapred_local_dir = ''
@active_vol_nums.to_i.times {|vol_num|
  mapred_local_dir = mapred_local_dir == '' ? '' : "#{mapred_local_dir},"
  # CDH3: ${user.name} is N/A!
  mapred_local_dir = "#{mapred_local_dir}#{node['grid']['vol_root']}/#{vol_num}/var/lib/mapred/local"
}
-%>
    <property>
        <name>mapred.local.dir</name>
        <value><%= mapred_local_dir %></value>
        <!-- <value><%= node['grid']['vol_root'] %>/0/var/lib/mapred/local,<%= node['grid']['vol_root'] %>/1/var/lib/mapred/local</value> -->
        <description>
          The local directory where MapReduce stores intermediate data files.
          May be a comma-separated list of directories on different devices in order to spread disk i/o.
          Directories that do not exist are ignored.
        </description>
    </property>
<%
mapred_temp_dir = ''
@active_vol_nums.to_i.times {|vol_num|
  mapred_temp_dir = mapred_temp_dir == '' ? '' : "#{mapred_temp_dir},"
  # CDH3: ${user.name} is N/A!
  if node['hadoop']['install_flavor'] == 'cdh' then
    mapred_temp_dir = "#{mapred_temp_dir}#{node['grid']['vol_root']}/#{vol_num}/tmp/mapred/temp"
  else
    mapred_temp_dir = "#{mapred_temp_dir}#{node['grid']['vol_root']}/#{vol_num}/tmp/${user.name}/temp"
  end
}
-%>
    <property>
        <name>mapred.temp.dir</name>
        <value><%= mapred_temp_dir %></value>
        <!-- <value><%= node['grid']['vol_root'] %>/0/tmp/${user.name}/temp,<%= node['grid']['vol_root'] %>/1/tmp/${user.name}/temp</value> -->
        <description>
          A shared directory for temporary files.
        </description>
    </property>

    <property>
        <name>mapred.hosts</name>
        <value><%= node['hadoop']['mapred.hosts'] %></value>
        <description>
          Names a file that contains the list of nodes that may connect to the jobtracker.
          If the value is empty, all hosts are permitted.
        </description>
    </property>
    <property>
        <name>mapred.hosts.exclude</name>
        <value><%= node['hadoop']['mapred.hosts.exclude'] %></value>
        <description>
          Names a file that contains the list of hosts that should be excluded by the jobtracker.
          If the value is empty, no hosts are excluded.
        </description>
    </property>

    <property>
        <name>mapred.jobtracker.taskScheduler</name>
        <value><%= node['hadoop']['mapred.jobtracker.taskScheduler'] %></value>
    </property>

  <% if node['hadoop']['with_security'] then -%>
    <property>
        <name>mapred.acls.enabled</name>
        <value><%= node['hadoop']['mapred.acls.enabled'] %></value>
    </property>
    <property>
        <name>mapreduce.cluster.administrators</name>
        <value><%= node['hadoop']['mapreduce.cluster.administrators'] %></value>
    </property>
    <property>
        <name>mapreduce.jobtracker.kerberos.principal</name>
        <value><%= node['hadoop']['mapreduce.jobtracker.kerberos.principal'] %></value>
        <!-- _HOST is replaced with the mapred.job.tracker's host name -->
        <!-- <value>mapred/${this.jobtracker.fqdn}@${this.realm}</value> -->
    </property>
    <property>
        <name>mapreduce.jobtracker.keytab.file</name>
        <value><%= node['hadoop']['mapreduce.jobtracker.keytab.file'] %></value>
    </property>
    <property>
        <name>mapreduce.tasktracker.kerberos.principal</name>
        <value><%= node['hadoop']['mapreduce.tasktracker.kerberos.principal'] %></value>
        <!-- <value>mapred/_HOST@${this.realm}</value> -->
    </property>
    <property>
        <name>mapreduce.tasktracker.keytab.file</name>
        <value><%= node['hadoop']['mapreduce.tasktracker.keytab.file'] %></value>
    </property>

    <property>
        <name>mapred.task.tracker.task-controller</name>
        <value><%= node['hadoop']['mapred.task.tracker.task-controller'] %></value>
    </property>
    <property>
        <name>mapreduce.tasktracker.group</name>
        <value><%= node['hadoop']['mapreduce.tasktracker.group'] %></value>
    </property>

    <!-- separated job history server is N/A on the MRv1 of the CDH4.
    <property>
        <name>mapreduce.history.server.embedded</name>
        <value><%= node['hadoop']['mapreduce.history.server.embedded'] %></value>
    </property>
    <property>
        <name>mapreduce.history.server.http.address</name>
        <value><%= node['hadoop']['mapreduce.history.server.http.address'] %></value>
    </property>
    <property>
        <name>mapreduce.jobhistory.kerberos.principal</name>
        <value><%= node['hadoop']['mapreduce.jobhistory.kerberos.principal'] %></value>
    </property>
    <property>
        <name>mapreduce.jobhistory.keytab.file</name>
        <value><%= node['hadoop']['mapreduce.jobhistory.keytab.file'] %></value>
    </property>
    -->
  <% end -%>
<% 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>
