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

raeburn raeburn at source.lon-capa.org
Sat Nov 24 11:48:02 EST 2018


raeburn		Sat Nov 24 16:48:02 2018 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm 
  Log:
  - Domain config for load balancer to use cookie to record offload target.
  
  
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.341 loncom/interface/domainprefs.pm:1.342
--- loncom/interface/domainprefs.pm:1.341	Sun Nov 18 22:50:52 2018
+++ loncom/interface/domainprefs.pm	Sat Nov 24 16:48:01 2018
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.341 2018/11/18 22:50:52 raeburn Exp $
+# $Id: domainprefs.pm,v 1.342 2018/11/24 16:48:01 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -6339,13 +6339,13 @@
     my $numinrow = 1;
     my $datatable;
     my %servers = &Apache::lonnet::internet_dom_servers($dom);
-    my (%currbalancer,%currtargets,%currrules,%existing);
+    my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
     if (ref($settings) eq 'HASH') {
         %existing = %{$settings};
     }
     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
-                                  \%currtargets,\%currrules);
+                                  \%currtargets,\%currrules,\%currcookies);
     } else {
         return;
     }
@@ -6422,6 +6422,9 @@
         my %hostherechecked = (
                                   no => ' checked="checked"',
                               );
+        my %balcookiechecked = (
+                                  no => ' checked="checked"', 
+                               );
         foreach my $sparetype (@sparestypes) {
             my $targettable;
             for (my $i=0; $i<$numspares; $i++) {
@@ -6477,6 +6480,11 @@
                 }
             }
         }
+        if ($currcookies{$lonhost}) {
+            %balcookiechecked = (
+                                    yes => ' checked="checked"',
+                                );
+        }
         $datatable .= &mt('Hosting on balancer itself').'<br />'.
                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
@@ -6485,7 +6493,12 @@
                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                           '</i></label><br />';
         }
-        $datatable .= '</div></td></tr>'.
+        $datatable .= &mt('Use balancer cookie').'<br />'.
+                      '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
+                      $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
+                      '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
+                      $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
+                      '</div></td></tr>'.
                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                                            $othertitle,$usertypes,$types,\%servers,
                                            \%currbalancer,$lonhost,
@@ -6499,10 +6512,11 @@
 }
 
 sub get_loadbalancers_config {
-    my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
+    my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
     return unless ((ref($servers) eq 'HASH') &&
                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
-                   (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
+                   (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
+                   (ref($currcookies) eq 'HASH'));
     if (keys(%{$existing}) > 0) {
         my $oldlonhost;
         foreach my $key (sort(keys(%{$existing}))) {
@@ -6521,6 +6535,9 @@
                 $currbalancer->{$key} = 1;
                 $currtargets->{$key} = $existing->{$key}{'targets'};
                 $currrules->{$key} = $existing->{$key}{'rules'};
+                if ($existing->{$key}{'cookie'}) {
+                    $currcookies->{$key} = 1;
+                }
             }
         }
     } else {
@@ -17003,12 +17020,12 @@
     my @sparestypes = ('primary','default');
     my %typetitles = &sparestype_titles();
     my $resulttext;
-    my (%currbalancer,%currtargets,%currrules,%existing);
+    my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
         %existing = %{$domconfig{'loadbalancing'}};
     }
     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
-                              \%currtargets,\%currrules);
+                              \%currtargets,\%currrules,\%currcookies);
     my ($saveloadbalancing,%defaultshash,%changes);
     my ($alltypes,$othertypes,$titles) =
         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
@@ -17060,6 +17077,18 @@
             }
             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
         }
+        if ($env{'form.loadbalancing_cookie_'.$i}) {
+            $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
+            if (exists($currbalancer{$balancer})) { 
+                unless ($currcookies{$balancer}) {
+                    $changes{'curr'}{$balancer}{'cookie'} = 1;
+                }
+            }
+        } elsif (exists($currbalancer{$balancer})) {
+            if ($currcookies{$balancer}) {
+                $changes{'curr'}{$balancer}{'cookie'} = 1;
+            }
+        }
         if (ref($currtargets{$balancer}) eq 'HASH') {
             foreach my $sparetype (@sparestypes) {
                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
@@ -17213,6 +17242,10 @@
                                 }
                             }
                         }
+                        if ($changes{'curr'}{$balancer}{'cookie'}) {
+                            $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
+                                                      $balancer).'</li>'; 
+                        }
                         if (keys(%toupdate)) {
                             my %thismachine;
                             my $updatedhere;
@@ -17442,12 +17475,12 @@
     }
     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
     $allinsttypes = join("','", at alltypes);
-    my (%currbalancer,%currtargets,%currrules,%existing);
+    my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
     if (ref($settings) eq 'HASH') {
         %existing = %{$settings};
     }
     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
-                              \%currtargets,\%currrules);
+                              \%currtargets,\%currrules,\%currcookies);
     my $balancers = join("','",sort(keys(%currbalancer)));
     return <<"END";
 




More information about the LON-CAPA-cvs mailing list