Class: InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor
- Inherits:
-
Object
- Object
- InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor
- Defined in:
- lib/instance_agent/plugins/codedeploy/command_executor.rb
Constant Summary collapse
- InvalidCommandNameFailure =
Class.new(Exception)
Class Attribute Summary collapse
-
.command_methods ⇒ Object
readonly
Returns the value of attribute command_methods.
Instance Attribute Summary collapse
-
#deployment_system ⇒ Object
readonly
Returns the value of attribute deployment_system.
Class Method Summary collapse
Instance Method Summary collapse
- #command_method(command_name) ⇒ Object
- #execute_command(command, deployment_specification) ⇒ Object
-
#initialize(options = {}) ⇒ CommandExecutor
constructor
A new instance of CommandExecutor.
- #map ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ CommandExecutor
Returns a new instance of CommandExecutor.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/instance_agent/plugins/codedeploy/command_executor.rb', line 24 def initialize( = {}) @deployment_system = "CodeDeploy" @hook_mapping = [:hook_mapping] if(!@hook_mapping.nil?) map end begin max_revisions = ProcessManager::Config.config[:max_revisions] @archives_to_retain = max_revisions.nil?? ARCHIVES_TO_RETAIN : Integer(max_revisions) if @archives_to_retain < 0 raise ArgumentError end rescue ArgumentError log(:error, "Invalid configuration :max_revision=#{max_revisions}") Platform.util.quit() end log(:info, "Archives to retain is: #{@archives_to_retain}}") end |
Class Attribute Details
.command_methods ⇒ Object (readonly)
Returns the value of attribute command_methods.
17 18 19 |
# File 'lib/instance_agent/plugins/codedeploy/command_executor.rb', line 17 def command_methods @command_methods end |
Instance Attribute Details
#deployment_system ⇒ Object (readonly)
Returns the value of attribute deployment_system.
20 21 22 |
# File 'lib/instance_agent/plugins/codedeploy/command_executor.rb', line 20 def deployment_system @deployment_system end |
Class Method Details
.command(name, &blk) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/instance_agent/plugins/codedeploy/command_executor.rb', line 43 def self.command(name, &blk) @command_methods ||= Hash.new method = Seahorse::Util.underscore(name).to_sym @command_methods[name] = method define_method(method, &blk) end |
Instance Method Details
#command_method(command_name) ⇒ Object
66 67 68 69 |
# File 'lib/instance_agent/plugins/codedeploy/command_executor.rb', line 66 def command_method(command_name) raise InvalidCommandNameFailure.new("Unsupported command type: #{command_name}.") unless self.class.command_methods.has_key?(command_name) self.class.command_methods[command_name] end |
#execute_command(command, deployment_specification) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/instance_agent/plugins/codedeploy/command_executor.rb', line 52 def execute_command(command, deployment_specification) method_name = command_method(command.command_name) log(:debug, "Command #{command.command_name} maps to method #{method_name}") deployment_specification = DeploymentSpecification.parse(deployment_specification) log(:debug, "Successfully parsed the deployment spec") log(:debug, "Creating deployment root directory #{deployment_root_dir(deployment_specification)}") FileUtils.mkdir_p(deployment_root_dir(deployment_specification)) raise "Error creating deployment root directory #{deployment_root_dir(deployment_specification)}" if !File.directory?(deployment_root_dir(deployment_specification)) send(method_name, command, deployment_specification) end |
#map ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/instance_agent/plugins/codedeploy/command_executor.rb', line 120 def map @hook_mapping.each_pair do |command, lifecycle_events| InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor.command command do |cmd, deployment_spec| #run the scripts script_log = ScriptLog.new lifecycle_events.each do |lifecycle_event| hook_command = HookExecutor.new(:lifecycle_event => lifecycle_event, :application_name => deployment_spec.application_name, :deployment_id => deployment_spec.deployment_id, :deployment_group_name => deployment_spec.deployment_group_name, :deployment_group_id => deployment_spec.deployment_group_id, :deployment_root_dir => deployment_root_dir(deployment_spec), :last_successful_deployment_dir => last_successful_deployment_dir(deployment_spec.deployment_group_id), :app_spec_path => app_spec_path) script_log.concat_log(hook_command.execute) end script_log.log end end end |