Meadow.pm 1.91 KB
Newer Older
1 2 3 4 5 6 7
# A Meadow is an abstract interface for one of several implementations of Workers' process manager.
#
# A Meadow knows how to check&change the actual status of Workers

package Bio::EnsEMBL::Hive::Meadow;

use strict;
8 9
use warnings;

10 11

sub new {
12 13 14 15 16
    my ($class, $config) = @_;

    my $self = bless {}, $class;

    $self->config( $config );
17

18
    return $self;
19 20
}

21

22 23
sub type { # should return 'LOCAL' or 'LSF'
    my $class = shift @_;
24

25
    $class = ref($class) if(ref($class));
26

27
    return (reverse split(/::/, $class ))[0];
28 29
}

30 31 32 33

sub toString {
    my $self = shift @_;

Leo Gordon's avatar
Leo Gordon committed
34
    return "Meadow:\t".$self->type.'/'.$self->name;
35 36 37
}


38
sub config {
Leo Gordon's avatar
Leo Gordon committed
39 40
    my $self = shift @_;

41 42
    if(@_) {
        $self->{'_config'} = shift @_;
Leo Gordon's avatar
Leo Gordon committed
43
    }
44 45 46 47 48 49 50 51
    return $self->{'_config'};
}


sub config_get {
    my $self = shift @_;

    return $self->config->get('Meadow', $self->type, $self->name, @_);
Leo Gordon's avatar
Leo Gordon committed
52 53
}

54 55

sub config_set {
56 57
    my $self = shift @_;

58 59 60 61 62 63 64 65 66
    return $self->config->set('Meadow', $self->type, $self->name, @_);
}


sub pipeline_name { # if set, provides a filter for job-related queries
    my $self = shift @_;

    if(@_) { # new value is being set (which can be undef)
        $self->{'_pipeline_name'} = shift @_;
67
    }
68
    return $self->{'_pipeline_name'};
69 70
}

71

72 73 74
sub job_name_prefix {
    my $self = shift @_;

75
    return ($self->pipeline_name() ? $self->pipeline_name().'-' : '') . 'Hive-';
76 77
}

78

Leo Gordon's avatar
Leo Gordon committed
79
sub generate_job_name {
80
    my ($self, $worker_count, $iteration, $rc_name) = @_;
Leo Gordon's avatar
Leo Gordon committed
81

82
    return $self->job_name_prefix()
83
        ."${rc_name}-${iteration}"
Leo Gordon's avatar
Leo Gordon committed
84
        . (($worker_count > 1) ? "[1-${worker_count}]" : '');
Leo Gordon's avatar
Leo Gordon committed
85 86
}

87

88 89 90
sub responsible_for_worker {
    my ($self, $worker) = @_;

91
    return ($worker->meadow_type eq $self->type) && ($worker->meadow_name eq $self->name);
92 93
}

94

95
sub check_worker_is_alive_and_mine {
96 97 98 99 100
    my ($self, $worker) = @_;

    die "Please use a derived method";
}

101

102 103 104 105 106 107 108
sub kill_worker {
    my ($self, $worker) = @_;

    die "Please use a derived method";
}

1;