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

Storable->new() now performs setting of all parameters without the use of...

Storable->new() now performs setting of all parameters without the use of rearrange (NB: change of call format!)
parent 54f235a4
......@@ -32,25 +32,10 @@
package Bio::EnsEMBL::Hive::Accumulator;
use strict;
use Bio::EnsEMBL::Utils::Argument ('rearrange');
use Bio::EnsEMBL::Hive::Utils ('stringify');
use base ( 'Bio::EnsEMBL::Hive::Storable' ); # inherit dbID(), adaptor() and new() methods
sub new {
my $class = shift @_;
my $self = $class->SUPER::new( @_ ); # deal with Storable stuff
my ($struct_name, $signature_template) =
rearrange([qw(struct_name signature_template) ], @_);
$self->struct_name($struct_name) if(defined($struct_name));
$self->signature_template($signature_template) if(defined($signature_template));
use Bio::EnsEMBL::Hive::Utils ('stringify');
return $self;
}
use base ( 'Bio::EnsEMBL::Hive::Storable' );
sub struct_name {
......
......@@ -37,37 +37,11 @@ package Bio::EnsEMBL::Hive::Analysis;
use strict;
use Bio::EnsEMBL::Utils::Argument ('rearrange');
use Bio::EnsEMBL::Hive::Utils ('stringify');
use base ( 'Bio::EnsEMBL::Hive::Storable', # inherit dbID(), adaptor() and new() methods
);
use base ( 'Bio::EnsEMBL::Hive::Storable' );
sub new {
my $class = shift @_;
my $self = $class->SUPER::new( @_ ); # deal with Storable stuff
my ($logic_name, $module, $parameters, $resource_class_id, $failed_job_tolerance, $max_retry_count, $can_be_empty, $priority, $meadow_type, $analysis_capacity) =
rearrange([qw(logic_name module parameters resource_class_id failed_job_tolerance max_retry_count can_be_empty priority meadow_type analysis_capacity) ], @_);
$self->logic_name($logic_name) if($logic_name);
$self->module($module) if($module);
$self->parameters($parameters) if($parameters);
$self->resource_class_id($resource_class_id) if($resource_class_id);
$self->failed_job_tolerance($failed_job_tolerance) if($failed_job_tolerance);
$self->max_retry_count($max_retry_count) if($max_retry_count);
$self->can_be_empty($can_be_empty) if($can_be_empty);
$self->priority($priority) if($priority);
$self->meadow_type($meadow_type) if($meadow_type);
$self->analysis_capacity($analysis_capacity) if( defined($analysis_capacity) );
return $self;
}
sub logic_name {
my $self = shift;
$self->{'_logic_name'} = shift if(@_);
......
......@@ -42,39 +42,13 @@
package Bio::EnsEMBL::Hive::AnalysisCtrlRule;
use strict;
use Bio::EnsEMBL::Utils::Argument ('rearrange');
use Bio::EnsEMBL::Utils::Exception ('throw');
use Bio::EnsEMBL::Hive::URLFactory;
use Bio::EnsEMBL::Hive::Extensions;
use base ( 'Bio::EnsEMBL::Hive::Storable' ); # inherit dbID(), adaptor() and new() methods
=head2 new
Title : new
Usage : ...AnalysisCtrlRule->new;
Function: Constructor for empty AnalysisCtrlRule object
Returns : Bio::EnsEMBL::Hive::AnalysisCtrlRule
Args : none
=cut
sub new {
my $class = shift @_;
my $self = $class->SUPER::new( @_ ); # deal with Storable stuff
my ( $condition_analysis_url, $ctrled_analysis_id ) =
rearrange( [ qw (CONDITION_ANALYSIS_URL CTRLED_ANALYSIS_ID) ], @_ );
# simple scalars:
$self->condition_analysis_url( $condition_analysis_url ) if(defined($condition_analysis_url));
$self->ctrled_analysis_id( $ctrled_analysis_id ) if(defined($ctrled_analysis_id));
return $self;
}
use base ( 'Bio::EnsEMBL::Hive::Storable' );
=head2 ctrled_analysis_id
......
......@@ -38,43 +38,15 @@ package Bio::EnsEMBL::Hive::AnalysisJob;
use strict;
use Bio::EnsEMBL::Utils::Argument ('rearrange');
use Bio::EnsEMBL::Hive::Utils ('stringify', 'destringify');
use Bio::EnsEMBL::Hive::DBSQL::AnalysisJobAdaptor;
use Bio::EnsEMBL::Hive::DBSQL::DataflowRuleAdaptor;
use base ( 'Bio::EnsEMBL::Hive::Storable', # inherit dbID(), adaptor() and new() methods
use base ( 'Bio::EnsEMBL::Hive::Storable', # inherit dbID(), adaptor() and new() methods
'Bio::EnsEMBL::Hive::Params', # inherit param management functionality
);
sub new {
my $class = shift @_;
my $self = $class->SUPER::new( @_ ); # deal with Storable stuff
my($prev_job_id, $analysis_id, $input_id, $param_id_stack, $accu_id_stack, $worker_id, $status, $retry_count, $completed, $runtime_msec, $query_count, $semaphore_count, $semaphored_job_id) =
rearrange([qw(prev_job_id analysis_id input_id param_id_stack accu_id_stack worker_id status retry_count completed runtime_msec query_count semaphore_count semaphored_job_id) ], @_);
$self->prev_job_id($prev_job_id) if(defined($prev_job_id));
$self->analysis_id($analysis_id) if(defined($analysis_id));
$self->input_id($input_id) if(defined($input_id));
$self->param_id_stack($param_id_stack) if(defined($param_id_stack));
$self->accu_id_stack($accu_id_stack) if(defined($accu_id_stack));
$self->worker_id($worker_id) if(defined($worker_id));
$self->status($status) if(defined($status));
$self->retry_count($retry_count) if(defined($retry_count));
$self->completed($completed) if(defined($completed));
$self->runtime_msec($runtime_msec) if(defined($runtime_msec));
$self->query_count($query_count) if(defined($query_count));
$self->semaphore_count($semaphore_count) if(defined($semaphore_count));
$self->semaphored_job_id($semaphored_job_id) if(defined($semaphored_job_id));
return $self;
}
sub prev_job_id {
my $self = shift;
$self->{'_prev_job_id'} = shift if(@_);
......@@ -352,12 +324,12 @@ sub dataflow_output_id {
my $fan_cache_this_branch = $self->fan_cache()->{$funnel_dataflow_rule_id} ||= [];
push @$fan_cache_this_branch, map { Bio::EnsEMBL::Hive::AnalysisJob->new(
-prev_job_id => $self->dbID,
-analysis_id => $target_analysis_or_table->dbID, # expecting an Analysis
-input_id => $_,
-param_id_stack => $param_id_stack,
-accu_id_stack => $accu_id_stack,
# -semaphored_job_id => to be set when the $funnel_job has been stored
'prev_job_id' => $self->dbID,
'analysis_id' => $target_analysis_or_table->dbID, # expecting an Analysis
'input_id' => $_,
'param_id_stack' => $param_id_stack,
'accu_id_stack' => $accu_id_stack,
# semaphored_job_id => to be set when the $funnel_job has been stored
) } @$output_ids_for_this_rule;
} else { # either a semaphored funnel or a non-semaphored dataflow:
......@@ -373,13 +345,13 @@ sub dataflow_output_id {
} else {
my $funnel_job = Bio::EnsEMBL::Hive::AnalysisJob->new(
-prev_job_id => $self->dbID,
-analysis_id => $target_analysis_or_table->dbID, # expecting an Analysis
-input_id => $output_ids_for_this_rule->[0],
-param_id_stack => $param_id_stack,
-accu_id_stack => $accu_id_stack,
-semaphore_count => scalar(@$fan_jobs), # "pre-increase" the semaphore count before creating the dependent jobs
-semaphored_job_id => $self->semaphored_job_id(), # propagate parent's semaphore if any
'prev_job_id' => $self->dbID,
'analysis_id' => $target_analysis_or_table->dbID, # expecting an Analysis
'input_id' => $output_ids_for_this_rule->[0],
'param_id_stack' => $param_id_stack,
'accu_id_stack' => $accu_id_stack,
'semaphore_count' => scalar(@$fan_jobs), # "pre-increase" the semaphore count before creating the dependent jobs
'semaphored_job_id' => $self->semaphored_job_id(), # propagate parent's semaphore if any
);
my ($funnel_job_id) = @{ $job_adaptor->store_jobs_and_adjust_counters( [ $funnel_job ], 0) };
......@@ -393,12 +365,12 @@ sub dataflow_output_id {
}
} else { # non-semaphored dataflow (but potentially propagating any existing semaphores)
my @non_semaphored_jobs = map { Bio::EnsEMBL::Hive::AnalysisJob->new(
-prev_job_id => $self->dbID,
-analysis_id => $target_analysis_or_table->dbID, # expecting an Analysis
-input_id => $_,
-param_id_stack => $param_id_stack,
-accu_id_stack => $accu_id_stack,
-semaphored_job_id => $self->semaphored_job_id(), # propagate parent's semaphore if any
'prev_job_id' => $self->dbID,
'analysis_id' => $target_analysis_or_table->dbID, # expecting an Analysis
'input_id' => $_,
'param_id_stack' => $param_id_stack,
'accu_id_stack' => $accu_id_stack,
'semaphored_job_id' => $self->semaphored_job_id(), # propagate parent's semaphore if any
) } @$output_ids_for_this_rule;
push @output_job_ids, @{ $job_adaptor->store_jobs_and_adjust_counters( \@non_semaphored_jobs, 0) };
......
......@@ -37,11 +37,10 @@ package Bio::EnsEMBL::Hive::AnalysisStats;
use strict;
use Bio::EnsEMBL::Utils::Argument ('rearrange');
use Bio::EnsEMBL::Utils::Exception ('throw');
use Bio::EnsEMBL::Hive::Analysis;
use base ( 'Bio::EnsEMBL::Hive::Storable' ); # inherit dbID(), adaptor() and new() methods
use base ( 'Bio::EnsEMBL::Hive::Storable' );
## Minimum amount of time in msec that a worker should run before reporting
......@@ -50,45 +49,6 @@ sub min_batch_time {
return 2*60*1000;
}
sub new {
my $class = shift;
my $self = $class->SUPER::new( @_ ); # deal with Storable stuff
my ( $analysis_id, $batch_size, $hive_capacity, $status,
$total_job_count, $semaphored_job_count, $ready_job_count, $done_job_count, $failed_job_count, $num_running_workers, $num_required_workers,
$behaviour, $input_capacity, $output_capacity, $avg_msec_per_job, $avg_input_msec_per_job, $avg_run_msec_per_job, $avg_output_msec_per_job,
$seconds_since_last_update, $sync_lock) =
rearrange([qw(analysis_id batch_size hive_capacity status
total_job_count semaphored_job_count ready_job_count done_job_count failed_job_count num_running_workers num_required_workers
behaviour input_capacity output_capacity avg_msec_per_job avg_input_msec_per_job avg_run_msec_per_job avg_output_msec_per_job
seconds_since_last_update sync_lock ) ], @_);
$self->analysis_id($analysis_id) if(defined($analysis_id));
$self->batch_size($batch_size) if(defined($batch_size));
$self->hive_capacity($hive_capacity) if(defined($hive_capacity));
$self->status($status) if(defined($status));
$self->total_job_count($total_job_count) if(defined($total_job_count));
$self->semaphored_job_count($semaphored_job_count) if(defined($semaphored_job_count));
$self->ready_job_count($ready_job_count) if(defined($ready_job_count));
$self->done_job_count($done_job_count) if(defined($done_job_count));
$self->failed_job_count($failed_job_count) if(defined($failed_job_count));
$self->num_running_workers($num_running_workers) if(defined($num_running_workers));
$self->num_required_workers($num_required_workers) if(defined($num_required_workers));
$self->behaviour($behaviour) if(defined($behaviour));
$self->input_capacity($input_capacity) if(defined($input_capacity));
$self->output_capacity($output_capacity) if(defined($output_capacity));
$self->avg_msec_per_job($avg_msec_per_job) if(defined($avg_msec_per_job));
$self->avg_input_msec_per_job($avg_input_msec_per_job) if(defined($avg_input_msec_per_job));
$self->avg_run_msec_per_job($avg_run_msec_per_job) if(defined($avg_run_msec_per_job));
$self->avg_output_msec_per_job($avg_output_msec_per_job) if(defined($avg_output_msec_per_job));
$self->seconds_since_last_update($seconds_since_last_update)if(defined($seconds_since_last_update)); # NB: this is an input_column_mapped field
$self->sync_lock($sync_lock) if(defined($sync_lock));
return $self;
}
## pre-settable storable object's getters/setters:
sub analysis_id { # an alias
......
......@@ -69,7 +69,7 @@ sub objectify { # turn the hashref into an object (if only we could inline in Pe
my $autoinc_id = $self->autoinc_id();
return $self->object_class()->new( -adaptor => $self, map { ('-'.uc( ($_ eq $autoinc_id) ? 'dbID' : $_ ) => $hashref->{$_}) } keys %$hashref );
return $self->object_class()->new( 'adaptor' => $self, map { ( ($_ eq $autoinc_id) ? 'dbID' : $_ ) => $hashref->{$_} } keys %$hashref );
}
......@@ -90,7 +90,7 @@ sub create_new {
? pop @_ # extra 'odd' parameter that would disrupt the hash integrity anyway
: 0; # do not check by default
my $object = $self->object_class()->new( -adaptor => $self, @_ );
my $object = $self->object_class()->new( 'adaptor' => $self, @_ );
return $self->store( $object, $check_presence_in_db_first );
}
......
......@@ -53,46 +53,12 @@ package Bio::EnsEMBL::Hive::DataflowRule;
use strict;
use Bio::EnsEMBL::Utils::Argument ('rearrange');
use Bio::EnsEMBL::Utils::Exception ('throw');
use Bio::EnsEMBL::Hive::Utils ('stringify');
use Bio::EnsEMBL::Hive::DBSQL::AnalysisAdaptor;
use base ( 'Bio::EnsEMBL::Hive::Storable', # inherit dbID(), adaptor() and new() methods
);
=head2 new
Usage : Bio::EnsEMBL::Hive::DataflowRule->new(-from_analysis => $fromAnalysis, -to_analysis => $toAnalysis, -branch_code => $branch_code);
Function: Constructor for DataflowRule object
Returns : Bio::EnsEMBL::Hive::DataflowRule
Args : a rearrange-compatible hash
=cut
sub new {
my $class = shift @_;
my $self = $class->SUPER::new( @_ ); # deal with Storable stuff
my ($fromAnalysis, $toAnalysis, $from_analysis_id, $branch_code, $funnel_dataflow_rule_id, $to_analysis_url, $input_id_template ) =
rearrange( [ qw (FROM_ANALYSIS TO_ANALYSIS FROM_ANALYSIS_ID BRANCH_CODE FUNNEL_DATAFLOW_RULE_ID TO_ANALYSIS_URL INPUT_ID_TEMPLATE) ], @_ );
# from objects:
$self->from_analysis( $fromAnalysis ) if(defined($fromAnalysis));
$self->to_analysis( $toAnalysis ) if(defined($toAnalysis));
# simple scalars:
$self->from_analysis_id($from_analysis_id) if(defined($from_analysis_id));
$self->to_analysis_url($to_analysis_url) if(defined($to_analysis_url));
$self->branch_code($branch_code) if(defined($branch_code));
$self->funnel_dataflow_rule_id($funnel_dataflow_rule_id) if(defined($funnel_dataflow_rule_id));
$self->input_id_template($input_id_template) if(defined($input_id_template));
return $self;
}
use base ( 'Bio::EnsEMBL::Hive::Storable' );
=head2 branch_code
......
......@@ -32,24 +32,8 @@
package Bio::EnsEMBL::Hive::NakedTable;
use strict;
use Bio::EnsEMBL::Utils::Argument ('rearrange');
use base ( 'Bio::EnsEMBL::Hive::Storable' ); # inherit dbID(), adaptor() and new() methods
sub new {
my $class = shift @_;
my $self = $class->SUPER::new( @_ ); # deal with Storable stuff
my ($table_name, $insertion_method) =
rearrange([qw(table_name insertion_method) ], @_);
$self->table_name($table_name) if(defined($table_name));
$self->insertion_method($insertion_method) if(defined($insertion_method));
return $self;
}
use base ( 'Bio::EnsEMBL::Hive::Storable' );
sub table_name {
......
......@@ -495,8 +495,8 @@ sub run {
}
my ($rc, $rc_newly_created) = $resource_class_adaptor->create_new(
defined($rc_id) ? (-DBID => $rc_id) : (),
-NAME => $rc_name,
defined($rc_id) ? ('dbID' => $rc_id) : (),
'name' => $rc_name,
1 # check whether this ResourceClass was already present in the database
);
$rc_id = $rc->dbID();
......@@ -511,16 +511,16 @@ sub run {
$resource_param_list = [ $resource_param_list ] unless(ref($resource_param_list)); # expecting either a scalar or a 2-element array
$resource_description_adaptor->create_new(
-resource_class_id => $rc_id,
-meadow_type => $meadow_type,
-submission_cmd_args => $resource_param_list->[0],
-worker_cmd_args => $resource_param_list->[1],
resource_class_id => $rc_id,
meadow_type => $meadow_type,
submission_cmd_args => $resource_param_list->[0],
worker_cmd_args => $resource_param_list->[1],
);
}
}
unless(my $default_rc = $resource_class_adaptor->fetch_by_name('default')) {
warn "\tNB:'default' resource class is not in the database (did you forget to inherit from SUPER::resource_classes ?) - creating it for you\n";
$resource_class_adaptor->create_new(-NAME => 'default');
$resource_class_adaptor->create_new('name' => 'default');
}
warn "Done.\n\n";
}
......@@ -579,36 +579,36 @@ sub run {
die "'-parameters' has to be a hash" unless(ref($parameters_hash) eq 'HASH');
$analysis = Bio::EnsEMBL::Hive::Analysis->new(
-logic_name => $logic_name,
-module => $module,
-parameters => $parameters_hash,
-resource_class_id => $rc_id,
-failed_job_tolerance => $failed_job_tolerance,
-max_retry_count => $max_retry_count,
-can_be_empty => $can_be_empty,
-priority => $priority,
-meadow_type => $meadow_type,
-analysis_capacity => $analysis_capacity,
'logic_name' => $logic_name,
'module' => $module,
'parameters' => $parameters_hash,
'resource_class_id' => $rc_id,
'failed_job_tolerance' => $failed_job_tolerance,
'max_retry_count' => $max_retry_count,
'can_be_empty' => $can_be_empty,
'priority' => $priority,
'meadow_type' => $meadow_type,
'analysis_capacity' => $analysis_capacity,
);
$analysis->get_compiled_module_name(); # check if it compiles and is named correctly
$analysis_adaptor->store($analysis);
my $stats = Bio::EnsEMBL::Hive::AnalysisStats->new(
-analysis_id => $analysis->dbID,
-batch_size => $batch_size,
-hive_capacity => $hive_capacity,
-status => $blocked ? 'BLOCKED' : 'EMPTY', # be careful, as this "soft" way of blocking may be accidentally unblocked by deep sync
-total_job_count => 0,
-semaphored_job_count => 0,
-ready_job_count => 0,
-done_job_count => 0,
-failed_job_count => 0,
-num_running_workers => 0,
-num_required_workers => 0,
-behaviour => 'STATIC',
-input_capacity => 4,
-output_capacity => 4,
-sync_lock => 0,
'analysis_id' => $analysis->dbID,
'batch_size' => $batch_size,
'hive_capacity' => $hive_capacity,
'status' => $blocked ? 'BLOCKED' : 'EMPTY', # be careful, as this "soft" way of blocking may be accidentally unblocked by deep sync
'total_job_count' => 0,
'semaphored_job_count' => 0,
'ready_job_count' => 0,
'done_job_count' => 0,
'failed_job_count' => 0,
'num_running_workers' => 0,
'num_required_workers' => 0,
'behaviour' => 'STATIC',
'input_capacity' => 4,
'output_capacity' => 4,
'sync_lock' => 0,
);
$analysis_stats_adaptor->store($stats);
}
......@@ -616,9 +616,9 @@ sub run {
# now create the corresponding jobs (if there are any):
if($input_ids) {
my @jobs = map { Bio::EnsEMBL::Hive::AnalysisJob->new(
-prev_job_id => undef, # these jobs are created by the initialization script, not by another job
-analysis_id => $analysis->dbID,
-input_id => $_, # input_ids are now centrally stringified in the AnalysisJob itself
'prev_job_id' => undef, # these jobs are created by the initialization script, not by another job
'analysis_id' => $analysis->dbID,
'input_id' => $_, # input_ids are now centrally stringified in the AnalysisJob itself
) } @$input_ids;
$job_adaptor->store_jobs_and_adjust_counters( \@jobs );
......@@ -648,8 +648,8 @@ sub run {
die "Could not fetch analysis '$condition_url' to create a control rule (in '".($analysis->logic_name)."')\n" unless defined $condition_analysis;
}
my $c_rule = Bio::EnsEMBL::Hive::AnalysisCtrlRule->new(
-condition_analysis_url => $condition_url,
-ctrled_analysis_id => $analysis->dbID,
'condition_analysis_url' => $condition_url,
'ctrled_analysis_id' => $analysis->dbID,
);
$ctrl_rule_adaptor->store( $c_rule, 1 );
......@@ -704,11 +704,11 @@ sub run {
foreach my $input_id_template (@$input_id_template_list) {
my $df_rule = Bio::EnsEMBL::Hive::DataflowRule->new(
-from_analysis => $analysis,
-to_analysis_url => $heir_url,
-branch_code => $branch_name_or_code,
-input_id_template => $input_id_template,
-funnel_dataflow_rule_id => $funnel_dataflow_rule_id,
'from_analysis' => $analysis,
'to_analysis_url' => $heir_url,
'branch_code' => $branch_name_or_code,
'input_id_template' => $input_id_template,
'funnel_dataflow_rule_id' => $funnel_dataflow_rule_id,
);
$dataflow_rule_adaptor->store( $df_rule, 1 );
......
......@@ -39,26 +39,9 @@ package Bio::EnsEMBL::Hive::ResourceClass;
use strict;
use Bio::EnsEMBL::Utils::Argument ('rearrange');
use base ( 'Bio::EnsEMBL::Hive::Storable', # inherit dbID(), adaptor() and new() methods
);
use base ( 'Bio::EnsEMBL::Hive::Storable' );
sub new {
my $class = shift @_;
my $self = $class->SUPER::new( @_ ); # deal with Storable stuff
my ($name) =
rearrange([qw(name) ], @_);
$self->name($name) if($name);
return $self;
}
sub name {
my $self = shift @_;
......
......@@ -40,26 +40,8 @@
package Bio::EnsEMBL::Hive::ResourceDescription;
use strict;
use Bio::EnsEMBL::Utils::Argument ('rearrange');
use base ( 'Bio::EnsEMBL::Hive::Storable' ); # inherit dbID(), adaptor() and new() methods
sub new {
my $class = shift @_;
my $self = $class->SUPER::new( @_ ); # deal with Storable stuff
my ($resource_class_id, $meadow_type, $submission_cmd_args, $worker_cmd_args) =
rearrange([qw(resource_class_id meadow_type submission_cmd_args worker_cmd_args) ], @_);
$self->resource_class_id($resource_class_id);
$self->meadow_type($meadow_type);
$self->submission_cmd_args($submission_cmd_args);
$self->worker_cmd_args($worker_cmd_args);
return $self;
}
use base ( 'Bio::EnsEMBL::Hive::Storable' );
sub resource_class_id {
......
......@@ -44,15 +44,13 @@ package Bio::EnsEMBL::Hive::Storable;
use strict;
use warnings;
use Bio::EnsEMBL::Utils::Argument qw(rearrange);
use Scalar::Util qw(weaken);
=head2 new
Arg [-ADAPTOR] : Bio::EnsEMBL::Hive::DBSQL::BaseAdaptor
Arg [-dbID] : database internal id
Caller : internal calls
Args : pairs of ($method_name, $value)
Caller : ObjectAdaptor, AnalysisJob, URLFactory.pm, HiveGeneric_conf, seed_pipeline.pl, standaloneJob.pl
Description : create a new Storable object
Returntype : Bio::EnsEMBL::Hive::Storable
Exceptions : Adaptor not a Bio::EnsEMBL::DBSQL::BaseAdaptor
......@@ -61,14 +59,15 @@ use Scalar::Util qw(weaken);
=cut
sub