ensembl-hive  2.6
Bio::EnsEMBL::Hive::GuestProcess Class Reference
+ Inheritance diagram for Bio::EnsEMBL::Hive::GuestProcess:

Public Member Functions

public String get_protocol_version ()
 
public check_version_compatibility ()
 
public Bio::EnsEMBL::Hive::GuestProcess new ()
 
protected String _get_wrapper_for_language ()
 
protected Hashref _get_all_registered_wrappers ()
 
public String get_wrapper_version ()
 
public void assert_runnable_exists ()
 
public void build_wrapper_for_language ()
 
public void DESTROY ()
 
public void print_debug ()
 
public IO::Handle child_in ()
 
public IO::Handle child_out ()
 
public Int child_pid ()
 
public Instance json_formatter ()
 
public void send_message ()
 
public void send_response ()
 
public Perl read_message ()
 
public void wait_for_OK ()
 
public Hashref param_defaults ()
 
public Hashref life_cycle ()
 
- Public Member Functions inherited from Bio::EnsEMBL::Hive::Process
public new ()
 
public life_cycle ()
 
public say_with_header ()
 
public enter_status ()
 
public warning ()
 
public param_defaults ()
 
public fetch_input ()
 
public run ()
 
public write_output ()
 
public Bio::EnsEMBL::Hive::Worker worker ()
 
public execute_writes ()
 
public Bio::EnsEMBL::Hive::DBSQL::DBAdaptor db ()
 
public Bio::EnsEMBL::Hive::DBSQL::DBConnection dbc ()
 
public Bio::EnsEMBL::Hive::DBSQL::DBConnection data_dbc ()
 
public Returns run_system_command ()
 
public Bio::EnsEMBL::Hive::AnalysisJob input_job ()
 
public input_id ()
 
public param ()
 
public param_required ()
 
public param_exists ()
 
public param_is_defined ()
 
public param_substitute ()
 
public dataflow_output_id ()
 
public dataflow_output_ids_from_json ()
 
public throw ()
 
public This complete_early ()
 
public Int debug ()
 
public worker_temp_directory ()
 
public cleanup_worker_temp_directory ()
 

Detailed Description

Synopsis

This is a variant of Bio::EnsEMBL::Hive::Process that forks into a wrapper that can itself
run jobs (runnables) written in a different language

Description

Upon initialisation, GuestProcess forks, and the child process executes the wrapper that
will allow running Runnables of the other language. The communication is ensured by two
pipes and is schematically similar to running "| wrapper |", except that GuestProcess
uses non-standard file descriptors, thus allowing the Runnable to still use std{in,out,err}.

The wrapper receives the two file-numbers that it is meant to use (one for reading data
from GuestProcess, and one to send data to GuestProcess). All the messages are passed
around in single-line JSON structures. The protocol is described below using the convention:
    ---> represents a message sent to the child process,
    <--- represents a message sent by the child process

The initialisation (in the constructor) consists in checking that both sides spek the same
version of the protocol:
    <--- { "version": "XXX" }
    ---> "OK"
GuestProcess will bail out if the response is not "OK"

Then, the child process (i.e. the runnable) will send its default parameters to GuestProcess.
This fills the usual param_defaults() section of the Runnable:
    <--- { ... param_defaults ... }
    ---> "OK"

The child process then goes to sleep, waiting for jobs to be seeded. Meanwhile,
GuestProcess enters a number of life_cycle() executions (as triggered by Worker).
Each one first sends a JSON object to the child process to initialize the job parameters
    ---> {
           "input_job": {
             "parameters": { ... the unsubstituted job parameters as compiled by Worker ... },
             // followed by several attributes of the job
             "input_id": { ...  },
             "dbID": XXX,
             "retry_count": XXX
           },
           "execute_writes": [1|0],
           "debug": XXX
         }
    <--- "OK"

