Class: Actions::ForemanAcd::DeployAllHosts

Inherits:
EntryAction
  • Object
show all
Defined in:
app/lib/actions/foreman_acd/deploy_all_hosts.rb

Overview

DeployAllHosts implements a Foreman Task EntryAction

Instance Method Summary collapse

Instance Method Details

#finalizeObject



35
36
# File 'app/lib/actions/foreman_acd/deploy_all_hosts.rb', line 35

def finalize
end

#humanized_nameObject



42
43
44
# File 'app/lib/actions/foreman_acd/deploy_all_hosts.rb', line 42

def humanized_name
  _('Deploy application instance hosts')
end

#plan(app_instance, safe_deploy) ⇒ Object



7
8
9
# File 'app/lib/actions/foreman_acd/deploy_all_hosts.rb', line 7

def plan(app_instance, safe_deploy)
  plan_self(:id => app_instance.id, :safe_deploy => safe_deploy)
end

#rescue_strategyObject



38
39
40
# File 'app/lib/actions/foreman_acd/deploy_all_hosts.rb', line 38

def rescue_strategy
  Dynflow::Action::Rescue::Fail
end

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/lib/actions/foreman_acd/deploy_all_hosts.rb', line 11

def run
  output[:status] = 'IN PROGRESS'
  app_instance = ::ForemanAcd::AppInstance.find(input.fetch(:id))
  safe_deploy = input.fetch(:safe_deploy)

  # Goal: all, safe_deploy or nothing
  begin
    if safe_deploy
      ::Foreman::Logging.logger('foreman_acd').info "Start to safe deploy hosts of the app #{app_instance}"
    else
      ::Foreman::Logging.logger('foreman_acd').info "Start to deploy all hosts of the app #{app_instance}"
    end
    app_deployer = ::ForemanAcd::AppDeployer.new(app_instance)
    output[:data] = app_deployer.deploy(safe_deploy)
    output[:status] = 'SUCCESS'
  rescue StandardError => e
    ::Foreman::Logging.logger('foreman_acd').error "Error while deploying hosts for application instance '#{app_instance.name}'. Clean up all other hosts: #{e}"
    app_instance.clean_all_hosts

    output[:status] = 'FAILURE'
    raise "Error while deploying hosts for application instance '#{app_instance.name}': (#{e.message})"
  end
end