Class: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller
- Inherits:
-
Agent::Base
- Object
- Agent::Base
- InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller
show all
- Defined in:
- lib/instance_agent/plugins/codedeploy/command_poller.rb
Constant Summary
collapse
- VERSION =
"2013-04-23"
Instance Method Summary
collapse
Methods inherited from Agent::Base
#description, #log, #run, runner
included
Constructor Details
Returns a new instance of CommandPoller.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/instance_agent/plugins/codedeploy/command_poller.rb', line 10
def initialize
CodeDeployPlugin::OnPremisesConfig.configure
region = ENV['AWS_REGION'] || InstanceMetadata.region
@host_identifier = ENV['AWS_HOST_IDENTIFIER'] || InstanceMetadata.host_identifier
log(:debug, "Configuring deploy control client: Region = #{region.inspect}")
log(:debug, "Deploy control endpoint override = " + ENV['AWS_DEPLOY_CONTROL_ENDPOINT'].inspect)
@deploy_control = InstanceAgent::Plugins::CodeDeployPlugin::CodeDeployControl.new(:region => region, :logger => InstanceAgent::Log, :ssl_ca_directory => ENV['AWS_SSL_CA_DIRECTORY'])
@deploy_control_client = @deploy_control.get_client
@plugin = InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor.new(:hook_mapping => create_hook_mapping)
log(:debug, "Initializing Host Agent: " +
"Host Identifier = #{@host_identifier}")
end
|
Instance Method Details
#acknowledge_command(command) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/instance_agent/plugins/codedeploy/command_poller.rb', line 99
def acknowledge_command(command)
log(:debug, "Calling PutHostCommandAcknowledgement:")
output = @deploy_control_client.put_host_command_acknowledgement(
:diagnostics => nil,
:host_command_identifier => command.host_command_identifier)
status = output.command_status
log(:debug, "Command Status = #{status}")
if status == 'Succeeded' || status == 'Failed'
log(:debug, "Calling PutHostCommandComplete: \"#{status}\" ")
@deploy_control_client.put_host_command_complete(
:command_status => status,
:diagnostics => {:format => "JSON", :payload => gather_diagnostics_from_acknowledge(status)},
:host_command_identifier => command.host_command_identifier)
return false
end
return true
end
|
#create_hook_mapping ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/instance_agent/plugins/codedeploy/command_poller.rb', line 27
def create_hook_mapping
{ "BeforeELBRemove"=>["BeforeELBRemove"],
"AfterELBRemove"=>["AfterELBRemove"],
"ApplicationStop"=>["ApplicationStop"],
"BeforeInstall"=>["BeforeInstall"],
"AfterInstall"=>["AfterInstall"],
"ApplicationStart"=>["ApplicationStart"],
"BeforeELBAdd"=>["BeforeELBAdd"],
"AfterELBAdd"=>["AfterELBAdd"],
"ValidateService"=>["ValidateService"]}
end
|
#get_deployment_specification(command) ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/instance_agent/plugins/codedeploy/command_poller.rb', line 119
def get_deployment_specification(command)
log(:debug, "Calling GetDeploymentSpecification:")
output = @deploy_control_client.get_deployment_specification(
:deployment_execution_id => command.deployment_execution_id,
:host_identifier => @host_identifier)
log(:debug, "GetDeploymentSpecification: " +
"Deployment System = #{output.deployment_system}")
raise "Deployment System mismatch: #{@plugin.deployment_system} != #{output.deployment_system}" unless @plugin.deployment_system == output.deployment_system
raise "Deployment Specification missing" if output.deployment_specification.nil?
output.deployment_specification.generic_envelope
end
|
#next_command ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/instance_agent/plugins/codedeploy/command_poller.rb', line 81
def next_command
log(:debug, "Calling PollHostCommand:")
output = @deploy_control_client.poll_host_command(:host_identifier => @host_identifier)
command = output.host_command
if command.nil?
log(:debug, "PollHostCommand: Host Command = nil")
else
log(:debug, "PollHostCommand: " +
"Host Identifier = #{command.host_identifier}; " +
"Host Command Identifier = #{command.host_command_identifier}; " +
"Deployment Execution ID = #{command.deployment_execution_id}; " +
"Command Name = #{command.command_name}")
raise "Host Identifier mismatch: #{@host_identifier} != #{command.host_identifier}" unless @host_identifier.include? command.host_identifier
raise "Command Name missing" if command.command_name.nil? || command.command_name.empty?
end
command
end
|
49
50
51
52
53
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
|
# File 'lib/instance_agent/plugins/codedeploy/command_poller.rb', line 49
def perform
return unless command = next_command
return unless acknowledge_command(command)
begin
spec = get_deployment_specification(command)
script_output = process_command(command, spec)
log(:debug, 'Calling PutHostCommandComplete: "Succeeded"')
@deploy_control_client.put_host_command_complete(
:command_status => 'Succeeded',
:diagnostics => {:format => "JSON", :payload => gather_diagnostics()},
:host_command_identifier => command.host_command_identifier)
rescue ScriptError => e
log(:debug, 'Calling PutHostCommandComplete: "Code Error" ')
@deploy_control_client.put_host_command_complete(
:command_status => "Failed",
:diagnostics => {:format => "JSON", :payload => gather_diagnostics_from_script_error(e)},
:host_command_identifier => command.host_command_identifier)
raise e
rescue Exception => e
log(:debug, 'Calling PutHostCommandComplete: "Code Error" ')
@deploy_control_client.put_host_command_complete(
:command_status => "Failed",
:diagnostics => {:format => "JSON", :payload => gather_diagnostics_from_error(e)},
:host_command_identifier => command.host_command_identifier)
raise e
end
end
|
#process_command(command, spec) ⇒ Object
131
132
133
134
|
# File 'lib/instance_agent/plugins/codedeploy/command_poller.rb', line 131
def process_command(command, spec)
log(:debug, "Calling #{@plugin.to_s}.execute_command")
@plugin.execute_command(command, spec)
end
|
#validate ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/instance_agent/plugins/codedeploy/command_poller.rb', line 40
def validate
test_profile = InstanceAgent::Config.config[:codedeploy_test_profile]
unless ["beta", "gamma"].include?(test_profile.downcase)
log(:debug, "Validating CodeDeploy Plugin Configuration")
Kernel.abort "Stopping CodeDeploy agent due to SSL validation error." unless @deploy_control.validate_ssl_config
log(:debug, "CodeDeploy Plugin Configuration is valid")
end
end
|