From this point, GuestProcess acts as a server, listening to events sent by the child.
Events are JSON objects composed of an "event" field (the name of the event) and a
"content" field (the payload). Events can be of the following kinds (with the expected
response from GuestProcess):

    <--- JOB_STATUS_UPDATE
         // The content is one of "PRE_CLEANUP", "FETCH_INPUT", "RUN", "WRITE_OUTPUT", "POST_HEALTHCHECK", "POST_CLEANUP"
    ---> "OK"

    <--- WARNING
         // The content is a JSON object:
            {
              "message": "XXX",
              "is_error": [true|false],
            }
    ---> "OK"

    <--- DATAFLOW
         // The content is a JSON object:
            {
              "branch_name_or_code": XXX,
              "output_ids": an array or a hash,
              "params": {
                "substituted": { ... the parameters that are currently substituted ... }
                "unsubstituted": { ... the parameters that have not yet been substituted ... }
              }
            }
    ---> dbIDs of the jobs that have been created

    <--- WORKER_TEMP_DIRECTORY
         // No content needed (ignored)
    ---> returns the temporary directory of the worker

    <--- JOB_END
         // The content is a JSON object describing the final state of the job
            {
              "complete": [true|false],
              "job": {
                "autoflow": [true|false],
                "lethal_for_worker": [true|false],
                "transient_error": [true|false],
              },
              "params": {
                "substituted": { ... the parameters that are currently substituted ... }
                "unsubstituted": { ... the parameters that have not yet been substituted ... }
              }
            }
    ---> "OK"


Definition at line 105 of file GuestProcess.pm.

Member Function Documentation

◆ _get_all_registered_wrappers()

protected Hashref Bio::EnsEMBL::Hive::GuestProcess::_get_all_registered_wrappers ( )
  Example     :
  Description : Lists all the languages and wrappers that are registered (either
                under via a EHIVE_WRAPPER environment variable, or via a "wrapper"
                file under $EHIVE_ROOT_DIR/wrappers/).
                Note that those wrappers are not necessarily usable, as 1) _get_wrapper_for_language
                performs additional checks and 2) the version numbers have to match
  Returntype  : Hashref { String => String }
  Exceptions  : None
 
Code:
click to view

◆ _get_wrapper_for_language()

protected String Bio::EnsEMBL::Hive::GuestProcess::_get_wrapper_for_language ( )
  Example     :
  Description : Finds the wrapper that understands the given language
  Returntype  : String
  Exceptions  : Can die if the wrapper doesn't exist
 
Code:
click to view

◆ assert_runnable_exists()

public void Bio::EnsEMBL::Hive::GuestProcess::assert_runnable_exists ( )
  Example     :
Bio::EnsEMBL::Hive::GuestProcess::assert_runnable_exists('python3', 'eHive.examples.TestRunnable');
  Description : Ask the wrapper to check whether the runnable exists (can be loaded)
  Returntype  : None
  Exceptions  : Die if there is no wrapper or the runnable can't be loaded
 
Code:
click to view

◆ build_wrapper_for_language()

public void Bio::EnsEMBL::Hive::GuestProcess::build_wrapper_for_language ( )
  Example     :
  Description : Ask the wrapper to build all the necessary code to run Runnables of this language
  Returntype  : None
  Exceptions  : Die if there is no wrapper or the build fails
 
Code:
click to view

◆ check_version_compatibility()

public Bio::EnsEMBL::Hive::GuestProcess::check_version_compatibility ( )

Undocumented method

Code:
click to view

◆ child_in()

public IO::Handle Bio::EnsEMBL::Hive::GuestProcess::child_in ( )
  Example     :
my $child_in = $process->child_in();
  Example     :
$process->child_in(*CHILD_WTR);
  Description : Getter/Setter for the file handle that allows talking to the
                child process.
  Returntype  : IO::Handle
  Exceptions  : none
 
Code:
click to view

◆ child_out()

public IO::Handle Bio::EnsEMBL::Hive::GuestProcess::child_out ( )
  Example     :
my $child_out = $process->child_out();
  Example     :
