From 700756366461b68bd781cf9361a8d2f61e5a5e44 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Fri, 11 Jul 2008 12:29:39 +0000 Subject: [PATCH] sharing job queue information among all si-server git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@11608 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 35 ++++++++++++---------- gosa-si/modules/ClientPackages.pm | 2 ++ gosa-si/modules/GosaPackages.pm | 2 +- gosa-si/modules/GosaSupportDaemon.pm | 34 +++++++++++++++++++++ gosa-si/server/events/clMessages.pm | 41 +++++++++++++------------- gosa-si/server/events/gosaTriggered.pm | 12 ++++---- gosa-si/tests/client.php | 2 +- 7 files changed, 84 insertions(+), 44 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index b6d603042..50709127a 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -1482,7 +1482,7 @@ sub session_start { sub watch_for_done_jobs { my ($kernel,$heap) = @_[KERNEL, HEAP]; - my $sql_statement = "SELECT * FROM ".$job_queue_tn." WHERE status='done'"; + my $sql_statement = "SELECT * FROM ".$job_queue_tn." WHERE ((status='done') AND (modified='0'))"; my $res = $job_db->select_dbentry( $sql_statement ); while( my ($id, $hit) = each %{$res} ) { @@ -1508,21 +1508,24 @@ sub watch_for_modified_jobs { # make out of the db result a gosa-si message my $update_msg = &db_res2si_msg ($res, "foreign_job_updates", "KNOWN_SERVER", "MY_LOCAL_ADDRESS"); - - # determine all other si-server a foreign_job_updates message should be send - my $sql_statement= "SELECT * FROM $known_server_tn"; - my $res = $known_server_db->select_dbentry( $sql_statement ); - while( my ($hit_num, $hit) = each %$res ) { - my $act_update_msg = $update_msg; - my $act_target_address = $hit->{hostname}; - my $act_target_key = $hit->{hostkey}; - my ($act_target_ip, $act_target_port) = split(/:/, $act_target_address); - my $act_source_address = &get_local_ip_for_remote_ip($act_target_ip).":$act_target_port"; - - $act_update_msg =~ s/KNOWN_SERVER<\/target>/$act_target_address<\/target>/g; - $act_update_msg =~ s/MY_LOCAL_ADDRESS<\/source>/$act_source_address<\/source>/g; - &send_msg_to_target($act_update_msg, $act_target_address, $act_target_key, "foreign_job_updates" , "J"); - } + + # update all other SI-server + &inform_all_other_si_server($update_msg); + +# # determine all other si-server a foreign_job_updates message should be send +# my $sql_statement= "SELECT * FROM $known_server_tn"; +# my $res = $known_server_db->select_dbentry( $sql_statement ); +# while( my ($hit_num, $hit) = each %$res ) { +# my $act_update_msg = $update_msg; +# my $act_target_address = $hit->{hostname}; +# my $act_target_key = $hit->{hostkey}; +# my ($act_target_ip, $act_target_port) = split(/:/, $act_target_address); +# my $act_source_address = &get_local_ip_for_remote_ip($act_target_ip).":$act_target_port"; +# +# $act_update_msg =~ s/KNOWN_SERVER<\/target>/$act_target_address<\/target>/g; +# $act_update_msg =~ s/MY_LOCAL_ADDRESS<\/source>/$act_source_address<\/source>/g; +# &send_msg_to_target($act_update_msg, $act_target_address, $act_target_key, "foreign_job_updates" , "J"); +# } # set jobs all jobs to modified = 0, wait until the next modification for updates of other si-server $sql_statement = "UPDATE $job_queue_tn SET modified='0' "; diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index 7db50cd1a..06b041023 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -944,6 +944,8 @@ sub hardware_config { xmlmessage=>'none', macaddress=>$macaddress, plainname=>'none', + siserver=>'localhost', + modified=>'1', }; my $hd_res = $main::job_db->add_dbentry($func_dic); &main::daemon_log("$session_id INFO: add '$macaddress' to job queue as an installing job", 5); diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index 686846d85..5f6b4657b 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -312,7 +312,7 @@ sub process_job_msg { macaddress=>$macaddress, plainname=>$plain_name, siserver=>"localhost", - modified=>"0", + modified=>"1", }; my $res = $main::job_db->add_dbentry($func_dic); if (not $res == 0) { diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index 33c9ec47d..88b2c60ea 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -28,6 +28,7 @@ my @functions = ( "get_interfaces", "is_local", "run_as", + "inform_all_other_si_server", ); @EXPORT = @functions; use strict; @@ -675,4 +676,37 @@ sub run_as { } +#=== FUNCTION ================================================================ +# NAME: inform_other_si_server +# PARAMETERS: message +# RETURNS: nothing +# DESCRIPTION: Sends message to all other SI-server found in known_server_db. +#=============================================================================== +sub inform_all_other_si_server { + my ($msg) = @_; + + # determine all other si-server from known_server_db + my $sql_statement= "SELECT * FROM $main::known_server_tn"; + my $res = $main::known_server_db->select_dbentry( $sql_statement ); + + while( my ($hit_num, $hit) = each %$res ) { + my $act_target_address = $hit->{hostname}; + my $act_target_key = $hit->{hostkey}; + + # determine the source address corresponding to the actual target address + my ($act_target_ip, $act_target_port) = split(/:/, $act_target_address); + my $act_source_address = &main::get_local_ip_for_remote_ip($act_target_ip).":$act_target_port"; + + # fill into message the correct target and source addresses + my $act_msg = $msg; + $act_msg =~ s/\w*<\/target>/$act_target_address<\/target>/g; + $act_msg =~ s/\w*<\/source>/$act_source_address<\/source>/g; + + # send message to the target + &main::send_msg_to_target($act_msg, $act_target_address, $act_target_key, "foreign_job_updates" , "J"); + } + + return; +} + 1; diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index 5ca859014..70da956b5 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -379,11 +379,13 @@ sub TASKBEGIN { &main::daemon_log("$session_id DEBUG: there are more than one processing job in queue for host '$macaddress', ". "delete entries", 7); - my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE status='processing' AND macaddress LIKE '$macaddress'"; - my ($err) = $main::job_db->del_dbentry($sql_statement); - if (not defined $err) { - &main::daemon_log("$session_id ERROR: can not delete multiple processing queue entries for host '$macaddress': ".Dumper($err), 1); - } + # set job to status 'done', job will be deleted automatically + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='done', modified='1'". + "WHERE status='processing' AND macaddress LIKE '$macaddress'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry( $sql_statement ); + } # in case of no and more than one running jobs in queue, add one single job @@ -460,25 +462,22 @@ sub TASKEND { if ($content eq "savelog 0") { &main::daemon_log("$session_id DEBUG: got savelog from host '$target' - job done", 7); - my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE status='processing' AND macaddress LIKE '$macaddress'"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->del_dbentry($sql_statement); + + # set job to status 'done', job will be deleted automatically + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='done', modified='1'". + "WHERE status='processing' AND macaddress LIKE '$macaddress'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry( $sql_statement ); } else { - - my $sql_statement = "UPDATE $main::job_queue_tn ". - "SET status='processing', result='$header "."$content', modified='1' ". - "WHERE status='processing' AND macaddress LIKE '$macaddress'"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->update_dbentry($sql_statement); - &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); - + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='processing', result='$header "."$content', modified='1' ". + "WHERE status='processing' AND macaddress LIKE '$macaddress'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); } -# -----------------------> Update hier -# finish -#
CLMSG_TASKBEGIN
-# macaddress auslesen, Client im LDAP lokalisieren -# FAIstate auf "error" setzen return; } diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 850fa8ea7..6d969a180 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -443,11 +443,13 @@ sub trigger_action_faireboot { &main::change_goto_state('locked', \@{$msg_hash->{macaddress}}, $session_id); &main::change_fai_state('install', \@{$msg_hash->{macaddress}}, $session_id); - # delete all jobs from jobqueue which correspond to fai - my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE (macaddress='$macaddress' AND ". - "status='processing')"; - $main::job_db->del_dbentry($sql_statement ); - + # set job to status 'done', job will be deleted automatically + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='done', modified='1'". + "WHERE (macaddress='$macaddress' AND status='processing')"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry( $sql_statement ); + return @out_msg_l; } diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 7620f5885..bcf4ced0d 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -20,7 +20,7 @@ for($count = 1; $count <= $zahl; $count++) # jobdb add #$data = "
gosa_network_completition
GOSAGOSAws-muc-2
"; #$data = "
job_sayHello
10.89.1.155:2008300:01:6c:9d:b9:fa00:1B:77:04:8A:6C 20130102133908
"; - $data = "
job_ping2
GOSA 00:01:6c:9d:b9:fa 00:01:6c:9d:b9:fa20130101000000
"; + #$data = "
job_ping
GOSA 00:01:6c:9d:b9:fa 00:01:6c:9d:b9:fa20130101000000
"; # jobdb delete #$data = "
gosa_delete_jobdb_entry
GOSA GOSA 3
"; -- 2.30.2