[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface domainprefs.pm

raeburn raeburn at source.lon-capa.org
Wed Apr 1 19:41:15 EDT 2015


raeburn		Wed Apr  1 23:41:15 2015 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	domainprefs.pm 
  Log:
  - For 2.11
    - Backport 1.260, 1.261
  
  
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.160.6.60 loncom/interface/domainprefs.pm:1.160.6.61
--- loncom/interface/domainprefs.pm:1.160.6.60	Mon Mar 30 20:47:13 2015
+++ loncom/interface/domainprefs.pm	Wed Apr  1 23:41:14 2015
@@ -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 @@
     if ($position eq 'top') {
         if (keys(%serverhomes) > 1) {
             my %spareid = &current_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 .= '<tr'.$css_class.'><td colspan="2">'.
                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
@@ -3529,7 +3535,7 @@
 }
 
 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 @@
                 }
             }
             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 .= '<tr'.$css_class.'>
                            <td rowspan="2">
                             <span class="LC_nobreak">'.
                           &mt('[_1] when busy, offloads to:'
-                              ,'<b>'.$server.'</b>').
+                              ,'<b>'.$server.'</b>').'</span><br />'.
+                          '<span class="LC_nobreak">'."\n".
+                          '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
+                          ' '.&mt('Switch active users on next access').'</label></span>'.
                           "\n";
             my (%current,%canselect);
             my @choices = 
@@ -10907,7 +10922,23 @@
             $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$/, at 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 @@
         } 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 @@
                 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 @@
                         $resulttext .= '</ul>';
                     }
                 }
+                if ($changes{'offloadnow'}) {
+                    if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
+                        if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
+                            $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
+                            foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
+                                $resulttext .= '<li>'.$lonhost.'</li>';
+                            }
+                            $resulttext .= '</ul>';
+                        } else {
+                            $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
+                        }
+                    } else {
+                        $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
+                    }
+                }
                 $resulttext .= '</ul>';
             } else {
                 $resulttext = $nochgmsg;
@@ -11992,7 +12060,7 @@
     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;




More information about the LON-CAPA-cvs mailing list