$process->child_out(*CHILD_RDR);
  Description : Getter/Setter for the file handle that allows receiving data
                from the child process.
  Returntype  : IO::Handle
  Exceptions  : none
 
Code:
click to view

◆ child_pid()

public Int Bio::EnsEMBL::Hive::GuestProcess::child_pid ( )
  Example     :
my $child_pid = $process->child_pid();
  Example     :
$process->child_pid($child_pid);
  Description : Getter/Setter for the process ID of the child
  Returntype  : integer
  Exceptions  : none
 
Code:
click to view

◆ DESTROY()

public void Bio::EnsEMBL::Hive::GuestProcess::DESTROY ( )
  Description : Destructor: tells the child to exit by sending an empty JSON object
  Returntype  : none
 
Code:
click to view

◆ get_protocol_version()

public String Bio::EnsEMBL::Hive::GuestProcess::get_protocol_version ( )
  Example     :
  Description : Returns the version number of the communication protocol
  Returntype  : String
 
Code:
click to view

◆ get_wrapper_version()

public String Bio::EnsEMBL::Hive::GuestProcess::get_wrapper_version ( )
  Example     :
  Description : Ask the wrapper what version it is on. The major number is expected to match $GUESTPROCESS_PROTOCOL_VERSION
  Returntype  : String
  Exceptions  : Die if there is no wrapper
 
Code:
click to view

◆ json_formatter()

public Instance Bio::EnsEMBL::Hive::GuestProcess::json_formatter ( )
  Example     :
my $json_formatter = $object_name->json_formatter();
  Example     :
$object_name->json_formatter($json_formatter);
  Description : Getter/Setter for the JSON formatter.
  Returntype  : instance of JSON
  Exceptions  : none
 
Code:
click to view

◆ life_cycle()

public Hashref Bio::EnsEMBL::Hive::GuestProcess::life_cycle ( )
  Example     :
my $partial_timings = $runnable->life_cycle();
  Description : Runs the life-cycle of the input job and returns the timings
                of each Runnable method (fetch_input, run, etc).
                See the description of this module for details about the protocol
  Returntype  : Hashref
  Exceptions  : none
 
Code:
click to view

◆ new()

public Bio::EnsEMBL::Hive::GuestProcess Bio::EnsEMBL::Hive::GuestProcess::new ( )
  Arg[1]      : $language: the programming language the external runnable is in
  Arg[2]      : $module: the name of the runnable (usually a package name)
  Example     :
  Description : Constructor
  Returntype  : Bio::EnsEMBL::Hive::GuestProcess
  Exceptions  : if $language or $module is not defined properly or if the pipes /
                child process could not be created
 
Code:
click to view

◆ param_defaults()

public Hashref Bio::EnsEMBL::Hive::GuestProcess::param_defaults ( )
  Example     :
my $param_defaults = $runnable->param_defaults();
  Example     :
$runnable->param_defaults($param_defaults);
  Description : Getter/Setter for the default parameters of this runnable.
                Hive only uses it as a getter, but here, we need a setter to
                define the parameters at the Perl layer once they've been
                retrieved from the child process.
  Returntype  : Hashref
  Exceptions  : none
 
Code:
click to view

◆ print_debug()

public void Bio::EnsEMBL::Hive::GuestProcess::print_debug ( )
  Example     :
$process->print_debug("debug message");
  Description : Prints a message if $self->{'_protocol_debug'} is set
  Returntype  : none
 
Code:
click to view

◆ read_message()

public Perl Bio::EnsEMBL::Hive::GuestProcess::read_message ( )
  Example     :
my $msg = $process->read_message();
  Description : Wait for and read the next message coming from the child.
                Again, the message itself is serialized and transmitted
                via the pipe
  Returntype  : Perl structure
  Exceptions  : raised by JSON / IO::Handle
 
Code:
click to view

◆ send_message()

public void Bio::EnsEMBL::Hive::GuestProcess::send_message ( )
  Example     :
