ensembl-hive  2.8.1
FailureTest.pm
Go to the documentation of this file.
1 =pod
2 
3 =head1 NAME
4 
6 
7 =head1 SYNOPSIS
8 
9  This is a RunnableDB module that implements Bio::EnsEMBL::Hive::Process interface
10  and is ran by Workers during the execution of eHive pipelines.
11  It is not generally supposed to be instantiated and used outside of this framework.
12 
13  Please refer to Bio::EnsEMBL::Hive::Process documentation to understand the basics of the RunnableDB interface.
14 
15  Please refer to Bio::EnsEMBL::Hive::PipeConfig::* pipeline configuration files to understand how to configure pipelines.
16 
17 =head1 DESCRIPTION
18 
19  This RunnableDB module is used to test failure of jobs in the hive system.
20 
21  It is intended for development/training purposes only.
22 
23  Available parameters:
24 
25  param('value'): is essentially your job's number.
26  If you are intending to create 100 jobs, let the param('value') take consecutive values from 1 to 100.
27 
28  param('divisor'): defines the failure rate for this particular analysis. If the modulo (value % divisor) is 0, the job will fail.
29  For example, if param('divisor')==5, jobs with 5, 10, 15, 20, 25,... param('value') will fail.
30 
31  param('state'): defines the state in which the jobs of this analysis may be failing.
32 
33  param('lethal_after'): makes jobs' failures lethal when 'value' is greater than this parameter
34 
35  param('time_FETCH_INPUT'): time in seconds that the job will spend sleeping in FETCH_INPUT state.
36 
37  param('time_RUN'): time in seconds that the job will spend sleeping in RUN state.
38 
39  param('time_WRITE_OUTPUT'): time in seconds that the job will spend sleeping in WRITE_OUTPUT state.
40 
41 =head1 LICENSE
42 
43  See the NOTICE file distributed with this work for additional information
44  regarding copyright ownership.
45 
46  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
47  You may obtain a copy of the License at
48 
49  http://www.apache.org/licenses/LICENSE-2.0
50 
51  Unless required by applicable law or agreed to in writing, software distributed under the License
52  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
53  See the License for the specific language governing permissions and limitations under the License.
54 
55 =head1 CONTACT
56 
57  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
58 
59 =cut
60 
61 
62 package Bio::EnsEMBL::Hive::Examples::FailureTest::RunnableDB::FailureTest;
63 
64 use strict;
65 use warnings;
66 
67 use base ('Bio::EnsEMBL::Hive::Process');
68 
69 BEGIN {
70 # die "Could not compile this nonsense!";
71 }
72 
73 =head2 param_defaults
74 
75  Description : Implements param_defaults() interface method of Bio::EnsEMBL::Hive::Process that defines module defaults for parameters.
76 
77 =cut
78 
79 sub param_defaults {
80 
81  return {
82  'value' => 1, # normally you generate a batch of jobs with different values of param('value')
83  'divisor' => 2, # but the same param('divisor') and see how every param('divisor')'s job will crash
84  'state' => 'RUN', # the state in which the process may commit apoptosis ('FETCH_INPUT', 'RUN' or 'WRITE_OUTPUT')
85  'lethal_after' => 0, # If value is above this (nonzero) threshold, job's death becomes lethal to the worker.
86 
87  'time_FETCH_INPUT' => 0, # how much time fetch_input() will spend in sleeping state
88  'time_RUN' => 1, # how much time run() will spend in sleeping state
89  'time_WRITE_OUTPUT' => 0, # how much time write_output() will spend in sleeping state
90 
91  'grab_mln' => 0, # how many millions of numeric elements to allocate
92  };
93 }
94 
95 
96 =head2 pre_cleanup
97 
98  Title : pre_cleanup
99  Function: sublcass can implement functions related to cleaning up the database/filesystem after the previous unsuccessful run.
100  Here we just define it to see when the job gets into this state.
101 
102 =cut
103 
104 sub pre_cleanup {
105 }
106 
107 
108 =head2 fetch_input
109 
110  Description : Implements fetch_input() interface method of Bio::EnsEMBL::Hive::Process that is used to read in parameters and load data.
111  Here it only calls dangerous_math() subroutine.
112 
113 =cut
114 
115 sub fetch_input {
116  my $self = shift @_;
117 
118  $self->dangerous_math('FETCH_INPUT');
119 }
120 
121 
122 =head2 run
123 
124  Description : Implements run() interface method of Bio::EnsEMBL::Hive::Process that is used to perform the main bulk of the job (minus input and output).
125  Here it only calls dangerous_math() subroutine.
126 
127 =cut
128 
129 sub run {
130  my $self = shift @_;
131 
132  my $mem_ref;
133  if(my $grab_mln = $self->param('grab_mln')) {
134  $mem_ref = $self->grab_memory( $grab_mln );
135  }
136 
137  $self->dangerous_math('RUN');
138 }
139 
140 
141 =head2 write_output
142 
143  Description : Implements write_output() interface method of Bio::EnsEMBL::Hive::Process that is used to deal with job's output after the execution.
144  Here it only calls dangerous_math() subroutine.
145 
146 =cut
147 
148 sub write_output {
149  my $self = shift @_;
150 
151  $self->dangerous_math('WRITE_OUTPUT');
152 }
153 
154 
155 =head2 post_cleanup
156 
157  Title : post_cleanup
158  Function: sublcass can implement functions related to cleaning up after running one job
159  (destroying non-trivial data structures in memory).
160  Here we just define it to see when the job gets into this state.
161 
162 =cut
163 
164 sub post_cleanup {
165 # my $self = shift @_;
166 #
167 # $self->dangerous_math( $self->param('state') ); # uncomment to simulate failures in POST_CLEANUP
168 }
169 
170 
171 =head2 dangerous_math
172 
173  Description: an internal subroutine that will first sleep for some predefined time,
174  and then either return or crash if $value is an integral multiple of $divisor.
175 
176 =cut
177 
178 sub dangerous_math {
179  my ($self, $current_state) = @_;
180 
181  # First, sleep as required:
182  my $seconds_to_sleep = $self->param('time_'.$current_state);
183  sleep( $seconds_to_sleep );
184 
185  my $state = $self->param('state');
186  return if($current_state ne $state);
187 
188  my $value = $self->param('value') or die "param('value') has to be a nonzero integer";
189  my $divisor = $self->param('divisor') or die "param('divisor') has to be a nonzero integer";
190 
191  if($value % $divisor == 0) {
192 
193  if(my $lethal_after = $self->param('lethal_after')) {
194  if($value>$lethal_after) { # take the Worker with us into the grave
195  $self->input_job->lethal_for_worker(1);
196  }
197  }
198 
199  die "Preprogrammed death since $value is a multiple of $divisor";
200  }
201 }
202 
203 
204 sub grab_memory {
205  my ($self, $grab_mln) = @_;
206 
207  my $elements = $grab_mln*1_000_000;
208  my $estimated_megs = $grab_mln*69 + 23; # empirically found by running on farm3, may differ elsewhere
209 
210  $|=1;
211 
212  $self->warning("Allocating $elements elements, which should map to approximately $estimated_megs megabytes");
213 
214  my @mem = (1..$elements);
215 
216  return \@mem;
217 }
218 
219 1;
220 
Bio::EnsEMBL::Hive::Examples::FailureTest::RunnableDB::FailureTest
Definition: FailureTest.pm:44
Bio::EnsEMBL::Hive::Process
Definition: Process.pm:77
Bio::EnsEMBL::Hive::PipeConfig
Definition: HiveGeneric_conf.pm:19
main
public main()
BEGIN
public BEGIN()
run
public run()
Bio
Definition: AltAlleleGroup.pm:4