ensembl-hive  2.5
TheApiary.pm
Go to the documentation of this file.
1 =pod
2 
3 =head1 NAME
4 
6 
7 =head1 SYNOPSIS
8 
9  my $hive_pipeline = Bio::EnsEMBL::Hive::TheApiary->find_by_url( 'mysql://ensro@compara3/lg4_long_mult' );
10 
11  my $final_result_table = Bio::EnsEMBL::Hive::TheApiary->find_by_url( 'mysql://ensro@compara3/lg4_long_mult?table_name=final_result' );
12 
13 =head1 DESCRIPTION
14 
15  Global cache for HivePipeline objects.
16 
17 =head1 LICENSE
18 
19  Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
20  Copyright [2016-2022] EMBL-European Bioinformatics Institute
21 
22  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
23  You may obtain a copy of the License at
24 
25  http://www.apache.org/licenses/LICENSE-2.0
26 
27  Unless required by applicable law or agreed to in writing, software distributed under the License
28  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29  See the License for the specific language governing permissions and limitations under the License.
30 
31 =head1 CONTACT
32 
33  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
34 
35 =cut
36 
37 
38 package Bio::EnsEMBL::Hive::TheApiary;
39 
40 use strict;
41 use warnings;
42 use Data::Dumper;
43 
47 
48 
49  # global instance to cache HivePipeline objects:
50 my $_global_Apiary_collection;
51 
52 
53 sub pipelines_collection {
54  my $class = shift @_;
55 
56  return $_global_Apiary_collection ||= Bio::EnsEMBL::Hive::Utils::Collection->new;
57 }
58 
59 
60 sub pipelines_except {
61  my ($class, $except_pipeline) = @_;
62 
63  my $except_unambig_key = $except_pipeline->unambig_key;
64 
65  return [ grep { $_->unambig_key ne $except_unambig_key } $class->pipelines_collection->list ];
66 }
67 
68 
69 sub find_by_url {
70  my $class = shift @_;
71  my $url = shift @_;
72  my $default_pipeline = shift @_;
73  my $no_die = shift @_;
74 
75  if(my $parsed_url = Bio::EnsEMBL::Hive::Utils::URL::parse( $url )) {
76 
77  my $unambig_key = Bio::EnsEMBL::Hive::Utils::URL::hash_to_unambig_url( $parsed_url );
78  my $query_params = $parsed_url->{'query_params'};
79  my $conn_params = $parsed_url->{'conn_params'};
80 
81  my $disconnect_when_inactive = $conn_params->{'disconnect_when_inactive'};
82  my $no_sql_schema_version_check = $conn_params->{'no_sql_schema_version_check'};
83 
84  my $hive_pipeline;
85 
86  if($unambig_key eq ':///') {
87 
88  $hive_pipeline = $default_pipeline;
89 
90  } elsif( not ($hive_pipeline = $class->pipelines_collection->find_one_by( 'unambig_key', $unambig_key ) ) ) {
91 
92  if($query_params and ($query_params->{'object_type'} eq 'NakedTable') ) { # do not check schema version when performing table dataflow:
93  $no_sql_schema_version_check = 1;
94  }
95 
96  $hive_pipeline = Bio::EnsEMBL::Hive::HivePipeline->new( # calling HivePipeline->new() triggers automatic addition to TheApiary
97  -url => $parsed_url->{'dbconn_part'},
98  -disconnect_when_inactive => $disconnect_when_inactive,
99  -no_sql_schema_version_check=> $no_sql_schema_version_check,
100  );
101  }
102 
103  return $query_params
104  ? $hive_pipeline->find_by_query( $query_params, $no_die )
105  : $hive_pipeline;
106 
107  } else {
108  die "Could not parse '$url' as URL";
109  }
110 }
111 
112 
113 sub fetch_remote_semaphores_controlling_this_one { # NB! This method has a (potentially unwanted) side-effect of adding @extra_pipelines to TheApiary. Use with caution.
114  my ($class, $this_semaphore_or_url, @extra_pipelines) = @_;
115 
116  my $this_semaphore_url = ref($this_semaphore_or_url)
117  ? $this_semaphore_or_url->relative_url( 0 ) # turn a semaphore into its global URL
118  : $this_semaphore_or_url; # just use the provided URL
119 
120  my @remote_controlling_semaphores = ();
121 
122  foreach my $remote_pipeline ($class->pipelines_collection->list, @extra_pipelines ) {
123 
124  push @remote_controlling_semaphores, @{ $remote_pipeline->hive_dba->get_SemaphoreAdaptor->fetch_all_by_dependent_semaphore_url( $this_semaphore_url ) };
125  }
126 
127  return \@remote_controlling_semaphores;
128 }
129 
130 1;