module ContainedMr::TemplateLogic
Logic shared by {ContainedMr::Template} and {ContainedMr::Mock::Template}.
Attributes
@return {String} the template’s unique identifier
@return {String} image_id
the unique ID of the Docker image used as a base
for images built by jobs derived from this template
@return {Number} the number of mapper jobs specified by this template
@return {String} prepended to Docker objects, for identification purposes
Public Instance Methods
@return {String} tag applied to the template’s base Docker image
# File lib/contained_mr/template_logic.rb, line 40 def image_tag "#{@name_prefix}/base.#{@id}" end
Computes the Dockerfile used to build a job’s mapper image.
@return {String} the Dockerfile
# File lib/contained_mr/template_logic.rb, line 28 def mapper_dockerfile job_dockerfile @_definition['mapper'] || {}, 'input' end
Computes the environment variables to be set in a mapper container.
@param {Number} i the mapper number @return {Array<String>} environment variables to be set in the mapper
# File lib/contained_mr/template_logic.rb, line 48 def mapper_env(i) [ "ITEM=#{i}", "ITEMS=#{@item_count.to_s}" ] end
@return {String} the map output’s path in the mapper Docker container
# File lib/contained_mr/template_logic.rb, line 60 def mapper_output_path (@_definition['mapper'] || {})['output'] || '/output' end
Creates a job using this template.
@param {String} id the job’s unique ID @param {Hash<String, Object>} json_options job options, extracted from JSON @return {ContainedMr::Job} a newly created job that uses this template
# File lib/contained_mr/template_logic.rb, line 21 def new_job(id, json_options) job_class.new self, id, json_options end
Computes the Dockerfile used to build a job’s reducer image.
@return {String} the Dockerfile
# File lib/contained_mr/template_logic.rb, line 35 def reducer_dockerfile job_dockerfile @_definition['reducer'] || {}, '.' end
Computes the environment variables to be set in the reducer container.
@return {Array<String>} environment variables to be set in the mapper
# File lib/contained_mr/template_logic.rb, line 55 def reducer_env [ "ITEMS=#{@item_count.to_s}" ] end
@return {String} the reducer output’s path in the reducer Docker container
# File lib/contained_mr/template_logic.rb, line 65 def reducer_output_path (@_definition['reducer'] || {})['output'] || '/output' end
Private Instance Methods
@private common code from mapper_dockerfile
and reducer_dockerfile
# File lib/contained_mr/template_logic.rb, line 70 def job_dockerfile(job_definition, input_source) <<DOCKER_END FROM #{image_tag} ARG affinity:image= COPY #{input_source} #{job_definition['input'] || '/input'} WORKDIR #{job_definition['chdir'] || '/'} ENTRYPOINT #{JSON.dump(job_definition['cmd'] || ['/bin/sh'])} DOCKER_END end
Reads the template’s definition, using data at the given path.
@param {IO} yaml_io IO implementation that produces the .yaml file
containing the definition
# File lib/contained_mr/template_logic.rb, line 85 def read_definition(yaml_io) @_definition = YAML.load yaml_io.read @_definition.freeze @item_count = @_definition['items'] || 1 end