From 21087ea316f6526c40e083ff788dfaa9fa8f2700 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Wed, 5 Nov 2008 11:23:11 +0000 Subject: [PATCH] update fixes * setting update-job to state error after wol (booting vs. sending msgs race condition) * importing jobs and activation problem git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@12922 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 79 ++++++++++++++++++++------ gosa-si/server/events/gosaTriggered.pm | 25 +++++++- 2 files changed, 84 insertions(+), 20 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index cc6b82f18..b09f02411 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -979,29 +979,78 @@ sub send_msg_to_target { sub update_jobdb_status_for_send_msgs { - my ($answer, $error) = @_; + my ($session_id, $answer, $error) = @_; if( $answer =~ /(\d+)<\/jobdb_id>/ ) { my $jobdb_id = $1; - - # sending msg faild + $answer =~ /
(.*)<\/header>/; + my $job_header = $1; + $answer =~ /(.*)<\/target>/; + my $job_target = $1; + + # sending msg failed if( $error ) { - if (not $answer =~ /
trigger_action_reinstall<\/header>/) { + + # set jobs to done, jobs do not need to deliver their message in any case + if (($job_header eq "trigger_action_localboot") + ||($job_header eq "trigger_action_lock") + ||($job_header eq "trigger_action_halt") + ) { + my $sql_statement = "UPDATE $job_queue_tn SET status='done' WHERE id=$jobdb_id"; + my $res = $job_db->update_dbentry($sql_statement); + + # reactivate jobs, jobs need to deliver their message + } elsif (($job_header eq "trigger_action_activate") + ||($job_header eq "trigger_action_update") + ||($job_header eq "trigger_action_reinstall") + ) { + &reactivate_job_with_delay($session_id, $job_target, $job_header, 30 ); + + # for all other messages + } else { my $sql_statement = "UPDATE $job_queue_tn ". "SET status='error', result='can not deliver msg, please consult log file' ". "WHERE id=$jobdb_id"; my $res = $job_db->update_dbentry($sql_statement); + &daemon_log("D \n$sql_statement\n$answer", 1); + } # sending msg was successful } else { - my $sql_statement = "UPDATE $job_queue_tn ". - "SET status='done' ". - "WHERE id=$jobdb_id AND status='processed'"; - my $res = $job_db->update_dbentry($sql_statement); + # set jobs localboot, lock, activate, halt, reboot and wake to done + # jobs reinstall, update, inst_update do themself setting to done + if (($job_header eq "trigger_action_localboot") + ||($job_header eq "trigger_action_lock") + ||($job_header eq "trigger_action_activate") + ||($job_header eq "trigger_action_halt") + ||($job_header eq "trigger_action_reboot") + ||($job_header eq "trigger_action_wake") + ) { + + my $sql_statement = "UPDATE $job_queue_tn ". + "SET status='done' ". + "WHERE id=$jobdb_id AND status='processed'"; + my $res = $job_db->update_dbentry($sql_statement); + } } } } +sub reactivate_job_with_delay { + my ($session_id, $target, $header, $delay) = @_ ; + # Sometimes the client is still booting or does not wake up, in this case reactivate the job (if it exists) with a delay of n sec + + if (not defined $delay) { $delay = 30 } ; + my $delay_timestamp = &calc_timestamp(&get_time(), "plus", $delay); + + my $sql = "UPDATE $job_queue_tn Set timestamp='$delay_timestamp', status='waiting' WHERE (macaddress='$target' AND headertag='$header')"; + my $res = $job_db->update_dbentry($sql); + daemon_log("$session_id INFO: '$header'-job will be reactivated at '$delay_timestamp' ". + "cause client '$target' is currently not available", 5); + daemon_log("$session_id $sql", 7); + return; +} + sub sig_handler { my ($kernel, $signal) = @_[KERNEL, ARG0] ; @@ -1473,15 +1522,7 @@ sub process_task { } if( $found_ip_flag == 0) { daemon_log("$session_id WARNING: no host found in known_clients or foreign_clients with mac address '$answer_target'", 3); - - # Sometimes the client is still booting or does not wake up, in this case reactivate the job (if it exists) with a delay of 30 sec - my $delay_timestamp = &calc_timestamp(&get_time(), "plus", 30); - my $sql = "UPDATE $job_queue_tn Set timestamp='$delay_timestamp', status='waiting' WHERE (macaddress='$answer_target' AND headertag='$answer_header')"; - my $res = $job_db->update_dbentry($sql); - daemon_log("$session_id INFO: '$answer_header'-job will be reactivated at '$delay_timestamp' ". - "cause client '$answer_target' is currently not available", 5); - daemon_log("$session_id $sql", 7); - + &reactivate_job_with_delay($session_id, $answer_target, $answer_header, 30); } # Answer is for one specific host @@ -1776,7 +1817,9 @@ sub watch_for_new_jobs { # update status in job queue to ... # ... 'processing', for jobs: 'reinstall', 'update' - if (($header =~ /gosa_trigger_action_reinstall/) || ($header =~ /gosa_trigger_action_update/)) { + if (($header =~ /gosa_trigger_action_reinstall/) + || ($header =~ /gosa_trigger_activate_new/) + || ($header =~ /gosa_trigger_action_update/)) { my $sql_statement = "UPDATE $job_queue_tn SET status='processing' WHERE id=$jobdb_id"; my $dbres = $job_db->update_dbentry($sql_statement); } diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 701a1d6f0..5046bd164 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -801,6 +801,25 @@ sub trigger_activate_new { my $dhcp_statement= (defined($msg_hash->{'dhcp'}))?@{$msg_hash->{'dhcp'}}[0]:undef; my $jobdb_id= (defined($msg_hash->{'jobdb_id'}))?@{$msg_hash->{'jobdb_id'}}[0]:undef; + # Sanity check for base + if (ref($base) eq "HASH") { + # Incoming msg has a xml tag 'base' but no content + $base = undef; + } + + # In case that the client is sleeping, wake it up + my %data = ( 'macaddress' => $mac ); + my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data); + &main::server_server_com::trigger_wake($msg, $msg_hash, $session_id); + my $sql_statement= "SELECT * FROM $main::known_server_tn"; + my $query_res = $main::known_server_db->select_dbentry( $sql_statement ); + while( my ($hit_num, $hit) = each %{ $query_res } ) { + my $host_name = $hit->{hostname}; + my $host_key = $hit->{hostkey}; + $wake_msg =~ s/\S+<\/target>/$host_name<\/target>/g; + my $error = &main::send_msg_to_target($wake_msg, $host_name, $host_key, $header, $session_id); + } + my $ldap_handle = &main::get_ldap_handle(); my $ldap_entry; my $ogroup_entry; @@ -877,8 +896,10 @@ sub trigger_activate_new { } elsif ($ldap_mesg->count == 0) { &main::daemon_log("$session_id WARNING: No System with mac address '$mac' was found in base '".$main::ldap_base."'! Re-queuing job.", 4); - $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting' WHERE id = $jobdb_id"); - $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET timestamp = '".&get_time(60)."' WHERE id = $jobdb_id"); + my $sql_statement = "UPDATE ".$main::job_queue_tn. + " SET status='waiting', timestamp = '".(&calc_timestamp(&get_time(), 'plus', 60))."' ". + " WHERE id = $jobdb_id"; + $main::job_db->exec_statement($sql_statement); return undef; } -- 2.30.2