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

Registry support is now cenralised in DBAdaptor, so scripts just pass reg_*...

Registry support is now cenralised in DBAdaptor, so scripts just pass reg_* options into the constructor. Passing -reg_type allows to connect to originally non-Hive Registry entries.
parent c522f7d3
......@@ -37,6 +37,7 @@ package Bio::EnsEMBL::Hive::DBSQL::DBAdaptor;
use strict;
use Bio::EnsEMBL::Registry;
use Bio::EnsEMBL::Utils::Argument ('rearrange');
use Bio::EnsEMBL::Hive::URLFactory;
......@@ -49,13 +50,31 @@ use base ('Bio::EnsEMBL::DBSQL::DBAdaptor');
sub new {
my ($class, @args) = @_;
my ($url, $no_sql_schema_version_check) = rearrange(['URL', 'NO_SQL_SCHEMA_VERSION_CHECK'], @args);
my ($url, $reg_conf, $reg_type, $reg_alias, $no_sql_schema_version_check)
= rearrange(['URL', 'REG_CONF', 'REG_TYPE', 'REG_ALIAS', 'NO_SQL_SCHEMA_VERSION_CHECK'], @args);
$url .= ';nosqlvc=1' if($url && $no_sql_schema_version_check);
my $self = $url
? (Bio::EnsEMBL::Hive::URLFactory->fetch($url) || die "Unable to connect to DBA using url='$url'\n")
: ($class->SUPER::new(@args) || die "Unable to connect to DBA using parameters (".join(', ', @args).")\n");
my $self;
if($url) {
$self = Bio::EnsEMBL::Hive::URLFactory->fetch($url)
or die "Unable to connect to DBA using url='$url'\n";
} elsif($reg_alias) {
Bio::EnsEMBL::Registry->load_all($reg_conf) if($reg_conf);
$reg_type ||= 'hive';
$self = Bio::EnsEMBL::Registry->get_DBAdaptor($reg_alias, $reg_type)
or die "Unable to connect to DBA using reg_conf='$reg_conf', reg_type='$reg_type', reg_alias='$reg_alias'\n";
if($reg_type ne 'hive') { # ensure we are getting a Hive adaptor even from a non-Hive Registry entry:
$self = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new( -dbconn => $self->dbc(), -no_sql_schema_version_check => $no_sql_schema_version_check );
}
} else {
$self = $class->SUPER::new(@args)
or die "Unable to connect to DBA using parameters (".join(', ', @args).")\n"
}
unless($no_sql_schema_version_check) {
......
......@@ -56,8 +56,11 @@ sub main {
my $reset_all_jobs_for_analysis = 0;
my $reset_failed_jobs_for_analysis = 0;
$self->{'url'} = undef;
$self->{'reg_conf'} = undef;
$self->{'reg_type'} = undef;
$self->{'reg_alias'} = undef;
$self->{'nosqlvc'} = undef;
$self->{'sleep_minutes'} = 1;
$self->{'retry_throwing_jobs'} = undef;
......@@ -68,10 +71,11 @@ sub main {
GetOptions(
# connection parameters
'url=s' => \$self->{'url'},
'reg_conf|regfile=s' => \$self->{'reg_conf'},
'reg_type=s' => \$self->{'reg_type'},
'reg_alias|regname=s'=> \$self->{'reg_alias'},
'url=s' => \$self->{'url'},
'nosqlvc' => \$self->{'nosqlvc'},
'nosqlvc=i' => \$self->{'nosqlvc'}, # can't use the binary "!" as it is a propagated option
# loop control
'run' => \$run,
......@@ -132,11 +136,14 @@ sub main {
}
}
if($self->{'reg_conf'} and $self->{'reg_alias'}) {
Bio::EnsEMBL::Registry->load_all($self->{'reg_conf'});
$self->{'dba'} = Bio::EnsEMBL::Registry->get_DBAdaptor($self->{'reg_alias'}, 'hive');
} elsif($self->{'url'}) {
$self->{'dba'} = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(-url => $self->{'url'}, -no_sql_schema_version_check => $self->{'nosqlvc'} );
if($self->{'url'} or $self->{'reg_alias'}) {
$self->{'dba'} = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(
-url => $self->{'url'},
-reg_conf => $self->{'reg_conf'},
-reg_type => $self->{'reg_type'},
-reg_alias => $self->{'reg_alias'},
-no_sql_schema_version_check => $self->{'nosqlvc'},
);
} else {
print "\nERROR : Connection parameters (url or reg_conf+reg_alias) need to be specified\n\n";
script_usage(1);
......@@ -293,17 +300,7 @@ sub generate_worker_cmd {
exit(1);
}
if ($self->{'reg_conf'}) { # if reg_conf is defined, we have to pass it anyway, regardless of whether it is used to connect to the Hive database or not:
$worker_cmd .= ' -reg_conf '. $self->{'reg_conf'};
}
if ($self->{'reg_alias'}) { # then we pass the connection parameters:
$worker_cmd .= ' -reg_alias '. $self->{'reg_alias'};
} else {
$worker_cmd .= " -url '". $self->{'safe_url'} ."'";
}
foreach my $worker_option ('nosqlvc', 'job_limit', 'life_span', 'retry_throwing_jobs', 'can_respecialize', 'hive_log_dir', 'debug') {
foreach my $worker_option ('url', 'reg_conf', 'reg_type', 'reg_alias', 'nosqlvc', 'job_limit', 'life_span', 'retry_throwing_jobs', 'can_respecialize', 'hive_log_dir', 'debug') {
if(defined(my $value = $self->{$worker_option})) {
$worker_cmd .= " -${worker_option} $value";
}
......@@ -436,6 +433,7 @@ __DATA__
=head2 Connection parameters
-reg_conf <path> : path to a Registry configuration file
-reg_type <string> : type of the registry entry ('hive', 'core', 'compara', etc - defaults to 'hive')
-reg_alias <string> : species/alias name for the Hive DBAdaptor
-url <url string> : url defining where hive database is located
......
......@@ -36,16 +36,17 @@ sub _options {
my ($self) = @_;
GetOptions(
# connection parameters
'reg_conf|regfile=s' => \$self->{'reg_conf'},
'reg_alias|regname=s' => \$self->{'reg_alias'},
'url=s' => \$self->{'url'},
'reg_conf|reg_file=s' => \$self->{'reg_conf'},
'reg_type=s' => \$self->{'reg_type'},
'url=s' => \$self->{url},
'reg_alias|reg_name=s' => \$self->{'reg_alias'},
'nosqlvc=i' => \$self->{'nosqlvc'}, # using "=i" instead of "!" for consistency with scripts where it is a propagated option
'f|format=s' => \$self->{format},
'o|output=s' => \$self->{output},
'f|format=s' => \$self->{'format'},
'o|output=s' => \$self->{'output'},
'h|help' => \$self->{help},
'm|man' => \$self->{man},
'h|help' => \$self->{'help'},
'm|man' => \$self->{'man'},
);
}
......@@ -53,25 +54,21 @@ sub _process_options {
my ($self) = @_;
#Check for help
if($self->{help}) {
if($self->{'help'}) {
pod2usage({-exitvalue => 0, -verbose => 1});
}
if($self->{man}) {
if($self->{'man'}) {
pod2usage({-exitvalue => 0, -verbose => 2});
}
#Check for DB
if($self->{'reg_conf'} and $self->{'reg_alias'}) {
$self->{'reg_type'} ||= 'hive';
Bio::EnsEMBL::Registry->load_all($self->{'reg_conf'});
$self->{dba} = Bio::EnsEMBL::Registry->get_DBAdaptor($self->{'reg_alias'}, $self->{'reg_type'});
if($self->{'reg_type'} ne 'hive') { # have to ensure we are getting a Hive DBAdaptor:
my $dbc = $self->{dba}->dbc();
$self->{dba} = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(-dbconn => $dbc);
}
} elsif($self->{url}) {
$self->{dba} = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(-url => $self->{url});
if($self->{'url'} or $self->{'reg_alias'}) {
$self->{'dba'} = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(
-url => $self->{'url'},
-reg_conf => $self->{'reg_conf'},
-reg_type => $self->{'reg_type'},
-reg_alias => $self->{'reg_alias'},
-no_sql_schema_version_check => $self->{'nosqlvc'},
);
} else {
pod2usage({
-message => 'ERROR: Connection parameters (url or reg_conf+reg_alias) need to be specified',
......@@ -80,7 +77,7 @@ sub _process_options {
});
}
if(! $self->{output}) {
if(! $self->{'output'}) {
pod2usage({
-message => 'ERROR: No -output flag given',
-exitvalue => 1,
......@@ -88,9 +85,9 @@ sub _process_options {
});
}
if(!$self->{format}) {
if($self->{output}=~/\.(\w+)$/) {
$self->{format} = $1;
if(!$self->{'format'}) {
if($self->{'output'}=~/\.(\w+)$/) {
$self->{'format'} = $1;
} else {
die "Format was not set and could not guess from ".$self->output().". Please use either way to select it.\n";
}
......@@ -100,16 +97,16 @@ sub _process_options {
sub _write_graph {
my ($self) = @_;
my $graph = Bio::EnsEMBL::Hive::Utils::Graph->new( $self->{dba} );
my $graph = Bio::EnsEMBL::Hive::Utils::Graph->new( $self->{'dba'} );
my $graphviz = $graph->build();
my $call = q{as_}.$self->{format};
my $call = q{as_}.$self->{'format'};
eval {$graphviz->$call($self->{output});};
eval {$graphviz->$call($self->{'output'});};
if($@) {
warn $@;
pod2usage({
-message => 'Error detected. Check '.$self->{format}.' is a valid format. Use a format name as supported by graphviz',
-message => 'Error detected. Check '.$self->{'format'}.' is a valid format. Use a format name as supported by graphviz',
-exitvalue => 1,
-verbose => 1
});
......
......@@ -20,13 +20,15 @@ use Bio::EnsEMBL::Hive::Utils ('script_usage');
sub main {
my ($reg_conf, $reg_alias, $url, $before_datetime, $days_ago);
my ($url, $reg_conf, $reg_type, $reg_alias, $nosqlvc, $before_datetime, $days_ago);
GetOptions(
# connect to the database:
'reg_conf|regfile=s' => \$reg_conf,
'reg_alias|regname=s' => \$reg_alias,
'url=s' => \$url,
'url=s' => \$url,
'reg_conf|regfile=s' => \$reg_conf,
'reg_type=s' => \$reg_type,
'reg_alias|regname=s' => \$reg_alias,
'nosqlvc=i' => \$nosqlvc, # using "=i" instead of "!" for consistency with scripts where it is a propagated option
# specify the threshold datetime:
'before_datetime=s' => \$before_datetime,
......@@ -34,11 +36,14 @@ sub main {
);
my $hive_dba;
if($reg_conf and $reg_alias) {
Bio::EnsEMBL::Registry->load_all($reg_conf);
$hive_dba = Bio::EnsEMBL::Registry->get_DBAdaptor($reg_alias, 'hive');
} elsif($url) {
$hive_dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(-url => $url);
if($url or $reg_alias) {
$hive_dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(
-url => $url,
-reg_conf => $reg_conf,
-reg_type => $reg_type,
-reg_alias => $reg_alias,
-no_sql_schema_version_check => $nosqlvc,
);
} else {
warn "\nERROR: Connection parameters (url or reg_conf+reg_alias) need to be specified\n";
script_usage(1);
......
......@@ -24,26 +24,40 @@ exit(0);
sub main {
my ($url, $bacct_source_line, $lsf_user, $help, $start_date, $end_date);
my ($url, $reg_conf, $reg_type, $reg_alias, $nosqlvc, $bacct_source_line, $lsf_user, $help, $start_date, $end_date);
GetOptions(
'url=s' => \$url,
'dump|file=s' => \$bacct_source_line,
'lu|lsf_user=s' => \$lsf_user,
'sd|start_date=s' => \$start_date,
'ed|end_date=s' => \$end_date,
'h|help' => \$help,
# connect to the database:
'url=s' => \$url,
'reg_conf|regfile=s' => \$reg_conf,
'reg_type=s' => \$reg_type,
'reg_alias|regname=s' => \$reg_alias,
'nosqlvc=i' => \$nosqlvc, # using "=i" instead of "!" for consistency with scripts where it is a propagated option
'dump|file=s' => \$bacct_source_line,
'lu|lsf_user=s' => \$lsf_user,
'sd|start_date=s' => \$start_date,
'ed|end_date=s' => \$end_date,
'h|help' => \$help,
);
if ($help) { script_usage(0); }
unless( $url ) {
print "\nERROR : --url is an obligatory parameter for connecting to your database\n\n";
my $hive_dba;
if($url or $reg_alias) {
$hive_dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(
-url => $url,
-reg_conf => $reg_conf,
-reg_type => $reg_type,
-reg_alias => $reg_alias,
-no_sql_schema_version_check => $nosqlvc,
);
} else {
warn "\nERROR: Connection parameters (url or reg_conf+reg_alias) need to be specified\n";
script_usage(1);
}
my $dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(-url => $url );
my $dbc = $dba->dbc();
my $dbc = $hive_dba->dbc();
warn "Creating the 'lsf_report' table if it doesn't exist...\n";
$dbc->do (qq{
......
......@@ -21,7 +21,7 @@ use Bio::EnsEMBL::Hive::Valley;
Bio::EnsEMBL::Registry->no_version_check(1);
my ($reg_conf, $reg_alias, $url, $nosqlvc); # Connection parameters
my ($url, $reg_conf, $reg_type, $reg_alias, $nosqlvc); # Connection parameters
my ($resource_class_id, $resource_class_name, $analysis_id, $logic_name, $job_id, $force); # Task specification parameters
my ($job_limit, $life_span, $no_cleanup, $no_write, $hive_log_dir, $worker_log_dir, $retry_throwing_jobs, $can_respecialize); # Worker control parameters
my ($help, $debug);
......@@ -29,10 +29,11 @@ my ($help, $debug);
GetOptions(
# Connection parameters:
'url=s' => \$url,
'reg_conf|regfile=s' => \$reg_conf,
'reg_type=s' => \$reg_type,
'reg_alias|regname=s' => \$reg_alias,
'url=s' => \$url,
'nosqlvc' => \$nosqlvc,
'nosqlvc=i' => \$nosqlvc, # can't use the binary "!" as it is a propagated option
# Task specification parameters:
'rc_id=i' => \$resource_class_id,
......@@ -63,10 +64,9 @@ if($reg_conf) { # if reg_conf is defined, we load it regardless of whether i
Bio::EnsEMBL::Registry->load_all($reg_conf);
}
my $DBA;
if($reg_alias) {
$DBA = Bio::EnsEMBL::Registry->get_DBAdaptor($reg_alias, 'hive');
} elsif($url) {
my $hive_dba;
if($url or $reg_alias) {
# Perform environment variable substitution separately with and without curly braces.
# Fixme: Perl 5.10 has a cute new "branch reset" (?|pattern)
# that would allow to merge the two substitutions below into a nice one-liner.
......@@ -74,21 +74,30 @@ if($reg_alias) {
#
# Make sure expressions stay as they were if we were unable to substitute them.
#
$url =~ s/\$(\{(\w+)\})/defined($ENV{$2})?"$ENV{$2}":"\$$1"/eg;
$url =~ s/\$((\w+))/defined($ENV{$2})?"$ENV{$2}":"\$$1"/eg;
if($url) {
$url =~ s/\$(\{(\w+)\})/defined($ENV{$2})?"$ENV{$2}":"\$$1"/eg;
$url =~ s/\$((\w+))/defined($ENV{$2})?"$ENV{$2}":"\$$1"/eg;
}
$hive_dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(
-url => $url,
-reg_conf => $reg_conf,
-reg_type => $reg_type,
-reg_alias => $reg_alias,
-no_sql_schema_version_check => $nosqlvc,
);
$DBA = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(-url => $url, -no_sql_schema_version_check => $nosqlvc);
} else {
print "\nERROR : Connection parameters (url or reg_conf+reg_alias) need to be specified\n\n";
script_usage(1);
}
unless($DBA and $DBA->isa("Bio::EnsEMBL::Hive::DBSQL::DBAdaptor")) {
unless($hive_dba and $hive_dba->isa("Bio::EnsEMBL::Hive::DBSQL::DBAdaptor")) {
print "ERROR : no database connection\n\n";
script_usage(1);
}
my $queen = $DBA->get_Queen();
my $queen = $hive_dba->get_Queen();
my ($meadow_type, $meadow_name, $process_id, $exec_host) = Bio::EnsEMBL::Hive::Valley->new()->whereami();
......
......@@ -13,7 +13,6 @@ BEGIN {
use Getopt::Long;
use Bio::EnsEMBL::Registry;
use Bio::EnsEMBL::Hive::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Hive::DBSQL::AnalysisJobAdaptor;
use Bio::EnsEMBL::Hive::Utils ('destringify', 'stringify', 'script_usage');
......@@ -39,13 +38,16 @@ sub show_seedable_analyses {
sub main {
my ($reg_conf, $reg_alias, $url, $analysis_id, $logic_name, $input_id);
my ($url, $reg_conf, $reg_type, $reg_alias, $nosqlvc, $analysis_id, $logic_name, $input_id);
GetOptions(
# connect to the database:
'reg_conf|regfile=s' => \$reg_conf,
'reg_alias|regname=s' => \$reg_alias,
'url=s' => \$url,
'url=s' => \$url,
'reg_conf|regfile=s' => \$reg_conf,
'reg_type=s' => \$reg_type,
'reg_alias|regname=s' => \$reg_alias,
'nosqlvc=i' => \$nosqlvc, # using "=i" instead of "!" for consistency with scripts where it is a propagated option
# identify the analysis:
'analysis_id=i' => \$analysis_id,
......@@ -56,11 +58,14 @@ sub main {
);
my $hive_dba;
if($reg_conf and $reg_alias) {
Bio::EnsEMBL::Registry->load_all($reg_conf);
$hive_dba = Bio::EnsEMBL::Registry->get_DBAdaptor($reg_alias, 'hive');
} elsif($url) {
$hive_dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(-url => $url);
if($url or $reg_alias) {
$hive_dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(
-url => $url,
-reg_conf => $reg_conf,
-reg_type => $reg_type,
-reg_alias => $reg_alias,
-no_sql_schema_version_check => $nosqlvc,
);
} else {
warn "\nERROR: Connection parameters (url or reg_conf+reg_alias) need to be specified\n";
script_usage(1);
......@@ -115,7 +120,7 @@ __DATA__
=head1 SYNOPSIS
seed_pipeline.pl {-url <url> | -reg_conf <reg_conf> -reg_alias <reg_alias>} [ {-analysis_id <analysis_id> | -logic_name <logic_name>} [ -input_id <input_id> ] ]
seed_pipeline.pl {-url <url> | -reg_conf <reg_conf> [-reg_type <reg_type>] -reg_alias <reg_alias>} [ {-analysis_id <analysis_id> | -logic_name <logic_name>} [ -input_id <input_id> ] ]
=head1 DESCRIPTION
......
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