ensembl-hive  2.8.1
BeekeeperAdaptor.pm
Go to the documentation of this file.
1 =pod
2 
3 =head1 NAME
4 
6 
7 =head1 DESCRIPTION
8 
9  This is the adaptor for Bio::EnsEMBL::Hive::Beekeeper
10 
11  It contains all the beekeeper-management methods that are
12  called by beekeeper.pl and requir the database.
13 
14 =head1 LICENSE
15 
16  See the NOTICE file distributed with this work for additional information
17  regarding copyright ownership.
18 
19  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
20  You may obtain a copy of the License at
21 
22  http://www.apache.org/licenses/LICENSE-2.0
23 
24  Unless required by applicable law or agreed to in writing, software distributed under the License
25  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26  See the License for the specific language governing permissions and limitations under the License.
27 
28 =head1 CONTACT
29 
30  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
31 
32 =cut
33 
34 
35 package Bio::EnsEMBL::Hive::DBSQL::BeekeeperAdaptor;
36 
37 use strict;
38 use warnings;
39 use base ('Bio::EnsEMBL::Hive::DBSQL::ObjectAdaptor');
40 
41 # --------------------------------- ObjectAdaptor implementation ---------------------------------------
42 
43 sub default_table_name {
44  return 'beekeeper';
45 }
46 
47 
48 sub object_class {
49  return 'Bio::EnsEMBL::Hive::Beekeeper';
50 }
51 
52 
53 # --------------------------------- Beekeeper methods ---------------------------------------
54 
55 =head2 find_live_beekeepers_in_my_meadow
56 
57  Arg[1] : Bio::EnsEMBL::Hive::Beekeeper $ref_beekeeper
58  Example : my $live_beekeepers_in_my_meadow = $bk_adaptor->find_live_beekeepers_in_my_meadow($beekeeper);
59  Description : Returns all the beekeepers registered on the same host as $ref_beekeeper that are still alive.
60  Returntype : Arrayref of Bio::EnsEMBL::Hive::Beekeeper
61  Exceptions : none
62  Caller : general
63  Status : Stable
64 
65 =cut
66 
67 sub find_live_beekeepers_in_my_meadow {
68  my ($self, $ref_beekeeper) = @_;
69 
70  my $filter = sprintf("meadow_host = '%s' AND beekeeper_id != %d AND cause_of_death IS NULL", $ref_beekeeper->meadow_host, $ref_beekeeper->dbID);
71  return $self->fetch_all($filter);
72 }
73 
74 
75 =head2 bury_other_beekeepers
76 
77  Arg[1] : Bio::EnsEMBL::Hive::Beekeeper $ref_beekeeper
78  Example : $bk_adaptor->bury_other_beekeepers($ref_beekeeper);
79  Description : Calls find_live_beekeepers_in_my_meadow() and buries the beekeepers that
80  are not running any more (not find with `ps`)
81  Returntype : none
82  Exceptions : none
83  Caller : general
84  Status : Stable
85 
86 =cut
87 
88 sub bury_other_beekeepers {
89  my ($self, $ref_beekeeper) = @_;
90 
91  my $allegedly_live_beekeepers_in_my_meadow = $self->find_live_beekeepers_in_my_meadow($ref_beekeeper);
92  foreach my $beekeeper_to_check (@$allegedly_live_beekeepers_in_my_meadow) {
93  my $pid = $beekeeper_to_check->process_id;
94  my $cmd = qq{ps -p $pid -f | fgrep beekeeper.pl};
95  my $beekeeper_entry = qx{$cmd};
96 
97  unless ($beekeeper_entry) {
98  $beekeeper_to_check->set_cause_of_death('DISAPPEARED');
99  }
100  }
101 }
102 
103 
104 =head2 reload_beekeeper_is_blocked
105 
106  Arg[1] : Bio::EnsEMBL::Hive::Beekeeper $beekeeper
107  Example : my $is_blocked = $bk_adaptor->reload_beekeeper_is_blocked($beekeeper);
108  Description : Updates the object with the freshest value of is_blocked coming from the database
109  for this beekeeper, and return the new value.
110  Returntype : none
111  Exceptions : none
112  Caller : general
113  Status : Stable
114 
115 =cut
116 
117 sub reload_beekeeper_is_blocked {
118  my ($self, $beekeeper) = @_;
119 
120  my $query = 'SELECT is_blocked FROM beekeeper WHERE beekeeper_id = ?';
121 
122  my $sth = $self->dbc->prepare($query);
123  $sth->execute($beekeeper->dbID);
124 
125  my ($is_blocked) = $sth->fetchrow_array();
126  $sth->finish;
127 
128  $beekeeper->is_blocked( $is_blocked );
129 
130  return $is_blocked;
131 }
132 
133 
134 =head2 block_all_alive_beekeepers
135 
136  Example : $bk_adaptor->block_all_alive_beekeepers();
137  Description : Set is_blocked for all beekeepers known to the
138  pipeline which haven't died yet. Part of the "shut
139  everything down" feature - as eHive stands we cannot
140  tell other beekeepers to kill their respective active
141  workers (unless said workers happen to belong to the
142  same meadow, in which case we can essentially hijack
143  them) but at least we can prevent them from spawning
144  new workers.
145  Returntype : none
146  Exception : none
147  Caller : beekeeper.pl
148  Status : Stable
149 
150 =cut
151 
152 sub block_all_alive_beekeepers {
153  my ( $self ) = @_;
154 
155  my $statement = 'UPDATE beekeeper SET is_blocked = 1 WHERE cause_of_death IS NULL';
156  my $sth = $self->dbc()->prepare( $statement );
157  $sth->execute();
158  $sth->finish();
159 
160  return;
161 }
162 
163 
164 1;
Bio::EnsEMBL::Hive::Beekeeper
Definition: Beekeeper.pm:13
Bio::EnsEMBL::Hive::DBSQL::BeekeeperAdaptor
Definition: BeekeeperAdaptor.pm:13
Bio::EnsEMBL::Hive::Beekeeper::is_blocked
public is_blocked()
Bio::EnsEMBL::Hive::Beekeeper::process_id
public process_id()