--- loncom/interface/domainprefs.pm 2015/03/30 20:47:13 1.160.6.60 +++ loncom/interface/domainprefs.pm 2015/04/01 23:41:14 1.160.6.61 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.160.6.60 2015/03/30 20:47:13 raeburn Exp $ +# $Id: domainprefs.pm,v 1.160.6.61 2015/04/01 23:41:14 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -3279,7 +3279,13 @@ sub print_usersessions { if ($position eq 'top') { if (keys(%serverhomes) > 1) { my %spareid = ¤t_offloads_to($dom,$settings,\%servers); - $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal); + my $curroffloadnow; + if (ref($settings) eq 'HASH') { + if (ref($settings->{'offloadnow'}) eq 'HASH') { + $curroffloadnow = $settings->{'offloadnow'}; + } + } + $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal); } else { $datatable .= ''. &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.'); @@ -3529,7 +3535,7 @@ sub current_offloads_to { } sub spares_row { - my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_; + my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_; my $css_class; my $numinrow = 4; my $itemcount = 1; @@ -3549,12 +3555,21 @@ sub spares_row { } } next unless (ref($spareid->{$server}) eq 'HASH'); + my $checkednow; + if (ref($curroffloadnow) eq 'HASH') { + if ($curroffloadnow->{$server}) { + $checkednow = ' checked="checked"'; + } + } $css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; $datatable .= ' '. &mt('[_1] when busy, offloads to:' - ,''.$server.''). + ,''.$server.'').'
'. + ''."\n". + ''. "\n"; my (%current,%canselect); my @choices = @@ -10907,7 +10922,23 @@ sub modify_usersessions { $changes{'spares'}{$lonhost} = \%spareschg; } } - + $defaultshash{'usersessions'}{'offloadnow'} = {}; + my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow'); + my @okoffload; + if (@offloadnow) { + foreach my $server (@offloadnow) { + if (&Apache::lonnet::hostname($server) ne '') { + unless (grep(/^\Q$server\E$/,@okoffload)) { + push(@okoffload,$server); + } + } + } + if (@okoffload) { + foreach my $lonhost (@okoffload) { + $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1; + } + } + } if (ref($domconfig{'usersessions'}) eq 'HASH') { if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') { if (ref($changes{'spares'}) eq 'HASH') { @@ -10918,8 +10949,27 @@ sub modify_usersessions { } else { $savespares = 1; } + if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') { + foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) { + unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) { + $changes{'offloadnow'} = 1; + last; + } + } + unless ($changes{'offloadnow'}) { + foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) { + unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) { + $changes{'offloadnow'} = 1; + last; + } + } + } + } elsif (@okoffload) { + $changes{'offloadnow'} = 1; + } + } elsif (@okoffload) { + $changes{'offloadnow'} = 1; } - my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.'); if ((keys(%changes) > 0) || ($savespares)) { my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash, @@ -10932,6 +10982,9 @@ sub modify_usersessions { if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') { $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'}; } + if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') { + $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'}; + } } my $cachetime = 24*60*60; &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime); @@ -11000,6 +11053,21 @@ sub modify_usersessions { $resulttext .= ''; } } + if ($changes{'offloadnow'}) { + if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') { + if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) { + $resulttext .= '
  • '.&mt('Switch active users on next access, for server(s):').'
      '; + foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) { + $resulttext .= '
    • '.$lonhost.'
    • '; + } + $resulttext .= '
    '; + } else { + $resulttext .= '
  • '.&mt('No servers now set to switch active users on next access.'); + } + } else { + $resulttext .= '
  • '.&mt('No servers now set to switch active users on next access.').'
  • '; + } + } $resulttext .= ''; } else { $resulttext = $nochgmsg; @@ -11992,7 +12060,7 @@ sub devalidate_remote_domconfs { my %thismachine; map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids(); my @posscached = ('domainconfig','domdefaults'); - if (keys(%servers) > 1) { + if (keys(%servers)) { foreach my $server (keys(%servers)) { next if ($thismachine{$server}); my @cached;