| 3 |
# $Id$ |
# $Id$ |
| 4 |
# |
# |
| 5 |
# $Log$ |
# $Log$ |
| 6 |
|
# Revision 1.11 2003/06/25 22:52:58 joko |
| 7 |
|
# fix:!? add storage in any case |
| 8 |
|
# |
| 9 |
|
# Revision 1.10 2003/06/06 03:26:24 joko |
| 10 |
|
# + sub existsStorage |
| 11 |
|
# |
| 12 |
|
# Revision 1.9 2003/03/27 15:31:08 joko |
| 13 |
|
# fixes to modules regarding new namespace(s) below Data::Mungle::* |
| 14 |
|
# |
| 15 |
|
# Revision 1.8 2003/02/18 19:19:47 joko |
| 16 |
|
# + modified locator handling |
| 17 |
|
# |
| 18 |
|
# Revision 1.7 2003/01/30 22:21:52 joko |
| 19 |
|
# + changed 'connect'-behaviour back to old state |
| 20 |
|
# + renamed log-output (now using 'initializing' instead of 'booting' - corresponding to 'initStorage') |
| 21 |
|
# |
| 22 |
|
# Revision 1.6 2003/01/30 21:44:00 joko |
| 23 |
|
# + temporary fix: (FIXME) now connecting to storage on storagehandle-instantiation |
| 24 |
|
# |
| 25 |
|
# Revision 1.5 2003/01/19 02:39:57 joko |
| 26 |
|
# + moved 'deep_copy' from module 'libp' to module 'Data.Transform.Deep' |
| 27 |
|
# + preserved order for hashes '$self->{config}' and '$self->{locator}' by using Tie::IxHash |
| 28 |
|
# |
| 29 |
# Revision 1.4 2002/12/04 07:38:07 jonen |
# Revision 1.4 2002/12/04 07:38:07 jonen |
| 30 |
# + deep copy |
# + deep copy |
| 31 |
# |
# |
| 54 |
# get logger instance |
# get logger instance |
| 55 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
| 56 |
|
|
| 57 |
use libp qw( deep_copy ); |
|
| 58 |
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main |
| 59 |
|
use Tie::IxHash; |
| 60 |
use Data::Dumper; |
use Data::Dumper; |
| 61 |
|
|
| 62 |
use Data::Storage; |
use Data::Storage; |
| 63 |
#use Data::Storage::Locator; |
use Data::Storage::Locator; |
| 64 |
|
use Data::Mungle::Transform::Deep qw( deep_copy ); |
| 65 |
|
use Data::Mungle::Compare::Struct qw( isEmpty ); |
| 66 |
|
|
| 67 |
sub new { |
sub new { |
| 68 |
my $invocant = shift; |
my $invocant = shift; |
| 74 |
$logger->debug( __PACKAGE__ . "->new( @args )" ); |
$logger->debug( __PACKAGE__ . "->new( @args )" ); |
| 75 |
|
|
| 76 |
my $self = { @_ }; |
my $self = { @_ }; |
| 77 |
return bless $self, $class; |
bless $self, $class; |
| 78 |
|
|
| 79 |
|
# preserve order of configuration variables |
| 80 |
|
#$self->{config} = {}; |
| 81 |
|
tie %{$self->{config}}, 'Tie::IxHash'; |
| 82 |
|
tie %{$self->{locator}}, 'Tie::IxHash'; |
| 83 |
|
|
| 84 |
|
return $self; |
| 85 |
} |
} |
| 86 |
|
|
| 87 |
sub addConfig { |
sub addConfig { |
| 110 |
$self->{storage}->{$name} = $storage; |
$self->{storage}->{$name} = $storage; |
| 111 |
} |
} |
| 112 |
|
|
| 113 |
|
sub existsStorage { |
| 114 |
|
my $self = shift; |
| 115 |
|
my $name = shift; |
| 116 |
|
return exists $self->{storage}->{$name}; |
| 117 |
|
} |
| 118 |
|
|
| 119 |
sub initLocator { |
sub initLocator { |
| 120 |
my $self = shift; |
my $self = shift; |
| 121 |
my $name = shift; |
my $name = shift; |
| 122 |
my $db_config = $self->{config}->{$name}; |
my $db_config = $self->{config}->{$name}; |
| 123 |
|
$db_config ||= {}; |
| 124 |
|
|
| 125 |
$logger->debug( __PACKAGE__ . "->initLocator( db_config $db_config )" ); |
$logger->debug( __PACKAGE__ . "->initLocator( name='$name' )" ); |
| 126 |
|
|
| 127 |
my $cfg_locator = {}; |
my $cfg_locator = {}; |
| 128 |
|
|
| 132 |
$cfg_locator->{$_} = $default->{$_}; |
$cfg_locator->{$_} = $default->{$_}; |
| 133 |
} |
} |
| 134 |
|
|
|
# name it |
|
|
$cfg_locator->{name} = $name; |
|
|
|
|
| 135 |
# merge in specific settings |
# merge in specific settings |
| 136 |
my $specific = deep_copy($db_config); |
my $specific = deep_copy($db_config); |
| 137 |
foreach (keys %$specific) { |
foreach (keys %$specific) { |
| 147 |
# HACK: set errorhandler if dbi settings are present |
# HACK: set errorhandler if dbi settings are present |
| 148 |
$cfg_locator->{dbi}->{HandleError} = \&_dbErrorHandler if $cfg_locator->{dbi}; |
$cfg_locator->{dbi}->{HandleError} = \&_dbErrorHandler if $cfg_locator->{dbi}; |
| 149 |
|
|
| 150 |
|
# trace |
| 151 |
|
#print "locator:", "\n"; |
| 152 |
|
#print Dumper($cfg_locator); |
| 153 |
|
|
| 154 |
|
# check locator metadata |
| 155 |
|
if (isEmpty($cfg_locator)) { |
| 156 |
|
$logger->warning( __PACKAGE__ . "->initLocator( name='$name' ): Metadata was empty. Please check configuration." ); |
| 157 |
|
return; |
| 158 |
|
} |
| 159 |
|
|
| 160 |
|
# name it |
| 161 |
|
$cfg_locator->{name} = $name; |
| 162 |
|
|
| 163 |
# create new locator object |
# create new locator object |
| 164 |
$self->{locator}->{$name} = Data::Storage::Locator->new( $cfg_locator ); |
$self->{locator}->{$name} = Data::Storage::Locator->new( $cfg_locator ); |
| 165 |
|
|
| 168 |
sub initLocators { |
sub initLocators { |
| 169 |
my $self = shift; |
my $self = shift; |
| 170 |
foreach (keys %{$self->{config}}) { |
foreach (keys %{$self->{config}}) { |
| 171 |
|
#print $_, "\n"; |
| 172 |
$self->initLocator($_, $self->{config}->{$_}) if !/^_/; |
$self->initLocator($_, $self->{config}->{$_}) if !/^_/; |
| 173 |
} |
} |
| 174 |
#print "locs: ", Dumper($self->{locator}); |
#print "locs: ", Dumper($self->{locator}); |
| 184 |
my $self = shift; |
my $self = shift; |
| 185 |
my $name = shift; |
my $name = shift; |
| 186 |
|
|
| 187 |
|
return if $self->existsStorage($name); |
| 188 |
|
|
| 189 |
my $locator = $self->getLocator($name); |
my $locator = $self->getLocator($name); |
| 190 |
$logger->info( __PACKAGE__ . " is booting storage declared by locator \"$name\"" ); |
$logger->info( __PACKAGE__ . " is initializing storage declared by locator \"$name\"" ); |
| 191 |
|
|
| 192 |
my $storage = Data::Storage->new($locator); |
my $storage = Data::Storage->new($locator); |
| 193 |
|
|
| 194 |
|
# TODO: do below (after 'testAvailability' and 'testIntegrity') again!!! |
| 195 |
|
#$storage->connect(); |
| 196 |
|
|
| 197 |
|
$self->addStorage($name, $storage); |
| 198 |
|
|
| 199 |
my $log_prefix = __PACKAGE__ . "->initStorage: "; |
my $log_prefix = __PACKAGE__ . "->initStorage: "; |
| 200 |
$log_prefix .= "dsn=\"$self->{locator}->{$name}->{dsn}\"" if $self->{locator}->{$name}->{dsn}; |
$log_prefix .= "dsn=\"$self->{locator}->{$name}->{dsn}\"" if $self->{locator}->{$name}->{dsn}; |
| 204 |
$locator->{status}->{availability} = $storage->testAvailability(); |
$locator->{status}->{availability} = $storage->testAvailability(); |
| 205 |
if ( !$storage->testAvailability() ) { |
if ( !$storage->testAvailability() ) { |
| 206 |
$logger->error( "$log_prefix: testAvailability failed" ); |
$logger->error( "$log_prefix: testAvailability failed" ); |
| 207 |
|
return; |
| 208 |
} |
} |
| 209 |
} |
} |
| 210 |
|
|
| 215 |
# actions if integrity fails |
# actions if integrity fails |
| 216 |
if (!$locator->{status}->{integrity}) { |
if (!$locator->{status}->{integrity}) { |
| 217 |
$logger->error( "$log_prefix: testIntegrity failed" ); |
$logger->error( "$log_prefix: testIntegrity failed" ); |
| 218 |
|
return; |
| 219 |
} |
} |
| 220 |
} |
} |
| 221 |
|
|
| 232 |
if ( !@{$storage->getChildNodes()} ) { |
if ( !@{$storage->getChildNodes()} ) { |
| 233 |
$locator->{status}->{empty} = 1; |
$locator->{status}->{empty} = 1; |
| 234 |
$logger->warning( "$log_prefix: Storage is empty."); |
$logger->warning( "$log_prefix: Storage is empty."); |
| 235 |
#return; |
return; |
| 236 |
} |
} |
| 237 |
} |
} |
| 238 |
|
|
| 255 |
|
|
| 256 |
#$self->{storage}->{$name} = $storage; |
#$self->{storage}->{$name} = $storage; |
| 257 |
#print "add storage: $name", "\n"; |
#print "add storage: $name", "\n"; |
| 258 |
$self->addStorage($name, $storage); |
#$self->addStorage($name, $storage); |
| 259 |
|
|
| 260 |
return 1; |
return 1; |
| 261 |
|
|
| 264 |
sub initStorages { |
sub initStorages { |
| 265 |
my $self = shift; |
my $self = shift; |
| 266 |
foreach (keys %{$self->{locator}}) { |
foreach (keys %{$self->{locator}}) { |
| 267 |
|
#print $_, "\n"; |
| 268 |
$self->initStorage($_); |
$self->initStorage($_); |
| 269 |
} |
} |
| 270 |
} |
} |
| 283 |
} |
} |
| 284 |
|
|
| 285 |
1; |
1; |
| 286 |
|
__END__ |