From: rettenbe Date: Tue, 4 Mar 2008 14:31:51 +0000 (+0000) Subject: finished jobs are set to 'done' and deleted from job queue X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7c5ebee2a31e2eeb2b09e5cc0ee0fa6f05716ee7;p=gosa.git finished jobs are set to 'done' and deleted from job queue git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9323 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index f3b7f1436..86678654b 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -795,6 +795,7 @@ sub get_local_ip_for_remote_ip { return $result; } + sub send_msg_to_target { my ($msg, $address, $encrypt_key, $msg_header) = @_ ; my $error = 0; @@ -805,8 +806,7 @@ sub send_msg_to_target { if( $msg_header ) { $header = "'$msg_header'-"; - } - else { + } else { $header = ""; } @@ -853,14 +853,12 @@ sub send_msg_to_target { $sql_statement = "DELETE FROM known_clients WHERE hostname='$address'"; $res = $known_clients_db->del_dbentry($sql_statement); daemon_log("WARNING: failed 2x to send msg to host '$address', delete host from known_clients", 3); - } - else { + } else { $sql_statement = "UPDATE known_clients SET status='$new_status' WHERE hostname='$address'"; $res = $known_clients_db->update_dbentry($sql_statement); if($new_status eq "down"){ daemon_log("WARNING: set '$address' from status '$act_status' to '$new_status'", 3); - } - else { + } else { daemon_log("INFO: set '$address' from status '$act_status' to '$new_status'", 5); } } @@ -891,6 +889,27 @@ sub send_msg_to_target { } +sub update_jobdb_status_for_send_msgs { + my ($answer, $error) = @_; + if( $answer =~ /(\d+)<\/jobdb_id>/ ) { + my $jobdb_id = $1; + if( $error ) { + # sending msg faild + 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); + } else { + # sending msg was successful + my $sql_statement = "UPDATE $job_queue_tn ". + "SET status='done' ". + "WHERE id='$jobdb_id'"; + my $res = $job_db->update_dbentry($sql_statement); + } + } +} + + sub _start { my ($kernel) = $_[KERNEL]; &trigger_db_loop($kernel); @@ -901,7 +920,7 @@ sub _start { sub client_input { no strict "refs"; - my ($kernel, $session, $heap,$input,$wheel) = @_[KERNEL, SESSION, HEAP, ARG0, ARG1]; + my ($kernel, $session, $heap, $input, $wheel) = @_[KERNEL, SESSION, HEAP, ARG0, ARG1]; my $session_id = $session->ID; my ($msg, $msg_hash, $module); my $error = 0; @@ -970,7 +989,8 @@ sub client_input { while( my ($hit_num, $hit) = each %{ $query_res } ) { my $host_name = $hit->{hostname}; my $host_key = $hit->{hostkey}; - &send_msg_to_target($answer, $host_name, $host_key, $answer_header); + my $error = &send_msg_to_target($answer, $host_name, $host_key, $answer_header); + &update_jobdb_status_for_send_msgs($answer, $error); } } @@ -983,7 +1003,8 @@ sub client_input { my $host_name = $hit->{hostname}; my $host_key = $hit->{hostkey}; $answer =~ s/KNOWN_SERVER/$host_name/g; - &send_msg_to_target($answer, $host_name, $host_key, $answer_header); + my $error = &send_msg_to_target($answer, $host_name, $host_key, $answer_header); + &update_jobdb_status_for_send_msgs($answer, $error); } } @@ -1005,12 +1026,13 @@ sub client_input { $answer =~ /
(\S+)<\/header>/; my $header; if( defined $1 ) { $header = $1; } - &send_msg_to_target($answer, $server_address, $GosaPackages_key, $header); + my $error = &send_msg_to_target($answer, $server_address, $GosaPackages_key, $header); + &update_jobdb_status_for_send_msgs($answer, $error); } # target of msg is a mac address elsif( $answer_target =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i ) { - daemon_log("target is mac address '$answer_target', looking for host in known_clients", 3); + daemon_log("INFO: target is mac address '$answer_target', looking for host in known_clients", 5); my $sql_statement = "SELECT * FROM known_clients WHERE macaddress='$answer_target'"; my $query_res = $known_clients_db->select_dbentry( $sql_statement ); my $found_ip_flag = 0; @@ -1018,8 +1040,9 @@ sub client_input { my $host_name = $hit->{hostname}; my $host_key = $hit->{hostkey}; $answer =~ s/$answer_target/$host_name/g; - daemon_log("found host '$host_name', associated to '$answer_target'", 3); - &send_msg_to_target($answer, $host_name, $host_key, $answer_header); + daemon_log("INFO: found host '$host_name', associated to '$answer_target'", 5); + my $error = &send_msg_to_target($answer, $host_name, $host_key, $answer_header); + &update_jobdb_status_for_send_msgs($answer, $error); $found_ip_flag++ ; } if( $found_ip_flag == 0) { @@ -1031,7 +1054,8 @@ sub client_input { while( my ($hit_num, $hit) = each %{ $query_res } ) { my $bus_address = $hit->{hostname}; my $bus_key = $hit->{hostkey}; - &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header); + my $error = &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header); + &update_jobdb_status_for_send_msgs($answer, $error); last; } } @@ -1051,19 +1075,21 @@ sub client_input { my $query_res = $known_server_db->select_dbentry( $sql_statement ); my $res_length = keys( %{$query_res} ); if( $res_length == 0 ){ - daemon_log("WARNING: send '$answer_header' to '$bus_address' failed, no bus found in known_server", 3); + daemon_log("WARNING: send '$answer_header' to '$bus_address' failed, ". + "no bus found in known_server", 3); } else { while( my ($hit_num, $hit) = each %{ $query_res } ) { my $bus_key = $hit->{hostkey}; - &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header); + my $error = &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header); + &update_jobdb_status_for_send_msgs($answer, $error); } } } next; } - # send_msg - &send_msg_to_target($answer, $answer_target, $encrypt_key, $answer_header); + my $error = &send_msg_to_target($answer, $answer_target, $encrypt_key, $answer_header); + &update_jobdb_status_for_send_msgs($answer, $error); } } } @@ -1074,7 +1100,9 @@ sub client_input { my $session_id = $1; if( defined $session_id ) { my $session_reference = $kernel->ID_id_to_session($session_id); - $heap = $session_reference->get_heap(); + if( defined $session_reference ) { + $heap = $session_reference->get_heap(); + } } } $heap->{client}->put($client_answer); @@ -1143,6 +1171,10 @@ sub watch_for_new_jobs { $job_msg =~ s/<\/xml>$/$jobdb_id<\/jobdb_id><\/xml>/; my $func_error = &send_msg_to_target($job_msg, $server_address, $GosaPackages_key, $header); + + # update status in job queue to 'processing' + $sql_statement = "UPDATE $job_queue_tn SET status='processing' WHERE id='$jobdb_id'"; + my $res = $job_db->update_dbentry($sql_statement); } $kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay); diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index 9f1f25696..6f6a5e0b7 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -314,12 +314,9 @@ sub process_gosa_msg { no strict 'refs'; @out_msg_l = &{$event_hash->{$header}."::$header"}($msg, $msg_hash, $session_id); } -print STDERR "===============================\n"; -print STDERR Dumper(@out_msg_l); - # if delivery not possible raise error and return - if( not defined @out_msg_l[0] ) { + if( not defined $out_msg_l[0] ) { &main::daemon_log("WARNING: GosaPackages got no answer from event handler '$header'", 3); @out_msg_l = (); } elsif( $out_msg_l[0] eq 'nohandler') { @@ -349,6 +346,8 @@ sub process_job_msg { my $macaddress; if( exists $msg_hash->{'macaddress'} ) { $macaddress = @{$msg_hash->{'macaddress'}}[0]; + } elsif (@{$msg_hash->{'target'}}[0] =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i ) { + $macaddress = $1; } else { $error ++; $out_msg = "". @@ -356,7 +355,7 @@ sub process_job_msg { "$server_address". "GOSA". "1". - "no mac address specified". + "no mac address specified, neither in target-tag nor in macaddres-tag". ""; } diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index 3e6551f12..e33c83eaa 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -248,7 +248,7 @@ sub get_where_statement { if( exists $phrase->{'operator'} ) { my $op = $op_hash->{$phrase->{'operator'}[0]}; if( not defined $op ) { - &main::daemon_log("Can not translate operator '$operator' in where ". + &main::daemon_log("ERROR: Can not translate operator '$operator' in where ". "statement to sql valid syntax. Please use 'eq', ". "'ne', 'ge', 'gt', 'le', 'lt' in xml message\n", 1); &main::daemon_log($msg, 8); diff --git a/gosa-si/server/events/databases.pm b/gosa-si/server/events/databases.pm index 054d5eab0..a8916fdb9 100644 --- a/gosa-si/server/events/databases.pm +++ b/gosa-si/server/events/databases.pm @@ -158,7 +158,8 @@ sub update_status_jobdb_entry { # conditions # no timestamp update if status eq waiting - my $res_hash = $main::job_db->select_dbentry("SELECT * FROM $table $where AND status='processing' "); + my $sql_statement = "SELECT * FROM $table $where AND status='processing'"; + my $res_hash = $main::job_db->select_dbentry($sql_statement); if( (0 != keys(%$res_hash)) && ($update =~ /timestamp/i) ) { $error ++; $out_xml = "1there is no timestamp update allowed while status is 'processing'"; @@ -171,7 +172,6 @@ sub update_status_jobdb_entry { # check success of db update if( not $db_res > 0 ) { $error++; }; - } } diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 2e54deb5b..d16dd1bbb 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -26,6 +26,7 @@ my @events = ( "trigger_action_rescan", "trigger_action_wake", "recreate_fai_server_db", + "send_user_msg", ); @EXPORT = @events; @@ -51,15 +52,99 @@ sub get_events { return \@events; } +sub send_user_msg { + my ($msg, $msg_hash, $session_id) = @_ ; + my @out_msg_l; + my @user_list; + my @group_list; + + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'source'}}[0]; + my $target = @{$msg_hash->{'target'}}[0]; + my $message = @{$msg_hash->{'message'}}[0]; + if( exists $msg_hash->{'user'} ) { @user_list = @{$msg_hash->{'user'}}; } + if( exists $msg_hash->{'group'} ) { @group_list = @{$msg_hash->{'group'}}; } + + # error handling + if( not @user_list && not @group_list ) { + &main::daemon_log("WARNING: no user-tag or a group-tag specified in 'send_user_msg'", 3); + return ("
$header
GOSAGOSA". + "no user-tag or a group-tag specified in 'send_user_msg'
"); + } + if( not defined $message ) { + &main::daemon_log("WARNING: no message-tag specified in 'send_user_msg'", 3); + return ("
$header
GOSAGOSA". + "no message-tag specified in 'send_user_msg'
"); + + } + + # resolve groups to users + if( @group_list ) { + # build ldap connection + &main::refresh_ldap_handle(); + if( not defined $main::ldap_handle ) { + &main::daemon_log("ERROR: cannot connect to ldap", 1); + return (); + } + foreach my $group (@group_list) { + # Perform search + my $mesg = $main::ldap_handle->search( + base => $main::ldap_base, + scope => 'sub', + attrs => ['memberUid'], + filter => "(&(objectClass=posixGroup)(cn=$group)(memberUid=*))"); + if($mesg->code) { + &main::daemon_log($mesg->error, 1); + return (); + } + my $entry= $mesg->entry(0); + my @users= $entry->get_value("memberUid"); + foreach my $user (@users) { push(@user_list, $user); } + } + } + + # drop multiple users in @user_list + my %seen = (); + foreach my $user (@user_list) { + $seen{$user}++; + } + @user_list = keys %seen; + + # build xml messages sended to client where user is logged in + foreach my $user (@user_list) { + my $sql_statement = "SELECT * FROM $main::login_users_tn WHERE user='$user'"; + my $db_res = $main::login_users_db->select_dbentry($sql_statement); + + if(0 == keys(%{$db_res})) { + + } else { + while( my($hit, $content) = each %{$db_res} ) { + my $out_hash = &create_xml_hash('send_user_msg', $main::server_address, $content->{'client'}); + &add_content2xml_hash($out_hash, 'message', $message); + &add_content2xml_hash($out_hash, 'user', $user); + if( exists $msg_hash->{'jobdb_id'} ) { + &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]); + } + my $out_msg = &create_xml_string($out_hash); + push(@out_msg_l, $out_msg); + } + } + } + + return @out_msg_l; +} + sub recreate_fai_server_db { my ($msg, $msg_hash, $session_id) = @_ ; - + my $out_msg; + $main::fai_server_db->create_table("new_fai_server", \@main::fai_server_col_names); &main::create_fai_server_db("new_fai_server"); $main::fai_server_db->move_table("new_fai_server", $main::fai_server_tn); - return; + my @out_msg_l = ( $out_msg ); + return @out_msg_l; } @@ -105,17 +190,14 @@ sub get_client_for_login_usr { sub ping { - my ($msg, $msg_hash, $session_id) = @_ ; - my $source = @{$msg_hash->{source}}[0]; - my $target = @{$msg_hash->{target}}[0]; - my $out_hash = &create_xml_hash("ping", $source, $target); - &add_content2xml_hash($out_hash, "session_id", $session_id); - my $out_msg = &create_xml_string($out_hash); - - my @out_msg_l = ( $out_msg ); - return @out_msg_l; -} + my ($msg, $msg_hash, $session_id) = @_ ; + my $out_msg = $msg; + $out_msg =~ s/
gosa_/
/; + $out_msg =~ s/<\/xml>/$session_id<\/session_id><\/xml>/; + my @out_msg_l = ( $out_msg ); + return @out_msg_l; +} sub gen_smb_hash { my ($msg, $msg_hash, $session_id) = @_ ; @@ -163,6 +245,9 @@ sub detect_hardware { my $target = @{$msg_hash->{target}}[0]; my $out_hash = &create_xml_hash("detect_hardware", $source, $target); + if( exists $msg_hash->{'jobdb_id'} ) { + &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]); + } my $out_msg = &create_xml_string($out_hash); my @out_msg_l = ( $out_msg ); @@ -176,6 +261,9 @@ sub trigger_reload_ldap_config { my $target = @{$msg_hash->{target}}[0]; my $out_hash = &create_xml_hash("reload_ldap_config", $main::server_address, $main::server_address, $target); + if( exists $msg_hash->{'jobdb_id'} ) { + &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]); + } my $out_msg = &create_xml_string($out_hash); my @out_msg_l; push(@out_msg_l, $out_msg); @@ -191,8 +279,10 @@ sub set_activated_for_installation { my $target = @{$msg_hash->{target}}[0]; my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target); + if( exists $msg_hash->{'jobdb_id'} ) { + &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]); + } my $out_msg = &create_xml_string($out_hash); - my @out_msg_l = ( $out_msg ); return @out_msg_l; } @@ -288,7 +378,9 @@ sub trigger_action_rescan { sub trigger_action_wake { my ($msg, $msg_hash) = @_; - my %data = ( 'macAddress' => \@{$msg_hash->{macAddress}} ); + my %data = ( 'macAddress' => \@{$msg_hash->{'macAddress'}} , + 'jobdb_id' => \@{$msg_hash->{'jobdb_id'}}, + ); my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data); my @out_msg_l = ($out_msg); return @out_msg_l; diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 244686b60..1d53e1ad6 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -18,10 +18,11 @@ if($sock->connected()){ # jobdb add #$data = "
gosa_network_completition
GOSAGOSAws-muc-2
"; #$data = "
job_sayHello
10.89.1.155:2008300:1B:77:04:8A:6C 20130102133900
"; -#$data = "
job_ping
10.89.1.155:20083 10.89.1.155:2008100:01:6c:9d:b9:fa 20130102133900
"; +#$data = "
job_ping
GOSA 00:01:6c:9d:b9:fa 00:01:6c:9d:b9:fa19700101000000
"; + # jobdb delete -#$data = "
gosa_delete_jobdb_entry
3
"; +#$data = "
gosa_delete_jobdb_entry
GOSA GOSA 1
"; # smbhash #$data = "
gosa_gen_smb_hash
GOSAGOSAtester
"; @@ -30,8 +31,8 @@ if($sock->connected()){ #$data = "
gosa_trigger_reload_ldap_config
GOSA00:01:6c:9d:b9:fa
"; # jobdb update -#$data = "
gosa_update_status_jobdb_entry
GOSAGOSA 00:01:6c:9d:b9:fa 23450101000000XXXXXXXXXXXXXXx
"; -#$data = "
gosa_update_status_jobdb_entry
GOSAGOSA waiting processing update
"; +#$data = "
gosa_update_status_jobdb_entry
GOSA GOSA 1 19700101000000
"; +#$data = "
gosa_update_status_jobdb_entry
GOSAGOSA 00:01:6c:9d:b9:fa done update
"; # jobdb query #$data = "
gosa_query_jobdb
GOSA GOSA". @@ -44,23 +45,23 @@ if($sock->connected()){ #$data= "
gosa_query_jobdb
GOSA GOSA
"; # jobdb count -#$data = "
gosa_count_packages_list
GOSA GOSA
"; +#$data = "
gosa_count_jobdb
GOSA GOSA
"; # jobdb clear -#$data = "
gosa_clear_jobdb
"; +#$data = "
gosa_clear_jobdb
GOSA GOSA
"; # set gosa-si-client to 'activated' -#$data = "
gosa_set_activated_for_installation
10.89.1.31:20083 127.0.0.1:20081
"; +#$data = "
job_set_activated_for_installation
10.89.1.31:20083 GOSA 00:01:6c:9d:b9:fa
"; + # trigger jobs at client #$data = "
gosa_detect_hardware
10.89.1.31:20083 10.89.1.31:20081
"; #$data = "
gosa_new_key_for_client
00:01:6c:9d:b9:fa 10.89.1.31:20081
"; -#$data = "
gosa_trigger_action_wake
00:01:6c:9d:b9:fa 10.89.1.31:20081
"; +#$data = "
job_trigger_action_wake
00:01:6c:9d:b9:fa GOSA 19700101000000
"; #$data = "
gosa_trigger_action_faireboot
00:01:6c:9d:b9:fa GOSA
"; -#$data = "
job_trigger_action_reinstall
GOSA 00:01:6c:9d:b9:fa ". -# "00:01:6c:9d:b9:fa 20130101000000
"; -$data = "
gosa_ping
00:01:6c:9d:b9:fa GOSA
"; +#$data = "
job_trigger_action_reinstall
GOSA 00:01:6c:9d:b9:fa 00:01:6c:9d:b9:fa 20130101000000
"; +#$data = "
gosa_ping
00:01:6c:9d:b9:fa GOSA
"; # to test @@ -87,6 +88,12 @@ $data = "
gosa_ping
00:01:6c:9d:b9:fa write($data); $answer = "nothing"; $answer = $sock->read();