1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

Logging for MADs. Closes ticket #5

git-svn-id: http://svn.opennebula.org/trunk@56 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Constantino Vázquez Blanco 2008-07-14 14:51:15 +00:00
parent 89500288b2
commit e3bdd5c9b9
7 changed files with 99 additions and 70 deletions

View File

@ -28,7 +28,9 @@
# This file MUST preserve SH syntax
#-------------------------------------------------------------------------------
# MADs will generate cores and logs if defined
# Debug for MADs.
# If set, MADs will generate cores and logs in $ONE_LOCATION/var.
# Possible values are [0=ERROR, 1=DEBUG]
ONE_MAD_DEBUG=
# Nice Priority to run the drivers

View File

@ -35,36 +35,17 @@ function export_rc_vars
fi
}
function log_with_date
{
PID=$$
LOG_FILE=$1
shift
mkfifo /tmp/one_fifo.$PID.err /tmp/one_fifo.$PID.out
# This line creates an empty log file
echo -n "" > $LOG_FILE
# Write out fifo to STDOUT
cat /tmp/one_fifo.$PID.out &
while read line < /tmp/one_fifo.$PID.err
do
echo `date +"%D %T"`: $line >> $LOG_FILE
done &
$* 2>/tmp/one_fifo.$PID.err 1>/tmp/one_fifo.$PID.out
rm /tmp/one_fifo.$PID.out /tmp/one_fifo.$PID.err
}
function execute_mad
{
MAD_FILE=`basename $0`
if [ -z "$LOG_FILE" ]; then
LOG_FILE=$MAD_FILE
fi
if [ -n "${ONE_MAD_DEBUG}" ]; then
log_with_date var/$MAD_FILE.log nice -n $PRIORITY bin/$MAD_FILE.rb $*
exec nice -n $PRIORITY bin/$MAD_FILE.rb $* 2> var/$LOG_FILE.log
else
exec nice -n $PRIORITY bin/$MAD_FILE.rb $* 2> /dev/null
fi

View File

@ -14,8 +14,11 @@ DRIVER_NAME=`basename $1 | cut -d. -f1`
export_rc_vars $ONE_LOCATION/etc/${DRIVER_NAME}/${DRIVER_NAME}rc
# Go to ONE_LOCATION
cd $ONE_LOCATION
LOG_FILE=$DRIVER_NAME
# Execute the actual MAD
execute_mad $*

View File

@ -18,6 +18,14 @@ require 'fileutils'
require 'thread'
require 'one_ssh'
DEBUG_LEVEL=ENV["ONE_MAD_DEBUG"]
##
# Debug constants
##
ERROR, DEBUG=[0,1]
####################
# SENSOR DEFINTION #
@ -199,8 +207,9 @@ class IM < ONEMad
def initialize(sensors=nil)
super(3, 4)
#log_file=File.open("im.log", "w")
#set_logger(log_file)
if DEBUG_LEVEL and !DEBUG_LEVEL.empty?
set_logger(STDERR,DEBUG_LEVEL)
end
if sensors
@sensors=sensors
@ -220,8 +229,10 @@ class IM < ONEMad
if done.length>0
done.each{|a|
STDOUT.puts a.get_result
tmp_result = a.get_result
STDOUT.puts tmp_result
STDOUT.flush
log(tmp_result,DEBUG)
}
@action_mutex.lock
@ -236,6 +247,7 @@ class IM < ONEMad
def action_init(args)
STDOUT.puts "INIT SUCCESS"
STDOUT.flush
log("INIT SUCCESS",DEBUG)
end
def action_monitor(args)

View File

@ -2,6 +2,8 @@
ONE_LOCATION=ENV["ONE_LOCATION"]
DEBUG_LEVEL=ENV["ONE_MAD_DEBUG"]
if !ONE_LOCATION
puts "ONE_LOCATION not set"
exit -1
@ -17,13 +19,24 @@ require 'open3'
class DM < ONEMad
###########################
# Constructor #
###########################
def initialize
super(5, 4)
if DEBUG_LEVEL and !DEBUG_LEVEL.empty?
set_logger(STDERR,DEBUG_LEVEL)
end
end
###########################
# Actions #
###########################
def action_init(args)
send_message("INIT", "SUCCESS")
log("KVM Access Driver initialized.")
end
def action_deploy(args)
@ -39,7 +52,7 @@ class DM < ONEMad
end
def action_checkpoint(args)
send_message("CHECKPOINT", "FAILURE", args[1], "action not supported for KVM")
send_message("CHECKPOINT", "FAILURE", args[1], "action not supported for KVM")
end
def action_save(args)
@ -62,6 +75,10 @@ class DM < ONEMad
stdout=std[1].read
stderr=std[2].read
if !stderr.empty?
log(stderr,ONEMad::ERROR)
end
exit_code=get_exit_code(stderr)
if exit_code!=0
@ -74,9 +91,6 @@ class DM < ONEMad
return nil
end
log("STDOUT:"+stdout)
log("STDERR:"+stderr)
info = parse_virsh_dominfo(stdout)
# TODO -> Get more info, like NET info. Need to know the iface name (e.g. tap0)
@ -93,8 +107,9 @@ class DM < ONEMad
stdout=std[1].read
stderr=std[2].read
log("STDOUT:"+stdout)
log("STDERR:"+stderr)
if !stderr.empty?
log(stderr,ONEMad::ERROR)
end
write_response(name, stdout, stderr, args)
end
@ -120,7 +135,7 @@ class DM < ONEMad
#########################################
# Get information from virsh #
# Parsers for virsh output #
#########################################
# From STDERR if exit code == 1

View File

@ -31,8 +31,15 @@
# send_message("INIT", "SUCCESS")
# end
class ONEMad
##
# Debug constants
##
ERROR, DEBUG=[0,1]
# * +num_params_in+: number of parameters that mensages will have
# * +num_params_out+: number of parameters that mensages sent back
# will have
@ -43,17 +50,31 @@ class ONEMad
else
@num_params_out=num_params_out
end
#@logger=STDERR
@debug_level = -1
end
# Sends a message to the logger
def log(str)
#@logger.puts(str)
#@logger.flush
def log(str, level)
if level == ERROR
str = "------- ERROR ---------------\n" +
str +
"\n-----------------------------"
end
if @debug_level != -1 and level <= @debug_level
str.split("\n").each{|line|
@logger.puts(Time.now.ctime + ": " + line.strip)
@logger.flush
}
end
end
# Sets the logger file, this can be an open file
def set_logger(logger)
def set_logger(logger, level)
@debug_level = level.to_i
@logger=logger
end
@ -67,6 +88,8 @@ class ONEMad
line=str.split(/\s+/)
log(str,DEBUG)
args=Array.new
args+=line[0..(@num_params-2)]
args<<line[(@num_params-1)..-1].join(' ') if line.length>=@num_params
@ -84,7 +107,8 @@ class ONEMad
end
STDOUT.puts to_send.join(' ')
STDOUT.flush
#log to_send.join(' ')
log(to_send.join(' '),DEBUG)
end
# Proceses each message received, called by +loop+.

View File

@ -5,6 +5,8 @@ XM_PATH=ENV["XM_PATH"]
ONE_LOCATION=ENV["ONE_LOCATION"]
DEBUG_LEVEL=ENV["ONE_MAD_DEBUG"]
if !ONE_LOCATION
puts "ONE_LOCATION not set"
exit -1
@ -24,9 +26,9 @@ class DM < ONEMad
def initialize
super(5, 4)
#Set log file
#log_file=File.open("dm.log", "w")
#set_logger(log_file)
if DEBUG_LEVEL and !DEBUG_LEVEL.empty?
set_logger(STDERR,DEBUG_LEVEL)
end
init_actions
end
@ -71,8 +73,8 @@ class DM < ONEMad
# Add sched-cred command if credits are defined
if(credits)
cmd_str+=" \\&\\& sudo #{XM_PATH} sched-cred -d #{vm_name} -w #{credits}"
STDERR.puts "Setting credits for the VM"
STDERR.puts "Command: #{cmd_str}"
log("Setting credits for the VM",ONEMad::DEBUG)
log("Command: #{cmd_str}",ONEMad::DEBUG)
end
cmd=SSHCommand.new(cmd_str)
@ -109,10 +111,6 @@ class DM < ONEMad
end
def action_poll(args)
#std=Open3.popen3(
# "ssh -n #{args[2]} sudo #{XENTOP_PATH} -bi2 ;"+
# " echo ExitCode: $? 1>&2")
action_number=args[1]
action_host=args[2]
@ -122,6 +120,10 @@ class DM < ONEMad
stdout=a.stdout
stderr=a.stderr
if !stderr.empty?
log(stderr,ONEMad::ERROR)
end
exit_code=get_exit_code(stderr)
if exit_code!=0
@ -129,11 +131,6 @@ class DM < ONEMad
return nil
end
#log("stdout:")
#log(stdout)
#log("stderr:")
#log(stderr)
values=parse_xentop(args[3], stdout)
if !values
@ -169,15 +166,13 @@ class DM < ONEMad
send_ssh_action(action_number, action_host, action)
end
def exec_xm_command(host, command)
Open3.popen3(
"ssh -n #{host} sudo /usr/sbin/xm #{command} ;"+
" echo ExitCode: $? 1>&2")
end
def write_response(action, stdout, stderr, args)
exit_code=get_exit_code(stderr)
if !stderr.empty?
log(stderr,ONEMad::ERROR)
end
if exit_code==0
domain_name=get_domain_name(stdout)
send_message(action, "SUCCESS", args[1], domain_name)
@ -186,10 +181,7 @@ class DM < ONEMad
send_message(action, "FAILURE", args[1], error_message)
end
#log("stdout:")
#log(stdout)
#log("stderr:")
#log(stderr)
end