Module: ContainedMr::TemplateLogic

Included in:
Mock::Template, Template
Defined in:
lib/contained_mr/template_logic.rb

Overview

Logic shared by Template and Mock::Template.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idString (readonly)

Returns the template’s unique identifier.

Returns:

  • (String)

    the template’s unique identifier



7
8
9
# File 'lib/contained_mr/template_logic.rb', line 7

def id
  @id
end

#image_idString (readonly)

Returns image_id the unique ID of the Docker image used as a base for images built by jobs derived from this template.

Returns:

  • (String)

    image_id the unique ID of the Docker image used as a base for images built by jobs derived from this template



14
15
16
# File 'lib/contained_mr/template_logic.rb', line 14

def image_id
  @image_id
end

#item_countNumber (readonly)

Returns the number of mapper jobs specified by this template.

Returns:

  • (Number)

    the number of mapper jobs specified by this template



10
11
12
# File 'lib/contained_mr/template_logic.rb', line 10

def item_count
  @item_count
end

#name_prefixString (readonly)

Returns prepended to Docker objects, for identification purposes.

Returns:

  • (String)

    prepended to Docker objects, for identification purposes



4
5
6
# File 'lib/contained_mr/template_logic.rb', line 4

def name_prefix
  @name_prefix
end

Instance Method Details

#image_tagString

Returns tag applied to the template’s base Docker image.

Returns:

  • (String)

    tag applied to the template’s base Docker image



40
41
42
# File 'lib/contained_mr/template_logic.rb', line 40

def image_tag
  "#{@name_prefix}/base.#{@id}"
end

#mapper_dockerfileString

Computes the Dockerfile used to build a job’s mapper image.

Returns:

  • (String)

    the Dockerfile



28
29
30
# File 'lib/contained_mr/template_logic.rb', line 28

def mapper_dockerfile
  job_dockerfile @_definition['mapper'] || {}, 'input'
end

#mapper_env(i) ⇒ Array<String>

Computes the environment variables to be set in a mapper container.

Parameters:

  • i (Number)

    the mapper number

Returns:

  • (Array<String>)

    environment variables to be set in the mapper



48
49
50
# File 'lib/contained_mr/template_logic.rb', line 48

def mapper_env(i)
  [ "ITEM=#{i}", "ITEMS=#{@item_count.to_s}" ]
end

#mapper_output_pathString

Returns the map output’s path in the mapper Docker container.

Returns:

  • (String)

    the map output’s path in the mapper Docker container



60
61
62
# File 'lib/contained_mr/template_logic.rb', line 60

def mapper_output_path
  (@_definition['mapper'] || {})['output'] || '/output'
end

#new_job(id, json_options) ⇒ ContainedMr::Job

Creates a job using this template.

Parameters:

  • id (String)

    the job’s unique ID

  • json_options (Hash<String, Object>)

    job options, extracted from JSON

Returns:



21
22
23
# File 'lib/contained_mr/template_logic.rb', line 21

def new_job(id, json_options)
  job_class.new self, id, json_options
end

#reducer_dockerfileString

Computes the Dockerfile used to build a job’s reducer image.

Returns:

  • (String)

    the Dockerfile



35
36
37
# File 'lib/contained_mr/template_logic.rb', line 35

def reducer_dockerfile
  job_dockerfile @_definition['reducer'] || {}, '.'
end

#reducer_envArray<String>

Computes the environment variables to be set in the reducer container.

Returns:

  • (Array<String>)

    environment variables to be set in the mapper



55
56
57
# File 'lib/contained_mr/template_logic.rb', line 55

def reducer_env
  [ "ITEMS=#{@item_count.to_s}" ]
end

#reducer_output_pathString

Returns the reducer output’s path in the reducer Docker container.

Returns:

  • (String)

    the reducer output’s path in the reducer Docker container



65
66
67
# File 'lib/contained_mr/template_logic.rb', line 65

def reducer_output_path
  (@_definition['reducer'] || {})['output'] || '/output'
end