--- loncom/interface/domainprefs.pm 2012/08/27 06:28:05 1.169
+++ loncom/interface/domainprefs.pm 2013/01/04 05:37:05 1.182
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.169 2012/08/27 06:28:05 raeburn Exp $
+# $Id: domainprefs.pm,v 1.182 2013/01/04 05:37:05 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -219,7 +219,11 @@ sub handler {
'requestcourses','requestauthor','coursecategories',
'serverstatuses','helpsettings',
'coursedefaults','usersessions');
- if (keys(%servers) > 1) {
+ my %existing;
+ if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
+ %existing = %{$domconfig{'loadbalancing'}};
+ }
+ if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
push(@prefs_order,'loadbalancing');
}
my %prefs = (
@@ -384,7 +388,7 @@ sub handler {
'loadbalancing' =>
{text => 'Dedicated Load Balancer',
help => 'Domain_Configuration_Load_Balancing',
- header => [{col1 => 'Server',
+ header => [{col1 => 'Balancers',
col2 => 'Default destinations',
col3 => 'User affliation',
col4 => 'Overrides'},
@@ -402,26 +406,59 @@ sub handler {
col2 => 'Value'}],
};
}
+
+
+
my @roles = ('student','coordinator','author','admin');
my @actions = &Apache::loncommon::get_env_multiple('form.actions');
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:changePage(document.$phase,'pickactions')",
text=>"Settings to display/modify"});
my $confname = $dom.'-domainconfig';
+
if ($phase eq 'process') {
&Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
} elsif ($phase eq 'display') {
my $js = &recaptcha_js();
- if (keys(%servers) > 1) {
+ if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
my ($othertitle,$usertypes,$types) =
&Apache::loncommon::sorted_inst_types($dom);
- $js = &lonbalance_targets_js($dom,$types,\%servers).
- &new_spares_js().
- &common_domprefs_js().
- &Apache::loncommon::javascript_array_indexof();
+ $js .= &lonbalance_targets_js($dom,$types,\%servers,
+ $domconfig{'loadbalancing'}).
+ &new_spares_js().
+ &common_domprefs_js().
+ &Apache::loncommon::javascript_array_indexof();
}
&Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
} else {
+# check if domconfig user exists for the domain.
+ my $servadm = $r->dir_config('lonAdmEMail');
+ my ($configuserok,$author_ok,$switchserver) =
+ &config_check($dom,$confname,$servadm);
+ unless ($configuserok eq 'ok') {
+ &Apache::lonconfigsettings::print_header($r,$phase,$context);
+ $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
+ $confname).
+ ' '
+ );
+ if ($switchserver) {
+ $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
+ ' '.
+ &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
+ ' '.
+ &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
+ ' '.
+ &mt('To do that now, use the following link: [_1]',$switchserver)
+ );
+ } else {
+ $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
+ ' '.
+ &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
+ );
+ }
+ $r->print(&Apache::loncommon::end_page());
+ return OK;
+ }
if (keys(%domconfig) == 0) {
my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
my @ids=&Apache::lonnet::current_machine_ids();
@@ -455,6 +492,7 @@ sub handler {
}
}
}
+
&Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
}
return OK;
@@ -516,6 +554,7 @@ sub print_config_box {
my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
my $rowtotal = 0;
my $output;
+
if ($action eq 'coursecategories') {
$output = &coursecategories_javascript($settings);
}
@@ -804,7 +843,7 @@ sub print_login {
'
'.
''.$choices{'directlogin'}.
' ';
- foreach my $hostid (keys(%servers)) {
+ foreach my $hostid (sort keys(%servers)) {
next if ($servers{$hostid} eq $servers{$lonhost});
my $selected = '';
if (ref($disallowed{$lonhost}) eq 'HASH') {
@@ -1186,13 +1225,12 @@ sub display_color_options {
} else {
$datatable .= ' ';
}
- my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
+ my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
+
$datatable .= ''.
- ' '.$fontlink.
- ' '.
- ' ';
+ ' '.
+ ' ';
unless ($role eq 'login') {
$datatable .= ''.
''.$choices->{'fontmenu'}.' ';
@@ -1201,13 +1239,13 @@ sub display_color_options {
} else {
$datatable .= ' ';
}
- $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
+ $current_color = $designs->{'fontmenu'} ?
+ $designs->{'fontmenu'} : $defaults->{'fontmenu'};
$datatable .= ''.
- ' '.$fontlink.
- ' '.
- ' ';
+ ' '.
+ ' ';
}
my $switchserver = &check_switchserver($dom,$confname);
foreach my $img (@{$images}) {
@@ -1334,13 +1372,16 @@ sub display_color_options {
}
$datatable .= ''.
' ';
@@ -1362,13 +1403,13 @@ sub display_color_options {
$datatable .= ''.
'';
foreach my $item (@{$links}) {
- $datatable .= ''."\n".
- &color_pick($phase,$role,$item,$choices->{$item},
- $designs->{'links'}{$item});
+ my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
+ $datatable .= ' '."\n";
+
if ($designs->{'links'}{$item}) {
- $datatable.=' ';
+ $datatable.=' ';
}
- $datatable .= ' ';
}
$$rowtotal += $itemcount;
@@ -1709,9 +1750,7 @@ sub print_quotas {
} elsif ($context eq 'requestauthor') {
my $curroption;
if (ref($settings) eq 'HASH') {
- if (ref($settings->{'requestauthor'}) eq 'HASH') {
- $curroption = $settings->{'requestauthor'};
- }
+ $curroption = $settings->{'default'};
}
if (!$curroption) {
$curroption = 'norequest';
@@ -1856,8 +1895,8 @@ sub print_quotas {
$checked = ' checked="checked"';
}
$datatable .= ''.
- ' '.
+ ' '.
$titles{$option}.' ';
}
} else {
@@ -1960,7 +1999,7 @@ sub print_requestmail {
$datatable .= ''.
' '.
- $fullname.' ';
+ $fullname.' ('.$uname.':'.$udom.')';
}
$datatable .= '
';
} else {
@@ -2386,7 +2425,7 @@ sub radiobutton_prefs {
return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
(ref($choices) eq 'HASH'));
- my (%checkedon,%checkedoff,$datatable,$css_class,$cell_colspan);
+ my (%checkedon,%checkedoff,$datatable,$css_class);
foreach my $item (@{$toggles}) {
if ($defaultchecked->{$item} eq 'on') {
@@ -2877,16 +2916,13 @@ sub print_loadbalancing {
my $numinrow = 1;
my $datatable;
my %servers = &Apache::lonnet::internet_dom_servers($dom);
- my ($currbalancer,$currtargets,$currrules);
- if (keys(%servers) > 1) {
- if (ref($settings) eq 'HASH') {
- $currbalancer = $settings->{'lonhost'};
- $currtargets = $settings->{'targets'};
- $currrules = $settings->{'rules'};
- } else {
- ($currbalancer,$currtargets) =
- &Apache::lonnet::get_lonbalancer_config(\%servers);
- }
+ my (%currbalancer,%currtargets,%currrules,%existing);
+ if (ref($settings) eq 'HASH') {
+ %existing = %{$settings};
+ }
+ if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
+ &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
+ \%currtargets,\%currrules);
} else {
return;
}
@@ -2896,104 +2932,190 @@ sub print_loadbalancing {
if (ref($types) eq 'ARRAY') {
$rownum += scalar(@{$types});
}
- my $css_class = ' class="LC_odd_row"';
- my $targets_div_style = 'display: none';
- my $disabled_div_style = 'display: block';
- my $homedom_div_style = 'display: none';
- $datatable = ' '.
- ''.
- ''."\n".
- ''."\n";
- foreach my $lonhost (sort(keys(%servers))) {
- my $selected;
- if ($lonhost eq $currbalancer) {
- $selected .= ' selected="selected"';
- }
- $datatable .= ' '.$lonhost.' '."\n";
- }
- $datatable .= '
'.
- ''.&mt('No dedicated Load Balancer').'
'."\n".
- ''.&mt('Offloads to:').'
';
- my ($numspares,@spares) = &count_servers($currbalancer,%servers);
- my @sparestypes = ('primary','default');
- my %typetitles = &sparestype_titles();
- foreach my $sparetype (@sparestypes) {
- my $targettable;
- for (my $i=0; $i<$numspares; $i++) {
- my $checked;
- if (ref($currtargets) eq 'HASH') {
- if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
- if (grep(/^\Q$spares[$i]\E$/,@{$currtargets->{$sparetype}})) {
- $checked = ' checked="checked"';
+ my @css_class = ('LC_odd_row','LC_even_row');
+ my $balnum = 0;
+ my $islast;
+ my (@toshow,$disabledtext);
+ if (keys(%currbalancer) > 0) {
+ @toshow = sort(keys(%currbalancer));
+ if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
+ push(@toshow,'');
+ }
+ } else {
+ @toshow = ('');
+ $disabledtext = &mt('No existing load balancer');
+ }
+ foreach my $lonhost (@toshow) {
+ if ($balnum == scalar(@toshow)-1) {
+ $islast = 1;
+ } else {
+ $islast = 0;
+ }
+ my $cssidx = $balnum%2;
+ my $targets_div_style = 'display: none';
+ my $disabled_div_style = 'display: block';
+ my $homedom_div_style = 'display: none';
+ $datatable .= '
'.
+ ''.
+ '';
+ if ($lonhost eq '') {
+ $datatable .= '';
+ if (keys(%currbalancer) > 0) {
+ $datatable .= &mt('Add balancer:');
+ } else {
+ $datatable .= &mt('Enable balancer:');
+ }
+ $datatable .= ' '.
+ ''."\n".
+ ''.&mt('None').
+ ' '."\n";
+ foreach my $server (sort(keys(%servers))) {
+ next if ($currbalancer{$server});
+ $datatable .= ''.$server.' '."\n";
+ }
+ $datatable .=
+ ' '."\n".
+ ' '."\n";
+ } else {
+ $datatable .= ''.$lonhost.' '.
+ ' '.
+ &mt('Stop balancing').' '.
+ ' ';
+ $targets_div_style = 'display: block';
+ $disabled_div_style = 'display: none';
+ if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
+ $homedom_div_style = 'display: block';
+ }
+ }
+ $datatable .= '
'.
+ ''.$disabledtext.'
'."\n".
+ ''.&mt('Offloads to:').' ';
+ my ($numspares,@spares) = &count_servers($lonhost,%servers);
+ my @sparestypes = ('primary','default');
+ my %typetitles = &sparestype_titles();
+ foreach my $sparetype (@sparestypes) {
+ my $targettable;
+ for (my $i=0; $i<$numspares; $i++) {
+ my $checked;
+ if (ref($currtargets{$lonhost}) eq 'HASH') {
+ if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
+ if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
+ $checked = ' checked="checked"';
+ }
+ }
+ }
+ my ($chkboxval,$disabled);
+ if (($lonhost ne '') && (exists($servers{$lonhost}))) {
+ $chkboxval = $spares[$i];
+ }
+ if (exists($currbalancer{$spares[$i]})) {
+ $disabled = ' disabled="disabled"';
+ }
+ $targettable .=
+ '
'.$chkboxval.
+ ' ';
+ my $rem = $i%($numinrow);
+ if ($rem == 0) {
+ if (($i > 0) && ($i < $numspares-1)) {
+ $targettable .= ' ';
+ }
+ if ($i < $numspares-1) {
+ $targettable .= '
';
}
}
}
- my $chkboxval;
- if (($currbalancer ne '') && (grep((/^\Q$currbalancer\E$/,keys(%servers))))) {
- $chkboxval = $spares[$i];
- }
- $targettable .= ' '.$chkboxval.
- ' ';
- my $rem = $i%($numinrow);
- if ($rem == 0) {
- if ($i > 0) {
- $targettable .= ' ';
- }
- $targettable .= '
';
+ if ($targettable ne '') {
+ my $rem = $numspares%($numinrow);
+ my $colsleft = $numinrow - $rem;
+ if ($colsleft > 1 ) {
+ $targettable .= ''.
+ ' ';
+ } elsif ($colsleft == 1) {
+ $targettable .= ' ';
+ }
+ $datatable .= ''.$typetitles{$sparetype}.' '.
+ ' ';
+ }
+ }
+ $datatable .= ' '.
+ &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
+ $othertitle,$usertypes,$types,\%servers,
+ \%currbalancer,$lonhost,
+ $targets_div_style,$homedom_div_style,
+ $css_class[$cssidx],$balnum,$islast);
+ $$rowtotal += $rownum;
+ $balnum ++;
+ }
+ $datatable .= '
';
+ return $datatable;
+}
+
+sub get_loadbalancers_config {
+ my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
+ return unless ((ref($servers) eq 'HASH') &&
+ (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
+ (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
+ if (keys(%{$existing}) > 0) {
+ my $oldlonhost;
+ foreach my $key (sort(keys(%{$existing}))) {
+ if ($key eq 'lonhost') {
+ $oldlonhost = $existing->{'lonhost'};
+ $currbalancer->{$oldlonhost} = 1;
+ } elsif ($key eq 'targets') {
+ if ($oldlonhost) {
+ $currtargets->{$oldlonhost} = $existing->{'targets'};
+ }
+ } elsif ($key eq 'rules') {
+ if ($oldlonhost) {
+ $currrules->{$oldlonhost} = $existing->{'rules'};
+ }
+ } elsif (ref($existing->{$key}) eq 'HASH') {
+ $currbalancer->{$key} = 1;
+ $currtargets->{$key} = $existing->{$key}{'targets'};
+ $currrules->{$key} = $existing->{$key}{'rules'};
}
}
- if ($targettable ne '') {
- my $rem = $numspares%($numinrow);
- my $colsleft = $numinrow - $rem;
- if ($colsleft > 1 ) {
- $targettable .= '
'.
- ' ';
- } elsif ($colsleft == 1) {
- $targettable .= '
';
+ } else {
+ my ($balancerref,$targetsref) =
+ &Apache::lonnet::get_lonbalancer_config($servers);
+ if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
+ foreach my $server (sort(keys(%{$balancerref}))) {
+ $currbalancer->{$server} = 1;
+ $currtargets->{$server} = $targetsref->{$server};
}
- $datatable .= '
'.$typetitles{$sparetype}.' '.
- '
';
}
}
- $datatable .= '
'.
- &loadbalancing_rules($dom,$intdom,$currrules,$othertitle,
- $usertypes,$types,\%servers,$currbalancer,
- $targets_div_style,$homedom_div_style,$css_class);
- $$rowtotal += $rownum;
- return $datatable;
+ return;
}
sub loadbalancing_rules {
my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
- $currbalancer,$targets_div_style,$homedom_div_style,$css_class) = @_;
+ $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
+ $css_class,$balnum,$islast) = @_;
my $output;
+ my $num = 0;
my ($alltypes,$othertypes,$titles) =
&loadbalancing_titles($dom,$intdom,$usertypes,$types);
if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
foreach my $type (@{$alltypes}) {
+ $num ++;
my $current;
if (ref($currrules) eq 'HASH') {
$current = $currrules->{$type};
}
if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
- if ($dom ne &Apache::lonnet::host_domain($currbalancer)) {
+ if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
$current = '';
}
}
$output .= &loadbalance_rule_row($type,$titles->{$type},$current,
- $servers,$currbalancer,$dom,
- $targets_div_style,$homedom_div_style,$css_class);
+ $servers,$currbalancer,$lonhost,$dom,
+ $targets_div_style,$homedom_div_style,
+ $css_class,$balnum,$num,$islast);
}
}
return $output;
@@ -3030,8 +3152,8 @@ sub loadbalancing_titles {
}
sub loadbalance_rule_row {
- my ($type,$title,$current,$servers,$currbalancer,$dom,$targets_div_style,
- $homedom_div_style,$css_class) = @_;
+ my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
+ $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
my @rulenames = ('default','homeserver');
my %ruletitles = &offloadtype_text();
if ($type eq '_LC_external') {
@@ -3044,9 +3166,15 @@ sub loadbalance_rule_row {
if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
$style = $homedom_div_style;
}
+ my $space;
+ if ($islast && $num == 1) {
+ $space = '
';
+ }
my $output =
- ''.$title.'
'."\n".
- ''."\n";
+ '
'.$space.
+ ''.$title.'
'."\n".
+ ''.$space.
+ ''."\n";
for (my $i=0; $i<@rulenames; $i++) {
my $rule = $rulenames[$i];
my ($checked,$extra);
@@ -3062,17 +3190,20 @@ sub loadbalance_rule_row {
unless ($checked) {
$default = ' selected="selected"';
}
- $extra = ':
'."\n".
- ' '."\n";
- foreach my $lonhost (sort(keys(%{$servers}))) {
- next if ($lonhost eq $currbalancer);
+ $extra =
+ ': '."\n".
+ ' '."\n";
+ foreach my $server (sort(keys(%{$servers}))) {
+ if (ref($currbalancer) eq 'HASH') {
+ next if (exists($currbalancer->{$server}));
+ }
my $selected;
- if ($lonhost eq $current) {
+ if ($server eq $current) {
$selected = ' selected="selected"';
}
- $extra .= ''.$lonhost.' ';
+ $extra .= ''.$server.' ';
}
$extra .= ' ';
}
@@ -3080,9 +3211,9 @@ sub loadbalance_rule_row {
$checked = ' checked="checked"';
}
$output .= ''.
- ' '.$ruletitles{$rulenames[$i]}.
' '.$extra.' '."\n";
}
@@ -5566,7 +5697,7 @@ sub check_switchserver {
my @ids=&Apache::lonnet::current_machine_ids();
foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
if (!$allowed) {
- $switchserver=''.&mt('Switch Server').' ';
+ $switchserver=''.&mt('Switch Server').' ';
}
return $switchserver;
}
@@ -5836,6 +5967,10 @@ sub modify_quotas {
$cond = $conditions{$inconf{$type}};
}
$resulttext .= ''.&mt('Set to be available to [_1].',$typetitle).' '.$cond.' ';
+ } elsif ($context eq 'requestauthor') {
+ $resulttext .= ''.&mt('Set to "[_1]" for "[_2]".',
+ $titles{$inconf{$type}},$typetitle);
+
} else {
$resulttext .= ' '.&mt('Set to be available to [_1]',$typetitle).' ';
}
@@ -6209,13 +6344,16 @@ sub modify_autocreate {
foreach my $item (@types) {
if ($changes{$item}) {
my $newtxt = $offon[$newvals{$item}];
- $resulttext .= ''.&mt("$title{$item} set to [_1]$newtxt [_2]",'',' ').' ';
+ $resulttext .= ''.
+ &mt("$title{$item} set to [_1]$newtxt [_2]",
+ '',' ').
+ ' ';
}
}
if ($changes{'xmldc'}) {
my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
- $resulttext .= ''.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'',' ').' ';
+ $resulttext .= ''.&mt("$title{'xmldc'} set to [_1]",''.$newtxt.' ').' ';
}
$resulttext .= '';
} else {
@@ -6361,7 +6499,11 @@ sub modify_directorysrch {
} else {
$chgtext =~ s/\; $//;
}
- $resulttext .= ''.&mt("Users from domain '[_1] ' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).' ';
+ $resulttext .=
+ ''.
+ &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
+ ''.$dom.' ',$chgtext).
+ ' ';
}
}
}
@@ -6389,7 +6531,7 @@ sub modify_directorysrch {
}
}
$chgtext =~ s/\; $//;
- $resulttext .= ''.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).' ';
+ $resulttext .= ''.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).' ';
}
$resulttext .= '';
} else {
@@ -6975,10 +7117,12 @@ sub process_captcha {
if (ref($current->{'recaptchakeys'}) eq 'HASH') {
$currpub = $current->{'recaptchakeys'}{'public'};
$currpriv = $current->{'recaptchakeys'}{'private'};
- $newsettings->{'recaptchakeys'} = {
- public => '',
- private => '',
- }
+ unless ($newsettings->{'captcha'} eq 'recaptcha') {
+ $newsettings->{'recaptchakeys'} = {
+ public => '',
+ private => '',
+ }
+ }
}
if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
if ($container eq 'cancreate') {
@@ -8064,186 +8208,192 @@ sub modify_loadbalancing {
my @sparestypes = ('primary','default');
my %typetitles = &sparestype_titles();
my $resulttext;
- if (keys(%servers) > 1) {
- my ($currbalancer,$currtargets,$currrules);
- if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
- $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
- $currtargets = $domconfig{'loadbalancing'}{'targets'};
- $currrules = $domconfig{'loadbalancing'}{'rules'};
- } else {
- ($currbalancer,$currtargets) =
- &Apache::lonnet::get_lonbalancer_config(\%servers);
- }
- my ($saveloadbalancing,%defaultshash,%changes);
- my ($alltypes,$othertypes,$titles) =
- &loadbalancing_titles($dom,$intdom,$usertypes,$types);
- my %ruletitles = &offloadtype_text();
- my $balancer = $env{'form.loadbalancing_lonhost'};
- if (!$servers{$balancer}) {
- undef($balancer);
- }
- if ($currbalancer ne $balancer) {
- $changes{'lonhost'} = 1;
- }
- $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
- if ($balancer ne '') {
- unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
- $saveloadbalancing = 1;
+ my (%currbalancer,%currtargets,%currrules,%existing);
+ if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
+ %existing = %{$domconfig{'loadbalancing'}};
+ }
+ &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
+ \%currtargets,\%currrules);
+ my ($saveloadbalancing,%defaultshash,%changes);
+ my ($alltypes,$othertypes,$titles) =
+ &loadbalancing_titles($dom,$intdom,$usertypes,$types);
+ my %ruletitles = &offloadtype_text();
+ my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
+ for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
+ my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
+ if ($balancer eq '') {
+ next;
+ }
+ if (!exists($servers{$balancer})) {
+ if (exists($currbalancer{$balancer})) {
+ push(@{$changes{'delete'}},$balancer);
}
- foreach my $sparetype (@sparestypes) {
- my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
- my @offloadto;
- foreach my $target (@targets) {
- if (($servers{$target}) && ($target ne $balancer)) {
- if ($sparetype eq 'default') {
- if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
- next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
- }
- }
- unless(grep(/^\Q$target\E$/,@offloadto)) {
- push(@offloadto,$target);
+ next;
+ }
+ if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
+ push(@{$changes{'delete'}},$balancer);
+ next;
+ }
+ if (!exists($currbalancer{$balancer})) {
+ push(@{$changes{'add'}},$balancer);
+ }
+ $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
+ $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
+ $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
+ unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
+ $saveloadbalancing = 1;
+ }
+ foreach my $sparetype (@sparestypes) {
+ my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
+ my @offloadto;
+ foreach my $target (@targets) {
+ if (($servers{$target}) && ($target ne $balancer)) {
+ if ($sparetype eq 'default') {
+ if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
+ next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
}
}
- $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
+ unless(grep(/^\Q$target\E$/,@offloadto)) {
+ push(@offloadto,$target);
+ }
}
- }
- } else {
- foreach my $sparetype (@sparestypes) {
- $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
+ $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
}
}
- if (ref($currtargets) eq 'HASH') {
+ if (ref($currtargets{$balancer}) eq 'HASH') {
foreach my $sparetype (@sparestypes) {
- if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
- my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
+ if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
+ my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
if (@targetdiffs > 0) {
- $changes{'targets'} = 1;
+ $changes{'curr'}{$balancer}{'targets'} = 1;
}
- } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
- if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
- $changes{'targets'} = 1;
+ } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
+ if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
+ $changes{'curr'}{$balancer}{'targets'} = 1;
}
}
}
} else {
- foreach my $sparetype (@sparestypes) {
- if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
- if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
- $changes{'targets'} = 1;
+ if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
+ foreach my $sparetype (@sparestypes) {
+ if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
+ if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
+ $changes{'curr'}{$balancer}{'targets'} = 1;
+ }
}
}
}
}
my $ishomedom;
- if ($balancer ne '') {
- if (&Apache::lonnet::host_domain($balancer) eq $dom) {
- $ishomedom = 1;
- }
+ if (&Apache::lonnet::host_domain($balancer) eq $dom) {
+ $ishomedom = 1;
}
if (ref($alltypes) eq 'ARRAY') {
foreach my $type (@{$alltypes}) {
my $rule;
- if ($balancer ne '') {
- unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
+ unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
(!$ishomedom)) {
- $rule = $env{'form.loadbalancing_rules_'.$type};
- }
- if ($rule eq 'specific') {
- $rule = $env{'form.loadbalancing_singleserver_'.$type};
- }
+ $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
}
- $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
- if (ref($currrules) eq 'HASH') {
- if ($rule ne $currrules->{$type}) {
- $changes{'rules'}{$type} = 1;
+ if ($rule eq 'specific') {
+ $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
+ }
+ $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
+ if (ref($currrules{$balancer}) eq 'HASH') {
+ if ($rule ne $currrules{$balancer}{$type}) {
+ $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
}
} elsif ($rule ne '') {
- $changes{'rules'}{$type} = 1;
+ $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
}
}
}
- my $nochgmsg = &mt('No changes made to Load Balancer settings.');
- if ((keys(%changes) > 0) || ($saveloadbalancing)) {
- my $putresult = &Apache::lonnet::put_dom('configuration',
- \%defaultshash,$dom);
- if ($putresult eq 'ok') {
- if (keys(%changes) > 0) {
- if ($changes{'lonhost'}) {
- if ($currbalancer ne '') {
- &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
- }
- if ($balancer eq '') {
- $resulttext .= ''.&mt('Load Balancing with dedicated server discontinued').' ';
- } else {
- &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
- $resulttext .= ''.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
- }
- } else {
+ }
+ my $nochgmsg = &mt('No changes made to Load Balancer settings.');
+ if ((keys(%changes) > 0) || ($saveloadbalancing)) {
+ unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
+ $defaultshash{'loadbalancing'} = {};
+ }
+ my $putresult = &Apache::lonnet::put_dom('configuration',
+ \%defaultshash,$dom);
+
+ if ($putresult eq 'ok') {
+ if (keys(%changes) > 0) {
+ if (ref($changes{'delete'}) eq 'ARRAY') {
+ foreach my $balancer (sort(@{$changes{'delete'}})) {
+ $resulttext .= ' '.&mt('Load Balancing discontinued for: [_1]',$balancer).' ';
&Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
}
- if (($changes{'targets'}) && ($balancer ne '')) {
- my %offloadstr;
- foreach my $sparetype (@sparestypes) {
- if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
- if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
- $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
+ }
+ if (ref($changes{'add'}) eq 'ARRAY') {
+ foreach my $balancer (sort(@{$changes{'add'}})) {
+ $resulttext .= ''.&mt('Load Balancing enabled for: [_1]',$balancer);
+ }
+ }
+ if (ref($changes{'curr'}) eq 'HASH') {
+ foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
+ if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
+ if ($changes{'curr'}{$balancer}{'targets'}) {
+ my %offloadstr;
+ foreach my $sparetype (@sparestypes) {
+ if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
+ if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
+ $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
+ }
+ }
}
- }
- }
- if (keys(%offloadstr) == 0) {
- $resulttext .= ' '.&mt("Servers to which Load Balance server offloads set to 'None', by default").' ';
- } else {
- my $showoffload;
- foreach my $sparetype (@sparestypes) {
- $showoffload .= ''.$typetitles{$sparetype}.' : ';
- if (defined($offloadstr{$sparetype})) {
- $showoffload .= $offloadstr{$sparetype};
+ if (keys(%offloadstr) == 0) {
+ $resulttext .= ''.&mt("Servers to which Load Balance server offloads set to 'None', by default").' ';
} else {
- $showoffload .= &mt('None');
+ my $showoffload;
+ foreach my $sparetype (@sparestypes) {
+ $showoffload .= ''.$typetitles{$sparetype}.' : ';
+ if (defined($offloadstr{$sparetype})) {
+ $showoffload .= $offloadstr{$sparetype};
+ } else {
+ $showoffload .= &mt('None');
+ }
+ $showoffload .= (' 'x3);
+ }
+ $resulttext .= ''.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).' ';
}
- $showoffload .= (' 'x3);
}
- $resulttext .= ''.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).' ';
}
- }
- if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
- if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
- foreach my $type (@{$alltypes}) {
- if ($changes{'rules'}{$type}) {
- my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
- my $balancetext;
- if ($rule eq '') {
- $balancetext = $ruletitles{'default'};
- } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
- $balancetext = $ruletitles{$rule};
- } else {
- $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
+ if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
+ if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
+ foreach my $type (@{$alltypes}) {
+ if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
+ my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
+ my $balancetext;
+ if ($rule eq '') {
+ $balancetext = $ruletitles{'default'};
+ } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
+ $balancetext = $ruletitles{$rule};
+ } else {
+ $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
+ }
+ $resulttext .= ''.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).' ';
}
- $resulttext .= ''.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).' ';
}
}
}
+ &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
}
- if ($resulttext ne '') {
- $resulttext = &mt('Changes made:').'';
- } else {
- $resulttext = $nochgmsg;
- }
+ }
+ if ($resulttext ne '') {
+ $resulttext = &mt('Changes made:').'';
} else {
$resulttext = $nochgmsg;
- if ($balancer ne '') {
- &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
- }
}
} else {
- $resulttext = ''.
- &mt('An error occurred: [_1]',$putresult).' ';
+ $resulttext = $nochgmsg;
}
} else {
- $resulttext = $nochgmsg;
+ $resulttext = ''.
+ &mt('An error occurred: [_1]',$putresult).' ';
}
} else {
- $resulttext = &mt('Load Balancing unavailable as this domain only has one server.');
+ $resulttext = $nochgmsg;
}
return $resulttext;
}
@@ -8348,6 +8498,7 @@ sub active_dc_picker {
' '.
&Apache::loncommon::plainname($dcname,$dcdom).
+ ' ('.$dcname.':'.$dcdom.')'.
' ';
}
$datatable .= '';
@@ -8399,7 +8550,7 @@ sub count_servers {
}
sub lonbalance_targets_js {
- my ($dom,$types,$servers) = @_;
+ my ($dom,$types,$servers,$settings) = @_;
my $select = &mt('Select');
my ($alltargets,$allishome,$allinsttypes,@alltypes);
if (ref($servers) eq 'HASH') {
@@ -8421,39 +8572,71 @@ sub lonbalance_targets_js {
}
push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
$allinsttypes = join("','",@alltypes);
+ my (%currbalancer,%currtargets,%currrules,%existing);
+ if (ref($settings) eq 'HASH') {
+ %existing = %{$settings};
+ }
+ &get_loadbalancers_config($servers,\%existing,\%currbalancer,
+ \%currtargets,\%currrules);
+ my $balancers = join("','",sort(keys(%currbalancer)));
return <<"END";