Module: ContainedMr::JobLogic

Included in:
Job, Mock::Job
Defined in:
lib/contained_mr/job_logic.rb

Overview

Logic shared by Job and Mock::Job.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idString (readonly)

Returns the job’s unique identifier.

Returns:

  • (String)

    the job’s unique identifier



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

def id
  @id
end

#item_countNumber (readonly)

Returns the number of mapper jobs that will be run.

Returns:

  • (Number)

    the number of mapper jobs that will be run



13
14
15
# File 'lib/contained_mr/job_logic.rb', line 13

def item_count
  @item_count
end

#mapper_image_idString (readonly)

Returns the unique ID of the Docker image used to run the mappers.

Returns:

  • (String)

    the unique ID of the Docker image used to run the mappers



16
17
18
# File 'lib/contained_mr/job_logic.rb', line 16

def mapper_image_id
  @mapper_image_id
end

#name_prefixString (readonly)

Returns prepended to Docker objects, for identification purposes.

Returns:

  • (String)

    prepended to Docker objects, for identification purposes



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

def name_prefix
  @name_prefix
end

#reducer_image_idString (readonly)

Returns the unique ID of the Docker image used to run the reducer.

Returns:

  • (String)

    the unique ID of the Docker image used to run the reducer



19
20
21
# File 'lib/contained_mr/job_logic.rb', line 19

def reducer_image_id
  @reducer_image_id
end

#templateContainedMr::Template (readonly)

Returns the template this job is derived from.

Returns:



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

def template
  @template
end

Instance Method Details

#mapper_container_options(i) ⇒ Hash<String, Object>

Returns params used to create a mapper container.

Returns:

  • (Hash<String, Object>)

    params used to create a mapper container



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/contained_mr/job_logic.rb', line 53

def mapper_container_options(i)
  ulimits = @mapper_options[:ulimits].map do |k, v|
    { "Name" => k.to_s, "Soft" => v, "Hard" => v }
  end

  env = @template.mapper_env i
  env.push "affinity:image==#{mapper_image_tag}"

  {
    'name' => "#{@name_prefix}_mapper.#{@id}.#{i}",
    'Image' => mapper_image_tag,
    'Hostname' => "#{i}.mapper", 'Domainname' => '',
    'Labels' => { 'contained_mr.ctl' => @name_prefix },
    'Env' => env, 'Ulimits' => ulimits,
    'NetworkDisabled' => true, 'ExposedPorts' => {},
    'HostConfig' => container_host_config(@mapper_options),
  }
end

#mapper_image_tagString

Returns tag applied to the Docker image used by the job’s mappers.

Returns:

  • (String)

    tag applied to the Docker image used by the job’s mappers



43
44
45
# File 'lib/contained_mr/job_logic.rb', line 43

def mapper_image_tag
  "#{@name_prefix}/mapper.#{@id}"
end

#mapper_runner(i) ⇒ ContainedMr::Runner

Returns the runner used for a mapper.

Parameters:

  • i (Number)

    the mapper number

Returns:

  • (ContainedMr::Runner)

    the runner used for the given mapper; nil if the given mapper was not started



26
27
28
29
30
31
# File 'lib/contained_mr/job_logic.rb', line 26

def mapper_runner(i)
  if i < 1 || i > @item_count
    raise ArgumentError, "Invalid mapper number #{i}"
  end
  @mappers[i - 1]
end

#reducer_container_optionsHash<String, Object>

Returns params used to create a reducer container.

Returns:

  • (Hash<String, Object>)

    params used to create a reducer container



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/contained_mr/job_logic.rb', line 73

def reducer_container_options
  ulimits = @reducer_options[:ulimits].map do |k, v|
    { "Name" => k.to_s, "Soft" => v, "Hard" => v }
  end

  env = @template.reducer_env
  env.push "affinity:image==#{reducer_image_tag}"

  {
    'name' => "#{@name_prefix}_reducer.#{@id}",
    'Image' => reducer_image_tag,
    'Hostname' => 'reducer', 'Domainname' => '',
    'Labels' => { 'contained_mr.ctl' => @name_prefix },
    'Env' => env, 'Ulimits' => ulimits,
    'NetworkDisabled' => true, 'ExposedPorts' => {},
    'HostConfig' => container_host_config(@reducer_options),
  }
end

#reducer_image_tagString

Returns tag applied to the Docker image used by the job’s reducers.

Returns:

  • (String)

    tag applied to the Docker image used by the job’s reducers



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

def reducer_image_tag
  "#{@name_prefix}/reducer.#{@id}"
end

#reducer_runnerContainedMr::Runner

Returns the runner used for the reducer.

Returns:



37
38
39
# File 'lib/contained_mr/job_logic.rb', line 37

def reducer_runner
  @reducer
end