Changeset c381f17e441575b3b3c05fcc82b1b0687bc0264a in xas-supervisor


Ignore:
Timestamp:
12/09/15 08:27:11 (3 years ago)
Author:
Kevin L. Esteb <kevin@…>
Branches:
master
Children:
f612bf0cf2d302696dd777cd41ad9ceeb1c3372f
Parents:
fdbba6d01c088f2248591d4df8b5792bc62525ab
git-author:
Kevin L. Esteb <kevin@…> (12/09/15 08:27:11)
git-committer:
Kevin L. Esteb <kevin@…> (12/09/15 08:27:11)
Message:

Fixing logic errors

Location:
trunk
Files:
3 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/XAS/Supervisor/Controller.pm

    rfdbba6d01c088f2248591d4df8b5792bc62525ab rc381f17e441575b3b3c05fcc82b1b0687bc0264a  
    88  debug     => 0, 
    99  version   => $VERSION, 
    10   base      => 'XAS::Lib::Net::Server', 
    11   mixin     => 'XAS::Lib::Mixins::JSON::Server', 
    12   utils     => ':validation stat2text', 
     10  base      => 'XAS::Lib::RPC::JSON::Server', 
     11  utils     => 'stat2text :validation', 
    1312  constants => ':process :jsonrpc HASHREF', 
    1413  vars => { 
     
    2019; 
    2120 
     21use Data::Dumper; 
     22 
    2223# ---------------------------------------------------------------------- 
    2324# Public Methods 
     
    3132    $self->log->debug("$alias: entering session_initialize() - supervisor"); 
    3233 
    33     # communications from RPC. 
     34    # define our events. 
    3435 
    3536    $poe_kernel->state('kill_process',   $self, '_kill_process'); 
     
    4243    $poe_kernel->state('list_processes', $self, '_list_processes'); 
    4344 
     45    # define the RPC methods, linked to the events 
     46 
     47    $self->methods->insert('kill_process'); 
     48    $self->methods->insert('stop_process'); 
     49    $self->methods->insert('stat_process'); 
     50    $self->methods->insert('pause_process'); 
     51    $self->methods->insert('resume_process'); 
     52    $self->methods->insert('list_processes'); 
     53    $self->methods->insert('check_status'); 
     54 
    4455    # walk the chain 
    4556 
     
    7081 
    7182sub _stop_process { 
    72     my $self = $_[OBJECT]; 
    73     my ($params, $ctx) = validate_params(\@_[ARG0,ARG1], [ 
    74         { type => HASHREF }, 
    75         { type => HASHREF }, 
    76     ]); 
     83    my ($self, $params, $ctx) = @_[OBJECT,ARG0,ARG1]; 
    7784 
    7885    my $alias = $self->alias; 
     
    98105 
    99106sub _kill_process { 
    100     my $self = $_[OBJECT]; 
    101     my ($params, $ctx) = validate_params(\@_[ARG0,ARG1], [ 
    102         { type => HASHREF }, 
    103         { type => HASHREF }, 
    104     ]); 
     107    my ($self, $params, $ctx) = @_[OBJECT,ARG0,ARG1]; 
    105108 
    106109    my $alias = $self->alias; 
     
    126129 
    127130sub _stat_process { 
    128     my $self = $_[OBJECT]; 
    129     my ($params, $ctx) = validate_params(\@_[ARG0,ARG1], [ 
    130         { type => HASHREF }, 
    131         { type => HASHREF }, 
    132     ]); 
    133  
    134     my $alias = $self->alias; 
    135     my $name  = $params->{'name'}; 
    136  
    137     if (my $process = $self->processes->{$name}) { 
    138  
    139         my $stat     = $process->stat_process(); 
    140         my $status   = stat2text($stat); 
    141         my $response = $self->message('supervisor_status', $name, $status); 
    142  
    143         $self->process_response($response, $ctx); 
     131    my ($self, $params, $ctx) = @_[OBJECT,ARG0,ARG1]; 
     132 
     133    my $alias = $self->alias; 
     134    my $name  = $params->{'name'}; 
     135 
     136    if (my $process = $self->processes->{$name}) { 
     137 
     138        my $stat   = $process->stat_process(); 
     139        my $status = stat2text($stat); 
     140 
     141        $self->process_response($status, $ctx); 
    144142 
    145143    } else { 
     
    157155 
    158156sub _start_process { 
    159     my $self = $_[OBJECT]; 
    160     my ($params, $ctx) = validate_params(\@_[ARG0,ARG1], [ 
    161         { type => HASHREF }, 
    162         { type => HASHREF }, 
    163     ]); 
     157    my ($self, $params, $ctx) = @_[OBJECT,ARG0,ARG1]; 
    164158 
    165159    my $alias = $self->alias; 
     
    185179 
    186180sub _pause_process { 
    187     my $self = $_[OBJECT]; 
    188     my ($params, $ctx) = validate_params(\@_[ARG0,ARG1], [ 
    189         { type => HASHREF }, 
    190         { type => HASHREF }, 
    191     ]); 
     181    my ($self, $params, $ctx) = @_[OBJECT,ARG0,ARG1]; 
    192182 
    193183    my $alias = $self->alias; 
     
    213203 
    214204sub _resume_process { 
    215     my $self = $_[OBJECT]; 
    216     my ($params, $ctx) = validate_params(\@_[ARG0,ARG1], [ 
    217         { type => HASHREF }, 
    218         { type => HASHREF }, 
    219     ]); 
     205    my ($self, $params, $ctx) = @_[OBJECT,ARG0,ARG1]; 
    220206 
    221207    my $alias = $self->alias; 
     
    241227 
    242228sub _check_status { 
    243     my $self = $_[OBJECT]; 
    244     my ($params, $ctx, $status, $count) = validate_params(\@_[ARG0...ARG3], [ 
    245         { type => HASHREF }, 
    246         { type => HASHREF }, 
    247         1, 
    248         1, 
    249     ]); 
     229    my ($self, $params, $ctx, $status, $count) = @_[OBJECT,ARG0...ARG3]; 
    250230 
    251231    my $alias = $self->alias; 
     
    258238        if ($stat == $status) { 
    259239 
    260             my $response = $self->message('supervisor_status', $name, $stat); 
     240            my $response = 'stopped'; 
     241 
     242            $response = 'running' if ($stat == PROC_RUNNING); 
     243            $response = 'paused'  if ($stat == PROC_PAUSED); 
     244            $response = 'killed'  if ($stat == PROC_KILLED); 
    261245 
    262246            $self->process_response($response, $ctx); 
     
    297281 
    298282sub _list_processes { 
    299     my $self = $_[OBJECT]; 
    300     my ($params, $ctx) = validate_params(\@_[ARG0,ARG1], [ 
    301         { type => HASHREF }, 
    302         { type => HASHREF }, 
    303     ]); 
    304  
    305     my $alias = $self->alias; 
    306     my $list = join(',', sort(keys($self->processes))); 
    307     my $response = $self->message('supervisor_list', $list); 
    308  
    309     $self->process_response($response, $ctx); 
     283    my ($self, $params, $ctx) = @_[OBJECT,ARG0,ARG1]; 
     284 
     285    my $alias = $self->alias; 
     286    my @response = sort(keys($self->processes)); 
     287 
     288    $self->process_response(\@response, $ctx); 
    310289 
    311290} 
     
    314293# Private Methods 
    315294# ---------------------------------------------------------------------- 
    316  
    317 sub init { 
    318     my $class = shift; 
    319  
    320     my $self = $class->SUPER::init(@_); 
    321  
    322     my @methods = [ 
    323         'stop_process', 
    324         'start_process', 
    325         'stat_process', 
    326         'kill_process', 
    327         'pause_process', 
    328         'resume_process', 
    329         'list_processes', 
    330     ]; 
    331  
    332     $self->init_json_server(\@methods); 
    333  
    334     return $self; 
    335  
    336 } 
    337295 
    3382961; 
Note: See TracChangeset for help on using the changeset viewer.