Skip to content

Commit

Permalink
Bug #5113 Improve exception handling ec2 drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio committed Apr 18, 2017
1 parent 264a402 commit 6565c15
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 33 deletions.
12 changes: 10 additions & 2 deletions src/im_mad/remotes/ec2.d/poll
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,13 @@ host = ARGV[-1]
host_id = ARGV[-2]
ec2_drv = EC2Driver.new(host, host_id)

ec2_drv.monitor_all_vms

begin
ec2_drv.monitor_all_vms
rescue Exception => e

STDERR.puts e.message
STDERR.puts "********** STACK TRACE ************"
STDERR.puts e.backtrace
STDERR.puts "***********************************"
exit -1
end
9 changes: 8 additions & 1 deletion src/vmm_mad/remotes/ec2/cancel
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,12 @@ host = ARGV[1]

ec2_drv = EC2Driver.new(host)

ec2_drv.cancel(deploy_id)

begin
ec2_drv.cancel(deploy_id)
rescue Exception => e
handle_exception("Cancel", e, host, deploy_id)
end



6 changes: 3 additions & 3 deletions src/vmm_mad/remotes/ec2/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ text=File.read(dfile)

begin
puts ec2_drv.deploy(id, host, text, lcm_state, deploy_id)

rescue Exception => e
STDERR.puts "Deploy of VM #{id} on host #{host} with #{dfile} failed " +
"due to \"#{e.message}\""
exit -1

handle_exception("Deploy", e, host, deploy_id, id, dfile)
end
58 changes: 37 additions & 21 deletions src/vmm_mad/remotes/ec2/ec2_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,29 @@
require 'VirtualMachineDriver'
require 'opennebula'

# >> /var/log/one/oned.log
def handle_exception(action, ex, host, did, id = nil, file = nil)

file ||= ""
id ||= ""
STDERR.puts action + " of VM #{id} #{did} on host #{host} #{file} "+
"due to \"#{ex.message}\""
STDERR.puts "********* STACK TRACE *********"
STDERR.puts ex.backtrace
STDERR.puts "*******************************"
exit (-1)
end





begin
PUBLIC_CLOUD_EC2_CONF = YAML::load(File.read(EC2_DRIVER_CONF))
rescue Exception => e
STDERR.puts "Unable to read '#{EC2_DRIVER_CONF}'. Invalid YAML syntax:\n" <<
e.message
exit 1
str_error="Unable to read '#{EC2_DRIVER_CONF}'. Invalid YAML syntax:\n" +
e.message + "\n********Stack trace from EC2 IM driver*********\n"
raise str_error
end

# The main class for the EC2 driver
Expand Down Expand Up @@ -252,7 +269,12 @@ def initialize(host, host_id=nil)
# DEPLOY action, also sets ports and ip if needed
def deploy(id, host, xml_text, lcm_state, deploy_id)
if lcm_state == "BOOT" || lcm_state == "BOOT_FAILURE"
ec2_info = get_deployment_info(host, xml_text)

begin
ec2_info = get_deployment_info(host, xml_text)
rescue Exception => e
raise e
end

load_default_template_values

Expand Down Expand Up @@ -439,8 +461,7 @@ def monitor_all_vms
vms_info << " DEPLOY_ID=#{i.instance_id},\n"
vms_info << " VM_NAME=#{i.instance_id},\n"
vms_info << " IMPORT_TEMPLATE=\"#{vm_template_to_one}\",\n"
vms_info << " POLL=\"#{poll_data}\" ]\n"

vms_info << " POLL=\"#{poll_data}\" ]\n"
if one_id
name = i.instance_type
cpu, mem = instance_type_capacity(name)
Expand All @@ -449,9 +470,8 @@ def monitor_all_vms
end

end
rescue => e
STDERR.puts(e.message)
exit(-1)
rescue => e
raise e
end

host_info << "USEDMEMORY=#{usedmemory.round}\n"
Expand Down Expand Up @@ -481,7 +501,7 @@ def instance_type_capacity(name)

# Get the EC2 section of the template. If more than one EC2 section
# the CLOUD element is used and matched with the host
def get_deployment_info(host, xml_text)
def get_deployment_info(host, xml_text)
xml = REXML::Document.new xml_text

ec2 = nil
Expand Down Expand Up @@ -511,10 +531,9 @@ def get_deployment_info(host, xml_text)
if all_ec2_elements.size == 1
ec2 = all_ec2_elements[0]
else
STDERR.puts("Cannot find PUBLIC_CLOUD element in deployment "\
raise RuntimeError.new("Cannot find PUBLIC_CLOUD element in deployment "\
" file or no HOST site matching the requested in the "\
"template.")
exit(-1)
" template.")
end
end

Expand Down Expand Up @@ -587,13 +606,11 @@ def parse_poll(instance, onevm, do_cw, cw_mon_time)
# +deploy_id+: String, VM id in EC2
# +ec2_action+: Symbol, one of the keys of the EC2 hash constant (i.e :run)
def ec2_action(deploy_id, ec2_action)
begin
i = get_instance(deploy_id)

begin
i.send(EC2[ec2_action][:cmd])
i.send(EC2[ec2_action][:cmd])
rescue => e
STDERR.puts e.message
exit(-1)
raise e
end
end

Expand Down Expand Up @@ -678,11 +695,10 @@ def get_instance(id)
if instance.exists?
return instance
else
raise "Instance #{id} does not exist"
raise RuntimeError.new("Instance #{id} does not exist")
end
rescue => e
STDERR.puts e.message
exit(-1)
raise e
end
end

Expand Down
7 changes: 5 additions & 2 deletions src/vmm_mad/remotes/ec2/poll
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ id = ARGV[2]

ec2_drv = EC2Driver.new(host)

ec2_drv.poll(id, deploy_id)

begin
ec2_drv.poll(id, deploy_id)
rescue Excetion => e
handle_exception("Poll", e, host, deploy_id, id)
end
7 changes: 6 additions & 1 deletion src/vmm_mad/remotes/ec2/reboot
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ host = ARGV[1]

ec2_drv = EC2Driver.new(host)

ec2_drv.reboot(deploy_id)

begin
ec2_drv.reboot(deploy_id)
rescue Exception => e
handle_exception("Reboot", e, host, deploy_id)
end

7 changes: 6 additions & 1 deletion src/vmm_mad/remotes/ec2/restore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ host = ARGV[1]
deploy_id = ARGV[2]

ec2_drv = EC2Driver.new(host)
ec2_drv.restore(deploy_id)

begin
ec2_drv.restore(deploy_id)
rescue Exception => e
handle_exception("Restore", e, host, deploy_id)
end
7 changes: 6 additions & 1 deletion src/vmm_mad/remotes/ec2/save
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ file = ARGV[1]
host = ARGV[2]

ec2_drv = EC2Driver.new(host)
ec2_drv.save(deploy_id)

begin
ec2_drv.save(deploy_id)
rescue Exception => e
handle_exception("Save", e, host, deploy_id, nil, file)
end

7 changes: 6 additions & 1 deletion src/vmm_mad/remotes/ec2/shutdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@ lcm_state = vm.lcm_state_str

ec2_drv = EC2Driver.new(host)

ec2_drv.shutdown(deploy_id, lcm_state)
begin
ec2_drv.shutdown(deploy_id, lcm_state)
rescue Exception => e
handle_exception("Save", e, host, deploy_id, vm_id)
end


0 comments on commit 6565c15

Please sign in to comment.