diff options
-rw-r--r-- | config-db/OpenSLX/ConfigDB.pm | 19 | ||||
-rw-r--r-- | config-db/OpenSLX/DBSchema.pm | 29 | ||||
-rw-r--r-- | config-db/OpenSLX/MetaDB/DBI.pm | 23 | ||||
-rw-r--r-- | os-plugins/OpenSLX/OSPlugin/Roster.pm | 23 |
4 files changed, 85 insertions, 9 deletions
diff --git a/config-db/OpenSLX/ConfigDB.pm b/config-db/OpenSLX/ConfigDB.pm index 1d9c6a36..37bc1404 100644 --- a/config-db/OpenSLX/ConfigDB.pm +++ b/config-db/OpenSLX/ConfigDB.pm @@ -151,9 +151,8 @@ The precise name of the database that should be connected (defaults to 'openslx' sub connect ## no critic (ProhibitBuiltinHomonyms) { my $self = shift; - my $dbParams = shift; - # hash-ref with any additional info that might be required by - # specific metadb-module (not used yet) + my $dbParams = shift; # hash-ref with any additional info that might be + # required by specific metadb-module (not used yet) my $dbType = $openslxConfig{'db-type'}; # name of underlying database module... @@ -191,6 +190,17 @@ sub connect ## no critic (ProhibitBuiltinHomonyms) $self->{'db-schema'}->checkAndUpgradeDBSchemaIfNecessary($self) or die _tr('unable to check/update DB schema!'); + # check if any plugins (or plugin-attributes) have been added/removed since + # last DB-session and bring the DB up-to-date, if so + my $pluginInfoHashVal + = OpenSLX::OSPlugin::Roster->computeMD5HashOverAvailablePlugins(); + my $pluginInfoHashValInDB = $metaDB->schemaFetchPluginInfoHashVal(); + vlog(1, "plugin-info-hashes: $pluginInfoHashVal <=> $pluginInfoHashValInDB"); + if ($pluginInfoHashValInDB ne $pluginInfoHashVal) { + $self->cleanupAnyInconsistencies(); + return if !$metaDB->schemaSetPluginInfoHashVal($pluginInfoHashVal); + } + return 1; } @@ -1285,9 +1295,6 @@ sub addInstalledPlugin my $pluginName = shift; my $pluginAttrs = shift || {}; - # make sure the attributes of this plugin are available via default system - $self->synchronizeAttributesWithDB(); - return $self->{'meta-db'}->addInstalledPlugin( $vendorOSID, $pluginName, $pluginAttrs ); diff --git a/config-db/OpenSLX/DBSchema.pm b/config-db/OpenSLX/DBSchema.pm index 3fa9c40b..24f46fc6 100644 --- a/config-db/OpenSLX/DBSchema.pm +++ b/config-db/OpenSLX/DBSchema.pm @@ -34,7 +34,7 @@ use OpenSLX::Basics; ### fk => foreign key (integer) ################################################################################ -my $VERSION = 0.32; +my $VERSION = 0.33; my $DbSchema = { 'version' => $VERSION, @@ -173,11 +173,16 @@ my $DbSchema = { 'meta' => { # information about the database as such 'cols' => [ - 'schema_version:s.5', # schema-version currently implemented by DB + 'plugin_info_hash:s.32', # hash-value identifying a specific + # set of plugins and their + # attributes + 'schema_version:s.5', # schema-version currently + # implemented by DB ], 'vals' => [ { - 'schema_version' => $VERSION, + 'plugin_info_hash' => '', + 'schema_version' => $VERSION, }, ], }, @@ -723,6 +728,24 @@ sub _schemaUpgradeDBFrom return 1; }, + 0.33 => sub { + my $metaDB = shift; + + # add new column meta.plugin_info_hash + $metaDB->schemaAddColumns( + 'meta', + [ + 'plugin_info_hash:s.32', + ], + undef, + [ + 'plugin_info_hash:s.32', + 'schema_version:s.5', + ] + ); + + return 1; + }, ); 1; diff --git a/config-db/OpenSLX/MetaDB/DBI.pm b/config-db/OpenSLX/MetaDB/DBI.pm index 7acb861f..c4606f0c 100644 --- a/config-db/OpenSLX/MetaDB/DBI.pm +++ b/config-db/OpenSLX/MetaDB/DBI.pm @@ -1273,6 +1273,29 @@ sub schemaSetDBVersion return 1; } +sub schemaFetchPluginInfoHashVal +{ + my $self = shift; + + my $row + = $self->{dbh}->selectrow_hashref('SELECT plugin_info_hash FROM meta'); + + return $row->{plugin_info_hash}; +} + +sub schemaSetPluginInfoHashVal +{ + my $self = shift; + my $pluginInfoHashVal = shift; + + $self->{dbh}->do("UPDATE meta SET plugin_info_hash = '$pluginInfoHashVal'") + or croak _tr( + 'Unable to set plugin-info-hash-value to %s!', $pluginInfoHashVal + ); + + return 1; +} + sub schemaConvertTypeDescrToNative { # a default implementation, many DBs need to override... my $self = shift; diff --git a/os-plugins/OpenSLX/OSPlugin/Roster.pm b/os-plugins/OpenSLX/OSPlugin/Roster.pm index 7bfed044..93887ec7 100644 --- a/os-plugins/OpenSLX/OSPlugin/Roster.pm +++ b/os-plugins/OpenSLX/OSPlugin/Roster.pm @@ -18,6 +18,7 @@ use warnings; use OpenSLX::Basics; use Clone qw(clone); +use Digest::MD5 qw(md5_hex); my %plugins; @@ -40,6 +41,28 @@ sub getAvailablePlugins return \%pluginInfo; } +=item C<computeMD5HashOverAvailablePlugins()> + +Returns a MD5 hash representing the list of available plugins and all their +attributes. + +=cut + +sub computeMD5HashOverAvailablePlugins +{ + my $class = shift; + + $class->_init() if !%plugins; + + my $pluginInfoString = ''; + foreach my $pluginName (sort keys %plugins) { + my $attrInfo = $plugins{$pluginName}->getAttrInfo(); + my $attrList = join ',', sort keys %$attrInfo; + $pluginInfoString .= $pluginName . '(' . $attrList . ')'; + } + return md5_hex($pluginInfoString); +} + =item C<getPlugin()> Returns an instance of the plugin with the given name |