Show
Ignore:
Timestamp:
04/24/08 17:14:36 (7 months ago)
Author:
kindlund
Message:

Updated Manager to support DB retrieval of URLs for multiple, simultaneous VMs.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/trunk/lib/HoneyClient/Manager.pm

    r1547 r1558  
    241241use Data::Dumper; 
    242242 
     243# Make sure Sys::Hostname loads. 
     244BEGIN { use_ok('Sys::Hostname') or diag("Can't load Sys::Hostname package.  Check to make sure the package library is correctly listed within the path."); } 
     245require_ok('Sys::Hostname'); 
     246use Sys::Hostname; 
     247 
     248# Make sure Sys::HostIP loads. 
     249BEGIN { use_ok('Sys::HostIP') or diag("Can't load Sys::HostIP package.  Check to make sure the package library is correctly listed within the path."); } 
     250require_ok('Sys::HostIP'); 
     251use Sys::HostIP; 
     252 
    243253=end testing 
    244254 
     
    264274# Include Database Libraries 
    265275use HoneyClient::Manager::Database; 
     276 
     277# Use Hostname Libraries 
     278use Sys::Hostname::Long; 
     279 
     280# Use HostIP Libraries 
     281use Sys::HostIP; 
    266282 
    267283# Use Dumper Library 
     
    540556} 
    541557 
     558# Helper function designed to get new URLs from the Drone 
     559# database.  If it's the first attempt at obtaining URLs, 
     560# then it will ask the Drone database for any existing, 
     561# pre-assigned URLs.  Otherwise, it will ask the Drone 
     562# database for new, unassigned URLs. 
     563# 
     564# Inputs: first_attempt 
     565# Outputs: Hashref of (url => priority) pairs. 
     566sub _get_urls { 
     567 
     568    # Extract arguments. 
     569    my (%args) = @_; 
     570 
     571    # Returned argument. 
     572    my $ret = { }; 
     573 
     574    # If this is the first attempt, then get any pre-assigned URLs. 
     575    if ($args{'first_attempt'}) { 
     576        $ret = HoneyClient::Manager::Database::get_queue_urls_by_hostname(Sys::Hostname::Long::hostname_long); 
     577    } else { 
     578        $ret = HoneyClient::Manager::Database::get_new_queue_urls(Sys::Hostname::Long::hostname_long, getVar(name => "num_urls_to_process")); 
     579    } 
     580    return $ret; 
     581} 
    542582 
    543583# Signal handler to help give user immediate feedback during 
     
    644684    } 
    645685 
     686    # Register the host system with the database, if need be. 
     687    if (getVar(name      => "enable", 
     688               namespace => "HoneyClient::Manager::Database")) { 
     689 
     690        my $host = { 
     691            org => getVar(name => "organization"), 
     692            hostname => Sys::Hostname::Long::hostname_long, 
     693            ip => Sys::HostIP->ip, 
     694        }; 
     695        HoneyClient::Manager::Database::insert_host($host); 
     696    } 
     697 
    646698    # If supported, get a URL list from the database. 
    647699    my $remoteLinksExist = 0; 
    648700    my $queue_url_list = {}; 
    649701    my $tid = undef; 
     702    my $first_access_attempt = 1; 
    650703    while (getVar(name      => "enable", 
    651704                  namespace => "HoneyClient::Manager::Database")) { 
    652705        $LOG->info("Waiting for new URLs from database."); 
    653         # TODO: Fix this. 
    654         #$queue_url_list = HoneyClient::Manager::Database::get_queue_urls(getVar(name => "num_urls_to_process"), $vm->database_id)
    655         $queue_url_list = HoneyClient::Manager::Database::get_queue_urls(getVar(name => "num_urls_to_process"), 1145); 
     706        $queue_url_list = _get_urls(first_attempt => $first_access_attempt); 
     707        $first_access_attempt = 0
     708 
    656709        $remoteLinksExist = scalar(%{$queue_url_list}); 
    657710        while (!$localLinksExist && !$remoteLinksExist) { 
     
    661714            # XXX: Trap/ignore all errors and simply retry. 
    662715            eval { 
    663                 # TODO: Fix this. 
    664                 #$queue_url_list = HoneyClient::Manager::Database::get_queue_urls(getVar(name => "num_urls_to_process"), $vm->database_id); 
    665                 $queue_url_list = HoneyClient::Manager::Database::get_queue_urls(getVar(name => "num_urls_to_process"), 1145); 
     716                $queue_url_list = _get_urls(first_attempt => 0); 
    666717                $remoteLinksExist = scalar(%{$queue_url_list}); 
    667718            }; 
  • honeyclient/trunk/lib/HoneyClient/Manager/Database.pm

    r1532 r1558  
    296296 
    297297# XXX: Need to comment this further. 
    298 sub get_queue_urls
    299     $AUTOLOAD = "Database::get_queue_urls"; 
     298sub get_queue_urls_by_hostname
     299    $AUTOLOAD = "Database::get_queue_urls_by_hostname"; 
    300300    # Results from this call are YAML-encoded; need to deserialize them. 
    301301    return YAML::XS::Load(_AUTOLOAD(@_)); 
    302302} 
     303 
     304# XXX: Need to comment this further. 
     305sub get_new_queue_urls { 
     306    $AUTOLOAD = "Database::get_new_queue_urls"; 
     307    # Results from this call are YAML-encoded; need to deserialize them. 
     308    return YAML::XS::Load(_AUTOLOAD(@_)); 
     309} 
     310 
    303311 
    304312# XXX: Need to comment this further.