Commit 01684654 authored by Leo Gordon's avatar Leo Gordon
Browse files

api_change: moved caching of MetaParameters and PipelineWideParameters into Cacheable

parent 1c1f70c9
......@@ -62,20 +62,5 @@ package Bio::EnsEMBL::Hive;
use strict;
use warnings;
use Bio::EnsEMBL::Hive::Utils::Collection;
our %hash_of_collections;
sub collection {
my $class = shift @_;
my $key = shift @_;
if(@_) {
$hash_of_collections{$key} = shift @_;
}
return $hash_of_collections{$key} ||= Bio::EnsEMBL::Hive::Utils::Collection->new();
}
1;
......@@ -41,6 +41,9 @@ use Bio::EnsEMBL::Hive::DBSQL::DBConnection;
use Bio::EnsEMBL::Hive::DBSQL::SqlSchemaAdaptor;
use Bio::EnsEMBL::Hive::Utils ('throw');
use Bio::EnsEMBL::Hive::Utils::Collection;
use Bio::EnsEMBL::Hive::MetaParameters;
use Bio::EnsEMBL::Hive::PipelineWideParameters;
use Bio::EnsEMBL::Hive::ResourceClass;
use Bio::EnsEMBL::Hive::ResourceDescription;
use Bio::EnsEMBL::Hive::Analysis;
......@@ -94,7 +97,7 @@ sub new {
my $code_sql_schema_version = Bio::EnsEMBL::Hive::DBSQL::SqlSchemaAdaptor->get_code_sql_schema_version()
|| die "DB($url) Could not establish code_sql_schema_version, please check that 'EHIVE_ROOT_DIR' environment variable is set correctly";
my $db_sql_schema_version = eval { $self->get_MetaAdaptor->fetch_value_by_key( 'hive_sql_schema_version' ); };
my $db_sql_schema_version = eval { $self->get_MetaAdaptor->get_value_by_key( 'hive_sql_schema_version' ); };
if($@) {
if($@ =~ /hive_meta.*doesn't exist/) {
......@@ -149,7 +152,7 @@ sub hive_use_triggers { # getter only, not setter
my $self = shift @_;
unless( defined($self->{'_hive_use_triggers'}) ) {
my $hive_use_triggers = $self->get_MetaAdaptor->fetch_value_by_key( 'hive_use_triggers' );
my $hive_use_triggers = $self->get_MetaAdaptor->get_value_by_key( 'hive_use_triggers' );
$self->{'_hive_use_triggers'} = $hive_use_triggers || 0;
}
return $self->{'_hive_use_triggers'};
......@@ -160,7 +163,7 @@ sub hive_use_param_stack { # getter only, not setter
my $self = shift @_;
unless( defined($self->{'_hive_use_param_stack'}) ) {
my $hive_use_param_stack = $self->get_MetaAdaptor->fetch_value_by_key( 'hive_use_param_stack' );
my $hive_use_param_stack = $self->get_MetaAdaptor->get_value_by_key( 'hive_use_param_stack' );
$self->{'_hive_use_param_stack'} = $hive_use_param_stack || 0;
}
return $self->{'_hive_use_param_stack'};
......@@ -186,6 +189,7 @@ our %adaptor_type_2_package_name = (
# aliases:
'Job' => 'Bio::EnsEMBL::Hive::DBSQL::AnalysisJobAdaptor',
'Worker' => 'Bio::EnsEMBL::Hive::Queen',
'MetaParameters' => 'Bio::EnsEMBL::Hive::DBSQL::MetaAdaptor',
);
......@@ -262,8 +266,9 @@ sub AUTOLOAD {
sub init_collections { # should not really belong to DBAdaptor, temporarily squatting here...
foreach my $AdaptorType ('Meta', 'PipelineWideParameters') {
Bio::EnsEMBL::Hive->collection( $AdaptorType, {} );
foreach my $AdaptorType ('MetaParameters', 'PipelineWideParameters') {
my $class = 'Bio::EnsEMBL::Hive::'.$AdaptorType;
$class->collection( {} );
}
foreach my $AdaptorType ('ResourceClass', 'ResourceDescription', 'Analysis', 'AnalysisStats', 'AnalysisCtrlRule', 'DataflowRule') {
......@@ -276,9 +281,10 @@ sub init_collections { # should not really belong to DBAdaptor, temporarily squ
sub load_collections {
my $self = shift @_;
foreach my $AdaptorType ('Meta', 'PipelineWideParameters') {
foreach my $AdaptorType ('MetaParameters', 'PipelineWideParameters') {
my $adaptor = $self->get_adaptor( $AdaptorType );
Bio::EnsEMBL::Hive->collection( $AdaptorType, $adaptor->get_param_hash() );
my $class = 'Bio::EnsEMBL::Hive::'.$AdaptorType;
$class->collection( $adaptor->fetch_param_hash() );
}
foreach my $AdaptorType ('ResourceClass', 'ResourceDescription', 'Analysis', 'AnalysisStats', 'AnalysisCtrlRule', 'DataflowRule') {
......@@ -292,16 +298,13 @@ sub load_collections {
sub save_collections {
my $self = shift @_;
my $meta_adaptor = $self->get_adaptor( 'Meta' );
while(my ($meta_key, $meta_value) = each %{ Bio::EnsEMBL::Hive->collection( 'Meta' ) } ) {
$meta_adaptor->remove_all_by_meta_key($meta_key); # make sure the previous values are gone
$meta_adaptor->store_pair( $meta_key, $meta_value );
}
my $pwp_adaptor = $self->get_adaptor( 'PipelineWideParameters' );
while(my ($param_name, $param_value) = each %{ Bio::EnsEMBL::Hive->collection( 'PipelineWideParameters' ) } ) {
$pwp_adaptor->remove_all_by_param_name($param_name); # make sure the previous values are gone
$pwp_adaptor->store_pair( $param_name, $param_value );
foreach my $AdaptorType ('MetaParameters', 'PipelineWideParameters') {
my $adaptor = $self->get_adaptor( $AdaptorType );
my $class = 'Bio::EnsEMBL::Hive::'.$AdaptorType;
while( my ($hash_key,$hash_value) = each %{ $class->collection() } ) {
$adaptor->replace_pair( $hash_key, $hash_value );
# warn "Stored/updated '$hash_key' => '$hash_value'\n";
}
}
foreach my $AdaptorType ('ResourceClass', 'ResourceDescription', 'Analysis', 'AnalysisStats', 'AnalysisCtrlRule', 'DataflowRule') {
......
......@@ -35,6 +35,7 @@
package Bio::EnsEMBL::Hive::DBSQL::MetaAdaptor;
use strict;
use Bio::EnsEMBL::Hive::MetaParameters;
use base ('Bio::EnsEMBL::Hive::DBSQL::NakedTableAdaptor');
......@@ -44,25 +45,33 @@ sub default_table_name {
}
sub store_pair {
sub replace_pair {
my ($self, $meta_key, $meta_value) = @_;
$self->remove_all_by_meta_key($meta_key); # make sure the previous values are gone
return $self->store( { 'meta_key' => $meta_key, 'meta_value' => $meta_value } );
}
sub get_param_hash {
sub fetch_param_hash {
my $self = shift @_;
return $self->fetch_HASHED_FROM_meta_key_TO_meta_value();
}
sub fetch_value_by_key {
sub get_value_by_key {
my ($self, $meta_key) = @_;
my $pair = $self->fetch_by_meta_key( $meta_key );
return $pair && $pair->{'meta_value'};
if( my $collection = Bio::EnsEMBL::Hive::MetaParameters->collection() ) {
return $collection->{ $meta_key };
} else {
my $pair = $self->fetch_by_meta_key( $meta_key );
return $pair && $pair->{'meta_value'};
}
}
1;
......
......@@ -45,20 +45,21 @@ sub default_table_name {
}
sub store_pair {
sub replace_pair {
my ($self, $param_name, $param_value) = @_;
$self->remove_all_by_param_name($param_name); # make sure the previous values are gone
return $self->store( { 'param_name' => $param_name, 'param_value' => stringify( $param_value ) } );
}
=head2 get_param_hash
=head2 fetch_param_hash
Description: returns the content of the 'meta' table as a hash
=cut
sub get_param_hash {
sub fetch_param_hash {
my $self = shift @_;
my $original_value = $self->fetch_HASHED_FROM_param_name_TO_param_value();
......
=pod
=head1 NAME
Bio::EnsEMBL::Hive::MetaParameters
=head1 DESCRIPTION
A class-container for cached meta parameters
=head1 LICENSE
Copyright [1999-2014] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
=head1 CONTACT
Please subscribe to the Hive mailing list: http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users to discuss Hive-related questions or to be notified of our updates
=cut
package Bio::EnsEMBL::Hive::MetaParameters;
use strict;
use base ( 'Bio::EnsEMBL::Hive::Cacheable' );
1;
......@@ -16,7 +16,7 @@ By inheriting from this module you make your module able to deal with parameters
## typical usage:
# $job->param_init(
# $runObj->param_defaults(), # module-wide built-in defaults have the lowest precedence (will always be the same for this module)
# $self->db->get_PipelineWideParametersAdaptor->get_param_hash(), # then come the pipeline-wide parameters from the 'meta' table (define things common to all modules in this pipeline)
# $self->db->get_PipelineWideParametersAdaptor->fetch_param_hash(), # then come the pipeline-wide parameters from the 'meta' table (define things common to all modules in this pipeline)
# $self->analysis->parameters(), # analysis-wide 'parameters' are even more specific (can be defined differently for several occurence of the same module)
# $job->input_id(), # job-specific 'input_id' parameters have the highest precedence
# );
......
......@@ -444,12 +444,12 @@ sub add_objects_from_config {
my $self = shift @_;
warn "Adding hive_meta table entries ...\n";
my $hm_coll = Bio::EnsEMBL::Hive->collection('Meta');
my $hm_coll = Bio::EnsEMBL::Hive::MetaParameters->collection();
%$hm_coll = (%$hm_coll, %{$self->hive_meta_table()} );
warn "Done.\n\n";
warn "Adding pipeline-wide parameters ...\n";
my $mc_coll = Bio::EnsEMBL::Hive->collection('PipelineWideParameters');
my $mc_coll = Bio::EnsEMBL::Hive::PipelineWideParameters->collection();
%$mc_coll = (%$mc_coll, %{$self->pipeline_wide_parameters()} );
warn "Done.\n\n";
......
=pod
=head1 NAME
Bio::EnsEMBL::Hive::PipelineWideParameters
=head1 DESCRIPTION
A class-container for cached pipeline-wide parameters
=head1 LICENSE
Copyright [1999-2014] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
=head1 CONTACT
Please subscribe to the Hive mailing list: http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users to discuss Hive-related questions or to be notified of our updates
=cut
package Bio::EnsEMBL::Hive::PipelineWideParameters;
use strict;
use base ( 'Bio::EnsEMBL::Hive::Cacheable' );
1;
......@@ -666,7 +666,7 @@ sub run_one_batch {
my @params_precedence = (
$runnable_object->param_defaults(),
$self->adaptor->db->get_PipelineWideParametersAdaptor->get_param_hash(),
$self->adaptor->db->get_PipelineWideParametersAdaptor->fetch_param_hash(),
$self->analysis->parameters(),
);
......
......@@ -158,7 +158,7 @@ sub main {
my $queen = $self->{'dba'}->get_Queen;
my $pipeline_name = $self->{'dba'}->get_MetaAdaptor->fetch_value_by_key( 'hive_pipeline_name' );
my $pipeline_name = $self->{'dba'}->get_MetaAdaptor->get_value_by_key( 'hive_pipeline_name' );
if($pipeline_name) {
warn "Pipeline name: $pipeline_name\n";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment