Class: ContainedMr::Mock::Job

Inherits:
Object
  • Object
show all
Includes:
JobLogic
Defined in:
lib/contained_mr/mock/job.rb

Overview

See Also:

  • {ContainedMr{ContainedMr::Job}

Instance Attribute Summary collapse

Attributes included from JobLogic

#mapper_image_id, #reducer_image_id

Instance Method Summary collapse

Methods included from JobLogic

#mapper_container_options, #mapper_image_options, #mapper_image_tag, #mapper_runner, #reducer_container_options, #reducer_image_options, #reducer_image_tag, #reducer_runner

Constructor Details

#initialize(template, id, json_options) ⇒ Job

Returns a new instance of Job.

See Also:

  • ContainedMr::Mock::Job.{ContainedMr{ContainedMr::Job{ContainedMr::Job#initialize}


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/contained_mr/mock/job.rb', line 20

def initialize(template, id, json_options)
  @template = template
  @id = id
  @name_prefix = template.name_prefix
  @item_count = template.item_count

  @mapper_image_id = nil
  @reducer_image_id = nil

  @mappers = Array.new @item_count
  @reducer = nil
  @mapper_options = nil
  @reducer_options = nil
  @_mapper_input = nil

  @destroyed = false
  @_json_options = json_options
  parse_options json_options

  @mock_mappers = (1..@item_count).map do |i|
    ContainedMr::Mock::Runner.new mapper_container_options(i),
      @mapper_options[:wait_time], @template.mapper_output_path
  end
  @mock_reducer = ContainedMr::Mock::Runner.new reducer_container_options,
      @reducer_options[:wait_time], @template.reducer_output_path
end

Instance Attribute Details

#_json_optionsHash (readonly)

Returns the options provided to the Job constructor.

Returns:

  • (Hash)

    the options provided to the Job constructor



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

def _json_options
  @_json_options
end

#_mapper_inputString (readonly)

Returns the input data provided to #build_mapper_image.

Returns:



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

def _mapper_input
  @_mapper_input
end

#idObject (readonly)

See Also:

  • ContainedMr::Mock::Job.{ContainedMr{ContainedMr::Job}


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

def id
  @id
end

#item_countObject (readonly)

See Also:

  • ContainedMr::Mock::Job.{ContainedMr{ContainedMr::Job}


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

def item_count
  @item_count
end

#name_prefixObject (readonly)

See Also:

  • ContainedMr::Mock::Job.{ContainedMr{ContainedMr::Job}


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

def name_prefix
  @name_prefix
end

#templateObject (readonly)

See Also:

  • ContainedMr::Mock::Job.{ContainedMr{ContainedMr::Job}


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

def template
  @template
end

Instance Method Details

#_mock_mapper_runner(i) ⇒ ContainedMr::Mock::Runner

Returns the mock pretending to be the runner used for a mapper.

Parameters:

  • i (Number)

    the mapper number

Returns:



96
97
98
99
100
101
# File 'lib/contained_mr/mock/job.rb', line 96

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

#_mock_reducer_runnerContainedMr::Mock::Runner

Returns the mock pretending to be the runner used for the reducer.

Returns:



108
109
110
# File 'lib/contained_mr/mock/job.rb', line 108

def _mock_reducer_runner
  @mock_reducer
end

#build_mapper_image(mapper_input) ⇒ Object

See Also:

  • ContainedMr::Mock::Job.{ContainedMr{ContainedMr::Job{ContainedMr::Job#build_mapper_image}


54
55
56
57
58
59
60
# File 'lib/contained_mr/mock/job.rb', line 54

def build_mapper_image(mapper_input)
  unless @mapper_image_id.nil?
    raise RuntimeError, 'Mapper image already exists'
  end
  @_mapper_input = mapper_input
  @mapper_image_id = 'mock-job-mapper-image-id'
end

#build_reducer_imageObject

See Also:

  • ContainedMr::Mock::Job.{ContainedMr{ContainedMr::Job{ContainedMr::Job#build_reducer_image}


63
64
65
66
67
68
69
70
71
# File 'lib/contained_mr/mock/job.rb', line 63

def build_reducer_image
  unless @reducer_image_id.nil?
    raise RuntimeError, 'Reducer image already exists'
  end
  1.upto @item_count do |i|
    raise RuntimeError, 'Not all mappers ran' if mapper_runner(i).nil?
  end
  @reducer_image_id = 'mock-job-reducer-image-id'
end

#destroy!Object

See Also:

  • ContainedMr::Mock::Job.{ContainedMr{ContainedMr::Job{ContainedMr::Job#destroy}


48
49
50
51
# File 'lib/contained_mr/mock/job.rb', line 48

def destroy!
  @destroyed = true
  self
end

#destroyed?Boolean

Returns true if #destroy! was called.

Returns:



15
16
17
# File 'lib/contained_mr/mock/job.rb', line 15

def destroyed?
  @destroyed
end

#run_mapper(i) ⇒ Object

Raises:

  • (RuntimeError)

See Also:

  • ContainedMr::Mock::Job.{ContainedMr{ContainedMr::Job{ContainedMr::Job#run_mapper}


74
75
76
77
78
79
80
# File 'lib/contained_mr/mock/job.rb', line 74

def run_mapper(i)
  if i < 1 || i > @item_count
    raise ArgumentError, "Invalid mapper number #{i}"
  end
  raise RuntimeError, 'Mapper image does not exist' if @mapper_image_id.nil?
  @mappers[i - 1] = @mock_mappers[i - 1]
end

#run_reducerObject

See Also:

  • ContainedMr::Mock::Job.{ContainedMr{ContainedMr::Job{ContainedMr::Job#run_reducer}


83
84
85
86
87
88
# File 'lib/contained_mr/mock/job.rb', line 83

def run_reducer
  if @reducer_image_id.nil?
    raise RuntimeError, 'Reducer image does not exist'
  end
  @reducer = @mock_reducer
end