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

raeburn raeburn at source.lon-capa.org
Sun Jul 31 19:05:01 EDT 2011


raeburn		Sun Jul 31 23:05:01 2011 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm 
  Log:
  - Bug 6371.
    Setting of servers to offload to moved from /home/httpd/lonTabs/spare.tab
    to DC's Domain configuration (User session hosting/offloading category).
    Work in progress.
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.144 loncom/interface/domainprefs.pm:1.145
--- loncom/interface/domainprefs.pm:1.144	Fri Jul 29 14:25:36 2011
+++ loncom/interface/domainprefs.pm	Sun Jul 31 23:05:00 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.144 2011/07/29 14:25:36 raeburn Exp $
+# $Id: domainprefs.pm,v 1.145 2011/07/31 23:05:00 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -352,9 +352,11 @@
                               col2 => 'Value',}],
                  },
         'usersessions' =>
-                 {text  => 'User session hosting',
+                 {text  => 'User session hosting/offloading',
                   help  => 'Domain_Configuration_User_Sessions',
-                  header => [{col1 => 'Hosting of users from other domains',
+                  header => [{col1 => 'Domain server',
+                              col2 => 'Servers to offload sessions to when busy'},
+                             {col1 => 'Hosting of users from other domains',
                               col2 => 'Rules'},
                              {col1 => "Hosting domain's own users elsewhere",
                               col2 => 'Rules'}],
@@ -488,16 +490,20 @@
     }
     if ($numheaders > 1) {
         my $colspan = '';
+        my $rightcolspan = '';
         if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
             $colspan = ' colspan="2"';
         }
+        if ($action eq 'usersessions') {
+            $rightcolspan = ' colspan="3"'; 
+        }
         $output .= '
           <tr>
            <td>
             <table class="LC_nested">
              <tr class="LC_info_row">
               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
-              <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
+              <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
              </tr>';
         $rowtotal ++;
         if ($action eq 'autoupdate') {
@@ -583,7 +589,18 @@
         } elsif ($action eq 'helpsettings') {
             $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'usersessions') {
-            $output .= &print_usersessions('bottom',$dom,$settings,\$rowtotal);
+            $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
+           </table>
+          </td>
+         </tr>
+         <tr>
+           <td>
+            <table class="LC_nested">
+             <tr class="LC_info_row">
+              <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
+              <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
+                       &print_usersessions('bottom',$dom,$settings,\$rowtotal);
+            $rowtotal ++;
         } elsif ($action eq 'coursedefaults') {
             $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'rolecolors') {
@@ -2287,118 +2304,131 @@
     my ($css_class,$datatable,%checked,%choices);
     my (%by_ip,%by_location, at intdoms);
     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
-    if (keys(%by_location) == 0) {
-        if ($position eq 'top') {
-            $datatable .= '<tr'.$css_class.'><td colspan="2">'.
-                          &mt('Nothing to set here, as the cluster to which this domain belongs only contains this institution.');
-        }
-    }
-    my %lt = &usersession_titles();
+
+    my @alldoms = &Apache::lonnet::all_domains();
+    my %uniques = &Apache::lonnet::get_unique_servers(\@alldoms);
+    my %servers = &dom_servers($dom);
     my $itemcount = 1;
-    my $numinrow = 5;
-    my $prefix;
-    my @types;
     if ($position eq 'top') {
-        $prefix = 'hosted';
-        @types = ('excludedomain','includedomain');
+        if (keys(%uniques) > 1) {
+            my %spareid = &current_offloads_to($dom,$settings,\%servers);
+            $datatable .= &spares_row(\%servers,\%spareid,\%uniques,$rowtotal);
+        } else {
+            $datatable .= '<tr'.$css_class.'><td colspan="2">'.
+                          &mt('Nothing to set here, as the cluster to which this domain belongs only contains this server.');
+        }
     } else {
-        $prefix = 'remote';
-        @types = ('version','excludedomain','includedomain');
-    }
-    my (%current,%checkedon,%checkedoff);
-    my @lcversions = &Apache::lonnet::all_loncaparevs();
-    my @locations = sort(keys(%by_location));
-    foreach my $type (@types) {
-        $checkedon{$type} = '';
-        $checkedoff{$type} = ' checked="checked"';
-    }
-    if (ref($settings) eq 'HASH') {
-        if (ref($settings->{$prefix}) eq 'HASH') {
-            foreach my $key (keys(%{$settings->{$prefix}})) {
-                $current{$key} = $settings->{$prefix}{$key};
-                if ($key eq 'version') {
-                    if ($current{$key} ne '') {
-                        $checkedon{$key} = ' checked="checked"';
-                        $checkedoff{$key} = '';
-                    }
-                } elsif (ref($current{$key}) eq 'ARRAY') {
-                    $checkedon{$key} = ' checked="checked"';
-                    $checkedoff{$key} = '';
-                }
+        if (keys(%by_location) == 0) {
+            $datatable .= '<tr'.$css_class.'><td colspan="2">'.
+                          &mt('Nothing to set here, as the cluster to which this domain belongs only contains this institution.');
+        } else {
+            my %lt = &usersession_titles();
+            my $numinrow = 5;
+            my $prefix;
+            my @types;
+            if ($position eq 'bottom') {
+                $prefix = 'remote';
+                @types = ('version','excludedomain','includedomain');
+            } else {
+                $prefix = 'hosted';
+                @types = ('excludedomain','includedomain');
             }
-        }
-    }
-    foreach my $type (@types) {
-        next if ($type ne 'version' && !@locations);
-        $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
-        $datatable .= '<tr'.$css_class.'>
-                       <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
-                           <span class="LC_nobreak"> 
-                           <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label> 
-                           <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
-        if ($type eq 'version') {
-            my $selector = '<select name="'.$prefix.'_version">';
-            foreach my $version (@lcversions) {
-                my $selected = '';
-                if ($current{'version'} eq $version) {
-                    $selected = ' selected="selected"';
+            my (%current,%checkedon,%checkedoff);
+            my @lcversions = &Apache::lonnet::all_loncaparevs();
+            my @locations = sort(keys(%by_location));
+            foreach my $type (@types) {
+                $checkedon{$type} = '';
+                $checkedoff{$type} = ' checked="checked"';
+            }
+            if (ref($settings) eq 'HASH') {
+                if (ref($settings->{$prefix}) eq 'HASH') {
+                    foreach my $key (keys(%{$settings->{$prefix}})) {
+                        $current{$key} = $settings->{$prefix}{$key};
+                        if ($key eq 'version') {
+                            if ($current{$key} ne '') {
+                                $checkedon{$key} = ' checked="checked"';
+                                $checkedoff{$key} = '';
+                            }
+                        } elsif (ref($current{$key}) eq 'ARRAY') {
+                            $checkedon{$key} = ' checked="checked"';
+                            $checkedoff{$key} = '';
+                        }
+                    }
                 }
-                $selector .= ' <option value="'.$version.'"'.
-                             $selected.'>'.$version.'</option>';
             }
-            $selector .= '</select> ';
-            $datatable .= &mt('remote server must be version: [_1] or later',$selector);
-        } else {
-            $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
-                         'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
-                         ' />'.(' 'x2).
-                         '<input type="button" value="'.&mt('uncheck all').'" '.
-                         'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
-                         "\n".
-                         '</div><div><table>';
-            my $rem;
-            for (my $i=0; $i<@locations; $i++) {
-                my ($showloc,$value,$checkedtype);
-                if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
-                    my $ip = $by_location{$locations[$i]}->[0];
-                    if (ref($by_ip{$ip}) eq 'ARRAY') {
-                        $value = join(':',@{$by_ip{$ip}});
-                        $showloc = join(', ',@{$by_ip{$ip}});
-                        if (ref($current{$type}) eq 'ARRAY') {
-                            foreach my $loc (@{$by_ip{$ip}}) {  
-                                if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
-                                    $checkedtype = ' checked="checked"';
-                                    last;
+            foreach my $type (@types) {
+                next if ($type ne 'version' && !@locations);
+                $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
+                $datatable .= '<tr'.$css_class.'>
+                               <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
+                               <span class="LC_nobreak"> 
+                               <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label> 
+                               <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
+                if ($type eq 'version') {
+                    my $selector = '<select name="'.$prefix.'_version">';
+                    foreach my $version (@lcversions) {
+                        my $selected = '';
+                        if ($current{'version'} eq $version) {
+                            $selected = ' selected="selected"';
+                        }
+                        $selector .= ' <option value="'.$version.'"'.
+                                     $selected.'>'.$version.'</option>';
+                    }
+                    $selector .= '</select> ';
+                    $datatable .= &mt('remote server must be version: [_1] or later',$selector);
+                } else {
+                    $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
+                                 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
+                                 ' />'.(' 'x2).
+                                 '<input type="button" value="'.&mt('uncheck all').'" '.
+                                 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
+                                 "\n".
+                                 '</div><div><table>';
+                    my $rem;
+                    for (my $i=0; $i<@locations; $i++) {
+                        my ($showloc,$value,$checkedtype);
+                        if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
+                            my $ip = $by_location{$locations[$i]}->[0];
+                            if (ref($by_ip{$ip}) eq 'ARRAY') {
+                                 $value = join(':',@{$by_ip{$ip}});
+                                $showloc = join(', ',@{$by_ip{$ip}});
+                                if (ref($current{$type}) eq 'ARRAY') {
+                                    foreach my $loc (@{$by_ip{$ip}}) {  
+                                        if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
+                                            $checkedtype = ' checked="checked"';
+                                            last;
+                                        }
+                                    }
                                 }
                             }
                         }
+                        $rem = $i%($numinrow);
+                        if ($rem == 0) {
+                            if ($i > 0) {
+                                $datatable .= '</tr>';
+                            }
+                            $datatable .= '<tr>';
+                        }
+                        $datatable .= '<td class="LC_left_item">'.
+                                      '<span class="LC_nobreak"><label>'.
+                                      '<input type="checkbox" name="'.$prefix.'_'.$type.
+                                      '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
+                                      '</label></span></td>';
                     }
-                }
-                $rem = $i%($numinrow);
-                if ($rem == 0) {
-                    if ($i > 0) {
-                        $datatable .= '</tr>';
+                    $rem = @locations%($numinrow);
+                    my $colsleft = $numinrow - $rem;
+                    if ($colsleft > 1 ) {
+                        $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
+                                      ' </td>';
+                    } elsif ($colsleft == 1) {
+                        $datatable .= '<td class="LC_left_item"> </td>';
                     }
-                    $datatable .= '<tr>';
+                    $datatable .= '</tr></table>';
                 }
-                $datatable .= '<td class="LC_left_item">'.
-                              '<span class="LC_nobreak"><label>'.
-                              '<input type="checkbox" name="'.$prefix.'_'.$type.
-                              '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
-                              '</label></span></td>';
-            }
-            $rem = @locations%($numinrow);
-            my $colsleft = $numinrow - $rem;
-            if ($colsleft > 1 ) {
-                $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
-                              ' </td>';
-            } elsif ($colsleft == 1) {
-                $datatable .= '<td class="LC_left_item"> </td>';
+                $datatable .= '</td></tr>';
+                $itemcount ++;
             }
-            $datatable .= '</tr></table>';
         }
-        $datatable .= '</td></tr>';
-        $itemcount ++;
     }
     $$rowtotal += $itemcount;
     return $datatable;
@@ -2452,6 +2482,156 @@
     return;
 }
 
+sub current_offloads_to {
+    my ($dom,$settings,$servers) = @_;
+    my (%spareid,%otherdomconfigs);
+    if ((ref($settings) eq 'HASH') && (ref($servers) eq 'HASH')) {
+        foreach my $lonhost (sort(keys(%{$servers}))) {
+            my $gotspares;
+            if (ref($settings->{'spares'}) eq 'HASH') {
+                if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
+                    $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
+                    $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
+                    $gotspares = 1;
+                }
+            }
+            unless ($gotspares) {
+                my $gotspares;
+                my $serverhomeID =
+                    &Apache::lonnet::get_server_homeID($servers->{$lonhost});
+                my $serverhomedom =
+                    &Apache::lonnet::host_domain($serverhomeID);
+                if ($serverhomedom ne $dom) {
+                    if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
+                        if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
+                            if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
+                                $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
+                                $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
+                                $gotspares = 1;
+                            }
+                        }
+                    } else {
+                        $otherdomconfigs{$serverhomedom} =
+                            &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
+                        if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
+                            if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
+                                if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
+                                    if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
+                                        $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
+                                        $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
+                                        $gotspares = 1;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            unless ($gotspares) {
+                if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
+                    $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
+                    $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
+               } else {
+                    my $server_hostname = &Apache::lonnet::hostname($lonhost);
+                    my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
+                    if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
+                        $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
+                        $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
+                    } else {
+                        my %requested;
+                        $requested{'spareid'} = 'HASH';
+                        my %returnhash = &Apache::lonnet::get_remote_globals($lonhost,\%requested);
+                        my $spareshash = $returnhash{'spareid'};
+                        if (ref($spareshash) eq 'HASH') {
+                            $spareid{$lonhost}{'primary'} = $spareshash->{'primary'};
+                            $spareid{$lonhost}{'default'} = $spareshash->{'default'};
+                        }
+                    }
+                }
+            }
+        }
+    }
+    return %spareid;
+}
+
+sub spares_row {
+    my ($servers,$spareid,$uniques,$rowtotal) = @_;
+    my $css_class;
+    my $numinrow = 4;
+    my $itemcount = 1;
+    my $datatable;
+    if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH')) {
+        foreach my $server (sort(keys(%{$servers}))) {
+            $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
+            $datatable .= '<tr'.$css_class.'>
+                           <td rowspan="2">
+                            <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>';
+            my (%current,%canselect);
+            if (ref($spareid->{$server}) eq 'HASH') {
+                foreach my $type ('primary','default') {
+                    if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
+                        my @spares = @{$spareid->{$server}{$type}};
+                        if (@spares > 0) {
+                            $current{$type} .= '<table>';
+                            for (my $i=0;  $i<@spares; $i++) {
+                                my $rem = $i%($numinrow);
+                                if ($rem == 0) {
+                                    if ($i > 0) {
+                                        $current{$type} .= '</tr>';
+                                    }
+                                    $current{$type} .= '<tr>';
+                                }
+                                $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" /> '.
+                                                   $spareid->{$server}{$type}[$i].
+                                                   '</label></td>';
+                            }
+                            $current{$type} .= '</tr></table>';
+                        }
+                    }
+                    if ($current{$type} eq '') {
+                        $current{$type} = &mt('None specified');
+                    }
+                    $canselect{$type} =
+                        &newspare_select($server,$type,$spareid->{$server}{$type},$uniques);
+                }
+            }
+            $datatable .= '<td><i>'.&mt('primary').'</i><td>'.$current{'primary'}.'</td>'.
+                          '<td>'.&mt('Add new [_1]primary[_2]:','<i>','</i>').' '.
+                          $canselect{'primary'}.'</td></tr>'.
+                          '<tr'.$css_class.'>'.
+                          '<td><i>'.&mt('default').'</i></td>'.
+                          '<td>'.$current{'default'}.'</td>'.
+                          '<td>'.&mt('Add new [_1]default[_2]:','<i>','</i>').' '.
+                          $canselect{'default'}.'</td></tr>';
+            $itemcount ++;
+        }
+    }
+    $$rowtotal += $itemcount;
+    return $datatable;
+}
+
+sub newspare_select {
+    my ($server,$type,$currspares,$uniques) = @_;
+    my $output;
+    if (ref($uniques) eq 'HASH') {
+        if (keys(%{$uniques}) > 1) {
+            $output = '<select name="newspare_'.$type.'_'.$server.'">'."\n".
+                      '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
+            foreach my $lonhost (sort(keys(%{$uniques}))) {
+                next if ($lonhost eq $server);
+                if (ref($currspares) eq 'ARRAY') {
+                    if (@{$currspares} > 0) {
+                        next if (grep(/^\Q$lonhost\E$/,@{$currspares}));
+                    }
+                }
+                $output .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
+            }
+            $output .= '<select>';
+        }
+    }
+    return $output;
+}
+
 sub contact_titles {
     my %titles = &Apache::lonlocal::texthash (
                    'supportemail' => 'Support E-mail address',
@@ -6766,8 +6946,14 @@
 
 sub modify_usersessions {
     my ($dom,%domconfig) = @_;
-    my @types = ('version','excludedomain','includedomain');
-    my @prefixes = ('remote','hosted');
+    my @hostingtypes = ('version','excludedomain','includedomain');
+    my @offloadtypes = ('primary','default');
+    my %types = (
+                  remote => \@hostingtypes,
+                  hosted => \@hostingtypes,
+                  spares => \@offloadtypes,
+                );
+    my @prefixes = ('remote','hosted','spares');
     my @lcversions = &Apache::lonnet::all_loncaparevs();
     my (%by_ip,%by_location, at intdoms);
     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
@@ -6780,7 +6966,8 @@
     my $resulttext;
     my %iphost = &Apache::lonnet::get_iphost();
     foreach my $prefix (@prefixes) {
-        foreach my $type (@types) {
+        next if ($prefix eq 'spares');
+        foreach my $type (@{$types{$prefix}}) {
             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
             if ($type eq 'version') {
                 my $value = $env{'form.'.$prefix.'_'.$type};
@@ -6872,6 +7059,66 @@
             }
         }
     }
+
+    my @alldoms = &Apache::lonnet::all_domains();
+    my %uniques = &Apache::lonnet::get_unique_servers(\@alldoms);
+    my %servers = &dom_servers($dom);
+    my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
+    my $savespares;
+
+    foreach my $lonhost (sort(keys(%servers))) {
+        my $serverhomeID =
+            &Apache::lonnet::get_server_homeID($servers{$lonhost});
+        $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
+        my %spareschg;
+        foreach my $type (@{$types{'spares'}}) {
+            my @okspares;
+            my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
+            foreach my $server (@checked) {
+                unless (($server eq $lonhost) || ($server eq $serverhomeID)) {
+                    if ($uniques{$server}) {
+                        push(@okspares,$server);
+                    }
+                }
+            }
+            my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
+            my $newspare;
+            if (($new ne '') && ($uniques{$new})) {
+                unless (($new eq $lonhost) || ($new eq $serverhomeID)) {
+                    $newspare = $new;
+                    $spareschg{$type} = 1;
+                }
+            }
+            if (ref($spareid{$lonhost}) eq 'HASH') {
+                if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
+                    my @diffs = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{'spares'}{$lonhost}{$type},\@okspares);
+                    if (@diffs > 0) {
+                        $spareschg{$type} = 1;
+                    } elsif ($new ne '') {
+                        $spareschg{$type} = 1;
+                    }
+                }
+            }
+            my @spares = sort(@okspares,$newspare);
+            $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
+        }
+        if (keys(%spareschg) > 0) {
+            $changes{'spares'}{$lonhost} = \%spareschg;
+        }
+    }
+
+    if (ref($domconfig{'usersessions'}) eq 'HASH') {
+        if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
+            if (ref($changes{'spares'}) eq 'HASH') {
+                if (keys(%{$changes{'spares'}}) > 0) {
+                    $savespares = 1;
+                }
+            }
+        } else {
+            $savespares = 1;
+        }
+    }
+
     if (keys(%changes) > 0) {
         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                                                  $dom);
@@ -6891,31 +7138,53 @@
             foreach my $prefix (@prefixes) {
                 if (ref($changes{$prefix}) eq 'HASH') {
                     $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
-                    foreach my $type (@types) {
-                        if (defined($changes{$prefix}{$type})) {
-                            my $newvalue;
-                            if (ref($defaultshash{'usersessions'}) eq 'HASH') {
-                                if (ref($defaultshash{'usersessions'}{$prefix})) {
-                                    if ($type eq 'version') {
-                                        $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
-                                    } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
-                                        if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
-                                            $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
+                    if ($prefix eq 'spares') {
+                        if (ref($changes{$prefix}) eq 'HASH') {
+                            foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
+                                $resulttext .= '<li><b>'.$lonhost.'</b> ';
+                                if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
+                                    foreach my $type (@{$types{$prefix}}) {
+                                        if ($changes{$prefix}{$lonhost}{$type}) {
+                                            my $offloadto = &mt('None');
+                                            if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
+                                                if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
+                                                    $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
+                                                }
+                                            }
+                                            $resulttext .= &mt('[_1] set to: [_2]','<i>'.$lt{'type'}.'</i>',$offloadto).(' 'x3);
                                         }
                                     }
                                 }
+                                $resulttext .= '</li>';
                             }
-                            if ($newvalue eq '') {
-                                if ($type eq 'version') {
-                                    $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
+                        }
+                    } else {
+                        foreach my $type (@{$types{$prefix}}) {
+                            if (defined($changes{$prefix}{$type})) {
+                                my $newvalue;
+                                if (ref($defaultshash{'usersessions'}) eq 'HASH') {
+                                    if (ref($defaultshash{'usersessions'}{$prefix})) {
+                                        if ($type eq 'version') {
+                                            $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
+                                        } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
+                                            if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
+                                                $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
+                                            }
+                                        }
+                                    }
+                                }
+                                if ($newvalue eq '') {
+                                    if ($type eq 'version') {
+                                        $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
+                                    } else {
+                                        $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
+                                    }
                                 } else {
-                                    $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
+                                    if ($type eq 'version') {
+                                        $newvalue .= ' '.&mt('(or later)'); 
+                                    }
+                                    $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
                                 }
-                            } else {
-                                if ($type eq 'version') {
-                                    $newvalue .= ' '.&mt('(or later)'); 
-                                } 
-                                $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>'; 
                             }
                         }
                     }
@@ -6928,7 +7197,7 @@
                           &mt('An error occurred: [_1]',$putresult).'</span>';
         }
     } else {
-        $resulttext =  &mt('No changes made to settings for user session hosting.');
+        $resulttext =  &mt('No changes made to settings for user session hosting/offloading.');
     }
     return $resulttext;
 }
@@ -7081,9 +7350,12 @@
                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
 
                remote => 'Hosting of sessions for users in this domain on servers in other domains',
+               spares => 'Servers offloaded to, when busy',
                version => 'LON-CAPA version requirement',
                excludedomain => 'Allow all, but exclude specific domains',
                includedomain => 'Deny all, but include specific domains',
+               primary => 'Primary (checked first)',
+               default => 'Default', 
            );
 }
 


More information about the LON-CAPA-cvs mailing list