Use cached conf if backend fails (Closes: #1429)

environments/ppa-mbqj77/deployments/1
Xavier Guimard 7 years ago
parent 5d02b10b6b
commit c4c63abc8b
  1. 23
      lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf.pm
  2. 16
      lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Reload.pm

@ -97,7 +97,7 @@ sub new {
if ( $self->{localStorage} and not defined( $self->{refLocalStorage} ) ) {
eval "use $self->{localStorage};";
if ($@) {
$msg .= "Unable to load $self->{localStorage}: $@.\n";
$msg .= "Error: Unable to load $self->{localStorage}: $@.\n";
}
# TODO: defer that until $> > 0 (to avoid creating local cache with
@ -132,7 +132,7 @@ sub saveConf {
my $tmp = $self->store($conf);
unless ( $tmp > 0 ) {
$msg .= "Configuration $conf->{cfgNum} not stored.\n";
$msg .= "Error: Configuration $conf->{cfgNum} not stored.\n";
$self->unlock();
return ( $tmp ? $tmp : UNKNOWN_ERROR );
}
@ -167,7 +167,7 @@ sub getConf {
else {
$args->{cfgNum} ||= $self->lastCfg;
unless ( $args->{cfgNum} ) {
$msg .= "No configuration available in backend.\n";
$msg .= "Error: No configuration available in backend.\n";
}
my $r;
unless ( ref( $self->{refLocalStorage} ) ) {
@ -180,7 +180,7 @@ sub getConf {
else {
eval { $r = $self->{refLocalStorage}->get('conf') }
if ( $> and not $args->{noCache} );
$msg = "Warn: $@" if ($@);
$msg .= "Warn: $@" if ($@);
if ( ref($r)
and $r->{cfgNum}
and $args->{cfgNum}
@ -191,8 +191,18 @@ sub getConf {
$args->{noCache} = 1;
}
else {
$r = $self->getDBConf($args);
return undef unless ( $r->{cfgNum} );
my $r2 = $self->getDBConf($args);
unless ( $r2->{cfgNum} ) {
$r = $self->{refLocalStorage}->get('conf') unless ($r);
$msg .=
$r
? "Error: Using previous cached configuration\n"
: "Error: No configuration found in local cache\n";
return undef unless ($r);
}
else {
$r = $r2;
}
$self->setDefault( $r, $args->{localPrm} );
$self->compactConf($r);
@ -201,7 +211,6 @@ sub getConf {
$self->setLocalConf($r)
if ( $self->{refLocalStorage}
and not( $args->{noCache} == 1 or $args->{raw} ) );
}
}

@ -34,7 +34,6 @@ sub onReload {
sub checkConf {
my ( $class, $force ) = @_;
my $prm = { local => !$force, localPrm => $class->localConfig };
$prm->{noCache} = 1 unless ( $class->cfgNum );
my $conf = $class->confAcc->getConf($prm);
unless ( ref($conf) ) {
@ -44,10 +43,19 @@ sub checkConf {
return $force ? 0 : $class->cfgNum ? 1 : 0;
}
if ($Lemonldap::NG::Common::Conf::msg) {
if ( $Lemonldap::NG::Common::Conf::msg =~ /Error:/ ) {
$class->logger->error($Lemonldap::NG::Common::Conf::msg);
}
elsif ( $Lemonldap::NG::Common::Conf::msg =~ /Warn:/ ) {
$class->logger->warn($Lemonldap::NG::Common::Conf::msg);
}
else {
$class->logger->debug($Lemonldap::NG::Common::Conf::msg);
}
}
if ( !$class->cfgNum or $class->cfgNum != $conf->{cfgNum} ) {
$class->logger->debug(
"Get configuration $conf->{cfgNum} ($Lemonldap::NG::Common::Conf::msg)"
);
$class->logger->debug("Get configuration $conf->{cfgNum}");
$class->lastCheck( time() );
unless ( $class->cfgNum( $conf->{cfgNum} ) ) {
$class->logger->error('No configuration available');

Loading…
Cancel
Save