$process->send_message($perl_structure);
  Description : Send the Perl structure to the child process via the pipe (and
                serialized in JSON).
  Returntype  : none
  Exceptions  : raised by JSON / IO::Handle
 
Code:
click to view

◆ send_response()

public void Bio::EnsEMBL::Hive::GuestProcess::send_response ( )
  Example     :
$process->send_response('OK');
  Description : Wrapper around send_message to send a response to the child.
  Returntype  : none
  Exceptions  : raised by JSON / IO::Handle
 
Code:
click to view

◆ wait_for_OK()

public void Bio::EnsEMBL::Hive::GuestProcess::wait_for_OK ( )
  Example     :
$process->wait_for_OK();
  Description : Wait for the child process to send the OK signal
  Returntype  : none
  Exceptions  : dies if the response is not OK, or anything raised by read_message()
 
Code:
click to view

The documentation for this class was generated from the following file:
Bio::EnsEMBL::Hive::GuestProcess::check_version_compatibility
public check_version_compatibility()
Bio::EnsEMBL::Hive::GuestProcess
Definition: GuestProcess.pm:105
Bio::EnsEMBL::Hive::GuestProcess::send_response
public void send_response()
Bio::EnsEMBL::Hive::GuestProcess::param_defaults
public Hashref param_defaults()
Bio::EnsEMBL::Hive::GuestProcess::DESTROY
public void DESTROY()
Bio::EnsEMBL::Hive::GuestProcess::build_wrapper_for_language
public void build_wrapper_for_language()
Bio::EnsEMBL::Hive::GuestProcess::_get_wrapper_for_language
protected String _get_wrapper_for_language()
Bio::EnsEMBL::Hive::Process::debug
public Int debug()
Bio::EnsEMBL::Hive::Process::input_id
public input_id()
Bio::EnsEMBL::Hive::GuestProcess::get_protocol_version
public String get_protocol_version()
Bio::EnsEMBL::Hive::GuestProcess::child_in
public IO::Handle child_in()
Bio::EnsEMBL::Hive::Process
Definition: Process.pm:77
Bio::EnsEMBL::Hive::GuestProcess::child_out
public IO::Handle child_out()
Bio::EnsEMBL::Hive::GuestProcess::life_cycle
public Hashref life_cycle()
Bio::EnsEMBL::Hive::GuestProcess::assert_runnable_exists
public void assert_runnable_exists()
Bio::EnsEMBL::Hive::GuestProcess::new
public Bio::EnsEMBL::Hive::GuestProcess new()
Bio::EnsEMBL::Hive::Utils::Stopwatch
Definition: Stopwatch.pm:33
Bio::EnsEMBL::Hive::Process::execute_writes
public execute_writes()
Bio::EnsEMBL::Hive::GuestProcess::read_message
public Perl read_message()
Bio::EnsEMBL::Hive::GuestProcess::wait_for_OK
public void wait_for_OK()
Bio::EnsEMBL::Hive::GuestProcess::get_wrapper_version
public String get_wrapper_version()
Bio::EnsEMBL::Hive::Process::input_job
public Bio::EnsEMBL::Hive::AnalysisJob input_job()
Bio::EnsEMBL::Hive::Process::worker
public Bio::EnsEMBL::Hive::Worker worker()
Bio::EnsEMBL::Hive::Utils::Stopwatch::new
public new()
Bio::EnsEMBL::Hive::GuestProcess::json_formatter
public Instance json_formatter()
Bio::EnsEMBL::Hive::GuestProcess::_get_all_registered_wrappers
protected Hashref _get_all_registered_wrappers()
Bio::EnsEMBL::Hive::GuestProcess::send_message
public void send_message()
Bio::EnsEMBL::Hive::GuestProcess::print_debug
public void print_debug()
Bio::EnsEMBL::Hive::GuestProcess::child_pid
public Int child_pid()
Bio::EnsEMBL::Hive::Process::run
public run()