From: rettenbe Date: Thu, 24 Jan 2008 09:46:27 +0000 (+0000) Subject: add xml-message gosa_count_jobdb to GosaPackages X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6e7c37f8affa32f73e01a162f6426b32aefa14e7;p=gosa.git add xml-message gosa_count_jobdb to GosaPackages add option limit to query_jobdb at GosaPackages git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8582 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/modules/DBsqlite.pm b/gosa-si/modules/DBsqlite.pm index 031702871..2e838333f 100644 --- a/gosa-si/modules/DBsqlite.pm +++ b/gosa-si/modules/DBsqlite.pm @@ -166,64 +166,6 @@ sub add_dbentry { } } - -# error-flags -# 1 no table ($table) defined -# 2 no restriction parameter ($restric_pram) defined -# 3 no restriction value ($restric_val) defined -# 4 column name not known in table -# 5 no column names to change specified -#sub update_dbentry { -# my $self = shift; -# my $arg = shift; -# -# -# # check completeness of function parameter -# # extract table statement from arg hash -# my $table = $arg->{table}; -# if (not defined $table) { -# return 1; -# } else { -# delete $arg->{table}; -# } -# -# # extract where parameter from arg hash -# my $where_statement = ""; -# if( exists $arg->{where} ) { -# my $where_hash = @{ $arg->{where} }[0]; -# if( 0 < keys %{ $where_hash } ) { -# my @where_list; -# while( my ($rest_pram, $rest_val) = each %{ $where_hash } ) { -# my $statement; -# if( $rest_pram eq 'timestamp' ) { -# $statement = "$rest_pram<'@{ $rest_val }[0]'"; -# } else { -# $statement = "$rest_pram='@{ $rest_val }[0]'"; -# } -# push( @where_list, $statement ); -# } -# $where_statement .= "WHERE ".join('AND ', @where_list); -# } -# } -# -# # extract update parameter from arg hash -# my $update_hash = @{ $arg->{update} }[0]; -# my $update_statement = ""; -# if( 0 < keys %{ $update_hash } ) { -# my @update_list; -# while( my ($rest_pram, $rest_val) = each %{ $update_hash } ) { -# my $statement = "$rest_pram='@{ $rest_val }[0]'"; -# push( @update_list, $statement ); -# } -# $update_statement .= join(', ', @update_list); -# } -# -# my $sql_statement = "UPDATE $table SET $update_statement $where_statement"; -# &create_lock($self,'update_dbentry'); -# my $db_answer = $self->{dbh}->do($sql_statement); -# &remove_lock($self,'update_dbentry'); -# return $db_answer; -#} sub update_dbentry { my ($self, $sql)= @_; my $db_answer= &exec_statement($self, $sql); @@ -260,7 +202,9 @@ sub get_table_columns { sub select_dbentry { my ($self, $sql)= @_; - + my $error= 0; + my $answer= {}; + my $db_answer= &exec_statement($self, $sql); # fetch column list of db and create a hash with column_name->column_value of the select query @@ -268,7 +212,6 @@ sub select_dbentry { my $table = $1; my $column_list = &get_table_columns($self, $table); my $list_len = @{ $column_list } ; - my $answer = {}; my $hit_counter = 0; foreach my $hit ( @{ $db_answer }) { $hit_counter++; diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index 88b5b65e0..04a1f29c5 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -346,7 +346,7 @@ sub process_gosa_msg { elsif ($header eq 'delete_jobdb_entry') { $out_msg = &delete_jobdb_entry } elsif ($header eq 'clear_jobdb') { $out_msg = &clear_jobdb } elsif ($header eq 'update_status_jobdb_entry' ) { $out_msg = &update_status_jobdb_entry } - elsif ($header eq 'update_timestamp_jobdb_entry' ) { $out_msg = &update_timestamp_jobdb_entry } + elsif ($header eq 'count_jobdb' ) { $out_msg = &count_jobdb } else { # msg could not be assigned to core function # fetch all available eventhandler under $server_event_dir @@ -528,6 +528,32 @@ sub get_update_statement { return $update_str; } +sub get_limit_statement { + my ($msg, $msg_hash)= @_; + my $error= 0; + my $limit_str = ""; + my ($from, $to); + + if( not exists $msg_hash->{'limit'} ) { $error++; }; + + if( $error == 0 ) { + eval { + my $limit= @{$msg_hash->{'limit'}}[0]; + $from= @{$limit->{'from'}}[0]; + $to= @{$limit->{'to'}}[0]; + }; + if( $@ ) { + $error++; + } + } + + if( $error == 0 ) { + $limit_str= "LIMIT $from, $to"; + } + + return $limit_str; +} + sub query_jobdb { my ($msg) = @_; my $msg_hash = &transform_msg2hash($msg); @@ -536,15 +562,35 @@ sub query_jobdb { my $select= &get_select_statement($msg, $msg_hash); my $table= $main::job_queue_table_name; my $where= &get_where_statement($msg, $msg_hash); - my $sql_statement= "SELECT $select FROM $table $where"; + my $limit= &get_limit_statement($msg, $msg_hash); + my $sql_statement= "SELECT $select FROM $table $where $limit"; # execute db query my $res_hash = $main::job_db->select_dbentry($sql_statement); my $out_xml = &db_res_2_xml($res_hash); + + return $out_xml; +} + + +sub count_jobdb { + my ($msg)= @_; + my $out_xml= "error"; + + # prepare query sql statement + my $table= $main::job_queue_table_name; + my $sql_statement= "SELECT * FROM $table "; + # execute db query + my $res_hash = $main::job_db->select_dbentry($sql_statement); + + my $count = keys(%{$res_hash}); + $out_xml= "$count"; + return $out_xml; } + sub delete_jobdb_entry { my ($msg) = @_ ; my $msg_hash = &transform_msg2hash($msg); diff --git a/gosa-si/modules/ServerPackages.pm b/gosa-si/modules/ServerPackages.pm index 80ce0ada7..ceb926825 100644 --- a/gosa-si/modules/ServerPackages.pm +++ b/gosa-si/modules/ServerPackages.pm @@ -292,6 +292,10 @@ sub get_ip { #=============================================================================== sub register_at_bus { + + + print STDERR ">>>>>>>>>>>>>>>>>>>>>>>>1\n"; + # add bus to known_server_db my $res = $main::known_server_db->add_dbentry( {table=>'known_server', primkey=>'hostname', @@ -300,6 +304,7 @@ sub register_at_bus { hostkey=>$bus_passwd, timestamp=>&get_time, } ); + print STDERR ">>>>>>>>>>>>>>>>>>>>>>>>2\n"; my $msg_hash = &create_xml_hash("here_i_am", $server_address, $bus_address); my $answer = ""; $answer = &send_msg_hash2address($msg_hash, $bus_address, $bus_passwd); @@ -452,7 +457,8 @@ sub process_incoming_msg { else { if ($target eq "*") { # msg is for all clients - my $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients'} ); + my $sql_statement = "SELECT * FROM known_clients"; + my $query_res = $main::known_clients_db->select_dbentry( $sql_statement ); while( my ($hit_num, $hit) = each %{ $query_res } ) { $host_name = $hit->{hostname}; $host_key = $hit->{hostkey}; @@ -465,15 +471,17 @@ sub process_incoming_msg { my $host_key; - if( not defined $host_key ) { - my $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients', hostname=>$target} ); + if( not defined $host_key ) { + my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$target'"; + my $query_res = $main::known_clients_db->select_dbentry( $sql_statement ); if( 1 == keys %{$query_res} ) { $host_key = $query_res->{1}->{host_key}; } } if( not defined $host_key ) { - my $query_res = $main::known_server_db->select_dbentry( {table=>'known_server', hostname=>$target} ); + my $sql_statement = "SELECT * FROM known_server WHERE hostname='$target'"; + my $query_res = $main::known_server_db->select_dbentry( $sql_statement ); if( 1 == keys %{$query_res} ) { $host_key = $query_res->{1}->{host_key}; } @@ -535,7 +543,8 @@ sub new_passwd { my $query_res; # check known_clients_db - $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients', hostname=>$source_name} ); + my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$source_name'"; + $query_res = $main::known_clients_db->select_dbentry( $sql_statement ); if( 1 == keys %{$query_res} ) { my $update_hash = { table=>'known_clients' }; $update_hash->{where} = [ { hostname=>[$source_name] } ]; diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index f095d31a1..bcfef94a1 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -12,20 +12,23 @@ if($sock->connected()){ /* Prepare a hunge bunch of data to be send */ # add -#$data = "
gosa_ping
10.89.1.155:2008210.89.1.155:20080
"; #$data = "
job_ping
10.89.1.155:2008300:1B:77:04:8A:6C 19700101000000
"; #$data = "
job_sayHello
10.89.1.155:2008300:1B:77:04:8A:6C 20130102133900
"; -$data = "
job_ping
10.89.1.155:2008300:1B:77:04:8A:6C 20130102133900
"; +#$data = "
job_ping
10.89.1.155:2008300:1B:77:04:8A:6C 20130102133900
"; # delete -#$data = "
gosa_delete_jobdb_entry
error
"; +#$data = "
gosa_delete_jobdb_entry
3
"; # update #$data = "
gosa_update_status_jobdb_entry
waiting processing update
"; # query -#$data = "
gosa_query_jobdb
andgt2le4
"; -#$data= "
gosa_query_jobdb
waiting
"; +#$data = "
gosa_query_jobdb
andgt0le5
"; +$data= "
gosa_query_jobdb
ping03
"; + +# count +#$data = "
gosa_count_jobdb
"; + # clear