From bd95070a26bbbca7ddee2be352439f35fed29d71 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Mon, 22 Jun 2009 15:37:21 +0000 Subject: [PATCH] new functionality: periodical jobs git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13762 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/client/events/gosaTriggered.pm | 5 +- gosa-si/gosa-si-server | 40 +++- gosa-si/modules/GosaPackages.pm | 26 +++ gosa-si/modules/GosaSupportDaemon.pm | 7 +- gosa-si/server/events/databases.pm | 4 +- gosa-si/server/events/gosaTriggered.pm | 262 ++++++++++++------------- gosa-si/tests/client.php | 7 +- 7 files changed, 197 insertions(+), 154 deletions(-) diff --git a/gosa-si/client/events/gosaTriggered.pm b/gosa-si/client/events/gosaTriggered.pm index bfe3a24ab..82040804e 100644 --- a/gosa-si/client/events/gosaTriggered.pm +++ b/gosa-si/client/events/gosaTriggered.pm @@ -126,8 +126,9 @@ sub usr_msg { my ($rand_fh, $rand_file) = tempfile( SUFFIX => '.goto_notify'); print $rand_fh "source:$source\ntarget:$target\nusr:$to\nsubject:".@{$msg_hash->{'subject'}}[0]."\nmessage:".@{$msg_hash->{'message'}}[0]."\n"; close $rand_fh; - - my $feedback = system("/usr/bin/goto-notify user-message '$to' '$subject' '$message' '$rand_file' &" ); + + my ($host, $port) = split(':', $target); + my $feedback = system("/usr/bin/goto-notify user-message '$to' '$subject' '$message' '$rand_file' '$host' &" ); return } diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index be587d270..8e7f37918 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -151,6 +151,7 @@ my @job_queue_col_names = ("id INTEGER PRIMARY KEY", "plainname VARCHAR(255) DEFAULT 'none'", "siserver VARCHAR(255) DEFAULT 'none'", "modified INTEGER DEFAULT '0'", + "periodic VARCHAR(6) DEFAULT 'none'", ); # holds all other gosa-si-server @@ -225,6 +226,10 @@ our $logged_in_user_date_of_expiry = 600; # List of month names, used in function daemon_log my @monthnames = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); +# List of accepted periodical xml tags related to cpan modul DateTime +our $check_periodic = {"months"=>'', "weeks"=>'', "days"=>'', "hours"=>'', "minutes"=>''}; + + %cfg_defaults = ( "general" => { "log-file" => [\$log_file, "/var/run/".$prg.".log"], @@ -1327,7 +1332,7 @@ sub msg_to_decrypt { $msg =~ s/
gosa_/
/; my $error= &send_msg_to_target($msg, $hostname, $hostkey, $header, $session_id); if ($error) { - &daemon_log("$session_id ERROR: Some problems occurred while trying to send msg to client '$hostkey': $msg", 1); + &daemon_log("$session_id ERROR: Some problems occurred while trying to send msg to client '$hostname': $msg", 1); } } else @@ -1700,16 +1705,33 @@ sub session_start { sub watch_for_done_jobs { - #CHECK: $heap for what? - my ($kernel,$heap) = @_[KERNEL, HEAP]; + my $kernel = $_[KERNEL]; 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} ) { - my $jobdb_id = $hit->{id}; - my $sql_statement = "DELETE FROM $job_queue_tn WHERE id=$jobdb_id"; - my $res = $job_db->del_dbentry($sql_statement); + while( my ($number, $hit) = each %{$res} ) + { + # Periodical jobs should not be deleted but reactivated with new timestamp instead. + if (exists $check_periodic->{$hit->{periodic}}) + { + my $reactivated_ts = $hit->{timestamp}; + my $act_ts = int(&get_time()); + while ($act_ts > int($reactivated_ts)) # Redo calculation to avoid multiple jobs in the past + { + $reactivated_ts = &calc_timestamp($reactivated_ts, "plus", 1, $hit->{periodic}); + } + my $sql = "UPDATE $job_queue_tn SET status='waiting', timestamp='$reactivated_ts' WHERE id='".$hit->{id}."'"; + my $res = $job_db->exec_statement($sql); + &daemon_log("J INFO: Update periodical job '".$hit->{headertag}."' for client '".$hit->{targettag}."'. New execution time '$reactivated_ts'.", 5); + } + # Non periodical jobs can be deleted. + else + { + my $jobdb_id = $hit->{id}; + my $sql_statement = "DELETE FROM $job_queue_tn WHERE id=$jobdb_id"; + my $res = $job_db->del_dbentry($sql_statement); + } } $kernel->delay_set('watch_for_done_jobs',$job_queue_loop_delay); @@ -1936,7 +1958,7 @@ sub watch_for_new_jobs { my $func_error = &send_msg_to_target($job_msg, $server_address, $GosaPackages_key, $header, "J"); # update status in job queue to ... - # ... 'processing', for jobs: 'reinstall', 'update' + # ... 'processing', for jobs: 'reinstall', 'update', activate_new if (($header =~ /gosa_trigger_action_reinstall/) || ($header =~ /gosa_trigger_activate_new/) || ($header =~ /gosa_trigger_action_update/)) { @@ -1947,7 +1969,7 @@ sub watch_for_new_jobs { # ... 'done', for all other jobs, they are no longer needed in the jobqueue else { my $sql_statement = "UPDATE $job_queue_tn SET status='done' WHERE id=$jobdb_id"; - my $dbres = $job_db->update_dbentry($sql_statement); + my $dbres = $job_db->exec_statement($sql_statement); } diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index ea5bc2a51..88b291008 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -246,6 +246,8 @@ sub process_job_msg { "1". "no mac address specified, neither in target-tag nor in macaddres-tag". ""; + + return ($out_msg); } # Determine plain_name for host @@ -276,6 +278,29 @@ sub process_job_msg { &main::release_ldap_handle($ldap_handle); } + # Check if it is a periodical job + my $periodic = 'none'; + if (exists $msg_hash->{periodic}) + { + $periodic = $msg_hash->{periodic}[0]; + if (not defined $periodic) # Periodic tag is not defined + { + $periodic = ""; + } + + if (not exists $main::check_periodic->{$periodic}) # Periodic tag is not valid + { + &main::daemon_log("$session_id ERROR: Message contains invalid periodic-tag '$periodic'.". + " Please use one of the following tags instead: '".join("', '", keys(%$main::check_periodic))."'.". + " Aborted message: $msg", 1); + $out_msg = "". + "
answer
$main::server_addressGOSA". + "1Message contains invalid periodic-tag '$periodic'". + "
"; + return ($out_msg); + } + } + # Add job to job queue if( $error == 0 ) { my $func_dic = {table=>$main::job_queue_tn, @@ -291,6 +316,7 @@ sub process_job_msg { plainname=>$plain_name, siserver=>"localhost", modified=>"1", + periodic=>$periodic, }; 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 526afd36c..566ba0e57 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -840,7 +840,8 @@ sub check_opsi_res { } sub calc_timestamp { - my ($timestamp, $operation, $value) = @_ ; + my ($timestamp, $operation, $value, $entity) = @_ ; + $entity = defined $entity ? $entity : "seconds"; my $res_timestamp = 0; $value = int($value); @@ -855,12 +856,12 @@ sub calc_timestamp { ); if ($operation eq "plus" || $operation eq "+") { - $dt->add( seconds => $value); + $dt->add($entity => $value); $res_timestamp = $dt->ymd('').$dt->hms(''); } if ($operation eq "minus" || $operation eq "-") { - $dt->subtract(seconds => $value); + $dt->subtract($entity => $value); $res_timestamp = $dt->ymd('').$dt->hms(''); } diff --git a/gosa-si/server/events/databases.pm b/gosa-si/server/events/databases.pm index ac934d53b..881ebb820 100644 --- a/gosa-si/server/events/databases.pm +++ b/gosa-si/server/events/databases.pm @@ -139,9 +139,7 @@ sub delete_jobdb_entry { #} # set job to status 'done', job will be deleted automatically - my $sql_statement = "UPDATE $main::job_queue_tn ". - "SET status='done', modified='1' ". - "$where"; + my $sql_statement = "UPDATE $main::job_queue_tn SET status='done', modified='1', periodic='none' $where"; &main::daemon_log("$session_id DEBUG: $sql_statement", 7); my $res = $main::job_db->update_dbentry( $sql_statement ); diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 5b645e859..2a54b86e0 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -82,13 +82,13 @@ sub send_user_msg { my $delivery_time = @{$msg_hash->{'delivery_time'}}[0]; my $message = @{$msg_hash->{'message'}}[0]; - # keep job queue uptodate if necessary - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# # keep job queue uptodate if necessary +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } # error handling if (not $delivery_time =~ /^\d{14}$/) { @@ -145,12 +145,12 @@ sub recreate_fai_server_db { my ($msg, $msg_hash, $session_id) = @_ ; my $out_msg; - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } $main::fai_server_db->create_table("new_fai_server", \@main::fai_server_col_names); &main::create_fai_server_db("new_fai_server",undef,"dont", $session_id); @@ -165,12 +165,12 @@ sub recreate_fai_release_db { my ($msg, $msg_hash, $session_id) = @_ ; my $out_msg; - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } $main::fai_release_db->create_table("new_fai_release", \@main::fai_release_col_names); &main::create_fai_release_db("new_fai_release", $session_id); @@ -185,12 +185,12 @@ sub recreate_packages_list_db { my ($msg, $msg_hash, $session_id) = @_ ; my $out_msg; - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } &main::create_packages_list_db; @@ -207,13 +207,13 @@ sub get_login_usr_for_client { my $target = @{$msg_hash->{'target'}}[0]; my $client = @{$msg_hash->{'client'}}[0]; - # Set job status - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# # Set job status +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } # If $client is a mac address if ($client =~ /^\w\w:\w\w:\w\w:\w\w:\w\w:\w\w$/i) @@ -270,13 +270,13 @@ sub get_client_for_login_usr { my $target = @{$msg_hash->{'target'}}[0]; my $usr = @{$msg_hash->{'usr'}}[0]; - # Set job status - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# # Set job status +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } # Search for clients where $usr is logged in my $sql_statement = "SELECT * FROM $main::login_users_tn WHERE user LIKE '%$usr%'"; @@ -347,7 +347,7 @@ sub detect_hardware { my $mac = @{$msg_hash->{macaddress}}[0]; my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; &main::daemon_log("$session_id DEBUG: $sql_statement", 7); my $res = $main::job_db->exec_statement($sql_statement); } @@ -371,12 +371,12 @@ sub trigger_reload_syslog_config { my $macaddress = @{$msg_hash->{macaddress}}[0]; - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } my $out_msg = &ClientPackages::new_syslog_config($macaddress, $session_id); my @out_msg_l = ( $out_msg ); @@ -394,12 +394,12 @@ sub trigger_reload_ntp_config { my $macaddress = @{$msg_hash->{macaddress}}[0]; - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } my $out_msg = &ClientPackages::new_ntp_config($macaddress, $session_id); my @out_msg_l = ( $out_msg ); @@ -412,12 +412,12 @@ sub trigger_reload_ldap_config { my ($msg, $msg_hash, $session_id) = @_ ; my $mac = @{$msg_hash->{macaddress}}[0]; - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } my $out_msg = &ClientPackages::new_ldap_config($mac, $session_id); my @out_msg_l = ( $out_msg ); @@ -431,17 +431,17 @@ sub set_activated_for_installation { my $header = @{$msg_hash->{header}}[0]; my $source = @{$msg_hash->{source}}[0]; my $mac= (defined($msg_hash->{'macaddress'}))?@{$msg_hash->{'macaddress'}}[0]:undef; + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; my @out_msg_l; # TODO Sanity check macAddress defined - # update status of job - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# # update status of job +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } # If a client gets a 'set_activated_for_installation' msg, always deliver a fresh 'new_ldap_config' # just for backup and robustness purposes @@ -472,12 +472,12 @@ sub trigger_action_faireboot { &main::change_goto_state('locked', \@{$msg_hash->{macaddress}}, $session_id); &main::change_fai_state('install', \@{$msg_hash->{macaddress}}, $session_id); - # 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 LIKE '$mac' AND status='processing')"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->update_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 LIKE '$mac' AND status='processing')"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->update_dbentry( $sql_statement ); return ( $out_msg ); } @@ -489,13 +489,13 @@ sub trigger_action_lock { # Set LDAP state &main::change_goto_state('locked', \@{$msg_hash->{macaddress}}, $session_id); - # Set job status - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# # Set job status +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } return; } @@ -509,13 +509,13 @@ sub trigger_action_activate { # Set LDAP state &main::change_goto_state('active', \@{$msg_hash->{macaddress}}, $session_id); - # Set job status - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# # Set job status +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } # Create message for client my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $mac); @@ -553,13 +553,13 @@ sub trigger_action_localboot { # Set LDAP state &main::change_fai_state('localboot', \@{$msg_hash->{macaddress}}, $session_id); - # Set job status - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# # Set job status +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } return @out_msg_l; } @@ -573,13 +573,13 @@ sub trigger_action_halt { # Create message for client my $out_msg = &main::create_xml_string(&main::create_xml_hash("trigger_action_halt", $source, $mac)); - # Set job status - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# # Set job status +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } return ($out_msg); } @@ -596,14 +596,6 @@ sub trigger_action_reboot { # Set LDAP state &main::change_fai_state('reboot', \@{$msg_hash->{macaddress}}, $session_id); - # Set job status - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } - return ($out_msg); } @@ -663,13 +655,13 @@ sub trigger_action_instant_update { # Set LDAP state &main::change_fai_state('update', \@{$msg_hash->{macaddress}}, $session_id); - # Set job status - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# # Set job status +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } # Create wakeup message for all foreign server my %data = ( 'macaddress' => \@{$msg_hash->{macaddress}} ); @@ -690,13 +682,13 @@ sub new_key_for_client { # Create message for client my $out_msg = &main::create_xml_string(&main::create_xml_hash("new_key", $source, $mac)); - # Set job status - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# # Set job status +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } return ($out_msg); } @@ -710,13 +702,13 @@ sub trigger_action_rescan { # Create message for client my $out_msg = &main::create_xml_string(&main::create_xml_hash("detect_hardware", $source, $mac)); - # Set job status - my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } +# # Set job status +# my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } return ( $out_msg ); } @@ -724,14 +716,14 @@ sub trigger_action_rescan { sub trigger_action_wake { my ($msg, $msg_hash, $session_id) = @_; - - # Set job status my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; - if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->exec_statement($sql_statement); - } + +# # Set job status +# if( defined $jobdb_id) { +# my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE ((id=$jobdb_id) AND (NOT status='done'))"; +# &main::daemon_log("$session_id DEBUG: $sql_statement", 7); +# my $res = $main::job_db->exec_statement($sql_statement); +# } # Create wakeup message for all foreign server my $out_hash = &create_xml_hash("trigger_wake", "GOSA", "KNOWN_SERVER"); diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index a6e88f97a..cad44ef30 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -16,6 +16,10 @@ for($count = 1; $count <= $zahl; $count++) if($sock->connected()){ + ############################## + # periodical jobs + $data = "
job_trigger_action_reboot
GOSA00:0c:29:4c:4b:0c00:0c:29:4c:4b:0c20090622000000minutes
"; + /* Prepare a hunge bunch of data to be send */ # jobdb add #$data = "
gosa_network_completition
GOSAGOSAws-muc-2
"; @@ -77,7 +81,7 @@ for($count = 1; $count <= $zahl; $count++) #$data = "
gosa_get_client_for_login_usr
GOSA GOSA rettenbe
"; # List all si-server providing opsi - $data = "
gosa_get_hosts_with_module
GOSA linux-cl-7:20081 opsi
"; + #$data = "
gosa_get_hosts_with_module
GOSA linux-cl-7:20081 opsi
"; # Send messages to a user and displayed message via konch #$data = "
gosa_send_user_msg
GOSA GOSA ".base64_encode("eine wichtige nachricht")." admin polle harald 20130101235959 ".base64_encode("kaffeepause")."
"; @@ -214,7 +218,6 @@ for($count = 1; $count <= $zahl; $count++) - $sock->write($data); $answer = "nothing"; $answer = $sock->read(); -- 2.30.2