summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e975536)
raw | patch | inline | side by side (parent: e975536)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 8 Jan 2008 14:46:30 +0000 (14:46 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 8 Jan 2008 14:46:30 +0000 (14:46 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8250 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/gosa-si-server | patch | blob | history | |
gosa-si/modules/DBsqlite.pm | patch | blob | history | |
gosa-si/modules/GosaPackages.pm | patch | blob | history | |
gosa-si/tests/client.php | patch | blob | history |
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 24295fba0798bae5eb3474e77a8012f9c7eff25a..4e4097a89355b031a1a2052bca67659a0ef1e8b0 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
}
# connect to gosa-si job queue
-my @job_col_names = ("timestamp", "status", "result", "header", "target", "xmlmessage", "macaddress");
+my @job_col_names = ("timestamp", "status", "result", "headertag", "targettag", "xmlmessage", "macaddress");
$job_db = GOSA::DBsqlite->new($job_queue_file_name);
$job_db->create_table('jobs', \@job_col_names);
print $act_client $in_msg."\n";
#my $act_pipe = $busy_child{$pid}{pipe_rd};
- sleep(10);
- close ($act_client);
delete $busy_child{$pid};
$free_child{$pid} = $child_hash;
+ # give the client a chance to read
+ sleep(2);
+ close ($act_client);
}
}
}
my $timestamp = "$year$month$monthday$hours$minutes$seconds";
- #my $res = $job_db->select_dbentry( { table=>$job_queue_table_name, status=>'waiting', timestamp=>'$timestamp'} );
- my $res = $job_db->select_dbentry( { table=>$job_queue_table_name, status=>'waiting', timestamp=>'2007010709014800'} );
+ my $res = $job_db->select_dbentry( { table=>$job_queue_table_name, status=>'waiting', timestamp=>$timestamp } );
while( my ($id, $hit) = each %{$res} ) {
if (not defined $target) {
&daemon_log("ERROR: no host found for mac address: $job_msg_hash->{mac}[0]", 1);
+ &daemon_log("xml message: $hit->{xmlmessage}", 5);
+ my $update_hash = { table=>$job_queue_table_name,
+ update=> [ { status=>['error'], result=>["no host found for mac address"] } ],
+ where=> [ { ROWID=>[$jobdb_id] } ],
+ };
+ my $res = $job_db->update_dbentry($update_hash);
+
next;
}
my $error = &send_msg_hash2address($out_msg_hash, "$gosa_ip:$gosa_port", $gosa_passwd);
+#######################
+# TODO exchange ROWID with jobid, insert column jobid in table jobs befor
+
if ($error == 0) {
- my $sql = "UPDATE '$job_queue_table_name' SET status='processing', target='$target' WHERE ROWID='$jobdb_id'";
+ my $sql = "UPDATE '$job_queue_table_name' SET status='processing', targettag='$target' WHERE ROWID='$jobdb_id'";
my $res = $job_db->exec_statement($sql);
+ } else {
+ my $update_hash = { table=>$job_queue_table_name,
+ update=> [ { status=>'error' } ],
+ where=> [ { ROWID=>$jobdb_id } ],
+ };
+ my $res = $job_db->update_dbentry($update_hash);
}
-
}
index 76014acdea135a8718846c73ddac3ddf2b7e1cfc..9f341ec5e132ab1eb83f06fb8da75227d6bb1649 100644 (file)
my $sql_statement = " INSERT INTO $table VALUES ('".join("', '", @add_list)."')";
print " INSERT INTO $table VALUES ('".join("', '", @add_list)."')\n";
- $obj->{dbh}->do($sql_statement);
+ my $db_res = $obj->{dbh}->do($sql_statement);
+ print " DB result: $db_res\n";
return 0;
}
} else {
delete $arg->{table};
}
+
# extract where parameter from arg hash
- my $restric_pram = $arg->{where};
- if (not defined $restric_pram) {
- return 2;
- } else {
- delete $arg->{'where'};
- }
- # extrac where value from arg hash
- my $restric_val = $arg->{$restric_pram};
- if (not defined $restric_val) {
- return 3;
- } else {
- delete $arg->{$restric_pram};
- }
-
- # check wether table has all specified columns
- my $columns = {};
- my @res = @{$obj->{dbh}->selectall_arrayref("pragma table_info('$table')")};
- foreach my $column (@res) {
- $columns->{@$column[1]} = "";
- }
- my @pram_list = keys %$arg;
- foreach my $pram (@pram_list) {
- if (not exists $columns->{$pram}) {
- return 4;
+ 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);
}
}
-
-
- # select all changes
- my @change_list;
- my $sql_part;
- while (my($pram, $val) = each(%{$arg})) {
- push(@change_list, "$pram='$val'");
- }
-
- if (not @change_list) {
- return 5;
+ # 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);
}
- $obj->{dbh}->do("UPDATE $table SET ".join(', ',@change_list)." WHERE $restric_pram='$restric_val'");
- return 0;
+ my $sql_statement = "UPDATE $table SET $update_statement $where_statement";
+ my $db_answer = $obj->{dbh}->do($sql_statement);
+ return $db_answer;
}
} else {
delete $arg->{table};
}
- # extract where parameter from arg hash
- my $restric_pram = $arg->{where};
- if (not defined $restric_pram) {
- return 2;
- } else {
- delete $arg->{'where'};
+
+ # collect select statements
+ my @del_list;
+ while (my ($pram, $val) = each %{$arg}) {
+ if ( $pram eq 'timestamp' ) {
+ push(@del_list, "$pram < '$val'");
+ } else {
+ push(@del_list, "$pram = '$val'");
+ }
}
- # extrac where value from arg hash
- my $restric_val = $arg->{$restric_pram};
- if (not defined $restric_val) {
- return 3;
+
+ my $where_statement;
+ if( not @del_list ) {
+ $where_statement = "";
} else {
- delete $arg->{$restric_pram};
- }
-
- # check wether entry exists
- my $res = @{$obj->{dbh}->selectall_arrayref( "SELECT * FROM $table WHERE $restric_pram='$restric_val'")};
- if ($res == 0) {
- return 4;
+ $where_statement = "WHERE ".join(' AND ', @del_list);
}
- $obj->{dbh}->do("DELETE FROM $table WHERE $restric_pram='$restric_val'");
+ my $sql_statement = "DELETE FROM $table $where_statement";
+ my $db_res = $obj->{dbh}->do($sql_statement);
- return 0;
+ return $db_res;
}
} else {
push(@select_list, "$pram = '$val'");
}
-
}
+
if (@select_list == 0) {
$sql_statement = "SELECT ROWID, * FROM '$table'";
} else {
index a441a2fe1bea7a153c49e98fa16aac85d79c5952..eea707322b1140f74b22f5d9ca1cd3b0c4d928cc 100644 (file)
}
# create gosa job queue as a SQLite DB
-my @col_names = ("id", "timestamp", "status", "result", "header",
- "target", "xml", "mac");
my $table_name = "jobs";
my $sqlite = GOSA::DBsqlite->new($job_queue_file_name);
-#$sqlite->create_table($table_name, \@col_names);
# decide wether msg is a core function or a event handler
if ( $header eq 'query_jobdb') { $out_msg = &query_jobdb }
+ 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 }
else {
# msg could not be assigned to core function
# fetch all available eventhandler under $server_event_dir
timestamp=>@{$msg_hash->{timestamp}}[0],
status=>'waiting',
result=>'none',
- header=>$header,
- target=>$target,
+ headertag=>$header,
+ targettag=>$target,
xmlmessage=>$msg,
macaddress=>@{$msg_hash->{mac}}[0],
};
}
&main::daemon_log("GosaPackages: $header job successfully added to job queue", 3);
- return;
+ return "<xml><1>$res</1></xml>";
}
return $out_xml;
}
+sub delete_jobdb_entry {
+ my ($msg) = @_ ;
+ my $msg_hash = &transform_msg2hash($msg);
+
+ # prepare query sql statement
+ my @where = @{$msg_hash->{where}};
+ my $where_hash = {table=>$main::job_queue_table_name };
+ foreach my $where_pram (@where) {
+ my $where_val = @{$msg_hash->{$where_pram}}[0];
+ if (defined $where_val) {
+ $where_hash->{$where_pram} = $where_val;
+ }
+ }
+
+ # execute db query
+ my $db_res = $main::job_db->del_dbentry($where_hash);
+
+ my $res;
+ if( $db_res > 0 ) {
+ $res = 0 ;
+ } else {
+ $res = 1;
+ }
+
+ # prepare xml answer
+ my $out_xml = "<xml><1>$res</1></xml>";
+ return $out_xml;
+
+}
+
+sub clear_jobdb {
+ my ($msg) = @_ ;
+ my $msg_hash = &transform_msg2hash($msg);
+
+ my $where_hash = {table=>$main::job_queue_table_name };
+
+ # execute db query
+ my $db_res = $main::job_db->del_dbentry($where_hash);
+ print STDERR "db_res=$db_res\n";
+ my $res;
+ if( $db_res eq '0E0' ) {
+ $res = 0 ;
+ } else {
+ $res = 1;
+ }
+
+ # prepare xml answer
+ my $out_xml = "<xml><1>$res</1></xml>";
+ return $out_xml;
+}
+
+sub update_status_jobdb_entry {
+ my ($msg) = @_ ;
+ my $msg_hash = &transform_msg2hash($msg);
+
+ # prepare query sql statement
+ my $update_hash = {table=>$main::job_queue_table_name };
+ if( exists $msg_hash->{where} ) {
+ $update_hash->{where} = $msg_hash->{where};
+ } else {
+ $update_hash->{where} = [];
+ }
+
+ if( not exists $msg_hash->{update}[0]->{status} ) {
+ return "<xml><1>1</1></xml>";
+ }
+ $update_hash->{update} = [ { status=>$msg_hash->{update}[0]->{status} } ];
+ #$update_hash->{update} = $msg_hash->{update};
+
+ # execute db query
+ my $db_res = $main::job_db->update_dbentry($update_hash);
+
+ # transform db answer to error returnment
+ my $res;
+ if( $db_res > 0 ) {
+ $res = 0 ;
+ } else {
+ $res = 1;
+ }
+
+ # prepare xml answer
+ my $out_xml = "<xml><1>$res</1></xml>";
+ return $out_xml;
+}
+
+sub update_timestamp_jobdb_entry {
+ my ($msg) = @_ ;
+ my $msg_hash = &transform_msg2hash($msg);
+
+ # prepare query sql statement
+ my $update_hash = {table=>$main::job_queue_table_name };
+ if( exists $msg_hash->{where} ) {
+ $update_hash->{where} = $msg_hash->{where};
+ } else {
+ $update_hash->{where} = [];
+ }
+
+ if( not exists $msg_hash->{update}[0]->{timestamp} ) {
+ return "<xml><1>1</1></xml>";
+ }
+
+ $update_hash->{update} = [ { timestamp=>$msg_hash->{update}[0]->{timestamp} } ];
+
+ # execute db query
+ my $db_res = $main::job_db->update_dbentry($update_hash);
+
+ # transform db answer to error returnment
+ my $res;
+ if( $db_res > 0 ) {
+ $res = 0 ;
+ } else {
+ $res = 1;
+ }
+
+ # prepare xml answer
+ my $out_xml = "<xml><1>$res</1></xml>";
+ return $out_xml;
+
+}
1;
index 30c39b9d6c2105a9bedde1e1ded1a4f3b65ad433..83f4470d6793cdad67f47ac5ddda6a110e546854 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
if($sock->connected()){
/* Prepare a hunge bunch of data to be send */
+
+# add
#$data = "<xml><header>gosa_ping</header><source>10.89.1.155:20082</source><target></target><mac>11:22:33:44:55</mac></xml>";
#$data = "<xml> <header>job_ping</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>19700101000000</timestamp> </xml>";
#$data = "<xml> <header>job_sayHello</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133900</timestamp> </xml>";
#$data = "<xml> <header>job_ping</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133900</timestamp> </xml>";
- $data = "<xml><header>gosa_query_jobdb</header><where>status</where><status>waiting</status></xml>";
- $sock->write($data);
+# delete
+ #$data = "<xml> <header>gosa_delete_jobdb_entry</header> <where>headertag</where> <headertag>sayHello</headertag> </xml>";
+ $data = "<xml> <header>gosa_clear_jobdb</header> </xml>";
+
+# update
+ #$data = "<xml> <header>gosa_update_status_jobdb_entry</header> <where> <status>waiting</status> </where> <update> <status>processing</status> </update></xml>";
+ #$data = "<xml> <header>gosa_update_status_jobdb_entry</header> <update> <status>waiting</status> </update></xml>";
+ #$data = "<xml> <header>gosa_update_timestamp_jobdb_entry</header> <update> <timestamp>20130123456789</timestamp> </update></xml>";
+
+# query
+ #$data = "<xml><header>gosa_query_jobdb</header><where>status</where><status>waiting</status></xml>";
+
+# clear
+ #$data = "<xml> <header>gosa_clear_jobdb</header> </xml>";
- #$sock->setEncryptionKey("ferdinand_frost");
+ $sock->write($data);
$answer = $sock->read();
echo "$answer\n";