Tuesday, February 24, 2009

Generator Controller Communication

In my last post I mentioned that I took ActiveMQ out of the project and settled on web services for communicating between the Generators an the controller, but I left out how the communication would work.


I settled on a very simple model. Generators are responsible for asking for work and attempting to update the controller with generation status. The Controller is responsible for doling out work, tracking progress, error management and and dealing with rogue generators.

Rogue generators aren't likely given their stability over the last 5 years, but if they were to go bad they would do things like:
  • Ask for a site to generate. Not complete generating the site.  Ask for another site to generate.
  • Fail to report a status update for generating a site.
In these cases, the controller has the error checking capabilities to clean up the generation data as much as possible and either tell the generator to do nothing, re-render a site, or render a new site.

The Perl Doc for the module used by the generator to communicate with the controller is probably the best way to understand how this works.

=head1 Enotify::Generator::ControllerCommunicator

  This package enables communication with the enotify controller
  web application.
 
  The functionality in this package supports the communication model
  where the generator ALWAYS initiates contact with the Controller.
  The process flow is as follows
 
  1) a cron task kicks off the generator
  2) the generator asks the controller what work to do
  3) the controller responds with the name of a project
  4) the generator generates the site & sends status messages
     to the controller during the update process
  5) the generator finishes the site update, notifies the controller and exits
     

the cron tab is on a 2 minute retry, with logic to keep multiple generators from starting. so step 1 will happen at most 2 minutes after step 5 completes
 

  What does the controller do with the status updates.
   
    The controller uses these status updates to record the progress of the generator in the Generation object. Each status message corresponds to a column in the generation table. The Controller records the current time in that columns when it recieves a status
    message.
   
    Status updates are simply messages saying the generator is starting or ending some part of the site generation. For example:
       
    GENERATION_BUG_LIST_DOWNLOAD_START means the generator is about to start downloading
    the sites bug lists and GENERATION_BUG_LIST_DOWNLOAD_END means the generator finished
    downloading those bug lists.

    Complete list of status messages
 
        GENERATION_START
        GENERATION_END
       
        GENERATION_BUG_LIST_DOWNLOAD_START
        GENERATION_BUG_LIST_DOWNLOAD_END

        GENERATION_RENDERING_PAGES_START
        GENERATION_RENDERING_PAGES_END

        GENERATION_RENDERING_GRAPHS_START
        GENERATION_RENDERING_GRAPHS_END

   The controller identifies all requests based on the IP address of the
   generator which is automatically passed with every call.
  
   Deployment Requirement:
     Because it is technally possible for a DHCP generator to change it's IP
     address while running a site, the enterprise deployment of this mechanism
     requires generators with Static IP addresses.
    
    
   Example use:
  
    $controller_comunicator = Enotify::Generator::ControllerCommunicator::new();
    
    $site_name = $controller_comunicator->get_site_to_generate()
   
    print "Site Name " . $site_name;
   
    >Site Name foo
   
    $controller_comunicator->
    
=cut

=head2 ControllerCommunicator->get_site_to_generate() {{{

    Purpose: This method requests a new site to generate from the
              controller.
            
    Expects: Nothing. Seriously, it is the controllers responcibility
             to deal with generators that go crazy or ask for this
             info multiple times.
                 
    Returns: (STRING) The short name of the site that is being updated. This
             is also the last directory in the path to the
             directory for the site.
            
             print "enotify/sites/" . $controller_comunicator->get_site_to_generate()
   
             > enotif/sites/foo
=cut
=head2 ControllerCommunicator->update_generation_progress() {{{

    Purpose: This method sends a status update to the controller.
           
                Valid Status messages:

                        GENERATION_START
                        GENERATION_END

                        GENERATION_BUG_LIST_DOWNLOAD_START
                        GENERATION_BUG_LIST_DOWNLOAD_END

                        GENERATION_RENDERING_PAGES_START
                        GENERATION_RENDERING_PAGES_END

                        GENERATION_RENDERING_GRAPHS_START
                        GENERATION_RENDERING_GRAPHS_END
         
            
    Expects: The name of the update to send.
                 
    Returns: (BOOLEAN) True if the update succeeded. False if there was a server error.
            
             print  $controller_comunicator->get_site_to_generate(GENERATION_START)
   
             > 1
=cut

No comments: