Class: MotherBrain::Upgrade::Worker

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Celluloid, MB::Mixin::AttributeSetting, MB::Mixin::Locks, MB::Mixin::Services, Logging
Defined in:
lib/mb/upgrade/worker.rb

Overview

Upgrades a plugin by pinning cookbook versions and default attributes (based on the plugin components’ version attributes).

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

add_argument_header, dev, filename, #log_exception, logger, #logger, reset, set_logger, setup

Constructor Details

#initialize(job, environment_name, plugin, options = {}) ⇒ Worker

Returns a new instance of Worker.

Parameters:

Options Hash (options):

  • component_versions (Hash)

    Hash of components and the versions to set them to

  • cookbook_versions (Hash)

    Hash of cookbooks and the versions to set them to

  • environment_attributes (Hash)

    any additional attributes to set on the environment

  • environment_attributes_file (String)

    any additional attributes to set on the environment via a json file

  • :force (Boolean)

    Force any locks to be overwritten



40
41
42
43
44
45
# File 'lib/mb/upgrade/worker.rb', line 40

def initialize(job, environment_name, plugin, options = {})
  @job              = job
  @environment_name = environment_name
  @plugin           = plugin
  @options          = options
end

Instance Attribute Details

#environment_nameString (readonly)

Returns:

  • (String)


15
16
17
# File 'lib/mb/upgrade/worker.rb', line 15

def environment_name
  @environment_name
end

#jobMotherBrain::Job (readonly)

Returns:



18
19
20
# File 'lib/mb/upgrade/worker.rb', line 18

def job
  @job
end

#optionsHash (readonly)

Returns:

  • (Hash)


21
22
23
# File 'lib/mb/upgrade/worker.rb', line 21

def options
  @options
end

#pluginMotherBrain::Plugin (readonly)

Returns:



24
25
26
# File 'lib/mb/upgrade/worker.rb', line 24

def plugin
  @plugin
end

Instance Method Details

#runObject

Raises:

  • (ComponentNotFound)

    if a component version is passed that does not have a corresponding component in the plugin

  • (ComponentNotVersioned)

    if a component version is passed that does not have a version attribute in the corresponding component

  • (EnvironmentNotFound)

    if the environment does not exist



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/mb/upgrade/worker.rb', line 54

def run
  job.set_status("Starting")
  job.report_running

  assert_environment_exists

  chef_synchronize(chef_environment: environment_name, force: options[:force], job: job) do
    if component_versions.any?
      job.set_status("Setting component versions")
      set_component_versions(environment_name, plugin, component_versions)
    end

    if cookbook_versions.any?
      job.set_status("Setting cookbook versions")
      set_cookbook_versions(environment_name, cookbook_versions)
    end

    if environment_attributes.any?
      job.set_status("Setting environment attributes")
      set_environment_attributes(environment_name, environment_attributes)
    end

    if environment_attributes_file
      job.set_status("Setting environment attributes from #{environment_attributes_file}")
      set_environment_attributes_from_file(environment_name, environment_attributes_file)
    end

    run_chef if nodes.any?
  end

  job.report_success
rescue => ex
  job.report_failure(ex)
ensure
  job.terminate if job && job.alive?
end