From b81df354699d1b08a75b5fac4fb913e68b4d9d83 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Sun, 25 Mar 2012 17:48:51 +0000 Subject: [PATCH] Have Client work to aggregate some XML processing git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.7@11991 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Client.pm | 56 ++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/perl-xCAT/xCAT/Client.pm b/perl-xCAT/xCAT/Client.pm index 9826a8d32..dceb2e141 100644 --- a/perl-xCAT/xCAT/Client.pm +++ b/perl-xCAT/xCAT/Client.pm @@ -44,6 +44,30 @@ my $EXITCODE; # save the bitmask of all exit codes returned by calls to hand 1; +sub rspclean { + my $response = shift; + my $callback = shift; + my $rsps = XMLin($response,SuppressEmpty=>undef,ForceArray=>1); + foreach my $rsp (@{$rsps->{xcatresponse}}) { + #add ESC back + foreach my $key (keys %$rsp) { + if (ref($rsp->{$key}) eq 'ARRAY') { + foreach my $text (@{$rsp->{$key}}) { + next unless defined $text; + $text =~ s/xxxxESCxxxx/\e/g; + } + } + else { + $rsp->{$key} =~ s/xxxxESCxxxx/\e/g; + } + } + $callback->($rsp); + if ($rsp->{serverdone}) { + return 1; + } + } + return 0; +} ################################# # submit_request will take an xCAT command and pass it to the xCAT # server for execution. @@ -169,6 +193,8 @@ $request->{clienttype}->[0] = "cli"; # setup clienttype for auditlog my $response; my $rsp; my $cleanexit=0; + my $massresponse=""; + my $nextcoalescetime=time()+1; while (<$client>) { $response .= $_; if (m/<\/xcatresponse>/) { @@ -176,32 +202,30 @@ $request->{clienttype}->[0] = "cli"; # setup clienttype for auditlog $response =~ s/\e/xxxxESCxxxx/g; if ($ENV{XCATXMLTRACE}) { print $response; } - $rsp = XMLin($response,SuppressEmpty=>undef,ForceArray=>1); + $massresponse.=$response; if($ENV{XCATXMLWARNING}) { validateXML($response); } - - #add ESC back - foreach my $key (keys %$rsp) { - if (ref($rsp->{$key}) eq 'ARRAY') { - foreach my $text (@{$rsp->{$key}}) { - next unless defined $text; - $text =~ s/xxxxESCxxxx/\e/g; - } - } - else { - $rsp->{$key} =~ s/xxxxESCxxxx/\e/g; - } + my $shouldexit; + if (time() > $nextcoalescetime) { + $nextcoalescetime=time()+1; + $massresponse .= ""; + $shouldexit = rspclean($massresponse,$callback); + $massresponse=""; } - + $response=''; - $callback->($rsp); - if ($rsp->{serverdone}) { + if ($shouldexit) { $cleanexit=1; last; } } } + if (not $cleanexit and $massresponse ne "") { + $massresponse .= ""; + $cleanexit = rspclean($massresponse,$callback); + } + $massresponse=""; unless ($cleanexit) { print STDERR "ERROR/WARNING: communication with the xCAT server seems to have been ended prematurely\n"; }