Class: ContainedMr::Runner

Inherits:
Object
  • Object
show all
Includes:
RunnerLogic
Defined in:
lib/contained_mr/runner.rb

Overview

Handles running a single mapper or reducer.

Instance Attribute Summary

Attributes included from RunnerLogic

#container_id, #ended_at, #output, #started_at, #status_code, #stderr, #stdout, #timed_out

Instance Method Summary collapse

Methods included from RunnerLogic

#json_file, #ran_for

Constructor Details

#initialize(container_options, time_limit, output_path) ⇒ Runner

Initialize a runner.

Parameters:

  • container_options (Hash<String, Object>)

    docker container creation options, passed to Docker::Container.create without modification

  • time_limit (Number)

    maximum number of seconds that the runner’s container is allowed to execute before being terminated

  • output_path (String)

    the location of the file inside the container whose output will be saved



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/contained_mr/runner.rb', line 18

def initialize(container_options, time_limit, output_path)
  @_container_options = container_options
  @_time_limit = time_limit
  @_output_path = output_path

  @container_id = nil
  @started_at = @ended_at = nil
  @status_code = nil
  @timed_out = nil
  @stdout = @stderr = nil
  @output = nil
end

Instance Method Details

#destroy!(container = nil) ⇒ ContainedMr::Runner

Removes the container used to run a mapper / reducer.

Parameters:

  • container (Docker::Container) (defaults to: nil)

    the mapper / reducer’s container; if not supplied, an extra Docker API query is performed to obtain the container object

Returns:



50
51
52
53
54
55
56
57
# File 'lib/contained_mr/runner.rb', line 50

def destroy!(container = nil)
  unless @container_id.nil?
    container ||= Docker::Container.get @container_id
    container.delete force: true
    @container_id = nil
  end
  self
end

#performContainedMr::Runner

Performs a full mapper / reducer step.

Returns:



34
35
36
37
38
39
40
41
42
# File 'lib/contained_mr/runner.rb', line 34

def perform
  container = create
  @container_id = container.id

  execute container
  fetch_console_output container
  fetch_file_output container
  destroy! container
end