From 820c61cb9315dd7de9d6ac01246916b7e81f3750 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Tue, 13 Oct 2009 10:20:48 +0000 Subject: [PATCH] * gosa-si-server: initializing of message procession changed, old: watcher continously invoke message procession, new: direct invokation by incoming message * gosa-si-server: writes micro seconds to log too * opsi_com: refactoring, opsi calls are in a seperate function now git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14590 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 18 ++-- gosa-si/server/events/opsi_com.pm | 173 +++++++++--------------------- gosa-si/tests/client.php | 19 +++- 3 files changed, 76 insertions(+), 134 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 7b1a5569b..bc28f7482 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -39,7 +39,7 @@ use Digest::MD5 qw(md5 md5_hex md5_base64); use XML::Simple; use Data::Dumper; use Sys::Syslog qw( :DEFAULT setlogsock); -use Time::HiRes qw( usleep); +use Time::HiRes qw( usleep clock_gettime ); use Cwd; use File::Spec; use File::Basename; @@ -51,6 +51,7 @@ use POE qw(Component::Server::TCP Wheel::Run Filter::Reference); use Net::LDAP; use Net::LDAP::Util qw(:escape); + # revision number of server and program name my $server_headURL; my $server_revision; @@ -387,10 +388,13 @@ sub daemon_log { $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday; $year+=1900; - + # Microseconds since epoch + my $microSeconds = sprintf("%.2f", clock_gettime ( 'CLOCK_REALTIME' )); + $microSeconds =~ s/^\d*(.\d\d)$/$1/; + # Build log message and write it to log file and commandline chomp($msg); - my $log_msg = "$month $monthday $hours:$minutes:$seconds $prg $msg\n"; + my $log_msg = "$month $monthday $hours:$minutes:$seconds$microSeconds $prg $msg\n"; flock(LOG_HANDLE, LOCK_EX); seek(LOG_HANDLE, 0, 2); print LOG_HANDLE $log_msg; @@ -1311,7 +1315,7 @@ sub msg_to_decrypt { module=>$module, sessionid=>$session_id, } ); - + $kernel->yield('watch_for_next_tasks'); } # target is own address with forward_to_gosa-tag pointing at myself -> forward to gosa @@ -1431,6 +1435,7 @@ sub msg_to_decrypt { sessionid=>$session_id, } ); $done = 1; + $kernel->yield('watch_for_next_tasks'); } @@ -1705,7 +1710,6 @@ sub session_start { $kernel->yield('register_at_foreign_servers'); $kernel->yield('create_fai_server_db', $fai_server_tn ); $kernel->yield('create_fai_release_db', $fai_release_tn ); - $kernel->yield('watch_for_next_tasks'); $kernel->sig(USR1 => "sig_handler"); $kernel->sig(USR2 => "recreate_packages_db"); $kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay); @@ -2277,8 +2281,6 @@ sub watch_for_next_tasks { my $sql = "DELETE FROM $incoming_tn WHERE id=$message_id"; my $res = $incoming_db->exec_statement($sql); } - - $kernel->delay_set('watch_for_next_tasks', 1); } @@ -3696,6 +3698,7 @@ POE::Component::Server::TCP->new( }, InlineStates => { msg_to_decrypt => \&msg_to_decrypt, + watch_for_next_tasks => \&watch_for_next_tasks, next_task => \&next_task, task_result => \&handle_task_result, task_done => \&handle_task_done, @@ -3717,7 +3720,6 @@ POE::Session->create( task_result => \&handle_task_result, task_done => \&handle_task_done, task_debug => \&handle_task_debug, - watch_for_next_tasks => \&watch_for_next_tasks, watch_for_new_messages => \&watch_for_new_messages, watch_for_delivery_messages => \&watch_for_delivery_messages, watch_for_done_messages => \&watch_for_done_messages, diff --git a/gosa-si/server/events/opsi_com.pm b/gosa-si/server/events/opsi_com.pm index 48ab4e2ff..abd23984e 100644 --- a/gosa-si/server/events/opsi_com.pm +++ b/gosa-si/server/events/opsi_com.pm @@ -48,6 +48,7 @@ use warnings; use GOSA::GosaSupportDaemon; use Data::Dumper; use XML::Quote qw(:all); +use Time::HiRes qw( time ); BEGIN {} @@ -62,7 +63,7 @@ my $licenseTyp_hash = { 'OEM'=>'', 'VOLUME'=>'', 'RETAIL'=>''}; # ---------------------------------------------------------------------------- -# S U B R O U T I N E S +# external methods handling the comunication with GOsa/GOsa-si # ---------------------------------------------------------------------------- @@ -148,11 +149,10 @@ sub opsi_add_product_to_client { method => 'setProductActionRequest', params => [ $productId, $hostId, "setup" ], id => 1, }; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); + if (&check_opsi_res($res)) { return ( (caller(0))[3]." : ".$_, 1 ); }; - # return message return ( &create_xml_string($out_hash) ); } @@ -2034,6 +2034,7 @@ sub opsi_getLicenseInformationForProduct { # @param # sub opsi_getPool { + my $startTime = Time::HiRes::time; my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; @@ -2122,6 +2123,9 @@ sub opsi_getPool { } $out_hash->{licenses} = [$res_hash]; + my $endTime = Time::HiRes::time; + my $elapsedTime = sprintf("%.4f", ($endTime - $startTime)); + &main::daemon_log("0 DEBUG: time to process gosa-si message '$header' : $elapsedTime seconds", 1034); return ( &create_xml_string($out_hash) ); } @@ -2443,27 +2447,37 @@ print STDERR Dumper $pram1; } +# ---------------------------------------------------------------------------- +# internal methods handling the comunication with Opsi +# ---------------------------------------------------------------------------- + +sub _callOpsi { + my %arg = ('method'=>undef, 'params'=>[], 'id'=>1, @_); + + my $callObject = { + method => $arg{method}, + params => $arg{params}, + id => $arg{id}, + }; + + my $startTime = Time::HiRes::time; + my $opsiResult = $main::opsi_client->call($main::opsi_url, $callObject); + my $endTime = Time::HiRes::time; + my $elapsedTime = sprintf("%.4f", ($endTime - $startTime)); + + &main::daemon_log("0 DEBUG: time to process opsi call '$arg{method}' : $elapsedTime seconds", 1034); + return $opsiResult; +} sub _getLicensePool_hash { - my %arg = ( - 'licensePoolId' => undef, - @_, - ); + my %arg = ( 'licensePoolId' => undef, @_ ); if (not defined $arg{licensePoolId} ) { return ("function requires licensePoolId as parameter", 1); } - # Fetch pool infos from Opsi server - my $callobj = { - method => 'getLicensePool_hash', - params => [ $arg{licensePoolId} ], - id => 1, - }; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - - # Check Opsi error + my $res = &_callOpsi( method => 'getLicensePool_hash', params =>[$arg{licensePoolId}], id => 1 ); my ($res_error, $res_error_str) = &check_opsi_res($res); if ($res_error){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } @@ -2471,15 +2485,8 @@ sub _getLicensePool_hash { } sub _getSoftwareLicenses_listOfHashes { - # Fetch licenses associated to the given pool - my $callobj = { - method => 'getSoftwareLicenses_listOfHashes', - params => [ ], - id => 1, - }; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - - # Check Opsi error + + my $res = &_callOpsi( method => 'getSoftwareLicenses_listOfHashes' ); my ($res_error, $res_error_str) = &check_opsi_res($res); if ($res_error){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } @@ -2487,21 +2494,9 @@ sub _getSoftwareLicenses_listOfHashes { } sub _getSoftwareLicenseUsages_listOfHashes { - my %arg = ( - 'hostId' => "", - 'licensePoolId' => "", - @_, - ); - - # Fetch pool infos from Opsi server - my $callobj = { - method => 'getSoftwareLicenseUsages_listOfHashes', - params => [ $arg{hostId}, $arg{licensePoolId} ], - id => 1, - }; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); + my %arg = ( 'hostId' => "", 'licensePoolId' => "", @_ ); - # Check Opsi error + my $res = &_callOpsi( method=>'getSoftwareLicenseUsages_listOfHashes', params=>[ $arg{hostId}, $arg{licensePoolId} ] ); my ($res_error, $res_error_str) = &check_opsi_res($res); if ($res_error){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } @@ -2509,11 +2504,7 @@ sub _getSoftwareLicenseUsages_listOfHashes { } sub _removeSoftwareLicenseFromLicensePool { - my %arg = ( - 'softwareLicenseId' => undef, - 'licensePoolId' => undef, - @_, - ); + my %arg = ( 'softwareLicenseId' => undef, 'licensePoolId' => undef, @_ ); if (not defined $arg{softwareLicenseId} ) { return ("function requires softwareLicenseId as parameter", 1); @@ -2522,15 +2513,7 @@ sub _removeSoftwareLicenseFromLicensePool { return ("function requires licensePoolId as parameter", 1); } - # Remove software license from license pool - my $callobj = { - method => 'removeSoftwareLicenseFromLicensePool', - params => [ $arg{softwareLicenseId}, $arg{licensePoolId} ], - id => 1, - }; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - - # Check Opsi error + my $res = &_callOpsi( method=>'removeSoftwareLicenseFromLicensePool', params=>[ $arg{softwareLicenseId}, $arg{licensePoolId} ] ); my ($res_error, $res_error_str) = &check_opsi_res($res); if ($res_error){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } @@ -2538,11 +2521,7 @@ sub _removeSoftwareLicenseFromLicensePool { } sub _deleteSoftwareLicense { - my %arg = ( - 'softwareLicenseId' => undef, - 'removeFromPools' => "false", - @_, - ); + my %arg = ( 'softwareLicenseId' => undef, 'removeFromPools' => "false", @_ ); if (not defined $arg{softwareLicenseId} ) { return ("function requires softwareLicenseId as parameter", 1); @@ -2552,15 +2531,7 @@ sub _deleteSoftwareLicense { $removeFromPools = "removeFromPools"; } - # Fetch - my $callobj = { - method => 'deleteSoftwareLicense', - params => [ $arg{softwareLicenseId}, $removeFromPools ], - id => 1, - }; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - - # Check Opsi error + my $res = &_callOpsi( method=>'deleteSoftwareLicense', params=>[ $arg{softwareLicenseId}, $removeFromPools ] ); my ($res_error, $res_error_str) = &check_opsi_res($res); if ($res_error){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } @@ -2568,23 +2539,13 @@ sub _deleteSoftwareLicense { } sub _getLicensePoolId { - my %arg = ( - 'productId' => undef, - @_, - ); + my %arg = ( 'productId' => undef, @_ ); if (not defined $arg{productId} ) { return ("function requires productId as parameter", 1); } - my $callobj = { - method => 'getLicensePoolId', - params => [ $arg{productId} ], - id => 1, - }; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - - # Check Opsi error + my $res = &_callOpsi( method => 'getLicensePoolId', params => [ $arg{productId} ] ); my ($res_error, $res_error_str) = &check_opsi_res($res); if ($res_error){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } @@ -2592,23 +2553,13 @@ sub _getLicensePoolId { } sub _getLicenseContract_hash { - my %arg = ( - 'licenseContractId' => undef, - @_, - ); + my %arg = ( 'licenseContractId' => undef, @_ ); if (not defined $arg{licenseContractId} ) { return ("function requires licenseContractId as parameter", 1); } - my $callobj = { - method => 'getLicenseContract_hash', - params => [ $arg{licenseContractId} ], - id => 1, - }; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - - # Check Opsi error + my $res = &_callOpsi( method => 'getLicenseContract_hash', params => [ $arg{licenseContractId} ] ); my ($res_error, $res_error_str) = &check_opsi_res($res); if ($res_error){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } @@ -2623,18 +2574,11 @@ sub _createLicenseContract { 'notificationDate' => undef, 'expirationDate' => undef, 'notes' => undef, - @_, - ); - - # Create license contract at Opsi server - my $callobj = { - method => 'createLicenseContract', - params => [ $arg{licenseContractId}, $arg{partner}, $arg{conclusionDate}, $arg{notificationDate}, $arg{expirationDate}, $arg{notes} ], - id => 1, - }; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); + @_ ); - # Check Opsi error + my $res = &_callOpsi( method => 'createLicenseContract', + params => [ $arg{licenseContractId}, $arg{partner}, $arg{conclusionDate}, $arg{notificationDate}, $arg{expirationDate}, $arg{notes} ], + ); my ($res_error, $res_error_str) = &check_opsi_res($res); if ($res_error){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } @@ -2649,17 +2593,11 @@ sub _createSoftwareLicense { 'maxInstallations' => undef, 'boundToHost' => undef, 'expirationDate' => undef, - @_, - ); + @_ ); - my $callobj = { - method => 'createSoftwareLicense', + my $res = &_callOpsi( method => 'createSoftwareLicense', params => [ $arg{softwareLicenseId}, $arg{licenseContractId}, $arg{licenseType}, $arg{maxInstallations}, $arg{boundToHost}, $arg{expirationDate} ], - id => 1, - }; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - - # Check Opsi error + ); my ($res_error, $res_error_str) = &check_opsi_res($res); if ($res_error){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } @@ -2671,8 +2609,7 @@ sub _addSoftwareLicenseToLicensePool { 'softwareLicenseId' => undef, 'licensePoolId' => undef, 'licenseKey' => undef, - @_, - ); + @_ ); if (not defined $arg{softwareLicenseId} ) { return ("function requires softwareLicenseId as parameter", 1); @@ -2681,15 +2618,7 @@ sub _addSoftwareLicenseToLicensePool { return ("function requires licensePoolId as parameter", 1); } - # Add software license to license pool - my $callobj = { - method => 'addSoftwareLicenseToLicensePool', - params => [ $arg{softwareLicenseId}, $arg{licensePoolId}, $arg{licenseKey} ], - id => 1, - }; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - - # Check Opsi error + my $res = &_callOpsi( method => 'addSoftwareLicenseToLicensePool', params => [ $arg{softwareLicenseId}, $arg{licensePoolId}, $arg{licenseKey} ] ); my ($res_error, $res_error_str) = &check_opsi_res($res); if ($res_error){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index f01246d9e..7ecf664d6 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -4,7 +4,13 @@ require_once("../../gosa-core/include/class_socketClient.inc"); error_reporting(E_ALL); -$zahl= 1; +function microtime_float() +{ + list($usec, $sec) = explode(" ", microtime()); + return ((float)$usec + (float)$sec); +} + +$zahl= 10; for($count = 1; $count <= $zahl; $count++) { @@ -47,7 +53,7 @@ for($count = 1; $count <= $zahl; $count++) #$data = "
gosa_opsi_getSoftwareLicense_hash
GOSA00:01:6C:9D:B9:FAl_2009-09-22_09:50:58_0
"; - #$data = "
gosa_opsi_getPool
GOSA00:01:6C:9D:B9:FALicensePool
"; + $data = "
gosa_opsi_getPool
GOSA00:01:6C:9D:B9:FALicensePool
"; #$data = "
gosa_opsi_removeLicense
GOSA00:01:6C:9D:B9:FALicensePooll_2009-09-22_14:06:11
"; @@ -56,7 +62,7 @@ for($count = 1; $count <= $zahl; $count++) #$data = "
gosa_opsi_boundHostToLicense
GOSA00:01:6C:9D:B9:FAandisLizenzkrakenarme.intranet.gonicus.de
"; #$data = "
gosa_opsi_unboundHostFromLicense
GOSA00:01:6C:9D:B9:FAandisLizenz
"; - $data = "
gosa_opsi_getAllSoftwareLicenses
GOSA00:01:6C:9D:B9:FA
"; + #$data = "
gosa_opsi_getAllSoftwareLicenses
GOSA00:01:6C:9D:B9:FA
"; ############################## @@ -267,13 +273,18 @@ for($count = 1; $count <= $zahl; $count++) #$data = "
gosa_trigger_reload_syslog_config
GOSA GOSA 00:0C:29:4C:4B:0C
"; + $time_start = microtime_float(); $sock->write($data); $answer = "nothing"; $answer = $sock->read(); - echo "$count: $answer\n"; $sock->close(); + + $time_end = microtime_float(); + $time = $time_end - $time_start; + echo "Processing time: $time seconds\n"; + }else{ echo "... FAILED!\n"; } -- 2.30.2