[LON-CAPA-cvs] cvs: loncom / lond /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Fri Aug 5 00:35:50 EDT 2011


raeburn		Fri Aug  5 04:35:50 2011 EDT

  Modified files:              
    /loncom	lond 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Specify types of globals available from &read_lonnet_global() in lond.
    - Include lonBalancer from httpd.conf
  - lonnet::get_remote_globals() returns two arguments - $result (ok etc.),
     and reference to hash of lonnet globals retrievable from remote server. 
  
  
Index: loncom/lond
diff -u loncom/lond:1.479 loncom/lond:1.480
--- loncom/lond:1.479	Tue Aug  2 03:11:35 2011
+++ loncom/lond	Fri Aug  5 04:35:45 2011
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.479 2011/08/02 03:11:35 raeburn Exp $
+# $Id: lond,v 1.480 2011/08/05 04:35:45 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -60,7 +60,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.479 $'; #' stupid emacs
+my $VERSION='$Revision: 1.480 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -92,6 +92,8 @@
 
 my %perlvar;			# Will have the apache conf defined perl vars.
 
+my $dist;
+
 #
 #   The hash below is used for command dispatching, and is therefore keyed on the request keyword.
 #    Each element of the hash contains a reference to an array that contains:
@@ -1646,20 +1648,48 @@
     my $userinput = "$cmd:$tail";
     my $requested = &Apache::lonnet::thaw_unescape($tail);
     my $result;
+    my %packagevars = (
+                        spareid => \%Apache::lonnet::spareid,
+                        perlvar => \%Apache::lonnet::perlvar,
+                      );
+    my %limit_to = (
+                    perlvar => {
+                                 lonOtherAuthen => 1,
+                                 lonBalancer    => 1,
+                                 lonVersion     => 1,
+                                 lonSysEMail    => 1,
+                                 lonHostID      => 1,
+                                 lonRole        => 1,
+                                 lonDefDomain   => 1,
+                                 lonLoadLim     => 1,
+                                 lonUserLoadLim => 1,
+                               }
+                  );
     if (ref($requested) eq 'HASH') {
         foreach my $what (keys(%{$requested})) {
-            my $type = $requested->{$what};
-            my $lonnetglobal = 'Apache::lonnet::'.$what;
             my $response;
-            if ($type eq 'HASH') {
-                if (defined(%{$lonnetglobal})) {
-                    my $hashref = \%{$lonnetglobal};
-                    $response = &Apache::lonnet::freeze_escape($hashref);
+            my $items = {};
+            if (exists($packagevars{$what})) {
+                if (ref($limit_to{$what}) eq 'HASH') {
+                    foreach my $varname (keys(%{$packagevars{$what}})) {
+                        if ($limit_to{$what}{$varname}) {
+                            $items->{$varname} = $packagevars{$what}{$varname};
+                        }
+                    }
+                } else {
+                    $items = $packagevars{$what};
                 }
-            } else {
-                if (defined(${$lonnetglobal})) {
-                    $response = &escape(${$lonnetglobal});
+                if ($what eq 'perlvar') {
+                    if (!exists($packagevars{$what}{'lonBalancer'})) {
+                        if ($dist =~ /^(centos|rhes|fedora|scientific)/) {
+                            my $othervarref=LONCAPA::Configuration::read_conf('httpd.conf');
+                            if (ref($othervarref) eq 'HASH') {
+                                $items->{'lonBalancer'} = $othervarref->{'lonBalancer'};
+                            }
+                        }
+                    }
                 }
+                $response = &Apache::lonnet::freeze_escape($items);
             }
             $result .= &escape($what).'='.$response.'&';
         }
@@ -6404,7 +6434,7 @@
 &Apache::lonnet::load_hosts_tab();
 my %iphost = &Apache::lonnet::get_iphost(1);
 
-my $dist=`$perlvar{'lonDaemons'}/distprobe`;
+$dist=`$perlvar{'lonDaemons'}/distprobe`;
 
 my $arch = `uname -i`;
 chomp($arch);
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1124 loncom/lonnet/perl/lonnet.pm:1.1125
--- loncom/lonnet/perl/lonnet.pm:1.1124	Tue Aug  2 03:11:42 2011
+++ loncom/lonnet/perl/lonnet.pm	Fri Aug  5 04:35:50 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1124 2011/08/02 03:11:42 raeburn Exp $
+# $Id: lonnet.pm,v 1.1125 2011/08/05 04:35:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -308,40 +308,42 @@
 
 sub get_remote_globals {
     my ($lonhost,$whathash,$ignore_cache) = @_;
-    my (%returnhash,%whatneeded);
-    if (ref($whathash) eq 'ARRAY') {
+    my ($result,%returnhash,%whatneeded);
+    if (ref($whathash) eq 'HASH') {
         foreach my $what (sort(keys(%{$whathash}))) {
-            my $type = $whathash->{$what};
             my $hashid = $lonhost.'-'.$what;
-            my ($result,$cached); 
+            my ($response,$cached);
             unless ($ignore_cache) {
-                ($result,$cached)=&is_cached_new('lonnetglobal',$hashid);
-                $returnhash{$what} = $result;
+                ($response,$cached)=&is_cached_new('lonnetglobal',$hashid);
             }
             if (defined($cached)) {
-                $returnhash{$what} = $result;
+                $returnhash{$what} = $response;
             } else {
-                $whatneeded{$what} = $type;
+                $whatneeded{$what} = 1;
             }
         }
-        if (keys(%whatneeded) > 0) {
+        if (keys(%whatneeded) == 0) {
+            $result = 'ok';
+        } else {
             my $requested = &freeze_escape(\%whatneeded);
             my $rep=&reply('readlonnetglobal:'.$requested,$lonhost);
-            unless (($rep=~/^refused/) || ($rep=~/^rejected/) || ($rep eq 'con_lost')) {
+            if (($rep=~/^(refused|rejected|error)/) || ($rep eq 'con_lost') ||
+                ($rep eq 'unknown_cmd')) {
+                $result = $rep;
+            } else {
+                $result = 'ok';
                 my @pairs=split(/\&/,$rep);
-                if ($rep !~ /^error/) {
-                    foreach my $item (@pairs) {
-                        my ($key,$value)=split(/=/,$item,2);
-                        my $what = &unescape($key);
-                        my $hashid = $lonhost.'-'.$what;
-                        $returnhash{$what}=&thaw_unescape($value);
-                        &do_cache_new('lonnetglobal',$hashid,$returnhash{$what},600);
-                    }
+                foreach my $item (@pairs) {
+                    my ($key,$value)=split(/=/,$item,2);
+                    my $what = &unescape($key);
+                    my $hashid = $lonhost.'-'.$what;
+                    $returnhash{$what}=&thaw_unescape($value);
+                    &do_cache_new('lonnetglobal',$hashid,$returnhash{$what},600);
                 }
             }
         }
     }
-    return %returnhash;
+    return ($result,\%returnhash);
 }
 
 sub remote_devalidate_cache {




More information about the LON-CAPA-cvs mailing list