Diff for /loncom/lonnet/perl/lonnet.pm between versions 1.1117 and 1.1123

version 1.1117, 2011/07/04 09:25:06 version 1.1123, 2011/08/01 22:13:49
Line 306  sub get_server_homeID { Line 306  sub get_server_homeID {
     return &do_cache_new('serverhomeID',$hostname,$serverhomeID,$cachetime);      return &do_cache_new('serverhomeID',$hostname,$serverhomeID,$cachetime);
 }  }
   
   sub get_remote_globals {
       my ($lonhost,$whathash,$ignore_cache) = @_;
       my (%returnhash,%whatneeded);
       if (ref($whathash) eq 'ARRAY') {
           foreach my $what (sort(keys(%{$whathash}))) {
               my $type = $whathash->{$what};
               my $hashid = $lonhost.'-'.$what;
               my ($result,$cached); 
               unless ($ignore_cache) {
                   ($result,$cached)=&is_cached_new('lonnetglobal',$hashid);
                   $returnhash{$what} = $result;
               }
               if (defined($cached)) {
                   $returnhash{$what} = $result;
               } else {
                   $whatneeded{$what} = $type;
               }
           }
           if (keys(%whatneeded) > 0) {
               my $requested = &freeze_escape(\%whatneeded);
               my $rep=&reply('readlonnetglobal:'.$requested,$lonhost);
               unless (($rep=~/^refused/) || ($rep=~/^rejected/) || ($rep eq 'con_lost')) {
                   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);
                       }
                   }
               }
           }
       }
       return %returnhash;
   }
   
 # -------------------------------------------------- Non-critical communication  # -------------------------------------------------- Non-critical communication
 sub subreply {  sub subreply {
     my ($cmd,$server)=@_;      my ($cmd,$server)=@_;
Line 773  sub spareserver { Line 811  sub spareserver {
         my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom);          my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom);
         $remotesessions = $udomdefaults{'remotesessions'};          $remotesessions = $udomdefaults{'remotesessions'};
     }      }
     foreach my $try_server (@{ $spareid{'primary'} }) {      my $spareshash = &this_host_spares($udom);
         if ($uint_dom) {      if (ref($spareshash) eq 'HASH') {
              next unless (&spare_can_host($udom,$uint_dom,$remotesessions,          if (ref($spareshash->{'primary'}) eq 'ARRAY') {
                                           $try_server));              foreach my $try_server (@{ $spareshash->{'primary'} }) {
                   if ($uint_dom) {
                       next unless (&spare_can_host($udom,$uint_dom,$remotesessions,
                                                    $try_server));
                   }
           ($spare_server, $lowest_load) =
               &compare_server_load($try_server, $spare_server, $lowest_load);
               }
         }          }
  ($spare_server, $lowest_load) =  
     &compare_server_load($try_server, $spare_server, $lowest_load);  
     }  
   
     my $found_server = ($spare_server ne '' && $lowest_load < 100);          my $found_server = ($spare_server ne '' && $lowest_load < 100);
   
     if (!$found_server) {          if (!$found_server) {
  foreach my $try_server (@{ $spareid{'default'} }) {              if (ref($spareshash->{'default'}) eq 'ARRAY') { 
             if ($uint_dom) {          foreach my $try_server (@{ $spareshash->{'default'} }) {
                 next unless (&spare_can_host($udom,$uint_dom,$remotesessions,                      if ($uint_dom) {
                                              $try_server));                          next unless (&spare_can_host($udom,$uint_dom,
             }                                                       $remotesessions,$try_server));
     ($spare_server, $lowest_load) =                      }
  &compare_server_load($try_server, $spare_server, $lowest_load);              ($spare_server, $lowest_load) =
  }          &compare_server_load($try_server, $spare_server, $lowest_load);
                   }
       }
           }
     }      }
   
     if (!$want_server_name) {      if (!$want_server_name) {
Line 843  sub compare_server_load { Line 888  sub compare_server_load {
 # --------------------------- ask offload servers if user already has a session  # --------------------------- ask offload servers if user already has a session
 sub find_existing_session {  sub find_existing_session {
     my ($udom,$uname) = @_;      my ($udom,$uname) = @_;
     foreach my $try_server (@{ $spareid{'primary'} },      my $spareshash = &this_host_spares($udom);
     @{ $spareid{'default'} }) {      if (ref($spareshash) eq 'HASH') {
  return $try_server if (&has_user_session($try_server, $udom, $uname));          if (ref($spareshash->{'primary'}) eq 'ARRAY') {
               foreach my $try_server (@{ $spareshash->{'primary'} }) {
                   return $try_server if (&has_user_session($try_server, $udom, $uname));
               }
           }
           if (ref($spareshash->{'default'}) eq 'ARRAY') {
               foreach my $try_server (@{ $spareshash->{'default'} }) {
                   return $try_server if (&has_user_session($try_server, $udom, $uname));
               }
           }
     }      }
     return;      return;
 }  }
Line 1035  sub can_host_session { Line 1089  sub can_host_session {
     }      }
     if ($canhost) {      if ($canhost) {
         if (ref($hostedsessions) eq 'HASH') {          if (ref($hostedsessions) eq 'HASH') {
               my $uprimary_id = &Apache::lonnet::domain($udom,'primary');
               my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
             if (ref($hostedsessions->{'excludedomain'}) eq 'ARRAY') {              if (ref($hostedsessions->{'excludedomain'}) eq 'ARRAY') {
                 if (grep(/^\Q$udom\E$/,@{$hostedsessions->{'excludedomain'}})) {                  if (($uint_dom ne '') && 
                       (grep(/^\Q$uint_dom\E$/,@{$hostedsessions->{'excludedomain'}}))) {
                     $canhost = 0;                      $canhost = 0;
                 } else {                  } else {
                     $canhost = 1;                      $canhost = 1;
                 }                  }
             }              }
             if (ref($hostedsessions->{'includedomain'}) eq 'ARRAY') {              if (ref($hostedsessions->{'includedomain'}) eq 'ARRAY') {
                 if (grep(/^\Q$udom\E$/,@{$hostedsessions->{'includedomain'}})) {                  if (($uint_dom ne '') && 
                       (grep(/^\Q$uint_dom\E$/,@{$hostedsessions->{'includedomain'}}))) {
                     $canhost = 1;                      $canhost = 1;
                 } else {                  } else {
                     $canhost = 0;                      $canhost = 0;
Line 1074  sub spare_can_host { Line 1132  sub spare_can_host {
     return $canhost;      return $canhost;
 }  }
   
   sub this_host_spares {
       my ($dom) = @_;
       my $cachetime = 60*60*24;
       my @hosts = &current_machine_ids();
       foreach my $lonhost (@hosts) {
           if (&host_domain($lonhost) eq $dom) {
               my ($result,$cached)=&is_cached_new('spares',$dom);
               if (defined($cached)) {
                   return $result;
               } else {
                   my %domconfig =
                       &Apache::lonnet::get_dom('configuration',['usersessions'],$dom);
                   if (ref($domconfig{'usersessions'}) eq 'HASH') {
                       if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                           if (ref($domconfig{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                               return &do_cache_new('spares',$dom,$domconfig{'usersessions'}{'spares'}{$lonhost},$cachetime);
                           }
                       }
                   }
               }
               last;
           }
       }
       my $serverhomedom = &host_domain($perlvar{'lonHostID'});
       my ($result,$cached)=&is_cached_new('spares',$serverhomedom);
       if (defined($cached)) {
           return $result;
       } else {
           my %homedomconfig =
               &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
           if (ref($homedomconfig{'usersessions'}) eq 'HASH') {
               if (ref($homedomconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   if (ref($homedomconfig{'usersessions'}{'spares'}{$perlvar{'lonHostID'}}) eq 'HASH') {
                       return &do_cache_new('spares',$serverhomedom,$homedomconfig{'usersessions'}{'spares'}{$perlvar{'lonHostID'}},$cachetime);
                   }
               }
           }
       }
       return \%spareid;
   }
   
 # ---------------------- Find the homebase for a user from domain's lib servers  # ---------------------- Find the homebase for a user from domain's lib servers
   
 my %homecache;  my %homecache;
Line 3998  sub restore { Line 4097  sub restore {
 }  }
   
 # ---------------------------------------------------------- Course Description  # ---------------------------------------------------------- Course Description
   #
   #  
   
 sub coursedescription {  sub coursedescription {
     my ($courseid,$args)=@_;      my ($courseid,$args)=@_;
Line 4027  sub coursedescription { Line 4128  sub coursedescription {
  return %returnhash;   return %returnhash;
     }      }
   
     # get the data agin      # get the data again
   
     if (!$args->{'one_time'}) {      if (!$args->{'one_time'}) {
  $envhash{'course.'.$normalid.'.last_cache'}=time;   $envhash{'course.'.$normalid.'.last_cache'}=time;
     }      }
Line 4035  sub coursedescription { Line 4137  sub coursedescription {
     if ($chome ne 'no_host') {      if ($chome ne 'no_host') {
        %returnhash=&dump('environment',$cdomain,$cnum);         %returnhash=&dump('environment',$cdomain,$cnum);
        if (!exists($returnhash{'con_lost'})) {         if (!exists($returnhash{'con_lost'})) {
      my $username = $env{'user.name'}; # Defult username
      if(defined $args->{'user'}) {
          $username = $args->{'user'};
      }
            $returnhash{'home'}= $chome;             $returnhash{'home'}= $chome;
    $returnhash{'domain'} = $cdomain;     $returnhash{'domain'} = $cdomain;
    $returnhash{'num'} = $cnum;     $returnhash{'num'} = $cnum;
Line 4046  sub coursedescription { Line 4152  sub coursedescription {
            }             }
            $returnhash{'url'}=&clutter($returnhash{'url'});             $returnhash{'url'}=&clutter($returnhash{'url'});
            $returnhash{'fn'}=LONCAPA::tempdir() .             $returnhash{'fn'}=LONCAPA::tempdir() .
        $env{'user.name'}.'_'.$cdomain.'_'.$cnum;         $username.'_'.$cdomain.'_'.$cnum;
            $envhash{'course.'.$normalid.'.home'}=$chome;             $envhash{'course.'.$normalid.'.home'}=$chome;
            $envhash{'course.'.$normalid.'.domain'}=$cdomain;             $envhash{'course.'.$normalid.'.domain'}=$cdomain;
            $envhash{'course.'.$normalid.'.num'}=$cnum;             $envhash{'course.'.$normalid.'.num'}=$cnum;
Line 11038  revokecustomrole($udom,$uname,$url,$role Line 11144  revokecustomrole($udom,$uname,$url,$role
   
 =item *  =item *
   
 coursedescription($courseid) : returns a hash of information about the  coursedescription($courseid,$options) : returns a hash of information about the
 specified course id, including all environment settings for the  specified course id, including all environment settings for the
 course, the description of the course will be in the hash under the  course, the description of the course will be in the hash under the
 key 'description'  key 'description'
   
   $options is an optional parameter that if supplied is a hash reference that controls
   what how this function works.  It has the following key/values:
   
   =over 4
   
   =item freshen_cache
   
   If defined, and the environment cache for the course is valid, it is 
   returned in the returned hash.
   
   =item one_time
   
   If defined, the last cache time is set to _now_
   
   =item user
   
   If defined, the supplied username is used instead of the current user.
   
   
   =back
   
 =item *  =item *
   
 resdata($name,$domain,$type,@which) : request for current parameter  resdata($name,$domain,$type,@which) : request for current parameter
Line 11435  splitting on '&', supports elements that Line 11562  splitting on '&', supports elements that
   
 =head2 Logging Routines  =head2 Logging Routines
   
 =over 4  
   
 These routines allow one to make log messages in the lonnet.log and  These routines allow one to make log messages in the lonnet.log and
 lonnet.perm logfiles.  lonnet.perm logfiles.
   
   =over 4
   
 =item *  =item *
   
 logtouch() : make sure the logfile, lonnet.log, exists  logtouch() : make sure the logfile, lonnet.log, exists
Line 11455  logperm() : append a permanent message t Line 11583  logperm() : append a permanent message t
 file never gets deleted by any automated portion of the system, only  file never gets deleted by any automated portion of the system, only
 messages of critical importance should go in here.  messages of critical importance should go in here.
   
   
 =back  =back
   
 =head2 General File Helper Routines  =head2 General File Helper Routines

Removed from v.1.1117  
changed lines
  Added in v.1.1123


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>